vnode interface conversion
[unix-history] / usr / src / sys / kern / vfs_subr.c
index 125fafc..e2bfb32 100644 (file)
@@ -4,24 +4,34 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)vfs_subr.c  7.57 (Berkeley) %G%
+ *     @(#)vfs_subr.c  7.73 (Berkeley) %G%
  */
 
 /*
  * External virtual filesystem routines
  */
 
  */
 
 /*
  * External virtual filesystem routines
  */
 
-#include "param.h"
-#include "proc.h"
-#include "mount.h"
-#include "time.h"
-#include "vnode.h"
-#include "specdev.h"
-#include "namei.h"
-#include "ucred.h"
-#include "buf.h"
-#include "errno.h"
-#include "malloc.h"
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/mount.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>
+
+enum vtype iftovt_tab[16] = {
+       VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON,
+       VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VBAD,
+};
+int    vttoif_tab[9] = {
+       0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK,
+       S_IFSOCK, S_IFIFO, S_IFMT,
+};
 
 /*
  * Remove a mount point from the list of mounted filesystems.
 
 /*
  * Remove a mount point from the list of mounted filesystems.
@@ -137,10 +147,13 @@ void vattr_null(vap)
 {
 
        vap->va_type = VNON;
 {
 
        vap->va_type = VNON;
+       vap->va_size = vap->va_bytes = VNOVAL;
+#ifdef _NOQUAD
+       vap->va_size_rsv = vap->va_bytes_rsv = VNOVAL;
+#endif
        vap->va_mode = vap->va_nlink = vap->va_uid = vap->va_gid =
        vap->va_mode = vap->va_nlink = vap->va_uid = vap->va_gid =
-               vap->va_fsid = vap->va_fileid = vap->va_size =
-               vap->va_size_rsv = vap->va_blocksize = vap->va_rdev =
-               vap->va_bytes = vap->va_bytes_rsv =
+               vap->va_fsid = vap->va_fileid =
+               vap->va_blocksize = vap->va_rdev =
                vap->va_atime.tv_sec = vap->va_atime.tv_usec =
                vap->va_mtime.tv_sec = vap->va_mtime.tv_usec =
                vap->va_ctime.tv_sec = vap->va_ctime.tv_usec =
                vap->va_atime.tv_sec = vap->va_atime.tv_usec =
                vap->va_mtime.tv_sec = vap->va_mtime.tv_usec =
                vap->va_ctime.tv_sec = vap->va_ctime.tv_usec =
@@ -151,7 +164,8 @@ void vattr_null(vap)
  * Routines having to do with the management of the vnode table.
  */
 struct vnode *vfreeh, **vfreet;
  * Routines having to do with the management of the vnode table.
  */
 struct vnode *vfreeh, **vfreet;
-extern struct vnodeops dead_vnodeops, spec_vnodeops;
+extern struct vnodeops dead_vnodeops;
+extern struct vnodeops spec_vnodeops;
 extern void vclean();
 long numvnodes;
 struct vattr va_null;
 extern void vclean();
 long numvnodes;
 struct vattr va_null;
@@ -209,8 +223,11 @@ getnewvnode(tag, mp, vops, vpp)
                vfreeh = vq;
                vp->v_freef = NULL;
                vp->v_freeb = NULL;
                vfreeh = vq;
                vp->v_freef = NULL;
                vp->v_freeb = NULL;
+               vp->v_lease = NULL;
                if (vp->v_type != VBAD)
                        vgone(vp);
                if (vp->v_type != VBAD)
                        vgone(vp);
+               if (vp->v_data)
+                       panic("cleaned vnode isn't");
                vp->v_flag = 0;
                vp->v_lastr = 0;
                vp->v_socket = 0;
                vp->v_flag = 0;
                vp->v_lastr = 0;
                vp->v_socket = 0;
@@ -232,7 +249,7 @@ insmntque(vp, mp)
        register struct vnode *vp;
        register struct mount *mp;
 {
        register struct vnode *vp;
        register struct mount *mp;
 {
-       struct vnode *vq;
+       register struct vnode *vq;
 
        /*
         * Delete from old mount point vnode list, if on one.
 
        /*
         * Delete from old mount point vnode list, if on one.
@@ -251,16 +268,11 @@ insmntque(vp, mp)
                vp->v_mountb = NULL;
                return;
        }
                vp->v_mountb = NULL;
                return;
        }
-       if (mp->mnt_mounth) {
-               vp->v_mountf = mp->mnt_mounth;
-               vp->v_mountb = &mp->mnt_mounth;
-               mp->mnt_mounth->v_mountb = &vp->v_mountf;
-               mp->mnt_mounth = vp;
-       } else {
-               mp->mnt_mounth = vp;
-               vp->v_mountb = &mp->mnt_mounth;
-               vp->v_mountf = NULL;
-       }
+       if (vq = mp->mnt_mounth)
+               vq->v_mountb = &vp->v_mountf;
+       vp->v_mountf = vq;
+       vp->v_mountb = &mp->mnt_mounth;
+       mp->mnt_mounth = vp;
 }
 
 /*
 }
 
 /*
@@ -419,7 +431,7 @@ vinvalbuf(vp, save)
                        splx(s);
                        if (save && (bp->b_flags & B_DELWRI)) {
                                dirty++;
                        splx(s);
                        if (save && (bp->b_flags & B_DELWRI)) {
                                dirty++;
-                               (void) bwrite(bp);
+                               (void) VOP_BWRITE(bp);
                                break;
                        }
                        if (bp->b_vp != vp)
                                break;
                        }
                        if (bp->b_vp != vp)
@@ -441,6 +453,8 @@ bgetvp(vp, bp)
        register struct vnode *vp;
        register struct buf *bp;
 {
        register struct vnode *vp;
        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");
@@ -453,16 +467,11 @@ bgetvp(vp, bp)
        /*
         * Insert onto list for new vnode.
         */
        /*
         * Insert onto list for new vnode.
         */
-       if (vp->v_cleanblkhd) {
-               bp->b_blockf = vp->v_cleanblkhd;
-               bp->b_blockb = &vp->v_cleanblkhd;
-               vp->v_cleanblkhd->b_blockb = &bp->b_blockf;
-               vp->v_cleanblkhd = bp;
-       } else {
-               vp->v_cleanblkhd = bp;
-               bp->b_blockb = &vp->v_cleanblkhd;
-               bp->b_blockf = NULL;
-       }
+       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;
 }
 
 /*
 }
 
 /*
@@ -502,8 +511,10 @@ reassignbuf(bp, newvp)
 {
        register struct buf *bq, **listheadp;
 
 {
        register struct buf *bq, **listheadp;
 
-       if (newvp == NULL)
-               panic("reassignbuf: NULL");
+       if (newvp == NULL) {
+               printf("reassignbuf: NULL");
+               return;
+       }
        /*
         * Delete from old vnode list, if on one.
         */
        /*
         * Delete from old vnode list, if on one.
         */
@@ -520,16 +531,11 @@ reassignbuf(bp, newvp)
                listheadp = &newvp->v_dirtyblkhd;
        else
                listheadp = &newvp->v_cleanblkhd;
                listheadp = &newvp->v_dirtyblkhd;
        else
                listheadp = &newvp->v_cleanblkhd;
-       if (*listheadp) {
-               bp->b_blockf = *listheadp;
-               bp->b_blockb = listheadp;
-               bp->b_blockf->b_blockb = &bp->b_blockf;
-               *listheadp = bp;
-       } else {
-               *listheadp = bp;
-               bp->b_blockb = listheadp;
-               bp->b_blockf = NULL;
-       }
+       if (bq = *listheadp)
+               bq->b_blockb = &bp->b_blockf;
+       bp->b_blockf = bq;
+       bp->b_blockb = listheadp;
+       *listheadp = bp;
 }
 
 /*
 }
 
 /*
@@ -654,6 +660,8 @@ vget(vp)
        return (0);
 }
 
        return (0);
 }
 
+int bug_refs = 0;
+
 /*
  * Vnode reference, just increment the count
  */
 /*
  * Vnode reference, just increment the count
  */
@@ -662,6 +670,10 @@ void vref(vp)
 {
 
        vp->v_usecount++;
 {
 
        vp->v_usecount++;
+       if (vp->v_type != VBLK && curproc)
+               curproc->p_spare[0]++;
+       if (bug_refs)
+               vprint("vref: ");
 }
 
 /*
 }
 
 /*
@@ -670,6 +682,7 @@ void vref(vp)
 void vput(vp)
        register struct vnode *vp;
 {
 void vput(vp)
        register struct vnode *vp;
 {
+
        VOP_UNLOCK(vp);
        vrele(vp);
 }
        VOP_UNLOCK(vp);
        vrele(vp);
 }
@@ -683,13 +696,23 @@ void vrele(vp)
 {
        struct proc *p = curproc;               /* XXX */
 
 {
        struct proc *p = curproc;               /* XXX */
 
+#ifdef DIAGNOSTIC
        if (vp == NULL)
                panic("vrele: null vp");
        if (vp == NULL)
                panic("vrele: null vp");
+#endif
        vp->v_usecount--;
        vp->v_usecount--;
-       if (vp->v_usecount < 0)
-               vprint("vrele: bad ref count", vp);
+       if (vp->v_type != VBLK && curproc)
+               curproc->p_spare[0]--;
+       if (bug_refs)
+               vprint("vref: ");
        if (vp->v_usecount > 0)
                return;
        if (vp->v_usecount > 0)
                return;
+#ifdef DIAGNOSTIC
+       if (vp->v_usecount != 0 || vp->v_writecount != 0) {
+               vprint("vrele: bad ref count", vp);
+               panic("vrele: ref cnt");
+       }
+#endif
        if (vfreeh == NULLVP) {
                /*
                 * insert into empty list
        if (vfreeh == NULLVP) {
                /*
                 * insert into empty list
@@ -711,7 +734,7 @@ void vrele(vp)
 /*
  * Page or buffer structure gets a reference.
  */
 /*
  * Page or buffer structure gets a reference.
  */
-vhold(vp)
+void vhold(vp)
        register struct vnode *vp;
 {
 
        register struct vnode *vp;
 {
 
@@ -721,7 +744,7 @@ vhold(vp)
 /*
  * Page or buffer structure frees a reference.
  */
 /*
  * Page or buffer structure frees a reference.
  */
-holdrele(vp)
+void holdrele(vp)
        register struct vnode *vp;
 {
 
        register struct vnode *vp;
 {
 
@@ -843,16 +866,16 @@ void vclean(vp, flags)
         * If purging an active vnode, it must be unlocked, closed,
         * and deactivated before being reclaimed.
         */
         * If purging an active vnode, it must be unlocked, closed,
         * and deactivated before being reclaimed.
         */
-       (*(origops->vn_unlock))(vp);
+       (*(origops->vop_unlock))(vp);
        if (active) {
                if (flags & DOCLOSE)
        if (active) {
                if (flags & DOCLOSE)
-                       (*(origops->vn_close))(vp, IO_NDELAY, NOCRED, p);
-               (*(origops->vn_inactive))(vp, p);
+                       (*(origops->vop_close))(vp, IO_NDELAY, NOCRED, p);
+               (*(origops->vop_inactive))(vp, p);
        }
        /*
         * Reclaim the vnode.
         */
        }
        /*
         * Reclaim the vnode.
         */
-       if ((*(origops->vn_reclaim))(vp))
+       if ((*(origops->vop_reclaim))(vp))
                panic("vclean: cannot reclaim");
        if (active)
                vrele(vp);
                panic("vclean: cannot reclaim");
        if (active)
                vrele(vp);
@@ -918,7 +941,6 @@ void vgone(vp)
 {
        register struct vnode *vq;
        struct vnode *vx;
 {
        register struct vnode *vq;
        struct vnode *vx;
-       long count;
 
        /*
         * If a vgone (or vclean) is already in progress,
 
        /*
         * If a vgone (or vclean) is already in progress,
@@ -942,6 +964,7 @@ void vgone(vp)
                *vp->v_mountb = vq;
                vp->v_mountf = NULL;
                vp->v_mountb = NULL;
                *vp->v_mountb = vq;
                vp->v_mountf = NULL;
                vp->v_mountb = NULL;
+               vp->v_mount = NULL;
        }
        /*
         * If special device, remove it from special device alias list.
        }
        /*
         * If special device, remove it from special device alias list.
@@ -960,17 +983,18 @@ void vgone(vp)
                                panic("missing bdev");
                }
                if (vp->v_flag & VALIASED) {
                                panic("missing bdev");
                }
                if (vp->v_flag & VALIASED) {
-                       count = 0;
+                       vx = NULL;
                        for (vq = *vp->v_hashchain; vq; vq = vq->v_specnext) {
                                if (vq->v_rdev != vp->v_rdev ||
                                    vq->v_type != vp->v_type)
                                        continue;
                        for (vq = *vp->v_hashchain; vq; vq = vq->v_specnext) {
                                if (vq->v_rdev != vp->v_rdev ||
                                    vq->v_type != vp->v_type)
                                        continue;
-                               count++;
+                               if (vx)
+                                       break;
                                vx = vq;
                        }
                                vx = vq;
                        }
-                       if (count == 0)
+                       if (vx == NULL)
                                panic("missing alias");
                                panic("missing alias");
-                       if (count == 1)
+                       if (vq == NULL)
                                vx->v_flag &= ~VALIASED;
                        vp->v_flag &= ~VALIASED;
                }
                                vx->v_flag &= ~VALIASED;
                        vp->v_flag &= ~VALIASED;
                }
@@ -1054,8 +1078,9 @@ vprint(label, vp)
 
        if (label != NULL)
                printf("%s: ", label);
 
        if (label != NULL)
                printf("%s: ", label);
-       printf("type %s, usecount %d, refcount %d,", typename[vp->v_type],
-               vp->v_usecount, vp->v_holdcnt);
+       printf("type %s, usecount %d, writecount %d, refcount %d,",
+               typename[vp->v_type], vp->v_usecount, vp->v_writecount,
+               vp->v_holdcnt);
        buf[0] = '\0';
        if (vp->v_flag & VROOT)
                strcat(buf, "|VROOT");
        buf[0] = '\0';
        if (vp->v_flag & VROOT)
                strcat(buf, "|VROOT");