Skip to content

Commit 67ab8c4

Browse files
shroffniigaw
authored andcommitted
nvme-cli: extend show-topology tabular output for non-multipath subsys
The current tabular output of show-topology command does not display a controller if it has no associated namespaces. However, it is valid for a controller within a subsystem to have no namespaces attached. In such cases, it is still useful to display controller information such as the controller name, transport type, address, and state, while leaving the namespace-related fields (e.g., namespace and nsid) as "--". Update the tabular output of show-topology command to include controllers and their associated fields regardless of whether any namespaces are present. While we are at it, also dispaly the error message using nvme_show_error() instead of using printf(). This change applies to non-multipath subsystems. A subsequent commit will extend this behavior to multipath subsystems. Signed-off-by: Nilay Shroff <[email protected]> [wagi: reformatted argument list and dropped redundant comments] Signed-off-by: Daniel Wagner <[email protected]>
1 parent 293cadf commit 67ab8c4

1 file changed

Lines changed: 54 additions & 29 deletions

File tree

nvme-print-stdout.c

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6148,11 +6148,33 @@ static void stdout_subsystem_topology_multipath(nvme_subsystem_t s,
61486148
}
61496149
}
61506150

6151+
static int subsystem_topology_add_row(struct table *t,
6152+
const char *ns, const char *nsid, const char *ctrl,
6153+
const char *trtype, const char *address, const char *state)
6154+
{
6155+
int row = table_get_row_id(t);
6156+
if (row < 0) {
6157+
nvme_show_error("Failed to add subsys topology row");
6158+
return row;
6159+
}
6160+
6161+
table_set_value_str(t, 0, row, ns, CENTERED);
6162+
table_set_value_str(t, 1, row, nsid, CENTERED);
6163+
table_set_value_str(t, 2, row, ctrl, CENTERED);
6164+
table_set_value_str(t, 3, row, trtype, CENTERED);
6165+
table_set_value_str(t, 4, row, address, CENTERED);
6166+
table_set_value_str(t, 5, row, state, CENTERED);
6167+
6168+
table_add_row(t, row);
6169+
6170+
return 0;
6171+
}
6172+
61516173
static void stdout_tabular_subsystem_topology(nvme_subsystem_t s)
61526174
{
61536175
nvme_ctrl_t c;
61546176
nvme_ns_t n;
6155-
int row;
6177+
int ret, num_ns;
61566178
struct table *t;
61576179
struct table_column columns[] = {
61586180
{"Namespace", LEFT, 0},
@@ -6165,45 +6187,48 @@ static void stdout_tabular_subsystem_topology(nvme_subsystem_t s)
61656187

61666188
t = table_create();
61676189
if (!t) {
6168-
printf("Failed to init table\n");
6190+
nvme_show_error("Failed to init subsys topology table");
61696191
return;
61706192
}
61716193

61726194
if (table_add_columns(t, columns, ARRAY_SIZE(columns)) < 0) {
6173-
printf("Failed to add columns\n");
6195+
nvme_show_error("Failed to add subsys topology columns");
61746196
goto free_tbl;
61756197
}
61766198

61776199
nvme_subsystem_for_each_ctrl(s, c) {
6178-
nvme_ctrl_for_each_ns(c, n) {
6179-
c = nvme_ns_get_ctrl(n);
6180-
6181-
row = table_get_row_id(t);
6182-
if (row < 0) {
6183-
printf("Failed to add row\n");
6200+
num_ns = 0;
6201+
6202+
nvme_ctrl_for_each_ns(c, n)
6203+
num_ns++;
6204+
6205+
if (!num_ns) {
6206+
ret = subsystem_topology_add_row(t,
6207+
"--", /* Namespace */
6208+
"--", /* NSID */
6209+
nvme_ctrl_get_name(c),
6210+
nvme_ctrl_get_transport(c),
6211+
nvme_ctrl_get_traddr(c),
6212+
nvme_ctrl_get_state(c));
6213+
if (ret < 0)
61846214
goto free_tbl;
6185-
}
6215+
} else {
6216+
nvme_ctrl_for_each_ns(c, n) {
6217+
char nsid[32];
61866218

6187-
/* col 0: Namespace */
6188-
table_set_value_str(t, 0, row,
6189-
nvme_ns_get_name(n), LEFT);
6190-
/* col 1: NSID */
6191-
table_set_value_int(t, 1, row,
6192-
nvme_ns_get_nsid(n), CENTERED);
6193-
/* col 2: Controller */
6194-
table_set_value_str(t, 2, row,
6195-
nvme_ctrl_get_name(c), LEFT);
6196-
/* col 3: Trtype */
6197-
table_set_value_str(t, 3, row,
6198-
nvme_ctrl_get_transport(c), LEFT);
6199-
/* col 4: Address */
6200-
table_set_value_str(t, 4, row,
6201-
nvme_ctrl_get_traddr(c), LEFT);
6202-
/* col 5: State */
6203-
table_set_value_str(t, 5, row,
6204-
nvme_ctrl_get_state(c), LEFT);
6219+
snprintf(nsid, sizeof(nsid), "%u",
6220+
nvme_ns_get_nsid(n));
62056221

6206-
table_add_row(t, row);
6222+
ret = subsystem_topology_add_row(t,
6223+
nvme_ns_get_name(n),
6224+
(const char *)nsid,
6225+
nvme_ctrl_get_name(c),
6226+
nvme_ctrl_get_transport(c),
6227+
nvme_ctrl_get_traddr(c),
6228+
nvme_ctrl_get_state(c));
6229+
if (ret < 0)
6230+
goto free_tbl;
6231+
}
62076232
}
62086233
}
62096234
table_print(t);

0 commit comments

Comments
 (0)