diff mbox series

[iproute2-rc,v1,2/2] rdma: Properly print device and link names in CLI output

Message ID 20200811073201.663398-3-leon@kernel.org
State Accepted
Delegated to: stephen hemminger
Headers show
Series Fix rdmatool JSON conversion | expand

Commit Message

Leon Romanovsky Aug. 11, 2020, 7:32 a.m. UTC
From: Leon Romanovsky <leonro@nvidia.com>

The citied commit broke the CLI output and printed ifindex/ifname
instead of dev/link.

Before:
[leonro@vm ~]$ rdma res show qp
link mlx5_0/lqpn 1 type GSI state RTS sq-psn 0 comm ib_core
[leonro@vm ~]$ rdma res show cq
ifindex 0 ifname rocep0s9 cqn 0 cqe 1023 users 2 poll-ctx WORKQUEUE adaptive-moderation on comm ib_core

After:
[leonro@vm ~]$ rdma res show qp
link mlx5_0/- lqpn 1 type GSI state RTS sq-psn 0 comm [ib_core]
[leonro@vm ~]$ rdma res show cq
dev rocep0s9 cqn 0 cqe 1023 users 2 poll-ctx WORKQUEUE adaptive-moderation on comm [ib_core]

It was missed because rdmatool mostly used in JSON mode.

Fixes: b0a688a542cd ("rdma: Rewrite custom JSON and prints logic to use common API")
Signed-off-by: Leon Romanovsky <leonro@nvidia.com>
---
 rdma/res.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

--
2.26.2

Comments

Stephen Hemminger Aug. 16, 2020, 10:48 p.m. UTC | #1
On Tue, 11 Aug 2020 10:32:01 +0300
Leon Romanovsky <leon@kernel.org> wrote:

> +	print_color_string(PRINT_ANY, COLOR_NONE, "ifname", "dev %s ", name);

Since this is an interface name, you might want to consider using COLOR_IFNAME?

I will go ahead and apply it as is but more work is needed here.
Leon Romanovsky Aug. 17, 2020, 7:44 a.m. UTC | #2
On Sun, Aug 16, 2020 at 03:48:46PM -0700, Stephen Hemminger wrote:
> On Tue, 11 Aug 2020 10:32:01 +0300
> Leon Romanovsky <leon@kernel.org> wrote:
>
> > +	print_color_string(PRINT_ANY, COLOR_NONE, "ifname", "dev %s ", name);
>
> Since this is an interface name, you might want to consider using COLOR_IFNAME?
>
> I will go ahead and apply it as is but more work is needed here.

Thanks for taking care.
diff mbox series

Patch

diff --git a/rdma/res.c b/rdma/res.c
index b7a703f8..dc12bbe4 100644
--- a/rdma/res.c
+++ b/rdma/res.c
@@ -166,17 +166,27 @@  void print_comm(struct rd *rd, const char *str, struct nlattr **nla_line)

 void print_dev(struct rd *rd, uint32_t idx, const char *name)
 {
-	print_color_int(PRINT_ANY, COLOR_NONE, "ifindex", "ifindex %d ", idx);
-	print_color_string(PRINT_ANY, COLOR_NONE, "ifname", "ifname %s ", name);
+	print_color_int(PRINT_ANY, COLOR_NONE, "ifindex", NULL, idx);
+	print_color_string(PRINT_ANY, COLOR_NONE, "ifname", "dev %s ", name);
 }

 void print_link(struct rd *rd, uint32_t idx, const char *name, uint32_t port,
 		struct nlattr **nla_line)
 {
+	char tmp[64] = {};
+
 	print_color_uint(PRINT_JSON, COLOR_NONE, "ifindex", NULL, idx);
-	print_color_string(PRINT_ANY, COLOR_NONE, "ifname", "link %s/", name);
-	if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
-		print_color_uint(PRINT_ANY, COLOR_NONE, "port", "%u ", port);
+	print_color_string(PRINT_ANY, COLOR_NONE, "ifname", NULL, name);
+	if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]) {
+		print_color_uint(PRINT_ANY, COLOR_NONE, "port", NULL, port);
+		snprintf(tmp, sizeof(tmp), "%s/%d", name, port);
+	} else {
+		snprintf(tmp, sizeof(tmp), "%s/-", name);
+	}
+
+	if (!rd->json_output)
+		print_color_string(PRINT_ANY, COLOR_NONE, NULL, "link %s ",
+				   tmp);
 }

 void print_qp_type(struct rd *rd, uint32_t val)