update includes
[unix-history] / usr / src / sys / nfs / nfs_node.c
index f1f20c3..acdaf25 100644 (file)
@@ -17,7 +17,7 @@
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)nfs_node.c  7.11 (Berkeley) %G%
+ *     @(#)nfs_node.c  7.28 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -26,8 +26,6 @@
 #include "proc.h"
 #include "mount.h"
 #include "vnode.h"
 #include "proc.h"
 #include "mount.h"
 #include "vnode.h"
-#include "../ufs/dir.h"
-#include "namei.h"
 #include "errno.h"
 #include "nfsv2.h"
 #include "nfs.h"
 #include "errno.h"
 #include "nfsv2.h"
 #include "nfs.h"
@@ -117,7 +115,7 @@ loop:
                        continue;
                if ((np->n_flag & NLOCKED) != 0) {
                        np->n_flag |= NWANT;
                        continue;
                if ((np->n_flag & NLOCKED) != 0) {
                        np->n_flag |= NWANT;
-                       sleep((caddr_t)np, PINOD);
+                       (void) tsleep((caddr_t)np, PINOD, "nfsnode", 0);
                        goto loop;
                }
                vp = NFSTOV(np);
                        goto loop;
                }
                vp = NFSTOV(np);
@@ -136,10 +134,12 @@ loop:
        /*
         * Insert the nfsnode in the hash queue for its new file handle
         */
        /*
         * Insert the nfsnode in the hash queue for its new file handle
         */
-       np->n_flag = NLOCKED;
+       np->n_flag = 0;
        insque(np, nh);
        insque(np, nh);
+       nfs_lock(vp);
        bcopy((caddr_t)fhp, (caddr_t)&np->n_fh, NFSX_FH);
        np->n_attrstamp = 0;
        bcopy((caddr_t)fhp, (caddr_t)&np->n_fh, NFSX_FH);
        np->n_attrstamp = 0;
+       np->n_direofoffset = 0;
        np->n_sillyrename = (struct sillyrename *)0;
        np->n_size = 0;
        np->n_mtime = 0;
        np->n_sillyrename = (struct sillyrename *)0;
        np->n_size = 0;
        np->n_mtime = 0;
@@ -154,11 +154,11 @@ nfs_inactive(vp)
        register struct nameidata *ndp;
        register struct sillyrename *sp;
        struct nfsnode *dnp;
        register struct nameidata *ndp;
        register struct sillyrename *sp;
        struct nfsnode *dnp;
+       extern int prtactive;
 
        np = VTONFS(vp);
 
        np = VTONFS(vp);
-       if (vp->v_count != 0)
-               printf("nfs_inactive: pushing active fileid %d fsid 0x%x\n",
-                       np->n_vattr.va_fileid, np->n_vattr.va_fsid);
+       if (prtactive && vp->v_usecount != 0)
+               vprint("nfs_inactive: pushing active", vp);
        nfs_lock(vp);
        sp = np->n_sillyrename;
        np->n_sillyrename = (struct sillyrename *)0;
        nfs_lock(vp);
        sp = np->n_sillyrename;
        np->n_sillyrename = (struct sillyrename *)0;
@@ -176,7 +176,7 @@ nfs_inactive(vp)
                free((caddr_t)sp, M_TEMP);
        }
        nfs_unlock(vp);
                free((caddr_t)sp, M_TEMP);
        }
        nfs_unlock(vp);
-       np->n_flag &= NBUFFERED;
+       np->n_flag &= NMODIFIED;
 #ifdef notdef
        /*
         * Scan the request list for any requests left hanging about
 #ifdef notdef
        /*
         * Scan the request list for any requests left hanging about
@@ -207,10 +207,10 @@ nfs_reclaim(vp)
        register struct vnode *vp;
 {
        register struct nfsnode *np = VTONFS(vp);
        register struct vnode *vp;
 {
        register struct nfsnode *np = VTONFS(vp);
+       extern int prtactive;
 
 
-       if (vp->v_count != 0)
-               printf("nfs_reclaim: pushing active fileid %d fsid 0x%x\n",
-                       np->n_vattr.va_fileid, np->n_vattr.va_fsid);
+       if (prtactive && vp->v_usecount != 0)
+               vprint("nfs_reclaim: pushing active", vp);
        /*
         * Remove the nfsnode from its hash chain.
         */
        /*
         * Remove the nfsnode from its hash chain.
         */
