[ofa-general] [PATCH] opensm/osm_subnet: consolidate some duplicated code
Sasha Khapyorsky
sashak at voltaire.com
Sat Dec 13 12:43:03 PST 2008
Consolidate some duplicated code in osm_get_*_by_mad_addr() functions.
Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
opensm/include/opensm/osm_subnet.h | 2 +-
opensm/opensm/osm_subnet.c | 118 +++++++++++-------------------------
2 files changed, 36 insertions(+), 84 deletions(-)
diff --git a/opensm/include/opensm/osm_subnet.h b/opensm/include/opensm/osm_subnet.h
index d97d5f4..fe456d5 100644
--- a/opensm/include/opensm/osm_subnet.h
+++ b/opensm/include/opensm/osm_subnet.h
@@ -741,7 +741,7 @@ struct osm_mgrp;
ib_api_status_t
osm_get_gid_by_mad_addr(IN struct osm_log *p_log,
IN const osm_subn_t * p_subn,
- IN const struct osm_mad_addr *p_mad_addr,
+ IN struct osm_mad_addr *p_mad_addr,
OUT ib_gid_t * p_gid);
/*
* PARAMETERS
diff --git a/opensm/opensm/osm_subnet.c b/opensm/opensm/osm_subnet.c
index c41962d..9136021 100644
--- a/opensm/opensm/osm_subnet.c
+++ b/opensm/opensm/osm_subnet.c
@@ -210,58 +210,12 @@ osm_subn_init(IN osm_subn_t * const p_subn,
/**********************************************************************
**********************************************************************/
-ib_api_status_t
-osm_get_gid_by_mad_addr(IN osm_log_t * p_log,
- IN const osm_subn_t * p_subn,
- IN const osm_mad_addr_t * p_mad_addr,
- OUT ib_gid_t * p_gid)
-{
- const cl_ptr_vector_t *p_tbl;
- const osm_port_t *p_port = NULL;
-
- if (p_gid == NULL) {
- OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 7505: "
- "Provided output GID is NULL\n");
- return (IB_INVALID_PARAMETER);
- }
-
- /* Find the port gid of the request in the subnet */
- p_tbl = &p_subn->port_lid_tbl;
-
- CL_ASSERT(cl_ptr_vector_get_size(p_tbl) < 0x10000);
-
- if ((uint16_t) cl_ptr_vector_get_size(p_tbl) >
- cl_ntoh16(p_mad_addr->dest_lid)) {
- p_port =
- cl_ptr_vector_get(p_tbl, cl_ntoh16(p_mad_addr->dest_lid));
- if (p_port == NULL) {
- OSM_LOG(p_log, OSM_LOG_DEBUG,
- "Did not find any port with LID: %u\n",
- cl_ntoh16(p_mad_addr->dest_lid));
- return (IB_INVALID_PARAMETER);
- }
- p_gid->unicast.interface_id = p_port->p_physp->port_guid;
- p_gid->unicast.prefix = p_subn->opt.subnet_prefix;
- } else {
- /* The dest_lid is not in the subnet table - this is an error */
- OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 7501: "
- "LID is out of range: %u\n",
- cl_ntoh16(p_mad_addr->dest_lid));
- return (IB_INVALID_PARAMETER);
- }
-
- return (IB_SUCCESS);
-}
-
-/**********************************************************************
- **********************************************************************/
-osm_physp_t *osm_get_physp_by_mad_addr(IN osm_log_t * p_log,
- IN const osm_subn_t * p_subn,
- IN osm_mad_addr_t * p_mad_addr)
+osm_port_t *osm_get_port_by_mad_addr(IN osm_log_t * p_log,
+ IN const osm_subn_t * p_subn,
+ IN osm_mad_addr_t * p_mad_addr)
{
const cl_ptr_vector_t *p_port_lid_tbl;
osm_port_t *p_port = NULL;
- osm_physp_t *p_physp = NULL;
/* Find the port gid of the request in the subnet */
p_port_lid_tbl = &p_subn->port_lid_tbl;
@@ -273,53 +227,51 @@ osm_physp_t *osm_get_physp_by_mad_addr(IN osm_log_t * p_log,
p_port =
cl_ptr_vector_get(p_port_lid_tbl,
cl_ntoh16(p_mad_addr->dest_lid));
- if (p_port == NULL) {
- /* The port is not in the port_lid table - this is an error */
- OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 7502: "
- "Cannot locate port object by lid: %u\n",
- cl_ntoh16(p_mad_addr->dest_lid));
-
- goto Exit;
- }
- p_physp = p_port->p_physp;
} else {
/* The dest_lid is not in the subnet table - this is an error */
- OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 7503: "
+ OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 7504: "
"Lid is out of range: %u\n",
cl_ntoh16(p_mad_addr->dest_lid));
}
-Exit:
- return p_physp;
+ return p_port;
}
-/**********************************************************************
- **********************************************************************/
-osm_port_t *osm_get_port_by_mad_addr(IN osm_log_t * p_log,
- IN const osm_subn_t * p_subn,
- IN osm_mad_addr_t * p_mad_addr)
+ib_api_status_t
+osm_get_gid_by_mad_addr(IN osm_log_t * p_log,
+ IN const osm_subn_t * p_subn,
+ IN osm_mad_addr_t * p_mad_addr,
+ OUT ib_gid_t * p_gid)
{
- const cl_ptr_vector_t *p_port_lid_tbl;
- osm_port_t *p_port = NULL;
+ const osm_port_t *p_port = NULL;
- /* Find the port gid of the request in the subnet */
- p_port_lid_tbl = &p_subn->port_lid_tbl;
+ if (p_gid == NULL) {
+ OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 7505: "
+ "Provided output GID is NULL\n");
+ return (IB_INVALID_PARAMETER);
+ }
- CL_ASSERT(cl_ptr_vector_get_size(p_port_lid_tbl) < 0x10000);
+ p_port = osm_get_port_by_mad_addr(p_log, p_subn, p_mad_addr);
+ if (!p_port)
+ return IB_INVALID_PARAMETER;
- if ((uint16_t) cl_ptr_vector_get_size(p_port_lid_tbl) >
- cl_ntoh16(p_mad_addr->dest_lid)) {
- p_port =
- cl_ptr_vector_get(p_port_lid_tbl,
- cl_ntoh16(p_mad_addr->dest_lid));
- } else {
- /* The dest_lid is not in the subnet table - this is an error */
- OSM_LOG(p_log, OSM_LOG_ERROR, "ERR 7504: "
- "Lid is out of range: %u\n",
- cl_ntoh16(p_mad_addr->dest_lid));
- }
+ p_gid->unicast.interface_id = p_port->p_physp->port_guid;
+ p_gid->unicast.prefix = p_subn->opt.subnet_prefix;
- return p_port;
+ return IB_SUCCESS;
+}
+
+osm_physp_t *osm_get_physp_by_mad_addr(IN osm_log_t * p_log,
+ IN const osm_subn_t * p_subn,
+ IN osm_mad_addr_t * p_mad_addr)
+{
+ osm_port_t *p_port = NULL;
+
+ p_port = osm_get_port_by_mad_addr(p_log, p_subn, p_mad_addr);
+ if (!p_port)
+ return NULL;
+
+ return p_port->p_physp;
}
/**********************************************************************
--
1.6.0.4.766.g6fc4a
More information about the general
mailing list