[ofa-general] [PATCH 3/5] libibnetdisc: make all fields of ibnd_fabric_t public

Ira Weiny weiny2 at llnl.gov
Thu Aug 13 20:42:51 PDT 2009


From: Ira Weiny <weiny2 at llnl.gov>
Date: Thu, 13 Aug 2009 20:08:51 -0700
Subject: [PATCH] libibnetdisc: make all fields of ibnd_fabric_t public

	In addition clean up the name of the chassis struct

Signed-off-by: Ira Weiny <weiny2 at llnl.gov>
---
 .../libibnetdisc/include/infiniband/ibnetdisc.h    |   41 +++++++++----
 infiniband-diags/libibnetdisc/src/chassis.c        |   23 ++++----
 infiniband-diags/libibnetdisc/src/ibnetdisc.c      |   63 +++++++++-----------
 infiniband-diags/libibnetdisc/src/internal.h       |   24 --------
 4 files changed, 69 insertions(+), 82 deletions(-)

diff --git a/infiniband-diags/libibnetdisc/include/infiniband/ibnetdisc.h b/infiniband-diags/libibnetdisc/include/infiniband/ibnetdisc.h
index 4a57855..414e068 100644
--- a/infiniband-diags/libibnetdisc/include/infiniband/ibnetdisc.h
+++ b/infiniband-diags/libibnetdisc/include/infiniband/ibnetdisc.h
@@ -38,8 +38,7 @@
 #include <infiniband/mad.h>
 #include <iba/ib_types.h>
 
-struct ib_fabric;		/* forward declare */
-struct chassis;			/* forward declare */
+struct ibnd_chassis;		/* forward declare */
 struct ibnd_port;		/* forward declare */
 
 /** =========================================================================
@@ -67,13 +66,13 @@ typedef struct ibnd_node {
 
 	char nodedesc[IB_SMP_DATA_SIZE];
 
-	struct ibnd_port **ports; /* in order array of port pointers
-				   the size of this array is info.numports + 1
-				   items MAY BE NULL!  (ie 0 == switches only) */
+	struct ibnd_port **ports;	/* in order array of port pointers
+					   the size of this array is info.numports + 1
+					   items MAY BE NULL!  (ie 0 == switches only) */
 
 	/* chassis info */
 	struct ibnd_node *next_chassis_node;	/* next node in ibnd_chassis_t->nodes */
-	struct chassis *chassis;	/* if != NULL the chassis this node belongs to */
+	struct ibnd_chassis *chassis;	/* if != NULL the chassis this node belongs to */
 	unsigned char ch_type;
 	unsigned char ch_anafanum;
 	unsigned char ch_slotnum;
@@ -92,9 +91,9 @@ typedef struct ibnd_node {
 typedef struct ibnd_port {
 	uint64_t guid;
 	int portnum;
-	int ext_portnum; /* optional if != 0 external port num */
-	ibnd_node_t *node; /* node this port belongs to */
-	struct ibnd_port *remoteport; /* null if SMA, or does not exist */
+	int ext_portnum;	/* optional if != 0 external port num */
+	ibnd_node_t *node;	/* node this port belongs to */
+	struct ibnd_port *remoteport;	/* null if SMA, or does not exist */
 	/* quick cache of info below */
 	uint16_t base_lid;
 	uint8_t lmc;
@@ -108,8 +107,8 @@ typedef struct ibnd_port {
 /** =========================================================================
  * Chassis
  */
-typedef struct chassis {
-	struct chassis *next;
+typedef struct ibnd_chassis {
+	struct ibnd_chassis *next;
 	uint64_t chassisguid;
 	unsigned char chassisnum;
 
@@ -124,11 +123,17 @@ typedef struct chassis {
 	ibnd_node_t *linenode[LINES_MAX_NUM + 1];
 } ibnd_chassis_t;
 
+/* HASH table defines */
+#define HASHGUID(guid) ((uint32_t)(((uint32_t)(guid) * 101) ^ ((uint32_t)((guid) >> 32) * 103)))
+#define HTSZ 137
+
+#define MAXHOPS		63
+
 /** =========================================================================
  * Fabric
  * Main fabric object which is returned and represents the data discovered
  */
-typedef struct ib_fabric {
+typedef struct ibnd_fabric {
 	/* the node the discover was initiated from
 	 * "from" parameter in ibnd_discover_fabric
 	 * or by default the node you ar running on
@@ -139,6 +144,18 @@ typedef struct ib_fabric {
 	/* NULL terminated list of all chassis found in the fabric */
 	ibnd_chassis_t *chassis;
 	int maxhops_discovered;
+
+	/* internal use only */
+	ibnd_node_t *nodestbl[HTSZ];
+	ibnd_port_t *portstbl[HTSZ];
+	ibnd_node_t *nodesdist[MAXHOPS + 1];
+	ibnd_chassis_t *first_chassis;
+	ibnd_chassis_t *current_chassis;
+	ibnd_chassis_t *last_chassis;
+	ibnd_node_t *switches;
+	ibnd_node_t *ch_adapters;
+	ibnd_node_t *routers;
+	ib_portid_t selfportid;
 } ibnd_fabric_t;
 
 /** =========================================================================
diff --git a/infiniband-diags/libibnetdisc/src/chassis.c b/infiniband-diags/libibnetdisc/src/chassis.c
index 0dd259a..4886cfc 100644
--- a/infiniband-diags/libibnetdisc/src/chassis.c
+++ b/infiniband-diags/libibnetdisc/src/chassis.c
@@ -91,7 +91,7 @@ char *ibnd_get_chassis_slot_str(ibnd_node_t * node, char *str, size_t size)
 	return (str);
 }
 
-static ibnd_chassis_t *find_chassisnum(struct ibnd_fabric *fabric,
+static ibnd_chassis_t *find_chassisnum(ibnd_fabric_t * fabric,
 				       unsigned char chassisnum)
 {
 	ibnd_chassis_t *current;
@@ -207,14 +207,14 @@ static uint64_t get_chassisguid(ibnd_node_t * node)
 		return sysimgguid;
 }
 
-static ibnd_chassis_t *find_chassisguid(struct ibnd_fabric *f,
+static ibnd_chassis_t *find_chassisguid(ibnd_fabric_t * fabric,
 					ibnd_node_t * node)
 {
 	ibnd_chassis_t *current;
 	uint64_t chguid;
 
 	chguid = get_chassisguid(node);
-	for (current = f->first_chassis; current; current = current->next) {
+	for (current = fabric->first_chassis; current; current = current->next) {
 		if (current->chassisguid == chguid)
 			return current;
 	}
@@ -224,7 +224,6 @@ static ibnd_chassis_t *find_chassisguid(struct ibnd_fabric *f,
 
 uint64_t ibnd_get_chassis_guid(ibnd_fabric_t * fabric, unsigned char chassisnum)
 {
-	struct ibnd_fabric *f = CONV_FABRIC_INTERNAL(fabric);
 	ibnd_chassis_t *chassis;
 
 	if (!fabric) {
@@ -232,7 +231,7 @@ uint64_t ibnd_get_chassis_guid(ibnd_fabric_t * fabric, unsigned char chassisnum)
 		return 0;
 	}
 
-	chassis = find_chassisnum(f, chassisnum);
+	chassis = find_chassisnum(fabric, chassisnum);
 	if (chassis)
 		return chassis->chassisguid;
 	else
@@ -783,7 +782,7 @@ static void voltaire_portmap(ibnd_port_t * port)
 		port->ext_portnum = int2ext_map_slb8[chipnum][portnum];
 }
 
-static int add_chassis(struct ibnd_fabric *fabric)
+static int add_chassis(ibnd_fabric_t * fabric)
 {
 	if (!(fabric->current_chassis = calloc(1, sizeof(ibnd_chassis_t)))) {
 		IBND_ERROR("OOM: failed to allocate chassis object\n");
@@ -819,7 +818,7 @@ static void add_node_to_chassis(ibnd_chassis_t * chassis, ibnd_node_t * node)
 	Returns:
 	0 on success, -1 on failure
 */
-int group_nodes(struct ibnd_fabric *fabric)
+int group_nodes(ibnd_fabric_t * fabric)
 {
 	ibnd_node_t *node;
 	int dist;
@@ -833,7 +832,7 @@ int group_nodes(struct ibnd_fabric *fabric)
 	/* an appropriate chassis record (slotnum and position) */
 	/* according to internal connectivity */
 	/* not very efficient but clear code so... */
-	for (dist = 0; dist <= fabric->fabric.maxhops_discovered; dist++) {
+	for (dist = 0; dist <= fabric->maxhops_discovered; dist++) {
 		for (node = fabric->nodesdist[dist]; node; node = node->dnext) {
 			if (mad_get_field(node->info, 0,
 					  IB_NODE_VENDORID_F) == VTR_VENDOR_ID)
@@ -844,7 +843,7 @@ int group_nodes(struct ibnd_fabric *fabric)
 
 	/* separate every Voltaire chassis from each other and build linked list of them */
 	/* algorithm: catch spine and find all surrounding nodes */
-	for (dist = 0; dist <= fabric->fabric.maxhops_discovered; dist++) {
+	for (dist = 0; dist <= fabric->maxhops_discovered; dist++) {
 		for (node = fabric->nodesdist[dist]; node; node = node->dnext) {
 			if (mad_get_field(node->info, 0,
 					  IB_NODE_VENDORID_F) != VTR_VENDOR_ID)
@@ -863,7 +862,7 @@ int group_nodes(struct ibnd_fabric *fabric)
 
 	/* now make pass on nodes for chassis which are not Voltaire */
 	/* grouped by common SystemImageGUID */
-	for (dist = 0; dist <= fabric->fabric.maxhops_discovered; dist++) {
+	for (dist = 0; dist <= fabric->maxhops_discovered; dist++) {
 		for (node = fabric->nodesdist[dist]; node; node = node->dnext) {
 			if (mad_get_field(node->info, 0,
 					  IB_NODE_VENDORID_F) == VTR_VENDOR_ID)
@@ -913,12 +912,12 @@ int group_nodes(struct ibnd_fabric *fabric)
 				}
 			}
 		}
-		if (dist == fabric->fabric.maxhops_discovered)
+		if (dist == fabric->maxhops_discovered)
 			dist = MAXHOPS;	/* skip to CAs */
 		else
 			dist++;
 	}
 
-	fabric->fabric.chassis = fabric->first_chassis;
+	fabric->chassis = fabric->first_chassis;
 	return (0);
 }
diff --git a/infiniband-diags/libibnetdisc/src/ibnetdisc.c b/infiniband-diags/libibnetdisc/src/ibnetdisc.c
index 1fc964c..2cd2c9b 100644
--- a/infiniband-diags/libibnetdisc/src/ibnetdisc.c
+++ b/infiniband-diags/libibnetdisc/src/ibnetdisc.c
@@ -67,7 +67,7 @@ void decode_port_info(ibnd_port_t * port)
 }
 
 static int get_port_info(struct ibmad_port *ibmad_port,
-			 struct ibnd_fabric *fabric, ibnd_port_t * port,
+			 ibnd_fabric_t * fabric, ibnd_port_t * port,
 			 int portnum, ib_portid_t * portid)
 {
 	char width[64], speed[64];
@@ -98,7 +98,7 @@ static int get_port_info(struct ibmad_port *ibmad_port,
  * Returns -1 if error.
  */
 static int query_node_info(struct ibmad_port *ibmad_port,
-			   struct ibnd_fabric *fabric, ibnd_node_t * node,
+			   ibnd_fabric_t * fabric, ibnd_node_t * node,
 			   ib_portid_t * portid)
 {
 	if (!smp_query_via(&(node->info), portid, IB_ATTR_NODE_INFO, 0, 0,
@@ -116,7 +116,7 @@ static int query_node_info(struct ibmad_port *ibmad_port,
 /*
  * Returns 0 if non switch node is found, 1 if switch is found, -1 if error.
  */
-static int query_node(struct ibmad_port *ibmad_port, struct ibnd_fabric *fabric,
+static int query_node(struct ibmad_port *ibmad_port, ibnd_fabric_t * fabric,
 		      ibnd_node_t * node, ibnd_port_t * port,
 		      ib_portid_t * portid)
 {
@@ -175,28 +175,28 @@ static int add_port_to_dpath(ib_dr_path_t * path, int nextport)
 	return path->cnt;
 }
 
-static int extend_dpath(struct ibmad_port *ibmad_port, struct ibnd_fabric *f,
+static int extend_dpath(struct ibmad_port *ibmad_port, ibnd_fabric_t * fabric,
 			ib_portid_t * portid, int nextport)
 {
 	int rc = 0;
 
 	if (portid->lid) {
 		/* If we were LID routed we need to set up the drslid */
-		if (!f->selfportid.lid)
-			if (ib_resolve_self_via(&f->selfportid, NULL, NULL,
+		if (!fabric->selfportid.lid)
+			if (ib_resolve_self_via(&fabric->selfportid, NULL, NULL,
 						ibmad_port) < 0) {
 				IBND_ERROR("Failed to resolve self\n");
 				return -1;
 			}
 
-		portid->drpath.drslid = (uint16_t) f->selfportid.lid;
+		portid->drpath.drslid = (uint16_t) fabric->selfportid.lid;
 		portid->drpath.drdlid = 0xFFFF;
 	}
 
 	rc = add_port_to_dpath(&portid->drpath, nextport);
 
-	if ((rc != -1) && (portid->drpath.cnt > f->fabric.maxhops_discovered))
-		f->fabric.maxhops_discovered = portid->drpath.cnt;
+	if ((rc != -1) && (portid->drpath.cnt > fabric->maxhops_discovered))
+		fabric->maxhops_discovered = portid->drpath.cnt;
 	return (rc);
 }
 
@@ -216,7 +216,7 @@ static void dump_endnode(ib_portid_t * path, char *prompt,
 		   port->base_lid + (1 << port->lmc) - 1, node->nodedesc);
 }
 
-static ibnd_node_t *find_existing_node(struct ibnd_fabric *fabric,
+static ibnd_node_t *find_existing_node(ibnd_fabric_t * fabric,
 				       ibnd_node_t * new)
 {
 	int hash = HASHGUID(new->guid) % HTSZ;
@@ -231,7 +231,6 @@ static ibnd_node_t *find_existing_node(struct ibnd_fabric *fabric,
 
 ibnd_node_t *ibnd_find_node_guid(ibnd_fabric_t * fabric, uint64_t guid)
 {
-	struct ibnd_fabric *f = CONV_FABRIC_INTERNAL(fabric);
 	int hash = HASHGUID(guid) % HTSZ;
 	ibnd_node_t *node;
 
@@ -240,7 +239,7 @@ ibnd_node_t *ibnd_find_node_guid(ibnd_fabric_t * fabric, uint64_t guid)
 		return (NULL);
 	}
 
-	for (node = f->nodestbl[hash]; node; node = node->htnext)
+	for (node = fabric->nodestbl[hash]; node; node = node->htnext)
 		if (node->guid == guid)
 			return (ibnd_node_t *) node;
 
@@ -268,7 +267,6 @@ ibnd_node_t *ibnd_update_node(struct ibmad_port * ibmad_port,
 	char portinfo_port0[IB_SMP_DATA_SIZE];
 	void *nd = node->nodedesc;
 	int p = 0;
-	struct ibnd_fabric *f = CONV_FABRIC_INTERNAL(fabric);
 
 	if (_check_ibmad_port(ibmad_port) < 0)
 		return (NULL);
@@ -283,7 +281,7 @@ ibnd_node_t *ibnd_update_node(struct ibmad_port * ibmad_port,
 		return (NULL);
 	}
 
-	if (query_node_info(ibmad_port, f, node, &(node->path_portid)))
+	if (query_node_info(ibmad_port, fabric, node, &(node->path_portid)))
 		return (NULL);
 
 	if (!smp_query_via(nd, &(node->path_portid), IB_ATTR_NODE_DESC, 0, 0,
@@ -292,7 +290,7 @@ ibnd_node_t *ibnd_update_node(struct ibmad_port * ibmad_port,
 
 	/* update all the port info's */
 	for (p = 1; p >= node->numports; p++) {
-		get_port_info(ibmad_port, f, node->ports[p],
+		get_port_info(ibmad_port, fabric, node->ports[p],
 			      p, &(node->path_portid));
 	}
 
@@ -320,7 +318,6 @@ done:
 
 ibnd_node_t *ibnd_find_node_dr(ibnd_fabric_t * fabric, char *dr_str)
 {
-	struct ibnd_fabric *f = CONV_FABRIC_INTERNAL(fabric);
 	int i = 0;
 	ibnd_node_t *rc;
 	ib_dr_path_t path;
@@ -330,7 +327,7 @@ ibnd_node_t *ibnd_find_node_dr(ibnd_fabric_t * fabric, char *dr_str)
 		return (NULL);
 	}
 
-	rc = f->fabric.from_node;
+	rc = fabric->from_node;
 
 	if (str2drpath(&path, dr_str, 0, 0) == -1) {
 		return (NULL);
@@ -369,7 +366,7 @@ static void add_to_portguid_hash(ibnd_port_t * port, ibnd_port_t * hash[])
 	hash[hash_idx] = port;
 }
 
-static void add_to_type_list(ibnd_node_t * node, struct ibnd_fabric *fabric)
+static void add_to_type_list(ibnd_node_t * node, ibnd_fabric_t * fabric)
 {
 	switch (node->type) {
 	case IB_NODE_CA:
@@ -387,7 +384,7 @@ static void add_to_type_list(ibnd_node_t * node, struct ibnd_fabric *fabric)
 	}
 }
 
-static void add_to_nodedist(ibnd_node_t * node, struct ibnd_fabric *fabric)
+static void add_to_nodedist(ibnd_node_t * node, ibnd_fabric_t * fabric)
 {
 	int dist = node->dist;
 	if (node->type != IB_NODE_SWITCH)
@@ -397,7 +394,7 @@ static void add_to_nodedist(ibnd_node_t * node, struct ibnd_fabric *fabric)
 	fabric->nodesdist[dist] = node;
 }
 
-static ibnd_node_t *create_node(struct ibnd_fabric *fabric,
+static ibnd_node_t *create_node(ibnd_fabric_t * fabric,
 				ibnd_node_t * temp, ib_portid_t * path,
 				int dist)
 {
@@ -416,8 +413,8 @@ static ibnd_node_t *create_node(struct ibnd_fabric *fabric,
 	add_to_nodeguid_hash(node, fabric->nodestbl);
 
 	/* add this to the all nodes list */
-	node->next = fabric->fabric.nodes;
-	fabric->fabric.nodes = (ibnd_node_t *) node;
+	node->next = fabric->nodes;
+	fabric->nodes = (ibnd_node_t *) node;
 
 	add_to_type_list(node, fabric);
 	add_to_nodedist(node, fabric);
@@ -434,7 +431,7 @@ static struct ibnd_port *find_existing_port_node(ibnd_node_t * node,
 	return (node->ports[port->portnum]);
 }
 
-static struct ibnd_port *add_port_to_node(struct ibnd_fabric *fabric,
+static struct ibnd_port *add_port_to_node(ibnd_fabric_t * fabric,
 					  ibnd_node_t * node,
 					  ibnd_port_t * temp)
 {
@@ -480,7 +477,7 @@ static void link_ports(ibnd_node_t * node, ibnd_port_t * port,
 }
 
 static int get_remote_node(struct ibmad_port *ibmad_port,
-			   struct ibnd_fabric *fabric, ibnd_node_t * node,
+			   ibnd_fabric_t * fabric, ibnd_node_t * node,
 			   ibnd_port_t * port, ib_portid_t * path,
 			   int portnum, int dist)
 {
@@ -542,7 +539,7 @@ ibnd_fabric_t *ibnd_discover_fabric(struct ibmad_port * ibmad_port,
 				    ib_portid_t * from, int hops)
 {
 	int rc = 0;
-	struct ibnd_fabric *fabric = NULL;
+	ibnd_fabric_t *fabric = NULL;
 	ib_portid_t my_portid = { 0 };
 	ibnd_node_t node_buf;
 	ibnd_port_t port_buf;
@@ -588,7 +585,7 @@ ibnd_fabric_t *ibnd_discover_fabric(struct ibmad_port * ibmad_port,
 	if (!node)
 		goto error;
 
-	fabric->fabric.from_node = (ibnd_node_t *) node;
+	fabric->from_node = (ibnd_node_t *) node;
 
 	port = add_port_to_node(fabric, node, &port_buf);
 	if (!port)
@@ -669,7 +666,6 @@ static void destroy_node(ibnd_node_t * node)
 
 void ibnd_destroy_fabric(ibnd_fabric_t * fabric)
 {
-	struct ibnd_fabric *f = CONV_FABRIC_INTERNAL(fabric);
 	int dist = 0;
 	ibnd_node_t *node = NULL;
 	ibnd_node_t *next = NULL;
@@ -678,21 +674,21 @@ void ibnd_destroy_fabric(ibnd_fabric_t * fabric)
 	if (!fabric)
 		return;
 
-	ch = f->first_chassis;
+	ch = fabric->first_chassis;
 	while (ch) {
 		ch_next = ch->next;
 		free(ch);
 		ch = ch_next;
 	}
 	for (dist = 0; dist <= MAXHOPS; dist++) {
-		node = f->nodesdist[dist];
+		node = fabric->nodesdist[dist];
 		while (node) {
 			next = node->dnext;
 			destroy_node(node);
 			node = next;
 		}
 	}
-	free(f);
+	free(fabric);
 }
 
 void ibnd_debug(int i)
@@ -736,7 +732,6 @@ void ibnd_iter_nodes(ibnd_fabric_t * fabric, ibnd_iter_node_func_t func,
 void ibnd_iter_nodes_type(ibnd_fabric_t * fabric, ibnd_iter_node_func_t func,
 			  int node_type, void *user_data)
 {
-	struct ibnd_fabric *f = CONV_FABRIC_INTERNAL(fabric);
 	ibnd_node_t *list = NULL;
 	ibnd_node_t *cur = NULL;
 
@@ -752,13 +747,13 @@ void ibnd_iter_nodes_type(ibnd_fabric_t * fabric, ibnd_iter_node_func_t func,
 
 	switch (node_type) {
 	case IB_NODE_SWITCH:
-		list = f->switches;
+		list = fabric->switches;
 		break;
 	case IB_NODE_CA:
-		list = f->ch_adapters;
+		list = fabric->ch_adapters;
 		break;
 	case IB_NODE_ROUTER:
-		list = f->routers;
+		list = fabric->routers;
 		break;
 	default:
 		IBND_DEBUG("Invalid node_type specified %d\n", node_type);
diff --git a/infiniband-diags/libibnetdisc/src/internal.h b/infiniband-diags/libibnetdisc/src/internal.h
index f06d2c3..ba32291 100644
--- a/infiniband-diags/libibnetdisc/src/internal.h
+++ b/infiniband-diags/libibnetdisc/src/internal.h
@@ -40,8 +40,6 @@
 
 #include <infiniband/ibnetdisc.h>
 
-#define MAXHOPS		63
-
 #define	IBND_DEBUG(fmt, ...) \
 	if (ibdebug) { \
 		printf("%s:%u; " fmt, __FILE__, __LINE__, ## __VA_ARGS__); \
@@ -49,26 +47,4 @@
 #define	IBND_ERROR(fmt, ...) \
 		fprintf(stderr, "%s:%u; " fmt, __FILE__, __LINE__, ## __VA_ARGS__)
 
-/* HASH table defines */
-#define HASHGUID(guid) ((uint32_t)(((uint32_t)(guid) * 101) ^ ((uint32_t)((guid) >> 32) * 103)))
-#define HTSZ 137
-
-struct ibnd_fabric {
-	/* This member MUST BE FIRST */
-	ibnd_fabric_t fabric;
-
-	/* internal use only */
-	ibnd_node_t *nodestbl[HTSZ];
-	ibnd_port_t *portstbl[HTSZ];
-	ibnd_node_t *nodesdist[MAXHOPS + 1];
-	ibnd_chassis_t *first_chassis;
-	ibnd_chassis_t *current_chassis;
-	ibnd_chassis_t *last_chassis;
-	ibnd_node_t *switches;
-	ibnd_node_t *ch_adapters;
-	ibnd_node_t *routers;
-	ib_portid_t selfportid;
-};
-#define CONV_FABRIC_INTERNAL(fabric) ((struct ibnd_fabric *)fabric)
-
 #endif				/* _INTERNAL_H_ */
-- 
1.5.4.5




More information about the general mailing list