]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
zns: Add list command
authorAndreas Hindborg <andreas.hindborg@wdc.com>
Mon, 13 Sep 2021 13:13:53 +0000 (13:13 +0000)
committerKeith Busch <kbusch@kernel.org>
Tue, 28 Sep 2021 15:21:23 +0000 (09:21 -0600)
Signed-off-by: Andreas Hindborg <andreas.hindborg@wdc.com>
nvme-print.c
nvme-print.h
plugins/zns/zns.c
plugins/zns/zns.h

index 7bb34cd3dc297a7890ca6aabafdc346f063919ff..fc6d9c512b3f23547e1f9327b2cde2ed595bc99c 100644 (file)
@@ -5632,7 +5632,7 @@ void nvme_show_lba_status(struct nvme_lba_status *list, unsigned long len,
        }
 }
 
-static void nvme_show_list_item(nvme_ns_t n)
+void nvme_show_list_item(nvme_ns_t n)
 {
        char usage[128] = { 0 }, format[128] = { 0 };
 
index 0a606f4e421fbb1321232cb28a0aca2cad1f9347..c3ba64ae7091147a038abe46bd87e3082d24e6e0 100644 (file)
@@ -103,6 +103,7 @@ void nvme_show_zns_changed( struct nvme_zns_changed_zone_log *log,
        unsigned long flags);
 void nvme_show_zns_report_zones(void *report, __u32 descs,
        __u8 ext_size, __u32 report_size, unsigned long flags);
+void nvme_show_list_item(nvme_ns_t n);
 
 const char *nvme_cmd_to_string(int admin, __u8 opcode);
 const char *nvme_select_to_string(int sel);
index 3b4ae39337940d75785898ea6f9bdc5fd54c6b6c..9562d3642c034e8eb330b4c249754cc16113b6d7 100644 (file)
 #include "zns.h"
 
 static const char *namespace_id = "Namespace identifier to use";
+static const char dash[100] = { [0 ... 99] = '-' };
+
+static int detect_zns(nvme_ns_t ns, int *out_supported)
+{
+       int err = 0;
+       char *zoned;
+
+       *out_supported = 0;
+
+       zoned = nvme_get_attr(nvme_ns_get_sysfs_dir(ns), "queue/zoned");
+       if (!zoned) {
+               *out_supported = 0;
+               return err;
+       }
+
+       *out_supported = strcmp("host-managed", zoned) == 0;
+       free(zoned);
+
+       return err;
+}
+
+static int print_zns_list_ns(nvme_ns_t ns)
+{
+       int supported;
+       int err = 0;
+
+       err = detect_zns(ns, &supported);
+       if (err) {
+               perror("Failed to enumerate namespace");
+               return err;
+       }
+
+       if (supported) {
+               nvme_show_list_item(ns);
+       }
+
+       return err;
+}
+
+static int print_zns_list(nvme_root_t nvme_root)
+{
+       int err = 0;
+       nvme_host_t h;
+       nvme_subsystem_t s;
+       nvme_ctrl_t c;
+       nvme_ns_t n;
+       nvme_for_each_host(nvme_root, h)
+       {
+               nvme_for_each_subsystem(h, s)
+               {
+                       nvme_subsystem_for_each_ns(s, n)
+                       {
+                               err = print_zns_list_ns(n);
+                               if (err)
+                                       return err;
+                       }
+
+                       nvme_subsystem_for_each_ctrl(s, c)
+                       {
+                               nvme_ctrl_for_each_ns(c, n)
+                               {
+                                       err = print_zns_list_ns(n);
+                                       if (err)
+                                               return err;
+                               }
+                       }
+               }
+       }
+
+       return err;
+}
+
+static int list(int argc, char **argv, struct command *cmd,
+               struct plugin *plugin)
+{
+       int err = 0;
+       nvme_root_t nvme_root;
+
+       printf("%-21s %-20s %-40s %-9s %-26s %-16s %-8s\n", "Node", "SN",
+              "Model", "Namespace", "Usage", "Format", "FW Rev");
+       printf("%-.21s %-.20s %-.40s %-.9s %-.26s %-.16s %-.8s\n", dash, dash,
+              dash, dash, dash, dash, dash);
+
+       nvme_root = nvme_scan(NULL);
+       if (nvme_root) {
+               err = print_zns_list(nvme_root);
+       } else {
+               fprintf(stderr, "Failed to scan nvme subsystems\n");
+               err = -errno;
+       }
+
+       nvme_free_tree(nvme_root);
+
+       return err;
+}
 
 static int id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin)
 {
index a92de69c5214bda6ebf30f598ce4219c87891346..a746aaa793e2d6a9065ae39a36eee0481a32996e 100644 (file)
@@ -21,6 +21,7 @@ PLUGIN(NAME("zns", "Zoned Namespace Command Set"),
                ENTRY("set-zone-desc", "Attaches zone descriptor extension data", set_zone_desc)
                ENTRY("zone-append", "Writes data and metadata (if applicable), appended to the end of the requested zone", zone_append)
                ENTRY("changed-zone-list", "Retrieves the changed zone list log", changed_zone_list)
+               ENTRY("list", "List ZNS enabled devices", list)
        )
 );