From: Hannes Reinecke Date: Fri, 11 Mar 2022 08:16:09 +0000 (+0100) Subject: nvme: print out ANA state for 'list-subsys' X-Git-Tag: v2.0-rc6~4^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=63b9959796caea4bc20f7e61f7fdf7853a34fb35;p=users%2Fsagi%2Fnvme-cli.git nvme: print out ANA state for 'list-subsys' 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 --- diff --git a/nvme-print.c b/nvme-print.c index d1aef1a3..b7d120d1 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -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) diff --git a/nvme-print.h b/nvme-print.h index 15f1e35a..94e6fff9 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -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 aa7a4f7e..1ee9a062 100644 --- 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: