From: Nilay Shroff <nilay@linux.ibm.com>
To: linux-nvme@lists.infradead.org
Cc: dwagner@suse.de, gjoyce@linux.ibm.com
Subject: [PATCH 1/2] nvme-cli: extend show-topology tabular output for non-multipath subsys
Date: Tue, 31 Mar 2026 19:42:08 +0530 [thread overview]
Message-ID: <20260331141215.3098243-2-nilay@linux.ibm.com> (raw)
In-Reply-To: <20260331141215.3098243-1-nilay@linux.ibm.com>
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 <nilay@linux.ibm.com>
---
nvme-print-stdout.c | 98 +++++++++++++++++++++++++++++++--------------
1 file changed, 69 insertions(+), 29 deletions(-)
diff --git a/nvme-print-stdout.c b/nvme-print-stdout.c
index 2e469ea50..769afa695 100644
--- a/nvme-print-stdout.c
+++ b/nvme-print-stdout.c
@@ -6148,11 +6148,48 @@ static void stdout_subsystem_topology_multipath(nvme_subsystem_t s,
}
}
+static int subsystem_topology_add_row(struct table *t,
+ const char *ns,
+ const char *nsid,
+ const char *ctrl,
+ const char *trtype,
+ const char *address,
+ const char *state)
+{
+ int row = table_get_row_id(t);
+ if (row < 0) {
+ nvme_show_error("Failed to add subsys topology row");
+ return row;
+ }
+
+ /* col 0: Namespace */
+ table_set_value_str(t, 0, row, ns, CENTERED);
+
+ /* col 1: NSID */
+ table_set_value_str(t, 1, row, nsid, CENTERED);
+
+ /* col 2: Controller */
+ table_set_value_str(t, 2, row, ctrl, CENTERED);
+
+ /* col 3: Trtype */
+ table_set_value_str(t, 3, row, trtype, CENTERED);
+
+ /* col 4: Address */
+ table_set_value_str(t, 4, row, address, CENTERED);
+
+ /* col 5: State */
+ table_set_value_str(t, 5, row, state, CENTERED);
+
+ table_add_row(t, row);
+
+ return 0;
+}
+
static void stdout_tabular_subsystem_topology(nvme_subsystem_t s)
{
nvme_ctrl_t c;
nvme_ns_t n;
- int row;
+ int ret, num_ns;
struct table *t;
struct table_column columns[] = {
{"Namespace", LEFT, 0},
@@ -6165,45 +6202,48 @@ static void stdout_tabular_subsystem_topology(nvme_subsystem_t s)
t = table_create();
if (!t) {
- printf("Failed to init table\n");
+ nvme_show_error("Failed to init subsys topology table");
return;
}
if (table_add_columns(t, columns, ARRAY_SIZE(columns)) < 0) {
- printf("Failed to add columns\n");
+ nvme_show_error("Failed to add subsys topology columns");
goto free_tbl;
}
nvme_subsystem_for_each_ctrl(s, c) {
- nvme_ctrl_for_each_ns(c, n) {
- c = nvme_ns_get_ctrl(n);
-
- row = table_get_row_id(t);
- if (row < 0) {
- printf("Failed to add row\n");
+ num_ns = 0;
+
+ nvme_ctrl_for_each_ns(c, n)
+ num_ns++;
+
+ if (!num_ns) {
+ ret = subsystem_topology_add_row(t,
+ "--", /* Namespace */
+ "--", /* NSID */
+ nvme_ctrl_get_name(c),
+ nvme_ctrl_get_transport(c),
+ nvme_ctrl_get_traddr(c),
+ nvme_ctrl_get_state(c));
+ if (ret < 0)
goto free_tbl;
- }
+ } else {
+ nvme_ctrl_for_each_ns(c, n) {
+ char nsid[32];
- /* col 0: Namespace */
- table_set_value_str(t, 0, row,
- nvme_ns_get_name(n), LEFT);
- /* col 1: NSID */
- table_set_value_int(t, 1, row,
- nvme_ns_get_nsid(n), CENTERED);
- /* col 2: Controller */
- table_set_value_str(t, 2, row,
- nvme_ctrl_get_name(c), LEFT);
- /* col 3: Trtype */
- table_set_value_str(t, 3, row,
- nvme_ctrl_get_transport(c), LEFT);
- /* col 4: Address */
- table_set_value_str(t, 4, row,
- nvme_ctrl_get_traddr(c), LEFT);
- /* col 5: State */
- table_set_value_str(t, 5, row,
- nvme_ctrl_get_state(c), LEFT);
+ snprintf(nsid, sizeof(nsid), "%u",
+ nvme_ns_get_nsid(n));
- table_add_row(t, row);
+ ret = subsystem_topology_add_row(t,
+ nvme_ns_get_name(n),
+ (const char *)nsid,
+ nvme_ctrl_get_name(c),
+ nvme_ctrl_get_transport(c),
+ nvme_ctrl_get_traddr(c),
+ nvme_ctrl_get_state(c));
+ if (ret < 0)
+ goto free_tbl;
+ }
}
}
table_print(t);
--
2.53.0
next prev parent reply other threads:[~2026-03-31 14:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-31 14:12 [PATCH 0/2] extend nvme show-topology tabular output Nilay Shroff
2026-03-31 14:12 ` Nilay Shroff [this message]
2026-03-31 14:12 ` [PATCH 2/2] nvme-cli: extend show-topology tabular output for multipath subsys Nilay Shroff
2026-04-01 14:05 ` [PATCH 0/2] extend nvme show-topology tabular output Daniel Wagner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260331141215.3098243-2-nilay@linux.ibm.com \
--to=nilay@linux.ibm.com \
--cc=dwagner@suse.de \
--cc=gjoyce@linux.ibm.com \
--cc=linux-nvme@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox