The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/ufs/ufs/ufs_gjournal.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2005-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    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.
   13  *
   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
   24  * SUCH DAMAGE.
   25  */
   26 
   27 #include <sys/cdefs.h>
   28 __FBSDID("$FreeBSD$");
   29 
   30 #include "opt_ufs.h"
   31 
   32 #include <sys/param.h>
   33 #include <sys/systm.h>
   34 #include <sys/kernel.h>
   35 #include <sys/vnode.h>
   36 #include <sys/lock.h>
   37 #include <sys/mount.h>
   38 #include <sys/mutex.h>
   39 
   40 #include <ufs/ufs/extattr.h>
   41 #include <ufs/ufs/quota.h>
   42 #include <ufs/ufs/inode.h>
   43 #include <ufs/ufs/ufsmount.h>
   44 #include <ufs/ufs/gjournal.h>
   45 
   46 #include <ufs/ffs/fs.h>
   47 #include <ufs/ffs/ffs_extern.h>
   48 
   49 /*
   50  * Change the number of unreferenced inodes.
   51  */
   52 static int
   53 ufs_gjournal_modref(struct vnode *vp, int count)
   54 {
   55         struct cg *cgp;
   56         struct buf *bp;
   57         ufs2_daddr_t cgbno;
   58         int error, cg;
   59         struct cdev *dev;
   60         struct inode *ip;
   61         struct ufsmount *ump;
   62         struct fs *fs;
   63         struct vnode *devvp;
   64         ino_t ino;
   65 
   66         ip = VTOI(vp);
   67         ump = ip->i_ump;
   68         fs = ip->i_fs;
   69         devvp = ip->i_devvp;
   70         ino = ip->i_number;
   71 
   72         cg = ino_to_cg(fs, ino);
   73         if (devvp->v_type != VCHR) {
   74                 /* devvp is a snapshot */
   75                 dev = VTOI(devvp)->i_devvp->v_rdev;
   76                 cgbno = fragstoblks(fs, cgtod(fs, cg));
   77         } else {
   78                 /* devvp is a normal disk device */
   79                 dev = devvp->v_rdev;
   80                 cgbno = fsbtodb(fs, cgtod(fs, cg));
   81         }
   82         if ((u_int)ino >= fs->fs_ipg * fs->fs_ncg)
   83                 panic("ufs_gjournal_modref: range: dev = %s, ino = %lu, fs = %s",
   84                     devtoname(dev), (u_long)ino, fs->fs_fsmnt);
   85         if ((error = bread(devvp, cgbno, (int)fs->fs_cgsize, NOCRED, &bp))) {
   86                 brelse(bp);
   87                 return (error);
   88         }
   89         cgp = (struct cg *)bp->b_data;
   90         if (!cg_chkmagic(cgp)) {
   91                 brelse(bp);
   92                 return (0);
   93         }
   94         bp->b_xflags |= BX_BKGRDWRITE;
   95         cgp->cg_unrefs += count;
   96         UFS_LOCK(ump);
   97         fs->fs_unrefs += count;
   98         fs->fs_fmod = 1;
   99         ACTIVECLEAR(fs, cg);
  100         UFS_UNLOCK(ump);
  101         bdwrite(bp);
  102         return (0);
  103 }
  104 
  105 void
  106 ufs_gjournal_orphan(struct vnode *vp)
  107 {
  108         struct inode *ip;
  109 
  110         if (vp->v_mount->mnt_gjprovider == NULL)
  111                 return;
  112         if (vp->v_usecount < 2 || (vp->v_vflag & VV_DELETED))
  113                 return;
  114         ip = VTOI(vp);
  115         if ((vp->v_type == VDIR && ip->i_nlink > 2) ||
  116             (vp->v_type != VDIR && ip->i_nlink > 1)) {
  117                 return;
  118         }
  119         vp->v_vflag |= VV_DELETED;
  120 
  121         ufs_gjournal_modref(vp, 1);
  122 }
  123 
  124 void
  125 ufs_gjournal_close(struct vnode *vp)
  126 {
  127         struct inode *ip;
  128 
  129         if (vp->v_mount->mnt_gjprovider == NULL)
  130                 return;
  131         if (!(vp->v_vflag & VV_DELETED))
  132                 return;
  133         ip = VTOI(vp);
  134         if (ip->i_nlink > 0)
  135                 return;
  136         ufs_gjournal_modref(vp, -1);
  137 }

Cache object: b9b104c2575ee5299b6a6560e8667113


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.