public inbox for linux-rdma@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] infiniband-diags/ibqueryerrors.c: use common portid in query_cap_mask()
       [not found]     ` <20090925093358.f9f747d4.weiny2-i2BcT+NCU+M@public.gmane.org>
@ 2009-10-23 16:33       ` Sasha Khapyorsky
  2009-10-23 16:34         ` [PATCH] infiniband-diags/ibqueryerrors.c: use common node_name Sasha Khapyorsky
  0 siblings, 1 reply; 2+ messages in thread
From: Sasha Khapyorsky @ 2009-10-23 16:33 UTC (permalink / raw)
  To: Ira Weiny; +Cc: Hal Rosenstock, linux-rdma


Use common portid in query_cap_mask() function instead of generating
this again in this function.

Signed-off-by: Sasha Khapyorsky <sashak-smomgflXvOZWk0Htik3J/w@public.gmane.org>
---
 infiniband-diags/src/ibqueryerrors.c |   25 ++++++++++---------------
 1 files changed, 10 insertions(+), 15 deletions(-)

diff --git a/infiniband-diags/src/ibqueryerrors.c b/infiniband-diags/src/ibqueryerrors.c
index 697afd1..fdd9246 100644
--- a/infiniband-diags/src/ibqueryerrors.c
+++ b/infiniband-diags/src/ibqueryerrors.c
@@ -261,23 +261,18 @@ static void print_results(ibnd_node_t * node, uint8_t * pc, int portnum,
 	}
 }
 
-static int query_cap_mask(ibnd_node_t * node, int portnum, uint16_t * cap_mask)
+static int query_cap_mask(ib_portid_t *portid, ibnd_node_t * node, int portnum,
+			  uint16_t * cap_mask)
 {
 	uint8_t pc[1024];
 	uint16_t rc_cap_mask;
-	ib_portid_t portid = { 0 };
-
-	if (node->type == IB_NODE_SWITCH)
-		ib_portid_set(&portid, node->smalid, 0, 0);
-	else
-		ib_portid_set(&portid, node->ports[portnum]->base_lid, 0, 0);
 
 	/* PerfMgt ClassPortInfo is a required attribute */
-	if (!pma_query_via(pc, &portid, portnum, ibd_timeout, CLASS_PORT_INFO,
+	if (!pma_query_via(pc, portid, portnum, ibd_timeout, CLASS_PORT_INFO,
 			   ibmad_port)) {
 		IBWARN("classportinfo query failed on %s, %s port %d",
 		       remap_node_name(node_name_map, node->guid,
-				       node->nodedesc), portid2str(&portid),
+				       node->nodedesc), portid2str(portid),
 		       portnum);
 		return -1;
 	}
@@ -371,18 +366,18 @@ void print_node(ibnd_node_t * node, void *user_data)
 
 	for (p = startport; p <= node->numports; p++) {
 		if (node->ports[p]) {
-			if (query_cap_mask(node, p, &cap_mask) < 0)
-				continue;
-
-			if (cap_mask & 0x100)
-				all_port_sup = 1;
-
 			if (node->type == IB_NODE_SWITCH)
 				ib_portid_set(&portid, node->smalid, 0, 0);
 			else
 				ib_portid_set(&portid, node->ports[p]->base_lid,
 					      0, 0);
 
+			if (query_cap_mask(&portid, node, p, &cap_mask) < 0)
+				continue;
+
+			if (cap_mask & 0x100)
+				all_port_sup = 1;
+
 			print_port(&portid, cap_mask, node, p, &header_printed);
 			if (!all_port_sup)
 				clear_port(&portid, cap_mask, node, p);
-- 
1.6.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] infiniband-diags/ibqueryerrors.c: use common node_name
  2009-10-23 16:33       ` [PATCH] infiniband-diags/ibqueryerrors.c: use common portid in query_cap_mask() Sasha Khapyorsky
@ 2009-10-23 16:34         ` Sasha Khapyorsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sasha Khapyorsky @ 2009-10-23 16:34 UTC (permalink / raw)
  To: Ira Weiny; +Cc: Hal Rosenstock, linux-rdma


Get common node_name string using remap_node_name() and use it over
reporting functions - in this way simplify the code, avoid multiple
remap_node searches and fix minor memory leaks.

Signed-off-by: Sasha Khapyorsky <sashak-smomgflXvOZWk0Htik3J/w@public.gmane.org>
---
 infiniband-diags/src/ibqueryerrors.c |   48 ++++++++++++---------------------
 1 files changed, 18 insertions(+), 30 deletions(-)

diff --git a/infiniband-diags/src/ibqueryerrors.c b/infiniband-diags/src/ibqueryerrors.c
index fdd9246..0842eb3 100644
--- a/infiniband-diags/src/ibqueryerrors.c
+++ b/infiniband-diags/src/ibqueryerrors.c
@@ -113,7 +113,7 @@ static void get_msg(char *width_msg, char *speed_msg, int msg_size,
 				      buf, 64, &max_speed));
 }
 
-static void print_port_config(ibnd_node_t * node, int portnum)
+static void print_port_config(char *node_name, ibnd_node_t * node, int portnum)
 {
 	char width[64], speed[64], state[64], physstate[64];
 	char remote_str[256];
@@ -145,10 +145,6 @@ static void print_port_config(ibnd_node_t * node, int portnum)
 		 mad_dump_val(IB_PORT_PHYS_STATE_F, physstate, 64, &iphystate));
 
 	if (port->remoteport) {
-		char *remap =
-		    remap_node_name(node_name_map, port->remoteport->node->guid,
-				    port->remoteport->node->nodedesc);
-
 		if (port->remoteport->ext_portnum)
 			snprintf(ext_port_str, 256, "%d",
 				 port->remoteport->ext_portnum);
@@ -162,9 +158,8 @@ static void print_port_config(ibnd_node_t * node, int portnum)
 			 port->remoteport->node->guid,
 			 port->remoteport->base_lid ? port->remoteport->
 			 base_lid : port->remoteport->node->smalid,
-			 port->remoteport->portnum, ext_port_str, remap,
+			 port->remoteport->portnum, ext_port_str, node_name,
 			 width_msg, speed_msg);
-		free(remap);
 	} else
 		snprintf(remote_str, 256, "           [  ] \"\" ( )\n");
 
@@ -203,8 +198,8 @@ static void report_suppressed(void)
 	}
 }
 
-static void print_results(ibnd_node_t * node, uint8_t * pc, int portnum,
-			  int *header_printed)
+static void print_results(char *node_name, ibnd_node_t * node, uint8_t * pc,
+			  int portnum, int *header_printed)
 {
 	char buf[1024];
 	char *str = buf;
@@ -245,23 +240,19 @@ static void print_results(ibnd_node_t * node, uint8_t * pc, int portnum,
 			}
 
 		if (!*header_printed) {
-			char *nodename =
-			    remap_node_name(node_name_map, node->guid,
-					    node->nodedesc);
 			printf("Errors for 0x%" PRIx64 " \"%s\"\n", node->guid,
-			       nodename);
+			       node_name);
 			*header_printed = 1;
-			free(nodename);
 		}
 
 		printf("   GUID 0x%" PRIx64 " port %d:%s\n", node->guid,
 		       portnum, str);
 		if (port_config)
-			print_port_config(node, portnum);
+			print_port_config(node_name, node, portnum);
 	}
 }
 
-static int query_cap_mask(ib_portid_t *portid, ibnd_node_t * node, int portnum,
+static int query_cap_mask(ib_portid_t *portid, char *node_name, int portnum,
 			  uint16_t * cap_mask)
 {
 	uint8_t pc[1024];
@@ -271,9 +262,7 @@ static int query_cap_mask(ib_portid_t *portid, ibnd_node_t * node, int portnum,
 	if (!pma_query_via(pc, portid, portnum, ibd_timeout, CLASS_PORT_INFO,
 			   ibmad_port)) {
 		IBWARN("classportinfo query failed on %s, %s port %d",
-		       remap_node_name(node_name_map, node->guid,
-				       node->nodedesc), portid2str(portid),
-		       portnum);
+		       node_name, portid2str(portid), portnum);
 		return -1;
 	}
 
@@ -284,30 +273,25 @@ static int query_cap_mask(ib_portid_t *portid, ibnd_node_t * node, int portnum,
 	return 0;
 }
 
-static void print_port(ib_portid_t * portid, uint16_t cap_mask,
+static void print_port(ib_portid_t * portid, uint16_t cap_mask, char *node_name,
 		       ibnd_node_t * node, int portnum, int *header_printed)
 {
 	uint8_t pc[1024];
-	char *nodename =
-	    remap_node_name(node_name_map, node->guid, node->nodedesc);
 
 	memset(pc, 0, 1024);
 
 	if (!pma_query_via(pc, portid, portnum, ibd_timeout,
 			   IB_GSI_PORT_COUNTERS, ibmad_port)) {
 		IBWARN("IB_GSI_PORT_COUNTERS query failed on %s, %s port %d\n",
-		       nodename, portid2str(portid), portnum);
-		goto cleanup;
+		       node_name, portid2str(portid), portnum);
+		return;
 	}
 	if (!(cap_mask & 0x1000)) {
 		/* if PortCounters:PortXmitWait not suppported clear this counter */
 		uint32_t foo = 0;
 		mad_encode_field(pc, IB_PC_XMT_WAIT_F, &foo);
 	}
-	print_results(node, pc, portnum, header_printed);
-
-cleanup:
-	free(nodename);
+	print_results(node_name, node, pc, portnum, header_printed);
 }
 
 static void clear_port(ib_portid_t * portid, uint16_t cap_mask,
@@ -365,6 +349,8 @@ void print_node(ibnd_node_t * node, void *user_data)
 		startport = 0;
 
 	for (p = startport; p <= node->numports; p++) {
+		char *node_name = remap_node_name(node_name_map, node->guid,
+						  node->nodedesc);
 		if (node->ports[p]) {
 			if (node->type == IB_NODE_SWITCH)
 				ib_portid_set(&portid, node->smalid, 0, 0);
@@ -372,16 +358,18 @@ void print_node(ibnd_node_t * node, void *user_data)
 				ib_portid_set(&portid, node->ports[p]->base_lid,
 					      0, 0);
 
-			if (query_cap_mask(&portid, node, p, &cap_mask) < 0)
+			if (query_cap_mask(&portid, node_name, p, &cap_mask) < 0)
 				continue;
 
 			if (cap_mask & 0x100)
 				all_port_sup = 1;
 
-			print_port(&portid, cap_mask, node, p, &header_printed);
+			print_port(&portid, cap_mask, node_name, node, p,
+				   &header_printed);
 			if (!all_port_sup)
 				clear_port(&portid, cap_mask, node, p);
 		}
+		free(node_name);
 	}
 
 	if (all_port_sup)
-- 
1.6.5.1

--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-10-23 16:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20090924235011.a9a16022.weiny2@llnl.gov>
     [not found] ` <f0e08f230909250707t36c1ebc4od5df33e36f6cd38a@mail.gmail.com>
     [not found]   ` <20090925093358.f9f747d4.weiny2@llnl.gov>
     [not found]     ` <20090925093358.f9f747d4.weiny2-i2BcT+NCU+M@public.gmane.org>
2009-10-23 16:33       ` [PATCH] infiniband-diags/ibqueryerrors.c: use common portid in query_cap_mask() Sasha Khapyorsky
2009-10-23 16:34         ` [PATCH] infiniband-diags/ibqueryerrors.c: use common node_name Sasha Khapyorsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox