[PATCH 2/7] nvmet: add debugfs support for queues

Hannes Reinecke hare at kernel.org
Wed Mar 20 07:40:12 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    | 10 ++++++
 drivers/nvme/target/debugfs.c | 68 +++++++++++++++++++++++++++++++++++
 drivers/nvme/target/debugfs.h |  2 ++
 drivers/nvme/target/nvmet.h   |  7 ++++
 4 files changed, 87 insertions(+)

diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index 6cd1b92fc500..66c31ff04ce5 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) {
 		/*
@@ -855,6 +857,14 @@ int nvmet_sq_init(struct nvmet_sq *sq)
 }
 EXPORT_SYMBOL_GPL(nvmet_sq_init);
 
+ssize_t nvmet_sq_peeraddr(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq,
+		char *traddr, size_t traddr_len)
+{
+	if (!ctrl->ops->queue_peertraddr)
+		return -EOPNOTSUPP;
+	return ctrl->ops->queue_peertraddr(ctrl, sq, traddr, traddr_len);
+}
+
 static inline u16 nvmet_check_ana_state(struct nvmet_port *port,
 		struct nvmet_ns *ns)
 {
diff --git a/drivers/nvme/target/debugfs.c b/drivers/nvme/target/debugfs.c
index 4b9451ad0db9..0c72dc631cd9 100644
--- a/drivers/nvme/target/debugfs.c
+++ b/drivers/nvme/target/debugfs.c
@@ -35,6 +35,74 @@ 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);
+
+static int nvmet_queue_peer_traddr_show(struct seq_file *m, void *p)
+{
+	struct nvmet_sq *sq = (struct nvmet_sq *)m->private;
+	ssize_t size;
+	char buf[NVMF_TRADDR_SIZE + 1];
+
+	size = nvmet_sq_peeraddr(sq->ctrl, sq, buf, NVMF_TRADDR_SIZE);
+	if (size < 0) {
+		buf[0] = '\0';
+		size = 0;
+	}
+	buf[size] = '\0';
+	seq_printf(m, "%s\n", buf);
+	return 0;
+}
+NVMET_DEBUGFS_ATTR(nvmet_queue_peer_traddr);
+
+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("host_traddr", S_IRUSR, queue_dir,
+			    sq, &nvmet_queue_peer_traddr_fops);
+	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 a2c6a949ff0f..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);
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index f0371163cb26..fae6493fd87a 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;
@@ -365,6 +368,8 @@ struct nvmet_fabrics_ops {
 	void (*discovery_chg)(struct nvmet_port *port);
 	u8 (*get_mdts)(const struct nvmet_ctrl *ctrl);
 	u16 (*get_max_queue_size)(const struct nvmet_ctrl *ctrl);
+	ssize_t (*queue_peertraddr)(struct nvmet_ctrl *ctrl,
+			struct nvmet_sq *sq, char *traddr, size_t traddr_len);
 };
 
 #define NVMET_MAX_INLINE_BIOVEC	8
@@ -498,6 +503,8 @@ void nvmet_sq_setup(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, u16 qid,
 		u16 size);
 void nvmet_sq_destroy(struct nvmet_sq *sq);
 int nvmet_sq_init(struct nvmet_sq *sq);
+ssize_t nvmet_sq_peeraddr(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq,
+		char *traddr, size_t traddr_len);
 
 void nvmet_ctrl_fatal_error(struct nvmet_ctrl *ctrl);
 
-- 
2.35.3




More information about the Linux-nvme mailing list