From: Hannes Reinecke <hare@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Keith Busch <kbusch@kernel.org>, Sagi Grimberg <sagi@grimberg.me>,
James Smart <james.smart@broadcom.com>,
linux-nvme@lists.infradead.org, Hannes Reinecke <hare@kernel.org>
Subject: [PATCH 2/7] nvmet: add debugfs support for queues
Date: Wed, 20 Mar 2024 15:40:12 +0100 [thread overview]
Message-ID: <20240320144017.106283-3-hare@kernel.org> (raw)
In-Reply-To: <20240320144017.106283-1-hare@kernel.org>
Add debugfs entries to display the status of the controller
queues.
Signed-off-by: Hannes Reinecke <hare@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
next prev parent reply other threads:[~2024-03-20 14:40 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-20 14:40 [PATCHv2 0/7] nvmet: debugfs support Hannes Reinecke
2024-03-20 14:40 ` [PATCH 1/7] nvmet: add " Hannes Reinecke
2024-03-20 14:40 ` Hannes Reinecke [this message]
2024-03-20 14:40 ` [PATCH 3/7] nvmet-tcp: implement queue_peer_traddr() Hannes Reinecke
2024-03-20 23:11 ` Sagi Grimberg
2024-03-21 6:56 ` Hannes Reinecke
2024-03-20 14:40 ` [PATCH 4/7] nvmet-rdma: " Hannes Reinecke
2024-03-20 14:40 ` [PATCH 5/7] nvmet-fc: " Hannes Reinecke
2024-03-20 14:40 ` [PATCH 6/7] nvme-fcloop: implement 'host_traddr' Hannes Reinecke
2024-03-20 14:40 ` [PATCH 7/7] lpfc_nvmet: " Hannes Reinecke
2024-03-20 23:07 ` [PATCHv2 0/7] nvmet: debugfs support Sagi Grimberg
2024-03-21 6:55 ` Hannes Reinecke
2024-03-21 8:59 ` Sagi Grimberg
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=20240320144017.106283-3-hare@kernel.org \
--to=hare@kernel.org \
--cc=hch@lst.de \
--cc=james.smart@broadcom.com \
--cc=kbusch@kernel.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox