[ofa-general] [PATCH] opensm: simplify osm_get_mgrp_by_mgid() search function

Sasha Khapyorsky sashak at voltaire.com
Mon Sep 15 05:24:14 PDT 2008


Simplify MC group search functions osm_get_mgrp_by_mgid(), it will
return pointer to struct osm_mgrp or NULL if it was not found (or marked
for deletion).

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 opensm/include/opensm/osm_sa.h         |    4 +-
 opensm/opensm/osm_sa_mcmember_record.c |   93 +++++++++-----------------------
 opensm/opensm/osm_sa_path_record.c     |   51 +++++++----------
 3 files changed, 48 insertions(+), 100 deletions(-)

diff --git a/opensm/include/opensm/osm_sa.h b/opensm/include/opensm/osm_sa.h
index b861ac4..52b69c5 100644
--- a/opensm/include/opensm/osm_sa.h
+++ b/opensm/include/opensm/osm_sa.h
@@ -490,9 +490,7 @@ osm_mcmr_rcv_find_or_create_new_mgrp(IN osm_sa_t * sa,
 *
 *********/
 
-ib_api_status_t
-osm_get_mgrp_by_mgid(IN osm_sa_t * sa,
-		     IN ib_gid_t * p_mgid, OUT osm_mgrp_t ** pp_mgrp);
+osm_mgrp_t *osm_get_mgrp_by_mgid(IN osm_sa_t * sa, IN ib_gid_t * p_mgid);
 
 END_C_DECLS
 #endif				/* _OSM_SA_H_ */
diff --git a/opensm/opensm/osm_sa_mcmember_record.c b/opensm/opensm/osm_sa_mcmember_record.c
index 13bce1f..81683f0 100644
--- a/opensm/opensm/osm_sa_mcmember_record.c
+++ b/opensm/opensm/osm_sa_mcmember_record.c
@@ -966,39 +966,16 @@ Exit:
 
 }
 
-
-typedef struct osm_sa_pr_mcmr_search_ctxt {
-	ib_gid_t mgid;
-	osm_mgrp_t *p_mgrp;
-	osm_sa_t *sa;
-} osm_sa_pr_mcmr_search_ctxt_t;
-
 /**********************************************************************
  *********************************************************************/
-static void
-__search_mgrp_by_mgid(IN osm_mgrp_t * const p_mgrp, IN void *context)
+static unsigned match_mgrp_by_mgid(IN osm_mgrp_t * const p_mgrp, ib_gid_t *mgid)
 {
-	osm_sa_pr_mcmr_search_ctxt_t *p_ctxt = context;
-	osm_sa_t *sa = p_ctxt->sa;
-
 	/* ignore groups marked for deletion */
-	if (p_mgrp->to_be_deleted)
-		return;
-
-	/* compare entire MGID so different scope will not sneak in for
-	   the same MGID */
-	if (memcmp(&p_mgrp->mcmember_rec.mgid, &p_ctxt->mgid, sizeof(ib_gid_t)))
-		return;
-
-	if (p_ctxt->p_mgrp) {
-		char gid_str[INET6_ADDRSTRLEN];
-		OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1B30: "
-			"Multiple MC groups for MGID %s\n",
-			inet_ntop(AF_INET6, p_mgrp->mcmember_rec.mgid.raw,
-				gid_str, sizeof gid_str));
-		return;
-	}
-	p_ctxt->p_mgrp = p_mgrp;
+	if (p_mgrp->to_be_deleted ||
+	    memcmp(&p_mgrp->mcmember_rec.mgid, mgid, sizeof(ib_gid_t)))
+		return 0;
+	else
+		return 1;
 }
 
 /**********************************************************************
@@ -1023,21 +1000,15 @@ static unsigned match_and_update_ipv6_snm_mgid(ib_gid_t *mgid)
 	return 0;
 }
 
-ib_api_status_t
-osm_get_mgrp_by_mgid(IN osm_sa_t *sa,
-		     IN ib_gid_t *p_mgid,
-		     OUT osm_mgrp_t **pp_mgrp)
+osm_mgrp_t *osm_get_mgrp_by_mgid(IN osm_sa_t *sa, IN ib_gid_t *p_mgid)
 {
-	osm_sa_pr_mcmr_search_ctxt_t mcmr_search_context;
-	osm_mgrp_t *p_mgrp;
+	ib_gid_t mgid;
 	int i;
 
-	memcpy(&mcmr_search_context.mgid, p_mgid, sizeof(*p_mgid));
-	mcmr_search_context.sa = sa;
-	mcmr_search_context.p_mgrp = NULL;
+	memcpy(&mgid, p_mgid, sizeof(mgid));
 
 	if (sa->p_subn->opt.consolidate_ipv6_snm_req &&
-	    match_and_update_ipv6_snm_mgid(&mcmr_search_context.mgid)) {
+	    match_and_update_ipv6_snm_mgid(&mgid)) {
 		char gid_str[INET6_ADDRSTRLEN];
 		OSM_LOG(sa->p_log, OSM_LOG_DEBUG,
 			"Special Case Solicited Node Mcast Join for MGID %s\n",
@@ -1046,17 +1017,12 @@ osm_get_mgrp_by_mgid(IN osm_sa_t *sa,
 	}
 
 	for (i = 0; i <= sa->p_subn->max_mcast_lid_ho - IB_LID_MCAST_START_HO;
-	     i++) {
-		p_mgrp = sa->p_subn->mgroups[i];
-		if (p_mgrp) {
-			__search_mgrp_by_mgid(p_mgrp, &mcmr_search_context);
-			if (mcmr_search_context.p_mgrp) {
-				*pp_mgrp = mcmr_search_context.p_mgrp;
-				return IB_SUCCESS;
-			}
-		}
-	}
-	return IB_NOT_FOUND;
+	     i++)
+		if (sa->p_subn->mgroups[i] &&
+		    match_mgrp_by_mgid(sa->p_subn->mgroups[i], &mgid))
+			return sa->p_subn->mgroups[i];
+
+	return NULL;
 }
 
 /**********************************************************************
@@ -1069,11 +1035,12 @@ osm_mcmr_rcv_find_or_create_new_mgrp(IN osm_sa_t * sa,
 				     const p_recvd_mcmember_rec,
 				     OUT osm_mgrp_t ** pp_mgrp)
 {
-	ib_api_status_t status;
+	osm_mgrp_t *mgrp;
 
-	status = osm_get_mgrp_by_mgid(sa, &p_recvd_mcmember_rec->mgid, pp_mgrp);
-	if (status == IB_SUCCESS)
-		return status;
+	if ((mgrp = osm_get_mgrp_by_mgid(sa, &p_recvd_mcmember_rec->mgid))) {
+		*pp_mgrp = mgrp;
+		return IB_SUCCESS;
+	}
 	return osm_mcmr_rcv_create_new_mgrp(sa, comp_mask,
 					    p_recvd_mcmember_rec, NULL,
 					    pp_mgrp);
@@ -1088,7 +1055,6 @@ __osm_mcmr_rcv_leave_mgrp(IN osm_sa_t * sa,
 {
 	boolean_t valid;
 	osm_mgrp_t *p_mgrp;
-	ib_api_status_t status;
 	ib_sa_mad_t *p_sa_mad;
 	ib_member_rec_t *p_recvd_mcmember_rec;
 	ib_member_rec_t mcmember_rec;
@@ -1100,7 +1066,6 @@ __osm_mcmr_rcv_leave_mgrp(IN osm_sa_t * sa,
 
 	OSM_LOG_ENTER(sa->p_log);
 
-	p_mgrp = NULL;
 	p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
 	p_recvd_mcmember_rec =
 	    (ib_member_rec_t *) ib_sa_mad_get_payload_ptr(p_sa_mad);
@@ -1113,8 +1078,8 @@ __osm_mcmr_rcv_leave_mgrp(IN osm_sa_t * sa,
 	}
 
 	CL_PLOCK_EXCL_ACQUIRE(sa->p_lock);
-	status = osm_get_mgrp_by_mgid(sa, &p_recvd_mcmember_rec->mgid, &p_mgrp);
-	if (status == IB_SUCCESS) {
+	p_mgrp = osm_get_mgrp_by_mgid(sa, &p_recvd_mcmember_rec->mgid);
+	if (p_mgrp) {
 		mlid = p_mgrp->mlid;
 		portguid = p_recvd_mcmember_rec->port_gid.unicast.interface_id;
 
@@ -1155,15 +1120,10 @@ __osm_mcmr_rcv_leave_mgrp(IN osm_sa_t * sa,
 
 				/* OK we can leave */
 				/* note: osm_sm_mcgrp_leave() will release sa->p_lock */
-
-				status =
-				    osm_sm_mcgrp_leave(sa->sm, mlid,
-						       portguid);
-				if (status != IB_SUCCESS) {
+				if (osm_sm_mcgrp_leave(sa->sm, mlid, portguid))
 					OSM_LOG(sa->p_log, OSM_LOG_ERROR,
 						"ERR 1B09: "
 						"osm_sm_mcgrp_leave failed\n");
-				}
 			}
 		} else {
 			char gid_str[INET6_ADDRSTRLEN];
@@ -1223,7 +1183,6 @@ __osm_mcmr_rcv_join_mgrp(IN osm_sa_t * sa, IN osm_madw_t * const p_madw)
 
 	OSM_LOG_ENTER(sa->p_log);
 
-	p_mgrp = NULL;
 	p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
 	p_recvd_mcmember_rec =
 	    (ib_member_rec_t *) ib_sa_mad_get_payload_ptr(p_sa_mad);
@@ -1276,8 +1235,8 @@ __osm_mcmr_rcv_join_mgrp(IN osm_sa_t * sa, IN osm_madw_t * const p_madw)
 				  &join_state);
 
 	/* do we need to create a new group? */
