[openib-general] [PATCH 1/5] opensm: eliminate global variable osm in updn

Sasha Khapyorsky sashak at voltaire.com
Sun Nov 26 14:30:00 PST 2006


Routing engine setup function for up/down already gets reference to osm
object as parameter - we can keep this reference as part of updn_t
structure rather than to use global variable for referencing osm object.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 osm/opensm/osm_ucast_updn.c |  335 +++++++++++++++++++++----------------------
 1 files changed, 165 insertions(+), 170 deletions(-)

diff --git a/osm/opensm/osm_ucast_updn.c b/osm/opensm/osm_ucast_updn.c
index 268dd13..4b227c9 100644
--- a/osm/opensm/osm_ucast_updn.c
+++ b/osm/opensm/osm_ucast_updn.c
@@ -110,15 +110,10 @@ typedef struct _updn
   cl_qmap_t      guid_rank_tbl;
   updn_input_t   updn_ucast_reg_inputs;
   cl_list_t *    p_root_nodes;
+  osm_opensm_t *p_osm;
 } updn_t;
 
 /* ///////////////////////////////// */
-/*  Globals                          */
-/* ///////////////////////////////// */
-/* This var is predefined and initialized */
-extern osm_opensm_t osm;
-
-/* ///////////////////////////////// */
 /*  Statics                          */
 /* ///////////////////////////////// */
 static int __osm_updn_find_root_nodes_by_min_hop(OUT updn_t *p_updn);
