[ofa-general] [PATCH] opensm: consolidate message "box" logging code

Sasha Khapyorsky sashak at voltaire.com
Thu Feb 7 20:05:08 PST 2008


Consolidate log message box (which looks like:

******************************************************************
************************* Hello World! ***************************
******************************************************************

) printing code.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 opensm/include/opensm/osm_log.h  |    8 +-
 opensm/opensm/libopensm.map      |    1 +
 opensm/opensm/osm_log.c          |   28 ++++++-
 opensm/opensm/osm_sm_state_mgr.c |   50 ++----------
 opensm/opensm/osm_state_mgr.c    |  164 +++++++-------------------------------
 5 files changed, 70 insertions(+), 181 deletions(-)

diff --git a/opensm/include/opensm/osm_log.h b/opensm/include/opensm/osm_log.h
index 1aad786..97d0556 100644
--- a/opensm/include/opensm/osm_log.h
+++ b/opensm/include/opensm/osm_log.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004-2007 Voltaire, Inc. All rights reserved.
+ * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
  * Copyright (c) 2002-2006 Mellanox Technologies LTD. All rights reserved.
  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
  *
@@ -391,9 +391,9 @@ osm_log_is_active(IN const osm_log_t * const p_log,
 
 extern int osm_log_printf(osm_log_t * p_log, osm_log_level_t level,
 			  const char *fmt, ...);
-
-void
-osm_log_raw(IN osm_log_t * const p_log,
+extern void osm_log_msg_box(osm_log_t *log, osm_log_level_t level,
+			    const char *func_name, const char *msg);
+extern void osm_log_raw(IN osm_log_t * const p_log,
 	    IN const osm_log_level_t verbosity, IN const char *p_buf);
 
 #define DBG_CL_LOCK 0
diff --git a/opensm/opensm/libopensm.map b/opensm/opensm/libopensm.map
index b3d4fe0..1d574bc 100644
--- a/opensm/opensm/libopensm.map
+++ b/opensm/opensm/libopensm.map
@@ -2,6 +2,7 @@ OPENSM_1.5 {
 	global:
 		osm_log;
 		osm_log_printf;
+		osm_log_msg_box;
 		osm_is_debug;
 		osm_log_init;
 		osm_log_init_v2;
diff --git a/opensm/opensm/osm_log.c b/opensm/opensm/osm_log.c
index 97f8920..b5b4bd9 100644
--- a/opensm/opensm/osm_log.c
+++ b/opensm/opensm/osm_log.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004-2006 Voltaire, Inc. All rights reserved.
+ * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
  * Copyright (c) 2002-2006 Mellanox Technologies LTD. All rights reserved.
  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
  *
@@ -243,6 +243,32 @@ osm_log_raw(IN osm_log_t * const p_log,
 	}
 }
 
+void osm_log_msg_box(IN osm_log_t *log, osm_log_level_t level,
+		     const char *func_name, const char *msg)
+{
+#define MSG_BOX_LENGTH 66
+	char buf[MSG_BOX_LENGTH + 1];
+	int i, n;
+
+	if (!osm_log_is_active(log, level))
+		return;
+
+	n = (MSG_BOX_LENGTH - strlen(msg))/2 - 1;
+	if (n < 0)
+		n = 0;
+	for (i = 0 ; i < n; i++)
+		sprintf(buf + i, "*");
+	n += snprintf(buf + n, sizeof(buf) - n, " %s ", msg);
+	for (i = n; i < MSG_BOX_LENGTH; i++)
+		sprintf(buf + i, "*");
+
+	osm_log(log, level, "%s:\n\n\n"
+		"*********************************************"
+		"*********************\n%s\n"
+		"*********************************************"
+		"*********************\n\n\n", func_name, buf);
+}
+
 boolean_t osm_is_debug(void)
 {
 #if defined( _DEBUG_ )
diff --git a/opensm/opensm/osm_sm_state_mgr.c b/opensm/opensm/osm_sm_state_mgr.c
index 4d0b026..27d7536 100644
--- a/opensm/opensm/osm_sm_state_mgr.c
+++ b/opensm/opensm/osm_sm_state_mgr.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004-2007 Voltaire, Inc. All rights reserved.
+ * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
  * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
  *
@@ -74,16 +74,8 @@ __osm_sm_state_mgr_standby_msg(IN const osm_sm_state_mgr_t * p_sm_mgr)
 {
 	osm_log(p_sm_mgr->p_log, OSM_LOG_SYS, "Entering STANDBY state\n");	/* Format Waived */
 
-	if (osm_log_is_active(p_sm_mgr->p_log, OSM_LOG_VERBOSE)) {
-		osm_log(p_sm_mgr->p_log, OSM_LOG_VERBOSE,
-			"__osm_sm_state_mgr_standby_msg: "
-			"\n\n\n********************************"
-			"**********************************\n"
-			"******************** ENTERING SM STANDBY"
-			" STATE *******************\n"
-			"**************************************"
-			"****************************\n\n\n");
-	}
+	osm_log_msg_box(p_sm_mgr->p_log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"ENTERING SM STANDBY STATE");
 }
 
 /**********************************************************************
@@ -93,16 +85,8 @@ __osm_sm_state_mgr_master_msg(IN const osm_sm_state_mgr_t * p_sm_mgr)
 {
 	osm_log(p_sm_mgr->p_log, OSM_LOG_SYS, "Entering MASTER state\n");	/* Format Waived */
 
-	if (osm_log_is_active(p_sm_mgr->p_log, OSM_LOG_VERBOSE)) {
-		osm_log(p_sm_mgr->p_log, OSM_LOG_VERBOSE,
-			"__osm_sm_state_mgr_master_msg: "
-			"\n\n\n********************************"
-			"**********************************\n"
-			"******************** ENTERING SM MASTER"
-			" STATE ********************\n"
-			"**************************************"
-			"****************************\n\n\n");
-	}
+	osm_log_msg_box(p_sm_mgr->p_log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"ENTERING SM MASTER STATE");
 }
 
 /**********************************************************************
@@ -110,16 +94,8 @@ __osm_sm_state_mgr_master_msg(IN const osm_sm_state_mgr_t * p_sm_mgr)
 static void
 __osm_sm_state_mgr_discovering_msg(IN const osm_sm_state_mgr_t * p_sm_mgr)
 {
-	if (osm_log_is_active(p_sm_mgr->p_log, OSM_LOG_VERBOSE)) {
-		osm_log(p_sm_mgr->p_log, OSM_LOG_VERBOSE,
-			"__osm_sm_state_mgr_discovering_msg: "
-			"\n\n\n********************************"
-			"**********************************\n"
-			"******************** ENTERING SM DISCOVERING"
-			" STATE ***************\n"
-			"**************************************"
-			"****************************\n\n\n");
-	}
+	osm_log_msg_box(p_sm_mgr->p_log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"ENTERING SM DISCOVERING STATE");
 }
 
 /**********************************************************************
@@ -129,16 +105,8 @@ __osm_sm_state_mgr_notactive_msg(IN const osm_sm_state_mgr_t * p_sm_mgr)
 {
 	osm_log(p_sm_mgr->p_log, OSM_LOG_SYS, "Entering NOT-ACTIVE state\n");	/* Format Waived */
 
-	if (osm_log_is_active(p_sm_mgr->p_log, OSM_LOG_VERBOSE)) {
-		osm_log(p_sm_mgr->p_log, OSM_LOG_VERBOSE,
-			"__osm_sm_state_mgr_notactive_msg: "
-			"\n\n\n********************************"
-			"**********************************\n"
-			"***************** ENTERING SM NOT-ACTIVE"
-			" STATE *******************\n"
-			"**************************************"
-			"****************************\n\n\n");
-	}
+	osm_log_msg_box(p_sm_mgr->p_log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"ENTERING SM NOT-ACTIVE STATE");
 }
 
 #if 0
diff --git a/opensm/opensm/osm_state_mgr.c b/opensm/opensm/osm_state_mgr.c
index 674ccf7..a2b0725 100644
--- a/opensm/opensm/osm_state_mgr.c
+++ b/opensm/opensm/osm_state_mgr.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004-2007 Voltaire, Inc. All rights reserved.
+ * Copyright (c) 2004-2008 Voltaire, Inc. All rights reserved.
  * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
  *
@@ -88,24 +88,9 @@ static void __osm_state_mgr_up_msg(IN const osm_sm_t *sm)
 	} else
 		osm_log(sm->p_log, OSM_LOG_INFO, "SUBNET UP\n");	/* Format Waived */
 