@@ -218,13 +218,8 @@ nfs_reclaim(vp)
        np->n_forw = np;
        np->n_back = np;
        cache_purge(vp);
        np->n_forw = np;
        np->n_back = np;
        cache_purge(vp);
-       /*
-        * Flush out any associated bio buffers that might be lying about
-        */
-       if (vp->v_type == VREG && (np->n_flag & NBUFFERED)) {
-               np->n_flag |= NLOCKED;
-               nfs_blkflush(vp, (daddr_t)0, np->n_size, TRUE);
-       }
+       np->n_flag = 0;
+       np->n_direofoffset = 0;
        return (0);
 }
 
        return (0);
 }
 
@@ -238,8 +233,14 @@ nfs_lock(vp)
 
        while (np->n_flag & NLOCKED) {
                np->n_flag |= NWANT;
 
        while (np->n_flag & NLOCKED) {
                np->n_flag |= NWANT;
-               sleep((caddr_t)np, PINOD);
+               if (np->n_lockholder == u.u_procp->p_pid)
+                       panic("locking against myself");
+               np->n_lockwaiter = u.u_procp->p_pid;
+               (void) tsleep((caddr_t)np, PINOD, "nfslock", 0);
        }
        }
+       np->n_lockwaiter = 0;
+       np->n_lockholder = u.u_procp->p_pid;
+       u.u_spare[0]++;
        np->n_flag |= NLOCKED;
 }
 
        np->n_flag |= NLOCKED;
 }
 
@@ -251,6 +252,10 @@ nfs_unlock(vp)
 {
        register struct nfsnode *np = VTONFS(vp);
 
 {
        register struct nfsnode *np = VTONFS(vp);
 
+       if ((np->n_flag & NLOCKED) == 0)
+               vprint("nfs_unlock: unlocked nfsnode", vp);
+       np->n_lockholder = 0;
+       u.u_spare[0]--;
        np->n_flag &= ~NLOCKED;
        if (np->n_flag & NWANT) {
                np->n_flag &= ~NWANT;
        np->n_flag &= ~NLOCKED;
        if (np->n_flag & NWANT) {
                np->n_flag &= ~NWANT;
@@ -258,6 +263,18 @@ nfs_unlock(vp)
        }
 }
 
        }
 }
 
+/*
+ * Check for a locked nfsnode
+ */
+nfs_islocked(vp)
+       struct vnode *vp;
+{
+
+       if (VTONFS(vp)->n_flag & NLOCKED)
+               return (1);
+       return (0);
+}
+
 /*
  * Unlock and vrele()
  * since I can't decide if dirs. should be locked, I will check for
 /*
  * Unlock and vrele()
  * since I can't decide if dirs. should be locked, I will check for
@@ -273,32 +290,14 @@ nfs_nput(vp)
        vrele(vp);
 }
 
        vrele(vp);
 }
 
-nfs_abortop(ndp)
-       register struct nameidata *ndp;
-{
-       register struct nfsnode *np;
-
-       if (ndp->ni_vp != NULL) {
-               np = VTONFS(ndp->ni_vp);
-               if (np->n_flag & NLOCKED)
-                       nfs_unlock(ndp->ni_vp);
-               vrele(ndp->ni_vp);
-       }
-       if (ndp->ni_dvp != NULL) {
-               np = VTONFS(ndp->ni_dvp);
-               if (np->n_flag & NLOCKED)
-                       nfs_unlock(ndp->ni_dvp);
-               vrele(ndp->ni_dvp);
-       }
-}
-
 /*
 /*
- * This is silly, but if you use a macro and try and use it in a file
- * that has mbuf.h included, m_data --> m_hdr.mh_data and this is not
- * a good thing
+ * Nfs abort op, called after namei() when a CREATE/DELETE isn't actually
+ * done. Currently nothing to do.
  */
  */
-struct nfsmount *vfs_to_nfs(mp)
-       struct mount *mp;
+/* ARGSUSED */
+nfs_abortop(ndp)
+       struct nameidata *ndp;
 {
 {
-       return ((struct nfsmount *)mp->m_data);
+
+       return (0);
 }
 }