Commit 625b6d10 authored by Al Viro's avatar Al Viro

namei: pass the struct path to store the result down into path_lookupat()

Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 18d8c860
...@@ -2086,8 +2086,8 @@ static inline int lookup_last(struct nameidata *nd) ...@@ -2086,8 +2086,8 @@ static inline int lookup_last(struct nameidata *nd)
} }
/* Returns 0 and nd will be valid on success; Retuns error, otherwise. */ /* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
static int path_lookupat(int dfd, const struct filename *name, static int path_lookupat(int dfd, const struct filename *name, unsigned flags,
unsigned int flags, struct nameidata *nd) struct nameidata *nd, struct path *path)
{ {
const char *s = path_init(dfd, name, flags, nd); const char *s = path_init(dfd, name, flags, nd);
int err; int err;
...@@ -2108,27 +2108,31 @@ static int path_lookupat(int dfd, const struct filename *name, ...@@ -2108,27 +2108,31 @@ static int path_lookupat(int dfd, const struct filename *name,
if (!err && nd->flags & LOOKUP_DIRECTORY) if (!err && nd->flags & LOOKUP_DIRECTORY)
if (!d_can_lookup(nd->path.dentry)) if (!d_can_lookup(nd->path.dentry))
err = -ENOTDIR; err = -ENOTDIR;
if (err) if (!err) {
terminate_walk(nd); *path = nd->path;
nd->path.mnt = NULL;
nd->path.dentry = NULL;
}
terminate_walk(nd);
path_cleanup(nd); path_cleanup(nd);
return err; return err;
} }
static int filename_lookup(int dfd, struct filename *name, static int filename_lookup(int dfd, struct filename *name, unsigned flags,
unsigned int flags, struct nameidata *nd) struct nameidata *nd, struct path *path)
{ {
int retval; int retval;
struct nameidata *saved_nd = set_nameidata(nd); struct nameidata *saved_nd = set_nameidata(nd);
retval = path_lookupat(dfd, name, flags | LOOKUP_RCU, nd); retval = path_lookupat(dfd, name, flags | LOOKUP_RCU, nd, path);
if (unlikely(retval == -ECHILD)) if (unlikely(retval == -ECHILD))
retval = path_lookupat(dfd, name, flags, nd); retval = path_lookupat(dfd, name, flags, nd, path);
if (unlikely(retval == -ESTALE)) if (unlikely(retval == -ESTALE))
retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd); retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL,
nd, path);
if (likely(!retval)) if (likely(!retval))
audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT); audit_inode(name, path->dentry, flags & LOOKUP_PARENT);
restore_nameidata(saved_nd); restore_nameidata(saved_nd);
return retval; return retval;
} }
...@@ -2209,10 +2213,8 @@ int kern_path(const char *name, unsigned int flags, struct path *path) ...@@ -2209,10 +2213,8 @@ int kern_path(const char *name, unsigned int flags, struct path *path)
int res = PTR_ERR(filename); int res = PTR_ERR(filename);
if (!IS_ERR(filename)) { if (!IS_ERR(filename)) {
res = filename_lookup(AT_FDCWD, filename, flags, &nd); res = filename_lookup(AT_FDCWD, filename, flags, &nd, path);
putname(filename); putname(filename);
if (!res)
*path = nd.path;
} }
return res; return res;
} }
...@@ -2241,9 +2243,7 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt, ...@@ -2241,9 +2243,7 @@ int vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt,
nd.root.dentry = dentry; nd.root.dentry = dentry;
nd.root.mnt = mnt; nd.root.mnt = mnt;
err = filename_lookup(AT_FDCWD, filename, err = filename_lookup(AT_FDCWD, filename,
flags | LOOKUP_ROOT, &nd); flags | LOOKUP_ROOT, &nd, path);
if (!err)
*path = nd.path;
putname(filename); putname(filename);
} }
return err; return err;
...@@ -2311,10 +2311,8 @@ int user_path_at_empty(int dfd, const char __user *name, unsigned flags, ...@@ -2311,10 +2311,8 @@ int user_path_at_empty(int dfd, const char __user *name, unsigned flags,
BUG_ON(flags & LOOKUP_PARENT); BUG_ON(flags & LOOKUP_PARENT);
err = filename_lookup(dfd, tmp, flags, &nd); err = filename_lookup(dfd, tmp, flags, &nd, path);
putname(tmp); putname(tmp);
if (!err)
*path = nd.path;
} }
return err; return err;
} }
...@@ -3261,44 +3259,42 @@ static int do_tmpfile(int dfd, struct filename *pathname, ...@@ -3261,44 +3259,42 @@ static int do_tmpfile(int dfd, struct filename *pathname,
struct file *file, int *opened) struct file *file, int *opened)
{ {
static const struct qstr name = QSTR_INIT("/", 1); static const struct qstr name = QSTR_INIT("/", 1);
struct dentry *dentry, *child; struct dentry *child;
struct inode *dir; struct inode *dir;
struct path path;
int error = path_lookupat(dfd, pathname, int error = path_lookupat(dfd, pathname,
flags | LOOKUP_DIRECTORY, nd); flags | LOOKUP_DIRECTORY, nd, &path);
if (unlikely(error)) if (unlikely(error))
return error; return error;
error = mnt_want_write(nd->path.mnt); error = mnt_want_write(path.mnt);
if (unlikely(error)) if (unlikely(error))
goto out; goto out;
dir = path.dentry->d_inode;
/* we want directory to be writable */ /* we want directory to be writable */
error = inode_permission(nd->inode, MAY_WRITE | MAY_EXEC); error = inode_permission(dir, MAY_WRITE | MAY_EXEC);
if (error) if (error)
goto out2; goto out2;
dentry = nd->path.dentry;
dir = dentry->d_inode;
if (!dir->i_op->tmpfile) { if (!dir->i_op->tmpfile) {
error = -EOPNOTSUPP; error = -EOPNOTSUPP;
goto out2; goto out2;
} }
child = d_alloc(dentry, &name); child = d_alloc(path.dentry, &name);
if (unlikely(!child)) { if (unlikely(!child)) {
error = -ENOMEM; error = -ENOMEM;
goto out2; goto out2;
} }
nd->flags &= ~LOOKUP_DIRECTORY; dput(path.dentry);
nd->flags |= op->intent; path.dentry = child;
dput(nd->path.dentry); error = dir->i_op->tmpfile(dir, child, op->mode);
nd->path.dentry = child;
error = dir->i_op->tmpfile(dir, nd->path.dentry, op->mode);
if (error) if (error)
goto out2; goto out2;
audit_inode(pathname, nd->path.dentry, 0); audit_inode(pathname, child, 0);
/* Don't check for other permissions, the inode was just created */ /* Don't check for other permissions, the inode was just created */
error = may_open(&nd->path, MAY_OPEN, op->open_flag); error = may_open(&path, MAY_OPEN, op->open_flag);
if (error) if (error)
goto out2; goto out2;
file->f_path.mnt = nd->path.mnt; file->f_path.mnt = path.mnt;
error = finish_open(file, nd->path.dentry, NULL, opened); error = finish_open(file, child, NULL, opened);
if (error) if (error)
goto out2; goto out2;
error = open_check_o_direct(file); error = open_check_o_direct(file);
...@@ -3311,9 +3307,9 @@ static int do_tmpfile(int dfd, struct filename *pathname, ...@@ -3311,9 +3307,9 @@ static int do_tmpfile(int dfd, struct filename *pathname,
spin_unlock(&inode->i_lock); spin_unlock(&inode->i_lock);
} }
out2: out2:
mnt_drop_write(nd->path.mnt); mnt_drop_write(path.mnt);
out: out:
path_put(&nd->path); path_put(&path);
return error; return error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment