[ofa-general] [PATCH] osm: reading guids file in ucast_mgr

Yevgeny Kliteynik kliteyn at dev.mellanox.co.il
Mon Jun 11 02:33:08 PDT 2007


Hi Hal,

This patch removes a code that was reading root guids file in 
osm_ucast_updn.c and replaces it with a more general function 
in osm_ucast_mgr.c

This function will also be used by fat-tree routing.

-- Yevgeny

Signed-off-by:  Yevgeny Kliteynik <kliteyn at dev.mellanox.co.il>

>From a8d32db1beacf6b42240357ab3e71584daadc791 Mon Sep 17 00:00:00 2001
From: Yevgeny Kliteynik <kliteyn at dev.mellanox.co.il>
Date: Mon, 11 Jun 2007 12:24:12 +0300
Subject: [PATCH 1/1] DELETE: make read_guid_file global

no changes added to commit (use "git add" and/or "git commit -a")

Signed-off-by: Yevgeny Kliteynik <kliteyn at dev.mellanox.co.il>
---
 opensm/include/opensm/osm_base.h      |    8 ++--
 opensm/include/opensm/osm_ucast_mgr.h |   36 ++++++++++++++++
 opensm/opensm/osm_ucast_mgr.c         |   74 +++++++++++++++++++++++++++++++++
 opensm/opensm/osm_ucast_updn.c        |   48 +++------------------
 4 files changed, 120 insertions(+), 46 deletions(-)

diff --git a/opensm/include/opensm/osm_base.h b/opensm/include/opensm/osm_base.h
index ee280d3..7f043a0 100644
--- a/opensm/include/opensm/osm_base.h
+++ b/opensm/include/opensm/osm_base.h
@@ -844,16 +844,16 @@ typedef enum _osm_mcast_req_type
 }	osm_mcast_req_type_t;
 /***********/
 
-/****s* OpenSM: Base/MAX_UPDN_GUID_FILE_LINE_LENGTH
+/****s* OpenSM: Base/MAX_GUID_FILE_LINE_LENGTH
 * NAME
-*	MAX_UPDN_GUID_FILE_LINE_LENGTH
+*	MAX_GUID_FILE_LINE_LENGTH
 *
 * DESCRIPTION
-*	The maximum line number when reading updn guid file
+*	The maximum line number when reading guid file
 *
 * SYNOPSIS
 */
-#define MAX_UPDN_GUID_FILE_LINE_LENGTH 120
+#define MAX_GUID_FILE_LINE_LENGTH 120
 /**********/
 
 /****s* OpenSM: Base/VendorOUIs
diff --git a/opensm/include/opensm/osm_ucast_mgr.h b/opensm/include/opensm/osm_ucast_mgr.h
index 39bf45a..e003f31 100644
--- a/opensm/include/opensm/osm_ucast_mgr.h
+++ b/opensm/include/opensm/osm_ucast_mgr.h
@@ -293,6 +293,42 @@ osm_ucast_mgr_build_lid_matrices(
 *	Unicast Manager
 *********/
 
+/****f* OpenSM: Unicast Manager/osm_ucast_mgr_read_guid_file
+* NAME
+*	osm_ucast_mgr_read_guid_file
+*
+* DESCRIPTION
+*	Read guid list from file.
+*
+* SYNOPSIS
+*/
+cl_status_t
+osm_ucast_mgr_read_guid_file(
+	IN  osm_ucast_mgr_t * const p_mgr,
+	IN  const char      * guid_file_name,
+	IN  cl_list_t       * p_list );
+/*
+* PARAMETERS
+*	p_mgr
+*		[in] Pointer to an osm_ucast_mgr_t object.
+*
+*	guid_file_name
+*		[in] Name of the file to read.
+*
+*	p_list
+*		[in] Pointer to the list that will be filled with guids.
+*
+* RETURN VALUES
+*	IB_SUCCESS if the file was read successfully.
+*
+* NOTES
+*	This function reads guids from a file and inserts them
+*	into a list.
+*
+* SEE ALSO
+*	Unicast Manager
+*********/
+
 /****f* OpenSM: Unicast Manager/osm_ucast_mgr_process
 * NAME
 *	osm_ucast_mgr_process
diff --git a/opensm/opensm/osm_ucast_mgr.c b/opensm/opensm/osm_ucast_mgr.c
index 9f40242..5182718 100644
--- a/opensm/opensm/osm_ucast_mgr.c
+++ b/opensm/opensm/osm_ucast_mgr.c
@@ -1044,6 +1044,80 @@ ucast_mgr_setup_all_switches(osm_subn_t *p_subn)
 
 /**********************************************************************
  **********************************************************************/
