vnode interface conversion
[unix-history] / usr / src / sys / kern / vfs_subr.c
index a1fcb39..e2bfb32 100644 (file)
@@ -4,24 +4,34 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)vfs_subr.c  7.59 (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;
@@ -414,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)
@@ -494,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.
         */
@@ -641,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
  */
@@ -649,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: ");
 }
 
 /*
 }
 
 /*
@@ -657,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);
 }
@@ -670,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
@@ -698,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;
 {
 
@@ -708,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;
 {
 
@@ -905,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,
@@ -929,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.
@@ -947,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;
                }
@@ -1041,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");