From: Nilay Shroff <nilay@linux.ibm.com>
To: linux-nvme@lists.infradead.org
Cc: dwagner@suse.de, hare@suse.de, kbusch@kernel.org, gjoyce@ibm.com
Subject: [PATCHv3 1/4] nvme: support <device> option in show-topology command
Date: Thu, 4 Sep 2025 23:26:48 +0530 [thread overview]
Message-ID: <20250904175654.1183750-2-nilay@linux.ibm.com> (raw)
In-Reply-To: <20250904175654.1183750-1-nilay@linux.ibm.com>
Although the help text for the nvme show-topology command indicates
support for a <device> option, this option has no effect in practice
— specifying an NVMe device name does not filter the output.
This commit adds proper support for the <device> option, enabling users
to filter the topology output based on the specified NVMe device.
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Nilay Shroff <nilay@linux.ibm.com>
---
nvme-print-stdout.c | 9 +++++++++
nvme.c | 17 ++++++++++++++++-
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/nvme-print-stdout.c b/nvme-print-stdout.c
index c597b608..eb56349a 100644
--- a/nvme-print-stdout.c
+++ b/nvme-print-stdout.c
@@ -5683,6 +5683,15 @@ static void stdout_simple_topology(nvme_root_t r,
nvme_for_each_host(r, h) {
nvme_for_each_subsystem(h, s) {
+ bool no_ctrl = true;
+ nvme_ctrl_t c;
+
+ nvme_subsystem_for_each_ctrl(s, c)
+ no_ctrl = false;
+
+ if (no_ctrl)
+ continue;
+
if (!first)
printf("\n");
first = false;
diff --git a/nvme.c b/nvme.c
index b3cd538b..f17a8091 100644
--- a/nvme.c
+++ b/nvme.c
@@ -10182,6 +10182,8 @@ static int show_topology_cmd(int argc, char **argv, struct command *command, str
const char *ranking = "Ranking order: namespace|ctrl";
nvme_print_flags_t flags;
_cleanup_nvme_root_ nvme_root_t r = NULL;
+ char *devname = NULL;
+ nvme_scan_filter_t filter = NULL;
enum nvme_cli_topo_ranking rank;
int err;
@@ -10224,7 +10226,20 @@ static int show_topology_cmd(int argc, char **argv, struct command *command, str
return -errno;
}
- err = nvme_scan_topology(r, NULL, NULL);
+ if (optind < argc)
+ devname = basename(argv[optind++]);
+
+ if (devname) {
+ int subsys_id, nsid;
+
+ if (sscanf(devname, "nvme%dn%d", &subsys_id, &nsid) != 2) {
+ nvme_show_error("Invalid device name %s\n", devname);
+ return -EINVAL;
+ }
+ filter = nvme_match_device_filter;
+ }
+
+ err = nvme_scan_topology(r, filter, (void *)devname);
if (err < 0) {
nvme_show_error("Failed to scan topology: %s", nvme_strerror(errno));
return err;
--
2.51.0
next prev parent reply other threads:[~2025-09-04 20:31 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-04 17:56 [PATCHv3 0/4] nvme-cli: enhance the visibility of multipath using show-topology command Nilay Shroff
2025-09-04 17:56 ` Nilay Shroff [this message]
2025-09-04 17:56 ` [PATCHv3 2/4] nvme: extend show-topology command to add support for multipath Nilay Shroff
2025-09-08 12:53 ` Hannes Reinecke
2025-09-04 17:56 ` [PATCHv3 3/4] nvme: add common APIs for printing tabular format output Nilay Shroff
2025-09-04 17:56 ` [PATCHv3 4/4] nvme: add support for printing show-topology in tabular form Nilay Shroff
2025-09-21 12:11 ` [PATCHv3 0/4] nvme-cli: enhance the visibility of multipath using show-topology command Nilay Shroff
2025-09-22 9:41 ` Daniel Wagner
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=20250904175654.1183750-2-nilay@linux.ibm.com \
--to=nilay@linux.ibm.com \
--cc=dwagner@suse.de \
--cc=gjoyce@ibm.com \
--cc=hare@suse.de \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
/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