linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Haim Boozaglo <haimbo@mellanox.com>
To: linux-rdma@vger.kernel.org
Cc: Vladimir Koushnir <vladimirk@mellanox.com>,
	Haim Boozaglo <haimbo@mellanox.com>
Subject: [PATCH 3/3] ibdiags: Support arbitrary number of IB devices in ibstat
Date: Tue,  6 Aug 2019 14:38:54 +0000	[thread overview]
Message-ID: <1565102334-20903-3-git-send-email-haimbo@mellanox.com> (raw)
In-Reply-To: <1565102334-20903-1-git-send-email-haimbo@mellanox.com>

From: Vladimir Koushnir <vladimirk@mellanox.com>

Allow showing more than 32 IB devices on the server.
umad_get_ca_namelist API is used for this purpose.

Signed-off-by: Vladimir Koushnir <vladimirk@mellanox.com>
Signed-off-by: Haim Boozaglo <haimbo@mellanox.com>
---
 infiniband-diags/ibstat.c | 47 ++++++++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 21 deletions(-)

diff --git a/infiniband-diags/ibstat.c b/infiniband-diags/ibstat.c
index 4601f2a..9c87ff8 100644
--- a/infiniband-diags/ibstat.c
+++ b/infiniband-diags/ibstat.c
@@ -232,23 +232,22 @@ static int ca_stat(char *ca_name, int portnum, int no_ports)
 	return 0;
 }
 
-static int ports_list(char names[][UMAD_CA_NAME_LEN], int n)
+static int ports_list(char *names, int n)
 {
 	__be64 guids[64];
-	int found, ports, i;
+	int ports, i, j;
 
-	for (i = 0, found = 0; i < n && found < 64; i++) {
+	for (i = 0; i < n ; i++) {
 		if ((ports =
-		     umad_get_ca_portguids(names[i], guids + found,
-					   64 - found)) < 0)
+		     umad_get_ca_portguids(&names[i * UMAD_CA_NAME_LEN],
+					   &guids[0], 64)) < 0)
 			return -1;
-		found += ports;
-	}
 
-	for (i = 0; i < found; i++)
-		if (guids[i])
-			printf("0x%016" PRIx64 "\n", be64toh(guids[i]));
-	return found;
+		for (j = 0; j < ports; j++)
+			if (guids[j])
+				printf("0x%016" PRIx64 "\n", be64toh(guids[j]));
+	}
+	return 0;
 }
 
 static int list_only, short_format, list_ports;
@@ -273,9 +272,10 @@ static int process_opt(void *context, int ch)
 
 int main(int argc, char *argv[])
 {
-	char names[UMAD_MAX_DEVICES][UMAD_CA_NAME_LEN];
+	char *names;
 	int dev_port = -1;
 	int n, i;
+	char *nptr;
 
 	const struct ibdiag_opt opts[] = {
 		{"list_of_cas", 'l', 0, NULL, "list all IB devices"},
@@ -302,33 +302,38 @@ int main(int argc, char *argv[])
 	if (umad_init() < 0)
 		IBPANIC("can't init UMAD library");
 
-	if ((n = umad_get_cas_names(names, UMAD_MAX_DEVICES)) < 0)
+	if ((n = umad_get_ca_namelist(&names)) < 0)
 		IBPANIC("can't list IB device names");
 
 	if (argc) {
 		for (i = 0; i < n; i++)
-			if (!strncmp(names[i], argv[0], sizeof names[i]))
+			if (!strncmp(&names[i * UMAD_CA_NAME_LEN],
+				     argv[0], UMAD_CA_NAME_LEN))
 				break;
 		if (i >= n)
 			IBPANIC("'%s' IB device can't be found", argv[0]);
-
-		strncpy(names[0], argv[0], sizeof(names[0])-1);
-		names[0][sizeof(names[0])-1] = '\0';
+		if (i != 0) {
+			strncpy(&names[0],
+				&names[i * UMAD_CA_NAME_LEN],
+				UMAD_CA_NAME_LEN);
+		}
 		n = 1;
 	}
 
 	if (list_ports) {
 		if (ports_list(names, n) < 0)
 			IBPANIC("can't list ports");
+		umad_free_ca_namelist(names);
 		return 0;
 	}
 
 	for (i = 0; i < n; i++) {
+		nptr = &names[i * UMAD_CA_NAME_LEN];
 		if (list_only)
-			printf("%s\n", names[i]);
-		else if (ca_stat(names[i], dev_port, short_format) < 0)
-			IBPANIC("stat of IB device '%s' failed", names[i]);
+			printf("%s\n", nptr);
+		else if (ca_stat(nptr, dev_port, short_format) < 0)
+			IBPANIC("stat of IB device '%s' failed", nptr);
 	}
-
+	umad_free_ca_namelist(names);
 	return 0;
 }
-- 
1.8.3.1


  parent reply	other threads:[~2019-08-06 14:39 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-06 14:38 [PATCH 1/3] libibumad: Support arbitrary number of IB devices Haim Boozaglo
2019-08-06 14:38 ` [PATCH 2/3] libibumad: Redesign resolve_ca_name to support " Haim Boozaglo
2019-08-06 14:38 ` Haim Boozaglo [this message]
2019-08-06 15:52 ` [PATCH 1/3] libibumad: Support " Leon Romanovsky
2019-08-07  7:26   ` Vladimir Koushnir
2019-08-07  7:44     ` Leon Romanovsky
2019-08-07  8:09       ` Vladimir Koushnir
2019-08-11 16:29 [PATCH rdma-core 0/3] get more than 32 available InfiniBand device names Haim Boozaglo
2019-08-11 16:29 ` [PATCH 3/3] ibdiags: Support arbitrary number of IB devices in ibstat Haim Boozaglo

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=1565102334-20903-3-git-send-email-haimbo@mellanox.com \
    --to=haimbo@mellanox.com \
    --cc=linux-rdma@vger.kernel.org \
    --cc=vladimirk@mellanox.com \
    /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;
as well as URLs for NNTP newsgroup(s).