BSD 4_4 release
[unix-history] / usr / src / sys / kern / vfs_subr.c
index eed29ed..d11e8d3 100644 (file)
@@ -1,10 +1,36 @@
 /*
 /*
- * Copyright (c) 1989 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1989, 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.
  *
  *
- *     @(#)vfs_subr.c  7.82 (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.
+ *
+ *     @(#)vfs_subr.c  8.1 (Berkeley) 6/10/93
  */
 
 /*
  */
 
 /*
 #include <sys/time.h>
 #include <sys/vnode.h>
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/vnode.h>
 #include <sys/stat.h>
-#include <sys/specdev.h>
 #include <sys/namei.h>
 #include <sys/ucred.h>
 #include <sys/buf.h>
 #include <sys/errno.h>
 #include <sys/malloc.h>
 
 #include <sys/namei.h>
 #include <sys/ucred.h>
 #include <sys/buf.h>
 #include <sys/errno.h>
 #include <sys/malloc.h>
 
+#include <vm/vm.h>
+#include <sys/sysctl.h>
+
+#include <miscfs/specfs/specdev.h>
+
 enum vtype iftovt_tab[16] = {
        VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON,
        VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VBAD,
 enum vtype iftovt_tab[16] = {
        VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON,
        VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VBAD,
@@ -34,6 +64,12 @@ int  vttoif_tab[9] = {
        S_IFSOCK, S_IFIFO, S_IFMT,
 };
 
        S_IFSOCK, S_IFIFO, S_IFMT,
 };
 
+/*
+ * Insq/Remq for the vnode usage lists.
+ */
+#define        bufinsvn(bp, dp)        list_enter_head(dp, bp, struct buf *, b_vnbufs)
+#define        bufremvn(bp)            list_remove(bp, struct buf *, b_vnbufs)
+
 /*
  * Remove a mount point from the list of mounted filesystems.
  * Unmount of the root is illegal.
 /*
  * Remove a mount point from the list of mounted filesystems.
  * Unmount of the root is illegal.
@@ -183,18 +219,19 @@ void vattr_null(vap)
                vap->va_mtime.ts_sec = vap->va_mtime.ts_nsec =
                vap->va_ctime.ts_sec = vap->va_ctime.ts_nsec =
                vap->va_flags = vap->va_gen = VNOVAL;
                vap->va_mtime.ts_sec = vap->va_mtime.ts_nsec =
                vap->va_ctime.ts_sec = vap->va_ctime.ts_nsec =
                vap->va_flags = vap->va_gen = VNOVAL;
+       vap->va_vaflags = 0;
 }
 
 /*
  * Routines having to do with the management of the vnode table.
  */
 }
 
 /*
  * Routines having to do with the management of the vnode table.
  */
-extern struct vnode *vfreeh, **vfreet;
+struct vnode *vfreeh, **vfreet = &vfreeh;
 extern int (**dead_vnodeop_p)();
 extern int (**dead_vnodeop_p)();
-extern int (**spec_vnodeop_p)();
 extern void vclean();
 long numvnodes;
 extern struct vattr va_null;
 
 extern void vclean();
 long numvnodes;
 extern struct vattr va_null;
 
+
 /*
  * Return the next vnode from the free list.
  */
 /*
  * Return the next vnode from the free list.
  */
