BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / nfs / nfs_node.c
index 3d735eb..810378e 100644 (file)
@@ -5,37 +5,50 @@
  * This code is derived from software contributed to Berkeley by
  * Rick Macklem at The University of Guelph.
  *
  * This code is derived from software contributed to Berkeley by
  * Rick Macklem at The University of Guelph.
  *
- * Redistribution is only permitted until one year after the first shipment
- * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
- * binary forms are permitted provided that: (1) source distributions retain
- * this entire copyright notice and comment, and (2) distributions including
- * binaries display the following acknowledgement:  This product includes
- * software developed by the University of California, Berkeley and its
- * contributors'' in the documentation or other materials provided with the
- * distribution and in all advertising materials mentioning features or use
- * of this software.  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.
- * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * 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.
  *
  *
- *     @(#)nfs_node.c  7.29 (Berkeley) 6/28/90
+ * 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.
+ *
+ *     @(#)nfs_node.c  7.34 (Berkeley) 5/15/91
  */
 
 #include "param.h"
 #include "systm.h"
  */
 
 #include "param.h"
 #include "systm.h"
-#include "user.h"
 #include "proc.h"
 #include "mount.h"
 #include "proc.h"
 #include "mount.h"
+#include "namei.h"
 #include "vnode.h"
 #include "vnode.h"
-#include "errno.h"
+#include "kernel.h"
+#include "malloc.h"
+
 #include "nfsv2.h"
 #include "nfs.h"
 #include "nfsnode.h"
 #include "nfsmount.h"
 #include "nfsv2.h"
 #include "nfs.h"
 #include "nfsnode.h"
 #include "nfsmount.h"
-#include "kernel.h"
-#include "malloc.h"
 
 /* The request list head */
 extern struct nfsreq nfsreqh;
 
 /* The request list head */
 extern struct nfsreq nfsreqh;
@@ -150,11 +163,11 @@ loop:
        return (0);
 }
 
        return (0);
 }
 
-nfs_inactive(vp)
+nfs_inactive(vp, p)
        struct vnode *vp;
        struct vnode *vp;
+       struct proc *p;
 {
        register struct nfsnode *np;
 {
        register struct nfsnode *np;
-       register struct nameidata *ndp;
        register struct sillyrename *sp;
        struct nfsnode *dnp;
        extern int prtactive;
        register struct sillyrename *sp;
        struct nfsnode *dnp;
        extern int prtactive;
@@ -169,14 +182,14 @@ nfs_inactive(vp)
                /*
                 * Remove the silly file that was rename'd earlier
                 */
                /*
                 * Remove the silly file that was rename'd earlier
                 */
-               ndp = &sp->s_namei;
                if (!nfs_nget(vp->v_mount, &sp->s_fh, &dnp)) {
                if (!nfs_nget(vp->v_mount, &sp->s_fh, &dnp)) {
-                       ndp->ni_dvp = NFSTOV(dnp);
-                       nfs_removeit(ndp);
-                       nfs_nput(ndp->ni_dvp);
+                       sp->s_dvp = NFSTOV(dnp);
+                       nfs_removeit(sp, p);
+                       nfs_nput(sp->s_dvp);
                }
                }
-               crfree(ndp->ni_cred);
-               free((caddr_t)sp, M_TEMP);
+               crfree(sp->s_cred);
+               vrele(sp->s_dvp);
+               free((caddr_t)sp, M_NFSREQ);
        }
        nfs_unlock(vp);
        np->n_flag &= NMODIFIED;
        }
        nfs_unlock(vp);
        np->n_flag &= NMODIFIED;
@@ -226,24 +239,31 @@ nfs_reclaim(vp)
        return (0);
 }
 
        return (0);
 }
 
+/*
+ * In theory, NFS does not need locking, but we make provision
+ * for doing it just in case it is needed.
+ */
+int donfslocking = 0;
 /*
  * Lock an nfsnode
  */
 /*
  * Lock an nfsnode
  */
+
 nfs_lock(vp)
        struct vnode *vp;
 {
        register struct nfsnode *np = VTONFS(vp);
 
 nfs_lock(vp)
        struct vnode *vp;
 {
        register struct nfsnode *np = VTONFS(vp);
 
+       if (!donfslocking)
+               return;
        while (np->n_flag & NLOCKED) {
                np->n_flag |= NWANT;
        while (np->n_flag & NLOCKED) {
                np->n_flag |= NWANT;
-               if (np->n_lockholder == u.u_procp->p_pid)
+               if (np->n_lockholder == curproc->p_pid)
                        panic("locking against myself");
                        panic("locking against myself");
-               np->n_lockwaiter = u.u_procp->p_pid;
+               np->n_lockwaiter = curproc->p_pid;
                (void) tsleep((caddr_t)np, PINOD, "nfslock", 0);
        }
        np->n_lockwaiter = 0;
                (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_lockholder = curproc->p_pid;
        np->n_flag |= NLOCKED;
 }
 
        np->n_flag |= NLOCKED;
 }
 
@@ -255,10 +275,7 @@ 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;
        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;
@@ -302,5 +319,7 @@ nfs_abortop(ndp)
        struct nameidata *ndp;
 {
 
        struct nameidata *ndp;
 {
 
+       if ((ndp->ni_nameiop & (HASBUF | SAVESTART)) == HASBUF)
+               FREE(ndp->ni_pnbuf, M_NAMEI);
        return (0);
 }
        return (0);
 }