From: Ira Weiny <wei...@llnl.gov>
Date: Thu, 13 Aug 2009 20:16:01 -0700
Subject: [PATCH] infiniband-diags/libibnetdisc: Introduce a context object.

        This object must be created before query functions can be used and is
        used to control the functionality of the queries.

Signed-off-by: Ira Weiny <wei...@llnl.gov>
---
 infiniband-diags/libibnetdisc/Makefile.am          |    4 +-
 .../libibnetdisc/include/infiniband/ibnetdisc.h    |   23 ++++--
 .../libibnetdisc/man/ibnd_create_ctx.3             |    2 +
 .../libibnetdisc/man/ibnd_destroy_ctx.3            |    2 +
 .../libibnetdisc/man/ibnd_discover_fabric.3        |   41 ++++++++---
 infiniband-diags/libibnetdisc/src/ibnetdisc.c      |   74 ++++++++++++++------
 infiniband-diags/libibnetdisc/src/internal.h       |    5 ++
 infiniband-diags/libibnetdisc/src/libibnetdisc.map |    2 +
 infiniband-diags/libibnetdisc/test/testleaks.c     |    7 ++-
 infiniband-diags/src/iblinkinfo.c                  |    8 ++-
 infiniband-diags/src/ibnetdiscover.c               |   13 +++-
 infiniband-diags/src/ibqueryerrors.c               |    8 ++-
 12 files changed, 141 insertions(+), 48 deletions(-)
 create mode 100644 infiniband-diags/libibnetdisc/man/ibnd_create_ctx.3
 create mode 100644 infiniband-diags/libibnetdisc/man/ibnd_destroy_ctx.3

diff --git a/infiniband-diags/libibnetdisc/Makefile.am 
b/infiniband-diags/libibnetdisc/Makefile.am
index 7085f14..5619aad 100644
--- a/infiniband-diags/libibnetdisc/Makefile.am
+++ b/infiniband-diags/libibnetdisc/Makefile.am
@@ -45,7 +45,9 @@ man_MANS = man/ibnd_debug.3 \
        man/ibnd_iter_nodes.3 \
        man/ibnd_iter_nodes_type.3 \
        man/ibnd_show_progress.3 \
-       man/ibnd_update_node.3
+       man/ibnd_update_node.3 \
+       man/ibnd_create_ctx.3 \
+       man/ibnd_destroy_ctx.3
 
 EXTRA_DIST = $(srcdir)/src/libibnetdisc.map libibnetdisc.ver $(man_MANS)
 
diff --git a/infiniband-diags/libibnetdisc/include/infiniband/ibnetdisc.h 
b/infiniband-diags/libibnetdisc/include/infiniband/ibnetdisc.h
index 414e068..65ba74f 100644
--- a/infiniband-diags/libibnetdisc/include/infiniband/ibnetdisc.h
+++ b/infiniband-diags/libibnetdisc/include/infiniband/ibnetdisc.h
@@ -38,8 +38,11 @@
 #include <infiniband/mad.h>
 #include <iba/ib_types.h>
 
-struct ibnd_chassis;           /* forward declare */
-struct ibnd_port;              /* forward declare */
+typedef struct ibnd_ctx ibnd_ctx_t;
+
+/* forward declares */
+struct ibnd_chassis;
+struct ibnd_port;
 
 /** =========================================================================
  * Node
@@ -159,15 +162,21 @@ typedef struct ibnd_fabric {
 } ibnd_fabric_t;
 
 /** =========================================================================
- * Initialization (fabric operations)
+ * Initialization
  */
 MAD_EXPORT void ibnd_debug(int i);
-MAD_EXPORT void ibnd_show_progress(int i);
 
