[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200301215240.873899-41-viro@ZenIV.linux.org.uk>
Date: Sun, 1 Mar 2020 21:52:26 +0000
From: Al Viro <viro@...IV.linux.org.uk>
To: linux-fsdevel@...r.kernel.org
Cc: linux-kernel@...r.kernel.org,
Linus Torvalds <torvalds@...ux-foundation.org>
Subject: [RFC][PATCH v3 41/55] follow_dotdot(): expand the call of path_parent_directory()
From: Al Viro <viro@...iv.linux.org.uk>
... and move the definition of path_parent_directory() towards
the last remaining user.
Signed-off-by: Al Viro <viro@...iv.linux.org.uk>
---
fs/namei.c | 42 ++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)
diff --git a/fs/namei.c b/fs/namei.c
index 8e588632e03a..9b66cd00edcb 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1440,21 +1440,8 @@ static void follow_mount(struct path *path)
}
}
-static struct dentry *path_parent_directory(struct path *path)
-{
- /* rare case of legitimate dget_parent()... */
- struct dentry *parent = dget_parent(path->dentry);
-
- if (unlikely(!path_connected(path->mnt, parent))) {
- dput(parent);
- parent = NULL;
- }
- return parent;
-}
-
static int follow_dotdot(struct nameidata *nd)
{
- struct dentry *parent;
while (1) {
if (path_equal(&nd->path, &nd->root)) {
if (unlikely(nd->flags & LOOKUP_BENEATH))
@@ -1462,9 +1449,13 @@ static int follow_dotdot(struct nameidata *nd)
break;
}
if (nd->path.dentry != nd->path.mnt->mnt_root) {
- parent = path_parent_directory(&nd->path);
- if (!parent)
+ /* rare case of legitimate dget_parent()... */
+ struct dentry *parent = dget_parent(nd->path.dentry);
+
+ if (unlikely(!path_connected(nd->path.mnt, parent))) {
+ dput(parent);
return -ENOENT;
+ }
dput(nd->path.dentry);
nd->path.dentry = parent;
break;
@@ -2600,6 +2591,17 @@ struct dentry *lookup_positive_unlocked(const char *name,
EXPORT_SYMBOL(lookup_positive_unlocked);
#ifdef CONFIG_UNIX98_PTYS
+static int path_parent_directory(struct path *path)
+{
+ struct dentry *old = path->dentry;
+ /* rare case of legitimate dget_parent()... */
+ path->dentry = dget_parent(path->dentry);
+ dput(old);
+ if (unlikely(!path_connected(path->mnt, path->dentry)))
+ return -ENOENT;
+ return 0;
+}
+
int path_pts(struct path *path)
{
/* Find something mounted on "pts" in the same directory as
@@ -2607,13 +2609,13 @@ int path_pts(struct path *path)
*/
struct dentry *child, *parent;
struct qstr this;
+ int ret;
- parent = path_parent_directory(path);
- if (!parent)
- return -ENOENT;
+ ret = path_parent_directory(path);
+ if (ret)
+ return ret;
- dput(path->dentry);
- path->dentry = parent;
+ parent = path->dentry;
this.name = "pts";
this.len = 3;
child = d_hash_and_lookup(parent, &this);
--
2.11.0
Powered by blists - more mailing lists