Skip to content

Commit d94dae3

Browse files
brgoingigaw
authored andcommitted
nvme-print: Update generic name listing to be platform independent
Refactors generic path discover in nvme-print and nvme-print-stdout to fall back to using livnvme_ns_get_generic name. Allows platform independent generic name behavior, and removes duplicated "ng%dn%d" string building on Linux. Also widens Generic list section of detailed list slightly to provide enough space for Windows generic names. Signed-off-by: Broc Going <bgoing@micron.com>
1 parent a95821f commit d94dae3

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

nvme-print-stdout.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5646,7 +5646,7 @@ static void stdout_generic_full_path(libnvme_ns_t n, char *path, size_t len)
56465646
* We could start trying to search for it but let's make
56475647
* it simple and just don't show the path at all.
56485648
*/
5649-
snprintf(path, len, "ng%dn%d", instance, head_instance);
5649+
snprintf(path, len, "%s", libnvme_ns_get_generic_name(n));
56505650
}
56515651

56525652
static void list_item(libnvme_ns_t n, struct table *t)
@@ -5797,7 +5797,7 @@ static void stdout_ns_details(libnvme_ns_t n)
57975797
nvme_dev_full_path(n, devname, sizeof(devname));
57985798
nvme_generic_full_path(n, genname, sizeof(genname));
57995799

5800-
printf("%-17s %-17s %#-10x %-21s %-25s %-16s ", devname,
5800+
printf("%-17s %-20s %#-10x %-21s %-25s %-16s ", devname,
58015801
genname, libnvme_ns_get_nsid(n), usage, usage_binary, format);
58025802
}
58035803

@@ -5955,9 +5955,9 @@ static void stdout_detailed_list(struct libnvme_global_ctx *ctx)
59555955
strset_iterate(&res.ctrls, stdout_detailed_ctrl, &res);
59565956
printf("\n");
59575957

5958-
printf("%-17s %-17s %-10s %-49s %-16s %-16s\n", "Device", "Generic",
5958+
printf("%-17s %-20s %-10s %-49s %-16s %-16s\n", "Device", "Generic",
59595959
"NSID", "Usage", "Format", "Controllers");
5960-
printf("%-.17s %-.17s %-.10s %-.49s %-.16s %-.16s\n", dash, dash, dash,
5960+
printf("%-.17s %-.20s %-.10s %-.49s %-.16s %-.16s\n", dash, dash, dash,
59615961
dash, dash, dash);
59625962
strset_iterate(&res.namespaces, stdout_detailed_ns, &res);
59635963

nvme-print.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,9 @@ void nvme_generic_full_path(libnvme_ns_t n, char *path, size_t len)
16831683
if (strncmp(path, "/dev/spdk/", 10) == 0 && stat(path, &st) == 0)
16841684
return;
16851685

1686-
sscanf(libnvme_ns_get_name(n), "nvme%dn%d", &instance, &head_instance);
1686+
if (sscanf(libnvme_ns_get_name(n), "nvme%dn%d", &instance, &head_instance) != 2)
1687+
return;
1688+
16871689
snprintf(path, len, "/dev/ng%dn%d", instance, head_instance);
16881690

16891691
if (stat(path, &st) == 0)
@@ -1692,7 +1694,7 @@ void nvme_generic_full_path(libnvme_ns_t n, char *path, size_t len)
16921694
* We could start trying to search for it but let's make
16931695
* it simple and just don't show the path at all.
16941696
*/
1695-
snprintf(path, len, "ng%dn%d", instance, head_instance);
1697+
snprintf(path, len, "%s", libnvme_ns_get_generic_name(n));
16961698
}
16971699

16981700
void nvme_show_list_item(libnvme_ns_t n, struct table *t)

0 commit comments

Comments
 (0)