[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1431555975-25997-12-git-send-email-viro@ZenIV.linux.org.uk>
Date: Wed, 13 May 2015 23:26:06 +0100
From: Al Viro <viro@...IV.linux.org.uk>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: Neil Brown <neilb@...e.de>, Christoph Hellwig <hch@...radead.org>,
linux-kernel@...r.kernel.org, linux-fsdevel@...r.kernel.org
Subject: [PATCH 12/21] namei: shift nameidata down into filename_parentat()
From: Al Viro <viro@...iv.linux.org.uk>
Signed-off-by: Al Viro <viro@...iv.linux.org.uk>
---
fs/namei.c | 84 ++++++++++++++++++++++++++++++++------------------------------
1 file changed, 43 insertions(+), 41 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c
index 6607a05..dbd1a34 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -2144,7 +2144,8 @@ static int filename_lookup(int dfd, struct filename *name, unsigned flags,
/* Returns 0 and nd will be valid on success; Retuns error, otherwise. */
static int path_parentat(int dfd, const struct filename *name,
- unsigned int flags, struct nameidata *nd)
+ unsigned int flags, struct nameidata *nd,
+ struct path *parent)
{
const char *s = path_init(dfd, name, flags, nd);
int err;
@@ -2153,26 +2154,34 @@ static int path_parentat(int dfd, const struct filename *name,
err = link_path_walk(s, nd);
if (!err)
err = complete_walk(nd);
- if (err)
- terminate_walk(nd);
+ if (!err) {
+ *parent = nd->path;
+ nd->path.mnt = NULL;
+ nd->path.dentry = NULL;
+ }
+ terminate_walk(nd);
path_cleanup(nd);
return err;
}
static int filename_parentat(int dfd, struct filename *name,
- unsigned int flags, struct nameidata *nd)
+ unsigned int flags, struct path *parent,
+ struct qstr *last, int *type)
{
int retval;
- struct nameidata *saved_nd = set_nameidata(nd);
+ struct nameidata nd, *saved_nd = set_nameidata(&nd);
- retval = path_parentat(dfd, name, flags | LOOKUP_RCU, nd);
+ retval = path_parentat(dfd, name, flags | LOOKUP_RCU, &nd, parent);
if (unlikely(retval == -ECHILD))
- retval = path_parentat(dfd, name, flags, nd);
+ retval = path_parentat(dfd, name, flags, &nd, parent);
if (unlikely(retval == -ESTALE))
- retval = path_parentat(dfd, name, flags | LOOKUP_REVAL, nd);
-
- if (likely(!retval))
- audit_inode(name, nd->path.dentry, LOOKUP_PARENT);
+ retval = path_parentat(dfd, name, flags | LOOKUP_REVAL,
+ &nd, parent);
+ if (likely(!retval)) {
+ *last = nd.last;
+ *type = nd.last_type;
+ audit_inode(name, parent->dentry, LOOKUP_PARENT);
+ }
restore_nameidata(saved_nd);
return retval;
}
@@ -2181,31 +2190,30 @@ static int filename_parentat(int dfd, struct filename *name,
struct dentry *kern_path_locked(const char *name, struct path *path)
{
struct filename *filename = getname_kernel(name);
- struct nameidata nd;
+ struct qstr last;
+ int type;
struct dentry *d;
int err;
if (IS_ERR(filename))
return ERR_CAST(filename);
- err = filename_parentat(AT_FDCWD, filename, 0, &nd);
+ err = filename_parentat(AT_FDCWD, filename, 0, path, &last, &type);
if (err) {
d = ERR_PTR(err);
goto out;
}
- if (nd.last_type != LAST_NORM) {
- path_put(&nd.path);
+ if (type != LAST_NORM) {
+ path_put(path);
d = ERR_PTR(-EINVAL);
goto out;
}
- mutex_lock_nested(&nd.path.dentry->d_inode->i_mutex, I_MUTEX_PARENT);
- d = __lookup_hash(&nd.last, nd.path.dentry, 0);
+ mutex_lock_nested(&path->dentry->d_inode->i_mutex, I_MUTEX_PARENT);
+ d = __lookup_hash(&last, path->dentry, 0);
if (IS_ERR(d)) {
- mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
- path_put(&nd.path);
- goto out;
+ mutex_unlock(&path->dentry->d_inode->i_mutex);
+ path_put(path);
}
- *path = nd.path;
out:
putname(filename);
return d;
@@ -2315,7 +2323,6 @@ user_path_parent(int dfd, const char __user *path,
int *type,
unsigned int flags)
{
- struct nameidata nd;
struct filename *s = getname(path);
int error;
@@ -2325,15 +2332,11 @@ user_path_parent(int dfd, const char __user *path,
if (IS_ERR(s))
return s;
- error = filename_parentat(dfd, s, flags, &nd);
+ error = filename_parentat(dfd, s, flags, parent, last, type);
if (error) {
putname(s);
- return ERR_PTR(error);
+ s = ERR_PTR(error);
}
- *parent = nd.path;
- *last = nd.last;
- *type = nd.last_type;
-
return s;
}
@@ -3392,7 +3395,8 @@ static struct dentry *filename_create(int dfd, struct filename *name,
struct path *path, unsigned int lookup_flags)
{
struct dentry *dentry = ERR_PTR(-EEXIST);
- struct nameidata nd;
+ struct qstr last;
+ int type;
int err2;
int error;
bool is_dir = (lookup_flags & LOOKUP_DIRECTORY);
@@ -3403,7 +3407,7 @@ static struct dentry *filename_create(int dfd, struct filename *name,
*/
lookup_flags &= LOOKUP_REVAL;
- error = filename_parentat(dfd, name, lookup_flags, &nd);
+ error = filename_parentat(dfd, name, lookup_flags, path, &last, &type);
if (error)
return ERR_PTR(error);
@@ -3411,18 +3415,17 @@ static struct dentry *filename_create(int dfd, struct filename *name,
* Yucky last component or no last component at all?
* (foo/., foo/.., /////)
*/
- if (nd.last_type != LAST_NORM)
+ if (type != LAST_NORM)
goto out;
- nd.flags &= ~LOOKUP_PARENT;
- nd.flags |= LOOKUP_CREATE | LOOKUP_EXCL;
/* don't fail immediately if it's r/o, at least try to report other errors */
- err2 = mnt_want_write(nd.path.mnt);
+ err2 = mnt_want_write(path->mnt);
/*
* Do the final lookup.
*/
- mutex_lock_nested(&nd.path.dentry->d_inode->i_mutex, I_MUTEX_PARENT);
- dentry = __lookup_hash(&nd.last, nd.path.dentry, nd.flags);
+ lookup_flags |= LOOKUP_CREATE | LOOKUP_EXCL;
+ mutex_lock_nested(&path->dentry->d_inode->i_mutex, I_MUTEX_PARENT);
+ dentry = __lookup_hash(&last, path->dentry, lookup_flags);
if (IS_ERR(dentry))
goto unlock;
@@ -3436,7 +3439,7 @@ static struct dentry *filename_create(int dfd, struct filename *name,
* all is fine. Let's be bastards - you had / on the end, you've
* been asking for (non-existent) directory. -ENOENT for you.
*/
- if (unlikely(!is_dir && nd.last.name[nd.last.len])) {
+ if (unlikely(!is_dir && last.name[last.len])) {
error = -ENOENT;
goto fail;
}
@@ -3444,17 +3447,16 @@ static struct dentry *filename_create(int dfd, struct filename *name,
error = err2;
goto fail;
}
- *path = nd.path;
return dentry;
fail:
dput(dentry);
dentry = ERR_PTR(error);
unlock:
- mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
+ mutex_unlock(&path->dentry->d_inode->i_mutex);
if (!err2)
- mnt_drop_write(nd.path.mnt);
+ mnt_drop_write(path->mnt);
out:
- path_put(&nd.path);
+ path_put(path);
return dentry;
}
--
2.1.4
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists