Hi Sasha,
Oops, I forgot to attach the patch. Here it is.
Timothy A. Meier wrote:
Hi Sasha,
This patch very similar to the "accessor" patch I submitted last week,
but focuses
primarily on the Log.
So, if all your method wants to do is write to the opensm log, the
OPENSM_LOG() macro
should help solve the problem of "where do I get the log, or the opensm
object?".
The OSM_LOG() macro can be maintained for the cases when there are
multiple logs.
What do you think? It tries to hide the opensm object.
I guess I got a little carried away hiding things... ;^)
--
Timothy A. Meier
Computer Scientist
ICCD/High Performance Computing
925.422.3341
[EMAIL PROTECTED]
>From a920d57ba7323b364ddb1e24aa1006856f11f9ad Mon Sep 17 00:00:00 2001
From: Tim Meier <[EMAIL PROTECTED]>
Date: Mon, 10 Mar 2008 11:32:04 -0700
Subject: [PATCH] opensm: added convenience function for the opensm log
A new OPENSM_LOG() macro was added to conveniently log
messages to opensm's log. As always, the OpenSM and
its log must be contructed and initialized before it
can be used. Assertions protect against its use if not
valid.
Signed-off-by: Tim Meier <[EMAIL PROTECTED]>
---
opensm/include/opensm/osm_log.h | 3 +++
opensm/include/opensm/osm_opensm.h | 3 +++
opensm/opensm/osm_opensm.c | 16 ++++++++++++++++
3 files changed, 22 insertions(+), 0 deletions(-)
diff --git a/opensm/include/opensm/osm_log.h b/opensm/include/opensm/osm_log.h
index dd63dc4..264b360 100644
--- a/opensm/include/opensm/osm_log.h
+++ b/opensm/include/opensm/osm_log.h
@@ -398,6 +398,9 @@ extern void osm_log_raw(IN osm_log_t * const p_log,
#define OSM_LOG(log, level, fmt, arg...) osm_log(log, level, "%s: " fmt,
__func__, ##arg)
+/* The OpenSM Log - a convenience function using the log in the fully
constructed OpenSM object*/
+#define OPENSM_LOG(level, fmt, arg...) osm_log(osm_opensm_get_opensm_log(),
level, "%s: " fmt, __func__, ##arg)
+
#define DBG_CL_LOCK 0
#define CL_PLOCK_EXCL_ACQUIRE( __exp__ ) \
diff --git a/opensm/include/opensm/osm_opensm.h
b/opensm/include/opensm/osm_opensm.h
index cd1e73b..f670978 100644
--- a/opensm/include/opensm/osm_opensm.h
+++ b/opensm/include/opensm/osm_opensm.h
@@ -504,6 +504,9 @@ osm_routing_engine_type_t osm_routing_engine_type(IN const
char *str);
void osm_dump_mcast_routes(osm_opensm_t * osm);
void osm_dump_all(osm_opensm_t * osm);
+/* log helper */
+osm_log_t * osm_opensm_get_opensm_log(void);
+
/****v* OpenSM/osm_exit_flag
*/
extern volatile unsigned int osm_exit_flag;
diff --git a/opensm/opensm/osm_opensm.c b/opensm/opensm/osm_opensm.c
index aa7ded3..f0370f4 100644
--- a/opensm/opensm/osm_opensm.c
+++ b/opensm/opensm/osm_opensm.c
@@ -67,6 +67,10 @@ struct routing_engine_module {
const char *name;
int (*setup) (osm_opensm_t * p_osm);
};
+/*
+ * A pointer to the OpenSM super object. See osm_opensm_construct().
+ */
+static osm_opensm_t * p_osm_object = NULL;
extern int osm_ucast_updn_setup(osm_opensm_t * p_osm);
extern int osm_ucast_file_setup(osm_opensm_t * p_osm);
@@ -170,6 +174,16 @@ static int osm_ucast_null_setup(osm_opensm_t * p_osm)
/**********************************************************************
**********************************************************************/
+osm_log_t * osm_opensm_get_opensm_log(void)
+{
+/* a convenience function for safely getting the OpenSM log
+ */
+ CL_ASSERT(p_osm_object);
+ CL_ASSERT(&p_osm_object->log);
+ return &p_osm_object->log;
+}
+/**********************************************************************
+ **********************************************************************/
void osm_opensm_construct(IN osm_opensm_t * const p_osm)
{
memset(p_osm, 0, sizeof(*p_osm));
@@ -180,6 +194,7 @@ void osm_opensm_construct(IN osm_opensm_t * const p_osm)
osm_mad_pool_construct(&p_osm->mad_pool);
osm_vl15_construct(&p_osm->vl15);
osm_log_construct(&p_osm->log);
+ p_osm_object = p_osm; /* save a pointer for subsequent use */
}
/**********************************************************************
@@ -245,6 +260,7 @@ void osm_opensm_destroy(IN osm_opensm_t * const p_osm)
cl_plock_destroy(&p_osm->lock);
osm_log_destroy(&p_osm->log);
+ p_osm_object = NULL; /* invalidate our reference */
}
/**********************************************************************
--
1.5.1
_______________________________________________
general mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general
To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general