Skip to content

Commit 2aa3847

Browse files
author
Al Viro
committed
non-RCU analogue of the previous commit
new helper: choose_mountpoint(). Wrapper around choose_mountpoint_rcu(), similar to lookup_mnt() vs. __lookup_mnt(). follow_dotdot() switched to it. Now we don't grab mount_lock exclusive anymore; note that the primitive used non-RCU mount traversals in other direction (lookup_mnt()) doesn't bother with that either - it uses mount_lock seqcount instead. Signed-off-by: Al Viro <[email protected]>
1 parent 7ef482f commit 2aa3847

File tree

1 file changed

+39
-17
lines changed

1 file changed

+39
-17
lines changed

fs/namei.c

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -605,10 +605,9 @@ static void terminate_walk(struct nameidata *nd)
605605
}
606606

607607
/* path_put is needed afterwards regardless of success or failure */
608-
static bool legitimize_path(struct nameidata *nd,
609-
struct path *path, unsigned seq)
608+
static bool __legitimize_path(struct path *path, unsigned seq, unsigned mseq)
610609
{
611-
int res = __legitimize_mnt(path->mnt, nd->m_seq);
610+
int res = __legitimize_mnt(path->mnt, mseq);
612611
if (unlikely(res)) {
613612
if (res > 0)
614613
path->mnt = NULL;
@@ -622,6 +621,12 @@ static bool legitimize_path(struct nameidata *nd,
622621
return !read_seqcount_retry(&path->dentry->d_seq, seq);
623622
}
624623

624+
static inline bool legitimize_path(struct nameidata *nd,
625+
struct path *path, unsigned seq)
626+
{
627+
return __legitimize_path(path, nd->m_seq, seq);
628+
}
629+
625630
static bool legitimize_links(struct nameidata *nd)
626631
{
627632
int i;
@@ -1154,6 +1159,31 @@ static bool choose_mountpoint_rcu(struct mount *m, const struct path *root,
11541159
return false;
11551160
}
11561161

1162+
static bool choose_mountpoint(struct mount *m, const struct path *root,
1163+
struct path *path)
1164+
{
1165+
bool found;
1166+
1167+
rcu_read_lock();
1168+
while (1) {
1169+
unsigned seq, mseq = read_seqbegin(&mount_lock);
1170+
1171+
found = choose_mountpoint_rcu(m, root, path, &seq);
1172+
if (unlikely(!found)) {
1173+
if (!read_seqretry(&mount_lock, mseq))
1174+
break;
1175+
} else {
1176+
if (likely(__legitimize_path(path, seq, mseq)))
1177+
break;
1178+
rcu_read_unlock();
1179+
path_put(path);
1180+
rcu_read_lock();
1181+
}
1182+
}
1183+
rcu_read_unlock();
1184+
return found;
1185+
}
1186+
11571187
/*
11581188
* Perform an automount
11591189
* - return -EISDIR to tell follow_managed() to stop and return the path we
@@ -1756,22 +1786,14 @@ static struct dentry *follow_dotdot(struct nameidata *nd,
17561786
if (path_equal(&nd->path, &nd->root))
17571787
goto in_root;
17581788
if (unlikely(nd->path.dentry == nd->path.mnt->mnt_root)) {
1759-
struct path path = nd->path;
1760-
path_get(&path);
1761-
while (1) {
1762-
if (!follow_up(&path)) {
1763-
path_put(&path);
1764-
goto in_root;
1765-
}
1766-
if (path_equal(&path, &nd->root)) {
1767-
path_put(&path);
1768-
goto in_root;
1769-
}
1770-
if (path.dentry != nd->path.mnt->mnt_root)
1771-
break;
1772-
}
1789+
struct path path;
1790+
1791+
if (!choose_mountpoint(real_mount(nd->path.mnt),
1792+
&nd->root, &path))
1793+
goto in_root;
17731794
path_put(&nd->path);
17741795
nd->path = path;
1796+
nd->inode = path.dentry->d_inode;
17751797
if (unlikely(nd->flags & LOOKUP_NO_XDEV))
17761798
return ERR_PTR(-EXDEV);
17771799
}

0 commit comments

Comments
 (0)