[PATCH RFC 1/1] nvme-multipath: Add debugfs entry for showing multipath info
Nilay Shroff
nilay at linux.ibm.com
Mon Jul 22 02:31:10 PDT 2024
NVMe native multipath supports different io policies for selecting
I/O path, however, we don't have any visibility about which path is
being selected by multipath code for forwarding I/O. This patch helps
add that visibility by adding a debugfs file for each head disk node
on the system. It creates a file named "multipath" under
"/sys/kernel/debug/block/nvmeXnY/". This file shows the information
about current selected "io-policy" as well as it prints a "table"
showing information about each online node and it's respective I/O
path, controller name, ana-state and optionally queue depth of each
path (if selected io-policy is queue-depth).
Signed-off-by: Nilay Shroff <nilay at linux.ibm.com>
---
drivers/nvme/host/multipath.c | 90 +++++++++++++++++++++++++++++++++++
drivers/nvme/host/nvme.h | 1 +
2 files changed, 91 insertions(+)
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 91d9eb3c22ef..143d4b279b43 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -6,6 +6,7 @@
#include <linux/backing-dev.h>
#include <linux/moduleparam.h>
#include <linux/vmalloc.h>
+#include <linux/debugfs.h>
#include <trace/events/block.h>
#include "nvme.h"
@@ -628,6 +629,91 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head)
ctrl->subsys->instance, head->instance);
return 0;
}
+static void nvme_mpath_numa_show(struct seq_file *m, struct nvme_ns_head *head)
+{
+ int node;
+ struct nvme_ns *ns;
+
+ seq_printf(m, "%-4s %-12s %-6s %s\n",
+ "node", "current-path", "ctrl", "ana-state");
+
+ for_each_online_node(node) {
+ ns = srcu_dereference(head->current_path[node], &head->srcu);
+ if (ns)
+ seq_printf(m, "%-4d %-12s %-6s %s\n",
+ node, ns->disk->disk_name,
+ dev_name(ns->ctrl->device),
+ nvme_ana_state_names[ns->ana_state]);
+ }
+}
+
+static void nvme_mpath_rr_show(struct seq_file *m, struct nvme_ns_head *head)
+{
+ int node;
+ struct nvme_ns *ns;
+
+ seq_printf(m, "%-4s %-12s %-6s %s\n",
+ "node", "rr-path", "ctrl", "ana-state");
+
+ for_each_online_node(node) {
+ list_for_each_entry_rcu(ns, &head->list, siblings) {
+ seq_printf(m, "%-4d %-12s %-6s %s\n",
+ node, ns->disk->disk_name,
+ dev_name(ns->ctrl->device),
+ nvme_ana_state_names[ns->ana_state]);
+ }
+ }
+}
+
+static void nvme_mpath_qd_show(struct seq_file *m, struct nvme_ns_head *head)
+{
+ int node;
+ struct nvme_ns *ns;
+
+ seq_printf(m, "%-4s %-12s %-6s %-10s %s\n",
+ "node", "path", "ctrl", "qdepth", "ana-state");
+
+ for_each_online_node(node) {
+ list_for_each_entry_rcu(ns, &head->list, siblings) {
+ seq_printf(m, "%-4d %-12s %-6s %-10d %s\n",
+ node, ns->disk->disk_name,
+ dev_name(ns->ctrl->device),
+ atomic_read(&ns->ctrl->nr_active),
+ nvme_ana_state_names[ns->ana_state]);
+
+ }
+ }
+}
+
+static int nvme_mpath_show(struct seq_file *m, void *p)
+{
+ struct nvme_ns_head *head = m->private;
+ int iopolicy = READ_ONCE(head->subsys->iopolicy);
+
+ seq_printf(m, "io-policy: %s\n", nvme_iopolicy_names[iopolicy]);
+
+ seq_puts(m, "io-path:\n");
+ seq_puts(m, "--------\n");
+
+ if (iopolicy == NVME_IOPOLICY_NUMA)
+ nvme_mpath_numa_show(m, head);
+ else if (iopolicy == NVME_IOPOLICY_RR)
+ nvme_mpath_rr_show(m, head);
+ else if (iopolicy == NVME_IOPOLICY_QD)
+ nvme_mpath_qd_show(m, head);
+
+ return 0;
+}
+
+static int nvme_mpath_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, nvme_mpath_show, inode->i_private);
+}
+static const struct file_operations nvme_mpath_fops = {
+ .open = nvme_mpath_open,
+ .read = seq_read,
+ .release = single_release
+};
static void nvme_mpath_set_live(struct nvme_ns *ns)
{
@@ -650,6 +736,9 @@ static void nvme_mpath_set_live(struct nvme_ns *ns)
return;
}
nvme_add_ns_head_cdev(head);
+ head->debugfs = debugfs_create_file("multipath", 0400,
+ head->disk->queue->debugfs_dir, head,
+ &nvme_mpath_fops);
}
mutex_lock(&head->lock);
@@ -969,6 +1058,7 @@ void nvme_mpath_shutdown_disk(struct nvme_ns_head *head)
return;
kblockd_schedule_work(&head->requeue_work);
if (test_bit(NVME_NSHEAD_DISK_LIVE, &head->flags)) {
+ debugfs_remove(head->debugfs);
nvme_cdev_del(&head->cdev, &head->cdev_device);
del_gendisk(head->disk);
}
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index f900e44243ae..5b4c0b70cedf 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -493,6 +493,7 @@ struct nvme_ns_head {
struct work_struct requeue_work;
struct mutex lock;
unsigned long flags;
+ struct dentry *debugfs;
#define NVME_NSHEAD_DISK_LIVE 0
struct nvme_ns __rcu *current_path[];
#endif
--
2.45.2
More information about the Linux-nvme
mailing list