+
+cl_status_t
+osm_ucast_mgr_read_guid_file(
+  IN  osm_ucast_mgr_t * const p_mgr,
+  IN  const char      * guid_file_name,
+  IN  cl_list_t       * p_list )
+{
+  cl_status_t   status = IB_SUCCESS;
+  FILE        * guid_file;
+  char          line[MAX_GUID_FILE_LINE_LENGTH];
+  char        * endptr;
+  uint64_t    * p_guid;
+
+  OSM_LOG_ENTER(p_mgr->p_log, osm_ucast_mgr_read_guid_file);
+
+  guid_file = fopen(guid_file_name, "r");
+  if (guid_file == NULL)
+  {
+    osm_log( p_mgr->p_log, OSM_LOG_ERROR,
+             "osm_ucast_mgr_read_guid_file: ERR 3A13: "
+             "Failed to open guid list file (%s)\n",
+             guid_file_name );
+    status = IB_NOT_FOUND;
+    goto Exit;
+  }
+
+  while ( fgets(line, MAX_GUID_FILE_LINE_LENGTH, guid_file) )
+  {
+    if (strcspn(line, " ,;.") != strlen(line))
+    {
+      osm_log( p_mgr->p_log, OSM_LOG_ERROR,
+               "osm_ucast_mgr_read_guid_file: ERR 3A14: "
+               "Bad formatted guid in file (%s): %s\n",
+               guid_file_name, line );
+      status = IB_NOT_FOUND;
+      break;
+    }
+
+    /* Skip empty lines anywhere in the file - only one 
+       char means the null termination */
+    if (strlen(line) <= 1)
+      continue;
+
+    p_guid = malloc(sizeof(uint64_t));
+    if (!p_guid)
+    {
+      status = IB_ERROR;
+      goto Exit;
+    }
+
+    *p_guid = strtoull(line, &endptr, 16);
+
+    /* check that the string is a number */
+    if (!(*p_guid) && (*endptr != '\0'))
+    {
+      osm_log( p_mgr->p_log, OSM_LOG_ERROR,
+               "osm_ucast_mgr_read_guid_file: ERR 3A15: "
+               "Bad formatted guid in file (%s): %s\n",
+               guid_file_name, line );
+      status = IB_NOT_FOUND;
+      break;
+    }
+
+    /* store the parsed guid */
+    cl_list_insert_tail(p_list, p_guid);
+  }
+
+Exit :
+  OSM_LOG_EXIT( p_mgr->p_log );
+  return (status);
+}
+
+/**********************************************************************
+ **********************************************************************/
 osm_signal_t
 osm_ucast_mgr_process(
   IN osm_ucast_mgr_t* const p_mgr )
diff --git a/opensm/opensm/osm_ucast_updn.c b/opensm/opensm/osm_ucast_updn.c
index 95a0622..23a9db5 100644
--- a/opensm/opensm/osm_ucast_updn.c
+++ b/opensm/opensm/osm_ucast_updn.c
@@ -53,6 +53,7 @@
 #include <complib/cl_qmap.h>
 #include <opensm/osm_switch.h>
 #include <opensm/osm_opensm.h>
+#include <opensm/osm_ucast_mgr.h>
 
 /* //////////////////////////// */
 /*  Local types                 */
@@ -303,9 +304,6 @@ updn_init(
   IN osm_opensm_t *p_osm )
 {
   cl_list_t * p_list;
-  FILE*       p_updn_guid_file;
-  char        line[MAX_UPDN_GUID_FILE_LINE_LENGTH];
-  uint64_t *  p_tmp;
   cl_list_iterator_t guid_iterator;
   ib_api_status_t status = IB_SUCCESS;
 
@@ -332,45 +330,11 @@ updn_init(
   */
   if (p_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)
-    {
-      osm_log( &p_osm->log, OSM_LOG_ERROR,
-               "updn_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) )
-    {
-      if (strcspn(line, " ,;.") == strlen(line))
-      {
-        /* Skip empty lines anywhere in the file - only one char means the Null termination */
-        if (strlen(line) > 1)
-        {
-          p_tmp = malloc(sizeof(uint64_t));
-          if (!p_tmp)
-          {
-            status = IB_ERROR;
-            goto Exit;
-          }
-          *p_tmp = strtoull(line, NULL, 16);
-          cl_list_insert_tail(p_updn->p_root_nodes, p_tmp);
-        }
-      }
-      else
-      {
-        osm_log( &p_osm->log, OSM_LOG_ERROR,
-                 "updn_init: ERR AA03: "
-                 "Bad formatted guid in file (%s): %s\n",
-                 p_osm->subn.opt.updn_guid_file, line );
-        status = IB_NOT_FOUND;
-        break;
-      }
-    }
+    status = osm_ucast_mgr_read_guid_file( &p_osm->sm.ucast_mgr,
+                                           p_osm->subn.opt.updn_guid_file,
+                                           p_updn->p_root_nodes );
+    if (status != IB_SUCCESS)
+       goto Exit;
 
     /* For Debug Purposes ... */
     osm_log( &p_osm->log, OSM_LOG_DEBUG,
-- 
1.5.1.4






More information about the general mailing list