2 * Copyright (c) 2005-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/vnode.h>
38 #include <sys/mount.h>
39 #include <sys/mutex.h>
41 #include <ufs/ufs/extattr.h>
42 #include <ufs/ufs/quota.h>
43 #include <ufs/ufs/inode.h>
44 #include <ufs/ufs/ufsmount.h>
45 #include <ufs/ufs/gjournal.h>
47 #include <ufs/ffs/fs.h>
48 #include <ufs/ffs/ffs_extern.h>
51 * Change the number of unreferenced inodes.
54 ufs_gjournal_modref(struct vnode *vp, int count)
68 ump = VFSTOUFS(vp->v_mount);
70 devvp = ump->um_devvp;
73 cg = ino_to_cg(fs, ino);
74 if (devvp->v_type == VREG) {
75 /* devvp is a snapshot */
76 dev = VFSTOUFS(devvp->v_mount)->um_devvp->v_rdev;
77 cgbno = fragstoblks(fs, cgtod(fs, cg));
78 } else if (devvp->v_type == VCHR) {
79 /* devvp is a normal disk device */
81 cgbno = fsbtodb(fs, cgtod(fs, cg));
86 if ((u_int)ino >= fs->fs_ipg * fs->fs_ncg)
87 panic("ufs_gjournal_modref: range: dev = %s, ino = %lu, fs = %s",
88 devtoname(dev), (u_long)ino, fs->fs_fsmnt);
89 if ((error = ffs_getcg(fs, devvp, cg, &bp, &cgp)) != 0)
91 cgp->cg_unrefs += count;
93 fs->fs_unrefs += count;
102 ufs_gjournal_orphan(struct vnode *vp)
106 if (vp->v_mount->mnt_gjprovider == NULL)
108 if (vp->v_usecount < 2 || (vp->v_vflag & VV_DELETED))
111 if ((vp->v_type == VDIR && ip->i_nlink > 2) ||
112 (vp->v_type != VDIR && ip->i_nlink > 1)) {
115 vp->v_vflag |= VV_DELETED;
117 ufs_gjournal_modref(vp, 1);
121 ufs_gjournal_close(struct vnode *vp)
125 if (vp->v_mount->mnt_gjprovider == NULL)
127 if (!(vp->v_vflag & VV_DELETED))
132 ufs_gjournal_modref(vp, -1);