BSD 4_4_Lite1 release
[unix-history] / usr / src / sys / ufs / lfs / lfs_segment.c
index e3e6a32..249d59d 100644 (file)
@@ -2,9 +2,35 @@
  * Copyright (c) 1991, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
  * Copyright (c) 1991, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
- * %sccs.include.redist.c%
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
  *
  *
- *     @(#)lfs_segment.c       8.2 (Berkeley) %G%
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ *     @(#)lfs_segment.c       8.5 (Berkeley) 1/4/94
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -91,7 +117,6 @@ lfs_vflush(vp)
        struct inode *ip;
        struct lfs *fs;
        struct segment *sp;
        struct inode *ip;
        struct lfs *fs;
        struct segment *sp;
-       int error, s;
 
        fs = VFSTOUFS(vp->v_mount)->um_lfs;
        if (fs->lfs_nactive > MAX_ACTIVE)
 
        fs = VFSTOUFS(vp->v_mount)->um_lfs;
        if (fs->lfs_nactive > MAX_ACTIVE)
@@ -101,12 +126,12 @@ lfs_vflush(vp)
 
 
        ip = VTOI(vp);
 
 
        ip = VTOI(vp);
-       if (vp->v_dirtyblkhd.le_next == NULL)
+       if (vp->v_dirtyblkhd.lh_first == NULL)
                lfs_writevnodes(fs, vp->v_mount, sp, VN_EMPTY);
 
        do {
                do {
                lfs_writevnodes(fs, vp->v_mount, sp, VN_EMPTY);
 
        do {
                do {
-                       if (vp->v_dirtyblkhd.le_next != NULL)
+                       if (vp->v_dirtyblkhd.lh_first != NULL)
                                lfs_writefile(fs, sp, vp);
                } while (lfs_writeinode(fs, sp, ip));
 
                                lfs_writefile(fs, sp, vp);
                } while (lfs_writeinode(fs, sp, ip));
 
@@ -132,9 +157,11 @@ lfs_writevnodes(fs, mp, sp, op)
 {
        struct inode *ip;
        struct vnode *vp;
 {
        struct inode *ip;
        struct vnode *vp;
-       int error, s, active;
 
 
-loop:  for (vp = mp->mnt_mounth; vp; vp = vp->v_mountf) {
+loop:
+       for (vp = mp->mnt_vnodelist.lh_first;
+            vp != NULL;
+            vp = vp->v_mntvnodes.le_next) {
                /*
                 * If the vnode that we are about to sync is no longer
                 * associated with this mount point, start over.
                /*
                 * If the vnode that we are about to sync is no longer
                 * associated with this mount point, start over.
@@ -148,7 +175,7 @@ loop:       for (vp = mp->mnt_mounth; vp; vp = vp->v_mountf) {
                        continue;
                */
 
                        continue;
                */
 
-               if (op == VN_EMPTY && vp->v_dirtyblkhd.le_next)
+               if (op == VN_EMPTY && vp->v_dirtyblkhd.lh_first)
                        continue;
 
                if (vp->v_type == VNON)
                        continue;
 
                if (vp->v_type == VNON)
@@ -162,10 +189,11 @@ loop:     for (vp = mp->mnt_mounth; vp; vp = vp->v_mountf) {
                 * the IFILE.
                 */
                ip = VTOI(vp);
                 * the IFILE.
                 */
                ip = VTOI(vp);
-               if ((ip->i_flag & (IMODIFIED | IACCESS | IUPDATE | ICHANGE) ||
-                   vp->v_dirtyblkhd.le_next != NULL) &&
+               if ((ip->i_flag &
+                   (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE) ||
+                   vp->v_dirtyblkhd.lh_first != NULL) &&
                    ip->i_number != LFS_IFILE_INUM) {
                    ip->i_number != LFS_IFILE_INUM) {
-                       if (vp->v_dirtyblkhd.le_next != NULL)
+                       if (vp->v_dirtyblkhd.lh_first != NULL)
                                lfs_writefile(fs, sp, vp);
                        (void) lfs_writeinode(fs, sp, ip);
                }
                                lfs_writefile(fs, sp, vp);
                        (void) lfs_writeinode(fs, sp, ip);
                }
@@ -187,8 +215,7 @@ lfs_segwrite(mp, flags)
        SEGUSE *segusep;
        daddr_t ibno;
        CLEANERINFO *cip;
        SEGUSE *segusep;
        daddr_t ibno;
        CLEANERINFO *cip;
-       int clean, error, i, s;
-       int do_ckp;
+       int clean, do_ckp, error, i;
 
        fs = VFSTOUFS(mp)->um_lfs;
 
 
        fs = VFSTOUFS(mp)->um_lfs;
 
@@ -255,9 +282,9 @@ lfs_segwrite(mp, flags)
        if (do_ckp || fs->lfs_doifile) {
 redo:
                vp = fs->lfs_ivnode;
        if (do_ckp || fs->lfs_doifile) {
 redo:
                vp = fs->lfs_ivnode;
-               while (vget(vp));
+               while (vget(vp, 1));
                ip = VTOI(vp);
                ip = VTOI(vp);
-               if (vp->v_dirtyblkhd.le_next != NULL)
+               if (vp->v_dirtyblkhd.lh_first != NULL)
                        lfs_writefile(fs, sp, vp);
                (void)lfs_writeinode(fs, sp, ip);
                vput(vp);
                        lfs_writefile(fs, sp, vp);
                (void)lfs_writeinode(fs, sp, ip);
                vput(vp);
@@ -352,7 +379,7 @@ lfs_writeinode(fs, sp, ip)
        int error, i, ndx;
        int redo_ifile = 0;
 
        int error, i, ndx;
        int redo_ifile = 0;
 
-       if (!(ip->i_flag & (IMODIFIED | IACCESS | IUPDATE | ICHANGE)))
+       if (!(ip->i_flag & (IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE)))
                return(0);
 
        /* Allocate a new inode block if necessary. */
                return(0);
 
        /* Allocate a new inode block if necessary. */
@@ -382,10 +409,10 @@ lfs_writeinode(fs, sp, ip)
        }
 
        /* Update the inode times and copy the inode onto the inode page. */
        }
 
        /* Update the inode times and copy the inode onto the inode page. */
-       if (ip->i_flag & IMODIFIED)
+       if (ip->i_flag & IN_MODIFIED)
                --fs->lfs_uinodes;
        ITIMES(ip, &time, &time);
                --fs->lfs_uinodes;
        ITIMES(ip, &time, &time);
-       ip->i_flag &= ~(IMODIFIED | IACCESS | IUPDATE | ICHANGE);
+       ip->i_flag &= ~(IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE);
        bp = sp->ibp;
        ((struct dinode *)bp->b_data)[sp->ninodes % INOPB(fs)] = ip->i_din;
        /* Increment inode count in segment summary block. */
        bp = sp->ibp;
        ((struct dinode *)bp->b_data)[sp->ninodes % INOPB(fs)] = ip->i_din;
        /* Increment inode count in segment summary block. */
@@ -494,7 +521,7 @@ lfs_gather(fs, sp, vp, match)
 
        sp->vp = vp;
        s = splbio();
 
        sp->vp = vp;
        s = splbio();
-loop:  for (bp = vp->v_dirtyblkhd.le_next; bp; bp = bp->b_vnbufs.qe_next) {
+loop:  for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = bp->b_vnbufs.le_next) {
                if (bp->b_flags & B_BUSY || !match(fs, bp) ||
                    bp->b_flags & B_GATHERED)
                        continue;
                if (bp->b_flags & B_BUSY || !match(fs, bp) ||
                    bp->b_flags & B_GATHERED)
                        continue;
@@ -607,7 +634,6 @@ lfs_initseg(fs)
        SEGUSE *sup;
        SEGSUM *ssp;
        struct buf *bp;
        SEGUSE *sup;
        SEGSUM *ssp;
        struct buf *bp;
-       daddr_t lbn, *lbnp;
        int repeat;
 
        sp = fs->lfs_sp;
        int repeat;
 
        sp = fs->lfs_sp;
@@ -680,7 +706,7 @@ lfs_newseg(fs)
        CLEANERINFO *cip;
        SEGUSE *sup;
        struct buf *bp;
        CLEANERINFO *cip;
        SEGUSE *sup;
        struct buf *bp;
-       int curseg, error, isdirty, sn;
+       int curseg, isdirty, sn;
 
         LFS_SEGENTRY(sup, fs, datosn(fs, fs->lfs_nextseg), bp);
         sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE;
 
         LFS_SEGENTRY(sup, fs, datosn(fs, fs->lfs_nextseg), bp);
         sup->su_flags |= SEGUSE_DIRTY | SEGUSE_ACTIVE;
@@ -726,7 +752,7 @@ lfs_writeseg(fs, sp)
        dev_t i_dev;
        size_t size;
        u_long *datap, *dp;
        dev_t i_dev;
        size_t size;
        u_long *datap, *dp;
-       int ch_per_blk, do_again, error, i, nblocks, num, s;
+       int ch_per_blk, do_again, i, nblocks, num, s;
        int (*strategy)__P((struct vop_strategy_args *));
        struct vop_strategy_args vop_strategy_a;
        u_short ninos;
        int (*strategy)__P((struct vop_strategy_args *));
        struct vop_strategy_args vop_strategy_a;
        u_short ninos;
@@ -1057,49 +1083,29 @@ lfs_shellsort(bp_array, lb_array, nmemb)
 }
 
 /*
 }
 
 /*
- * Check VXLOCK.  Return 1 if the vnode is locked.  Otherwise, bump the
- * ref count, removing the vnode from the free list if it is on it.
+ * Check VXLOCK.  Return 1 if the vnode is locked.  Otherwise, vget it.
  */
 lfs_vref(vp)
        register struct vnode *vp;
 {
  */
 lfs_vref(vp)
        register struct vnode *vp;
 {
-       register struct vnode *vq;
-       extern struct vnode *vfreeh;
-       extern struct vnode **vfreet;
 
        if (vp->v_flag & VXLOCK)
                return(1);
 
        if (vp->v_flag & VXLOCK)
                return(1);
-
-       if (vp->v_usecount == 0) {
-               if (vq = vp->v_freef)
-                       vq->v_freeb = vp->v_freeb;
-               else
-                       vfreet = vp->v_freeb;
-               *vp->v_freeb = vq;
-               vp->v_freef = NULL;
-               vp->v_freeb = NULL;
-       }
-       VREF(vp);
-       return (0);
+       return (vget(vp, 0));
 }
 
 void
 lfs_vunref(vp)
        register struct vnode *vp;
 {
 }
 
 void
 lfs_vunref(vp)
        register struct vnode *vp;
 {
-       extern struct vnode *vfreeh;
-       extern struct vnode **vfreet;
-
-       --vp->v_usecount;
+       extern int lfs_no_inactive;
 
        /*
 
        /*
-        * return to free list
+        * This is vrele except that we do not want to VOP_INACTIVE
+        * this vnode. Rather than inline vrele here, we use a global
+        * flag to tell lfs_inactive not to run. Yes, its gross.
         */
         */
-       if (vp->v_usecount == 0) {
-               *vfreet = vp;
-               vp->v_freeb = vfreet;
-               vp->v_freef = NULL;
-               vfreet = &vp->v_freef;
-       }
-       return;
+       lfs_no_inactive = 1;
+       vrele(vp);
+       lfs_no_inactive = 0;
 }
 }