-	status = osm_get_mgrp_by_mgid(sa, &p_recvd_mcmember_rec->mgid, &p_mgrp);
-	if (status == IB_NOT_FOUND || p_mgrp->to_be_deleted) {
+	p_mgrp = osm_get_mgrp_by_mgid(sa, &p_recvd_mcmember_rec->mgid);
+	if (!p_mgrp || p_mgrp->to_be_deleted) {
 		/* check for JoinState.FullMember = 1 o15.0.1.9 */
 		if ((join_state & 0x01) != 0x01) {
 			char gid_str[INET6_ADDRSTRLEN];
diff --git a/opensm/opensm/osm_sa_path_record.c b/opensm/opensm/osm_sa_path_record.c
index d60dc01..e614bab 100644
--- a/opensm/opensm/osm_sa_path_record.c
+++ b/opensm/opensm/osm_sa_path_record.c
@@ -1458,59 +1458,50 @@ __osm_pr_rcv_process_pair(IN osm_sa_t * sa,
 
 /**********************************************************************
  **********************************************************************/
-static void
-__osm_pr_get_mgrp(IN osm_sa_t * sa,
-		  IN const osm_madw_t * const p_madw, OUT osm_mgrp_t ** pp_mgrp)
+static osm_mgrp_t *pr_get_mgrp(IN osm_sa_t * sa,
+			       IN const osm_madw_t * const p_madw)
 {
 	ib_path_rec_t *p_pr;
 	const ib_sa_mad_t *p_sa_mad;
 	ib_net64_t comp_mask;
-	ib_api_status_t status;
-
-	OSM_LOG_ENTER(sa->p_log);
+	osm_mgrp_t *mgrp = NULL;
 
 	p_sa_mad = osm_madw_get_sa_mad_ptr(p_madw);
 	p_pr = (ib_path_rec_t *) ib_sa_mad_get_payload_ptr(p_sa_mad);
 
 	comp_mask = p_sa_mad->comp_mask;
 
-	if (comp_mask & IB_PR_COMPMASK_DGID) {
-		status = osm_get_mgrp_by_mgid(sa, &p_pr->dgid, pp_mgrp);
-		if (status != IB_SUCCESS) {
-			char gid_str[INET6_ADDRSTRLEN];
-			OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1F09: "
-				"No MC group found for PathRecord destination "
-				"GID %s\n",
-				inet_ntop(AF_INET6, p_pr->dgid.raw, gid_str,
-					sizeof gid_str));
-			goto Exit;
-		}
+	if ((comp_mask & IB_PR_COMPMASK_DGID) &&
+	    !(mgrp = osm_get_mgrp_by_mgid(sa, &p_pr->dgid))) {
+		char gid_str[INET6_ADDRSTRLEN];
+		OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1F09: "
+			"No MC group found for PathRecord destination GID %s\n",
+			inet_ntop(AF_INET6, p_pr->dgid.raw, gid_str,
+				  sizeof gid_str));
+		goto Exit;
 	}
 
 	if (comp_mask & IB_PR_COMPMASK_DLID) {
-		if (*pp_mgrp) {
+		if (mgrp) {
 			/* check that the MLID in the MC group is */
 			/* the same as the DLID in the PathRecord */
-			if ((*pp_mgrp)->mlid != p_pr->dlid) {
+			if (mgrp->mlid != p_pr->dlid) {
 				/* Note: perhaps this might be better indicated as an invalid request */
 				OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1F10: "
 					"MC group MLID 0x%x does not match "
 					"PathRecord destination LID 0x%x\n",
-					(*pp_mgrp)->mlid, p_pr->dlid);
-				*pp_mgrp = NULL;
+					mgrp->mlid, p_pr->dlid);
+				mgrp = NULL;
 				goto Exit;
 			}
-		} else {
-			*pp_mgrp = osm_get_mgrp_by_mlid(sa->p_subn, p_pr->dlid);
-			if (*pp_mgrp == NULL)
-				OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1F11: "
-					"No MC group found for PathRecord "
-					"destination LID 0x%x\n", p_pr->dlid);
-		}
+		} else if (!(mgrp = osm_get_mgrp_by_mlid(sa->p_subn, p_pr->dlid)))
+			OSM_LOG(sa->p_log, OSM_LOG_ERROR, "ERR 1F11: "
+				"No MC group found for PathRecord "
+				"destination LID 0x%x\n", p_pr->dlid);
 	}
 
 Exit:
-	OSM_LOG_EXIT(sa->p_log);
+	return mgrp;
 }
 
 /**********************************************************************
@@ -1743,7 +1734,7 @@ McastDest:
 		uint8_t hop_limit;
 
 		/* First, get the MC info */
-		__osm_pr_get_mgrp(sa, p_madw, &p_mgrp);
+		p_mgrp = pr_get_mgrp(sa, p_madw);
 
 		if (!p_mgrp)
 			goto Unlock;
-- 
1.6.0.1.196.g01914




More information about the general mailing list