@@ -205,6 +242,7 @@ getnewvnode(tag, mp, vops, vpp)
        struct vnode **vpp;
 {
        register struct vnode *vp, *vq;
        struct vnode **vpp;
 {
        register struct vnode *vp, *vq;
+       int s;
 
        if ((vfreeh == NULL && numvnodes < 2 * desiredvnodes) ||
            numvnodes < desiredvnodes) {
 
        if ((vfreeh == NULL && numvnodes < 2 * desiredvnodes) ||
            numvnodes < desiredvnodes) {
@@ -230,22 +268,32 @@ getnewvnode(tag, mp, vops, vpp)
                vp->v_lease = NULL;
                if (vp->v_type != VBAD)
                        vgone(vp);
                vp->v_lease = NULL;
                if (vp->v_type != VBAD)
                        vgone(vp);
+#ifdef DIAGNOSTIC
                if (vp->v_data)
                        panic("cleaned vnode isn't");
                if (vp->v_data)
                        panic("cleaned vnode isn't");
+               s = splbio();
+               if (vp->v_numoutput)
+                       panic("Clean vnode has pending I/O's");
+               splx(s);
+#endif
                vp->v_flag = 0;
                vp->v_lastr = 0;
                vp->v_flag = 0;
                vp->v_lastr = 0;
+               vp->v_lastw = 0;
+               vp->v_lasta = 0;
+               vp->v_cstart = 0;
+               vp->v_clen = 0;
                vp->v_socket = 0;
        }
                vp->v_socket = 0;
        }
+       vp->v_ralen = 1;
        vp->v_type = VNON;
        cache_purge(vp);
        vp->v_tag = tag;
        vp->v_op = vops;
        insmntque(vp, mp);
        vp->v_type = VNON;
        cache_purge(vp);
        vp->v_tag = tag;
        vp->v_op = vops;
        insmntque(vp, mp);
-       VREF(vp);
+       vp->v_usecount++;
        *vpp = vp;
        return (0);
 }
        *vpp = vp;
        return (0);
 }
-
 /*
  * Move a vnode from one mount queue to another.
  */
 /*
  * Move a vnode from one mount queue to another.
  */
