From a296e439f61f8f801e00ff97cc91d3714f384dda Mon Sep 17 00:00:00 2001 From: Minwoo Im Date: Sat, 18 Sep 2021 10:17:15 +0900 Subject: [PATCH] nvme-print: print generic ns chardev in verbose mode Generic device (e.g., /dev/ng0n1) is mapped to a block device (e.g., /dev/nvme0n1). This chardev can be taken in case that block device is failed to initialize from the kernel due to some reasons (e.g., metadata initialization failed). This generic node information can be shown in the verbose list mode with HIDDEN block device (nvme0n1 in the below example). root@localhost:~# nvme list -v NVM Express Subsystems Subsystem Subsystem-NQN Controllers ---------------- ------------------------------------------------------------------------------------------------ ---------------- nvme-subsys0 nqn.2019-08.org.qemu:subsys0 nvme0 NVM Express Controllers Device SN MN FR TxPort Address Subsystem Namespaces -------- -------------------- ---------------------------------------- -------- ------ -------------- ------------ ---------------- nvme0 foo QEMU NVMe Ctrl 1.0 pcie 0000:00:06.0 nvme-subsys0 nvme0n1, nvme0n2 NVM Express Namespaces Device Generic NSID Usage Format Controllers ------------ ------------ -------- -------------------------- ---------------- ---------------- nvme0n1 ng0n1 1 0.00 B / 0.00 B 1 B + 0 B nvme0 nvme0n2 ng0n2 2 268.44 MB / 268.44 MB 4 KiB + 0 B nvme0 The nvme0n1 is failed to initialize and it shows 0.00 B size which is invalid. In this case, we can take /dev/ng0n1 alternatively from the application through generic I/O path. Signed-off-by: Minwoo Im [dwagner: - ported from nvme-cli-monolithic - fixed indention] Signed-off-by: Daniel Wagner --- nvme-print.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/nvme-print.c b/nvme-print.c index e8487f0e..9e84e845 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -6276,11 +6276,13 @@ static void nvme_show_simple_list(nvme_root_t r) static void nvme_show_ns_details(nvme_ns_t n) { - char usage[128] = { 0 }, format[128] = { 0 }; + char usage[128] = { 0 }, format[128] = { 0 }, generic[128] = { 0 }; long long lba = nvme_ns_get_lba_size(n); double nsze = nvme_ns_get_lba_count(n) * lba; double nuse = nvme_ns_get_lba_util(n) * lba; + int instance; + int head_instance; const char *s_suffix = suffix_si_get(&nsze); const char *u_suffix = suffix_si_get(&nuse); @@ -6290,8 +6292,11 @@ static void nvme_show_ns_details(nvme_ns_t n) sprintf(format,"%3.0f %2sB + %2d B", (double)lba, l_suffix, nvme_ns_get_meta_size(n)); - printf("%-12s %-8x %-26s %-16s ", nvme_ns_get_name(n), - nvme_ns_get_nsid(n), usage, format); + sscanf(nvme_ns_get_name(n), "nvme%dn%d", &instance, &head_instance); + sprintf(generic, "ng%dn%d", instance, head_instance); + + printf("%-12s %-12s %-8x %-26s %-16s ", nvme_ns_get_name(n), + generic, nvme_ns_get_nsid(n), usage, format); } static void nvme_show_detailed_list(nvme_root_t r) @@ -6357,10 +6362,10 @@ static void nvme_show_detailed_list(nvme_root_t r) } printf("\n"); - printf("%-12s %-8s %-26s %-16s %-16s\n", "Device", "NSID", "Usage", - "Format", "Controllers"); - printf("%-.12s %-.8s %-.26s %-.16s %-.16s\n", dash, dash, dash, dash, - dash); + printf("%-12s %-12s %-8s %-26s %-16s %-16s\n", "Device", "Generic", + "NSID", "Usage", "Format", "Controllers"); + printf("%-.12s %-.12s %-.8s %-.26s %-.16s %-.16s\n", dash, dash, dash, + dash, dash, dash); nvme_for_each_host(r, h) { nvme_for_each_subsystem(h, s) { -- 2.50.1