[ofa-general] [PATCH] opensm: switch pre-routing preparation status check

Sasha Khapyorsky sashak at voltaire.com
Wed Feb 28 13:21:03 PST 2007


osm_switch_prepare_path_rebuild() will return status value now, it is
needed in order to track switch pre-routing preparation properly. Also
tiny p_sw->hops rework for potentially lockless p_sw->hops accessing.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 osm/include/opensm/osm_switch.h |    4 +-
 osm/opensm/osm_switch.c         |   32 +++++++++++++++++------------
 osm/opensm/osm_ucast_mgr.c      |   42 ++++++++++++++++++++++++--------------
 3 files changed, 47 insertions(+), 31 deletions(-)

diff --git a/osm/include/opensm/osm_switch.h b/osm/include/opensm/osm_switch.h
index c3ef865..4270904 100644
--- a/osm/include/opensm/osm_switch.h
+++ b/osm/include/opensm/osm_switch.h
@@ -1153,7 +1153,7 @@ osm_switch_path_count_get(
 *
 * SYNOPSIS
 */
-void
+int
 osm_switch_prepare_path_rebuild(
 	IN osm_switch_t* p_sw,
 	IN uint16_t max_lids );
@@ -1166,7 +1166,7 @@ osm_switch_prepare_path_rebuild(
 *		[in] Max number of lids in the subnet.
 *
 * RETURN VALUE
-*	None.
+*	Returns zero on success, or negative value if an error occurred.
 *
 * NOTES
 *
diff --git a/osm/opensm/osm_switch.c b/osm/opensm/osm_switch.c
index f258dbc..3a98a63 100644
--- a/osm/opensm/osm_switch.c
+++ b/osm/opensm/osm_switch.c
@@ -489,37 +489,43 @@ osm_switch_clear_hops(
 
 /**********************************************************************
  **********************************************************************/
-void
+int
 osm_switch_prepare_path_rebuild(
   IN osm_switch_t* p_sw,
   IN uint16_t max_lids )
 {
+  uint8_t **hops;
   unsigned i;
 
   for ( i = 0; i < p_sw->num_ports; i++ )
     osm_port_prof_construct( &p_sw->p_prof[i] );
   if (!p_sw->hops)
   {
-    p_sw->hops = malloc((max_lids + 1)*sizeof(p_sw->hops[0]));
-    if (!p_sw->hops)
-      return;
-    memset(p_sw->hops, 0, (max_lids + 1)*sizeof(p_sw->hops[0]));
+    hops = malloc((max_lids + 1)*sizeof(hops[0]));
+    if (!hops)
+      return -1;
+    memset(hops, 0, (max_lids + 1)*sizeof(hops[0]));
+    p_sw->hops = hops;
     p_sw->num_hops = max_lids + 1;
   }
   else if (max_lids + 1 > p_sw->num_hops)
   {
-    uint8_t **old_hops = p_sw->hops;
-
-    p_sw->hops = malloc((max_lids + 1)*sizeof(p_sw->hops[0]));
-    if (!p_sw->hops)
-      return;
-    memcpy(p_sw->hops, old_hops, p_sw->num_hops*sizeof(p_sw->hops[0]));
-    memset(p_sw->hops + p_sw->num_hops, 0,
-           (max_lids + 1 - p_sw->num_hops)*sizeof(p_sw->hops[0]));
+    uint8_t **old_hops;
+
+    hops = malloc((max_lids + 1)*sizeof(hops[0]));
+    if (!hops)
+      return -1;
+    memcpy(hops, p_sw->hops, p_sw->num_hops*sizeof(hops[0]));
+    memset(hops + p_sw->num_hops, 0,
+           (max_lids + 1 - p_sw->num_hops)*sizeof(hops[0]));
+    old_hops = p_sw->hops;
+    p_sw->hops = hops;
     p_sw->num_hops = max_lids + 1;
     free(old_hops);
   }
   p_sw->max_lid_ho = max_lids;
+
+  return 0;
 }
 
 /**********************************************************************
diff --git a/osm/opensm/osm_ucast_mgr.c b/osm/opensm/osm_ucast_mgr.c
index f02bae9..5b4ce45 100644
--- a/osm/opensm/osm_ucast_mgr.c
+++ b/osm/opensm/osm_ucast_mgr.c
@@ -404,20 +404,6 @@ static void __osm_ucast_mgr_dump_tables(osm_ucast_mgr_t *p_mgr)
 }
 
 /**********************************************************************
- Starting a rebuild, so notify the switch so it can clear tables, etc...
-**********************************************************************/
-static void
-__osm_ucast_mgr_setup_switch(
-  IN cl_map_item_t* const  p_map_item,
-  IN void* cxt )
-{
-  uint16_t lids = (uint16_t)cl_ptr_vector_get_size(&((osm_subn_t *)cxt)->port_lid_tbl);
-
-  osm_switch_prepare_path_rebuild((osm_switch_t *)p_map_item,
-                                  lids ? lids - 1 : 0);
-}
-
-/**********************************************************************
  Add each switch's own LID(s) to its LID matrix.
 **********************************************************************/
 static void
@@ -1195,6 +1181,30 @@ osm_ucast_mgr_build_lid_matrices(
 
 /**********************************************************************
  **********************************************************************/
+static int
+ucast_mgr_setup_all_switches(osm_subn_t *p_subn)
+{
+  osm_switch_t *p_sw;
+  uint16_t lids;
+
+  lids = (uint16_t)cl_ptr_vector_get_size(&p_subn->port_lid_tbl);
+  lids = lids ? lids - 1 : 0;
+
+  for (p_sw = (osm_switch_t*)cl_qmap_head(&p_subn->sw_guid_tbl);
+       p_sw != (osm_switch_t*)cl_qmap_end(&p_subn->sw_guid_tbl);
+       p_sw = (osm_switch_t*)cl_qmap_next(&p_sw->map_item))
+  if (osm_switch_prepare_path_rebuild(p_sw, lids)) {
+    osm_log(&p_subn->p_osm->log, OSM_LOG_ERROR,
+            "ucast_mgr_setup_all_switches: cannot setup switch 0x%016" PRIx64
+            "\n", cl_ntoh64(osm_node_get_node_guid(p_sw->p_node)));
+    return -1;
+  }
+
+  return 0;
+}
+
+/**********************************************************************
+ **********************************************************************/
 osm_signal_t
 osm_ucast_mgr_process(
   IN osm_ucast_mgr_t* const p_mgr )
@@ -1214,11 +1224,11 @@ osm_ucast_mgr_process(
   /*
     If there are no switches in the subnet, we are done.
   */
-  if (cl_qmap_count( p_sw_guid_tbl ) == 0)
+  if (cl_qmap_count( p_sw_guid_tbl ) == 0 ||
+      ucast_mgr_setup_all_switches(p_mgr->p_subn) < 0)
     goto Exit;
 
   p_mgr->any_change = FALSE;
-  cl_qmap_apply_func(p_sw_guid_tbl, __osm_ucast_mgr_setup_switch, p_mgr->p_subn);
 
   if (!p_routing_eng->build_lid_matrices ||
       p_routing_eng->build_lid_matrices(p_routing_eng->context) != 0)
-- 
1.5.0.1.40.gb40d




More information about the general mailing list