diff --git a/nvme-print-json.c b/nvme-print-json.c index 1766cae882..bbb948f53e 100644 --- a/nvme-print-json.c +++ b/nvme-print-json.c @@ -2558,6 +2558,14 @@ static void json_print_nvme_subsystem_list(nvme_root_t r, bool show_ana) obj_add_str(host_attrs, "HostID", hostid); subsystems = json_create_array(); nvme_for_each_subsystem(h, s) { + nvme_ctrl_t c; + bool no_ctrl = true; + + nvme_subsystem_for_each_ctrl(s, c) + no_ctrl = false; + if (no_ctrl) + continue; + subsystem_attrs = json_create_object(); obj_add_str(subsystem_attrs, "Name", nvme_subsystem_get_name(s)); obj_add_str(subsystem_attrs, "NQN", nvme_subsystem_get_nqn(s)); diff --git a/nvme-print-stdout.c b/nvme-print-stdout.c index 4686241e63..7d7d4b2735 100644 --- a/nvme-print-stdout.c +++ b/nvme-print-stdout.c @@ -1134,6 +1134,14 @@ static void stdout_subsystem(nvme_root_t r, bool show_ana) nvme_subsystem_t s; nvme_for_each_subsystem(h, s) { + bool no_ctrl = true; + nvme_ctrl_t c; + + nvme_subsystem_for_each_ctrl(s, c) + no_ctrl = false; + if (no_ctrl) + continue; + if (!first) printf("\n"); first = false; diff --git a/nvme.c b/nvme.c index 7c4e0bdadc..1dec63a447 100644 --- a/nvme.c +++ b/nvme.c @@ -3388,33 +3388,24 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin * static bool nvme_match_device_filter(nvme_subsystem_t s, nvme_ctrl_t c, nvme_ns_t ns, void *f_args) { - int ret, instance, nsid, s_num; char *devname = f_args; + nvme_ns_t n; - if (!devname || !strlen(devname)) + if (ns && !strcmp(devname, nvme_ns_get_name(ns))) return true; - ret = sscanf(devname, "nvme%dn%d", &instance, &nsid); - if (ret != 2) - return true; - - if (s) { - ret = sscanf(nvme_subsystem_get_name(s), "nvme-subsys%d", - &s_num); - if (ret == 1 && s_num == instance) - return true; - } if (c) { s = nvme_ctrl_get_subsystem(c); - - ret = sscanf(nvme_subsystem_get_name(s), "nvme-subsys%d", - &s_num); - if (ret == 1 && s_num == instance) - return true; + nvme_ctrl_for_each_ns(c, n) { + if (!strcmp(devname, nvme_ns_get_name(n))) + return true; + } } - if (ns) { - if (!strcmp(devname, nvme_ns_get_name(ns))) - return true; + if (s) { + nvme_subsystem_for_each_ns(s, n) { + if (!strcmp(devname, nvme_ns_get_name(n))) + return true; + } } return false;