[ofa-general] [PATCH 2/2] opensm: Add priv_release() function pointer member to osm_port_t.

Jim Schutt jaschut at sandia.gov
Fri Aug 28 12:08:16 PDT 2009


Although no routing engine currently uses osm_port_t:priv to reference
routing engine data that is persistent between calls to the engine,
one may be added in the future.

Since this type of bug was just fixed for osm_switch_t:priv, fix up
osm_port_t to use the same mechanism.

Signed-off-by: Jim Schutt <jaschut at sandia.gov>
---
 opensm/include/opensm/osm_port.h |    1 +
 opensm/opensm/osm_port.c         |    2 ++
 opensm/opensm/osm_ucast_mgr.c    |   19 ++++++++++++++-----
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/opensm/include/opensm/osm_port.h b/opensm/include/opensm/osm_port.h
index 7079e74..21379b2 100644
--- a/opensm/include/opensm/osm_port.h
+++ b/opensm/include/opensm/osm_port.h
@@ -1162,6 +1162,7 @@ typedef struct osm_port {
 	cl_qlist_t mcm_list;
 	int flag;
 	void *priv;
+	void (*priv_release)(struct osm_port *p_pt);
 } osm_port_t;
 /*
 * FIELDS
diff --git a/opensm/opensm/osm_port.c b/opensm/opensm/osm_port.c
index 751c0f0..519d8bd 100644
--- a/opensm/opensm/osm_port.c
+++ b/opensm/opensm/osm_port.c
@@ -132,6 +132,8 @@ void osm_physp_init(IN osm_physp_t * p_physp, IN const ib_net64_t port_guid,
  **********************************************************************/
 void osm_port_delete(IN OUT osm_port_t ** pp_port)
 {
+	if ((*pp_port)->priv_release)
+		(*pp_port)->priv_release(*pp_port);
 	/* cleanup all mcm recs attached */
 	osm_port_remove_all_mgrp(*pp_port);
 	free(*pp_port);
diff --git a/opensm/opensm/osm_ucast_mgr.c b/opensm/opensm/osm_ucast_mgr.c
index 629f628..1bf367d 100644
--- a/opensm/opensm/osm_ucast_mgr.c
+++ b/opensm/opensm/osm_ucast_mgr.c
@@ -385,6 +385,15 @@ static int set_fwd_tbl_top(IN osm_ucast_mgr_t * p_mgr, IN osm_switch_t * p_sw)
 
 /**********************************************************************
  **********************************************************************/
+static void minhop_port_priv_release(osm_port_t *port)
+{
+	if (port->priv)
+		free(port->priv);
+
+	port->priv_release = NULL;
+	port->priv = NULL;
+}
+
 static void alloc_ports_priv(osm_ucast_mgr_t * mgr)
 {
 	cl_qmap_t *port_tbl = &mgr->p_subn->port_guid_tbl;
@@ -396,6 +405,8 @@ static void alloc_ports_priv(osm_ucast_mgr_t * mgr)
 	for (item = cl_qmap_head(port_tbl); item != cl_qmap_end(port_tbl);
 	     item = cl_qmap_next(item)) {
 		port = (osm_port_t *) item;
+		if (port->priv_release)
+			port->priv_release(port);
 		lmc = ib_port_info_get_lmc(&port->p_physp->port_info);
 		if (!lmc)
 			continue;
@@ -404,11 +415,11 @@ static void alloc_ports_priv(osm_ucast_mgr_t * mgr)
 			OSM_LOG(mgr->p_log, OSM_LOG_ERROR, "ERR 3A09: "
 				"cannot allocate memory to track remote"
 				" systems for lmc > 0\n");
-			port->priv = NULL;
 			continue;
 		}
 		memset(r, 0, sizeof(*r) + sizeof(r->guids[0]) * (1 << lmc));
 		port->priv = r;
+		port->priv_release = minhop_port_priv_release;
 	}
 }
 
@@ -420,10 +431,8 @@ static void free_ports_priv(osm_ucast_mgr_t * mgr)
 	for (item = cl_qmap_head(port_tbl); item != cl_qmap_end(port_tbl);
 	     item = cl_qmap_next(item)) {
 		port = (osm_port_t *) item;
-		if (port->priv) {
-			free(port->priv);
-			port->priv = NULL;
-		}
+		if (port->priv_release)
+			port->priv_release(port);
 	}
 }
 
-- 
1.5.6.GIT




More information about the general mailing list