-	if (sm->p_subn->opt.sweep_interval)
-		osm_log(sm->p_log, OSM_LOG_VERBOSE,
-			"__osm_state_mgr_up_msg: "
-			"\n\n\n********************************"
-			"**********************************\n"
-			"**************************** SUBNET UP "
-			"***************************\n"
-			"**************************************"
-			"****************************\n\n\n");
-	else
-		osm_log(sm->p_log, OSM_LOG_VERBOSE,
-			"__osm_state_mgr_up_msg: "
-			"\n\n\n********************************"
-			"**********************************\n"
-			"******************* SUBNET UP "
-			"(sweep disabled) *******************\n"
-			"**************************************"
-			"****************************\n\n\n");
+	osm_log_msg_box(sm->p_log, OSM_LOG_VERBOSE, __FUNCTION__,
+			sm->p_subn->opt.sweep_interval ?
+				"SUBNET UP" : "SUBNET UP (sweep disabled)");
 }
 
 /**********************************************************************
@@ -114,44 +99,24 @@ static void __osm_state_mgr_init_errors_msg(IN osm_log_t *log)
 {
 	osm_log(log, OSM_LOG_SYS, "Errors during initialization\n");	/* Format Waived */
 
-	osm_log(log, OSM_LOG_ERROR,
-		"__osm_state_mgr_init_errors_msg: "
-		"\n\n\n********************************"
-		"**********************************\n"
-		"****************** ERRORS DURING INITI"
-		"ALIZATION ******************\n"
-		"**************************************"
-		"****************************\n\n\n");
+	osm_log_msg_box(log, OSM_LOG_ERROR, __FUNCTION__,
+			"ERRORS DURING INITIALIZATION");
 }
 
 /**********************************************************************
  **********************************************************************/
 static void __osm_state_mgr_light_sweep_done_msg(IN osm_log_t *log)
 {
-	if (osm_log_is_active(log, OSM_LOG_VERBOSE))
-		osm_log(log, OSM_LOG_VERBOSE,
-			"__osm_state_mgr_light_sweep_done_msg: "
-			"\n\n\n********************************"
-			"**********************************\n"
-			"********************** LIGHT SWEEP "
-			"COMPLETE **********************\n"
-			"**************************************"
-			"****************************\n\n\n");
+	osm_log_msg_box(log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"LIGHT SWEEP COMPLETE");
 }
 
 /**********************************************************************
  **********************************************************************/
 static void __osm_state_mgr_standby_msg(IN osm_log_t *log)
 {
-	if (osm_log_is_active(log, OSM_LOG_VERBOSE))
-		osm_log(log, OSM_LOG_VERBOSE,
-			"__osm_state_mgr_standby_msg: "
-			"\n\n\n********************************"
-			"**********************************\n"
-			"******************** ENTERING STANDBY"
-			" STATE **********************\n"
-			"**************************************"
-			"****************************\n\n\n");
+	osm_log_msg_box(log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"ENTERING STANDBY STATE");
 }
 
 /**********************************************************************
@@ -160,150 +125,79 @@ static void __osm_state_mgr_sm_port_down_msg(IN osm_log_t *log)
 {
 	osm_log(log, OSM_LOG_SYS, "SM port is down\n");	/* Format Waived */
 
