1 /* 2 * Copyright (c) 1991, 1993, 1995 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.9 (Berkeley) 05/14/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 struct proc *a_p; 39 } */ *ap; 40 { 41 struct vnode *vp = ap->a_vp; 42 struct inode *ip = VTOI(vp); 43 struct proc *p = ap->a_p; 44 struct timeval tv; 45 int mode, error = 0; 46 extern int prtactive; 47 48 if (prtactive && vp->v_usecount != 0) 49 vprint("ffs_inactive: pushing active", vp); 50 51 /* 52 * Ignore inodes related to stale file handles. 53 */ 54 if (ip->i_mode == 0) 55 goto out; 56 if (ip->i_nlink <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) { 57 #ifdef QUOTA 58 if (!getinoquota(ip)) 59 (void)chkiq(ip, -1, NOCRED, 0); 60 #endif 61 error = VOP_TRUNCATE(vp, (off_t)0, 0, NOCRED, p); 62 ip->i_rdev = 0; 63 mode = ip->i_mode; 64 ip->i_mode = 0; 65 ip->i_flag |= IN_CHANGE | IN_UPDATE; 66 VOP_VFREE(vp, ip->i_number, mode); 67 } 68 if (ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) { 69 tv = time; 70 VOP_UPDATE(vp, &tv, &tv, 0); 71 } 72 out: 73 VOP_UNLOCK(vp, 0, p); 74 /* 75 * If we are done with the inode, reclaim it 76 * so that it can be reused immediately. 77 */ 78 if (ip->i_mode == 0) 79 vrecycle(vp, (struct simplelock *)0, p); 80 return (error); 81 } 82 83 /* 84 * Reclaim an inode so that it can be used for other purposes. 85 */ 86 int 87 ufs_reclaim(vp, p) 88 struct vnode *vp; 89 struct proc *p; 90 { 91 register struct inode *ip; 92 int i; 93 extern int prtactive; 94 95 if (prtactive && vp->v_usecount != 0) 96 vprint("ufs_reclaim: pushing active", vp); 97 /* 98 * Remove the inode from its hash chain. 99 */ 100 ip = VTOI(vp); 101 ufs_ihashrem(ip); 102 /* 103 * Purge old data structures associated with the inode. 104 */ 105 cache_purge(vp); 106 if (ip->i_devvp) { 107 vrele(ip->i_devvp); 108 ip->i_devvp = 0; 109 } 110 #ifdef QUOTA 111 for (i = 0; i < MAXQUOTAS; i++) { 112 if (ip->i_dquot[i] != NODQUOT) { 113 dqrele(vp, ip->i_dquot[i]); 114 ip->i_dquot[i] = NODQUOT; 115 } 116 } 117 #endif 118 return (0); 119 } 120