From: Guixin Liu <kanie@linux.alibaba.com>
To: Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
Chaitanya Kulkarni <kch@nvidia.com>,
Hannes Reinecke <hare@suse.com>
Cc: linux-nvme@lists.infradead.org
Subject: [PATCH 1/2] nvmet: add namespace-level debugfs directory
Date: Mon, 22 Jun 2026 18:44:17 +0800 [thread overview]
Message-ID: <20260622104418.2070277-2-kanie@linux.alibaba.com> (raw)
In-Reply-To: <20260622104418.2070277-1-kanie@linux.alibaba.com>
Add per-namespace debugfs directory support under the subsystem debugfs
directory. Each enabled namespace gets a ns<nsid>/ directory created
during nvmet_ns_enable() and removed during nvmet_ns_disable().
This provides the infrastructure for exposing namespace-specific debug
information in subsequent patches.
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
drivers/nvme/target/core.c | 2 ++
drivers/nvme/target/debugfs.c | 21 +++++++++++++++++++++
drivers/nvme/target/debugfs.h | 5 +++++
drivers/nvme/target/nvmet.h | 3 +++
4 files changed, 31 insertions(+)
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 62dd59b9aa4f..9752913e05c6 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -616,6 +616,7 @@ int nvmet_ns_enable(struct nvmet_ns *ns)
nvmet_ns_changed(subsys, ns->nsid);
ns->enabled = true;
xa_set_mark(&subsys->namespaces, ns->nsid, NVMET_NS_ENABLED);
+ nvmet_debugfs_ns_setup(ns);
ret = 0;
out_unlock:
mutex_unlock(&subsys->lock);
@@ -642,6 +643,7 @@ void nvmet_ns_disable(struct nvmet_ns *ns)
ns->enabled = false;
xa_clear_mark(&subsys->namespaces, ns->nsid, NVMET_NS_ENABLED);
+ nvmet_debugfs_ns_free(ns);
list_for_each_entry(ctrl, &subsys->ctrls, subsys_entry)
pci_dev_put(radix_tree_delete(&ctrl->p2p_ns_map, ns->nsid));
diff --git a/drivers/nvme/target/debugfs.c b/drivers/nvme/target/debugfs.c
index 5dcbd5aa86e1..e6f51eb59010 100644
--- a/drivers/nvme/target/debugfs.c
+++ b/drivers/nvme/target/debugfs.c
@@ -153,6 +153,27 @@ static int nvmet_ctrl_tls_concat_show(struct seq_file *m, void *p)
NVMET_DEBUGFS_ATTR(nvmet_ctrl_tls_concat);
#endif
+void nvmet_debugfs_ns_setup(struct nvmet_ns *ns)
+{
+ char name[16];
+ struct dentry *parent = ns->subsys->debugfs_dir;
+
+ if (!parent)
+ return;
+ snprintf(name, sizeof(name), "ns%u", ns->nsid);
+ ns->debugfs_dir = debugfs_create_dir(name, parent);
+ if (IS_ERR(ns->debugfs_dir)) {
+ ns->debugfs_dir = NULL;
+ return;
+ }
+}
+
+void nvmet_debugfs_ns_free(struct nvmet_ns *ns)
+{
+ debugfs_remove_recursive(ns->debugfs_dir);
+ ns->debugfs_dir = NULL;
+}
+
int nvmet_debugfs_ctrl_setup(struct nvmet_ctrl *ctrl)
{
char name[32];
diff --git a/drivers/nvme/target/debugfs.h b/drivers/nvme/target/debugfs.h
index cfb8bbf6a297..b559d254fc2a 100644
--- a/drivers/nvme/target/debugfs.h
+++ b/drivers/nvme/target/debugfs.h
@@ -14,6 +14,8 @@ int nvmet_debugfs_subsys_setup(struct nvmet_subsys *subsys);
void nvmet_debugfs_subsys_free(struct nvmet_subsys *subsys);
int nvmet_debugfs_ctrl_setup(struct nvmet_ctrl *ctrl);
void nvmet_debugfs_ctrl_free(struct nvmet_ctrl *ctrl);
+void nvmet_debugfs_ns_setup(struct nvmet_ns *ns);
+void nvmet_debugfs_ns_free(struct nvmet_ns *ns);
int __init nvmet_init_debugfs(void);
void nvmet_exit_debugfs(void);
@@ -30,6 +32,9 @@ static inline int nvmet_debugfs_ctrl_setup(struct nvmet_ctrl *ctrl)
}
static inline void nvmet_debugfs_ctrl_free(struct nvmet_ctrl *ctrl) {}
+static inline void nvmet_debugfs_ns_setup(struct nvmet_ns *ns) {}
+static inline void nvmet_debugfs_ns_free(struct nvmet_ns *ns) {}
+
static inline int __init nvmet_init_debugfs(void)
{
return 0;
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 3305a88684ec..142a78d9160f 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -128,6 +128,9 @@ struct nvmet_ns {
u8 csi;
struct nvmet_pr pr;
struct xarray pr_per_ctrl_refs;
+#ifdef CONFIG_NVME_TARGET_DEBUGFS
+ struct dentry *debugfs_dir;
+#endif
};
static inline struct nvmet_ns *to_nvmet_ns(struct config_item *item)
--
2.43.7
next prev parent reply other threads:[~2026-06-22 10:44 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-22 10:44 [PATCH 0/2] nvmet: add namespace-level debugfs for reservation state Guixin Liu
2026-06-22 10:44 ` Guixin Liu [this message]
2026-06-22 10:44 ` [PATCH 2/2] nvmet: expose reservation state through debugfs Guixin Liu
2026-06-25 7:17 ` [PATCH 0/2] nvmet: add namespace-level debugfs for reservation state Daniel Wagner
2026-06-25 9:10 ` Guixin Liu
2026-07-06 3:10 ` Guixin Liu
2026-07-06 7:59 ` Daniel Wagner
2026-07-06 10:28 ` Guixin Liu
2026-07-06 12:57 ` Shin'ichiro Kawasaki
2026-07-07 1:42 ` Guixin Liu
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=20260622104418.2070277-2-kanie@linux.alibaba.com \
--to=kanie@linux.alibaba.com \
--cc=hare@suse.com \
--cc=hch@lst.de \
--cc=kch@nvidia.com \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.