]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
nvme-print: fix wrong list-subsys output when ns are attached to different ctrls
authorSagi Grimberg <sagi@grimberg.me>
Mon, 12 Jun 2023 15:34:06 +0000 (18:34 +0300)
committerDaniel Wagner <dwagner@suse.de>
Wed, 14 Jun 2023 11:46:13 +0000 (13:46 +0200)
If we list subsystem controllers not for a specific ns (user did not pass
a namespace device node), we cannot look at the first ns in the subsystem
to list because it may not be attached to all subsystem controllers.

We incorrectly assumes that subsystem namespaces (or at least the first of
them) are attached to all subsystem controllers.

Fix that by showing the multipath subsystem-list flavor only when the user
passed a specific namespace, and fallback to a simple controller list otherwise.

Fixes: cdeaab8fca6e ("nvme-print: Show ANA state only for one namespace")
Fixes: 7435ed9ae6a6 ("nvme-print: Show paths from the first namespace only")
Signed-off-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
nvme-print-json.c
nvme-print-stdout.c

index 132603d3da5b8cdac30b3740297ed5cca3db8b24..2f2b686b91cba8e9744d636d4178ceee7ccaaef4 100644 (file)
@@ -1717,7 +1717,6 @@ static void json_nvme_fdp_ruh_status(struct nvme_fdp_ruh_status *status, size_t
 }
 
 static unsigned int json_print_nvme_subsystem_multipath(nvme_subsystem_t s,
-                                                       bool show_ana,
                                                        json_object *paths)
 {
        nvme_ns_t n;
@@ -1741,9 +1740,8 @@ static unsigned int json_print_nvme_subsystem_multipath(nvme_subsystem_t s,
                                             nvme_ctrl_get_address(c));
                json_object_add_value_string(path_attrs, "State",
                                             nvme_ctrl_get_state(c));
-               if (show_ana)
-                       json_object_add_value_string(path_attrs, "ANAState",
-                                                    nvme_path_get_ana_state(p));
+               json_object_add_value_string(path_attrs, "ANAState",
+                                            nvme_path_get_ana_state(p));
                json_array_add_value_object(paths, path_attrs);
                i++;
        }
@@ -1803,7 +1801,7 @@ static void json_print_nvme_subsystem_list(nvme_root_t r, bool show_ana)
                        json_array_add_value_object(subsystems, subsystem_attrs);
                        paths = json_create_array();
 
-                       if (!json_print_nvme_subsystem_multipath(s, show_ana, paths))
+                       if (!show_ana || !json_print_nvme_subsystem_multipath(s, paths))
                                json_print_nvme_subsystem_ctrls(s, paths);
 
                        json_object_add_value_array(subsystem_attrs, "Paths",
index 65e48afb925dad078422b1de6d73486d1e1b314c..7c0a052072d4d7bd489b150a9c40a672448afc1b 100644 (file)
@@ -784,8 +784,7 @@ static void stdout_supported_cap_config_log(struct nvme_supported_cap_config_lis
        }
 }
 
-static unsigned int stdout_subsystem_multipath(nvme_subsystem_t s,
-                                              bool show_ana)
+static unsigned int stdout_subsystem_multipath(nvme_subsystem_t s)
 {
        nvme_ns_t n;
        nvme_path_t p;
@@ -797,10 +796,7 @@ static unsigned int stdout_subsystem_multipath(nvme_subsystem_t s,
 
        nvme_namespace_for_each_path(n, p) {
                nvme_ctrl_t c = nvme_path_get_ctrl(p);
-               const char *ana_state = "";
-
-               if (show_ana)
-                       ana_state = nvme_path_get_ana_state(p);
+               const char *ana_state = ana_state = nvme_path_get_ana_state(p);
 
                printf(" +- %s %s %s %s %s\n",
                        nvme_ctrl_get_name(c),
@@ -839,7 +835,7 @@ static void stdout_subsystem(nvme_root_t r, bool show_ana)
                               nvme_subsystem_get_nqn(s));
                        printf("\\\n");
 
-                       if (!stdout_subsystem_multipath(s, show_ana))
+                       if (!show_ana || !stdout_subsystem_multipath(s))
                                stdout_subsystem_ctrls(s);
                }
        }