diff mbox series

[3/4] fs: pass a nameidata into filename_lookup

Message ID 20200926092051.115577-4-hch@lst.de
State New
Headers show
Series [1/4] fs: remove the unused fs_lookup_param function | expand

Commit Message

Christoph Hellwig Sept. 26, 2020, 9:20 a.m. UTC
This allows keeping the LOOKUP_ROOT case for vfs_path_lookup entirely
out of the normal fast path.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 fs/namei.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)

Comments

Al Viro Sept. 26, 2020, 2:49 p.m. UTC | #1
On Sat, Sep 26, 2020 at 11:20:50AM +0200, Christoph Hellwig wrote:
> This allows keeping the LOOKUP_ROOT case for vfs_path_lookup entirely
> out of the normal fast path.

... saving you all of a if (unlikely(root)) {....} on it.  Not worth
it, and
> +	struct nameidata nd;
> +
> +	return filename_lookup(AT_FDCWD, getname_kernel(name), flags, path,
> +			       &nd);

is something I would rather avoid on the general principles - better have
set_nameidata()/restore_nameidata() done always to a local variable.  Makes
for somewhat easier analysis.

IOW, NAK
diff mbox series

Patch

diff --git a/fs/namei.c b/fs/namei.c
index 7963f97a130442..90e1cb008ae449 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2352,22 +2352,18 @@  static int path_lookupat(struct nameidata *nd, unsigned flags, struct path *path
 }
 
 static int filename_lookup(int dfd, struct filename *name, unsigned flags,
-		    struct path *path, struct path *root)
+		    struct path *path, struct nameidata *nd)
 {
 	int retval;
-	struct nameidata nd;
+
 	if (IS_ERR(name))
 		return PTR_ERR(name);
-	if (unlikely(root)) {
-		nd.root = *root;
-		flags |= LOOKUP_ROOT;
-	}
-	set_nameidata(&nd, dfd, name);
-	retval = path_lookupat(&nd, flags | LOOKUP_RCU, path);
+	set_nameidata(nd, dfd, name);
+	retval = path_lookupat(nd, flags | LOOKUP_RCU, path);
 	if (unlikely(retval == -ECHILD))
-		retval = path_lookupat(&nd, flags, path);
+		retval = path_lookupat(nd, flags, path);
 	if (unlikely(retval == -ESTALE))
-		retval = path_lookupat(&nd, flags | LOOKUP_REVAL, path);
+		retval = path_lookupat(nd, flags | LOOKUP_REVAL, path);
 
 	if (likely(!retval))
 		audit_inode(name, path->dentry,
@@ -2450,8 +2446,10 @@  struct dentry *kern_path_locked(const char *name, struct path *path)
 
 int kern_path(const char *name, unsigned int flags, struct path *path)
 {
-	return filename_lookup(AT_FDCWD, getname_kernel(name),
-			       flags, path, NULL);
+	struct nameidata nd;
+
+	return filename_lookup(AT_FDCWD, getname_kernel(name), flags, path,
+			       &nd);
 }
 EXPORT_SYMBOL(kern_path);
 
@@ -2467,10 +2465,12 @@  int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt,
 		    const char *name, unsigned int flags,
 		    struct path *path)
 {
-	struct path root = {.mnt = mnt, .dentry = dentry};
-	/* the first argument of filename_lookup() is ignored with root */
+	struct nameidata nd;
+
+	nd.root.mnt = mnt;
+	nd.root.dentry = dentry;
 	return filename_lookup(AT_FDCWD, getname_kernel(name),
-			       flags , path, &root);
+			       flags | LOOKUP_ROOT, path, &nd);
 }
 EXPORT_SYMBOL(vfs_path_lookup);
 
@@ -2643,8 +2643,10 @@  int path_pts(struct path *path)
 int user_path_at_empty(int dfd, const char __user *name, unsigned flags,
 		 struct path *path, int *empty)
 {
+	struct nameidata nd;
+
 	return filename_lookup(dfd, getname_flags(name, flags, empty),
-			       flags, path, NULL);
+			       flags, path, &nd);
 }
 EXPORT_SYMBOL(user_path_at_empty);