Skip to content

Commit

Permalink
logging: Make blackbox configurable
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Friesse <jfriesse@redhat.com>
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
  • Loading branch information
jfriesse committed Jan 30, 2018
1 parent df9d7d6 commit 79dba9c
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 11 deletions.
40 changes: 39 additions & 1 deletion exec/logconfig.c
Expand Up @@ -127,7 +127,7 @@ static int insert_into_buffer(
}

/*
* format set is the only global specific option that
* format set is global specific option that
* doesn't apply at system/subsystem level.
*/
static int corosync_main_config_format_set (
Expand Down Expand Up @@ -228,6 +228,40 @@ static int corosync_main_config_format_set (
return (-1);
}

/*
* blackbox is another global specific option that
* doesn't apply at system/subsystem level.
*/
static int corosync_main_config_blackbox_set (
const char **error_string)
{
const char *error_reason;
char *value = NULL;

if (map_get_string("logging.blackbox", &value) == CS_OK) {
if (strcmp (value, "on") == 0) {
(void)logsys_blackbox_set(QB_TRUE);
} else if (strcmp (value, "off") == 0) {
(void)logsys_blackbox_set(QB_FALSE);
} else {
error_reason = "unknown value for blackbox";
free(value);
goto parse_error;
}

free(value);
} else {
(void)logsys_blackbox_set(QB_TRUE);
}

return (0);

parse_error:
*error_string = error_reason;

return (-1);
}

static int corosync_main_config_log_destination_set (
const char *path,
const char *key,
Expand Down Expand Up @@ -522,6 +556,10 @@ static int corosync_main_config_read_logging (
goto parse_error;
}

if (corosync_main_config_blackbox_set(&error_reason) < 0) {
goto parse_error;
}

if (corosync_main_config_set ("logging", NULL, &error_reason) < 0) {
goto parse_error;
}
Expand Down
44 changes: 34 additions & 10 deletions exec/logsys.c
Expand Up @@ -118,6 +118,8 @@ static char *format_buffer=NULL;

static int logsys_thread_started = 0;

static int logsys_blackbox_enabled = 1;

static int _logsys_config_subsys_get_unlocked (const char *subsys)
{
unsigned int i;
Expand Down Expand Up @@ -308,7 +310,6 @@ int _logsys_system_setup(
int i;
int32_t fidx;
char tempsubsys[LOGSYS_MAX_SUBSYS_NAMELEN];
int blackbox_enable_res;

if ((mainsystem == NULL) ||
(strlen(mainsystem) >= LOGSYS_MAX_SUBSYS_NAMELEN)) {
Expand Down Expand Up @@ -370,7 +371,12 @@ int _logsys_system_setup(
QB_LOG_FILTER_FILE, "*", LOG_TRACE);
qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_SIZE, IPC_LOGSYS_SIZE);
qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_THREADED, QB_FALSE);
blackbox_enable_res = qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_TRUE);

/*
* Blackbox is disabled at the init and enabled later based
* on config (logging.blackbox) value.
*/
qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_FALSE);

if (logsys_format_set(NULL) == -1) {
return -1;
Expand All @@ -396,14 +402,6 @@ int _logsys_system_setup(
}
}

if (blackbox_enable_res < 0) {
LOGSYS_PERROR (-blackbox_enable_res, LOGSYS_LEVEL_WARNING,
"Unable to initialize log flight recorder. "\
"The most common cause of this error is " \
"not enough space on /dev/shm. Corosync will continue work, " \
"but blackbox will not be available");
}

pthread_mutex_unlock (&logsys_config_mutex);

return (0);
Expand Down Expand Up @@ -766,10 +764,26 @@ static void _logsys_config_apply_per_subsys(int32_t s)
logsys_loggers[s].dirty = QB_FALSE;
}

static void _logsys_config_apply_blackbox(void) {
int blackbox_enable_res;

blackbox_enable_res = qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, logsys_blackbox_enabled);

if (blackbox_enable_res < 0) {
LOGSYS_PERROR (-blackbox_enable_res, LOGSYS_LEVEL_WARNING,
"Unable to initialize log flight recorder. "\
"The most common cause of this error is " \
"not enough space on /dev/shm. Corosync will continue work, " \
"but blackbox will not be available");
}
}

void logsys_config_apply(void)
{
int32_t s;

_logsys_config_apply_blackbox();

for (s = 0; s <= LOGSYS_MAX_SUBSYS_COUNT; s++) {
if (strcmp(logsys_loggers[s].subsys, "") == 0) {
continue;
Expand Down Expand Up @@ -837,3 +851,13 @@ int logsys_thread_start (void)

return (0);
}

void logsys_blackbox_set(int enable)
{

pthread_mutex_lock (&logsys_config_mutex);

logsys_blackbox_enabled = enable;

pthread_mutex_unlock (&logsys_config_mutex);
}
1 change: 1 addition & 0 deletions exec/main.c
Expand Up @@ -225,6 +225,7 @@ static void corosync_blackbox_write_to_file (void)

if ((res = qb_log_blackbox_write_to_file(fname)) < 0) {
LOGSYS_PERROR(-res, LOGSYS_LEVEL_ERROR, "Can't store blackbox file");
return ;
}
snprintf(fdata_fname, sizeof(fdata_fname), "%s/fdata", get_run_dir());
unlink(fdata_fname);
Expand Down
2 changes: 2 additions & 0 deletions include/corosync/logsys.h
Expand Up @@ -256,6 +256,8 @@ extern int _logsys_subsys_create (const char *subsys, const char *filename);
*/
extern int logsys_thread_start (void);

extern void logsys_blackbox_set(int enable);

/**
* @brief logsys_subsys_id
*/
Expand Down
6 changes: 6 additions & 0 deletions man/corosync.conf.5
Expand Up @@ -533,6 +533,12 @@ This specifies that the code function name should be printed.

The default is off.

.TP
blackbox
This specifies that blackbox functionality should be enabled.

The defualt is on.

.PP
The following options are valid both for top level logging directive
and they can be overridden in logger_subsys entries.
Expand Down

0 comments on commit 79dba9c

Please sign in to comment.