[openib-general] [PATCH 1/4] Simplification of the ucast fdb dumps.
Sasha Khapyorsky
sashak at voltaire.com
Sat Jun 10 17:32:38 PDT 2006
This separates the dump procedure from rest of the flow and prevents
multiple fopen()/fclose() (one pair per switch) - one fopen() and one
fclose() instead.
Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
osm/opensm/osm_ucast_mgr.c | 187 +++++++++++++++++++++++---------------------
1 files changed, 96 insertions(+), 91 deletions(-)
diff --git a/osm/opensm/osm_ucast_mgr.c b/osm/opensm/osm_ucast_mgr.c
index 40422e5..cac7f9b 100644
--- a/osm/opensm/osm_ucast_mgr.c
+++ b/osm/opensm/osm_ucast_mgr.c
@@ -128,7 +128,7 @@ osm_ucast_mgr_init(
/**********************************************************************
**********************************************************************/
-void
+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 )
@@ -143,70 +143,65 @@ osm_ucast_mgr_dump_path_distribution(
OSM_LOG_ENTER( p_mgr->p_log, osm_ucast_mgr_dump_path_distribution );
- if( osm_log_is_active( p_mgr->p_log, OSM_LOG_DEBUG ) )
- {
- p_node = osm_switch_get_node_ptr( p_sw );
+ p_node = osm_switch_get_node_ptr( p_sw );
- num_ports = osm_switch_get_num_ports( p_sw );
- sprintf( p_mgr->p_report_buf, "osm_ucast_mgr_dump_path_distribution: "
- "Switch 0x%" PRIx64 "\n"
- "Port : Path Count Through Port",
- cl_ntoh64( osm_node_get_node_guid( p_node ) ) );
+ num_ports = osm_switch_get_num_ports( p_sw );
+ sprintf( p_mgr->p_report_buf, "osm_ucast_mgr_dump_path_distribution: "
+ "Switch 0x%" PRIx64 "\n"
+ "Port : Path Count Through Port",
+ cl_ntoh64( osm_node_get_node_guid( p_node ) ) );
- for( i = 0; i < num_ports; i++ )
+ for( i = 0; i < num_ports; i++ )
+ {
+ num_paths = osm_switch_path_count_get( p_sw , i );
+ sprintf( line, "\n %03u : %u", i, num_paths );
+ strcat( p_mgr->p_report_buf, line );
+ if( i == 0 )
{
- num_paths = osm_switch_path_count_get( p_sw , i );
- sprintf( line, "\n %03u : %u", i, num_paths );
- strcat( p_mgr->p_report_buf, line );
- if( i == 0 )
- {
- strcat( p_mgr->p_report_buf, " (switch management port)" );
- continue;
- }
-
- p_remote_node = osm_node_get_remote_node(
- p_node, i, NULL );
-
- if( p_remote_node == NULL )
- continue;
+ strcat( p_mgr->p_report_buf, " (switch management port)" );
+ continue;
+ }
- remote_guid_ho = cl_ntoh64(
- osm_node_get_node_guid( p_remote_node ) );
+ p_remote_node = osm_node_get_remote_node( p_node, i, NULL );
+ if( p_remote_node == NULL )
+ continue;
- switch( osm_node_get_remote_type( p_node, i ) )
- {
- case IB_NODE_TYPE_SWITCH:
- strcat( p_mgr->p_report_buf, " (link to switch" );
- break;
- case IB_NODE_TYPE_ROUTER:
- strcat( p_mgr->p_report_buf, " (link to router" );
- break;
- case IB_NODE_TYPE_CA:
- strcat( p_mgr->p_report_buf, " (link to CA" );
- break;
- default:
- strcat( p_mgr->p_report_buf, " (link to unknown type, node" );
- break;
- }
+ remote_guid_ho = cl_ntoh64( osm_node_get_node_guid( p_remote_node ) );
- sprintf( line, " 0x%" PRIx64 ")", remote_guid_ho );
- strcat( p_mgr->p_report_buf, line );
+ switch( osm_node_get_remote_type( p_node, i ) )
+ {
+ case IB_NODE_TYPE_SWITCH:
+ strcat( p_mgr->p_report_buf, " (link to switch" );
+ break;
+ case IB_NODE_TYPE_ROUTER:
+ strcat( p_mgr->p_report_buf, " (link to router" );
+ break;
+ case IB_NODE_TYPE_CA:
+ strcat( p_mgr->p_report_buf, " (link to CA" );
+ break;
+ default:
+ strcat( p_mgr->p_report_buf, " (link to unknown type, node" );
+ break;
}
- strcat( p_mgr->p_report_buf, "\n" );
-
- osm_log_raw( p_mgr->p_log, OSM_LOG_ROUTING, p_mgr->p_report_buf );
+ sprintf( line, " 0x%" PRIx64 ")", remote_guid_ho );
+ strcat( p_mgr->p_report_buf, line );
}
+ strcat( p_mgr->p_report_buf, "\n" );
+
+ osm_log_raw( p_mgr->p_log, OSM_LOG_ROUTING, p_mgr->p_report_buf );
+
OSM_LOG_EXIT( p_mgr->p_log );
}
/**********************************************************************
**********************************************************************/
-void
+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 const osm_switch_t* const p_sw,
+ IN FILE *p_fdbFile)
{
const osm_node_t* p_node;
uint8_t port_num;
@@ -217,34 +212,10 @@ osm_ucast_mgr_dump_ucast_routes(
uint16_t lid_ho;
char line[OSM_REPORT_LINE_SIZE];
uint32_t line_num = 0;
- FILE * p_fdbFile;
boolean_t ui_ucast_fdb_assign_func_defined;
- char *file_name = NULL;
OSM_LOG_ENTER( p_mgr->p_log, osm_ucast_mgr_dump_ucast_routes );
- if( !osm_log_is_active( p_mgr->p_log, OSM_LOG_ROUTING ) )
- goto Exit;
-
- file_name =
- (char*)malloc(strlen(p_mgr->p_subn->opt.dump_files_dir) + 10);
-
- CL_ASSERT(file_name);
-
- strcpy(file_name, p_mgr->p_subn->opt.dump_files_dir);
- strcat(file_name,"/osm.fdbs");
-
- /* Open the file or error */
- p_fdbFile = fopen(file_name, "a");
- if (! p_fdbFile)
- {
- osm_log( p_mgr->p_log, OSM_LOG_ERROR,
- "osm_ucast_mgr_dump_ucast_routes: ERR 3A12: "
- "Failed to open fdb file (%s)\n",
- file_name );
- goto Exit;
- }
-
p_node = osm_switch_get_node_ptr( p_sw );
max_lid_ho = osm_switch_get_max_lid_ho( p_sw );
@@ -324,15 +295,59 @@ osm_ucast_mgr_dump_ucast_routes(
if( line_num != 0 )
fprintf(p_fdbFile,"%s\n",p_mgr->p_report_buf );
- fclose(p_fdbFile);
-
- Exit:
- if (file_name)
- free(file_name);
OSM_LOG_EXIT( p_mgr->p_log );
}
/**********************************************************************
+ **********************************************************************/
+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 )
+{
+ 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_ucast_routes: 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);
+}
+
+/**********************************************************************
Add each switch's own LID to its LID matrix.
**********************************************************************/
static void
@@ -952,8 +967,6 @@ __osm_ucast_mgr_process_tbl(
__osm_ucast_mgr_set_table( p_mgr, p_sw );
- osm_ucast_mgr_dump_path_distribution( p_mgr, p_sw );
- osm_ucast_mgr_dump_ucast_routes( p_mgr, p_sw );
OSM_LOG_EXIT( p_mgr->p_log );
}
@@ -1047,7 +1060,6 @@ osm_ucast_mgr_process(
uint32_t iteration_max;
osm_signal_t signal;
cl_qmap_t *p_sw_guid_tbl;
- char *file_name = NULL;
OSM_LOG_ENTER( p_mgr->p_log, osm_ucast_mgr_process );
@@ -1148,26 +1160,19 @@ osm_ucast_mgr_process(
build and download the switch forwarding tables.
*/
- /* remove the old fdb dump file: */
- if( osm_log_is_active( p_mgr->p_log, OSM_LOG_ROUTING ) && (file_name =
- (char*)malloc(strlen(p_mgr->p_subn->opt.dump_files_dir) + 10)) )
- {
- strcpy(file_name, p_mgr->p_subn->opt.dump_files_dir);
- strcat(file_name, "/osm.fdbs");
- unlink(file_name);
- free(file_name);
- }
-
cl_qmap_apply_func( p_sw_guid_tbl,
__osm_ucast_mgr_process_tbl, p_mgr );
+ /* dump fdb into file: */
+ if ( osm_log_is_active( p_mgr->p_log, OSM_LOG_ROUTING ) )
+ osm_ucast_mgr_dump_tables( p_mgr );
+
/*
For now don't bother checking if the switch forwarding tables
actually needed updating. The current code will always update
them, and thus leave transactions pending on the wire.
Therefore, return OSM_SIGNAL_DONE_PENDING.
*/
-
signal = OSM_SIGNAL_DONE_PENDING;
}
else
More information about the general
mailing list