[openib-general] [PATCH 2/5] opensm: ucast_mgr dumper unification

Sasha Khapyorsky sashak at voltaire.com
Thu Oct 19 13:35:22 PDT 2006


This unifies ucsat_mgr dumper. Main goal is to provide infrastructure
for different dump file generation using the same routines.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 osm/opensm/osm_ucast_mgr.c |  104 +++++++++++++++++++++++---------------------
 1 files changed, 55 insertions(+), 49 deletions(-)

diff --git a/osm/opensm/osm_ucast_mgr.c b/osm/opensm/osm_ucast_mgr.c
index 2c5f1d1..b4880ad 100644
--- a/osm/opensm/osm_ucast_mgr.c
+++ b/osm/opensm/osm_ucast_mgr.c
@@ -129,10 +129,52 @@ osm_ucast_mgr_init(
 
 /**********************************************************************
  **********************************************************************/
+struct ucast_mgr_dump_context {
+	osm_ucast_mgr_t *p_mgr;
+	FILE *file;
+};
+
+static void
+ucast_mgr_dump(osm_ucast_mgr_t *p_mgr, FILE *file,
+	       void (*func)(cl_map_item_t *, void *))
+{
+	struct ucast_mgr_dump_context dump_context;
+
+	dump_context.p_mgr = p_mgr;
+	dump_context.file = file;
+
+	cl_qmap_apply_func(&p_mgr->p_subn->sw_guid_tbl, func, &dump_context );
+}
+
+static void
+ucast_mgr_dump_to_file(osm_ucast_mgr_t *p_mgr, const char *file_name,
+		       void (*func)(cl_map_item_t *, void *))
+{
+	char path[1024];
+	FILE  *file;
+
+	snprintf(path, sizeof(path), "%s/%s",
+		 p_mgr->p_subn->opt.dump_files_dir, file_name);
+  
+	file = fopen(path, "w");
+	if (!file) {
+		osm_log(p_mgr->p_log, OSM_LOG_ERROR,
+			"__osm_ucast_mgr_dump_tables: ERR 3A12: "
+			"Failed to open fdb file (%s)\n", path );
+		return;
+	}
+
+	ucast_mgr_dump(p_mgr, file, func);
+
+	fclose(file);
+}
+
+/**********************************************************************
+ **********************************************************************/
 static void
 __osm_ucast_mgr_dump_path_distribution(
-  IN const osm_ucast_mgr_t* const p_mgr,
-  IN const osm_switch_t* const p_sw )
+  IN cl_map_item_t *p_map_item,
+  IN void *cxt)
 {
   osm_node_t *p_node;
   osm_node_t *p_remote_node;
@@ -141,6 +183,8 @@ __osm_ucast_mgr_dump_path_distribution(
   uint32_t num_paths;
   ib_net64_t remote_guid_ho;
   char line[OSM_REPORT_LINE_SIZE];
+  osm_switch_t* p_sw = (osm_switch_t *)p_map_item;
+  osm_ucast_mgr_t* p_mgr = ((struct ucast_mgr_dump_context *)cxt)->p_mgr;
 
   OSM_LOG_ENTER( p_mgr->p_log, __osm_ucast_mgr_dump_path_distribution );
 
@@ -200,9 +244,8 @@ __osm_ucast_mgr_dump_path_distribution(
  **********************************************************************/
 static void
 __osm_ucast_mgr_dump_ucast_routes(
-  IN const osm_ucast_mgr_t*   const p_mgr,
-  IN const osm_switch_t*      const p_sw,
-  IN FILE *p_fdbFile )
+  IN cl_map_item_t *p_map_item,
+  IN void *cxt)
 {
   const osm_node_t*        p_node;
   uint8_t                  port_num;
@@ -214,6 +257,9 @@ __osm_ucast_mgr_dump_ucast_routes(
   char                     line[OSM_REPORT_LINE_SIZE];
   uint32_t                 line_num = 0;
   boolean_t                ui_ucast_fdb_assign_func_defined;
+  osm_switch_t* p_sw = (osm_switch_t *)p_map_item;
+  osm_ucast_mgr_t* p_mgr = ((struct ucast_mgr_dump_context *)cxt)->p_mgr;
+  FILE *p_fdbFile = ((struct ucast_mgr_dump_context *)cxt)->file;
   
   OSM_LOG_ENTER( p_mgr->p_log, __osm_ucast_mgr_dump_ucast_routes );
 
@@ -304,51 +350,11 @@ __osm_ucast_mgr_dump_ucast_routes(
 
 /**********************************************************************
  **********************************************************************/
-struct ucast_mgr_dump_context {
-	osm_ucast_mgr_t *p_mgr;
-	FILE *file;
-};
-
-static void
-__osm_ucast_mgr_dump_table(
-  IN cl_map_item_t* const  p_map_item,
-  IN void* context )
+static void __osm_ucast_mgr_dump_tables(osm_ucast_mgr_t *p_mgr)
 {
-  osm_switch_t* const p_sw = (osm_switch_t*)p_map_item;
-  struct ucast_mgr_dump_context *cxt = context;
-
-  if( osm_log_is_active( cxt->p_mgr->p_log, OSM_LOG_DEBUG ) )
-    __osm_ucast_mgr_dump_path_distribution( cxt->p_mgr, p_sw );
-  __osm_ucast_mgr_dump_ucast_routes( cxt->p_mgr, p_sw, cxt->file );
-}
-
-static void __osm_ucast_mgr_dump_tables(
-  IN osm_ucast_mgr_t *p_mgr )
-{
-  char file_name[1024];
-  struct ucast_mgr_dump_context dump_context;
-  FILE  *file;
-  
-  strncpy(file_name, p_mgr->p_subn->opt.dump_files_dir, sizeof(file_name) - 1);
-  strncat(file_name, "/osm.fdbs", sizeof(file_name) - strlen(file_name) - 1);
-  
-  file = fopen(file_name, "w");
-  if (!file)
-  {
-    osm_log( p_mgr->p_log, OSM_LOG_ERROR,
-             "__osm_ucast_mgr_dump_tables: ERR 3A12: "
-             "Failed to open fdb file (%s)\n",
-             file_name );
-    return;
-  }
-
-  dump_context.p_mgr = p_mgr;
-  dump_context.file = file;
-
-  cl_qmap_apply_func( &p_mgr->p_subn->sw_guid_tbl,
-                      __osm_ucast_mgr_dump_table, &dump_context );
-
-  fclose(file);
+  if( osm_log_is_active( p_mgr->p_log, OSM_LOG_DEBUG ) )
+    ucast_mgr_dump(p_mgr, NULL, __osm_ucast_mgr_dump_path_distribution);;
+  ucast_mgr_dump_to_file(p_mgr, "osm.fdbs", __osm_ucast_mgr_dump_ucast_routes);
 }
 
 /**********************************************************************
-- 
1.4.3.g7768





More information about the general mailing list