Skip to content

Commit c41a367

Browse files
shroffniigaw
authored andcommitted
nvme-cli: extend show-topology tabular output for multipath subsys
The current tabular output of the show-topology command does not display a controller if it has no associated nvme path or namespaces. However, it is valid for a controller within a subsystem to have no namespaces or paths attached. In such cases, it is still useful to display controller information such as the controller name, transport type, address, and state, while leaving NVMe path and namespace-related fields (e.g., nsid, nshead, nspath, anastate etc.) as "--". Update the tabular output of the 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 NVMe multipath subsystems. Signed-off-by: Nilay Shroff <[email protected]> [wagi: reformatted argument list and redudant comments] Signed-off-by: Daniel Wagner <[email protected]>
1 parent 67ab8c4 commit c41a367

1 file changed

Lines changed: 89 additions & 45 deletions

File tree

nvme-print-stdout.c

Lines changed: 89 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5945,13 +5945,47 @@ static bool subsystem_iopolicy_filter(const char *name, void *arg)
59455945
return true;
59465946
}
59475947

5948+
static int subsystem_topology_multipath_add_row(struct table *t,
5949+
const char *iopolicy, const char *nshead,
5950+
const char *nsid, const char *nspath,
5951+
const char *anastate, const char *iopolicy_info,
5952+
const char *ctrl, const char *trtype,
5953+
const char *address, const char *state)
5954+
{
5955+
int row;
5956+
int col = -1;
5957+
5958+
row = table_get_row_id(t);
5959+
if (row < 0) {
5960+
nvme_show_error("Failed to add subsys topology multipath row");
5961+
return row;
5962+
}
5963+
5964+
table_set_value_str(t, ++col, row, nshead, CENTERED);
5965+
table_set_value_str(t, ++col, row, nsid, CENTERED);
5966+
table_set_value_str(t, ++col, row, nspath, CENTERED);
5967+
table_set_value_str(t, ++col, row, anastate, CENTERED);
5968+
if (!strcmp(iopolicy, "numa") || !strcmp(iopolicy, "queue-depth"))
5969+
table_set_value_str(t, ++col, row, iopolicy_info, CENTERED);
5970+
table_set_value_str(t, ++col, row, ctrl, CENTERED);
5971+
table_set_value_str(t, ++col, row, trtype, CENTERED);
5972+
table_set_value_str(t, ++col, row, address, CENTERED);
5973+
table_set_value_str(t, ++col, row, state, CENTERED);
5974+
5975+
table_add_row(t, row);
5976+
5977+
return 0;
5978+
}
5979+
59485980
static void stdout_tabular_subsystem_topology_multipath(nvme_subsystem_t s)
59495981
{
59505982
nvme_ns_t n;
59515983
nvme_path_t p;
59525984
nvme_ctrl_t c;
5953-
int row, col;
59545985
bool first;
5986+
char nshead[32], nsid[32];
5987+
char iopolicy_info[256];
5988+
int ret, num_path;
59555989
struct table *t;
59565990
const char *iopolicy = nvme_subsystem_get_iopolicy(s);
59575991
struct table_column columns[] = {
@@ -5969,13 +6003,13 @@ static void stdout_tabular_subsystem_topology_multipath(nvme_subsystem_t s)
59696003

59706004
t = table_create();
59716005
if (!t) {
5972-
printf("Failed to init table\n");
6006+
nvme_show_error("Failed to init subsys topology multipath table");
59736007
return;
59746008
}
59756009

59766010
if (table_add_columns_filter(t, columns, ARRAY_SIZE(columns),
59776011
subsystem_iopolicy_filter, (void *)s) < 0) {
5978-
printf("Failed to add columns\n");
6012+
nvme_show_error("Failed to add subsys topology multipath columns");
59796013
goto free_tbl;
59806014
}
59816015

@@ -5984,61 +6018,71 @@ static void stdout_tabular_subsystem_topology_multipath(nvme_subsystem_t s)
59846018
nvme_namespace_for_each_path(n, p) {
59856019
c = nvme_path_get_ctrl(p);
59866020

5987-
row = table_get_row_id(t);
5988-
if (row < 0) {
5989-
printf("Failed to add row\n");
5990-
goto free_tbl;
5991-
}
5992-
/* For the first row we print actual NSHead name,
6021+
/*
6022+
* For the first row we print actual NSHead name,
59936023
* however, for the subsequent rows we print "arrow"
59946024
* ("-->") symbol for NSHead. This "arrow" style makes
59956025
* it visually obvious that susequenet entries (if
59966026
* present) are a path under the first NSHead.
59976027
*/
5998-
col = -1;
5999-
/* col 0: NSHead */
60006028
if (first) {
6001-
table_set_value_str(t, ++col, row,
6002-
nvme_ns_get_name(n), LEFT);
6029+
snprintf(nshead, sizeof(nshead), "%s",
6030+
nvme_ns_get_name(n));
60036031
first = false;
60046032
} else
6005-
table_set_value_str(t, ++col, row,
6006-
"-->", CENTERED);
6007-
/* col 1: NSID */
6008-
table_set_value_int(t, ++col, row,
6009-
nvme_ns_get_nsid(n), CENTERED);
6010-
/* col 2: NSPath */
6011-
table_set_value_str(t, ++col, row,
6012-
nvme_path_get_name(p), LEFT);
6013-
/* col 3: ANAState */
6014-
table_set_value_str(t, ++col, row,
6015-
nvme_path_get_ana_state(p), LEFT);
6033+
snprintf(nshead, sizeof(nshead), "%s", "-->");
6034+
6035+
snprintf(nsid, sizeof(nsid), "%u", nvme_ns_get_nsid(n));
60166036

60176037
if (!strcmp(iopolicy, "numa"))
6018-
/* col 4: Nodes */
6019-
table_set_value_str(t, ++col, row,
6020-
nvme_path_get_numa_nodes(p), CENTERED);
6038+
snprintf(iopolicy_info, sizeof(iopolicy_info),
6039+
"%s", nvme_path_get_numa_nodes(p));
60216040
else if (!strcmp(iopolicy, "queue-depth"))
6022-
/* col 4 : Qdepth */
6023-
table_set_value_int(t, ++col, row,
6024-
nvme_path_get_queue_depth(p), CENTERED);
6025-
6026-
/* col 5: Controller */
6027-
table_set_value_str(t, ++col, row,
6028-
nvme_ctrl_get_name(c), LEFT);
6029-
/* col 6: TrType */
6030-
table_set_value_str(t, ++col, row,
6031-
nvme_ctrl_get_transport(c), LEFT);
6032-
/* col 7: Address */
6033-
table_set_value_str(t, ++col, row,
6034-
nvme_ctrl_get_traddr(c), LEFT);
6035-
/* col 8: State */
6036-
table_set_value_str(t, ++col, row,
6037-
nvme_ctrl_get_state(c), LEFT);
6038-
6039-
table_add_row(t, row);
6041+
snprintf(iopolicy_info, sizeof(iopolicy_info),
6042+
"%d", nvme_path_get_queue_depth(p));
6043+
6044+
ret = subsystem_topology_multipath_add_row(t,
6045+
iopolicy,
6046+
nshead,
6047+
nsid,
6048+
nvme_path_get_name(p),
6049+
nvme_path_get_ana_state(p),
6050+
iopolicy_info,
6051+
nvme_ctrl_get_name(c),
6052+
nvme_ctrl_get_transport(c),
6053+
nvme_ctrl_get_traddr(c),
6054+
nvme_ctrl_get_state(c));
6055+
if (ret < 0)
6056+
goto free_tbl;
6057+
}
6058+
}
6059+
6060+
/*
6061+
* Next we print controller in the subsystem which may not have any
6062+
* nvme path associated to it.
6063+
*/
6064+
nvme_subsystem_for_each_ctrl(s, c) {
6065+
num_path = 0;
6066+
nvme_ctrl_for_each_path(c, p)
6067+
num_path++;
6068+
6069+
if (!num_path) {
6070+
ret = subsystem_topology_multipath_add_row(t,
6071+
iopolicy,
6072+
"--", /* NSHead */
6073+
"--", /* NSID */
6074+
"--", /* NSPath */
6075+
"--", /* ANAState */
6076+
"--", /* Nodes/Qdepth */
6077+
nvme_ctrl_get_name(c),
6078+
nvme_ctrl_get_transport(c),
6079+
nvme_ctrl_get_traddr(c),
6080+
nvme_ctrl_get_state(c));
6081+
if (ret < 0)
6082+
goto free_tbl;
60406083
}
60416084
}
6085+
60426086
table_print(t);
60436087
free_tbl:
60446088
table_free(t);

0 commit comments

Comments
 (0)