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_inode.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) 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  */
   40 
   41 #include <sys/cdefs.h>
   42 __FBSDID("$FreeBSD: releng/5.2/sys/ufs/ufs/ufs_inode.c 120777 2003-10-05 02:45:00Z jeff $");
   43 
   44 #include "opt_quota.h"
   45 #include "opt_ufs.h"
   46 
   47 #include <sys/param.h>
   48 #include <sys/systm.h>
   49 #include <sys/vnode.h>
   50 #include <sys/lock.h>
   51 #include <sys/mount.h>
   52 #include <sys/malloc.h>
   53 #include <sys/mutex.h>
   54 
   55 #include <ufs/ufs/extattr.h>
   56 #include <ufs/ufs/quota.h>
   57 #include <ufs/ufs/inode.h>
   58 #include <ufs/ufs/ufsmount.h>
   59 #include <ufs/ufs/ufs_extern.h>
   60 #ifdef UFS_DIRHASH
   61 #include <ufs/ufs/dir.h>
   62 #include <ufs/ufs/dirhash.h>
   63 #endif
   64 
   65 /*
   66  * Last reference to an inode.  If necessary, write or delete it.
   67  */
   68 int
   69 ufs_inactive(ap)
   70         struct vop_inactive_args /* {
   71                 struct vnode *a_vp;
   72                 struct thread *a_td;
   73         } */ *ap;
   74 {
   75         struct vnode *vp = ap->a_vp;
   76         struct inode *ip = VTOI(vp);
   77         struct thread *td = ap->a_td;
   78         mode_t mode;
   79         int error = 0;
   80 
   81         VI_LOCK(vp);
   82         if (prtactive && vp->v_usecount != 0)
   83                 vprint("ufs_inactive: pushing active", vp);
   84         VI_UNLOCK(vp);
   85 
   86         /*
   87          * Ignore inodes related to stale file handles.
   88          */
   89         if (ip->i_mode == 0)
   90                 goto out;
   91         if (ip->i_effnlink == 0 && DOINGSOFTDEP(vp))
   92                 softdep_releasefile(ip);
   93         if (ip->i_nlink <= 0) {
   94                 (void) vn_write_suspend_wait(vp, NULL, V_WAIT);
   95 #ifdef QUOTA
   96                 if (!getinoquota(ip))
   97                         (void)chkiq(ip, -1, NOCRED, FORCE);
   98 #endif
   99 #ifdef UFS_EXTATTR
  100                 ufs_extattr_vnode_inactive(vp, td);
  101 #endif
  102                 error = UFS_TRUNCATE(vp, (off_t)0, IO_EXT | IO_NORMAL,
  103                     NOCRED, td);
  104                 /*
  105                  * Setting the mode to zero needs to wait for the inode
  106                  * to be written just as does a change to the link count.
  107                  * So, rather than creating a new entry point to do the
  108                  * same thing, we just use softdep_change_linkcnt().
  109                  */
  110                 DIP(ip, i_rdev) = 0;
  111                 mode = ip->i_mode;
  112                 ip->i_mode = 0;
  113                 DIP(ip, i_mode) = 0;
  114                 ip->i_flag |= IN_CHANGE | IN_UPDATE;
  115                 if (DOINGSOFTDEP(vp))
  116                         softdep_change_linkcnt(ip);
  117                 UFS_VFREE(vp, ip->i_number, mode);
  118         }
  119         if (ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)) {
  120                 if ((ip->i_flag & (IN_CHANGE | IN_UPDATE | IN_MODIFIED)) == 0 &&
  121                     vn_write_suspend_wait(vp, NULL, V_NOWAIT)) {
  122                         ip->i_flag &= ~IN_ACCESS;
  123                 } else {
  124                         (void) vn_write_suspend_wait(vp, NULL, V_WAIT);
  125                         UFS_UPDATE(vp, 0);
  126                 }
  127         }
  128 out:
  129         VOP_UNLOCK(vp, 0, td);
  130         /*
  131          * If we are done with the inode, reclaim it
  132          * so that it can be reused immediately.
  133          */
  134         if (ip->i_mode == 0)
  135                 vrecycle(vp, NULL, td);
  136         return (error);
  137 }
  138 
  139 /*
  140  * Reclaim an inode so that it can be used for other purposes.
  141  */
  142 int
  143 ufs_reclaim(ap)
  144         struct vop_reclaim_args /* {
  145                 struct vnode *a_vp;
  146                 struct thread *a_td;
  147         } */ *ap;
  148 {
  149         struct vnode *vp = ap->a_vp;
  150         struct inode *ip = VTOI(vp);
  151         struct ufsmount *ump = ip->i_ump;
  152 #ifdef QUOTA
  153         int i;
  154 #endif
  155 
  156         VI_LOCK(vp);
  157         if (prtactive && vp->v_usecount != 0)
  158                 vprint("ufs_reclaim: pushing active", vp);
  159         VI_UNLOCK(vp);
  160         if (ip->i_flag & IN_LAZYMOD) {
  161                 ip->i_flag |= IN_MODIFIED;
  162                 UFS_UPDATE(vp, 0);
  163         }
  164         /*
  165          * Remove the inode from its hash chain.
  166          */
  167         ufs_ihashrem(ip);
  168         /*
  169          * Purge old data structures associated with the inode.
  170          */
  171         vrele(ip->i_devvp);
  172 #ifdef QUOTA
  173         for (i = 0; i < MAXQUOTAS; i++) {
  174                 if (ip->i_dquot[i] != NODQUOT) {
  175                         dqrele(vp, ip->i_dquot[i]);
  176                         ip->i_dquot[i] = NODQUOT;
  177                 }
  178         }
  179 #endif
  180 #ifdef UFS_DIRHASH
  181         if (ip->i_dirhash != NULL)
  182                 ufsdirhash_free(ip);
  183 #endif
  184         UFS_IFREE(ump, ip);
  185         vp->v_data = 0;
  186         return (0);
  187 }

Cache object: 10d769fd85fd48a1b40ed81d734b0518


[ 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.