HAMMER 61E/Many: Stabilization, Performance
[dragonfly.git] / sys / vfs / ufs / ufs_inode.c
blob90a84094df16d3e4a320717e54149eafdaeb84f1
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.
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.
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.
38 * @(#)ufs_inode.c 8.9 (Berkeley) 5/14/95
39 * $FreeBSD: src/sys/ufs/ufs/ufs_inode.c,v 1.25.2.3 2002/07/05 22:42:31 dillon Exp $
40 * $DragonFly: src/sys/vfs/ufs/ufs_inode.c,v 1.24 2008/01/02 22:42:37 dillon Exp $
43 #include "opt_quota.h"
44 #include "opt_ufs.h"
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/vnode.h>
49 #include <sys/mount.h>
50 #include <sys/malloc.h>
52 #include "quota.h"
53 #include "inode.h"
54 #include "ufsmount.h"
55 #include "ufs_extern.h"
56 #include "ffs_extern.h"
57 #ifdef UFS_DIRHASH
58 #include "dir.h"
59 #include "dirhash.h"
60 #endif
62 int prtactive = 0; /* 1 => print out reclaim of active vnodes */
65 * Last reference to an inode. If necessary, write or delete it.
67 * ufs_inactive(struct vnode *a_vp)
69 int
70 ufs_inactive(struct vop_inactive_args *ap)
72 struct vnode *vp = ap->a_vp;
73 struct inode *ip = VTOI(vp);
74 int mode, error = 0;
76 if (prtactive && vp->v_sysref.refcnt > 1)
77 vprint("ufs_inactive: pushing active", vp);
80 * Ignore inodes related to stale file handles.
82 if (ip == NULL || ip->i_mode == 0)
83 goto out;
84 if (ip->i_nlink <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
85 #ifdef QUOTA
86 if (!ufs_getinoquota(ip))
87 (void)ufs_chkiq(ip, -1, NOCRED, FORCE);
88 #endif
89 /* Must have a VM object to truncate */
90 error = ffs_truncate(vp, (off_t)0, 0, NOCRED);
91 ip->i_rdev = 0;
92 mode = ip->i_mode;
93 ip->i_mode = 0;
94 ip->i_flag |= IN_CHANGE | IN_UPDATE;
95 ffs_vfree(vp, ip->i_number, mode);
97 if (ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE))
98 ffs_update(vp, 0);
99 out:
101 * If we are done with the inode, reclaim it
102 * so that it can be reused immediately.
104 if (ip == NULL || ip->i_mode == 0)
105 vrecycle(vp);
106 return (error);
110 * Reclaim an inode so that it can be used for other purposes.
112 * ufs_reclaim(struct vnode *a_vp)
115 ufs_reclaim(struct vop_reclaim_args *ap)
117 struct inode *ip;
118 struct vnode *vp = ap->a_vp;
119 #ifdef QUOTA
120 int i;
121 #endif
123 if (prtactive && vp->v_sysref.refcnt > 1)
124 vprint("ufs_reclaim: pushing active", vp);
125 ip = VTOI(vp);
128 * Lazy updates.
130 if (ip) {
131 if (vp->v_flag & VFSMID) {
132 vp->v_flag &= ~VFSMID;
133 ++ip->i_fsmid;
134 ip->i_flag |= IN_LAZYMOD;
136 if (ip->i_flag & IN_LAZYMOD) {
137 ip->i_flag |= IN_MODIFIED;
138 ffs_update(vp, 0);
141 #ifdef INVARIANTS
142 if (ip && (ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE))) {
143 kprintf("WARNING: INODE %ld flags %08x: modified inode being released!\n", (long)ip->i_number, (int)ip->i_flag);
144 ip->i_flag |= IN_MODIFIED;
145 ffs_update(vp, 0);
147 #endif
149 * Remove the inode from its hash chain and purge namecache
150 * data associated with the vnode.
152 vp->v_data = NULL;
153 if (ip) {
154 ufs_ihashrem(ip);
155 if (ip->i_devvp) {
156 vrele(ip->i_devvp);
157 ip->i_devvp = 0;
159 #ifdef QUOTA
160 for (i = 0; i < MAXQUOTAS; i++) {
161 if (ip->i_dquot[i] != NODQUOT) {
162 ufs_dqrele(vp, ip->i_dquot[i]);
163 ip->i_dquot[i] = NODQUOT;
166 #endif
167 #ifdef UFS_DIRHASH
168 if (ip->i_dirhash != NULL)
169 ufsdirhash_free(ip);
170 #endif
171 kfree(ip, VFSTOUFS(vp->v_mount)->um_malloctype);
173 return (0);