]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-print: print generic ns chardev in verbose mode
authorMinwoo Im <minwoo.im.dev@gmail.com>
Sat, 18 Sep 2021 01:17:15 +0000 (10:17 +0900)
committerDaniel Wagner <dwagner@suse.de>
Mon, 15 Nov 2021 11:06:29 +0000 (12:06 +0100)
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 <minwoo.im.dev@gmail.com>
[dwagner: - ported from nvme-cli-monolithic
          - fixed indention]
Signed-off-by: Daniel Wagner <dwagner@suse.de>
nvme-print.c

index e8487f0e91405d3882663d4d4cdf0446ed0e6285..9e84e8455b199b72fb180c0976a337eb7183270f 100644 (file)
@@ -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) {