Skip to content

Commit 7ef482f

Browse files
author
Al Viro
committed
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 <[email protected]>
1 parent 165200d commit 7ef482f

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

fs/namei.c

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,26 @@ int follow_up(struct path *path)
11341134
}
11351135
EXPORT_SYMBOL(follow_up);
11361136

1137+
static bool choose_mountpoint_rcu(struct mount *m, const struct path *root,
1138+
struct path *path, unsigned *seqp)
1139+
{
1140+
while (mnt_has_parent(m)) {
1141+
struct dentry *mountpoint = m->mnt_mountpoint;
1142+
1143+
m = m->mnt_parent;
1144+
if (unlikely(root->dentry == mountpoint &&
1145+
root->mnt == &m->mnt))
1146+
break;
1147+
if (mountpoint != m->mnt.mnt_root) {
1148+
path->mnt = &m->mnt;
1149+
path->dentry = mountpoint;
1150+
*seqp = read_seqcount_begin(&mountpoint->d_seq);
1151+
return true;
1152+
}
1153+
}
1154+
return false;
1155+
}
1156+
11371157
/*
11381158
* Perform an automount
11391159
* - 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,
16961716
if (path_equal(&nd->path, &nd->root))
16971717
goto in_root;
16981718
if (unlikely(nd->path.dentry == nd->path.mnt->mnt_root)) {
1699-
struct path path = nd->path;
1719+
struct path path;
17001720
unsigned seq;
1701-
1702-
while (1) {
1703-
struct mount *mnt = real_mount(path.mnt);
1704-
struct mount *mparent = mnt->mnt_parent;
1705-
struct dentry *mountpoint = mnt->mnt_mountpoint;
1706-
seq = read_seqcount_begin(&mountpoint->d_seq);
1707-
if (&mparent->mnt == path.mnt)
1708-
goto in_root;
1709-
path.dentry = mountpoint;
1710-
path.mnt = &mparent->mnt;
1711-
if (path_equal(&path, &nd->root))
1712-
goto in_root;
1713-
if (path.dentry != path.mnt->mnt_root)
1714-
break;
1715-
}
1721+
if (!choose_mountpoint_rcu(real_mount(nd->path.mnt),
1722+
&nd->root, &path, &seq))
1723+
goto in_root;
17161724
if (unlikely(nd->flags & LOOKUP_NO_XDEV))
17171725
return ERR_PTR(-ECHILD);
17181726
nd->path = path;

0 commit comments

Comments
 (0)