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
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 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)ufs_inode.c 8.9 (Berkeley) 5/14/95
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include "opt_quota.h"
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/vnode.h>
47 #include <sys/mount.h>
48 #include <sys/malloc.h>
49 #include <sys/mutex.h>
51 #include <ufs/ufs/extattr.h>
52 #include <ufs/ufs/quota.h>
53 #include <ufs/ufs/inode.h>
54 #include <ufs/ufs/ufsmount.h>
55 #include <ufs/ufs/ufs_extern.h>
57 #include <ufs/ufs/dir.h>
58 #include <ufs/ufs/dirhash.h>
62 * Last reference to an inode. If necessary, write or delete it.
66 struct vop_inactive_args /* {
71 struct vnode *vp = ap->a_vp;
72 struct inode *ip = VTOI(vp);
73 struct thread *td = ap->a_td;
77 if (prtactive && vp->v_usecount != 0)
78 vprint("ufs_inactive: pushing active", vp);
80 * Ignore inodes related to stale file handles.
84 if (ip->i_effnlink == 0 && DOINGSOFTDEP(vp))
85 softdep_releasefile(ip);
86 if (ip->i_nlink <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
87 (void) vn_write_suspend_wait(vp, NULL, V_WAIT);
90 (void)chkiq(ip, -1, NOCRED, FORCE);
93 ufs_extattr_vnode_inactive(vp, td);
95 error = UFS_TRUNCATE(vp, (off_t)0, IO_EXT | IO_NORMAL,
98 * Setting the mode to zero needs to wait for the inode
99 * to be written just as does a change to the link count.
100 * So, rather than creating a new entry point to do the
101 * same thing, we just use softdep_change_linkcnt().
103 DIP_SET(ip, i_rdev, 0);
106 DIP_SET(ip, i_mode, 0);
107 ip->i_flag |= IN_CHANGE | IN_UPDATE;
108 if (DOINGSOFTDEP(vp))
109 softdep_change_linkcnt(ip);
110 UFS_VFREE(vp, ip->i_number, mode);
112 if (ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) {
113 if ((ip->i_flag & (IN_CHANGE | IN_UPDATE | IN_MODIFIED)) == 0 &&
114 vn_write_suspend_wait(vp, NULL, V_NOWAIT)) {
115 ip->i_flag &= ~IN_ACCESS;
117 (void) vn_write_suspend_wait(vp, NULL, V_WAIT);
123 * If we are done with the inode, reclaim it
124 * so that it can be reused immediately.
132 * Reclaim an inode so that it can be used for other purposes.
136 struct vop_reclaim_args /* {
141 struct vnode *vp = ap->a_vp;
142 struct inode *ip = VTOI(vp);
143 struct ufsmount *ump = ip->i_ump;
148 if (prtactive && vp->v_usecount != 0)
149 vprint("ufs_reclaim: pushing active", vp);
151 * Destroy the vm object and flush associated pages.
153 vnode_destroy_vobject(vp);
154 if (ip->i_flag & IN_LAZYMOD) {
155 ip->i_flag |= IN_MODIFIED;
159 * Remove the inode from its hash chain.
163 * Purge old data structures associated with the inode.
166 for (i = 0; i < MAXQUOTAS; i++) {
167 if (ip->i_dquot[i] != NODQUOT) {
168 dqrele(vp, ip->i_dquot[i]);
169 ip->i_dquot[i] = NODQUOT;
174 if (ip->i_dirhash != NULL)
178 * Lock the clearing of v_data so ffs_lock() can inspect it
179 * prior to obtaining the lock.