Rename printf -> kprintf in sys/ and add some defines where necessary
[dragonfly.git] / sys / vfs / ufs / ufs_inode.c
CommitLineData
984263bc
MD
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: src/sys/ufs/ufs/ufs_inode.c,v 1.25.2.3 2002/07/05 22:42:31 dillon Exp $
086c1d7e 40 * $DragonFly: src/sys/vfs/ufs/ufs_inode.c,v 1.21 2006/12/23 00:41:30 swildner Exp $
984263bc
MD
41 */
42
43#include "opt_quota.h"
44#include "opt_ufs.h"
45
46#include <sys/param.h>
7752e590 47#include <sys/systm.h>
984263bc
MD
48#include <sys/vnode.h>
49#include <sys/mount.h>
50#include <sys/malloc.h>
51
1f2de5d4
MD
52#include "quota.h"
53#include "inode.h"
54#include "ufsmount.h"
55#include "ufs_extern.h"
ac690a1d 56#include "ffs_extern.h"
984263bc 57#ifdef UFS_DIRHASH
1f2de5d4
MD
58#include "dir.h"
59#include "dirhash.h"
984263bc
MD
60#endif
61
62int prtactive = 0; /* 1 => print out reclaim of active vnodes */
63
64/*
65 * Last reference to an inode. If necessary, write or delete it.
0973c589 66 *
87de5057 67 * ufs_inactive(struct vnode *a_vp)
984263bc
MD
68 */
69int
0973c589 70ufs_inactive(struct vop_inactive_args *ap)
984263bc
MD
71{
72 struct vnode *vp = ap->a_vp;
73 struct inode *ip = VTOI(vp);
984263bc
MD
74 int mode, error = 0;
75
6b03328e 76 if (prtactive && vp->v_usecount != 1)
984263bc
MD
77 vprint("ufs_inactive: pushing active", vp);
78
79 /*
80 * Ignore inodes related to stale file handles.
81 */
3446c007 82 if (ip == NULL || ip->i_mode == 0)
984263bc 83 goto out;
f73cf1ce 84 if (ip->i_nlink <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
984263bc 85#ifdef QUOTA
50e58362
MD
86 if (!ufs_getinoquota(ip))
87 (void)ufs_chkiq(ip, -1, NOCRED, FORCE);
984263bc 88#endif
ac690a1d 89 error = ffs_truncate(vp, (off_t)0, 0, NOCRED);
984263bc
MD
90 ip->i_rdev = 0;
91 mode = ip->i_mode;
92 ip->i_mode = 0;
93 ip->i_flag |= IN_CHANGE | IN_UPDATE;
ac690a1d 94 ffs_vfree(vp, ip->i_number, mode);
984263bc
MD
95 }
96 if (ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE))
ac690a1d 97 ffs_update(vp, 0);
984263bc 98out:
984263bc
MD
99 /*
100 * If we are done with the inode, reclaim it
101 * so that it can be reused immediately.
102 */
3446c007 103 if (ip == NULL || ip->i_mode == 0)
87de5057 104 vrecycle(vp);
984263bc
MD
105 return (error);
106}
107
108/*
109 * Reclaim an inode so that it can be used for other purposes.
0973c589 110 *
87de5057 111 * ufs_reclaim(struct vnode *a_vp)
984263bc
MD
112 */
113int
0973c589 114ufs_reclaim(struct vop_reclaim_args *ap)
984263bc 115{
3ff2135f
RG
116 struct inode *ip;
117 struct vnode *vp = ap->a_vp;
984263bc
MD
118#ifdef QUOTA
119 int i;
120#endif
121
6b03328e 122 if (prtactive && vp->v_usecount != 1)
984263bc
MD
123 vprint("ufs_reclaim: pushing active", vp);
124 ip = VTOI(vp);
dc1be39c
MD
125
126 /*
127 * Lazy updates.
128 */
129 if (ip) {
6b008938
MD
130 if (vp->v_flag & VFSMID) {
131 vp->v_flag &= ~VFSMID;
dc1be39c
MD
132 ++ip->i_fsmid;
133 ip->i_flag |= IN_LAZYMOD;
134 }
135 if (ip->i_flag & IN_LAZYMOD) {
136 ip->i_flag |= IN_MODIFIED;
ac690a1d 137 ffs_update(vp, 0);
dc1be39c 138 }
984263bc 139 }
7752e590
MD
140#ifdef INVARIANTS
141 if (ip && (ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE))) {
086c1d7e 142 kprintf("WARNING: INODE %ld flags %08x: modified inode being released!\n", (long)ip->i_number, (int)ip->i_flag);
7752e590 143 ip->i_flag |= IN_MODIFIED;
ac690a1d 144 ffs_update(vp, 0);
7752e590
MD
145 }
146#endif
984263bc 147 /*
3446c007
MD
148 * Remove the inode from its hash chain and purge namecache
149 * data associated with the vnode.
984263bc 150 */
3446c007
MD
151 vp->v_data = NULL;
152 if (ip) {
153 ufs_ihashrem(ip);
154 if (ip->i_devvp) {
155 vrele(ip->i_devvp);
156 ip->i_devvp = 0;
157 }
984263bc 158#ifdef QUOTA
3446c007
MD
159 for (i = 0; i < MAXQUOTAS; i++) {
160 if (ip->i_dquot[i] != NODQUOT) {
50e58362 161 ufs_dqrele(vp, ip->i_dquot[i]);
3446c007
MD
162 ip->i_dquot[i] = NODQUOT;
163 }
984263bc 164 }
984263bc
MD
165#endif
166#ifdef UFS_DIRHASH
3446c007
MD
167 if (ip->i_dirhash != NULL)
168 ufsdirhash_free(ip);
984263bc 169#endif
efda3bd0 170 kfree(ip, VFSTOUFS(vp->v_mount)->um_malloctype);
3446c007 171 }
984263bc
MD
172 return (0);
173}