diff options
author | Al Viro <viro@zeniv.linux.org.uk> | 2021-04-02 04:28:03 +0200 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2021-04-07 19:57:16 +0200 |
commit | 06422964c8820233e9abd4ab8c6846e2b881b0b7 (patch) | |
tree | a9248ba6065d2b6a2cef7033a417ab141a3c51ba /fs/namei.c | |
parent | take LOOKUP_{ROOT,ROOT_GRABBED,JUMPED} out of LOOKUP_... space (diff) | |
download | linux-06422964c8820233e9abd4ab8c6846e2b881b0b7.tar.xz linux-06422964c8820233e9abd4ab8c6846e2b881b0b7.zip |
teach set_nameidata() to handle setting the root as well
That way we don't need the callers to mess with manually setting any fields
of nameidata instances. Old set_nameidata() gets renamed (__set_nameidata()),
new becomes an inlined helper that takes a struct path pointer and deals
with setting nd->root and putting ND_ROOT_PRESET in nd->state when new
argument is non-NULL.
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/namei.c')
-rw-r--r-- | fs/namei.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/fs/namei.c b/fs/namei.c index 622b9f15bf1c..40ffb249aa7f 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -577,7 +577,7 @@ struct nameidata { #define ND_ROOT_GRABBED 2 #define ND_JUMPED 4 -static void set_nameidata(struct nameidata *p, int dfd, struct filename *name) +static void __set_nameidata(struct nameidata *p, int dfd, struct filename *name) { struct nameidata *old = current->nameidata; p->stack = p->internal; @@ -587,10 +587,20 @@ static void set_nameidata(struct nameidata *p, int dfd, struct filename *name) p->path.dentry = NULL; p->total_link_count = old ? old->total_link_count : 0; p->saved = old; - p->state = 0; current->nameidata = p; } +static inline void set_nameidata(struct nameidata *p, int dfd, struct filename *name, + const struct path *root) +{ + __set_nameidata(p, dfd, name); + p->state = 0; + if (unlikely(root)) { + p->state = ND_ROOT_PRESET; + p->root = *root; + } +} + static void restore_nameidata(void) { struct nameidata *now = current->nameidata, *old = now->saved; @@ -2454,11 +2464,7 @@ int filename_lookup(int dfd, struct filename *name, unsigned flags, struct nameidata nd; if (IS_ERR(name)) return PTR_ERR(name); - set_nameidata(&nd, dfd, name); - if (unlikely(root)) { - nd.root = *root; - nd.state = ND_ROOT_PRESET; - } + set_nameidata(&nd, dfd, name, root); retval = path_lookupat(&nd, flags | LOOKUP_RCU, path); if (unlikely(retval == -ECHILD)) retval = path_lookupat(&nd, flags, path); @@ -2499,7 +2505,7 @@ static struct filename *filename_parentat(int dfd, struct filename *name, if (IS_ERR(name)) return name; - set_nameidata(&nd, dfd, name); + set_nameidata(&nd, dfd, name, NULL); retval = path_parentat(&nd, flags | LOOKUP_RCU, parent); if (unlikely(retval == -ECHILD)) retval = path_parentat(&nd, flags, parent); @@ -3530,7 +3536,7 @@ struct file *do_filp_open(int dfd, struct filename *pathname, int flags = op->lookup_flags; struct file *filp; - set_nameidata(&nd, dfd, pathname); + set_nameidata(&nd, dfd, pathname, NULL); filp = path_openat(&nd, op, flags | LOOKUP_RCU); if (unlikely(filp == ERR_PTR(-ECHILD))) filp = path_openat(&nd, op, flags); @@ -3555,9 +3561,7 @@ struct file *do_file_open_root(const struct path *root, if (IS_ERR(filename)) return ERR_CAST(filename); - set_nameidata(&nd, -1, filename); - nd.root = *root; - nd.state = ND_ROOT_PRESET; + set_nameidata(&nd, -1, filename, root); file = path_openat(&nd, op, flags | LOOKUP_RCU); if (unlikely(file == ERR_PTR(-ECHILD))) file = path_openat(&nd, op, flags); |