summaryrefslogtreecommitdiffstats
path: root/fs/namei.c
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2020-02-26 23:50:13 +0100
committerAl Viro <viro@zeniv.linux.org.uk>2020-04-02 07:09:21 +0200
commit7ef482fa65513b18eed05a5c5f00413aad137810 (patch)
tree3e96c7120638e473ba1296121fe4257184851ecd /fs/namei.c
parentfollow_dotdot(): be lazy about changing nd->path (diff)
downloadlinux-7ef482fa65513b18eed05a5c5f00413aad137810.tar.xz
linux-7ef482fa65513b18eed05a5c5f00413aad137810.zip
helper for mount rootwards traversal
The loops in follow_dotdot{_rcu()} are doing the same thing: we have a mount and we want to find out how far up the chain of mounts do we need to go. We follow the chain of mount until we find one that is not directly overmounting the root of another mount. If such a mount is found, we want the location it's mounted upon. If we run out of chain (i.e. get to a mount that is not mounted on anything else) or run into process' root, we report failure. On success, we want (in RCU case) d_seq of resulting location sampled or (in non-RCU case) references to that location acquired. This commit introduces such primitive for RCU case and switches follow_dotdot_rcu() to it; non-RCU case will be go in the next commit. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'fs/namei.c')
-rw-r--r--fs/namei.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/fs/namei.c b/fs/namei.c
index 9cfb7096e307..6529c2506491 100644
--- a/fs/namei.c
+++ b/fs/namei.c
@@ -1134,6 +1134,26 @@ int follow_up(struct path *path)
}
EXPORT_SYMBOL(follow_up);
+static bool choose_mountpoint_rcu(struct mount *m, const struct path *root,
+ struct path *path, unsigned *seqp)
+{
+ while (mnt_has_parent(m)) {
+ struct dentry *mountpoint = m->mnt_mountpoint;
+
+ m = m->mnt_parent;
+ if (unlikely(root->dentry == mountpoint &&
+ root->mnt == &m->mnt))
+ break;
+ if (mountpoint != m->mnt.mnt_root) {
+ path->mnt = &m->mnt;
+ path->dentry = mountpoint;
+ *seqp = read_seqcount_begin(&mountpoint->d_seq);
+ return true;
+ }
+ }
+ return false;
+}
+
/*
* Perform an automount
* - return -EISDIR to tell follow_managed() to stop and return the path we
@@ -1696,23 +1716,11 @@ static struct dentry *follow_dotdot_rcu(struct nameidata *nd,
if (path_equal(&nd->path, &nd->root))
goto in_root;
if (unlikely(nd->path.dentry == nd->path.mnt->mnt_root)) {
- struct path path = nd->path;
+ struct path path;
unsigned seq;
-
- while (1) {
- struct mount *mnt = real_mount(path.mnt);
- struct mount *mparent = mnt->mnt_parent;
- struct dentry *mountpoint = mnt->mnt_mountpoint;
- seq = read_seqcount_begin(&mountpoint->d_seq);
- if (&mparent->mnt == path.mnt)
- goto in_root;
- path.dentry = mountpoint;
- path.mnt = &mparent->mnt;
- if (path_equal(&path, &nd->root))
- goto in_root;
- if (path.dentry != path.mnt->mnt_root)
- break;
- }
+ if (!choose_mountpoint_rcu(real_mount(nd->path.mnt),
+ &nd->root, &path, &seq))
+ goto in_root;
if (unlikely(nd->flags & LOOKUP_NO_XDEV))
return ERR_PTR(-ECHILD);
nd->path = path;