From: Hannes Reinecke <hare@kernel.org>
To: Andreas Hindborg <a.hindborg@kernel.org>,
Breno Leitao <leitao@debian.org>,
Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
Chaitanya Kulkarni <kch@nvidia.com>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-nvme@lists.infradead.org,
Hannes Reinecke <hare@kernel.org>
Subject: [PATCH RFC v2 09/12] fs/configfs: open-code simple_pin_fs()
Date: Fri, 19 Jun 2026 10:36:49 +0200 [thread overview]
Message-ID: <20260619-configfs-ns-v2-9-82fd7094b8dc@kernel.org> (raw)
In-Reply-To: <20260619-configfs-ns-v2-0-82fd7094b8dc@kernel.org>
simple_pin_fs() is protected by an internal spin lock, to
protect against concurrent use of simple_release_fs().
But as we also need to clone the mountpoint we cannot
easily expand the scope of the lock as it's internal to
fs/libfs. So open-code simple_pin_fs() and simple_release_fs()
to be able to use a lock covering all use-cases.
Signed-off-by: Hannes Reinecke <hare@kernel.org>
---
fs/configfs/mount.c | 56 +++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 48 insertions(+), 8 deletions(-)
diff --git a/fs/configfs/mount.c b/fs/configfs/mount.c
index 36f275aaaf871f748dfcb011b782c22abe19d9d5..1f61bc1efe6e2644985c6b90777fa8ddcbb4b742 100644
--- a/fs/configfs/mount.c
+++ b/fs/configfs/mount.c
@@ -25,6 +25,7 @@
struct kmem_cache *configfs_dir_cachep;
static DEFINE_XARRAY(configfs_super_xa);
static struct configfs_super_info *configfs_root;
+static DEFINE_SPINLOCK(configfs_pin_lock);
static u64 configfs_ns_id(struct net *net_ns)
{
@@ -219,21 +220,60 @@ MODULE_ALIAS_FS("configfs");
struct dentry *configfs_pin_fs(struct super_block *sb)
{
- struct configfs_super_info *info = configfs_root;
- int err;
-
- err = simple_pin_fs(&configfs_fs_type, &info->mnt, &info->mnt_count);
- if (err)
- return ERR_PTR(err);
+ struct configfs_super_info *info;
+ spin_lock(&configfs_pin_lock);
+ if (sb) {
+ struct configfs_super_info *root = configfs_root;
+ struct dentry *dentry = sb->s_root;
+
+ info = sb->s_fs_info;
+ if (!info->mnt) {
+ struct vfsmount *mnt;
+
+ spin_unlock(&configfs_pin_lock);
+ mnt = mnt_clone_direct(root->mnt, dentry);
+ if (IS_ERR(mnt))
+ return ERR_CAST(mnt);
+ spin_lock(&configfs_pin_lock);
+ info->mnt = mnt;
+ } else {
+ mntget(info->mnt);
+ }
+ } else {
+ info = configfs_root;
+ if (!info->mnt) {
+ struct vfsmount *mnt;
+
+ spin_unlock(&configfs_pin_lock);
+ mnt = vfs_kern_mount(&configfs_fs_type, SB_KERNMOUNT,
+ configfs_fs_type.name, NULL);
+ if (IS_ERR(mnt))
+ return ERR_CAST(mnt);
+ spin_lock(&configfs_pin_lock);
+ info->mnt = mnt;
+ } else {
+ mntget(info->mnt);
+ }
+ }
+ info->mnt_count++;
+ spin_unlock(&configfs_pin_lock);
return info->mnt->mnt_root;
}
void configfs_release_fs(struct super_block *sb)
{
struct configfs_super_info *info = configfs_root;
-
- simple_release_fs(&info->mnt, &info->mnt_count);
+ struct vfsmount *mnt;
+
+ spin_lock(&configfs_pin_lock);
+ if (sb)
+ info = sb->s_fs_info;
+ mnt = info->mnt;
+ if (--info->mnt_count)
+ info->mnt = NULL;
+ spin_unlock(&configfs_pin_lock);
+ mntput(mnt);
}
static int __init configfs_init(void)
--
2.51.0
next prev parent reply other threads:[~2026-06-19 8:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-19 8:36 [PATCH RFC v2 00/12] namespace-aware configfs hare
2026-06-19 8:36 ` [PATCH RFC v2 01/12] fs/configfs: rework configfs_is_root() hare
2026-06-19 8:36 ` [PATCH RFC v2 02/12] fs/configfs: dynamically allocate super_info hare
2026-06-19 8:36 ` [PATCH RFC v2 03/12] fs/configfs: separate out configfs_{link,unlink}_root() hare
2026-06-19 8:36 ` [PATCH RFC v2 04/12] fs/configfs: add superblock as attribute to configfs_pin_fs() Hannes Reinecke
2026-06-19 8:36 ` [PATCH RFC v2 05/12] fs/configfs: add 'fill_subsystem' and 'clear_subsystem' callbacks Hannes Reinecke
2026-06-19 8:36 ` [PATCH RFC v2 06/12] fs/configfs: add superblock as attribute to configfs_pin_fs() Hannes Reinecke
2026-06-19 8:36 ` [PATCH RFC v2 07/12] fs/namespace: implement mnt_clone_direct() Hannes Reinecke
2026-06-19 8:36 ` [PATCH RFC v2 08/12] fs/configfs: switch to get_tree_keyed() Hannes Reinecke
2026-06-19 8:36 ` Hannes Reinecke [this message]
2026-06-19 8:36 ` [PATCH RFC v2 10/12] nvmet: make discovery subsystem dynamic Hannes Reinecke
2026-06-19 8:36 ` [PATCH RFC v2 11/12] nvmet: per net-namespace port list Hannes Reinecke
2026-06-19 8:36 ` [PATCH RFC v2 12/12] nvmet: make configfs setup namespace aware Hannes Reinecke
2026-06-19 13:25 ` [syzbot ci] Re: namespace-aware configfs syzbot ci
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=20260619-configfs-ns-v2-9-82fd7094b8dc@kernel.org \
--to=hare@kernel.org \
--cc=a.hindborg@kernel.org \
--cc=brauner@kernel.org \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=kch@nvidia.com \
--cc=leitao@debian.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
--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
Powered by JetHome