-MAD_EXPORT ibnd_fabric_t *ibnd_discover_fabric(struct ibmad_port *ibmad_port,
+MAD_EXPORT ibnd_ctx_t *ibnd_create_ctx(struct ibmad_port *ibmad_port);
+MAD_EXPORT void ibnd_destroy_ctx(ibnd_ctx_t * ctx);
+MAD_EXPORT int ibnd_show_progress(ibnd_ctx_t * ctx, int i);
+
+/** =========================================================================
+ * Fabric Operations
+ */
+MAD_EXPORT ibnd_fabric_t *ibnd_discover_fabric(ibnd_ctx_t * ctx,
                                               ib_portid_t * from, int hops);
        /**
-        * open: (required) ibmad_port object from libibmad
+        * ctx : (required) context created by ibnd_create_ctx.
         * from: (optional) specify the node to start scanning from.
         *       If NULL start from the node we are running on.
         * hops: (optional) Specify how much of the fabric to traverse.
@@ -181,7 +190,7 @@ MAD_EXPORT void ibnd_destroy_fabric(ibnd_fabric_t * fabric);
 MAD_EXPORT ibnd_node_t *ibnd_find_node_guid(ibnd_fabric_t * fabric,
                                            uint64_t guid);
 MAD_EXPORT ibnd_node_t *ibnd_find_node_dr(ibnd_fabric_t * fabric, char 
*dr_str);
-MAD_EXPORT ibnd_node_t *ibnd_update_node(struct ibmad_port *ibmad_port,
+MAD_EXPORT ibnd_node_t *ibnd_update_node(ibnd_ctx_t * ctx,
                                         ibnd_fabric_t * fabric,
                                         ibnd_node_t * node);
 
diff --git a/infiniband-diags/libibnetdisc/man/ibnd_create_ctx.3 
b/infiniband-diags/libibnetdisc/man/ibnd_create_ctx.3
new file mode 100644
index 0000000..8b321b0
--- /dev/null
+++ b/infiniband-diags/libibnetdisc/man/ibnd_create_ctx.3
@@ -0,0 +1,2 @@
+.\".TH IBND_CREATE_CTX 3  "Aug 12, 2009" "OpenIB" "OpenIB Programmer's Manual"
+.so man3/ibnd_discover_fabric.3
diff --git a/infiniband-diags/libibnetdisc/man/ibnd_destroy_ctx.3 
b/infiniband-diags/libibnetdisc/man/ibnd_destroy_ctx.3
new file mode 100644
index 0000000..bb9d96a
--- /dev/null
+++ b/infiniband-diags/libibnetdisc/man/ibnd_destroy_ctx.3
@@ -0,0 +1,2 @@
+.\".TH IBND_DESTROY_CTX 3  "Aug 12, 2009" "OpenIB" "OpenIB Programmer's Manual"
+.so man3/ibnd_discover_fabric.3
diff --git a/infiniband-diags/libibnetdisc/man/ibnd_discover_fabric.3 
b/infiniband-diags/libibnetdisc/man/ibnd_discover_fabric.3
index dfeaf47..f014977 100644
--- a/infiniband-diags/libibnetdisc/man/ibnd_discover_fabric.3
+++ b/infiniband-diags/libibnetdisc/man/ibnd_discover_fabric.3
@@ -1,46 +1,65 @@
 .TH IBND_DISCOVER_FABRIC 3  "July 25, 2008" "OpenIB" "OpenIB Programmer's 
Manual"
 .SH "NAME"
-ibnd_discover_fabric, ibnd_destroy_fabric, ibnd_debug ibnd_show_progress \- 
initialize ibnetdiscover library.
+ibnd_create_ctx, ibnd_destroy_ctx,
+ibnd_discover_fabric, ibnd_destroy_fabric, ibnd_debug, ibnd_show_progress \-
+initialize ibnetdiscover library and query the fabric.
 .SH "SYNOPSIS"
 .nf
 .B #include <infiniband/ibnetdisc.h>
 .sp
-.bi "ibnd_fabric_t *ibnd_discover_fabric(struct ibmad_port *ibmad_port, int 
timeout_ms, ib_portid_t *from, int hops)"
+.bi "ibnd_ctx_t *ibnd_create_ctx(struct ibmad_port *ibmad_port)"
+.BI "void ibnd_destroy_ctx(ibnd_ctx_t *ctx)"
+.bi "ibnd_fabric_t *ibnd_discover_fabric(ibnd_ctx_t *ctx, ib_portid_t *from, 
int hops)"
 .BI "void ibnd_destroy_fabric(ibnd_fabric_t *fabric)"
 .BI "void ibnd_debug(int i)"
-.BI "void ibnd_show_progress(int i)"
+.BI "int ibnd_show_progress(ibnd_ctx_t *ctx, int i)"
 .SH "DESCRIPTION"
-.B ibnd_discover_fabric()
-Discover the fabric connected to the port specified by ibmad_port, using a 
timeout specified.  The "from" and "hops" parameters are optional and allow one 
to scan part of a fabric by specifying a node "from" and a number of hops away 
from that node to scan, "hops".  This gives the user a "sub-fabric" which is 
"centered" anywhere they chose.
+.B ibnd_create_ctx()
+Create a context for the ibnetdiscover library to be used in query operations.
 
 ibmad_port must be opened with at least IB_SMI_CLASS and IB_SMI_DIRECT_CLASS
-classes for ibnd_discover_fabric to work.
+classes for queries to work.
+
+.B ibnd_discover_fabric()
+Discover the fabric using the context specified.  The "from" and "hops" 
parameters are optional and allow one to scan part of a fabric by specifying a 
node "from" and a number of hops away from that node to scan, "hops".  This 
gives the user a "sub-fabric" which is "centered" anywhere they chose.
 
 .B ibnd_destroy_fabric()
 free all memory and resources associated with the fabric.
 
+.B ibnd_destroy_ctx()
+free all memory and resources associated with the context.
+
 .B ibnd_debug()
 Set the debug level to be printed as library operations take place.
 
-.B ibnd_debug()
-Indicate that the library should print debug output which shows it's progress
+.B ibnd_show_progress()
+Indicate that the library should print output which shows it's progress
 through the fabric.
 
 .SH "RETURN VALUE"
+.B ibnd_create_ctx()
+return NULL on failure, otherwise a valid ibnd_ctx_t object.
+
 .B ibnd_discover_fabric()
 return NULL on failure, otherwise a valid ibnd_fabric_t object.
 
-.B ibnd_destory_fabric(), ibnd_debug()
+.B ibnd_show_progress()
+Returnes the previous setting for this value.
+
+.B ibnd_destory_fabric(), ibnd_debug(), ibnd_destroy_ctx()
 NONE
+
 .SH "EXAMPLES"
 
 .B Discover the entire fabric connected to device "mthca0", port 1.
 
        int mgmt_classes[2] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS};
        struct ibmad_port *ibmad_port = mad_rpc_open_port(ca, ca_port, 
mgmt_classes, 2);
-       ibnd_fabric_t *fabric = ibnd_discover_fabric(ibmad_port, 100, NULL, 0);
+       ibnd_ctx_t *ctx = ibnd_create_ctx(ibmad_port);
+       ibnd_fabric_t *fabric = ibnd_discover_fabric(ctx, NULL, 0);
        ...
        ibnd_destroy_fabric(fabric);
+       ibnd_destroy_ctx(ctx);
        mad_rpc_close_port(ibmad_port);
 
 .B Discover only a single node and those nodes connected to it.
@@ -48,7 +67,7 @@ NONE
        ...
        str2drpath(&(port_id.drpath), from, 0, 0);
        ...
-       ibnd_discover_fabric(ibmad_port, 100, &port_id, 1);
+       ibnd_discover_fabric(ctx, &port_id, 1);
        ...
 .SH "SEE ALSO"
        libibmad, mad_rpc_open_port
diff --git a/infiniband-diags/libibnetdisc/src/ibnetdisc.c 
b/infiniband-diags/libibnetdisc/src/ibnetdisc.c
index 2cd2c9b..4b320cd 100644
--- a/infiniband-diags/libibnetdisc/src/ibnetdisc.c
+++ b/infiniband-diags/libibnetdisc/src/ibnetdisc.c
@@ -57,9 +57,23 @@
 #include "internal.h"
 #include "chassis.h"
 
-static int show_progress = 0;
 int ibdebug;
 
+ibnd_ctx_t *ibnd_create_ctx(struct ibmad_port *ibmad_port)
+{
+       ibnd_ctx_t *rc = calloc(1, sizeof *rc);
+       if (!rc)
+               return (NULL);
+
+       rc->ibmad_port = ibmad_port;
+       return (rc);
+}
+
+void ibnd_destroy_ctx(ibnd_ctx_t * ctx)
+{
+       free(ctx);
+}
+
 void decode_port_info(ibnd_port_t * port)
 {
        port->base_lid = (uint16_t) mad_get_field(port->info, 0, IB_PORT_LID_F);
@@ -204,8 +218,6 @@ static void dump_endnode(ib_portid_t * path, char *prompt,
                         ibnd_node_t * node, ibnd_port_t * port)
 {
        char type[64];
-       if (!show_progress)
-               return;
 
        mad_dump_node_type(type, 64, &(node->type), sizeof(int)),
            printf("%s -> %s %s {%016" PRIx64
@@ -261,16 +273,29 @@ static int _check_ibmad_port(struct ibmad_port 
*ibmad_port)
        return (0);
 }
 
-ibnd_node_t *ibnd_update_node(struct ibmad_port * ibmad_port,
-                             ibnd_fabric_t * fabric, ibnd_node_t * node)
+static int check_ctx(ibnd_ctx_t * ctx)
+{
+       if (!ctx) {
+               IBND_DEBUG("ctx must be specified\n");
+               return (-1);
+       }
+
+       return (_check_ibmad_port(ctx->ibmad_port));
+}
+
+ibnd_node_t *ibnd_update_node(ibnd_ctx_t * ctx, ibnd_fabric_t * fabric,
+                             ibnd_node_t * node)
 {
        char portinfo_port0[IB_SMP_DATA_SIZE];
        void *nd = node->nodedesc;
        int p = 0;
+       struct ibmad_port *ibmad_port;
 
-       if (_check_ibmad_port(ibmad_port) < 0)
+       if (check_ctx(ctx) < 0)
                return (NULL);
 
+       ibmad_port = ctx->ibmad_port;
+
        if (!fabric) {
                IBND_DEBUG("fabric parameter NULL\n");
                return (NULL);
@@ -476,12 +501,12 @@ static void link_ports(ibnd_node_t * node, ibnd_port_t * 
port,
        remoteport->remoteport = (ibnd_port_t *) port;
 }
 
-static int get_remote_node(struct ibmad_port *ibmad_port,
-                          ibnd_fabric_t * fabric, ibnd_node_t * node,
-                          ibnd_port_t * port, ib_portid_t * path,
-                          int portnum, int dist)
+static int get_remote_node(ibnd_ctx_t * ctx, ibnd_fabric_t * fabric,
+                          ibnd_node_t * node, ibnd_port_t * port,
+                          ib_portid_t * path, int portnum, int dist)
 {
        int rc = 0;
+       struct ibmad_port *ibmad_port = ctx->ibmad_port;
        ibnd_node_t node_buf;
        ibnd_port_t port_buf;
        ibnd_node_t *remotenode, *oldnode;
@@ -525,8 +550,9 @@ static int get_remote_node(struct ibmad_port *ibmad_port,
                goto error;
        }
 
-       dump_endnode(path, oldnode ? "known remote" : "new remote",
-                    remotenode, remoteport);
+       if (ctx->show_progress)
+               dump_endnode(path, oldnode ? "known remote" : "new remote",
+                            remotenode, remoteport);
 
        link_ports(node, port, remotenode, remoteport);
 
@@ -535,7 +561,7 @@ error:
        return (rc);
 }
 
-ibnd_fabric_t *ibnd_discover_fabric(struct ibmad_port * ibmad_port,
+ibnd_fabric_t *ibnd_discover_fabric(ibnd_ctx_t * ctx,
                                    ib_portid_t * from, int hops)
 {
        int rc = 0;
@@ -550,7 +576,7 @@ ibnd_fabric_t *ibnd_discover_fabric(struct ibmad_port * 
ibmad_port,
        ib_portid_t *path;
        int max_hops = MAXHOPS - 1;     /* default find everything */
 
-       if (_check_ibmad_port(ibmad_port) < 0)
+       if (check_ctx(ctx) < 0)
                return (NULL);
 
        /* if not everything how much? */
@@ -576,7 +602,7 @@ ibnd_fabric_t *ibnd_discover_fabric(struct ibmad_port * 
ibmad_port,
        memset(&node_buf, 0, sizeof(node_buf));
        memset(&port_buf, 0, sizeof(port_buf));
 
-       if (query_node(ibmad_port, fabric, &node_buf, &port_buf, from)) {
+       if (query_node(ctx->ibmad_port, fabric, &node_buf, &port_buf, from)) {
                IBND_DEBUG("can't reach node %s\n", portid2str(from));
                goto error;
        }
@@ -591,7 +617,7 @@ ibnd_fabric_t *ibnd_discover_fabric(struct ibmad_port * 
ibmad_port,
        if (!port)
                goto error;
 
-       rc = get_remote_node(ibmad_port, fabric, node, port, from,
+       rc = get_remote_node(ctx, fabric, node, port, from,
                             mad_get_field(node->info, 0,
                                           IB_NODE_LOCAL_PORT_F), 0);
        if (rc < 0)
@@ -606,14 +632,15 @@ ibnd_fabric_t *ibnd_discover_fabric(struct ibmad_port * 
ibmad_port,
                        path = &node->path_portid;
 
                        IBND_DEBUG("dist %d node %p\n", dist, node);
-                       dump_endnode(path, "processing", node, port);
+                       if (ctx->show_progress)
+                               dump_endnode(path, "processing", node, port);
 
                        for (i = 1; i <= node->numports; i++) {
                                if (i == mad_get_field(node->info, 0,
                                                       IB_NODE_LOCAL_PORT_F))
                                        continue;
 
-                               if (get_port_info(ibmad_port, fabric,
+                               if (get_port_info(ctx->ibmad_port, fabric,
                                                  &port_buf, i, path)) {
                                        IBND_ERROR
                                            ("can't reach node %s port %d",
@@ -637,7 +664,7 @@ ibnd_fabric_t *ibnd_discover_fabric(struct ibmad_port * 
ibmad_port,
                                                            
IB_NODE_PORT_GUID_F);
                                }
 
-                               if (get_remote_node(ibmad_port, fabric, node,
+                               if (get_remote_node(ctx, fabric, node,
                                                    port, path, i, dist) < 0)
                                        goto error;
                        }
@@ -704,9 +731,14 @@ void ibnd_debug(int i)
        }
 }
 
-void ibnd_show_progress(int i)
+int ibnd_show_progress(ibnd_ctx_t * ctx, int i)
 {
-       show_progress = i;
+       int rc = 0;
+       if (check_ctx(ctx))
+               return (-1);
+       rc = ctx->show_progress;
+       ctx->show_progress = i;
+       return (rc);
 }
 
 void ibnd_iter_nodes(ibnd_fabric_t * fabric, ibnd_iter_node_func_t func,
diff --git a/infiniband-diags/libibnetdisc/src/internal.h 
b/infiniband-diags/libibnetdisc/src/internal.h
index ba32291..8753eae 100644
--- a/infiniband-diags/libibnetdisc/src/internal.h
+++ b/infiniband-diags/libibnetdisc/src/internal.h
@@ -47,4 +47,9 @@
 #define        IBND_ERROR(fmt, ...) \
                fprintf(stderr, "%s:%u; " fmt, __FILE__, __LINE__, ## 
__VA_ARGS__)
 
+struct ibnd_ctx {
+       struct ibmad_port *ibmad_port;
+       int show_progress;
+};
+
 #endif                         /* _INTERNAL_H_ */
diff --git a/infiniband-diags/libibnetdisc/src/libibnetdisc.map 
b/infiniband-diags/libibnetdisc/src/libibnetdisc.map
index bd108ab..56560ec 100644
--- a/infiniband-diags/libibnetdisc/src/libibnetdisc.map
+++ b/infiniband-diags/libibnetdisc/src/libibnetdisc.map
@@ -2,6 +2,8 @@ IBNETDISC_1.0 {
        global:
                ibnd_debug;
                ibnd_show_progress;
+               ibnd_create_ctx;
+               ibnd_destroy_ctx;
                ibnd_discover_fabric;
                ibnd_destroy_fabric;
                ibnd_find_node_guid;
diff --git a/infiniband-diags/libibnetdisc/test/testleaks.c 
b/infiniband-diags/libibnetdisc/test/testleaks.c
index cb5651e..b121bdd 100644
--- a/infiniband-diags/libibnetdisc/test/testleaks.c
+++ b/infiniband-diags/libibnetdisc/test/testleaks.c
@@ -87,6 +87,7 @@ int main(int argc, char **argv)
        int hops = 0;
        ib_portid_t port_id;
        int iters = -1;
+       ibnd_ctx_t *ctx = NULL;
 
        struct ibmad_port *ibmad_port;
        int mgmt_classes[2] = { IB_SMI_CLASS, IB_SMI_DIRECT_CLASS };
@@ -156,11 +157,12 @@ int main(int argc, char **argv)
 
        mad_rpc_set_timeout(ibmad_port, timeout_ms);
 
+       ctx = ibnd_create_ctx(ibmad_port);
        while (iters == -1 || iters-- > 0) {
                if (from) {
                        /* only scan part of the fabric */
                        str2drpath(&(port_id.drpath), from, 0, 0);
-                       if ((fabric = ibnd_discover_fabric(ibmad_port,
+                       if ((fabric = ibnd_discover_fabric(ctx,
                                                           &port_id,
                                                           hops)) == NULL) {
                                fprintf(stderr, "discover failed\n");
@@ -170,7 +172,7 @@ int main(int argc, char **argv)
                        guid = 0;
                } else {
                        if ((fabric =
-                            ibnd_discover_fabric(ibmad_port, NULL,
+                            ibnd_discover_fabric(ctx, NULL,
                                                  -1)) == NULL) {
                                fprintf(stderr, "discover failed\n");
                                rc = 1;
@@ -182,6 +184,7 @@ int main(int argc, char **argv)
        }
 
 close_port:
+       ibnd_destroy_ctx(ctx);
        mad_rpc_close_port(ibmad_port);
        exit(rc);
 }
diff --git a/infiniband-diags/src/iblinkinfo.c 
b/infiniband-diags/src/iblinkinfo.c
index 5dfadee..af5be09 100644
--- a/infiniband-diags/src/iblinkinfo.c
+++ b/infiniband-diags/src/iblinkinfo.c
@@ -274,6 +274,7 @@ main(int argc, char **argv)
        int rc = 0;
        int resolved = -1;
        ibnd_fabric_t *fabric = NULL;
+       ibnd_ctx_t *ctx = NULL;
        struct ibmad_port *ibmad_port;
        ib_portid_t port_id = {0};
        int mgmt_classes[3] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS};
@@ -313,6 +314,8 @@ main(int argc, char **argv)
 
        node_name_map = open_node_name_map(node_name_map_file);
 
+       ctx = ibnd_create_ctx(ibmad_port);
+
        if (dr_path) {
                /* only scan part of the fabric */
                if ((resolved = ib_resolve_portid_str_via(&port_id, dr_path, 
IB_DEST_DRPATH,
@@ -327,12 +330,12 @@ main(int argc, char **argv)
        }
 
        if (resolved >= 0)
-               if ((fabric = ibnd_discover_fabric(ibmad_port, &port_id,
+               if ((fabric = ibnd_discover_fabric(ctx, &port_id,
                                hops)) == NULL)
                        IBWARN("Single node discover failed; attempting full 
scan\n");
 
        if (!fabric)
-               if ((fabric = ibnd_discover_fabric(ibmad_port, NULL, -1)) == 
NULL) {
+               if ((fabric = ibnd_discover_fabric(ctx, NULL, -1)) == NULL) {
                        fprintf(stderr, "discover failed\n");
                        rc = 1;
                        goto close_port;
@@ -364,6 +367,7 @@ main(int argc, char **argv)
        ibnd_destroy_fabric(fabric);
 
 close_port:
+       ibnd_destroy_ctx(ctx);
        close_node_name_map(node_name_map);
        mad_rpc_close_port(ibmad_port);
        exit(rc);
diff --git a/infiniband-diags/src/ibnetdiscover.c 
b/infiniband-diags/src/ibnetdiscover.c
index b04f2c6..ecb591e 100644
--- a/infiniband-diags/src/ibnetdiscover.c
+++ b/infiniband-diags/src/ibnetdiscover.c
@@ -65,6 +65,7 @@ static char *node_name_map_file = NULL;
 static nn_map_t *node_name_map = NULL;
 
 static int report_max_hops = 0;
+static int show_progress = 0;
 
 /**
  * Define our own conversion functions to maintain compatibility with the old
@@ -610,7 +611,7 @@ static int process_opt(void *context, int ch, char *optarg)
                node_name_map_file = strdup(optarg);
                break;
        case 's':
-               ibnd_show_progress(1);
+               show_progress = 1;
                break;
        case 'l':
                list = LIST_CA_NODE | LIST_SWITCH_NODE | LIST_ROUTER_NODE;
@@ -643,6 +644,7 @@ static int process_opt(void *context, int ch, char *optarg)
 int main(int argc, char **argv)
 {
        ibnd_fabric_t *fabric = NULL;
+       ibnd_ctx_t *ctx = NULL;
 
        struct ibmad_port *ibmad_port;
        int mgmt_classes[2] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS};
@@ -683,8 +685,14 @@ int main(int argc, char **argv)
                IBERROR("can't open file %s for writing", argv[0]);
 
        node_name_map = open_node_name_map(node_name_map_file);
+       ctx = ibnd_create_ctx(ibmad_port);
 
-       if ((fabric = ibnd_discover_fabric(ibmad_port, NULL, -1)) == NULL)
+       if (!ctx)
+               IBERROR("failed to create libibnetdisc context\n");
+
+       ibnd_show_progress(ctx, show_progress);
+
+       if ((fabric = ibnd_discover_fabric(ctx, NULL, -1)) == NULL)
                IBERROR("discover failed\n");
 
        if (ports_report)
@@ -697,6 +705,7 @@ int main(int argc, char **argv)
                dump_topology(group, fabric);
 
        ibnd_destroy_fabric(fabric);
+       ibnd_destroy_ctx(ctx);
        close_node_name_map(node_name_map);
        mad_rpc_close_port(ibmad_port);
        exit(0);
diff --git a/infiniband-diags/src/ibqueryerrors.c 
b/infiniband-diags/src/ibqueryerrors.c
index 2c85423..0955415 100644
--- a/infiniband-diags/src/ibqueryerrors.c
+++ b/infiniband-diags/src/ibqueryerrors.c
@@ -392,6 +392,7 @@ main(int argc, char **argv)
        ib_portid_t portid = {0};
        int rc = 0;
        ibnd_fabric_t *fabric = NULL;
+       ibnd_ctx_t *ctx = NULL;
 
        int mgmt_classes[4] = {IB_SMI_CLASS, IB_SMI_DIRECT_CLASS, IB_SA_CLASS, 
IB_PERFORMANCE_CLASS};
 
@@ -427,6 +428,8 @@ main(int argc, char **argv)
 
        node_name_map = open_node_name_map(node_name_map_file);
 
+       ctx = ibnd_create_ctx(ibmad_port);
+
        /* limit the scan the fabric around the target */
        if (dr_path) {
                if ((resolved = ib_resolve_portid_str_via(&portid, dr_path, 
IB_DEST_DRPATH,
@@ -440,12 +443,12 @@ main(int argc, char **argv)
        }
 
        if (resolved >= 0)
-               if ((fabric = ibnd_discover_fabric(ibmad_port, &portid,
+               if ((fabric = ibnd_discover_fabric(ctx, &portid,
                                0)) == NULL)
                        IBWARN("Single node discover failed; attempting full 
scan\n");
 
        if (!fabric) /* do a full scan */
-               if ((fabric = ibnd_discover_fabric(ibmad_port, NULL, -1)) == 
NULL) {
+               if ((fabric = ibnd_discover_fabric(ctx, NULL, -1)) == NULL) {
                        fprintf(stderr, "discover failed\n");
                        rc = 1;
                        goto close_port;
@@ -479,6 +482,7 @@ main(int argc, char **argv)
        ibnd_destroy_fabric(fabric);
 
 close_port:
+       ibnd_destroy_ctx(ctx);
        mad_rpc_close_port(ibmad_port);
        close_node_name_map(node_name_map);
        exit(rc);
-- 
1.5.4.5

_______________________________________________
general mailing list
general@lists.openfabrics.org
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general

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

Reply via email to