]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme: print out ANA state for 'list-subsys'
authorHannes Reinecke <hare@suse.de>
Fri, 11 Mar 2022 08:16:09 +0000 (09:16 +0100)
committerHannes Reinecke <hare@suse.de>
Fri, 11 Mar 2022 14:44:24 +0000 (15:44 +0100)
Commit 00aeb92 ("nvme-list-subsys: Add device name argument
and print out ANA state") was not properly ported to libnvme/nvme-cli.
So port the missing bits.

Signed-off-by: Hannes Reinecke <hare@suse.de>
nvme-print.c
nvme-print.h
nvme.c

index d1aef1a3c39b1e49b79170c681e7b3dc11b624ed..b7d120d1ef77b4f0269f33135653ce30d00e9953 100644 (file)
@@ -2275,7 +2275,7 @@ void nvme_show_supported_cap_config_log(
        }
 }
 
-static void nvme_show_subsystem(nvme_root_t r)
+static void nvme_show_subsystem(nvme_root_t r, unsigned int nsid)
 {
        nvme_host_t h;
 
@@ -2290,17 +2290,20 @@ static void nvme_show_subsystem(nvme_root_t r)
                        printf("\\\n");
 
                        nvme_subsystem_for_each_ctrl(s, c) {
-                               printf(" +- %s %s %s %s\n",
+                               const char *ana_state =
+                                       nvme_ctrl_get_ana_state(c, nsid);
+                               printf(" +- %s %s %s %s %s\n",
                                       nvme_ctrl_get_name(c),
                                       nvme_ctrl_get_transport(c),
                                       nvme_ctrl_get_address(c),
-                                      nvme_ctrl_get_state(c));
+                                      nvme_ctrl_get_state(c),
+                                      ana_state ? : "");
                        }
                }
        }
 }
 
-static void json_print_nvme_subsystem_list(nvme_root_t r)
+static void json_print_nvme_subsystem_list(nvme_root_t r, unsigned int nsid)
 {
        struct json_object *host_attrs, *subsystem_attrs, *path_attrs;
        struct json_object *subsystems, *paths;
@@ -2340,6 +2343,13 @@ static void json_print_nvme_subsystem_list(nvme_root_t r)
                                                             nvme_ctrl_get_address(c));
                                json_object_add_value_string(path_attrs, "State",
                                                             nvme_ctrl_get_state(c));
+                               if (nsid != NVME_NSID_ALL) {
+                                       const char *ana_state =
+                                               nvme_ctrl_get_ana_state(c, nsid);
+                                       if (ana_state)
+                                               json_object_add_value_string(path_attrs,
+                                                                            "ANAState", ana_state);
+                               }
                                json_array_add_value_object(paths, path_attrs);
                        }
                        json_object_add_value_array(subsystem_attrs, "Paths",
@@ -2353,11 +2363,12 @@ static void json_print_nvme_subsystem_list(nvme_root_t r)
        json_free_object(root);
 }
 
-void nvme_show_subsystem_list(nvme_root_t r, enum nvme_print_flags flags)
+void nvme_show_subsystem_list(nvme_root_t r, unsigned int nsid,
+                             enum nvme_print_flags flags)
 {
        if (flags & JSON)
-               return json_print_nvme_subsystem_list(r);
-       nvme_show_subsystem(r);
+               return json_print_nvme_subsystem_list(r, nsid);
+       nvme_show_subsystem(r, nsid);
 }
 
 static void nvme_show_registers_cap(struct nvme_bar_cap *cap)
index 15f1e35a0129282f219aec1968b7be76019f7dc6..94e6fff99fc01cad02908056c2ad54c64e075194 100644 (file)
@@ -85,7 +85,8 @@ void nvme_show_id_ns_descs(void *data, unsigned nsid, enum nvme_print_flags flag
 void nvme_show_lba_status(struct nvme_lba_status *list, unsigned long len,
        enum nvme_print_flags flags);
 void nvme_show_list_items(nvme_root_t t, enum nvme_print_flags flags);
-void nvme_show_subsystem_list(nvme_root_t t, enum nvme_print_flags flags);
+void nvme_show_subsystem_list(nvme_root_t t, unsigned int nsid,
+                             enum nvme_print_flags flags);
 void nvme_show_id_nvmset(struct nvme_id_nvmset_list *nvmset, unsigned nvmset_id,
        enum nvme_print_flags flags);
 void nvme_show_primary_ctrl_cap(const struct nvme_primary_ctrl_cap *cap,
diff --git a/nvme.c b/nvme.c
index aa7a4f7e16cc70bfd49a28f488f52585e06c1a54..1ee9a062da98bf19b3e6993e1292a9bc42c5e84d 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -2416,25 +2416,6 @@ ret:
        return err;
 }
 
-static bool nvme_match_device_filter(nvme_subsystem_t s)
-{
-       nvme_ctrl_t c;
-       nvme_ns_t n;
-
-       if (!devicename || !strlen(devicename))
-               return true;
-
-       nvme_subsystem_for_each_ctrl(s, c)
-               if (!strcmp(devicename, nvme_ctrl_get_name(c)))
-                       return true;
-
-       nvme_subsystem_for_each_ns(s, n)
-               if (!strcmp(devicename, nvme_ns_get_name(n)))
-                       return true;
-
-       return false;
-}
-
 static int list_subsys(int argc, char **argv, struct command *cmd,
                struct plugin *plugin)
 {
@@ -2442,7 +2423,7 @@ static int list_subsys(int argc, char **argv, struct command *cmd,
        enum nvme_print_flags flags;
        const char *desc = "Retrieve information for subsystems";
        const char *verbose = "Increase output verbosity";
-       nvme_scan_filter_t filter = NULL;
+       __u32 nsid = NVME_NSID_ALL;
        int err;
 
        struct config {
@@ -2491,17 +2472,31 @@ static int list_subsys(int argc, char **argv, struct command *cmd,
                goto ret;
        }
 
-       if (devicename)
-               filter = nvme_match_device_filter;
+       if (devicename) {
+               char *n, *eptr = NULL;
 
-       err = nvme_scan_topology(r, filter);
+               n = strrchr(devicename, 'n');
+               if (!n) {
+                       fprintf(stderr, "Invalid device name %s\n", devicename);
+                       err = -EINVAL;
+                       goto ret;
+               }
+               nsid = strtoul(n + 1, &eptr, 10);
+               if (eptr == n + 1) {
+                       fprintf(stderr, "Invalid device nsid %s\n", devicename);
+                       err = -EINVAL;
+                       goto ret;
+               }
+       }
+
+       err = nvme_scan_topology(r, NULL);
        if (err) {
                fprintf(stderr, "Failed to scan topology: %s\n",
                        nvme_strerror(errno));
                goto ret;
        }
 
-       nvme_show_subsystem_list(r, flags);
+       nvme_show_subsystem_list(r, nsid, flags);
        nvme_free_tree(r);
 
 ret: