Blame SOURCES/bz1536219-1-logging-Make-blackbox-configurable.patch

b69418
From 8af39f66e56e319b6b93804c0400e6e29737a90f Mon Sep 17 00:00:00 2001
b69418
From: Jan Friesse <jfriesse@redhat.com>
b69418
Date: Mon, 22 Jan 2018 10:42:25 +0100
b69418
Subject: [PATCH] logging: Make blackbox configurable
b69418
b69418
Signed-off-by: Jan Friesse <jfriesse@redhat.com>
b69418
Reviewed-by: Christine Caulfield <ccaulfie@redhat.com>
b69418
(cherry picked from commit 79dba9c51f60c603673f97afd07fa506fd9ae9a7)
b69418
---
b69418
 exec/logconfig.c          |   40 +++++++++++++++++++++++++++++++++++++++-
b69418
 exec/logsys.c             |   44 ++++++++++++++++++++++++++++++++++----------
b69418
 exec/main.c               |    1 +
b69418
 include/corosync/logsys.h |    2 ++
b69418
 man/corosync.conf.5       |    6 ++++++
b69418
 5 files changed, 82 insertions(+), 11 deletions(-)
b69418
b69418
diff --git a/exec/logconfig.c b/exec/logconfig.c
b69418
index 6d0bed6..ccbffae 100644
b69418
--- a/exec/logconfig.c
b69418
+++ b/exec/logconfig.c
b69418
@@ -127,7 +127,7 @@ static int insert_into_buffer(
b69418
 }
b69418
 
b69418
 /*
b69418
- * format set is the only global specific option that
b69418
+ * format set is global specific option that
b69418
  * doesn't apply at system/subsystem level.
b69418
  */
b69418
 static int corosync_main_config_format_set (
b69418
@@ -228,6 +228,40 @@ parse_error:
b69418
 	return (-1);
b69418
 }
b69418
 
b69418
+/*
b69418
+ * blackbox is another global specific option that
b69418
+ * doesn't apply at system/subsystem level.
b69418
+ */
b69418
+static int corosync_main_config_blackbox_set (
b69418
+	const char **error_string)
b69418
+{
b69418
+	const char *error_reason;
b69418
+	char *value = NULL;
b69418
+
b69418
+	if (map_get_string("logging.blackbox", &value) == CS_OK) {
b69418
+		if (strcmp (value, "on") == 0) {
b69418
+			(void)logsys_blackbox_set(QB_TRUE);
b69418
+		} else if (strcmp (value, "off") == 0) {
b69418
+			(void)logsys_blackbox_set(QB_FALSE);
b69418
+		} else {
b69418
+			error_reason = "unknown value for blackbox";
b69418
+			free(value);
b69418
+			goto parse_error;
b69418
+		}
b69418
+
b69418
+		free(value);
b69418
+	} else {
b69418
+		(void)logsys_blackbox_set(QB_TRUE);
b69418
+	}
b69418
+
b69418
+	return (0);
b69418
+
b69418
+parse_error:
b69418
+	*error_string = error_reason;
b69418
+
b69418
+	return (-1);
b69418
+}
b69418
+
b69418
 static int corosync_main_config_log_destination_set (
b69418
 	const char *path,
b69418
 	const char *key,
b69418
@@ -522,6 +556,10 @@ static int corosync_main_config_read_logging (
b69418
 		goto parse_error;
b69418
 	}
b69418
 
b69418
+	if (corosync_main_config_blackbox_set(&error_reason) < 0) {
b69418
+		goto parse_error;
b69418
+	}
b69418
+
b69418
 	if (corosync_main_config_set ("logging", NULL, &error_reason) < 0) {
b69418
 		goto parse_error;
b69418
 	}
b69418
diff --git a/exec/logsys.c b/exec/logsys.c
b69418
index 6b4995d..a38cc5e 100644
b69418
--- a/exec/logsys.c
b69418
+++ b/exec/logsys.c
b69418
@@ -119,6 +119,8 @@ static char *format_buffer=NULL;
b69418
 
b69418
 static int logsys_thread_started = 0;
b69418
 
b69418
+static int logsys_blackbox_enabled = 1;
b69418
+
b69418
 static int _logsys_config_subsys_get_unlocked (const char *subsys)
b69418
 {
b69418
 	unsigned int i;
b69418
@@ -309,7 +311,6 @@ int _logsys_system_setup(
b69418
 	int i;
b69418
 	int32_t fidx;
b69418
 	char tempsubsys[LOGSYS_MAX_SUBSYS_NAMELEN];
b69418
-	int blackbox_enable_res;
b69418
 
b69418
 	if ((mainsystem == NULL) ||
b69418
 	    (strlen(mainsystem) >= LOGSYS_MAX_SUBSYS_NAMELEN)) {
b69418
@@ -371,7 +372,12 @@ int _logsys_system_setup(
b69418
 			  QB_LOG_FILTER_FILE, "*", LOG_TRACE);
b69418
 	qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_SIZE, IPC_LOGSYS_SIZE);
b69418
 	qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_THREADED, QB_FALSE);
b69418
-	blackbox_enable_res = qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_TRUE);
b69418
+
b69418
+	/*
b69418
+	 * Blackbox is disabled at the init and enabled later based
b69418
+	 * on config (logging.blackbox) value.
b69418
+	 */
b69418
+	qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, QB_FALSE);
b69418
 
