From: Christian Brauner <brauner@kernel.org>
To: Al Viro <viro@zeniv.linux.org.uk>, Seth Forshee <sforshee@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, Christian Brauner <brauner@kernel.org>
Subject: [PATCH v2 4/5] fs: use a for loop when locking a mount
Date: Tue, 28 Mar 2023 18:13:09 +0200 [thread overview]
Message-ID: <20230202-fs-move-mount-replace-v2-4-f53cd31d6392@kernel.org> (raw)
In-Reply-To: <20230202-fs-move-mount-replace-v2-0-f53cd31d6392@kernel.org>
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.
Signed-off-by: Christian Brauner <brauner@kernel.org>
---
fs/namespace.c | 50 +++++++++++++++++++++++++++++---------------------
1 file changed, 29 insertions(+), 21 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index 42dc87f86f34..7f22fcfd8eab 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -2308,31 +2308,39 @@ 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 vfsmount *mnt = path->mnt;
+ 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);
}
+
+ 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);
+ }
+
+ mp = get_mountpoint(dentry);
+ if (IS_ERR(mp)) {
+ namespace_unlock();
+ inode_unlock(dentry->d_inode);
return mp;
}
- namespace_unlock();
- inode_unlock(path->dentry->d_inode);
- path_put(path);
- path->mnt = mnt;
- dentry = path->dentry = dget(mnt->mnt_root);
- goto retry;
+
+ return mp;
}
static void unlock_mount(struct mountpoint *where)
--
2.34.1
next prev parent reply other threads:[~2023-03-28 16:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-28 16:13 [PATCH v2 0/5] fs: allow to mount beneath top mount Christian Brauner
2023-03-28 16:13 ` [PATCH v2 1/5] fs: add path_mounted() Christian Brauner
2023-04-05 19:29 ` Seth Forshee
2023-03-28 16:13 ` [PATCH v2 2/5] pnode: pass mountpoint directly Christian Brauner
2023-04-05 19:30 ` Seth Forshee
2023-04-06 13:01 ` Christian Brauner
2023-03-28 16:13 ` [PATCH v2 3/5] fs: fix __lookup_mnt() documentation Christian Brauner
2023-04-05 19:32 ` Seth Forshee
2023-03-28 16:13 ` Christian Brauner [this message]
2023-04-05 19:34 ` [PATCH v2 4/5] fs: use a for loop when locking a mount Seth Forshee
2023-03-28 16:13 ` [PATCH v2 5/5] fs: allow to mount beneath top mount Christian Brauner
2023-04-05 19:34 ` Seth Forshee
2023-04-06 13:56 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230202-fs-move-mount-replace-v2-4-f53cd31d6392@kernel.org \
--to=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=sforshee@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).