>From 3b4e97a345e8a0758cb9ef6de6517de61922831c Mon Sep 17 00:00:00 2001
From: Ira Weiny <[email protected]>
Date: Wed, 22 Apr 2009 18:44:17 -0700
Subject: [PATCH] Convert ibnetdiscover and iblinkinfo to use the new interface 
to libibnetdisc

Signed-off-by: Ira Weiny <[email protected]>
---
 infiniband-diags/src/iblinkinfo.c    |   24 +++++++++++++++++++-----
 infiniband-diags/src/ibnetdiscover.c |   14 ++++++++++----
 2 files changed, 29 insertions(+), 9 deletions(-)

diff --git a/infiniband-diags/src/iblinkinfo.c 
b/infiniband-diags/src/iblinkinfo.c
index 1e43788..16728cb 100644
--- a/infiniband-diags/src/iblinkinfo.c
+++ b/infiniband-diags/src/iblinkinfo.c
@@ -255,6 +255,7 @@ usage(void)
 int
 main(int argc, char **argv)
 {
+       int rc = 0;
        char *ca = 0;
        int ca_port = 0;
        ibnd_fabric_t *fabric = NULL;
@@ -264,6 +265,9 @@ main(int argc, char **argv)
        int hops = 0;
        ib_portid_t port_id;
 
+       struct ibmad_port *ibmad_port;
+       int mgmt_classes[2] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS};
+
        static char const str_opts[] = "S:D:n:C:P:t:sldgphuf:R";
        static const struct option long_opts[] = {
                { "S", 1, 0, 'S'},
@@ -352,20 +356,28 @@ main(int argc, char **argv)
        if (argc && !(f = fopen(argv[0], "w")))
                fprintf(stderr, "can't open file %s for writing", argv[0]);
 
+       ibmad_port = mad_rpc_open_port(ca, ca_port, mgmt_classes, 2);
+       if (!ibmad_port) {
+               fprintf(stderr, "Failed to open %s port %d", ca, ca_port);
+               exit(1);
+       }
+
        node_name_map = open_node_name_map(node_name_map_file);
 
        if (from) {
                /* only scan part of the fabric */
                str2drpath(&(port_id.drpath), from, 0, 0);
-               if ((fabric = ibnd_discover_fabric(ca, ca_port, timeout_ms, 
&port_id, hops)) == NULL) {
+               if ((fabric = ibnd_discover_fabric(ibmad_port, timeout_ms, 
&port_id, hops)) == NULL) {
                        fprintf(stderr, "discover failed\n");
-                       exit(1);
+                       rc = 1;
+                       goto close_port;
                }
                guid = 0;
        } else {
-               if ((fabric = ibnd_discover_fabric(ca, ca_port, timeout_ms, 
NULL, -1)) == NULL) {
+               if ((fabric = ibnd_discover_fabric(ibmad_port, timeout_ms, 
NULL, -1)) == NULL) {
                        fprintf(stderr, "discover failed\n");
-                       exit(1);
+                       rc = 1;
+                       goto close_port;
                }
        }
 
@@ -381,6 +393,8 @@ main(int argc, char **argv)
 
        ibnd_destroy_fabric(fabric);
 
+close_port:
        close_node_name_map(node_name_map);
-       exit(0);
+       mad_rpc_close_port(ibmad_port);
+       exit(rc);
 }
diff --git a/infiniband-diags/src/ibnetdiscover.c 
b/infiniband-diags/src/ibnetdiscover.c
index 99750f0..4cd0b37 100644
--- a/infiniband-diags/src/ibnetdiscover.c
+++ b/infiniband-diags/src/ibnetdiscover.c
@@ -650,6 +650,9 @@ int main(int argc, char **argv)
 {
        ibnd_fabric_t *fabric = NULL;
 
+       struct ibmad_port *ibmad_port;
+       int mgmt_classes[2] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS};
+
        const struct ibdiag_opt opts[] = {
                { "show", 's', 0, NULL, "show more information" },
                { "list", 'l', 0, NULL, "list of connected nodes" },
@@ -677,15 +680,17 @@ int main(int argc, char **argv)
        if (ibverbose)
                ibnd_debug(1);
 
+       ibmad_port = mad_rpc_open_port(ibd_ca, ibd_ca_port, mgmt_classes, 2);
+       if (!ibmad_port)
+               IBERROR("Failed to open %s port %d", ibd_ca, ibd_ca_port);
+
        if (argc && !(f = fopen(argv[0], "w")))
                IBERROR("can't open file %s for writing", argv[0]);
 
        node_name_map = open_node_name_map(node_name_map_file);
 
-       if ((fabric = ibnd_discover_fabric(ibd_ca, ibd_ca_port, ibd_timeout, 
NULL, -1)) == NULL) {
-               fprintf(stderr, "discover failed\n");
-               exit(1);
-       }
+       if ((fabric = ibnd_discover_fabric(ibmad_port, ibd_timeout, NULL, -1)) 
== NULL)
+               IBERROR(stderr, "discover failed\n");
 
        if (ports_report)
                ibnd_iter_nodes(fabric,
@@ -698,5 +703,6 @@ int main(int argc, char **argv)
 
        ibnd_destroy_fabric(fabric);
        close_node_name_map(node_name_map);
+       mad_rpc_close_port(ibmad_port);
        exit(0);
 }
-- 
1.5.4.5

_______________________________________________
general mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to