From: Vladimir Koushnir <vladimirk@xxxxxxxxxxxx> 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@xxxxxxxxxxxx> Signed-off-by: Haim Boozaglo <haimbo@xxxxxxxxxxxx> --- 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