Subject: EJUSTRETURN in VOP_LOOKUP
To: None <tech-kern@netbsd.org>
From: Antti Kantee <pooka@cs.hut.fi>
List: tech-kern
Date: 10/01/2007 17:58:37
--PEIAKu/WMn1b1Hv9
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

I'm planning to change EJUSTRETURN in CREATE/RENAME cases to ENOENT.
Is anyone opposed for any reason worth debating?  EJUSTRETURN is not
exported to userspace, so handling it creates extra trickery in file
system code there.  The change also simplifies some fs code a tiny bit.

-- 
Antti Kantee <pooka@iki.fi>                     Of course he runs NetBSD
http://www.iki.fi/pooka/                          http://www.NetBSD.org/
    "la qualité la plus indispensable du cuisinier est l'exactitude"

--PEIAKu/WMn1b1Hv9
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="ejustenoent.diff"

Index: fs/adosfs/adlookup.c
===================================================================
RCS file: /cvsroot/src/sys/fs/adosfs/adlookup.c,v
retrieving revision 1.9
diff -p -u -r1.9 adlookup.c
--- fs/adosfs/adlookup.c	9 Dec 2006 16:11:50 -0000	1.9
+++ fs/adosfs/adlookup.c	1 Oct 2007 14:44:33 -0000
@@ -208,9 +208,9 @@ adosfs_lookup(v)
 		}
 		cnp->cn_nameiop |= SAVENAME;
 #ifdef ADOSFS_DIAGNOSTIC
-		printf("EJUSTRETURN)");
+		printf("ENOENT)");
 #endif
-		return(EJUSTRETURN);
+		return(ENOENT);
 	}
 	if ((cnp->cn_flags & MAKEENTRY) && nameiop != CREATE)
 		cache_enter(vdp, NULL, cnp);
Index: fs/efs/efs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/efs/efs_vnops.c,v
retrieving revision 1.9
diff -p -u -r1.9 efs_vnops.c
--- fs/efs/efs_vnops.c	24 Sep 2007 00:42:12 -0000	1.9
+++ fs/efs/efs_vnops.c	1 Oct 2007 14:44:34 -0000
@@ -109,7 +109,7 @@ efs_lookup(void *v)
 				if (err)
 					return (err);
 				cnp->cn_flags |= SAVENAME;
-				return (EJUSTRETURN);
+				return (ENOENT);
 			}
 			return (err);
 		}
Index: fs/msdosfs/msdosfs_lookup.c
===================================================================
RCS file: /cvsroot/src/sys/fs/msdosfs/msdosfs_lookup.c,v
retrieving revision 1.12
diff -p -u -r1.12 msdosfs_lookup.c
--- fs/msdosfs/msdosfs_lookup.c	4 Mar 2007 06:02:59 -0000	1.12
+++ fs/msdosfs/msdosfs_lookup.c	1 Oct 2007 14:44:35 -0000
@@ -389,7 +389,7 @@ notfound:
 		 * information cannot be used.
 		 */
 		cnp->cn_flags |= SAVENAME;
-		return (EJUSTRETURN);
+		return (ENOENT);
 	}
 
 #if 0
Index: fs/puffs/puffs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/puffs/puffs_vnops.c,v
retrieving revision 1.101
diff -p -u -r1.101 puffs_vnops.c
--- fs/puffs/puffs_vnops.c	27 Sep 2007 21:44:12 -0000	1.101
+++ fs/puffs/puffs_vnops.c	1 Oct 2007 14:44:36 -0000
@@ -481,12 +481,10 @@ puffs_lookup(void *v)
 			    && cnp->cn_nameiop == CREATE) {
 				error = EROFS;
 
-			/* adjust values if we are creating */
 			} else if ((cnp->cn_flags & ISLASTCN)
 			    && (cnp->cn_nameiop == CREATE
 			      || cnp->cn_nameiop == RENAME)) {
 				cnp->cn_flags |= SAVENAME;
-				error = EJUSTRETURN;
 
 			/* save negative cache entry */
 			} else {
Index: fs/smbfs/smbfs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/smbfs/smbfs_vnops.c,v
retrieving revision 1.59
diff -p -u -r1.59 smbfs_vnops.c
--- fs/smbfs/smbfs_vnops.c	4 Mar 2007 06:03:01 -0000	1.59
+++ fs/smbfs/smbfs_vnops.c	1 Oct 2007 14:44:36 -0000
@@ -1315,7 +1315,7 @@ smbfs_lookup(v)
 				return (error);
 
 			cnp->cn_flags |= SAVENAME;
-			return (EJUSTRETURN);
+			return (ENOENT);
 		}
 
 		/*
Index: fs/tmpfs/tmpfs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/tmpfs/tmpfs_vnops.c,v
retrieving revision 1.39
diff -p -u -r1.39 tmpfs_vnops.c
--- fs/tmpfs/tmpfs_vnops.c	23 Jul 2007 15:41:01 -0000	1.39
+++ fs/tmpfs/tmpfs_vnops.c	1 Oct 2007 14:44:37 -0000
@@ -193,10 +193,8 @@ tmpfs_lookup(void *v)
 				/* Keep the component name in the buffer for
 				 * future uses. */
 				cnp->cn_flags |= SAVENAME;
