Skip to content

Commit 8d6a987

Browse files
shroffniigaw
authored andcommitted
nvme: support <device> option in show-topology command
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 <[email protected]> Signed-off-by: Nilay Shroff <[email protected]> Signed-off-by: Daniel Wagner <[email protected]>
1 parent 16e5d26 commit 8d6a987

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

nvme-print-stdout.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5683,6 +5683,15 @@ static void stdout_simple_topology(nvme_root_t r,
56835683

56845684
nvme_for_each_host(r, h) {
56855685
nvme_for_each_subsystem(h, s) {
5686+
bool no_ctrl = true;
5687+
nvme_ctrl_t c;
5688+
5689+
nvme_subsystem_for_each_ctrl(s, c)
5690+
no_ctrl = false;
5691+
5692+
if (no_ctrl)
5693+
continue;
5694+
56865695
if (!first)
56875696
printf("\n");
56885697
first = false;

nvme.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10207,6 +10207,8 @@ static int show_topology_cmd(int argc, char **argv, struct command *command, str
1020710207
const char *ranking = "Ranking order: namespace|ctrl";
1020810208
nvme_print_flags_t flags;
1020910209
_cleanup_nvme_root_ nvme_root_t r = NULL;
10210+
char *devname = NULL;
10211+
nvme_scan_filter_t filter = NULL;
1021010212
enum nvme_cli_topo_ranking rank;
1021110213
int err;
1021210214

@@ -10249,7 +10251,20 @@ static int show_topology_cmd(int argc, char **argv, struct command *command, str
1024910251
return -errno;
1025010252
}
1025110253

10252-
err = nvme_scan_topology(r, NULL, NULL);
10254+
if (optind < argc)
10255+
devname = basename(argv[optind++]);
10256+
10257+
if (devname) {
10258+
int subsys_id, nsid;
10259+
10260+
if (sscanf(devname, "nvme%dn%d", &subsys_id, &nsid) != 2) {
10261+
nvme_show_error("Invalid device name %s\n", devname);
10262+
return -EINVAL;
10263+
}
10264+
filter = nvme_match_device_filter;
10265+
}
10266+
10267+
err = nvme_scan_topology(r, filter, (void *)devname);
1025310268
if (err < 0) {
1025410269
nvme_show_error("Failed to scan topology: %s", nvme_strerror(errno));
1025510270
return err;

0 commit comments

Comments
 (0)