b69418
 	if (logsys_format_set(NULL) == -1) {
b69418
 		return -1;
b69418
@@ -397,14 +403,6 @@ int _logsys_system_setup(
b69418
 		}
b69418
 	}
b69418
 
b69418
-	if (blackbox_enable_res < 0) {
b69418
-		LOGSYS_PERROR (-blackbox_enable_res, LOGSYS_LEVEL_WARNING,
b69418
-		    "Unable to initialize log flight recorder. "\
b69418
-		    "The most common cause of this error is " \
b69418
-		    "not enough space on /dev/shm. Corosync will continue work, " \
b69418
-		    "but blackbox will not be available");
b69418
-	}
b69418
-
b69418
 	pthread_mutex_unlock (&logsys_config_mutex);
b69418
 
b69418
 	return (0);
b69418
@@ -767,10 +765,26 @@ static void _logsys_config_apply_per_subsys(int32_t s)
b69418
 	logsys_loggers[s].dirty = QB_FALSE;
b69418
 }
b69418
 
b69418
+static void _logsys_config_apply_blackbox(void) {
b69418
+	int blackbox_enable_res;
b69418
+
b69418
+	blackbox_enable_res = qb_log_ctl(QB_LOG_BLACKBOX, QB_LOG_CONF_ENABLED, logsys_blackbox_enabled);
b69418
+
b69418
+	if (blackbox_enable_res < 0) {
b69418
+		LOGSYS_PERROR (-blackbox_enable_res, LOGSYS_LEVEL_WARNING,
b69418
+		    "Unable to initialize log flight recorder. "\
b69418
+		    "The most common cause of this error is " \
b69418
+		    "not enough space on /dev/shm. Corosync will continue work, " \
b69418
+		    "but blackbox will not be available");
b69418
+	}
b69418
+}
b69418
+
b69418
 void logsys_config_apply(void)
b69418
 {
b69418
 	int32_t s;
b69418
 
b69418
+	_logsys_config_apply_blackbox();
b69418
+
b69418
 	for (s = 0; s <= LOGSYS_MAX_SUBSYS_COUNT; s++) {
b69418
 		if (strcmp(logsys_loggers[s].subsys, "") == 0) {
b69418
 			continue;
b69418
@@ -838,3 +852,13 @@ int logsys_thread_start (void)
b69418
 
b69418
 	return (0);
b69418
 }
b69418
+
b69418
+void logsys_blackbox_set(int enable)
b69418
+{
b69418
+
b69418
+	pthread_mutex_lock (&logsys_config_mutex);
b69418
+
b69418
+	logsys_blackbox_enabled = enable;
b69418
+
b69418
+	pthread_mutex_unlock (&logsys_config_mutex);
b69418
+}
b69418
diff --git a/exec/main.c b/exec/main.c
b69418
index 7fe24e2..cd587dc 100644
b69418
--- a/exec/main.c
b69418
+++ b/exec/main.c
b69418
@@ -220,6 +220,7 @@ static void corosync_blackbox_write_to_file (void)
b69418
 
b69418
 	if ((res = qb_log_blackbox_write_to_file(fname)) < 0) {
b69418
 		LOGSYS_PERROR(-res, LOGSYS_LEVEL_ERROR, "Can't store blackbox file");
b69418
+		return ;
b69418
 	}
b69418
 	snprintf(fdata_fname, sizeof(fdata_fname), "%s/fdata", get_run_dir());
b69418
 	unlink(fdata_fname);
b69418
diff --git a/include/corosync/logsys.h b/include/corosync/logsys.h
b69418
index 0b2fbff..ec38d2c 100644
b69418
--- a/include/corosync/logsys.h
b69418
+++ b/include/corosync/logsys.h
b69418
@@ -256,6 +256,8 @@ extern int _logsys_subsys_create (const char *subsys, const char *filename);
b69418
  */
b69418
 extern int logsys_thread_start (void);
b69418
 
b69418
+extern void logsys_blackbox_set(int enable);
b69418
+
b69418
 /**
b69418
  * @brief logsys_subsys_id
b69418
  */
b69418
diff --git a/man/corosync.conf.5 b/man/corosync.conf.5
b69418
index 0639028..68103d0 100644
b69418
--- a/man/corosync.conf.5
b69418
+++ b/man/corosync.conf.5
b69418
@@ -539,6 +539,12 @@ This specifies that the code function name should be printed.
b69418
 
b69418
 The default is off.
b69418
 
b69418
+.TP
b69418
+blackbox
b69418
+This specifies that blackbox functionality should be enabled.
b69418
+
b69418
+The defualt is on.
b69418
+
b69418
 .PP
b69418
 The following options are valid both for top level logging directive
b69418
 and they can be overridden in logger_subsys entries.
b69418
-- 
b69418
1.7.1
b69418