Skip to content

Commit fae35ae

Browse files
committed
nvme-print: suppress output when no ctrl is present for list-subsys
When using list-subsys with the optional device filter argument, the subsystem might not have any controller associated anymore, it was filtered out. Avoid outputting any whitespace (or empty json data structures) in this case. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 97c8bb0 commit fae35ae

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

nvme-print-json.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,6 +2558,14 @@ static void json_print_nvme_subsystem_list(nvme_root_t r, bool show_ana)
25582558
obj_add_str(host_attrs, "HostID", hostid);
25592559
subsystems = json_create_array();
25602560
nvme_for_each_subsystem(h, s) {
2561+
nvme_ctrl_t c;
2562+
bool no_ctrl = true;
2563+
2564+
nvme_subsystem_for_each_ctrl(s, c)
2565+
no_ctrl = false;
2566+
if (no_ctrl)
2567+
continue;
2568+
25612569
subsystem_attrs = json_create_object();
25622570
obj_add_str(subsystem_attrs, "Name", nvme_subsystem_get_name(s));
25632571
obj_add_str(subsystem_attrs, "NQN", nvme_subsystem_get_nqn(s));

nvme-print-stdout.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,15 @@ static void stdout_subsystem(nvme_root_t r, bool show_ana)
11321132

11331133
nvme_for_each_host(r, h) {
11341134
nvme_subsystem_t s;
1135+
nvme_ctrl_t c;
1136+
bool no_ctrl = true;
11351137

11361138
nvme_for_each_subsystem(h, s) {
1139+
nvme_subsystem_for_each_ctrl(s, c)
1140+
no_ctrl = false;
1141+
if (no_ctrl)
1142+
continue;
1143+
11371144
if (!first)
11381145
printf("\n");
11391146
first = false;

0 commit comments

Comments
 (0)