@@ -287,9 +335,11 @@ vwakeup(bp)
 {
        register struct vnode *vp;
 
 {
        register struct vnode *vp;
 
-       bp->b_dirtyoff = bp->b_dirtyend = 0;
+       bp->b_flags &= ~B_WRITEINPROG;
        if (vp = bp->b_vp) {
                vp->v_numoutput--;
        if (vp = bp->b_vp) {
                vp->v_numoutput--;
+               if (vp->v_numoutput < 0)
+                       panic("vwakeup: neg numoutput");
                if ((vp->v_flag & VBWAIT) && vp->v_numoutput <= 0) {
                        if (vp->v_numoutput < 0)
                                panic("vwakeup: neg numoutput");
                if ((vp->v_flag & VBWAIT) && vp->v_numoutput <= 0) {
                        if (vp->v_numoutput < 0)
                                panic("vwakeup: neg numoutput");
@@ -304,49 +354,67 @@ vwakeup(bp)
  * Called with the underlying object locked.
  */
 int
  * Called with the underlying object locked.
  */
 int
-vinvalbuf(vp, save, cred, p)
+vinvalbuf(vp, flags, cred, p, slpflag, slptimeo)
        register struct vnode *vp;
        register struct vnode *vp;
-       int save;
+       int flags;
        struct ucred *cred;
        struct proc *p;
        struct ucred *cred;
        struct proc *p;
+       int slpflag, slptimeo;
 {
        register struct buf *bp;
        struct buf *nbp, *blist;
        int s, error;
 
 {
        register struct buf *bp;
        struct buf *nbp, *blist;
        int s, error;
 
-       if (save) {
+       if (flags & V_SAVE) {
                if (error = VOP_FSYNC(vp, cred, MNT_WAIT, p))
                        return (error);
                if (error = VOP_FSYNC(vp, cred, MNT_WAIT, p))
                        return (error);
-               if (vp->v_dirtyblkhd != NULL)
+               if (vp->v_dirtyblkhd.le_next != NULL)
                        panic("vinvalbuf: dirty bufs");
        }
        for (;;) {
                        panic("vinvalbuf: dirty bufs");
        }
        for (;;) {
-               if (blist = vp->v_cleanblkhd)
-                       /* void */;
-               else if (blist = vp->v_dirtyblkhd)
-                       /* void */;
-               else
+               if ((blist = vp->v_cleanblkhd.le_next) && flags & V_SAVEMETA)
+                       while (blist && blist->b_lblkno < 0)
+                               blist = blist->b_vnbufs.qe_next;
+               if (!blist && (blist = vp->v_dirtyblkhd.le_next) && 
+                   (flags & V_SAVEMETA))
+                       while (blist && blist->b_lblkno < 0)
+                               blist = blist->b_vnbufs.qe_next;
+               if (!blist)
                        break;
                        break;
+
                for (bp = blist; bp; bp = nbp) {
                for (bp = blist; bp; bp = nbp) {
-                       nbp = bp->b_blockf;
+                       nbp = bp->b_vnbufs.qe_next;
+                       if (flags & V_SAVEMETA && bp->b_lblkno < 0)
+                               continue;
                        s = splbio();
                        if (bp->b_flags & B_BUSY) {
                                bp->b_flags |= B_WANTED;
                        s = splbio();
                        if (bp->b_flags & B_BUSY) {
                                bp->b_flags |= B_WANTED;
-                               sleep((caddr_t)bp, PRIBIO + 1);
+                               error = tsleep((caddr_t)bp,
+                                       slpflag | (PRIBIO + 1), "vinvalbuf",
+                                       slptimeo);
                                splx(s);
                                splx(s);
+                               if (error)
+                                       return (error);
                                break;
                        }
                        bremfree(bp);
                        bp->b_flags |= B_BUSY;
                        splx(s);
                                break;
                        }
                        bremfree(bp);
                        bp->b_flags |= B_BUSY;
                        splx(s);
-                       if (bp->b_vp != vp)
-                               reassignbuf(bp, bp->b_vp);
-                       else
-                               bp->b_flags |= B_INVAL;
+                       /*
+                        * XXX Since there are no node locks for NFS, I believe
+                        * there is a slight chance that a delayed write will
+                        * occur while sleeping just above, so check for it.
+                        */
+                       if ((bp->b_flags & B_DELWRI) && (flags & V_SAVE)) {
+                               (void) VOP_BWRITE(bp);
+                               break;
+                       }
+                       bp->b_flags |= B_INVAL;
                        brelse(bp);
                }
        }
                        brelse(bp);
                }
        }
-       if (vp->v_dirtyblkhd || vp->v_cleanblkhd)
+       if (!(flags & V_SAVEMETA) &&
+           (vp->v_dirtyblkhd.le_next || vp->v_cleanblkhd.le_next))
                panic("vinvalbuf: flush failed");
        return (0);
 }
                panic("vinvalbuf: flush failed");
        return (0);
 }
@@ -359,7 +427,6 @@ bgetvp(vp, bp)
        register struct buf *bp;
 {
        register struct vnode *vq;
        register struct buf *bp;
 {
        register struct vnode *vq;
-       register struct buf *bq;
 
        if (bp->b_vp)
                panic("bgetvp: not free");
 
        if (bp->b_vp)
                panic("bgetvp: not free");
@@ -372,11 +439,7 @@ bgetvp(vp, bp)
        /*
         * Insert onto list for new vnode.
         */
        /*
         * Insert onto list for new vnode.
         */
-       if (bq = vp->v_cleanblkhd)
-               bq->b_blockb = &bp->b_blockf;
-       bp->b_blockf = bq;
-       bp->b_blockb = &vp->v_cleanblkhd;
-       vp->v_cleanblkhd = bp;
+       bufinsvn(bp, &vp->v_cleanblkhd);
 }
 
 /*
 }
 
 /*
@@ -385,7 +448,6 @@ bgetvp(vp, bp)
 brelvp(bp)
        register struct buf *bp;
 {
 brelvp(bp)
        register struct buf *bp;
 {
-       struct buf *bq;
        struct vnode *vp;
 
        if (bp->b_vp == (struct vnode *) 0)
        struct vnode *vp;
 
        if (bp->b_vp == (struct vnode *) 0)
@@ -393,13 +455,8 @@ brelvp(bp)
        /*
         * Delete from old vnode list, if on one.
         */
        /*
         * Delete from old vnode list, if on one.
         */
-       if (bp->b_blockb) {
-               if (bq = bp->b_blockf)
-                       bq->b_blockb = bp->b_blockb;
-               *bp->b_blockb = bq;
-               bp->b_blockf = NULL;
-               bp->b_blockb = NULL;
-       }
+       if (bp->b_vnbufs.qe_next != NOLIST)
+               bufremvn(bp);
        vp = bp->b_vp;
        bp->b_vp = (struct vnode *) 0;
        HOLDRELE(vp);
        vp = bp->b_vp;
        bp->b_vp = (struct vnode *) 0;
        HOLDRELE(vp);
@@ -414,7 +471,7 @@ reassignbuf(bp, newvp)
        register struct buf *bp;
        register struct vnode *newvp;
 {
        register struct buf *bp;
        register struct vnode *newvp;
 {
-       register struct buf *bq, **listheadp;
+       register struct list_entry *listheadp;
 
        if (newvp == NULL) {
                printf("reassignbuf: NULL");
 
        if (newvp == NULL) {
                printf("reassignbuf: NULL");
@@ -423,11 +480,8 @@ reassignbuf(bp, newvp)
        /*
         * Delete from old vnode list, if on one.
         */
        /*
         * Delete from old vnode list, if on one.
         */
-       if (bp->b_blockb) {
-               if (bq = bp->b_blockf)
-                       bq->b_blockb = bp->b_blockb;
-               *bp->b_blockb = bq;
-       }
+       if (bp->b_vnbufs.qe_next != NOLIST)
+               bufremvn(bp);
        /*
         * If dirty, put on list of dirty buffers;
         * otherwise insert onto list of clean buffers.
        /*
         * If dirty, put on list of dirty buffers;
         * otherwise insert onto list of clean buffers.
@@ -436,11 +490,7 @@ reassignbuf(bp, newvp)
                listheadp = &newvp->v_dirtyblkhd;
        else
                listheadp = &newvp->v_cleanblkhd;
                listheadp = &newvp->v_dirtyblkhd;
        else
                listheadp = &newvp->v_cleanblkhd;
-       if (bq = *listheadp)
-               bq->b_blockb = &bp->b_blockf;
-       bp->b_blockf = bq;
-       bp->b_blockb = listheadp;
-       *listheadp = bp;
+       bufinsvn(bp, listheadp);
 }
 
 /*
 }
 
 /*
@@ -560,13 +610,11 @@ vget(vp)
                vp->v_freef = NULL;
                vp->v_freeb = NULL;
        }
                vp->v_freef = NULL;
                vp->v_freeb = NULL;
        }
-       VREF(vp);
+       vp->v_usecount++;
        VOP_LOCK(vp);
        return (0);
 }
 
        VOP_LOCK(vp);
        return (0);
 }
 
-int bug_refs = 0;
-
 /*
  * Vnode reference, just increment the count
  */
 /*
  * Vnode reference, just increment the count
  */
@@ -574,11 +622,9 @@ void vref(vp)
        struct vnode *vp;
 {
 
        struct vnode *vp;
 {
 
+       if (vp->v_usecount <= 0)
+               panic("vref used where vget required");
        vp->v_usecount++;
        vp->v_usecount++;
-       if (vp->v_type != VBLK && curproc)
-               curproc->p_spare[0]++;
-       if (bug_refs)
-               vprint("vref: ");
 }
 
 /*
 }
 
 /*
@@ -605,10 +651,6 @@ void vrele(vp)
                panic("vrele: null vp");
 #endif
        vp->v_usecount--;
                panic("vrele: null vp");
 #endif
        vp->v_usecount--;
-       if (vp->v_type != VBLK && curproc)
-               curproc->p_spare[0]--;
-       if (bug_refs)
-               vprint("vref: ");
        if (vp->v_usecount > 0)
                return;
 #ifdef DIAGNOSTIC
        if (vp->v_usecount > 0)
                return;
 #ifdef DIAGNOSTIC
@@ -617,19 +659,11 @@ void vrele(vp)
                panic("vrele: ref cnt");
        }
 #endif
                panic("vrele: ref cnt");
        }
 #endif
-       if (vfreeh == NULLVP) {
-               /*
-                * insert into empty list
-                */
-               vfreeh = vp;
-               vp->v_freeb = &vfreeh;
-       } else {
-               /*
-                * insert at tail of list
-                */
-               *vfreet = vp;
-               vp->v_freeb = vfreet;
-       }
+       /*
+        * insert at tail of LRU list
+        */
+       *vfreet = vp;
+       vp->v_freeb = vfreet;
        vp->v_freef = NULL;
        vfreet = &vp->v_freef;
        VOP_INACTIVE(vp);
        vp->v_freef = NULL;
        vfreet = &vp->v_freef;
        VOP_INACTIVE(vp);
@@ -665,7 +699,8 @@ void holdrele(vp)
  * system error). If MNT_FORCE is specified, detach any active vnodes
  * that are found.
  */
  * system error). If MNT_FORCE is specified, detach any active vnodes
  * that are found.
  */
-int busyprt = 0;       /* patch to print out busy vnodes */
+int busyprt = 0;       /* print out busy vnodes */
+struct ctldebug debug1 = { "busyprt", &busyprt };
 
 vflush(mp, skipvp, flags)
        struct mount *mp;
 
 vflush(mp, skipvp, flags)
        struct mount *mp;
@@ -692,6 +727,13 @@ loop:
                 */
                if ((flags & SKIPSYSTEM) && (vp->v_flag & VSYSTEM))
                        continue;
                 */
                if ((flags & SKIPSYSTEM) && (vp->v_flag & VSYSTEM))
                        continue;
+               /*
+                * If WRITECLOSE is set, only flush out regular file
+                * vnodes open for writing.
+                */
+               if ((flags & WRITECLOSE) &&
+                   (vp->v_writecount == 0 || vp->v_type != VREG))
+                       continue;
                /*
                 * With v_usecount == 0, all we need to do is clear
                 * out the vnode data structures and we are done.
                /*
                 * With v_usecount == 0, all we need to do is clear
                 * out the vnode data structures and we are done.
@@ -701,6 +743,7 @@ loop:
                        continue;
                }
                /*
                        continue;
                }
                /*
+                * If FORCECLOSE is set, forcibly close the vnode.
                 * For block or character devices, revert to an
                 * anonymous device. For all other files, just kill them.
                 */
                 * For block or character devices, revert to an
                 * anonymous device. For all other files, just kill them.
                 */
@@ -731,11 +774,6 @@ vclean(vp, flags)
        register struct vnode *vp;
        int flags;
 {
        register struct vnode *vp;
        int flags;
 {
-       struct vop_inactive_args vop_inactive_a;
-       struct vop_reclaim_args vop_reclaim_a;
-       struct vop_unlock_args vop_unlock_a;
-       struct vop_close_args vop_close_a;
-       int (**origops)();
        int active;
 
        /*
        int active;
 
        /*
@@ -746,6 +784,14 @@ vclean(vp, flags)
         */
        if (active = vp->v_usecount)
                VREF(vp);
         */
        if (active = vp->v_usecount)
                VREF(vp);
+       /*
+        * Even if the count is zero, the VOP_INACTIVE routine may still
+        * have the object locked while it cleans it out. The VOP_LOCK
+        * ensures that the VOP_INACTIVE routine is done with its work.
+        * For active vnodes, it ensures that no other activity can
+        * occur while the underlying object is being cleaned out.
+        */
+       VOP_LOCK(vp);
        /*
         * Prevent the vnode from being recycled or
         * brought into use while we clean it out.
        /*
         * Prevent the vnode from being recycled or
         * brought into use while we clean it out.
@@ -754,63 +800,37 @@ vclean(vp, flags)
                panic("vclean: deadlock");
        vp->v_flag |= VXLOCK;
        /*
                panic("vclean: deadlock");
        vp->v_flag |= VXLOCK;
        /*
-        * Even if the count is zero, the VOP_INACTIVE routine may still
-        * have the object locked while it cleans it out. The VOP_LOCK
-        * ensures that the VOP_INACTIVE routine is done with its work.
-        * For active vnodes, it ensures that no other activity can
-        * occur while the buffer list is being cleaned out.
+        * Clean out any buffers associated with the vnode.
         */
         */
-       VOP_LOCK(vp);
        if (flags & DOCLOSE)
        if (flags & DOCLOSE)
-               vinvalbuf(vp, 1, NOCRED, NULL);
+               vinvalbuf(vp, V_SAVE, NOCRED, NULL, 0, 0);
        /*
        /*
-        * Prevent any further operations on the vnode from
-        * being passed through to the old file system.
+        * Any other processes trying to obtain this lock must first
+        * wait for VXLOCK to clear, then call the new lock operation.
         */
         */
-       origops = vp->v_op;
-       vp->v_op = dead_vnodeop_p;
-       vp->v_tag = VT_NON;
+       VOP_UNLOCK(vp);
        /*
        /*
-        * If purging an active vnode, it must be unlocked, closed,
-        * and deactivated before being reclaimed.
+        * If purging an active vnode, it must be closed and
+        * deactivated before being reclaimed.
         */
         */
-       vop_unlock_a.a_desc = VDESC(vop_unlock);
-       vop_unlock_a.a_vp = vp;
-       VOCALL(origops,VOFFSET(vop_unlock),&vop_unlock_a);
        if (active) {
        if (active) {
-               /*
-                * Note: these next two calls imply
-                * that vop_close and vop_inactive implementations
-                * cannot count on the ops vector being correctly
-                * set.
-                */
-               if (flags & DOCLOSE) {
-                       vop_close_a.a_desc = VDESC(vop_close);
-                       vop_close_a.a_vp = vp;
-                       vop_close_a.a_fflag = IO_NDELAY;
-                       vop_close_a.a_p = NULL;
-                       VOCALL(origops,VOFFSET(vop_close),&vop_close_a);
-               };
-               vop_inactive_a.a_desc = VDESC(vop_inactive);
-               vop_inactive_a.a_vp = vp;
-               VOCALL(origops,VOFFSET(vop_inactive),&vop_inactive_a);
+               if (flags & DOCLOSE)
+                       VOP_CLOSE(vp, IO_NDELAY, NOCRED, NULL);
+               VOP_INACTIVE(vp);
        }
        /*
         * Reclaim the vnode.
         */
        }
        /*
         * Reclaim the vnode.
         */
-       /*
-        * Emulate VOP_RECLAIM.
-        */
-       vop_reclaim_a.a_desc = VDESC(vop_reclaim);
-       vop_reclaim_a.a_vp = vp;
-       if (VOCALL(origops,VOFFSET(vop_reclaim),&vop_reclaim_a))
+       if (VOP_RECLAIM(vp))
                panic("vclean: cannot reclaim");
        if (active)
                vrele(vp);
 
        /*
                panic("vclean: cannot reclaim");
        if (active)
                vrele(vp);
 
        /*
-        * Done with purge, notify sleepers in vget of the grim news.
+        * Done with purge, notify sleepers of the grim news.
         */
         */
+       vp->v_op = dead_vnodeop_p;
+       vp->v_tag = VT_NON;
        vp->v_flag &= ~VXLOCK;
        if (vp->v_flag & VXWANT) {
                vp->v_flag &= ~VXWANT;
        vp->v_flag &= ~VXLOCK;
        if (vp->v_flag & VXWANT) {
                vp->v_flag &= ~VXWANT;
@@ -931,9 +951,10 @@ void vgone(vp)
                vp->v_specinfo = NULL;
        }
        /*
                vp->v_specinfo = NULL;
        }
        /*
-        * If it is on the freelist, move it to the head of the list.
+        * If it is on the freelist and not already at the head,
+        * move it to the head of the list.
         */
         */
-       if (vp->v_freeb) {
+       if (vp->v_freeb && vfreeh != vp) {
                if (vq = vp->v_freef)
                        vq->v_freeb = vp->v_freeb;
                else
                if (vq = vp->v_freef)
                        vq->v_freeb = vp->v_freeb;
                else
@@ -961,9 +982,9 @@ vfinddev(dev, type, vpp)
                if (dev != vp->v_rdev || type != vp->v_type)
                        continue;
                *vpp = vp;
                if (dev != vp->v_rdev || type != vp->v_type)
                        continue;
                *vpp = vp;
-               return (0);
+               return (1);
        }
        }
-       return (1);
+       return (0);
 }
 
 /*
 }
 
 /*
@@ -1056,14 +1077,13 @@ int kinfo_vdebug = 1;
 int kinfo_vgetfailed;
 #define KINFO_VNODESLOP        10
 /*
 int kinfo_vgetfailed;
 #define KINFO_VNODESLOP        10
 /*
- * Dump vnode list (via kinfo).
+ * Dump vnode list (via sysctl).
  * Copyout address of vnode followed by vnode.
  */
 /* ARGSUSED */
  * Copyout address of vnode followed by vnode.
  */
 /* ARGSUSED */
-kinfo_vnode(op, where, acopysize, arg, aneeded)
-       int op;
+sysctl_vnode(where, sizep)
        char *where;
        char *where;
-       int *acopysize, arg, *aneeded;
+       size_t *sizep;
 {
        register struct mount *mp = rootfs;
        struct mount *omp;
 {
        register struct mount *mp = rootfs;
        struct mount *omp;
@@ -1075,10 +1095,10 @@ kinfo_vnode(op, where, acopysize, arg, aneeded)
 #define VPTRSZ sizeof (struct vnode *)
 #define VNODESZ        sizeof (struct vnode)
        if (where == NULL) {
 #define VPTRSZ sizeof (struct vnode *)
 #define VNODESZ        sizeof (struct vnode)
        if (where == NULL) {
-               *aneeded = (numvnodes + KINFO_VNODESLOP) * (VPTRSZ + VNODESZ);
+               *sizep = (numvnodes + KINFO_VNODESLOP) * (VPTRSZ + VNODESZ);
                return (0);
        }
                return (0);
        }
-       ewhere = where + *acopysize;
+       ewhere = where + *sizep;
                
        do {
                if (vfs_busy(mp)) {
                
        do {
                if (vfs_busy(mp)) {
@@ -1099,10 +1119,12 @@ again:
                                bp = savebp;
                                goto again;
                        }
                                bp = savebp;
                                goto again;
                        }
-                       if ((bp + VPTRSZ + VNODESZ <= ewhere) && 
-                           ((error = copyout((caddr_t)&vp, bp, VPTRSZ)) ||
-                            (error = copyout((caddr_t)vp, bp + VPTRSZ, 
-                             VNODESZ))))
+                       if (bp + VPTRSZ + VNODESZ > ewhere) {
+                               *sizep = bp - where;
+                               return (ENOMEM);
+                       }
+                       if ((error = copyout((caddr_t)&vp, bp, VPTRSZ)) ||
+                          (error = copyout((caddr_t)vp, bp + VPTRSZ, VNODESZ)))
                                return (error);
                        bp += VPTRSZ + VNODESZ;
                }
                                return (error);
                        bp += VPTRSZ + VNODESZ;
                }
@@ -1111,10 +1133,6 @@ again:
                vfs_unbusy(omp);
        } while (mp != rootfs);
 
                vfs_unbusy(omp);
        } while (mp != rootfs);
 
-       *aneeded = bp - where;
-       if (bp > ewhere)
-               *acopysize = ewhere - where;
-       else
-               *acopysize = bp - where;
+       *sizep = bp - where;
        return (0);
 }
        return (0);
 }