Skip to contentSkip to conversation

New mode for path_lookup (V1)

RFC PATCH In review Josef Sipek 3 participants 5 messages Apr 30, 2007 – May 4, 2007 VFS

lore
Share & tools
lore
#0 lore raw

cover New mode for path_lookup (V1)

Stackable file systems frequently need to lookup paths or path components starting from an arbitrary point in the namespace (identified by a dentry and a vfsmount). Currently, such file systems use lookup_one_len, which is frowned upon [1] as it does not pass the lookup intent along; not passing a lookup intent, for example, can trigger BUG_ON's when stacking on top of NFSv4.

The following patch introduces a new mode to path_lookup to allow lookup to start from an arbitrary point in the namespace. This approach has been suggested by Christoph Hellwig at the Linux Storage & Filesystem workshop in February of this year.

One indicates that the lookup should be relative to a dentry-vfsmnt pair by using the LOOKUP_ONE flag. For example, the following snippet of code, looks up "pathcomponent" in a directory pointed to by parent_{dentry,vfsmnt}:

nd.dentry = parent_dentry;
nd.mnt = parent_vfsmnt;

err = path_lookup("pathcomponent", LOOKUP_ONE, &nd);

if (!err) {
	/* exits */

	...

	/* once done, release the references */
	path_release(&nd);
} else if (err == -ENOENT) {
	/* doesn't exits */
} else {
	/* other error */
}

VFS functions such as lookup_create can be used on the nameidata structure to pass the create intent to the file system.

Currently, there is no easy way to pass the LOOKUP_OPEN intent. The proper way would be to call open_namei.

We'd like to get comments about what's necessary to make stackable file systems do lookups right - this includes potential changes to open_namei.

Josef 'Jeff' Sipek.

[1] http://marc.info/?l=linux-kernel&m=117343337823760&w=2

#1 lore raw

PATCH 1/1 fs: add 4th case to do_path_lookup

fs/namei.c +4 -0
index 2995fba..1516a9b 100644
@@ -1125,6 +1125,10 @@ static int fastcall do_path_lookup(int dfd, const char *name,
 		nd->mnt = mntget(fs->rootmnt);
 		nd->dentry = dget(fs->root);
 		read_unlock(&fs->lock);
+	} else if (flags & LOOKUP_ONE) {
+		/* nd->mnt and nd->dentry already set, just grab references */
+		mntget(nd->mnt);
+		dget(nd->dentry);
 	} else if (dfd == AT_FDCWD) {
 		read_lock(&fs->lock);
 		nd->mnt = mntget(fs->pwdmnt);
include/linux/namei.h +2 -0
index 92b422b..aa89d97 100644
@@ -48,6 +48,7 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
  *  - internal "there are more path compnents" flag
  *  - locked when lookup done with dcache_lock held
  *  - dentry cache is untrusted; force a real lookup
+ *  - lookup path from given dentry/vfsmount pair
  */
 #define LOOKUP_FOLLOW		 1
 #define LOOKUP_DIRECTORY	 2
@@ -55,6 +56,7 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
 #define LOOKUP_PARENT		16
 #define LOOKUP_NOALT		32
 #define LOOKUP_REVAL		64
+#define LOOKUP_ONE	       128
 /*
  * Intent data
  */
#2 lore raw

Re: [PATCH 1/1] fs: add 4th case to do_path_lookup

Quoted 30 lines · On Sun, 29 Apr 2007 23:30:12 -0400 Josef Sipek <[email protected]> wrote:
fs/namei.c +4 -0
index 2995fba..1516a9b 100644
@@ -1125,6 +1125,10 @@ static int fastcall do_path_lookup(int dfd, const char *name,
 		nd->mnt = mntget(fs->rootmnt);
 		nd->dentry = dget(fs->root);
 		read_unlock(&fs->lock);
+	} else if (flags & LOOKUP_ONE) {
+		/* nd->mnt and nd->dentry already set, just grab references */
+		mntget(nd->mnt);
+		dget(nd->dentry);
 	} else if (dfd == AT_FDCWD) {
 		read_lock(&fs->lock);
 		nd->mnt = mntget(fs->pwdmnt);
include/linux/namei.h +1 -0
index 92b422b..aa89d97 100644
@@ -48,6 +48,7 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
  *  - internal "there are more path compnents" flag
  *  - locked when lookup done with dcache_lock held
  *  - dentry cache is untrusted; force a real lookup
+ *  - lookup path from given dentry/vfsmount pair
  */
 #define LOOKUP_FOLLOW		 1
 #define LOOKUP_DIRECTORY	 2

include/linux/namei.h enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND}; · line 59

Quoted 4 lines
include/linux/namei.h +1 -0
@@ -55,6 +56,7 @@ enum {LAST_NORM, LAST_ROOT, LAST_DOT, LAST_DOTDOT, LAST_BIND};
 #define LOOKUP_PARENT		16
 #define LOOKUP_NOALT		32
 #define LOOKUP_REVAL		64
+#define LOOKUP_ONE	       128

Well the patch passes my too-small-to-care-about test ;)

Unless someone objects I'd suggest that you add it to the unionfs tree.

#3 lore raw

Re: [PATCH 1/1] fs: add 4th case to do_path_lookup

sorry, I proposed Jeff a reply long ago but haven't done yet.

Quoted 14 lines · Andrew Morton

fs/namei.c static int fastcall do_path_lookup(int dfd, const char *name, · line 1134

Quoted 11 lines
fs/namei.c +4 -0
@@ -1125,6 +1125,10 @@ static int fastcall do_path_lookup(int dfd, const char *name,
 		nd->mnt = mntget(fs->rootmnt);
 		nd->dentry = dget(fs->root);
 		read_unlock(&fs->lock);
+	} else if (flags & LOOKUP_ONE) {
+		/* nd->mnt and nd->dentry already set, just grab references */
+		mntget(nd->mnt);
+		dget(nd->dentry);
 	} else if (dfd == AT_FDCWD) {
 		read_lock(&fs->lock);
 		nd->mnt = mntget(fs->pwdmnt);

Well the patch passes my too-small-to-care-about test ;)

Quoted 1 line

Unless someone objects I'd suggest that you add it to the unionfs tree.

The code is obviously correct. There is one little thing that bothers me, and that's that nd was purely an output paramter to path_lookup and do_path_lookup, and no it's an input paramter for the least used case. It might make sense to just a simple helper ala:

static int path_component_lookup(struct dentry *dentry, struct vfsmount *mnt,
const char *name, unsigned int flags, struct nameidata *nd)

{
	int retval;

	nd->last_type = LAST_ROOT;
	nd->flags = flags;
	nd->mnt = mntget(mnt);
	nd->dentry = dget(dentry);
	nd->depth = 0;

	retval = path_walk(name, nd);
	if (unlikely(!retval && !audit_dummy_context() &&
	             nd->dentry && nd->dentry->d_inode))
		audit_inode(name, nd->dentry->d_inode);

	return retval;

}

instead.

#4 lore raw

Re: [PATCH 1/1] fs: add 4th case to do_path_lookup

Oh and btw, net/sunrpc/rpc_pipe.c:rpc_lookup_parent() and fs/nfsctl.c:do_open() should be switched to the new code, at which point the path_walk() export can go.