cache open with O_CREAT when the name already exists
authorKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Fri, 1 Mar 1991 05:23:30 +0000 (21:23 -0800)
committerKirk McKusick <mckusick@ucbvax.Berkeley.EDU>
Fri, 1 Mar 1991 05:23:30 +0000 (21:23 -0800)
SCCS-vsn: sys/kern/vfs_lookup.c 7.26
SCCS-vsn: sys/kern/vfs_cache.c 7.8
SCCS-vsn: sys/ufs/ffs/ufs_lookup.c 7.26
SCCS-vsn: sys/ufs/ufs/ufs_lookup.c 7.26

usr/src/sys/kern/vfs_cache.c
usr/src/sys/kern/vfs_lookup.c
usr/src/sys/ufs/ffs/ufs_lookup.c
usr/src/sys/ufs/ufs/ufs_lookup.c

index 834ce49..f4f9b90 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)vfs_cache.c 7.7 (Berkeley) %G%
+ *     @(#)vfs_cache.c 7.8 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -96,21 +96,24 @@ cache_lookup(ndp)
        if (!ndp->ni_makeentry) {
                nchstats.ncs_badhits++;
        } else if (ncp->nc_vp == NULL) {
        if (!ndp->ni_makeentry) {
                nchstats.ncs_badhits++;
        } else if (ncp->nc_vp == NULL) {
-               nchstats.ncs_neghits++;
-               /*
-                * move this slot to end of LRU chain, if not already there
-                */
-               if (ncp->nc_nxt) {
-                       /* remove from LRU chain */
-                       *ncp->nc_prev = ncp->nc_nxt;
-                       ncp->nc_nxt->nc_prev = ncp->nc_prev;
-                       /* and replace at end of it */
-                       ncp->nc_nxt = NULL;
-                       ncp->nc_prev = nchtail;
-                       *nchtail = ncp;
-                       nchtail = &ncp->nc_nxt;
+               if ((ndp->ni_nameiop & OPMASK) != CREATE) {
+                       nchstats.ncs_neghits++;
+                       /*
+                        * Move this slot to end of LRU chain,
+                        * if not already there.
+                        */
+                       if (ncp->nc_nxt) {
+                               /* remove from LRU chain */
+                               *ncp->nc_prev = ncp->nc_nxt;
+                               ncp->nc_nxt->nc_prev = ncp->nc_prev;
+                               /* and replace at end of it */
+                               ncp->nc_nxt = NULL;
+                               ncp->nc_prev = nchtail;
+                               *nchtail = ncp;
+                               nchtail = &ncp->nc_nxt;
+                       }
+                       return (ENOENT);
                }
                }
-               return (ENOENT);
        } else if (ncp->nc_vpid != ncp->nc_vp->v_id) {
                nchstats.ncs_falsehits++;
        } else {
        } else if (ncp->nc_vpid != ncp->nc_vp->v_id) {
                nchstats.ncs_falsehits++;
        } else {
index 9ec6183..3b4b9f5 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)vfs_lookup.c        7.25 (Berkeley) %G%
+ *     @(#)vfs_lookup.c        7.26 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -90,7 +90,7 @@ namei(ndp)
        lockparent = ndp->ni_nameiop & LOCKPARENT;
        docache = (ndp->ni_nameiop & NOCACHE) ^ NOCACHE;
        getbuf = (ndp->ni_nameiop & HASBUF) ^ HASBUF;
        lockparent = ndp->ni_nameiop & LOCKPARENT;
        docache = (ndp->ni_nameiop & NOCACHE) ^ NOCACHE;
        getbuf = (ndp->ni_nameiop & HASBUF) ^ HASBUF;
-       if (flag == DELETE || wantparent)
+       if (flag == DELETE || (wantparent && flag != CREATE))
                docache = 0;
        rdonly = MNT_RDONLY;
        if (ndp->ni_nameiop & REMOTE)
                docache = 0;
        rdonly = MNT_RDONLY;
        if (ndp->ni_nameiop & REMOTE)
index f89ad76..d96482a 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ufs_lookup.c        7.25 (Berkeley) %G%
+ *     @(#)ufs_lookup.c        7.26 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -126,9 +126,12 @@ ufs_lookup(vdp, ndp)
                } else if (ndp->ni_isdotdot) {
                        IUNLOCK(pdp);
                        error = vget(vdp);
                } else if (ndp->ni_isdotdot) {
                        IUNLOCK(pdp);
                        error = vget(vdp);
+                       if (!error && lockparent && *ndp->ni_next == '\0')
+                               ILOCK(pdp);
                } else {
                        error = vget(vdp);
                } else {
                        error = vget(vdp);
-                       IUNLOCK(pdp);
+                       if (!lockparent || error || *ndp->ni_next != '\0')
+                               IUNLOCK(pdp);
                }
                /*
                 * Check that the capability number did not change
                }
                /*
                 * Check that the capability number did not change
@@ -137,8 +140,9 @@ ufs_lookup(vdp, ndp)
                if (!error) {
                        if (vpid == vdp->v_id)
                                return (0);
                if (!error) {
                        if (vpid == vdp->v_id)
                                return (0);
-                       else
-                               iput(dp);
+                       iput(dp);
+                       if (lockparent && pdp != dp && *ndp->ni_next == '\0')
+                               IUNLOCK(pdp);
                }
                ILOCK(pdp);
                dp = pdp;
                }
                ILOCK(pdp);
                dp = pdp;
@@ -346,7 +350,7 @@ searchloop:
        /*
         * Insert name into cache (as non-existent) if appropriate.
         */
        /*
         * Insert name into cache (as non-existent) if appropriate.
         */
-       if (ndp->ni_makeentry)
+       if (ndp->ni_makeentry && flag != CREATE)
                cache_enter(ndp);
        return (ENOENT);
 
                cache_enter(ndp);
        return (ENOENT);
 
index f89ad76..d96482a 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ufs_lookup.c        7.25 (Berkeley) %G%
+ *     @(#)ufs_lookup.c        7.26 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
@@ -126,9 +126,12 @@ ufs_lookup(vdp, ndp)
                } else if (ndp->ni_isdotdot) {
                        IUNLOCK(pdp);
                        error = vget(vdp);
                } else if (ndp->ni_isdotdot) {
                        IUNLOCK(pdp);
                        error = vget(vdp);
+                       if (!error && lockparent && *ndp->ni_next == '\0')
+                               ILOCK(pdp);
                } else {
                        error = vget(vdp);
                } else {
                        error = vget(vdp);
-                       IUNLOCK(pdp);
+                       if (!lockparent || error || *ndp->ni_next != '\0')
+                               IUNLOCK(pdp);
                }
                /*
                 * Check that the capability number did not change
                }
                /*
                 * Check that the capability number did not change
@@ -137,8 +140,9 @@ ufs_lookup(vdp, ndp)
                if (!error) {
                        if (vpid == vdp->v_id)
                                return (0);
                if (!error) {
                        if (vpid == vdp->v_id)
                                return (0);
-                       else
-                               iput(dp);
+                       iput(dp);
+                       if (lockparent && pdp != dp && *ndp->ni_next == '\0')
+                               IUNLOCK(pdp);
                }
                ILOCK(pdp);
                dp = pdp;
                }
                ILOCK(pdp);
                dp = pdp;
@@ -346,7 +350,7 @@ searchloop:
        /*
         * Insert name into cache (as non-existent) if appropriate.
         */
        /*
         * Insert name into cache (as non-existent) if appropriate.
         */
-       if (ndp->ni_makeentry)
+       if (ndp->ni_makeentry && flag != CREATE)
                cache_enter(ndp);
        return (ENOENT);
 
                cache_enter(ndp);
        return (ENOENT);