-
-				error = EJUSTRETURN;
-			} else
-				error = ENOENT;
+			}
+			error = ENOENT;
 		} else {
 			struct tmpfs_node *tnode;
 
Index: fs/udf/udf_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/udf/udf_vnops.c,v
retrieving revision 1.11
diff -p -u -r1.11 udf_vnops.c
--- fs/udf/udf_vnops.c	24 Sep 2007 00:42:15 -0000	1.11
+++ fs/udf/udf_vnops.c	1 Oct 2007 14:44:38 -0000
@@ -565,7 +565,7 @@ udf_lookup(void *v)
 			/*
 			 * UGH, didn't find name. If we're creating or naming
 			 * on the last name this is OK and we ought to return
-			 * EJUSTRETURN if its allowed to be created.
+			 * ENOENT if its allowed to be created.
 			 */
 			error = ENOENT;
 			if (islastcn &&
@@ -577,7 +577,6 @@ udf_lookup(void *v)
 				if (!error) {
 					/* keep the component name */
 					cnp->cn_flags |= SAVENAME;
-					error = EJUSTRETURN;
 				}
 			}
 			/* done */
Index: fs/union/union_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/fs/union/union_vnops.c,v
retrieving revision 1.21
diff -p -u -r1.21 union_vnops.c
--- fs/union/union_vnops.c	29 Jul 2007 13:12:42 -0000	1.21
+++ fs/union/union_vnops.c	1 Oct 2007 14:44:39 -0000
@@ -365,7 +365,7 @@ union_lookup(v)
 			*ap->a_vpp = uppervp;
 			return (uerror);
 		}
