Skip to content

Commit c3b1f65

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 f0c31b7 commit c3b1f65

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,14 @@ static void stdout_subsystem(nvme_root_t r, bool show_ana)
11341134
nvme_subsystem_t s;
11351135

11361136
nvme_for_each_subsystem(h, s) {
1137+
bool no_ctrl = true;
1138+
nvme_ctrl_t c;
1139+
1140+
nvme_subsystem_for_each_ctrl(s, c)
1141+
no_ctrl = false;
1142+
if (no_ctrl)
1143+
continue;
1144+
11371145
if (!first)
11381146
printf("\n");
11391147
first = false;

0 commit comments

Comments
 (0)