-	if (osm_log_is_active(log, OSM_LOG_VERBOSE))
-		osm_log(log, OSM_LOG_VERBOSE,
-			"__osm_state_mgr_sm_port_down_msg: "
-			"\n\n\n********************************"
-			"**********************************\n"
-			"************************** SM PORT DOWN "
-			"**************************\n"
-			"**************************************"
-			"****************************\n\n\n");
+	osm_log_msg_box(log, OSM_LOG_VERBOSE, __FUNCTION__, "SM PORT DOWN");
 }
 
 /**********************************************************************
  **********************************************************************/
 static void __osm_state_mgr_lid_assign_msg(IN osm_log_t *log)
 {
-	if (osm_log_is_active(log, OSM_LOG_VERBOSE))
-		osm_log(log, OSM_LOG_VERBOSE,
-			"__osm_state_mgr_lid_assign_msg: "
-			"\n\n\n**************************************"
-			"****************************\n"
-			"***** LID ASSIGNMENT COMPLETE - STARTING SWITC"
-			"H TABLE CONFIG *****\n"
-			"*********************************************"
-			"*********************\n\n\n");
+	osm_log_msg_box(log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"LID ASSIGNMENT COMPLETE - STARTING SWITCH TABLE CONFIG");
 }
 
 /**********************************************************************
  **********************************************************************/
 static void __osm_state_mgr_set_sm_lid_done_msg(IN osm_log_t *log)
 {
-	if (osm_log_is_active(log, OSM_LOG_VERBOSE))
-		osm_log(log, OSM_LOG_VERBOSE,
-			"__osm_state_mgr_set_sm_lid_done_msg: "
-			"\n\n\n**************************************"
-			"****************************\n"
-			"**** SM LID ASSIGNMENT COMPLETE - STARTING SUBN"
-			"ET LID CONFIG *****\n"
-			"*********************************************"
-			"*********************\n\n\n");
+	osm_log_msg_box(log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"SM LID ASSIGNMENT COMPLETE - STARTING SUBNET LID CONFIG");
 }
 
 /**********************************************************************
  **********************************************************************/
 static void __osm_state_mgr_switch_config_msg(IN osm_log_t *log)
 {
-	if (osm_log_is_active(log, OSM_LOG_VERBOSE))
-		osm_log(log, OSM_LOG_VERBOSE,
-			"__osm_state_mgr_switch_config_msg: "
-			"\n\n\n**************************************"
-			"****************************\n"
-			"***************** SWITCHES CONFIGURED FOR UNICAST "
-			"****************\n"
-			"*********************************************"
-			"*********************\n\n\n");
+	osm_log_msg_box(log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"SWITCHES CONFIGURED FOR UNICAST");
 }
 
 /**********************************************************************
  **********************************************************************/
 static void __osm_state_mgr_multicast_config_msg(IN osm_log_t *log)
 {
-	if (osm_log_is_active(log, OSM_LOG_VERBOSE))
-		osm_log(log, OSM_LOG_VERBOSE,
-			"__osm_state_mgr_multicast_config_msg: "
-			"\n\n\n**************************************"
-			"****************************\n"
-			"**************** SWITCHES CONFIGURED FOR MULTICAST "
-			"***************\n"
-			"*********************************************"
-			"*********************\n\n\n");
+	osm_log_msg_box(log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"SWITCHES CONFIGURED FOR MULTICAST");
 }
 
 /**********************************************************************
  **********************************************************************/
 static void __osm_state_mgr_links_ports_msg(IN osm_log_t *log)
 {
-	if (osm_log_is_active(log, OSM_LOG_VERBOSE))
-		osm_log(log, OSM_LOG_VERBOSE,
-			"__osm_state_mgr_links_ports_msg: "
-			"\n\n\n**************************************"
-			"****************************\n"
-			"******* LINKS PORTS CONFIGURED - SET LINKS TO ARMED "
-			"STATE ********\n"
-			"*********************************************"
-			"*********************\n\n\n");
+	osm_log_msg_box(log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"LINKS PORTS CONFIGURED - SET LINKS TO ARMED STATE");
 }
 
 /**********************************************************************
  **********************************************************************/
 static void __osm_state_mgr_links_armed_msg(IN osm_log_t *log)
 {
-	if (osm_log_is_active(log, OSM_LOG_VERBOSE))
-		osm_log(log, OSM_LOG_VERBOSE,
-			"__osm_state_mgr_links_armed_msg: "
-			"\n\n\n**************************************"
-			"****************************\n"
-			"************* LINKS ARMED - SET LINKS TO ACTIVE "
-			"STATE ************\n"
-			"*********************************************"
-			"*********************\n\n\n");
+	osm_log_msg_box(log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"LINKS ARMED - SET LINKS TO ACTIVE STATE");
 }
 
 /**********************************************************************
  **********************************************************************/
 static void __osm_state_mgr_sweep_heavy_msg(IN osm_log_t *log)
 {
-	if (osm_log_is_active(log, OSM_LOG_VERBOSE))
-		osm_log(log, OSM_LOG_VERBOSE,
-			"__osm_state_mgr_sweep_heavy_msg: "
-			"\n\n\n**************************************"
-			"****************************\n"
-			"******************** INITIATING HEAVY SWEEP "
-			"**********************\n"
-			"*********************************************"
-			"*********************\n\n\n");
+	osm_log_msg_box(log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"INITIATING HEAVY SWEEP");
 }
 
 /**********************************************************************
  **********************************************************************/
 static void __osm_state_mgr_sweep_heavy_done_msg(IN osm_log_t *log)
 {
-	if (osm_log_is_active(log, OSM_LOG_VERBOSE))
-		osm_log(log, OSM_LOG_VERBOSE,
-			"__osm_state_mgr_sweep_heavy_done_msg: "
-			"\n\n\n**************************************"
-			"****************************\n"
-			"********************* HEAVY SWEEP COMPLETE "
-			"***********************\n"
-			"*********************************************"
-			"*********************\n\n\n");
+	osm_log_msg_box(log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"HEAVY SWEEP COMPLETE");
 }
 
 /**********************************************************************
  **********************************************************************/
 static void __osm_state_mgr_sweep_light_msg(IN osm_log_t *log)
 {
-	if (osm_log_is_active(log, OSM_LOG_VERBOSE))
-		osm_log(log, OSM_LOG_VERBOSE,
-			"__osm_state_mgr_sweep_light_msg: "
-			"\n\n\n**************************************"
-			"****************************\n"
-			"******************** INITIATING LIGHT SWEEP "
-			"**********************\n"
-			"*********************************************"
-			"*********************\n\n\n");
+	osm_log_msg_box(log, OSM_LOG_VERBOSE, __FUNCTION__,
+			"INITIATING LIGHT SWEEP");
 }
 
 /**********************************************************************
-- 
1.5.4.rc5




More information about the general mailing list