-		if (uerror == ENOENT || uerror == EJUSTRETURN) {
+		if (uerror == ENOENT) {
 			if (cnp->cn_flags & ISWHITEOUT) {
 				iswhiteout = 1;
 			} else if (lowerdvp != NULLVP) {
@@ -441,14 +441,14 @@ union_lookup(v)
 	}
 
 	/*
-	 * EJUSTRETURN is used by underlying filesystems to indicate that
+	 * ENOENT is used by underlying filesystems to indicate that
 	 * a directory modification op was started successfully.
 	 * This will only happen in the upper layer, since
 	 * the lower layer only does LOOKUPs.
 	 * If this union is mounted read-only, bounce it now.
 	 */
 
-	if ((uerror == EJUSTRETURN) && (cnp->cn_flags & ISLASTCN) &&
+	if ((uerror == ENOENT) && (cnp->cn_flags & ISLASTCN) &&
 	    (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
 	    ((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME)))
 		uerror = EROFS;
Index: kern/vfs_lookup.c
===================================================================
RCS file: /cvsroot/src/sys/kern/vfs_lookup.c,v
retrieving revision 1.97
diff -p -u -r1.97 vfs_lookup.c
--- kern/vfs_lookup.c	15 Aug 2007 12:07:34 -0000	1.97
+++ kern/vfs_lookup.c	1 Oct 2007 14:44:39 -0000
@@ -720,7 +720,8 @@ unionlookup:
 			goto unionlookup;
 		}
 
-		if (error != EJUSTRETURN)
+		if (error != ENOENT ||
+		    !(cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME))
 			goto bad;
 
 		/*
@@ -728,10 +729,8 @@ unionlookup:
 		 * slashes, and we are not going to create a directory,
 		 * then the name must exist.
 		 */
-		if ((cnp->cn_flags & (REQUIREDIR | CREATEDIR)) == REQUIREDIR) {
-			error = ENOENT;
+		if ((cnp->cn_flags & (REQUIREDIR | CREATEDIR)) == REQUIREDIR)
 			goto bad;
-		}
 
 		/*
 		 * If creating and at end of pathname, then can consider
@@ -972,7 +971,9 @@ relookup(struct vnode *dvp, struct vnode
 		if (*vpp != NULL)
 			panic("leaf `%s' should be empty", cnp->cn_nameptr);
 #endif
-		if (error != EJUSTRETURN)
+
+		if (error != ENOENT ||
+		    !(cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME))
 			goto bad;
 	}
 
Index: miscfs/genfs/layer_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/genfs/layer_vnops.c,v
retrieving revision 1.31
diff -p -u -r1.31 layer_vnops.c
--- miscfs/genfs/layer_vnops.c	16 Apr 2007 08:10:58 -0000	1.31
+++ miscfs/genfs/layer_vnops.c	1 Oct 2007 14:44:40 -0000
@@ -444,7 +444,7 @@ layer_lookup(v)
 	lvp = *ap->a_vpp;
 	*ap->a_vpp = NULL;
 
-	if (error == EJUSTRETURN && (flags & ISLASTCN) &&
+	if (error == ENOENT && (flags & ISLASTCN) &&
 	    (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
 	    (cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME))
 		error = EROFS;
Index: miscfs/umapfs/umap_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/miscfs/umapfs/umap_vnops.c,v
retrieving revision 1.43
diff -p -u -r1.43 umap_vnops.c
--- miscfs/umapfs/umap_vnops.c	9 Dec 2006 16:11:52 -0000	1.43
+++ miscfs/umapfs/umap_vnops.c	1 Oct 2007 14:44:41 -0000
@@ -397,7 +397,7 @@ umap_lookup(v)
 	vp = *ap->a_vpp;
 	*ap->a_vpp = NULL;
 
-	if (error == EJUSTRETURN && (cnf & ISLASTCN) &&
+	if (error == ENOENT && (cnf & ISLASTCN) &&
 	    (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
 	    (cnp->cn_nameiop == CREATE || cnp->cn_nameiop == RENAME))
 		error = EROFS;
Index: nfs/nfs_vnops.c
===================================================================
RCS file: /cvsroot/src/sys/nfs/nfs_vnops.c,v
retrieving revision 1.256
diff -p -u -r1.256 nfs_vnops.c
--- nfs/nfs_vnops.c	9 Jul 2007 21:11:31 -0000	1.256
+++ nfs/nfs_vnops.c	1 Oct 2007 14:44:43 -0000
@@ -913,7 +913,7 @@ dorpc:
 	    (flags & (ISLASTCN|ISDOTDOT)) == ISLASTCN &&
 	    (dvp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
 		cnp->cn_flags |= SAVENAME;
-		return (EJUSTRETURN);
+		return (ENOENT);
 	}
 #endif /* 0 */
 
@@ -1050,7 +1050,6 @@ noentry:
 			if (dvp->v_mount->mnt_flag & MNT_RDONLY) {
 				error = EROFS;
 			} else {
-				error = EJUSTRETURN;
 				cnp->cn_flags |= SAVENAME;
 			}
 		}
Index: ufs/ext2fs/ext2fs_lookup.c
===================================================================
RCS file: /cvsroot/src/sys/ufs/ext2fs/ext2fs_lookup.c,v
retrieving revision 1.52
diff -p -u -r1.52 ext2fs_lookup.c
--- ufs/ext2fs/ext2fs_lookup.c	24 Sep 2007 00:42:15 -0000	1.52
+++ ufs/ext2fs/ext2fs_lookup.c	1 Oct 2007 14:44:44 -0000
@@ -525,7 +525,7 @@ searchloop:
 		 * information cannot be used.
 		 */
 		cnp->cn_flags |= SAVENAME;
-		return (EJUSTRETURN);
+		return (ENOENT);
 	}
 	/*
 	 * Insert name into cache (as non-existent) if appropriate.

--PEIAKu/WMn1b1Hv9--