osaf/tools/saflog/include/saflog.h | 6 +++++ osaf/tools/saflog/src/saflog.c | 45 +++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 10 deletions(-)
There can be situations during switchover/failover when clients of LOG can be blocked because LOG is busy doing file i/o. One additional reason is that LOG clients use the common saflog routine that when called for the first time, does an initialize() and streamopen() both of which are synchronous calls and if streamopen() fails, saflog does a logfinalize() which is also a synchronous calls. So in a worst case scenario, when saflog() is called by a standby process that is becoming active, then saflog() can get blocked for <=30 seconds before it returns back to the caller, i.e. mds send timeout of 10 seconds X 3 synchronous APIs. This patch adds a separate safloginit() routine that can be used by saflog() users such that it is called much before during their lifetime than during role change. diff --git a/osaf/tools/saflog/include/saflog.h b/osaf/tools/saflog/include/saflog.h --- a/osaf/tools/saflog/include/saflog.h +++ b/osaf/tools/saflog/include/saflog.h @@ -19,6 +19,7 @@ #define SAFLOG_H #include <saAis.h> +#include <saLog.h> #ifdef __cplusplus extern "C" { @@ -33,6 +34,11 @@ extern "C" { extern void saflog(int priority, const SaNameT *logSvcUsrName, const char *format, ...) __attribute__ ((format(printf, 3, 4))); +extern int gl_initialized; +extern SaLogStreamHandleT gl_logStreamHandle; +extern SaLogHandleT gl_logHandle; + +extern void saflogInit(void); #ifdef __cplusplus } #endif diff --git a/osaf/tools/saflog/src/saflog.c b/osaf/tools/saflog/src/saflog.c --- a/osaf/tools/saflog/src/saflog.c +++ b/osaf/tools/saflog/src/saflog.c @@ -19,14 +19,40 @@ #include <syslog.h> #include <stdarg.h> #include <unistd.h> -#include <saLog.h> #include <saflog.h> +int gl_initialized; +SaLogStreamHandleT gl_logStreamHandle; +SaLogHandleT gl_logHandle; + +void saflogInit(void) +{ + SaAisErrorT error; + + if (!gl_initialized) { + SaVersionT logVersion = { 'A', 2, 1 }; + SaNameT stream_name = {.value = SA_LOG_STREAM_SYSTEM, .length = sizeof(SA_LOG_STREAM_SYSTEM)}; + + error = saLogInitialize(&gl_logHandle, NULL, &logVersion); + if (error != SA_AIS_OK) { + syslog(LOG_INFO, "saflogInit: saLogInitialize FAILED: %u", error); + return; + } + + error = saLogStreamOpen_2(gl_logHandle, &stream_name, NULL, 0, SA_TIME_ONE_SECOND, &gl_logStreamHandle); + if (error != SA_AIS_OK) { + syslog(LOG_INFO, "saflogInit: saLogStreamOpen_2 FAILED: %u", error); + if (saLogFinalize(gl_logHandle) != SA_AIS_OK) + syslog(LOG_INFO, "saflogInit: saLogFinalize FAILED: %u", error); + return; + } + gl_initialized = 1; + } +} + void saflog(int priority, const SaNameT *logSvcUsrName, const char *format, ...) { SaAisErrorT error; - static int initialized; - static SaLogStreamHandleT logStreamHandle; SaLogRecordT logRecord; SaLogBufferT logBuffer; va_list ap; @@ -36,25 +62,24 @@ void saflog(int priority, const SaNameT logBuffer.logBufSize = vsnprintf(str, sizeof(str), format, ap); va_end(ap); - if (!initialized) { + if (!gl_initialized) { SaVersionT logVersion = { 'A', 2, 1 }; SaNameT stream_name = {.value = SA_LOG_STREAM_SYSTEM, .length = sizeof(SA_LOG_STREAM_SYSTEM)}; - SaLogHandleT logHandle; - error = saLogInitialize(&logHandle, NULL, &logVersion); + error = saLogInitialize(&gl_logHandle, NULL, &logVersion); if (error != SA_AIS_OK) { syslog(LOG_INFO, "saLogInitialize FAILED: %u", error); goto done; } - error = saLogStreamOpen_2(logHandle, &stream_name, NULL, 0, SA_TIME_ONE_SECOND, &logStreamHandle); + error = saLogStreamOpen_2(gl_logHandle, &stream_name, NULL, 0, SA_TIME_ONE_SECOND, &gl_logStreamHandle); if (error != SA_AIS_OK) { syslog(LOG_INFO, "saLogStreamOpen_2 FAILED: %u", error); - if (saLogFinalize(logHandle) != SA_AIS_OK) + if (saLogFinalize(gl_logHandle) != SA_AIS_OK) syslog(LOG_INFO, "saLogFinalize FAILED: %u", error); goto done; } - initialized = 1; + gl_initialized = 1; } logRecord.logTimeStamp = SA_TIME_UNKNOWN; @@ -65,7 +90,7 @@ void saflog(int priority, const SaNameT logRecord.logBuffer = &logBuffer; logBuffer.logBuf = (SaUint8T *)str; - error = saLogWriteLogAsync(logStreamHandle, 0, 0, &logRecord); + error = saLogWriteLogAsync(gl_logStreamHandle, 0, 0, &logRecord); done: /* fallback to syslog at ANY error, syslog prio same as saflog severity */ ------------------------------------------------------------------------------ Managing the Performance of Cloud-Based Applications Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. Read the Whitepaper. http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk _______________________________________________ Opensaf-devel mailing list Opensaf-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/opensaf-devel