[ofa-general] [PATCH 6/8] Convert ibnetdiscover and iblinkinfo to use the new interface to libibnetdisc

Ira Weiny weiny2 at llnl.gov
Thu Apr 23 13:31:09 PDT 2009


From: Ira Weiny <weiny2 at llnl.gov>
Date: Thu, 23 Apr 2009 10:57:10 -0700
Subject: [PATCH] Convert ibnetdiscover and iblinkinfo to use the new interface to libibnetdisc

Signed-off-by: Ira Weiny <weiny2 at llnl.gov>
---
 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 39de7a2..82c2ce8 100644
--- a/infiniband-diags/src/iblinkinfo.c
+++ b/infiniband-diags/src/iblinkinfo.c
@@ -257,6 +257,7 @@ usage(void)
 int
 main(int argc, char **argv)
 {
+	int rc = 0;
 	char *ca = 0;
 	int ca_port = 0;
 	ibnd_fabric_t *fabric = NULL;
@@ -266,6 +267,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'},
@@ -354,20 +358,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;
 		}
 	}
 
@@ -383,6 +395,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..69fc5fb 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("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




More information about the general mailing list