[PATCH 8/8] nvmet: add debugfs support for queues

Hannes Reinecke hare at kernel.org
Fri Mar 22 00:03:33 PDT 2024


Add debugfs entries to display the status of the controller
queues.

Signed-off-by: Hannes Reinecke <hare at kernel.org>
---
 drivers/nvme/target/core.c    |  2 ++
 drivers/nvme/target/debugfs.c | 49 +++++++++++++++++++++++++++++++++++
 drivers/nvme/target/debugfs.h |  8 ++++++
 drivers/nvme/target/nvmet.h   |  3 +++
 4 files changed, 62 insertions(+)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 4955819e4f5f..694e91cdfc8d 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -791,6 +791,7 @@ void nvmet_sq_setup(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq,
 	sq->size = size;
 
 	ctrl->sqs[qid] = sq;
+	nvmet_debugfs_queue_setup(ctrl, sq);
 }
 
 static void nvmet_confirm_sq(struct percpu_ref *ref)
@@ -815,6 +816,7 @@ void nvmet_sq_destroy(struct nvmet_sq *sq)
 	wait_for_completion(&sq->free_done);
 	percpu_ref_exit(&sq->ref);
 	nvmet_auth_sq_free(sq);
+	nvmet_debugfs_queue_free(sq);
 
 	if (ctrl) {
 		/*
diff --git a/drivers/nvme/target/debugfs.c b/drivers/nvme/target/debugfs.c
index 40eeac97157a..a8fec34f36d4 100644
--- a/drivers/nvme/target/debugfs.c
+++ b/drivers/nvme/target/debugfs.c
@@ -35,6 +35,55 @@ struct dentry *nvmet_debugfs;
 		.release = single_release, \
 	}
 
+static int nvmet_queue_sqsize_show(struct seq_file *m, void *p)
+{
+	struct nvmet_sq *sq = (struct nvmet_sq *)m->private;
+
+	seq_printf(m, "%d\n", sq->size);
+	return 0;
+}
+NVMET_DEBUGFS_ATTR(nvmet_queue_sqsize);
+
+static int nvmet_queue_sqhead_show(struct seq_file *m, void *p)
+{
+	struct nvmet_sq *sq = (struct nvmet_sq *)m->private;
+	u32 sqhd = READ_ONCE(sq->sqhd);
+
+	if (sq->sqhd_disabled)
+		seq_puts(m, "disabled\n");
+	else
+		seq_printf(m, "%u\n", sqhd & 0x0000FFFF);
+	return 0;
+}
+NVMET_DEBUGFS_ATTR(nvmet_queue_sqhead);
+
+int nvmet_debugfs_queue_setup(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq)
+{
+	char name[32];
+	struct dentry *parent = ctrl->debugfs_dir, *queue_dir;
+
+	if (!parent)
+		return -ENODEV;
+	if (!sq)
+		return -EINVAL;
+	snprintf(name, sizeof(name), "queue%d", sq->qid);
+	queue_dir = debugfs_create_dir(name, parent);
+	if (IS_ERR(queue_dir))
+		return PTR_ERR(queue_dir);
+	sq->debugfs_dir = queue_dir;
+	debugfs_create_file("sqsize", S_IRUSR, queue_dir,
+			    sq, &nvmet_queue_sqsize_fops);
+	debugfs_create_file("sqhead", S_IRUSR, queue_dir,
+			    sq, &nvmet_queue_sqhead_fops);
+	return 0;
+}
+
+void nvmet_debugfs_queue_free(struct nvmet_sq *sq)
+{
+	debugfs_remove_recursive(sq->debugfs_dir);
+	sq->debugfs_dir = NULL;
+}
+
 static int nvmet_ctrl_hostnqn_show(struct seq_file *m, void *p)
 {
 	struct nvmet_ctrl *ctrl = (struct nvmet_ctrl *)m->private;
diff --git a/drivers/nvme/target/debugfs.h b/drivers/nvme/target/debugfs.h
index ff09e5597614..5192f8012b79 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);
+int nvmet_debugfs_queue_setup(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq);
+void nvmet_debugfs_queue_free(struct nvmet_sq *sq);
 
 int __init nvmet_init_debugfs(void);
 void nvmet_exit_debugfs(void);
@@ -30,6 +32,12 @@ static inline int nvmet_debugfs_ctrl_setup(struct nvmet_ctrl *ctrl)
 }
 static inline void nvmet_debugfs_ctrl_free(struct nvmet_ctrl *ctrl) {}
 
+static inline int nvmet_debugfs_sq_setup(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq)
+{
+	return 0;
+}
+static inline void nvmet_debugfs_sq_free(struct nvmet_sq *sq) {}
+
 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 3b7ba6d656cf..a6c2b106ba1c 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -109,6 +109,9 @@ struct nvmet_sq {
 	u16			size;
 	u32			sqhd;
 	bool			sqhd_disabled;
+#ifdef CONFIG_NVME_TARGET_DEBUGFS
+	struct dentry		*debugfs_dir;
+#endif
 #ifdef CONFIG_NVME_TARGET_AUTH
 	bool			authenticated;
 	struct delayed_work	auth_expired_work;
-- 
2.35.3




More information about the Linux-nvme mailing list