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 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 *
38 * @(#)ufs_inode.c 8.9 (Berkeley) 5/14/95
39 * $FreeBSD$
40 */
41
42 #include "opt_quota.h"
43
44 #include <sys/param.h>
45 #include <sys/vnode.h>
46 #include <sys/mount.h>
47 #include <sys/malloc.h>
48
49 #include <ufs/ufs/quota.h>
50 #include <ufs/ufs/inode.h>
51 #include <ufs/ufs/ufsmount.h>
52 #include <ufs/ufs/ufs_extern.h>
53
54 int prtactive = 0; /* 1 => print out reclaim of active vnodes */
55
56 /*
57 * Last reference to an inode. If necessary, write or delete it.
58 */
59 int
60 ufs_inactive(ap)
61 struct vop_inactive_args /* {
62 struct vnode *a_vp;
63 struct proc *a_p;
64 } */ *ap;
65 {
66 struct vnode *vp = ap->a_vp;
67 struct inode *ip = VTOI(vp);
68 struct proc *p = ap->a_p;
69 int mode, error = 0;
70
71 if (prtactive && vp->v_usecount != 0)
72 vprint("ufs_inactive: pushing active", vp);
73
74 /*
75 * Ignore inodes related to stale file handles.
76 */
77 if (ip->i_mode == 0)
78 goto out;
79 if (ip->i_nlink <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
80 #ifdef QUOTA
81 if (!getinoquota(ip))
82 (void)chkiq(ip, -1, NOCRED, 0);
83 #endif
84 error = UFS_TRUNCATE(vp, (off_t)0, 0, NOCRED, p);
85 ip->i_rdev = 0;
86 mode = ip->i_mode;
87 ip->i_mode = 0;
88 ip->i_flag |= IN_CHANGE | IN_UPDATE;
89 UFS_VFREE(vp, ip->i_number, mode);
90 }
91 if (ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE))
92 UFS_UPDATE(vp, 0);
93 out:
94 VOP_UNLOCK(vp, 0, p);
95 /*
96 * If we are done with the inode, reclaim it
97 * so that it can be reused immediately.
98 */
99 if (ip->i_mode == 0)
100 vrecycle(vp, (struct simplelock *)0, p);
101 return (error);
102 }
103
104 /*
105 * Reclaim an inode so that it can be used for other purposes.
106 */
107 int
108 ufs_reclaim(ap)
109 struct vop_reclaim_args /* {
110 struct vnode *a_vp;
111 struct proc *a_p;
112 } */ *ap;
113 {
114 register struct inode *ip;
115 register struct vnode *vp = ap->a_vp;
116 #ifdef QUOTA
117 int i;
118 #endif
119
120 if (prtactive && vp->v_usecount != 0)
121 vprint("ufs_reclaim: pushing active", vp);
122 ip = VTOI(vp);
123 if (ip->i_flag & IN_LAZYMOD) {
124 ip->i_flag |= IN_MODIFIED;
125 UFS_UPDATE(vp, 0);
126 }
127 /*
128 * Remove the inode from its hash chain.
129 */
130 ufs_ihashrem(ip);
131 /*
132 * Purge old data structures associated with the inode.
133 */
134 cache_purge(vp);
135 if (ip->i_devvp) {
136 vrele(ip->i_devvp);
137 ip->i_devvp = 0;
138 }
139 #ifdef QUOTA
140 for (i = 0; i < MAXQUOTAS; i++) {
141 if (ip->i_dquot[i] != NODQUOT) {
142 dqrele(vp, ip->i_dquot[i]);
143 ip->i_dquot[i] = NODQUOT;
144 }
145 }
146 #endif
147 FREE(vp->v_data, VFSTOUFS(vp->v_mount)->um_malloctype);
148 vp->v_data = 0;
149 return (0);
150 }
Cache object: b511257ece5ffdb3d3c1e3b7745d6da2
|