diff options
author | Christian Brauner <brauner@kernel.org> | 2023-05-03 13:18:41 +0200 |
---|---|---|
committer | Christian Brauner <brauner@kernel.org> | 2023-05-19 04:30:22 +0200 |
commit | 64f44b27ae9184e13ebbca230fa83da02a10f283 (patch) | |
tree | 09cc3e55262406d7f0736a35d87432915b45c420 /fs/namespace.c | |
parent | fs: properly document __lookup_mnt() (diff) | |
download | linux-64f44b27ae9184e13ebbca230fa83da02a10f283.tar.xz linux-64f44b27ae9184e13ebbca230fa83da02a10f283.zip |
fs: use a for loop when locking a mount
Currently, lock_mount() uses a goto to retry the lookup until it
succeeded in acquiring the namespace_lock() preventing the top mount
from being overmounted. While that's perfectly fine we want to lookup
the mountpoint on the parent of the top mount in later patches. So adapt
the code to make this easier to implement. Also, the for loop is
arguably a little cleaner and makes the code easier to follow. No
functional changes intended.
Reviewed-by: Seth Forshee (DigitalOcean) <sforshee@kernel.org>
Message-Id: <20230202-fs-move-mount-replace-v4-3-98f3d80d7eaa@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'fs/namespace.c')
-rw-r--r-- | fs/namespace.c | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/fs/namespace.c b/fs/namespace.c index 443b0fa564c4..f91a60e6039d 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -2318,30 +2318,37 @@ static int attach_recursive_mnt(struct mount *source_mnt, static struct mountpoint *lock_mount(struct path *path) { struct vfsmount *mnt; - struct dentry *dentry = path->dentry; -retry: - inode_lock(dentry->d_inode); - if (unlikely(cant_mount(dentry))) { - inode_unlock(dentry->d_inode); - return ERR_PTR(-ENOENT); - } - namespace_lock(); - mnt = lookup_mnt(path); - if (likely(!mnt)) { - struct mountpoint *mp = get_mountpoint(dentry); - if (IS_ERR(mp)) { - namespace_unlock(); + struct dentry *dentry; + struct mountpoint *mp; + + for (;;) { + dentry = path->dentry; + inode_lock(dentry->d_inode); + if (unlikely(cant_mount(dentry))) { inode_unlock(dentry->d_inode); - return mp; + return ERR_PTR(-ENOENT); } - return mp; + + namespace_lock(); + + mnt = lookup_mnt(path); + if (likely(!mnt)) + break; + + namespace_unlock(); + inode_unlock(dentry->d_inode); + path_put(path); + path->mnt = mnt; + path->dentry = dget(mnt->mnt_root); } - namespace_unlock(); - inode_unlock(path->dentry->d_inode); - path_put(path); - path->mnt = mnt; - dentry = path->dentry = dget(mnt->mnt_root); - goto retry; + + mp = get_mountpoint(dentry); + if (IS_ERR(mp)) { + namespace_unlock(); + inode_unlock(dentry->d_inode); + } + + return mp; } static void unlock_mount(struct mountpoint *where) |