1 /* 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * (c) UNIX System Laboratories, Inc. 5 * All or some portions of this file are derived from material licensed 6 * to the University of California by American Telephone and Telegraph 7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8 * the permission of UNIX System Laboratories, Inc. 9 * 10 * %sccs.include.redist.c% 11 * 12 * @(#)ufs_inode.c 8.8 (Berkeley) 03/30/95 13 */ 14 15 #include <sys/param.h> 16 #include <sys/systm.h> 17 #include <sys/proc.h> 18 #include <sys/vnode.h> 19 #include <sys/mount.h> 20 #include <sys/kernel.h> 21 #include <sys/malloc.h> 22 23 #include <ufs/ufs/quota.h> 24 #include <ufs/ufs/inode.h> 25 #include <ufs/ufs/ufsmount.h> 26 #include <ufs/ufs/ufs_extern.h> 27 28 u_long nextgennumber; /* Next generation number to assign. */ 29 int prtactive = 0; /* 1 => print out reclaim of active vnodes */ 30 31 /* 32 * Last reference to an inode. If necessary, write or delete it. 33 */ 34 int 35 ufs_inactive(ap) 36 struct vop_inactive_args /* { 37 struct vnode *a_vp; 38 } */ *ap; 39 { 40 register struct vnode *vp = ap->a_vp; 41 register struct inode *ip = VTOI(vp); 42 struct timeval tv; 43 int mode, error; 44 extern int prtactive; 45 46 if (prtactive && vp->v_usecount != 0) 47 vprint("ffs_inactive: pushing active", vp); 48 49 /* Get rid of inodes related to stale file handles. */ 50 if (ip->i_mode == 0) { 51 if ((vp->v_flag & VXLOCK) == 0) 52 vgone(vp); 53 return (0); 54 } 55 56 error = 0; 57 #ifdef DIAGNOSTIC 58 if (VOP_ISLOCKED(vp)) 59 panic("ffs_inactive: locked inode"); 60 if (curproc) 61 ip->i_lockholder = curproc->p_pid; 62 else 63 ip->i_lockholder = -1; 64 #endif 65 ip->i_flag |= IN_LOCKED; 66 if (ip->i_nlink <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) { 67 #ifdef QUOTA 68 if (!getinoquota(ip)) 69 (void)chkiq(ip, -1, NOCRED, 0); 70 #endif 71 error = VOP_TRUNCATE(vp, (off_t)0, 0, NOCRED, NULL); 72 ip->i_rdev = 0; 73 mode = ip->i_mode; 74 ip->i_mode = 0; 75 ip->i_flag |= IN_CHANGE | IN_UPDATE; 76 VOP_VFREE(vp, ip->i_number, mode); 77 } 78 if (ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) { 79 tv = time; 80 VOP_UPDATE(vp, &tv, &tv, 0); 81 } 82 VOP_UNLOCK(vp); 83 /* 84 * If we are done with the inode, reclaim it 85 * so that it can be reused immediately. 86 */ 87 if (vp->v_usecount == 0 && ip->i_mode == 0) 88 vgone(vp); 89 return (error); 90 } 91 92 /* 93 * Reclaim an inode so that it can be used for other purposes. 94 */ 95 int 96 ufs_reclaim(vp) 97 register struct vnode *vp; 98 { 99 register struct inode *ip; 100 int i; 101 extern int prtactive; 102 103 if (prtactive && vp->v_usecount != 0) 104 vprint("ufs_reclaim: pushing active", vp); 105 /* 106 * Remove the inode from its hash chain. 107 */ 108 ip = VTOI(vp); 109 ufs_ihashrem(ip); 110 /* 111 * Purge old data structures associated with the inode. 112 */ 113 cache_purge(vp); 114 if (ip->i_devvp) { 115 vrele(ip->i_devvp); 116 ip->i_devvp = 0; 117 } 118 #ifdef QUOTA 119 for (i = 0; i < MAXQUOTAS; i++) { 120 if (ip->i_dquot[i] != NODQUOT) { 121 dqrele(vp, ip->i_dquot[i]); 122 ip->i_dquot[i] = NODQUOT; 123 } 124 } 125 #endif 126 return (0); 127 } 128