[PATCH nvme-cli] nvme-print: fix wrong list-subsys output when ns are attached to different ctrls

Sagi Grimberg sagi at grimberg.me
Mon Jun 12 08:34:06 PDT 2023


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 at grimberg.me>
---
 nvme-print-json.c |  8 +++-----
 nvme-print.c      | 10 +++-------
 2 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/nvme-print-json.c b/nvme-print-json.c
index d9b19c96a8d6..e6f8e49e3497 100644
--- a/nvme-print-json.c
+++ b/nvme-print-json.c
@@ -1697,7 +1697,6 @@ void json_nvme_fdp_ruh_status(struct nvme_fdp_ruh_status *status, size_t len)
 }
 
 static unsigned int json_print_nvme_subsystem_multipath(nvme_subsystem_t s,
-							bool show_ana,
 						        json_object *paths)
 {
 	nvme_ns_t n;
@@ -1721,9 +1720,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++;
 	}
@@ -1782,7 +1780,7 @@ 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",
diff --git a/nvme-print.c b/nvme-print.c
index 38fc8d02251f..0e5fe934bb7e 100644
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -1025,8 +1025,7 @@ void nvme_show_supported_cap_config_log(
 	}
 }
 
-static unsigned int nvme_show_subsystem_multipath(nvme_subsystem_t s,
-						  bool show_ana)
+static unsigned int nvme_show_subsystem_multipath(nvme_subsystem_t s)
 {
 	nvme_ns_t n;
 	nvme_path_t p;
@@ -1038,10 +1037,7 @@ static unsigned int nvme_show_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 = nvme_path_get_ana_state(p);
 
 		printf(" +- %s %s %s %s %s\n",
 			nvme_ctrl_get_name(c),
@@ -1080,7 +1076,7 @@ static void nvme_show_subsystem(nvme_root_t r, bool show_ana)
 			       nvme_subsystem_get_nqn(s));
 			printf("\\\n");
 
-			if (!nvme_show_subsystem_multipath(s, show_ana))
+			if (!show_ana || !nvme_show_subsystem_multipath(s))
 				nvme_show_subsystem_ctrls(s);
 		}
 	}
-- 
2.40.1




More information about the Linux-nvme mailing list