Skip to content

Commit cce8b86

Browse files
dwsuseigaw
authored andcommitted
json: filter out pcie transport
The PCIe transport can't be configured and thus we should not append it to the config at all when dumping the configuration as JSON object. We should also avoid adding the hostnqn/subsys section if we don't have any ports defined. Signed-off-by: Daniel Wagner <[email protected]>
1 parent 2bb2eb0 commit cce8b86

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

src/nvme/json.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,9 @@ static void json_update_port(struct json_object *ctrl_array, nvme_ctrl_t c)
339339
const char *transport, *value;
340340

341341
transport = nvme_ctrl_get_transport(c);
342+
if (!strcmp(transport, "pcie"))
343+
return;
344+
342345
json_object_object_add(port_obj, "transport",
343346
json_object_new_string(transport));
344347
value = nvme_ctrl_get_traddr(c);
@@ -432,11 +435,13 @@ static void json_update_subsys(struct json_object *subsys_array,
432435
nvme_subsystem_for_each_ctrl(s, c) {
433436
json_update_port(port_array, c);
434437
}
435-
if (json_object_array_length(port_array))
438+
if (json_object_array_length(port_array)) {
436439
json_object_object_add(subsys_obj, "ports", port_array);
437-
else
440+
json_object_array_add(subsys_array, subsys_obj);
441+
} else {
438442
json_object_put(port_array);
439-
json_object_array_add(subsys_array, subsys_obj);
443+
json_object_put(subsys_obj);
444+
}
440445
}
441446

442447
int json_update_config(nvme_root_t r, const char *config_file)
@@ -476,12 +481,14 @@ int json_update_config(nvme_root_t r, const char *config_file)
476481
nvme_for_each_subsystem(h, s) {
477482
json_update_subsys(subsys_array, s);
478483
}
479-
if (json_object_array_length(subsys_array))
484+
if (json_object_array_length(subsys_array)) {
480485
json_object_object_add(host_obj, "subsystems",
481-
subsys_array);
482-
else
486+
subsys_array);
487+
json_object_array_add(json_root, host_obj);
488+
} else {
483489
json_object_put(subsys_array);
484-
json_object_array_add(json_root, host_obj);
490+
json_object_put(host_obj);
491+
}
485492
}
486493
if (!config_file) {
487494
ret = json_object_to_fd(1, json_root, JSON_C_TO_STRING_PRETTY);

0 commit comments

Comments
 (0)