namespace-aware configfs
Subsystems (4)
v3 cover namespace-aware configfs
Hey all,
during discussions at LSF/MM I thought it would be quite helpful to make configfs namespace aware, such that one could do:
unshare --mnt
mount -t configfs none /sys/kernel/config
and get a new instance of configfs. This will allow to have distinct configurations for each namespace.
This is particularly helpful if you want to run eg nvmet in a container; with this patchset each container can have its own configuration, and one can simulate a multi-node nvmet cluster using containers.
How it works:
The configfs 'root' entries are stored in 'configfs_super_info', which can be looked up from an xarray using the (network) namespace ID as the index. A configfs subsystem can be converted to be namespace aware by implementing the new subsyste callbacks 'fill_subsystem()' and 'clear_subsystem', which are responsible for populating the subsystem structure.
Upon registration via 'register_subsystem()' the subsystem is put in a linked list within 'configfs_super_info'. So when mount() is called from a different namespace this list is traversed, and new subsystems are created in the new namespace using the callbacks.
Open Issues:
- I've added a new function 'mnt_clone_direct()' to clone the vfsmount entry (the original code just did a simple_pin_fs()). Not sure if that's correct. Christian?
- Ideally I would love to make the whole thing work without having to mount a new configfs instance from within the container. Again, not sure if that's possible.
- I've decided to base it off the net namespace (and not any namespace). That makes implementation easier, but requires the various subsystems to actually _use_ the network namespace.
The current use-case (nvmet) does that, so it works for me :-)
Otherwise, as usual, commands and reviews are welcome.
Changes to the original submission:
- Changed to use 'net' namespace instead of 'mnt' namespace
- Smaller fixes as suggested by sashiko.
---
Changes in v3:
- Split off nvmet patches
- kbuild robot fixes
- Simplify namespace selection
- Link to v2: https://lore.kernel.org/r/[email protected]
---
Hannes Reinecke (12):
fs/configfs: rework configfs_is_root()
fs/configfs: dynamically allocate super_info fs/configfs: separate out configfs_{link,unlink}_root() fs/configfs: add superblock as attribute to configfs_pin_fs() fs/configfs: add 'fill_subsystem' and 'clear_subsystem' callbacks fs/namespace: implement mnt_clone_direct() fs/configfs: switch to get_tree_keyed()
fs/configfs: open-code simple_pin_fs()
nvmet: make discovery subsystem dynamic
nvmet: per net-namespace port list
nvmet: make configfs setup namespace aware
nvmet: enable transports for net namespaces
drivers/nvme/target/configfs.c | 206 +++++++++++++++++++++++++++------ drivers/nvme/target/core.c | 36 +++--- drivers/nvme/target/discovery.c | 91 +++++++++++---- drivers/nvme/target/loop.c | 4 + drivers/nvme/target/nvmet.h | 15 ++- drivers/nvme/target/rdma.c | 6 +- drivers/nvme/target/tcp.c | 6 +- fs/configfs/configfs_internal.h | 23 +++- fs/configfs/dir.c | 188 +++++++++++++++++++++++++----- fs/configfs/mount.c | 248 +++++++++++++++++++++++++++++++++------- fs/namespace.c | 11 ++ include/linux/configfs.h | 8 ++ include/linux/mount.h | 1 + 13 files changed, 682 insertions(+), 161 deletions(-)
---
base-commit: 66affa37cfac0aec061cc4bcf4a065b0c52f7e19
change-id: 20260619-configfs-ns-b5748b366366
Best regards,
Signature · 1 line
Hannes Reinecke <[email protected]>
RFC PATCH v3 1/12 fs/configfs: rework configfs_is_root()
In preparation for making configfs namespace-aware rework configfs_is_root() to not rely on static structures but rather use the information in the structures themselves.
--- fs/configfs/configfs_internal.h | 2 +- fs/configfs/mount.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-)
fs/configfs/configfs_internal.h +1 -1
@@ -63,7 +63,7 @@ extern spinlock_t configfs_dirent_lock;extern struct kmem_cache *configfs_dir_cachep; -extern int configfs_is_root (struct config_item *item); +extern bool configfs_is_root (struct config_item *item);extern struct inode *configfs_new_inode (umode_t mode,struct configfs_dirent *,struct super_block *);extern struct inode *configfs_create (struct dentry *,umode_t mode);
fs/configfs/mount.c +7 -2
@@ -47,9 +47,14 @@ static struct config_group configfs_root_group = { }, }; -int configfs_is_root (struct config_item *item) +bool configfs_is_root (struct config_item *item) { -return item == &configfs_root_group.cg_item; +struct configfs_dirent *sd; + +if (!item->ci_dentry) +return false; + sd = item->ci_dentry->d_fsdata; +return !!(sd->s_type &CONFIGFS_ROOT ); }static struct configfs_dirent configfs_root = {
Signature · 1 line
2.51.0
Breno Leitao
maintainerRe: [PATCH RFC v3 01/12] fs/configfs: rework configfs_is_root()
hello hannes,
Quoted 3 lines · Hannes Reinecke
In preparation for making configfs namespace-aware rework
configfs_is_root()to not rely on static structures but rather use the information in the structures themselves.>
Thanks for the cleanup. The approach looks fine: CONFIGFS_ROOT is only ever set on the single static configfs_root dirent.
Nit: "namespace-aware rework configfs_is_root()" reads as if a comma is missing -- "... namespace-aware, rework configfs_is_root() ...".
Quoted 27 lines
Signed-off-by Hannes Reinecke <[email protected]>--- fs/configfs/configfs_internal.h | 2 +- fs/configfs/mount.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-)fs/configfs/configfs_internal.h +1
-1@@ -63,7 +63,7 @@ extern spinlock_t configfs_dirent_lock;extern struct kmem_cache *configfs_dir_cachep; -extern int configfs_is_root (struct config_item *item); +extern bool configfs_is_root (struct config_item *item);extern struct inode *configfs_new_inode (umode_t mode,struct configfs_dirent *,struct super_block *);extern struct inode *configfs_create (struct dentry *,umode_t mode);fs/configfs/mount.c +0
-0@@ -47,9 +47,14 @@ static struct config_group configfs_root_group = { }, };
fs/configfs/mount.c static struct config_group configfs_root_group = { · line 57
Quoted 10 lines
fs/configfs/mount.c +7
-2-int configfs_is_root (struct config_item *item) +bool configfs_is_root (struct config_item *item) { -return item == &configfs_root_group.cg_item; +struct configfs_dirent *sd; + +if (!item->ci_dentry) +return false; + sd = item->ci_dentry->d_fsdata; +return !!(sd->s_type &CONFIGFS_ROOT );
The old helper was a pure pointer comparison and never touched item, so it tolerated a NULL or not-yet-attached item. The new one dereferences it (item). I suppose that item is never being called as NULL?!
Thanks
--breno
RFC PATCH v3 2/12 fs/configfs: dynamically allocate super_info
In reply to Hannes ReineckeDefine 'struct configfs_super_info' to hold all required structures and allocate the filesystem contents dynamically.
--- fs/configfs/configfs_internal.h | 13 ++++ fs/configfs/dir.c | 44 +++++++----- fs/configfs/mount.c | 148 ++++++++++++++++++++++++++++++---------- include/linux/configfs.h | 1 + 4 files changed, 154 insertions(+), 52 deletions(-)
fs/configfs/configfs_internal.h +13 -0
@@ -44,6 +44,17 @@ struct configfs_dirent {struct configfs_fragment *s_frag; }; +struct configfs_super_info { +struct configfs_dirent root; +struct config_group group; +struct list_head subsys_list; +struct mutex subsys_mutex; +struct vfsmount *mnt; +int mnt_count; +struct net *net_ns; +refcount_t ref; +}; +#define CONFIGFS_ROOT 0x0001#define CONFIGFS_DIR 0x0002#define CONFIGFS_ITEM_ATTR 0x0004
@@ -81,6 +92,8 @@ extern int configfs_setattr(struct mnt_idmap *idmap,extern struct dentry *configfs_pin_fs (void );extern void configfs_release_fs (void ); +extern struct configfs_super_info *configfs_get_super_info (struct net *net_ns); +extern void configfs_put_super_info (struct configfs_super_info *info);extern const struct file_operations configfs_dir_operations;extern const struct file_operations configfs_file_operations;
fs/configfs/dir.c +27 -17
106 lines not on this page · raw message
fs/configfs/mount.c +113 -35
228 lines not on this page · raw message
include/linux/configfs.h +1 -0
@@ -24,6 +24,7 @@#include <linux/list.h> /* struct list_head */ #include <linux/kref.h> /* struct kref */ #include <linux/mutex.h> /* struct mutex */ +#include <net/net_namespace.h> /* struct net */ #define CONFIGFS_ITEM_NAME_LEN 20
Signature · 1 line
2.51.0
RFC PATCH v3 3/12 fs/configfs: separate out configfs_{link,unlink}_root()
In reply to Hannes ReineckeSeparate out functions to link and unlink subsystem groups.
--- fs/configfs/dir.c | 74 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 28 deletions(-)
fs/configfs/dir.c +46 -28
@@ -1861,32 +1861,19 @@ void configfs_unregister_default_group(struct config_group *group) }EXPORT_SYMBOL (configfs_unregister_default_group); -int configfs_register_subsystem (struct configfs_subsystem *subsys) +static int configfs_link_root (struct configfs_super_info *info, +struct configfs_subsystem *subsys, +struct dentry *root) { -struct configfs_super_info *info;struct config_group *group = &subsys->su_group;struct dentry *dentry; -struct dentry *root;struct configfs_dirent *sd;struct configfs_fragment *frag;int err; - info =configfs_get_super_info (&init_net); -if (IS_ERR (info)) -return PTR_ERR (info); - frag =new_fragment (); -if (!frag) { -configfs_put_super_info (info); +if (!frag)return -ENOMEM ; - } - - root =configfs_pin_fs (); -if (IS_ERR (root)) { -put_fragment (frag); -configfs_put_super_info (info); -return PTR_ERR (root); - }if (!group->cg_item.ci_name) group->cg_item.ci_name = group->cg_item.ci_namebuf;
@@ -1924,33 +1911,48 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys)mutex_lock (&info->subsys_mutex);unlink_group (group);mutex_unlock (&info->subsys_mutex); -configfs_release_fs (); }put_fragment (frag); -configfs_put_super_info (info);return err; } -void configfs_unregister_subsystem (struct configfs_subsystem *subsys) +int configfs_register_subsystem (struct configfs_subsystem *subsys) {struct configfs_super_info *info; +struct dentry *root; +int err; + + info =configfs_get_super_info (&init_net); +if (WARN_ON (IS_ERR (info))) +return PTR_ERR (info); + + root =configfs_pin_fs (); +if (IS_ERR (root)) { + err =PTR_ERR (root); + goto out_put; + } + + err =configfs_link_root (info, subsys, root); +if (err) +configfs_release_fs (); + +out_put: +configfs_put_super_info (info); +return err; +} + +static bool configfs_unlink_root (struct configfs_subsystem *subsys) +{struct config_group *group = &subsys->su_group;struct dentry *dentry =dget (group->cg_item.ci_dentry);struct dentry *root = dentry->d_sb->s_root;struct configfs_dirent *sd = dentry->d_fsdata;struct configfs_fragment *frag = sd->s_frag; - info =configfs_get_super_info (&init_net); -if (WARN_ON (IS_ERR (info))) { -dput (dentry); -return ; - } -if (dentry->d_parent != root) {pr_err ("Tried to unregister non-subsystem!\n" );dput (dentry); -configfs_put_super_info (info); -return ; +return false; }down_write (&frag->frag_sem);
@@ -1978,6 +1980,22 @@ void configfs_unregister_subsystem(struct configfs_subsystem *subsys)inode_unlock (d_inode (root));dput (dentry); +return true; +} + +void configfs_unregister_subsystem (struct configfs_subsystem *subsys) +{ +struct configfs_super_info *info; +struct config_group *group = &subsys->su_group; + + info =configfs_get_super_info (&init_net); +if (WARN_ON (IS_ERR (info))) +return ; + +if (!configfs_unlink_root (subsys)) { +configfs_put_super_info (info); +return ; + }mutex_lock (&info->subsys_mutex);unlink_group (group);
Signature · 1 line
2.51.0
RFC PATCH v3 4/12 fs/configfs: add superblock as attribute to configfs_pin_fs()
In reply to Hannes ReineckeEach namspace might have its own superblock, so add it as an argument to configfs_pin_fs() to ensure that the correct filesystem instance will be pinned.
--- fs/configfs/configfs_internal.h | 4 ++-- fs/configfs/dir.c | 10 +++++----- fs/configfs/mount.c | 20 +++++++++++++------- 3 files changed, 20 insertions(+), 14 deletions(-)
fs/configfs/configfs_internal.h +2 -2
@@ -90,8 +90,8 @@ extern const unsigned char * configfs_get_name(struct configfs_dirent *sd);extern int configfs_setattr (struct mnt_idmap *idmap,struct dentry *dentry,struct iattr *iattr); -extern struct dentry *configfs_pin_fs (void ); -extern void configfs_release_fs (void ); +extern struct dentry *configfs_pin_fs (struct super_block *sb); +extern void configfs_release_fs (struct super_block *sb);extern struct configfs_super_info *configfs_get_super_info (struct net *net_ns);extern void configfs_put_super_info (struct configfs_super_info *info);
fs/configfs/dir.c +5 -5
@@ -1144,7 +1144,7 @@ int configfs_depend_item(struct configfs_subsystem *subsys,* Pin the configfs filesystem. This means we can safely access * the root of the configfs filesystem. */ - root =configfs_pin_fs (); + root =configfs_pin_fs (NULL );if (IS_ERR (root))return PTR_ERR (root);
@@ -1171,7 +1171,7 @@ int configfs_depend_item(struct configfs_subsystem *subsys,* If we succeeded, the fs is pinned via other methods. If not, * we're done with it anyway. So release_fs() is always right. */ -configfs_release_fs (); +configfs_release_fs (NULL );return ret; }
@@ -1926,7 +1926,7 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys)if (WARN_ON (IS_ERR (info)))return PTR_ERR (info); - root =configfs_pin_fs (); + root =configfs_pin_fs (NULL );if (IS_ERR (root)) { err =PTR_ERR (root); goto out_put;
@@ -1934,7 +1934,7 @@ int configfs_register_subsystem(struct configfs_subsystem *subsys) err =configfs_link_root (info, subsys, root);if (err) -configfs_release_fs (); +configfs_release_fs (NULL ); out_put:configfs_put_super_info (info);
@@ -2000,7 +2000,7 @@ void configfs_unregister_subsystem(struct configfs_subsystem *subsys)mutex_lock (&info->subsys_mutex);unlink_group (group);mutex_unlock (&info->subsys_mutex); -configfs_release_fs (); +configfs_release_fs (NULL );configfs_put_super_info (info); }
fs/configfs/mount.c +13 -7
@@ -192,18 +192,24 @@ static struct file_system_type configfs_fs_type = { };MODULE_ALIAS_FS ("configfs" ); -struct dentry *configfs_pin_fs (void ) +struct dentry *configfs_pin_fs (struct super_block *sb) { -int err =simple_pin_fs (&configfs_fs_type, &configfs_root->mnt, - &configfs_root->mnt_count); -return err ?ERR_PTR (err) : configfs_root->mnt->mnt_root; +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); + +return info->mnt->mnt_root; } -void configfs_release_fs (void ) +void configfs_release_fs (struct super_block *sb) { -simple_release_fs (&configfs_root->mnt, &configfs_root->mnt_count); -} +struct configfs_super_info *info = configfs_root; +simple_release_fs (&info->mnt, &info->mnt_count); +}static int __init configfs_init (void ) {
Signature · 1 line
2.51.0
RFC PATCH v3 5/12 fs/configfs: add 'fill_subsystem' and 'clear_subsystem' callbacks
In reply to Hannes ReineckeWhen creating a new per-namespace filesystem static initialisation doesn't work, so implement a 'fill_subsystem' and 'clear_subsystem' callbacks to 'struct configfs_subsystem' to allow for every driver to populate the subsystem structure dynamicall.
--- fs/configfs/configfs_internal.h | 4 ++ fs/configfs/dir.c | 104 +++++++++++++++++++++++++++++++++++++++- fs/configfs/mount.c | 4 ++ include/linux/configfs.h | 5 ++ 4 files changed, 116 insertions(+), 1 deletion(-)
fs/configfs/configfs_internal.h +4 -0
@@ -94,6 +94,10 @@ extern struct dentry *configfs_pin_fs(struct super_block *sb);extern void configfs_release_fs (struct super_block *sb);extern struct configfs_super_info *configfs_get_super_info (struct net *net_ns);extern void configfs_put_super_info (struct configfs_super_info *info); +extern void configfs_link_subsystems (struct super_block *sb, +struct configfs_super_info *info); +extern void configfs_unlink_subsystems (struct super_block *sb, +struct configfs_super_info *info);extern const struct file_operations configfs_dir_operations;extern const struct file_operations configfs_file_operations;
fs/configfs/dir.c +103 -1
130 lines not on this page · raw message
fs/configfs/mount.c +4 -0
@@ -157,6 +157,9 @@ static int configfs_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_root = root;set_default_d_op (sb, &configfs_dentry_ops);/* the rest get that */ sb->s_d_flags |=DCACHE_DONTCACHE ; + +configfs_link_subsystems (sb, info); +return 0 ; }
@@ -179,6 +182,7 @@ static void configfs_kill_sb(struct super_block *sb) {struct configfs_super_info *info = sb->s_fs_info; +configfs_unlink_subsystems (sb, info);kill_anon_super (sb);configfs_put_super_info (info); sb->s_fs_info =NULL ;
include/linux/configfs.h +5 -0
@@ -227,8 +227,13 @@ struct configfs_group_operations { };struct configfs_subsystem { +struct list_head su_link;struct config_group su_group;struct mutex su_mutex; +int (*fill_subsystem)(struct configfs_subsystem *subsys, +struct net *net_ns); +void (*clear_subsystem)(struct configfs_subsystem *subsys, +struct net *net_ns); };static inline struct configfs_subsystem *to_configfs_subsystem (struct config_group *group)
Signature · 1 line
2.51.0
RFC PATCH v3 6/12 fs/namespace: implement mnt_clone_direct()
In reply to Hannes ReineckeImplement mnt_clone_direct() to just clone an existing vfsmount.
--- fs/namespace.c | 11 +++++++++++ include/linux/mount.h | 1 + 2 files changed, 12 insertions(+)
fs/namespace.c +11 -0
@@ -1482,6 +1482,17 @@ struct vfsmount *mnt_clone_internal(const struct path *path)return &p->mnt; } +struct vfsmount *mnt_clone_direct (struct vfsmount *mnt,struct dentry *dentry) +{ +struct mount *p; + + p =clone_mnt (real_mount (mnt), dentry,CL_SLAVE ); +if (IS_ERR (p)) +return ERR_CAST (p); + p->mnt.mnt_flags |=MNT_INTERNAL ; +return &p->mnt; +} +/* * Returns the mount which either has the specified mnt_id, or has the next * smallest id afer the specified one.
include/linux/mount.h +1 -0
@@ -75,6 +75,7 @@ extern void mnt_drop_write_file(struct file *file);extern void mntput (struct vfsmount *mnt);extern struct vfsmount *mntget (struct vfsmount *mnt);extern void mnt_make_shortterm (struct vfsmount *mnt); +extern struct vfsmount *mnt_clone_direct (struct vfsmount *mnt,struct dentry *dentry);extern struct vfsmount *mnt_clone_internal (const struct path *path);extern bool __mnt_is_readonly (const struct vfsmount *mnt);extern bool mnt_may_suid (struct vfsmount *mnt);
Signature · 1 line
2.51.0
RFC PATCH v3 7/12 fs/configfs: switch to get_tree_keyed()
In reply to Hannes ReineckeSwitch to get_tree_keyed() to instatiate a new superblock whenever the mount namespace changed.
--- fs/configfs/mount.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-)
fs/configfs/mount.c +26 -5
@@ -123,11 +123,10 @@ void configfs_put_super_info(struct configfs_super_info *info)static int configfs_fill_super (struct super_block *sb,struct fs_context *fc) { -struct configfs_super_info *info =configfs_get_super_info (&init_net); +struct configfs_super_info *info = sb->s_fs_info;struct inode *inode;struct dentry *root; - sb->s_fs_info = info; sb->s_blocksize =PAGE_SIZE ; sb->s_blocksize_bits =PAGE_SHIFT ; sb->s_magic =CONFIGFS_MAGIC ;
@@ -138,7 +137,6 @@ static int configfs_fill_super(struct super_block *sb, struct fs_context *fc) &info->root, sb);if (IS_ERR (inode)) {pr_debug ("could not get root inode\n" ); -configfs_put_super_info (info);return PTR_ERR (inode); } inode->i_op = &configfs_root_inode_operations;
@@ -149,7 +147,6 @@ static int configfs_fill_super(struct super_block *sb, struct fs_context *fc) root =d_make_root (inode);if (!root) {pr_debug ("%s: could not get root dentry!\n" ,__func__); -configfs_put_super_info (info);return -ENOMEM ; } info->group.cg_item.ci_dentry = root;
@@ -165,15 +162,38 @@ static int configfs_fill_super(struct super_block *sb, struct fs_context *fc)static int configfs_get_tree (struct fs_context *fc) { -return get_tree_single (fc, configfs_fill_super); +struct net *net_ns = fc->fs_private; +struct configfs_super_info *info; +int err; + + info =configfs_get_super_info (net_ns); +if (IS_ERR (info)) +return PTR_ERR (info); + + err =get_tree_keyed (fc, configfs_fill_super, info); +if (err && fc->s_fs_info) +configfs_put_super_info (info); +return err; +} + +static void configfs_fs_context_free (struct fs_context *fc) +{ +struct net *net_ns = fc->fs_private; + + fc->fs_private =NULL ; +put_net (net_ns); }static const struct fs_context_operations configfs_context_ops = { .get_tree = configfs_get_tree, + .free = configfs_fs_context_free, };static int configfs_init_fs_context (struct fs_context *fc) { +struct net *net_ns =get_net (current->nsproxy->net_ns); + + fc->fs_private = net_ns; fc->ops = &configfs_context_ops;return 0 ; }
@@ -193,6 +213,7 @@ static struct file_system_type configfs_fs_type = { .name = "configfs", .init_fs_context = configfs_init_fs_context, .kill_sb = configfs_kill_sb, + .fs_flags = FS_USERNS_MOUNT, };MODULE_ALIAS_FS ("configfs" );
Signature · 1 line
2.51.0
RFC PATCH v3 8/12 fs/configfs: open-code simple_pin_fs()
In reply to Hannes Reineckesimple_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.
--- fs/configfs/mount.c | 56 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 8 deletions(-)
fs/configfs/mount.c +48 -8
@@ -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 )
Signature · 1 line
2.51.0
RFC PATCH v3 9/12 nvmet: make discovery subsystem dynamic
In reply to Hannes ReineckeIn preparation to make nvmet namespace-aware convert the discovery subsystem to dynamic allocation.
--- drivers/nvme/target/configfs.c | 33 +++++++++++++--- drivers/nvme/target/core.c | 30 ++++++-------- drivers/nvme/target/discovery.c | 86 +++++++++++++++++++++++++++++------------ drivers/nvme/target/nvmet.h | 11 ++++-- 4 files changed, 108 insertions(+), 52 deletions(-)
drivers/nvme/target/configfs.c +27 -6
@@ -51,6 +51,16 @@ static const struct nvmet_type_name_map nvmet_addr_family[] = { { NVMF_ADDR_FAMILY_LOOP, "loop" }, }; +u64 nvmet_get_ns_id (struct net *net_ns) +{ +struct ns_common *ns; + +if (!net_ns) +return 0 ; + ns =to_ns_common (net_ns); +return net_ns == &init_net ?0 : ns->ns_id; +} +static bool nvmet_is_port_enabled (struct nvmet_port *p,const char *caller) {if (p->enabled)
@@ -1734,14 +1744,17 @@ static const struct config_item_type nvmet_subsys_type = {static struct config_group *nvmet_subsys_make (struct config_group *group,const char *name) { -struct nvmet_subsys *subsys; +struct nvmet_subsys *subsys, *disc_subsys;if (sysfs_streq (name,NVME_DISC_SUBSYS_NAME )) {pr_err ("can't create discovery subsystem through configfs\n" );return ERR_PTR (-EINVAL ); } -if (sysfs_streq (name, nvmet_disc_subsys->subsysnqn)) { + disc_subsys =nvmet_get_disc_subsys (&init_net); +if (!disc_subsys) +return ERR_PTR (-ENOENT ); +if (sysfs_streq (name, disc_subsys->subsysnqn)) {pr_err ("can't create subsystem using unique discovery NQN\n" );return ERR_PTR (-EINVAL ); }
@@ -2308,12 +2321,17 @@ static struct config_group nvmet_hosts_group;static ssize_t nvmet_root_discovery_nqn_show (struct config_item *item,char *page) { -return snprintf (page,PAGE_SIZE ,"%s\n" , nvmet_disc_subsys->subsysnqn); +struct nvmet_subsys *disc_subsys =nvmet_get_disc_subsys (&init_net); + +if (!disc_subsys) +return -ENOENT ; +return snprintf (page,PAGE_SIZE ,"%s\n" , disc_subsys->subsysnqn); }static ssize_t nvmet_root_discovery_nqn_store (struct config_item *item,const char *page,size_t count) { +struct nvmet_subsys *disc_subsys;struct list_head *entry;char *old_nqn, *new_nqn;size_t len;
@@ -2338,12 +2356,15 @@ static ssize_t nvmet_root_discovery_nqn_store(struct config_item *item,return -EINVAL ; } } - old_nqn = nvmet_disc_subsys->subsysnqn; - nvmet_disc_subsys->subsysnqn = new_nqn; + disc_subsys =nvmet_get_disc_subsys (&init_net); +if (disc_subsys) { + old_nqn = disc_subsys->subsysnqn; + disc_subsys->subsysnqn = new_nqn; + }up_write (&nvmet_config_sem);kfree (old_nqn); -return len; +return disc_subsys ? len : -ENOENT ; }CONFIGFS_ATTR (nvmet_root_, discovery_nqn);
drivers/nvme/target/core.c +11 -19
@@ -1798,22 +1798,27 @@ static struct nvmet_subsys *nvmet_find_get_subsys(struct nvmet_port *port, const char *subsysnqn) {struct nvmet_subsys_link *p; +struct nvmet_subsys *disc_subsys;if (!port)return NULL ; + disc_subsys =nvmet_get_disc_subsys (&init_net); +if (!disc_subsys) +return NULL ; +if (!strcmp (NVME_DISC_SUBSYS_NAME , subsysnqn)) { -if (!kref_get_unless_zero (&nvmet_disc_subsys->ref)) +if (!kref_get_unless_zero (&disc_subsys->ref))return NULL ; -return nvmet_disc_subsys; +return disc_subsys; }down_read (&nvmet_config_sem); -if (!strncmp (nvmet_disc_subsys->subsysnqn, subsysnqn, +if (!strncmp (disc_subsys->subsysnqn, subsysnqn,NVMF_NQN_SIZE )) { -if (kref_get_unless_zero (&nvmet_disc_subsys->ref)) { +if (kref_get_unless_zero (&disc_subsys->ref)) {up_read (&nvmet_config_sem); -return nvmet_disc_subsys; +return disc_subsys; } }list_for_each_entry (p, &port->subsystems, entry) {
@@ -1888,14 +1893,8 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,INIT_LIST_HEAD (&subsys->ctrls);INIT_LIST_HEAD (&subsys->hosts); - ret =nvmet_debugfs_subsys_setup (subsys); -if (ret) - goto free_subsysnqn; -return subsys; -free_subsysnqn: -kfree (subsys->subsysnqn); free_fr:kfree (subsys->firmware_rev); free_mn:
@@ -1976,18 +1975,12 @@ static int __init nvmet_init(void)if (error) goto out_free_nvmet_aen_work_queue; - error =nvmet_init_discovery (); -if (error) - goto out_exit_debugfs; - error =nvmet_init_configfs ();if (error) - goto out_exit_discovery; + goto out_exit_debugfs;return 0 ; -out_exit_discovery: -nvmet_exit_discovery (); out_exit_debugfs:nvmet_exit_debugfs (); out_free_nvmet_aen_work_queue:
@@ -2006,7 +1999,6 @@ static int __init nvmet_init(void) static void __exit nvmet_exit(void) {nvmet_exit_configfs (); -nvmet_exit_discovery ();nvmet_exit_debugfs ();ida_destroy (&cntlid_ida);destroy_workqueue (nvmet_aen_wq);
drivers/nvme/target/discovery.c +62 -24
151 lines not on this page · raw message
drivers/nvme/target/nvmet.h +8 -3
@@ -325,6 +325,9 @@ struct nvmet_subsys {u16 cntlid_min;u16 cntlid_max; +/* For discovery subsystems */ +u64 genctr; +struct list_head ctrls;struct list_head hosts;
@@ -696,11 +699,13 @@ void nvmet_add_async_event(struct nvmet_ctrl *ctrl, u8 event_type,int __init nvmet_init_configfs (void ); void __exit nvmet_exit_configfs(void); +extern struct list_head *nvmet_get_port_list (struct net *net_ns); -int __init nvmet_init_discovery (void ); -void nvmet_exit_discovery (void ); +extern u64 nvmet_get_ns_id (struct net *net_ns); +extern int nvmet_add_disc_subsys (struct net *net_ns); +extern void nvmet_del_disc_subsys (struct net *net_ns); +extern struct nvmet_subsys *nvmet_get_disc_subsys (struct net *net_ns); -extern struct nvmet_subsys *nvmet_disc_subsys;extern struct rw_semaphore nvmet_config_sem;extern u32 nvmet_ana_group_enabled[NVMET_MAX_ANAGRPS +1 ];
Signature · 1 line
2.51.0
RFC PATCH v3 10/12 nvmet: per net-namespace port list
In reply to Hannes ReineckeThe port list needs to be per net-namespace, as each network namespace has a different view on the existing IP addresses etc.
So replace the global list with an xarray of lists indexed by the network namespace id.
--- drivers/nvme/target/configfs.c | 61 ++++++++++++++++++++++++++++++++++++++--- drivers/nvme/target/discovery.c | 4 ++- drivers/nvme/target/nvmet.h | 1 - 3 files changed, 60 insertions(+), 6 deletions(-)
drivers/nvme/target/configfs.c +57 -4
@@ -25,8 +25,7 @@static const struct config_item_type nvmet_host_type;static const struct config_item_type nvmet_subsys_type; -static LIST_HEAD (nvmet_ports_list); -struct list_head *nvmet_ports = &nvmet_ports_list; +static DEFINE_XARRAY (nvmet_ports_xa);struct nvmet_type_name_map {u8 type;
@@ -61,6 +60,60 @@ u64 nvmet_get_ns_id(struct net *net_ns)return net_ns == &init_net ?0 : ns->ns_id; } +struct list_head *nvmet_get_port_list (struct net *net_ns) +{ +struct list_head *port_list; +u64 ns_id =nvmet_get_ns_id (net_ns); + + port_list =xa_load (&nvmet_ports_xa, ns_id); +return port_list; +} + +static int nvmet_add_port_list (struct nvmet_port *p) +{ +u64 ns_id =nvmet_get_ns_id (&init_net); +struct list_head *port_list; +int err =0 ; + +xa_lock (&nvmet_ports_xa); + port_list =xa_load (&nvmet_ports_xa, ns_id); +if (!port_list) { + port_list =kzalloc_obj (*port_list); +if (!port_list) { + err = -ENOMEM ; + goto out_unlock; + } +INIT_LIST_HEAD (port_list); + err =__xa_insert (&nvmet_ports_xa, ns_id, + port_list,GFP_KERNEL ); +if (err <0 ) { +kfree (port_list); + goto out_unlock; + } + } +list_add (&p->global_entry, port_list); +out_unlock: +xa_unlock (&nvmet_ports_xa); +return err; +} + +static void nvmet_del_port_list (struct nvmet_port *p) +{ +struct list_head *port_list; +u64 ns_id =nvmet_get_ns_id (&init_net); + +xa_lock (&nvmet_ports_xa); + port_list =xa_load (&nvmet_ports_xa, ns_id); +if (!WARN_ON (!port_list)) { +list_del_init (&p->global_entry); +if (list_empty (port_list)) { +__xa_erase (&nvmet_ports_xa, ns_id); +kfree (port_list); + } + } +xa_unlock (&nvmet_ports_xa); +} +static bool nvmet_is_port_enabled (struct nvmet_port *p,const char *caller) {if (p->enabled)
@@ -2017,7 +2070,7 @@ static void nvmet_port_release(struct config_item *item)/* Let inflight controllers teardown complete */ flush_workqueue (nvmet_wq); -list_del (&port->global_entry); +nvmet_del_port_list (port);key_put (port->keyring);kfree (port->ana_state);
@@ -2085,7 +2138,7 @@ static struct config_group *nvmet_ports_make(struct config_group *group, port->ana_state[i] =NVME_ANA_INACCESSIBLE ; } -list_add (&port->global_entry, &nvmet_ports_list); +nvmet_add_port_list (port);INIT_LIST_HEAD (&port->entry);INIT_LIST_HEAD (&port->subsystems);
drivers/nvme/target/discovery.c +3 -1
@@ -111,6 +111,7 @@ void nvmet_subsys_disc_changed(struct nvmet_subsys *subsys, {struct nvmet_port *port;struct nvmet_subsys_link *s; +struct list_head *port_list;struct nvmet_subsys *disc_subsys;lockdep_assert_held (&nvmet_config_sem);
@@ -119,7 +120,8 @@ void nvmet_subsys_disc_changed(struct nvmet_subsys *subsys,return ; disc_subsys->genctr++; -list_for_each_entry (port, nvmet_ports, global_entry) + port_list =nvmet_get_port_list (&init_net); +list_for_each_entry (port, port_list, global_entry)list_for_each_entry (s, &port->subsystems, entry) {if (s->subsys != subsys)continue ;
drivers/nvme/target/nvmet.h +0 -1
@@ -665,7 +665,6 @@ u16 nvmet_zero_sgl(struct nvmet_req *req, off_t off, size_t len);u32 nvmet_get_log_page_len (struct nvme_command *cmd);u64 nvmet_get_log_page_offset (struct nvme_command *cmd); -extern struct list_head *nvmet_ports;void nvmet_port_disc_changed (struct nvmet_port *port,struct nvmet_subsys *subsys); void nvmet_subsys_disc_changed(struct nvmet_subsys *subsys,
Signature · 1 line
2.51.0
RFC PATCH v3 11/12 nvmet: make configfs setup namespace aware
In reply to Hannes ReineckeImplement 'fill_subsystem' and 'clear_subsystem' callbacks to make nvmet configfs namespace aware.
--- drivers/nvme/target/configfs.c | 103 +++++++++++++++++++++++++++++++---------- 1 file changed, 78 insertions(+), 25 deletions(-)
drivers/nvme/target/configfs.c +78 -25
@@ -1780,6 +1780,7 @@ static void nvmet_subsys_release(struct config_item *item) {struct nvmet_subsys *subsys =to_subsys (item); +configfs_remove_default_groups (&subsys->group);nvmet_subsys_del_ctrls (subsys);nvmet_subsys_put (subsys); }
@@ -2072,6 +2073,7 @@ static void nvmet_port_release(struct config_item *item)flush_workqueue (nvmet_wq);nvmet_del_port_list (port); +configfs_remove_default_groups (&port->group);key_put (port->keyring);kfree (port->ana_state);kfree (port);
@@ -2185,9 +2187,6 @@ static const struct config_item_type nvmet_ports_type = { .ct_owner = THIS_MODULE, }; -static struct config_group nvmet_subsystems_group; -static struct config_group nvmet_ports_group; -#ifdef CONFIG_NVME_TARGET_AUTH static ssize_t nvmet_host_dhchap_key_show (struct config_item *item,char *page)
@@ -2369,8 +2368,6 @@ static const struct config_item_type nvmet_hosts_type = { .ct_owner = THIS_MODULE, }; -static struct config_group nvmet_hosts_group; -static ssize_t nvmet_root_discovery_nqn_show (struct config_item *item,char *page) {
@@ -2384,9 +2381,11 @@ static ssize_t nvmet_root_discovery_nqn_show(struct config_item *item,static ssize_t nvmet_root_discovery_nqn_store (struct config_item *item,const char *page,size_t count) { +struct config_item *subsystems_item; +struct config_group *subsystems_group;struct nvmet_subsys *disc_subsys;struct list_head *entry; -char *old_nqn, *new_nqn; +char *old_nqn =NULL , *new_nqn;size_t len; len =strcspn (page,"\n" );
@@ -2398,7 +2397,14 @@ static ssize_t nvmet_root_discovery_nqn_store(struct config_item *item,return -ENOMEM ;down_write (&nvmet_config_sem); -list_for_each (entry, &nvmet_subsystems_group.cg_children) { + subsystems_item =config_group_find_item (to_config_group (item),"subsystems" ); +if (WARN_ON (!subsystems_item)) { +kfree (new_nqn); +up_write (&nvmet_config_sem); +return -EINVAL ; + } + subsystems_group =to_config_group (subsystems_item); +list_for_each (entry, &subsystems_group->cg_children) {struct config_item *item = container_of(entry, struct config_item, ci_entry);
@@ -2432,6 +2438,69 @@ static const struct config_item_type nvmet_root_type = { .ct_owner = THIS_MODULE, }; +static int nvmet_configfs_fill_subsystem (struct configfs_subsystem *subsys, +struct net *net_ns) +{ +struct config_group *subsystems_group, *ports_group, *hosts_group; +int err; + + err =nvmet_add_disc_subsys (net_ns); +if (err <0 ) +return err; + + subsystems_group =kzalloc_obj (*subsystems_group); +if (!subsystems_group) { +nvmet_del_disc_subsys (net_ns); +return -ENOMEM ; + } +config_group_init_type_name (subsystems_group, +"subsystems" , &nvmet_subsystems_type); +configfs_add_default_group (subsystems_group, + &subsys->su_group); + + ports_group =kzalloc_obj (*ports_group); +if (!ports_group) { +kfree (subsystems_group); +nvmet_del_disc_subsys (net_ns); +return -ENOMEM ; + } +config_group_init_type_name (ports_group, +"ports" , &nvmet_ports_type); +configfs_add_default_group (ports_group, + &subsys->su_group); + + hosts_group =kzalloc_obj (*hosts_group); +if (!hosts_group) { +kfree (ports_group); +kfree (subsystems_group); +nvmet_del_disc_subsys (net_ns); +return -ENOMEM ; + } +config_group_init_type_name (hosts_group, +"hosts" , &nvmet_hosts_type); +configfs_add_default_group (hosts_group, + &subsys->su_group); +strscpy (subsys->su_group.cg_item.ci_namebuf,"nvmet" , +sizeof (subsys->su_group.cg_item.ci_namebuf)); + subsys->su_group.cg_item.ci_type = &nvmet_root_type; + +return 0 ; +} + +static void nvmet_configfs_clear_subsystem (struct configfs_subsystem *subsys, +struct net *net_ns) +{ +struct config_group *g, *n; + +list_for_each_entry_safe (g, n, &subsys->su_group.default_groups, + group_entry) { +list_del (&g->group_entry); +config_item_put (&g->cg_item); +kfree (g); + } +nvmet_del_disc_subsys (net_ns); +} +static struct configfs_subsystem nvmet_configfs_subsystem = { .su_group = { .cg_item = {
@@ -2439,30 +2508,14 @@ static struct configfs_subsystem nvmet_configfs_subsystem = { .ci_type = &nvmet_root_type, }, }, + .fill_subsystem = nvmet_configfs_fill_subsystem, + .clear_subsystem = nvmet_configfs_clear_subsystem, };int __init nvmet_init_configfs (void ) {int ret; -config_group_init (&nvmet_configfs_subsystem.su_group); -mutex_init (&nvmet_configfs_subsystem.su_mutex); - -config_group_init_type_name (&nvmet_subsystems_group, -"subsystems" , &nvmet_subsystems_type); -configfs_add_default_group (&nvmet_subsystems_group, - &nvmet_configfs_subsystem.su_group); - -config_group_init_type_name (&nvmet_ports_group, -"ports" , &nvmet_ports_type); -configfs_add_default_group (&nvmet_ports_group, - &nvmet_configfs_subsystem.su_group); - -config_group_init_type_name (&nvmet_hosts_group, -"hosts" , &nvmet_hosts_type); -configfs_add_default_group (&nvmet_hosts_group, - &nvmet_configfs_subsystem.su_group); - ret =configfs_register_subsystem (&nvmet_configfs_subsystem);if (ret) {pr_err ("configfs_register_subsystem: %d\n" , ret);
Signature · 1 line
2.51.0
RFC PATCH v3 12/12 nvmet: enable transports for net namespaces
In reply to Hannes ReineckeAdd a net_ns pointer to the port and modify the transport target drivers to select the corrent namespaces when creating ports.
--- drivers/nvme/target/configfs.c | 19 +++++++++++++------ drivers/nvme/target/core.c | 12 ++++++++++-- drivers/nvme/target/discovery.c | 13 +++++++------ drivers/nvme/target/loop.c | 4 ++++ drivers/nvme/target/nvmet.h | 3 ++- drivers/nvme/target/rdma.c | 6 +++--- drivers/nvme/target/tcp.c | 6 +++--- fs/configfs/mount.c | 16 ++++++++++++++++ include/linux/configfs.h | 2 ++ 9 files changed, 60 insertions(+), 21 deletions(-)
drivers/nvme/target/configfs.c +13 -6
@@ -71,7 +71,7 @@ struct list_head *nvmet_get_port_list(struct net *net_ns)static int nvmet_add_port_list (struct nvmet_port *p) { -u64 ns_id =nvmet_get_ns_id (&init_net); +u64 ns_id =nvmet_get_ns_id (p->net_ns);struct list_head *port_list;int err =0 ;
@@ -100,7 +100,7 @@ static int nvmet_add_port_list(struct nvmet_port *p)static void nvmet_del_port_list (struct nvmet_port *p) {struct list_head *port_list; -u64 ns_id =nvmet_get_ns_id (&init_net); +u64 ns_id =nvmet_get_ns_id (p->net_ns);xa_lock (&nvmet_ports_xa); port_list =xa_load (&nvmet_ports_xa, ns_id);
@@ -1799,13 +1799,14 @@ static struct config_group *nvmet_subsys_make(struct config_group *group, const char *name) {struct nvmet_subsys *subsys, *disc_subsys; +struct net *net_ns =configfs_ns_from_group (group);if (sysfs_streq (name,NVME_DISC_SUBSYS_NAME )) {pr_err ("can't create discovery subsystem through configfs\n" );return ERR_PTR (-EINVAL ); } - disc_subsys =nvmet_get_disc_subsys (&init_net); + disc_subsys =nvmet_get_disc_subsys (net_ns);if (!disc_subsys)return ERR_PTR (-ENOENT );if (sysfs_streq (name, disc_subsys->subsysnqn)) {
@@ -1813,7 +1814,7 @@ static struct config_group *nvmet_subsys_make(struct config_group *group,return ERR_PTR (-EINVAL ); } - subsys =nvmet_subsys_alloc (name,NVME_NQN_NVME ); + subsys =nvmet_subsys_alloc (name,NVME_NQN_NVME , net_ns);if (IS_ERR (subsys))return ERR_CAST (subsys);
@@ -2125,6 +2126,10 @@ static struct config_group *nvmet_ports_make(struct config_group *group,return ERR_PTR (-ENOMEM ); } + port->net_ns =configfs_ns_from_group (group); +if (!port->net_ns) + port->net_ns =get_net (&init_net); +if (IS_ENABLED (CONFIG_NVME_TARGET_TCP_TLS ) &&nvme_keyring_id ()) { port->keyring =key_lookup (nvme_keyring_id ());if (IS_ERR (port->keyring)) {
@@ -2371,7 +2376,8 @@ static const struct config_item_type nvmet_hosts_type = {static ssize_t nvmet_root_discovery_nqn_show (struct config_item *item,char *page) { -struct nvmet_subsys *disc_subsys =nvmet_get_disc_subsys (&init_net); +struct net *net_ns =configfs_ns_from_group (to_config_group (item)); +struct nvmet_subsys *disc_subsys =nvmet_get_disc_subsys (net_ns);if (!disc_subsys)return -ENOENT ;
@@ -2383,6 +2389,7 @@ static ssize_t nvmet_root_discovery_nqn_store(struct config_item *item, {struct config_item *subsystems_item;struct config_group *subsystems_group; +struct net *net_ns =configfs_ns_from_group (to_config_group (item));struct nvmet_subsys *disc_subsys;struct list_head *entry;char *old_nqn =NULL , *new_nqn;
@@ -2415,7 +2422,7 @@ static ssize_t nvmet_root_discovery_nqn_store(struct config_item *item,return -EINVAL ; } } - disc_subsys =nvmet_get_disc_subsys (&init_net); + disc_subsys =nvmet_get_disc_subsys (net_ns);if (disc_subsys) { old_nqn = disc_subsys->subsysnqn; disc_subsys->subsysnqn = new_nqn;
drivers/nvme/target/core.c +10 -2
@@ -1803,7 +1803,7 @@ static struct nvmet_subsys *nvmet_find_get_subsys(struct nvmet_port *port,if (!port)return NULL ; - disc_subsys =nvmet_get_disc_subsys (&init_net); + disc_subsys =nvmet_get_disc_subsys (port->net_ns);if (!disc_subsys)return NULL ;
@@ -1835,7 +1835,7 @@ static struct nvmet_subsys *nvmet_find_get_subsys(struct nvmet_port *port, }struct nvmet_subsys *nvmet_subsys_alloc (const char *subsysnqn, -enum nvme_subsys_type type) +enum nvme_subsys_type type,struct net *net_ns) {struct nvmet_subsys *subsys;char serial[NVMET_SN_MAX_SIZE /2 ];
@@ -1893,8 +1893,16 @@ struct nvmet_subsys *nvmet_subsys_alloc(const char *subsysnqn,INIT_LIST_HEAD (&subsys->ctrls);INIT_LIST_HEAD (&subsys->hosts); +/* Disable debugfs for non-initial namespaces */ +if (net_ns == &init_net) { + ret =nvmet_debugfs_subsys_setup (subsys); +if (ret) + goto free_subsysnqn; + }return subsys; +free_subsysnqn: +kfree (subsys->subsysnqn); free_fr:kfree (subsys->firmware_rev); free_mn:
drivers/nvme/target/discovery.c +7 -6
@@ -26,7 +26,7 @@ int nvmet_add_disc_subsys(struct net *net_ns)int err; disc_subsys =nvmet_subsys_alloc (NVME_DISC_SUBSYS_NAME , -NVME_NQN_CURR ); +NVME_NQN_CURR , net_ns);if (IS_ERR (disc_subsys))return PTR_ERR (disc_subsys); err = xa_insert(&nvmet_disc_xa, ns_id,
@@ -67,7 +67,7 @@ void nvmet_port_disc_changed(struct nvmet_port *port,struct nvmet_subsys *disc_subsys;lockdep_assert_held (&nvmet_config_sem); - disc_subsys =nvmet_get_disc_subsys (&init_net); + disc_subsys =nvmet_get_disc_subsys (port->net_ns);if (WARN_ON (!disc_subsys))return ; disc_subsys->genctr++;
@@ -93,7 +93,7 @@ static void __nvmet_subsys_disc_changed(struct nvmet_port *port,struct nvmet_ctrl *ctrl;struct nvmet_subsys *disc_subsys; - disc_subsys =nvmet_get_disc_subsys (&init_net); + disc_subsys =nvmet_get_disc_subsys (port->net_ns);if (WARN_ON (!disc_subsys))return ;mutex_lock (&disc_subsys->lock);
@@ -113,14 +113,15 @@ void nvmet_subsys_disc_changed(struct nvmet_subsys *subsys,struct nvmet_subsys_link *s;struct list_head *port_list;struct nvmet_subsys *disc_subsys; +struct net *net_ns =configfs_ns_from_group (&subsys->group);lockdep_assert_held (&nvmet_config_sem); - disc_subsys =nvmet_get_disc_subsys (&init_net); + disc_subsys =nvmet_get_disc_subsys (net_ns);if (WARN_ON (!disc_subsys))return ; disc_subsys->genctr++; - port_list =nvmet_get_port_list (&init_net); + port_list =nvmet_get_port_list (net_ns);list_for_each_entry (port, port_list, global_entry)list_for_each_entry (s, &port->subsystems, entry) {if (s->subsys != subsys)
@@ -257,7 +258,7 @@ static void nvmet_execute_disc_get_log_page(struct nvmet_req *req) } hdr = buffer; - disc_subsys =nvmet_get_disc_subsys (&init_net); + disc_subsys =nvmet_get_disc_subsys (req->port->net_ns);nvmet_set_disc_traddr (req, req->port, traddr);
drivers/nvme/target/loop.c +4 -0
@@ -9,6 +9,7 @@#include <linux/nvme.h> #include <linux/module.h> #include <linux/parser.h> +#include <linux/nsproxy.h> #include "nvmet.h" #include "../host/nvme.h" #include "../host/fabrics.h"
@@ -538,6 +539,9 @@ static struct nvmet_port *nvme_loop_find_port(struct nvme_ctrl *ctrl)mutex_lock (&nvme_loop_ports_mutex);list_for_each_entry (p, &nvme_loop_ports, entry) { +/* Skip ports from non-matching namespaces */ +if (p->net_ns != current->nsproxy->net_ns) +continue ;/* if no transport address is specified use the first port */ if ((ctrl->opts->mask &NVMF_OPT_TRADDR ) &&strcmp (ctrl->opts->traddr, p->disc_addr.traddr))
drivers/nvme/target/nvmet.h +2 -1
@@ -210,6 +210,7 @@ struct nvmet_port {struct nvmet_ana_group ana_default_group;enum nvme_ana_state *ana_state;struct key *keyring; +struct net *net_ns;void *priv;bool enabled;int inline_data_size;
@@ -629,7 +630,7 @@ ssize_t nvmet_ctrl_host_traddr(struct nvmet_ctrl *ctrl, char *traddr, size_t traddr_len);struct nvmet_subsys *nvmet_subsys_alloc (const char *subsysnqn, -enum nvme_subsys_type type); +enum nvme_subsys_type type,struct net *net_ns);void nvmet_subsys_put (struct nvmet_subsys *subsys);void nvmet_subsys_del_ctrls (struct nvmet_subsys *subsys);
drivers/nvme/target/rdma.c +3 -3
@@ -1870,8 +1870,8 @@ static int nvmet_rdma_enable_port(struct nvmet_rdma_port *port)struct rdma_cm_id *cm_id;int ret; - cm_id =rdma_create_id (&init_net, nvmet_rdma_cm_handler, port, -RDMA_PS_TCP ,IB_QPT_RC ); + cm_id =rdma_create_id (port->nport->net_ns, nvmet_rdma_cm_handler, + port,RDMA_PS_TCP ,IB_QPT_RC );if (IS_ERR (cm_id)) {pr_err ("CM ID creation failed\n" );return PTR_ERR (cm_id);
@@ -1964,7 +1964,7 @@ static int nvmet_rdma_add_port(struct nvmet_port *nport) nport->max_queue_size =NVME_RDMA_MAX_QUEUE_SIZE ; } - ret =inet_pton_with_scope (&init_net, af, nport->disc_addr.traddr, + ret =inet_pton_with_scope (nport->net_ns, af, nport->disc_addr.traddr, nport->disc_addr.trsvcid, &port->addr);if (ret) { pr_err("malformed ip/port passed: %s:%s\n",
drivers/nvme/target/tcp.c +3 -3
@@ -2074,7 +2074,7 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport) goto err_port; } - ret =inet_pton_with_scope (&init_net, af, nport->disc_addr.traddr, + ret =inet_pton_with_scope (nport->net_ns, af, nport->disc_addr.traddr, nport->disc_addr.trsvcid, &port->addr);if (ret) { pr_err("malformed ip/port passed: %s:%s\n",
@@ -2087,8 +2087,8 @@ static int nvmet_tcp_add_port(struct nvmet_port *nport)if (port->nport->inline_data_size <0 ) port->nport->inline_data_size =NVMET_TCP_DEF_INLINE_DATA_SIZE ; - ret =sock_create (port->addr.ss_family,SOCK_STREAM , -IPPROTO_TCP , &port->sock); + ret =sock_create_kern (nport->net_ns, port->addr.ss_family,SOCK_STREAM , +IPPROTO_TCP , &port->sock);if (ret) {pr_err ("failed to create a socket\n" ); goto err_port;
fs/configfs/mount.c +16 -0
@@ -276,6 +276,22 @@ void configfs_release_fs(struct super_block *sb)mntput (mnt); } +struct net *configfs_ns_from_group (struct config_group *group) +{ +struct configfs_super_info *info = configfs_root; +struct net *net_ns =NULL ; + +if (group) { +struct dentry *dentry = group->cg_item.ci_dentry; + + info = dentry->d_sb->s_fs_info; +if (info) + net_ns = info->net_ns; + } +return net_ns; +} +EXPORT_SYMBOL_GPL (configfs_ns_from_group); +static int __init configfs_init (void ) {int err = -ENOMEM ;
include/linux/configfs.h +2 -0
@@ -258,6 +258,8 @@ configfs_register_default_group(struct config_group *parent_group, const struct config_item_type *item_type);void configfs_unregister_default_group (struct config_group *group); +struct net *configfs_ns_from_group (struct config_group *group); +/* These functions can sleep and can alloc with GFP_KERNEL */ /* WARNING: These cannot be called underneath configfs callbacks!! */ int configfs_depend_item(struct configfs_subsystem *subsys,
Signature · 1 line
2.51.0
syzbot ci has tested the following series
syzbot ci has tested the following series
[v3] namespace-aware configfs
https://lore.kernel.org/all/[email protected]
* [PATCH RFC v3 01/12] fs/configfs: rework configfs_is_root()
* [PATCH RFC v3 02/12] fs/configfs: dynamically allocate super_info
* [PATCH RFC v3 03/12] fs/configfs: separate out configfs_{link,unlink}_root()
* [PATCH RFC v3 04/12] fs/configfs: add superblock as attribute to configfs_pin_fs()
* [PATCH RFC v3 05/12] fs/configfs: add 'fill_subsystem' and 'clear_subsystem' callbacks
* [PATCH RFC v3 06/12] fs/namespace: implement mnt_clone_direct()
* [PATCH RFC v3 07/12] fs/configfs: switch to get_tree_keyed()
* [PATCH RFC v3 08/12] fs/configfs: open-code simple_pin_fs()
* [PATCH RFC v3 09/12] nvmet: make discovery subsystem dynamic
* [PATCH RFC v3 10/12] nvmet: per net-namespace port list
* [PATCH RFC v3 11/12] nvmet: make configfs setup namespace aware
* [PATCH RFC v3 12/12] nvmet: enable transports for net namespaces
and found the following issue:
BUG: sleeping function called from invalid context in configfs_get_super_info
Full report is available here:
https://ci.syzbot.org/series/f460be5a-d520-4bc1-9cfb-6492f841629b
***
BUG: sleeping function called from invalid context in configfs_get_super_info
tree: bpf-next URL: https://kernel.googlesource.com/pub/scm/linux/kernel/git/bpf/bpf-next.git base: 66affa37cfac0aec061cc4bcf4a065b0c52f7e19 arch: amd64 compiler: Debian clang version 22.1.6 (++20260514074242+fc4aad7b5db3-1~exp1~20260514074407.73), Debian LLD 22.1.6 config: https://ci.syzbot.org/builds/73803fa0-5ba4-4d03-976f-f9962ee982c8/config syz repro: https://ci.syzbot.org/findings/4102267c-e678-4ffc-9ac0-4fb2dcbe5c0d/syz_repro
BUG: sleeping function called from invalid context at ./include/linux/sched/mm.h:323
in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 5856, name: syz.0.17preempt_count: 1, expected: 0
RCU nest depth: 0, expected: 0
INFO: lockdep is turned off.
Preemption disabled at:
[<0000000000000000>] 0x0
CPU: 0 UID: 0 PID: 5856 Comm: syz.0.17 Tainted: G W syzkaller #0 PREEMPT(full) Tainted: [W]=WARN Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.2-debian-1.16.2-1 04/01/2014 Call Trace: <TASK> dump_stack_lvl+0xe8/0x150 lib/dump_stack.c:120 __might_resched+0x378/0x4d0 kernel/sched/core.c:9193 might_alloc include/linux/sched/mm.h:323 [inline] slab_pre_alloc_hook mm/slub.c:4559 [inline] slab_alloc_node mm/slub.c:4916 [inline] __kmalloc_cache_noprof+0x74/0x660 mm/slub.c:5446 _kmalloc_noprof include/linux/slab.h:969 [inline] _kzalloc_noprof include/linux/slab.h:1286 [inline] configfs_get_super_info+0x218/0x5e0 fs/configfs/mount.c:91 configfs_get_tree+0x41/0xd0 fs/configfs/mount.c:170 vfs_get_tree+0x92/0x2a0 fs/super.c:1694 vfs_cmd_create+0xa2/0x200 fs/fsopen.c:231 __do_sys_fsconfig fs/fsopen.c:463 [inline] __se_sys_fsconfig+0x6b9/0x810 fs/fsopen.c:350 do_syscall_x64 arch/x86/entry/syscall_64.c:63 [inline] do_syscall_64+0x174/0x580 arch/x86/entry/syscall_64.c:94 entry_SYSCALL_64_after_hwframe+0x77/0x7f RIP: 0033:0x7f5c9db9ce59 Code: ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 e8 ff ff ff f7 d8 64 89 01 48 RSP: 002b:00007f5c9ea71028 EFLAGS: 00000246 ORIG_RAX: 00000000000001af RAX: ffffffffffffffda RBX: 00007f5c9de15fa0 RCX: 00007f5c9db9ce59 RDX: 0000000000000000 RSI: 0000000000000006 RDI: 0000000000000003 RBP: 00007f5c9dc32e6f R08: 0000000000000000 R09: 0000000000000000 R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000 R13: 00007f5c9de16038 R14: 00007f5c9de15fa0 R15: 00007ffe63465d98 </TASK>
***
If these findings have caused you to resend the series or submit a separate fix, please add the following tag to your commit message:
---
This report is generated by a bot. It may contain errors. syzbot ci engineers can be reached at [email protected].
To test a patch for this bug, please reply with #syz test (should be on a separate line).
The patch should be attached to the email.
Note: arguments like custom git repos and branches are not supported.