@@ -129,12 +124,12 @@ static int __osm_updn_find_root_nodes_by
    remote ports */
 static updn_switch_dir_t
 __updn_get_dir(
+  IN updn_t *p_updn,
   IN uint8_t cur_rank,
   IN uint8_t rem_rank,
   IN uint64_t cur_guid,
   IN uint64_t rem_guid )
 {
-  updn_t *p_updn = osm.routing_engine.context;
   uint32_t i = 0, max_num_guids = p_updn->updn_ucast_reg_inputs.num_guids;
   uint64_t *p_guid = p_updn->updn_ucast_reg_inputs.guid_list;
   boolean_t cur_is_root = FALSE, rem_is_root = FALSE;
@@ -230,6 +225,7 @@ __updn_update_rank(
  **********************************************************************/
 static int
 __updn_bfs_by_node(
+  IN updn_t *p_updn,
   IN osm_subn_t *p_subn,
   IN ib_net64_t guid_index,
   IN cl_qmap_t *p_guid_rank_tbl )
@@ -243,8 +239,9 @@ __updn_bfs_by_node(
   uint16_t root_lid, max_sw_lid;
   updn_next_step_t *p_updn_switch, *p_tmp;
   updn_switch_dir_t next_dir, current_dir;
+  osm_log_t *p_log = &p_updn->p_osm->log;
 
-  OSM_LOG_ENTER( &(osm.log), __updn_bfs_by_node );
+  OSM_LOG_ENTER(p_log, __updn_bfs_by_node);
 
   /* Init the list pointers */
   p_nextList = (cl_list_t*)malloc(sizeof(cl_list_t));
@@ -258,13 +255,13 @@ __updn_bfs_by_node(
   /* Check valid pointer */
   if (!p_physp || !osm_physp_is_valid(p_physp ))
   {
-    OSM_LOG_EXIT( &(osm.log) );
+    OSM_LOG_EXIT( p_log );
     return 1;
   }
   /* The Root BFS - lid  */
   root_lid = cl_ntoh16(osm_physp_get_base_lid( p_physp ));
   /* printf ("-V- BFS through lid : 0x%x\n", root_lid); */
-  osm_log(&(osm.log), OSM_LOG_DEBUG,
+  osm_log(p_log, OSM_LOG_DEBUG,
           "__updn_bfs_by_node:"
           "Starting lid : 0x%x \n", root_lid);
 
@@ -272,7 +269,7 @@ __updn_bfs_by_node(
   {
     p_self_node = osm_get_switch_by_guid(p_subn, guid_index);
     /* Update its Min Hop Table */
-    osm_log(&(osm.log), OSM_LOG_DEBUG,
+    osm_log(p_log, OSM_LOG_DEBUG,
             "__updn_bfs_by_node:"
             "Update Min Hop Table of GUID 0x%" PRIx64 "\n",
             cl_ntoh64(p_port->guid));
@@ -293,10 +290,10 @@ __updn_bfs_by_node(
          Min Hop Table */
       if (osm_node_get_type(p_remote_physp->p_node) != IB_NODE_TYPE_SWITCH)
       {
-        osm_log(&(osm.log), OSM_LOG_ERROR,
+        osm_log(p_log, OSM_LOG_ERROR,
                 "__updn_bfs_by_node: ERR AA07: "
                 "This is a non switched subnet OR non valid connection, cannot perform UPDN algorithm\n");
-        OSM_LOG_EXIT( &(osm.log));
+        OSM_LOG_EXIT(p_log);
         return 1;
       }
       else
@@ -309,7 +306,7 @@ __updn_bfs_by_node(
           /* Update its Min Hop Table */
         {
           /* NOTE : Check if there is a function which prints the Min Hop Table */
-          osm_log(&(osm.log), OSM_LOG_DEBUG,
+          osm_log(p_log, OSM_LOG_DEBUG,
                   "__updn_bfs_by_node:"
                   "Update Min Hop Table of GUID 0x%" PRIx64 "\n",
                   cl_ntoh64(p_remote_physp->port_guid));
@@ -319,12 +316,12 @@ __updn_bfs_by_node(
         }
         else
         {
-          osm_log(&(osm.log), OSM_LOG_ERROR,
+          osm_log(p_log, OSM_LOG_ERROR,
                   "__updn_bfs_by_node: ERR AA09: "
                   " Invalid lid value 0x%x for switch 0x%" PRIx64 "\n",
                   root_lid,
                   cl_ntoh64(p_self_node->p_node->node_info.port_guid));
-          OSM_LOG_EXIT( &(osm.log));
+          OSM_LOG_EXIT(p_log);
           return 1;
         }
       }
@@ -333,7 +330,7 @@ __updn_bfs_by_node(
 
   CL_ASSERT(p_self_node);
 
-  osm_log(&(osm.log), OSM_LOG_DEBUG,
+  osm_log(p_log, OSM_LOG_DEBUG,
           "__updn_bfs_by_node:"
           "Starting from switch - port GUID 0x%" PRIx64 "\n",
           cl_ntoh64(p_self_node->p_node->node_info.port_guid));
@@ -343,7 +340,7 @@ __updn_bfs_by_node(
      action also free its memory */
   if (!(p_tmp=__updn_create_updn_next_step_t(UP, p_self_node)))
   {
-    osm_log(&(osm.log), OSM_LOG_ERROR,
+    osm_log(p_log, OSM_LOG_ERROR,
             "__updn_bfs_by_node:  ERR AA08: "
             "Could not create updn_next_step_t\n");
     return 1;
@@ -352,13 +349,13 @@ __updn_bfs_by_node(
   cl_list_insert_tail(p_currList,p_tmp );
 
   /* BFS the list till no next element */
-  osm_log(&(osm.log), OSM_LOG_VERBOSE,
+  osm_log(p_log, OSM_LOG_VERBOSE,
           "__updn_bfs_by_node:"
           "BFS the subnet [\n");
 
   while (!cl_is_list_empty(p_currList))
   {
-    osm_log(&(osm.log), OSM_LOG_DEBUG,
+    osm_log(p_log, OSM_LOG_DEBUG,
             "__updn_bfs_by_node:"
             "Starting a new iteration with %zu elements in current list\n",
             cl_list_count(p_currList));
@@ -373,7 +370,7 @@ __updn_bfs_by_node(
     while (p_updn_switch)
     {
       current_dir = p_updn_switch->state;
-      osm_log(&(osm.log), OSM_LOG_DEBUG,
+      osm_log(p_log, OSM_LOG_DEBUG,
               "__updn_bfs_by_node:"
               "Visiting port GUID 0x%" PRIx64 "\n",
               cl_ntoh64(p_updn_switch->p_sw->p_node->node_info.port_guid));
@@ -405,10 +402,10 @@ __updn_bfs_by_node(
         p_rem_rank = (updn_rank_t*)cl_qmap_get(p_guid_rank_tbl, remote_guid);
         p_cur_rank = (updn_rank_t*)cl_qmap_get(p_guid_rank_tbl, current_guid);
         /* Decide which direction to mark it (UP/DOWN) */
-        next_dir = __updn_get_dir (p_cur_rank->rank, p_rem_rank->rank,
+        next_dir = __updn_get_dir (p_updn, p_cur_rank->rank, p_rem_rank->rank,
                                    current_guid, remote_guid);
 
-        osm_log(&(osm.log), OSM_LOG_DEBUG,
+        osm_log(p_log, OSM_LOG_DEBUG,
                 "__updn_bfs_by_node:"
                 "move from 0x%016" PRIx64 " rank: %u "
                 "to 0x%016" PRIx64" rank: %u\n",
@@ -418,7 +415,7 @@ __updn_bfs_by_node(
            from DOWN to UP */
         if ((current_dir == DOWN) && (next_dir == UP))
         {
-          osm_log(&(osm.log), OSM_LOG_DEBUG,
+          osm_log(p_log, OSM_LOG_DEBUG,
                   "__updn_bfs_by_node:"
                   "Avoiding move from 0x%016" PRIx64 " to 0x%016" PRIx64"\n",
                   cl_ntoh64(current_guid), cl_ntoh64(remote_guid));
@@ -432,7 +429,7 @@ __updn_bfs_by_node(
         remote_min_hop = osm_switch_get_hop_count(p_remote_sw, root_lid, pn_rem);
         if (current_min_hop + 1 < remote_min_hop)
         {
-          osm_log(&(osm.log), OSM_LOG_DEBUG,
+          osm_log(p_log, OSM_LOG_DEBUG,
                   "__updn_bfs_by_node (less):"
                   "Setting Min Hop Table of switch: 0x%" PRIx64
                   "\n\t\tCurrent hop count is: %d, next hop count: %d"
@@ -444,7 +441,7 @@ __updn_bfs_by_node(
           set_hop_return_value = osm_switch_set_hops(p_remote_sw, root_lid, pn_rem, current_min_hop + 1);
           if (set_hop_return_value)
           {
-            osm_log(&(osm.log), OSM_LOG_ERROR,
+            osm_log(p_log, OSM_LOG_ERROR,
                     "__updn_bfs_by_node (less) ERR AA01: "
                     "Invalid value returned from set min hop is: %d\n",
                     set_hop_return_value);
@@ -468,12 +465,12 @@ __updn_bfs_by_node(
             /* Insert updn_switch item into the next list */
             if(!(p_tmp=__updn_create_updn_next_step_t(next_dir, p_remote_sw)))
             {
-              osm_log(&(osm.log), OSM_LOG_ERROR,
+              osm_log(p_log, OSM_LOG_ERROR,
                       "__updn_bfs_by_node: ERR AA11: "
                       "Could not create updn_next_step_t\n");
               return 1;
             }
-            osm_log(&(osm.log), OSM_LOG_DEBUG,
+            osm_log(p_log, OSM_LOG_DEBUG,
                     "__updn_bfs_by_node: "
                     "Inserting new element to the next list: guid=0x%" PRIx64 " %s\n",
                     cl_ntoh64(p_tmp->p_sw->p_node->node_info.port_guid),
@@ -486,7 +483,7 @@ __updn_bfs_by_node(
                                                                    root_lid,
                                                                    pn_rem))
         {
-          osm_log(&(osm.log), OSM_LOG_DEBUG,
+          osm_log(p_log, OSM_LOG_DEBUG,
                   "__updn_bfs_by_node (equal):"
                   "Setting Min Hop Table of switch: 0x%" PRIx64
                   "\n\t\tCurrent hop count is: %d, next hop count: %d"
@@ -500,7 +497,7 @@ __updn_bfs_by_node(
 
           if (set_hop_return_value)
           {
-            osm_log(&(osm.log), OSM_LOG_ERROR,
+            osm_log(p_log, OSM_LOG_ERROR,
                     "__updn_bfs_by_node (less) ERR AA12: "
                     "Invalid value returned from set min hop is: %d\n",
                     set_hop_return_value);
@@ -520,10 +517,10 @@ __updn_bfs_by_node(
   /* Cleanup p_currList - Had the pointer to cl_list_t */
   cl_list_destroy( p_currList );
   free (p_currList);
-  osm_log(&(osm.log), OSM_LOG_VERBOSE,
+  osm_log(p_log, OSM_LOG_VERBOSE,
           "__updn_bfs_by_node:"
           "BFS the subnet ]\n");
-  OSM_LOG_EXIT( &(osm.log));
+  OSM_LOG_EXIT(p_log);
   return 0;
 }
 
@@ -540,7 +537,7 @@ updn_destroy(
   p_map_item = cl_qmap_head( &p_updn->guid_rank_tbl);
   while( p_map_item != cl_qmap_end( &p_updn->guid_rank_tbl))
   {
-    osm_log (&(osm.log), OSM_LOG_DEBUG,
+    osm_log (&p_updn->p_osm->log, OSM_LOG_DEBUG,
              "osm_subn_calc_up_down_min_hop_table: "
              "guid = 0x%" PRIx64 " rank = %u\n",
              cl_ntoh64(cl_qmap_key(p_map_item)),
@@ -567,15 +564,15 @@ updn_destroy(
 /**********************************************************************
  **********************************************************************/
 static updn_t*
-updn_construct(void)
+updn_construct(osm_log_t *p_log)
 {
   updn_t* p_updn;
 
-  OSM_LOG_ENTER( &(osm.log), updn_construct);
+  OSM_LOG_ENTER( p_log, updn_construct);
   p_updn = malloc(sizeof(updn_t));
   if (p_updn)
     memset(p_updn, 0, sizeof(updn_t));
-  OSM_LOG_EXIT( &(osm.log) );
+  OSM_LOG_EXIT( p_log );
   return(p_updn);
 }
 
@@ -583,7 +580,8 @@ updn_construct(void)
  **********************************************************************/
 static cl_status_t
 updn_init(
-  IN updn_t* const p_updn )
+  IN updn_t* const p_updn,
+  IN osm_opensm_t *p_osm )
 {
   cl_list_t * p_list;
   FILE*           p_updn_guid_file;
@@ -592,13 +590,9 @@ updn_init(
   cl_list_iterator_t guid_iterator;
   ib_api_status_t status = IB_SUCCESS;
 
-  OSM_LOG_ENTER( &(osm.log), updn_init );
-  /* Make sure the p_updn isn't NULL */
-  if (!p_updn)
-  {
-    status = IB_ERROR;
-    goto Exit_Bad;
-  }
+  OSM_LOG_ENTER( &p_osm->log, updn_init );
+
+  p_updn->p_osm = p_osm;
   p_updn->state = UPDN_INIT;
   cl_qmap_init( &p_updn->guid_rank_tbl);
   p_list = (cl_list_t*)malloc(sizeof(cl_list_t));
@@ -614,78 +608,74 @@ updn_init(
   p_updn->updn_ucast_reg_inputs.num_guids = 0;
   p_updn->updn_ucast_reg_inputs.guid_list = NULL;
   p_updn->auto_detect_root_nodes = FALSE;
-  /* Check if updn is activated , then fetch root nodes */
-  if (osm.routing_engine.context)
+  /*
+     Check the source for root node list, if file parse it, otherwise
+     wait for a callback to activate auto detection
+  */
+  if (p_osm->subn.opt.updn_guid_file)
   {
-    /*
-       Check the source for root node list, if file parse it, otherwise
-       wait for a callback to activate auto detection
-    */
-    if (osm.subn.opt.updn_guid_file)
+    /* Now parse guid from file */
+    p_updn_guid_file = fopen(p_osm->subn.opt.updn_guid_file, "r");
+    if (p_updn_guid_file == NULL)
     {
-      /* Now parse guid from file */
-      p_updn_guid_file = fopen(osm.subn.opt.updn_guid_file, "r");
-      if (p_updn_guid_file == NULL)
-      {
-        osm_log( &osm.log, OSM_LOG_ERROR,
-                 "osm_opensm_init : ERR AA02: "
-                 "Failed to open guid list file (%s)\n",
-                 osm.subn.opt.updn_guid_file);
-        status = IB_NOT_FOUND;
-        goto Exit;
-      }
+      osm_log( &p_osm->log, OSM_LOG_ERROR,
+               "osm_opensm_init : ERR AA02: "
+               "Failed to open guid list file (%s)\n",
+               p_osm->subn.opt.updn_guid_file);
+      status = IB_NOT_FOUND;
+      goto Exit;
+    }
 
-      while ( fgets(line, MAX_UPDN_GUID_FILE_LINE_LENGTH, p_updn_guid_file) )
+    while ( fgets(line, MAX_UPDN_GUID_FILE_LINE_LENGTH, p_updn_guid_file) )
+    {
+      if (strcspn(line, " ,;.") == strlen(line))
       {
-        if (strcspn(line, " ,;.") == strlen(line))
+        /* Skip empty Lines anywhere in the file - only one char means the Null termination */
+        if (strlen(line) > 1)
         {
-          /* Skip empty Lines anywhere in the file - only one char means the Null termination */
-          if (strlen(line) > 1)
-          {
-            p_tmp = malloc(sizeof(uint64_t));
-            *p_tmp = strtoull(line, NULL, 16);
-            cl_list_insert_tail(p_updn->p_root_nodes, p_tmp);
-          }
-        }
-        else
-        {
-          osm_log( &osm.log, OSM_LOG_ERROR,
-                   "osm_opensm_init: ERR AA03: "
-                   "Bad formatted guid in file (%s): %s\n",
-                   osm.subn.opt.updn_guid_file, line );
-          status = IB_NOT_FOUND;
-          break;
+          p_tmp = malloc(sizeof(uint64_t));
+          *p_tmp = strtoull(line, NULL, 16);
+          cl_list_insert_tail(p_updn->p_root_nodes, p_tmp);
         }
       }
-
-      /* For Debug Purposes ... */
-      osm_log( &osm.log, OSM_LOG_DEBUG,
-               "osm_opensm_init: "
-               "UPDN - Root nodes fetching by file %s\n",
-               osm.subn.opt.updn_guid_file );
-      guid_iterator = cl_list_head(p_updn->p_root_nodes);
-      while( guid_iterator != cl_list_end(p_updn->p_root_nodes) )
+      else
       {
-        osm_log( &osm.log, OSM_LOG_DEBUG,
-                 "osm_opensm_init: "
-                 "Inserting GUID 0x%" PRIx64 " as root node\n",
-                 *((uint64_t*)cl_list_obj(guid_iterator)) );
-        guid_iterator = cl_list_next(guid_iterator);
+        osm_log( &p_osm->log, OSM_LOG_ERROR,
+                 "osm_opensm_init: ERR AA03: "
+                 "Bad formatted guid in file (%s): %s\n",
+                 p_osm->subn.opt.updn_guid_file, line );
+        status = IB_NOT_FOUND;
+        break;
       }
     }
-    else
+
+    /* For Debug Purposes ... */
+    osm_log( &p_osm->log, OSM_LOG_DEBUG,
+             "osm_opensm_init: "
+             "UPDN - Root nodes fetching by file %s\n",
+             p_osm->subn.opt.updn_guid_file );
+    guid_iterator = cl_list_head(p_updn->p_root_nodes);
+    while( guid_iterator != cl_list_end(p_updn->p_root_nodes) )
     {
-      p_updn->auto_detect_root_nodes = TRUE;
+      osm_log( &p_osm->log, OSM_LOG_DEBUG,
+               "osm_opensm_init: "
+               "Inserting GUID 0x%" PRIx64 " as root node\n",
+               *((uint64_t*)cl_list_obj(guid_iterator)) );
+      guid_iterator = cl_list_next(guid_iterator);
     }
-    /* If auto mode detection required - will be executed in main b4 the assignment of UI Ucast */
   }
+  else
+  {
+    p_updn->auto_detect_root_nodes = TRUE;
+  }
+  /* If auto mode detection required - will be executed in main b4 the assignment of UI Ucast */
 
   goto Exit;
 
   Exit_Bad :
     return 1;
   Exit :
-    OSM_LOG_EXIT( &(osm.log) );
+    OSM_LOG_EXIT( &p_osm->log );
   return (status);
 }
 
@@ -707,10 +697,11 @@ updn_subn_rank(
   cl_list_t     *p_currList,*p_nextList;
   cl_status_t did_cause_update;
   uint8_t num_ports, port_num;
+  osm_log_t *p_log = &p_updn->p_osm->log;
 
-  OSM_LOG_ENTER( &(osm.log), updn_subn_rank);
+  OSM_LOG_ENTER( p_log, updn_subn_rank);
 
-  osm_log(&(osm.log), OSM_LOG_VERBOSE,
+  osm_log(p_log, OSM_LOG_VERBOSE,
           "updn_subn_rank: "
           "Ranking starts from GUID 0x%" PRIx64 "\n", root_guid);
 
@@ -721,30 +712,30 @@ updn_subn_rank(
   p_currList = p_nextList;
 
   /* Check valid subnet & guid */
-  tbl_size = (uint16_t)(cl_qmap_count(&(osm.subn.port_guid_tbl)));
+  tbl_size = (uint16_t)(cl_qmap_count(&p_updn->p_osm->subn.port_guid_tbl));
   if (tbl_size == 0)
   {
-    osm_log(&(osm.log), OSM_LOG_ERROR,
+    osm_log(p_log, OSM_LOG_ERROR,
             "updn_subn_rank: ERR AA04: "
             "Port guid table is empty, cannot perform ranking\n");
-    OSM_LOG_EXIT( &(osm.log));
+    OSM_LOG_EXIT(p_log);
     return 1;
   }
 
-  p_root_port = (osm_port_t*) cl_qmap_get(&(osm.subn.port_guid_tbl), \
+  p_root_port = (osm_port_t*) cl_qmap_get(&p_updn->p_osm->subn.port_guid_tbl,
                                           cl_ntoh64(root_guid));
-  if( p_root_port == (osm_port_t*)cl_qmap_end( &(osm.subn.port_guid_tbl) ) )
+  if( p_root_port == (osm_port_t*)cl_qmap_end( &p_updn->p_osm->subn.port_guid_tbl ) )
   {
 
-    osm_log(&(osm.log), OSM_LOG_ERROR,
+    osm_log(p_log, OSM_LOG_ERROR,
             "updn_subn_rank: ERR AA05: "
             "Wrong guid value: 0x%" PRIx64 "\n", root_guid);
-    OSM_LOG_EXIT( &(osm.log));
+    OSM_LOG_EXIT(p_log);
     return 1;
   }
 
   /* Rank the first chosen guid anyway since its the base rank */
-  osm_log(&(osm.log), OSM_LOG_DEBUG,
+  osm_log(p_log, OSM_LOG_DEBUG,
           "updn_subn_rank: "
           "Ranking port GUID 0x%" PRIx64 "\n", root_guid);
 
@@ -763,7 +754,7 @@ updn_subn_rank(
   p_currList = p_nextList;
 
   /* BFS the list till its empty */
-  osm_log(&(osm.log), OSM_LOG_VERBOSE,
+  osm_log(p_log, OSM_LOG_VERBOSE,
           "updn_subn_rank: "
           "BFS the subnet [\n");
 
@@ -779,7 +770,7 @@ updn_subn_rank(
     while ( p_physp != NULL )
     {
       num_ports = osm_node_get_num_physp( p_physp->p_node );
-      osm_log(&(osm.log), OSM_LOG_DEBUG,
+      osm_log(p_log, OSM_LOG_DEBUG,
               "updn_subn_rank: "
               "Handling port GUID 0x%" PRIx64 "\n",
               cl_ntoh64(p_physp->port_guid));
@@ -800,19 +791,19 @@ updn_subn_rank(
              osm_physp_is_valid ( p_remote_physp ))
         {
           port_guid = p_remote_physp->port_guid;
-          osm_log(&(osm.log), OSM_LOG_DEBUG,
+          osm_log(p_log, OSM_LOG_DEBUG,
                   "updn_subn_rank: "
                   "Visiting remote port GUID 0x%" PRIx64 "\n",
                   cl_ntoh64(port_guid));
           /* Was it visited ?
              Only if the pointer equal to cl_qmap_end its not
              found in the list */
-          osm_log(&(osm.log), OSM_LOG_DEBUG,
+          osm_log(p_log, OSM_LOG_DEBUG,
                   "updn_subn_rank: "
                   "Ranking port GUID 0x%" PRIx64 "\n", cl_ntoh64(port_guid));
           did_cause_update = __updn_update_rank(&p_updn->guid_rank_tbl, port_guid, rank);
 
-          osm_log(&(osm.log), OSM_LOG_VERBOSE,
+          osm_log(p_log, OSM_LOG_VERBOSE,
                   "updn_subn_rank: "
                   "Rank of port GUID 0x%" PRIx64 " = %u\n", cl_ntoh64(port_guid),
                   ((updn_rank_t*)cl_qmap_get(&p_updn->guid_rank_tbl, port_guid))->rank
@@ -834,7 +825,7 @@ updn_subn_rank(
     p_currList = p_nextList;
   }
 
-  osm_log(&(osm.log), OSM_LOG_VERBOSE,
+  osm_log(p_log, OSM_LOG_VERBOSE,
           "updn_subn_rank: "
           "BFS the subnet ]\n");
 
@@ -842,12 +833,12 @@ updn_subn_rank(
   free(p_currList);
 
   /* Print Summary of ranking */
-  osm_log(&(osm.log), OSM_LOG_VERBOSE,
+  osm_log(p_log, OSM_LOG_VERBOSE,
           "updn_subn_rank: "
           "Rank Info :\n\t Root Guid = 0x%" PRIx64 "\n\t Max Node Rank = %d\n",
           cl_ntoh64(p_root_port->guid), rank);
   p_updn->state = UPDN_RANK;
-  OSM_LOG_EXIT( &(osm.log));
+  OSM_LOG_EXIT(p_log);
   return 0;
 }
 
@@ -858,33 +849,34 @@ __osm_subn_set_up_down_min_hop_table(
   IN updn_t* p_updn )
 {
   /* Init local vars */
-  osm_subn_t *p_subn = &(osm.subn);
+  osm_subn_t *p_subn = &p_updn->p_osm->subn;
+  osm_log_t *p_log = &p_updn->p_osm->log;
   osm_switch_t *p_next_sw,*p_sw;
   osm_port_t *p_next_port,*p_port;
   ib_net64_t port_guid;
 
-  OSM_LOG_ENTER( &(osm.log), __osm_subn_set_up_down_min_hop_table );
+  OSM_LOG_ENTER( p_log, __osm_subn_set_up_down_min_hop_table );
   if (p_updn->state == UPDN_INIT)
   {
-    osm_log(&(osm.log), OSM_LOG_ERROR,
+    osm_log(p_log, OSM_LOG_ERROR,
             "__osm_subn_set_up_down_min_hop_table: ERR AA06: "
             "Calculating Min Hop only allowed after ranking\n");
-    OSM_LOG_EXIT( &(osm.log) );
+    OSM_LOG_EXIT( p_log );
     return 1;
   }
 
   /* Check if its a non switched subnet .. */
   if ( cl_is_qmap_empty( &p_subn->sw_guid_tbl ) )
   {
-    osm_log(&(osm.log), OSM_LOG_ERROR,
+    osm_log(p_log, OSM_LOG_ERROR,
             "__osm_subn_set_up_down_min_hop_table: ERR AA10: "
             "This is a non switched subnet, cannot perform UPDN algorithm\n");
-    OSM_LOG_EXIT( &(osm.log));
+    OSM_LOG_EXIT(p_log);
     return 1;
   }
   /* Go over all the switches in the subnet - for each init their Min Hop
      Table */
-  osm_log(&(osm.log), OSM_LOG_VERBOSE,
+  osm_log(p_log, OSM_LOG_VERBOSE,
           "__osm_subn_set_up_down_min_hop_table: "
           "Init Min Hop Table of all switches [\n");
 
@@ -903,12 +895,12 @@ __osm_subn_set_up_down_min_hop_table(
       osm_switch_set_path(p_sw, lid_ho, OSM_NO_PATH, TRUE);
   }
 
-  osm_log(&(osm.log), OSM_LOG_VERBOSE,
+  osm_log(p_log, OSM_LOG_VERBOSE,
           "__osm_subn_set_up_down_min_hop_table: "
           "Init Min Hop Table of all switches ]\n");
 
   /* Now do the BFS for each port  in the subnet */
-  osm_log(&(osm.log), OSM_LOG_VERBOSE,
+  osm_log(p_log, OSM_LOG_VERBOSE,
           "__osm_subn_set_up_down_min_hop_table: "
           "BFS through all port guids in the subnet [\n");
   p_next_port = (osm_port_t*)cl_qmap_head( &p_subn->port_guid_tbl );
@@ -917,23 +909,23 @@ __osm_subn_set_up_down_min_hop_table(
     p_port = p_next_port;
     p_next_port = (osm_port_t*)cl_qmap_next( &p_port->map_item );
     port_guid = cl_qmap_key(&(p_port->map_item));
-    osm_log(&(osm.log), OSM_LOG_DEBUG,
+    osm_log(p_log, OSM_LOG_DEBUG,
             "__osm_subn_set_up_down_min_hop_table: "
             "BFS through port GUID 0x%" PRIx64 "\n",
             cl_ntoh64(port_guid));
-    if(__updn_bfs_by_node(p_subn,port_guid,
+    if(__updn_bfs_by_node(p_updn, p_subn, port_guid,
                           &p_updn->guid_rank_tbl))
     {
-      OSM_LOG_EXIT( &(osm.log) );
+      OSM_LOG_EXIT( p_log );
       return 1;
     }
   }
 
-  osm_log(&(osm.log), OSM_LOG_INFO,
+  osm_log(p_log, OSM_LOG_INFO,
           "__osm_subn_set_up_down_min_hop_table: "
           "BFS through all port guids in the subnet ]\n");
   /* Cleanup */
-  OSM_LOG_EXIT( &(osm.log) );
+  OSM_LOG_EXIT( p_log );
   return 0;
 }
 
@@ -949,13 +941,13 @@ __osm_subn_calc_up_down_min_hop_table(
   cl_map_item_t *p_map_item;
   int status;
 
-  OSM_LOG_ENTER( &(osm.log), osm_subn_calc_up_down_min_hop_table );
-  osm_log(&(osm.log), OSM_LOG_VERBOSE,
+  OSM_LOG_ENTER( &p_updn->p_osm->log, osm_subn_calc_up_down_min_hop_table );
+  osm_log(&p_updn->p_osm->log, OSM_LOG_VERBOSE,
           "__osm_subn_calc_up_down_min_hop_table: "
           "Ranking all port guids in the list\n");
   if (num_guids == 0)
   {
-    osm_log(&(osm.log), OSM_LOG_ERROR,
+    osm_log(&p_updn->p_osm->log, OSM_LOG_ERROR,
             "__osm_subn_calc_up_down_min_hop_table: ERR AA0A: "
             "No guids were given or number of guids is 0\n");
     return 1;
@@ -967,7 +959,7 @@ __osm_subn_calc_up_down_min_hop_table(
     updn_subn_rank(guid_list[idx], 0, p_updn);
   }
   /* After multiple ranking need to set Min Hop Table by UpDn algorithm  */
-  osm_log(&(osm.log), OSM_LOG_VERBOSE,
+  osm_log(&p_updn->p_osm->log, OSM_LOG_VERBOSE,
           "__osm_subn_calc_up_down_min_hop_table: "
           "Setting all switches' Min Hop Table\n");
 
@@ -977,7 +969,7 @@ __osm_subn_calc_up_down_min_hop_table(
   p_map_item = cl_qmap_head( &p_updn->guid_rank_tbl);
   while( p_map_item != cl_qmap_end( &p_updn->guid_rank_tbl))
   {
-    osm_log (&(osm.log), OSM_LOG_DEBUG,
+    osm_log (&p_updn->p_osm->log, OSM_LOG_DEBUG,
              "__osm_subn_calc_up_down_min_hop_table: "
              "guid = 0x%" PRIx64 " rank = %u\n",
              cl_ntoh64(cl_qmap_key(p_map_item)),
@@ -987,7 +979,7 @@ __osm_subn_calc_up_down_min_hop_table(
     p_map_item = cl_qmap_head( &p_updn->guid_rank_tbl);
   }
 
-  OSM_LOG_EXIT( &(osm.log));
+  OSM_LOG_EXIT( &p_updn->p_osm->log);
   return status;
 }
 
@@ -998,31 +990,33 @@ static int
 __osm_updn_call(
   void *ctx )
 {
-  OSM_LOG_ENTER(&(osm.log), __osm_updn_call);
+  updn_t *p_updn = ctx;
+
+  OSM_LOG_ENTER(&p_updn->p_osm->log, __osm_updn_call);
 
   /* First auto detect root nodes - if required */
-  if ( ((updn_t*)ctx)->auto_detect_root_nodes )
+  if ( p_updn->auto_detect_root_nodes )
   {
     /*    printf ("-V- b4 osm_updn_find_root_nodes_by_min_hop\n"); */
-    __osm_updn_find_root_nodes_by_min_hop( ((updn_t*)ctx) );
+    __osm_updn_find_root_nodes_by_min_hop( p_updn );
   }
   /*  printf ("-V- after osm_updn_find_root_nodes_by_min_hop\n"); */
   /* Only if there are assigned root nodes do the algorithm , otherwise perform do nothing */
-  if ( ((updn_t*)ctx)->updn_ucast_reg_inputs.num_guids > 0)
+  if ( p_updn->updn_ucast_reg_inputs.num_guids > 0)
   {
-    osm_log (&(osm.log), OSM_LOG_DEBUG,
+    osm_log (&(p_updn->p_osm->log), OSM_LOG_DEBUG,
              "__osm_updn_call: "
              "activating UPDN algorithm\n");
-    __osm_subn_calc_up_down_min_hop_table( ((updn_t*)ctx)->updn_ucast_reg_inputs.num_guids,
-                                           ((updn_t*)ctx)->updn_ucast_reg_inputs.guid_list,
-                                           ((updn_t*)ctx) );
+    __osm_subn_calc_up_down_min_hop_table( p_updn->updn_ucast_reg_inputs.num_guids,
+                                           p_updn->updn_ucast_reg_inputs.guid_list,
+                                           p_updn );
   }
   else
-    osm_log (&(osm.log), OSM_LOG_INFO,
+    osm_log (&p_updn->p_osm->log, OSM_LOG_INFO,
              "__osm_updn_call: "
              "disable UPDN algorithm, no root nodes were found\n");
   
-  OSM_LOG_EXIT(&(osm.log));
+  OSM_LOG_EXIT(&p_updn->p_osm->log);
   return 0;
 }
 
@@ -1036,7 +1030,7 @@ __osm_updn_convert_list2array(
   uint32_t i = 0, max_num = 0;
   uint64_t *p_guid;
 
-  OSM_LOG_ENTER(&(osm.log), __osm_updn_convert_list2array);
+  OSM_LOG_ENTER(&p_updn->p_osm->log, __osm_updn_convert_list2array);
 
   p_updn->updn_ucast_reg_inputs.num_guids = cl_list_count(
     p_updn->p_root_nodes);
@@ -1057,13 +1051,13 @@ __osm_updn_convert_list2array(
     }
     max_num = i;
     for (i = 0; i < max_num; i++ )
-      osm_log (&(osm.log), OSM_LOG_DEBUG,
+      osm_log (&p_updn->p_osm->log, OSM_LOG_DEBUG,
                "__osm_updn_convert_list2array: "
                "Map GUID 0x%" PRIx64 " into UPDN array\n",
                p_updn->updn_ucast_reg_inputs.guid_list[i]);
   }
   /* Since we need the template list for other sweeps, we wont destroy & free it */
-  OSM_LOG_EXIT(&(osm.log));
+  OSM_LOG_EXIT(&p_updn->p_osm->log);
 }
 
 /**********************************************************************
@@ -1073,11 +1067,12 @@ static int
 __osm_updn_find_root_nodes_by_min_hop(
   OUT updn_t *  p_updn )
 {
+  osm_opensm_t *p_osm = p_updn->p_osm;
   osm_switch_t *p_next_sw, *p_sw;
   osm_port_t   *p_next_port, *p_port;
   osm_physp_t  *p_physp;
   uint32_t      numCas = 0;
-  uint32_t      numSws = cl_qmap_count(&osm.subn.sw_guid_tbl);
+  uint32_t      numSws = cl_qmap_count(&p_osm->subn.sw_guid_tbl);
   cl_qmap_t     min_hop_hist; /* Histogram container */
   updn_hist_t  *p_updn_hist, *p_up_ht;
   uint8_t       maxHops = 0; /* contain the max histogram index */
@@ -1086,12 +1081,12 @@ __osm_updn_find_root_nodes_by_min_hop(
   cl_map_t      ca_by_lid_map; /* map holding all CA lids  */
   uint16_t self_lid_ho;
 
-  OSM_LOG_ENTER(&(osm.log), osm_updn_find_root_nodes_by_min_hop);
+  OSM_LOG_ENTER(&p_osm->log, osm_updn_find_root_nodes_by_min_hop);
 
-  osm_log (&(osm.log), OSM_LOG_DEBUG,
+  osm_log (&p_osm->log, OSM_LOG_DEBUG,
            "__osm_updn_find_root_nodes_by_min_hop: "
            "current number of ports in the subnet is %d\n",
-           cl_qmap_count(&osm.subn.port_guid_tbl));
+           cl_qmap_count(&p_osm->subn.port_guid_tbl));
   /* Init the required vars */
   cl_qmap_init( &min_hop_hist );
   cl_map_construct( &ca_by_lid_map );
@@ -1104,11 +1099,11 @@ __osm_updn_find_root_nodes_by_min_hop(
   */
 
   /* Find the Maximum number of CAs (and routers) for histogram normalization */
-  osm_log (&(osm.log), OSM_LOG_VERBOSE,
+  osm_log (&p_osm->log, OSM_LOG_VERBOSE,
            "__osm_updn_find_root_nodes_by_min_hop: "
            "Find the number of CA and store them in cl_list\n");
-  p_next_port = (osm_port_t*)cl_qmap_head( &osm.subn.port_guid_tbl );
-  while( p_next_port != (osm_port_t*)cl_qmap_end( &osm.subn.port_guid_tbl ) ) {
+  p_next_port = (osm_port_t*)cl_qmap_head( &p_osm->subn.port_guid_tbl );
+  while( p_next_port != (osm_port_t*)cl_qmap_end( &p_osm->subn.port_guid_tbl ) ) {
     p_port = p_next_port;
     p_next_port = (osm_port_t*)cl_qmap_next( &p_next_port->map_item );
     if ( osm_node_get_type(p_port->p_node) != IB_NODE_TYPE_SWITCH )
@@ -1122,20 +1117,20 @@ __osm_updn_find_root_nodes_by_min_hop(
          cl_list_insert_tail(p_ca_list, self);
       */
       cl_map_insert( &ca_by_lid_map, self_lid_ho, (void *)0x1);
-      osm_log (&(osm.log), OSM_LOG_DEBUG,
+      osm_log (&p_osm->log, OSM_LOG_DEBUG,
                "__osm_updn_find_root_nodes_by_min_hop: "
                "Inserting into array GUID 0x%" PRIx64 ", Lid: 0x%X\n",
                cl_ntoh64(osm_port_get_guid(p_port)), self_lid_ho);
     }
   }
-  osm_log (&(osm.log), OSM_LOG_DEBUG,
+  osm_log (&p_osm->log, OSM_LOG_DEBUG,
            "__osm_updn_find_root_nodes_by_min_hop: "
            "Found %u CA, %u SW in the subnet\n", numCas, numSws);
-  p_next_sw = (osm_switch_t*)cl_qmap_head( &osm.subn.sw_guid_tbl );
-  osm_log (&(osm.log), OSM_LOG_VERBOSE,
+  p_next_sw = (osm_switch_t*)cl_qmap_head( &p_osm->subn.sw_guid_tbl );
+  osm_log (&p_osm->log, OSM_LOG_VERBOSE,
            "__osm_updn_find_root_nodes_by_min_hop: "
            "Passing through all switches to collect Min Hop info\n");
-  while( p_next_sw != (osm_switch_t*)cl_qmap_end( &osm.subn.sw_guid_tbl ) )
+  while( p_next_sw != (osm_switch_t*)cl_qmap_end( &p_osm->subn.sw_guid_tbl ) )
   {
     uint16_t max_lid_ho, lid_ho;
     uint8_t hop_val;
@@ -1152,7 +1147,7 @@ __osm_updn_find_root_nodes_by_min_hop(
     max_lid_ho = osm_switch_get_max_lid_ho(p_sw);
     /* Get base lid of switch by retrieving port 0 lid of node pointer */
     self_lid_ho = cl_ntoh16( osm_node_get_base_lid( p_sw->p_node, 0 ) );
-    osm_log (&(osm.log), OSM_LOG_DEBUG,
+    osm_log (&p_osm->log, OSM_LOG_DEBUG,
              "__osm_updn_find_root_nodes_by_min_hop: "
              "Passing through switch lid 0x%X\n", self_lid_ho);
     for (lid_ho = 1; lid_ho <= max_lid_ho; lid_ho++)
@@ -1189,7 +1184,7 @@ __osm_updn_find_root_nodes_by_min_hop(
           CL_ASSERT (p_updn_hist);
           p_updn_hist->bar_value = 1;
           cl_qmap_insert(&min_hop_hist, (uint64_t)hop_val, &p_updn_hist->map_item);
-          osm_log (&(osm.log), OSM_LOG_DEBUG,
+          osm_log (&p_osm->log, OSM_LOG_DEBUG,
                    "__osm_updn_find_root_nodes_by_min_hop: "
                    "Creating new entry in histogram %u with bar value 1\n",
                    hop_val);
@@ -1198,7 +1193,7 @@ __osm_updn_find_root_nodes_by_min_hop(
         {
           /* Entry exist in the table , just increment the value */
           p_updn_hist->bar_value++;
-          osm_log (&(osm.log), OSM_LOG_DEBUG,
+          osm_log (&p_osm->log, OSM_LOG_DEBUG,
                    "__osm_updn_find_root_nodes_by_min_hop: "
                    "Updating entry in histogram %u with bar value %d\n",
                    hop_val, p_updn_hist->bar_value);
@@ -1210,7 +1205,7 @@ __osm_updn_find_root_nodes_by_min_hop(
        number of CAs */
     thd1 = numCas * 0.9;
     thd2 = numCas * 0.05;
-    osm_log (&(osm.log), OSM_LOG_DEBUG,
+    osm_log (&p_osm->log, OSM_LOG_DEBUG,
              "__osm_updn_find_root_nodes_by_min_hop: "
              "Pass over the histogram value and find only one root node above "
              "thd1 = %f && thd2 = %f\n", thd1, thd2);
@@ -1224,7 +1219,7 @@ __osm_updn_find_root_nodes_by_min_hop(
         numHopBarsOverThd1++;
       if ( p_up_ht->bar_value > thd2 )
         numHopBarsOverThd2++;
-      osm_log (&(osm.log), OSM_LOG_DEBUG,
+      osm_log (&p_osm->log, OSM_LOG_DEBUG,
                "__osm_updn_find_root_nodes_by_min_hop: "
                "Passing through histogram - Hop Index %u: "
                "numHopBarsOverThd1 = %u, numHopBarsOverThd2 = %u\n",
@@ -1233,7 +1228,7 @@ __osm_updn_find_root_nodes_by_min_hop(
     }
 
     /* destroy the qmap table and all its content - no longer needed */
-    osm_log (&(osm.log), OSM_LOG_DEBUG,
+    osm_log (&p_osm->log, OSM_LOG_DEBUG,
              "__osm_updn_find_root_nodes_by_min_hop: "
              "Cleanup: delete histogram "
              "UPDN - Root nodes fetching by auto detect\n");
@@ -1250,7 +1245,7 @@ __osm_updn_find_root_nodes_by_min_hop(
     {
       p_guid = malloc(sizeof(uint64_t));
       *p_guid = cl_ntoh64(osm_node_get_node_guid(p_sw->p_node));
-      osm_log (&(osm.log), OSM_LOG_DEBUG,
+      osm_log (&p_osm->log, OSM_LOG_DEBUG,
                "__osm_updn_find_root_nodes_by_min_hop: "
                "Inserting GUID 0x%" PRIx64 " as root node\n",
                *p_guid);
@@ -1265,7 +1260,7 @@ __osm_updn_find_root_nodes_by_min_hop(
   /* Now convert the cl_list to array */
   __osm_updn_convert_list2array(p_updn);
  
-  OSM_LOG_EXIT(&(osm.log));
+  OSM_LOG_EXIT(&p_osm->log);
   return 0;
 }
 
@@ -1284,14 +1279,14 @@ osm_ucast_updn_setup(
   osm_opensm_t *p_osm )
 {
 	updn_t *p_updn;
-	p_updn = updn_construct();
+	p_updn = updn_construct(&p_osm->log);
 	if (!p_updn)
 		return -1;
 	p_osm->routing_engine.context = p_updn;
 	p_osm->routing_engine.delete = __osm_updn_delete;
 	p_osm->routing_engine.ucast_fdb_assign = __osm_updn_call;
 
-	if (updn_init(p_updn) != IB_SUCCESS)
+	if (updn_init(p_updn, p_osm) != IB_SUCCESS)
 		return -1;
 	if (!p_updn->auto_detect_root_nodes)
 		__osm_updn_convert_list2array(p_updn);
-- 
1.4.4





More information about the general mailing list