[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [lvm-devel] [PATCH] In dmeventd, bridge LVM error log output to syslog.



Petr Rockai <prockai redhat com> writes:
>> I'd prefer to see a patch that adds a middle category, taking some of
>> the DEBUG messages and logging them as ERR or WARN.
>
> I will submit a patch later that changes the commandline options, so we
> can optionally enable the DEBUG logs to syslog with a -d-style option to
> dmeventd. For users, it doesn't make any sense to be logging at the most
> verbose level, to syslog.
Since Alasdair said this can't go in without the commandline options,
there's a patch that does both.

diff -rN -u -p old-upstream/daemons/dmeventd/dmeventd.c new-upstream/daemons/dmeventd/dmeventd.c
--- old-upstream/daemons/dmeventd/dmeventd.c	2010-05-12 17:12:32.000000000 +0200
+++ new-upstream/daemons/dmeventd/dmeventd.c	2010-05-12 17:12:32.000000000 +0200
@@ -54,7 +54,6 @@
 
 static volatile sig_atomic_t _exit_now = 0;	/* set to '1' when signal is given to exit */
 static volatile sig_atomic_t _thread_registries_empty = 1;	/* registries are empty initially */
-static int _debug = 0;
 
 /* List (un)link macros. */
 #define	LINK(x, head)		dm_list_add(head, &(x)->list)
@@ -98,6 +97,9 @@ static pthread_mutex_t _global_mutex;
 
 #define DEBUGLOG(fmt, args...) _debuglog(fmt, ## args)
 
+int dmeventd_debug = 0;
+static int _foreground = 0;
+
 /* Data kept about a DSO. */
 struct dso_data {
 	struct dm_list list;
@@ -204,7 +206,7 @@ static void _debuglog(const char *fmt, .
         time_t P;
         va_list ap;
  
-        if (!_debug)
+        if (!_foreground)
                 return;
  
         va_start(ap,fmt);
@@ -1666,7 +1668,8 @@ static void usage(char *prog, FILE *file
 	fprintf(file, "\n");
 	fprintf(file, "   -V       Show version of dmeventd\n");
 	fprintf(file, "   -h       Show this help information\n");
-	fprintf(file, "   -d       Don't fork, run in the foreground\n");
+	fprintf(file, "   -f       Don't fork, run in the foreground\n");
+	fprintf(file, "   -d       Log debug messages to syslog (-d, -dd, -ddd)\n");
 	fprintf(file, "\n");
 }
 
@@ -1680,7 +1683,7 @@ int main(int argc, char *argv[])
 	opterr = 0;
 	optind = 0;
 
-	while ((opt = getopt(argc, argv, "?hVd")) != EOF) {
+	while ((opt = getopt(argc, argv, "?fhVd")) != EOF) {
 		switch (opt) {
 		case 'h':
 			usage(argv[0], stdout);
@@ -1688,8 +1691,11 @@ int main(int argc, char *argv[])
 		case '?':
 			usage(argv[0], stderr);
 			exit(0);
+		case 'f':
+			_foreground++;
+			break;
 		case 'd':
-			_debug++;
+			dmeventd_debug++;
 			break;
 		case 'V':
 			printf("dmeventd version: %s\n", DM_LIB_VERSION);
@@ -1706,7 +1712,7 @@ int main(int argc, char *argv[])
 	if (setenv("LANG", "C", 1))
 		perror("Cannot set LANG to C");
 
-	if (!_debug)
+	if (!_foreground)
 		_daemonize();
 
 	openlog("dmeventd", LOG_PID, LOG_DAEMON);
@@ -1738,7 +1744,7 @@ int main(int argc, char *argv[])
 		exit(EXIT_FIFO_FAILURE);
 
 	/* Signal parent, letting them know we are ready to go. */
-	if (!_debug)
+	if (!_foreground)
 		kill(getppid(), SIGTERM);
 	syslog(LOG_NOTICE, "dmeventd ready for processing.");
 
diff -rN -u -p old-upstream/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c new-upstream/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
--- old-upstream/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c	2010-05-12 17:12:32.000000000 +0200
+++ new-upstream/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c	2010-05-12 17:12:32.000000000 +0200
@@ -23,6 +23,8 @@
 #include <pthread.h>
 #include <syslog.h>
 
+extern int dmeventd_debug;
+
 /*
  * register_device() is called first and performs initialisation.
  * Only one device may be registered or unregistered at a time.
@@ -54,9 +56,17 @@ static void _log_fn(int level,
 {
 	switch (level) {
 	case _LOG_DEBUG:
+		if (dmeventd_debug >= 3)
+			syslog(LOG_DEBUG, "%s", message);
+		break;
 	case _LOG_INFO:
+		if (dmeventd_debug >= 2)
+			syslog(LOG_INFO, "%s", message);
+		break;
 	case _LOG_NOTICE:
-		break; /* TODO */
+		if (dmeventd_debug >= 1)
+			syslog(LOG_NOTICE, "%s", message);
+		break;
 	case _LOG_WARN:
 		syslog(LOG_WARNING, "%s", message);
 		break;
diff -rN -u -p old-upstream/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c new-upstream/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
--- old-upstream/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c	2010-05-12 17:12:32.000000000 +0200
+++ new-upstream/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c	2010-05-12 17:12:32.000000000 +0200
@@ -160,7 +160,8 @@ static int _remove_failed_devices(const 
 
 	r = dmeventd_lvm2_run(cmd_str);
 
-	syslog(LOG_INFO, "Repair of mirrored LV %s/%s %s.", vg, lv, (r == ECMD_PROCESSED) ? "finished successfully" : "failed");
+	syslog(LOG_INFO, "Repair of mirrored LV %s/%s %s.", vg, lv,
+	       (r == ECMD_PROCESSED) ? "finished successfully" : "failed");
 
 	return (r == ECMD_PROCESSED) ? 0 : -1;
 }
diff -rN -u -p old-upstream/test/test-utils.sh new-upstream/test/test-utils.sh
--- old-upstream/test/test-utils.sh	2010-05-12 17:12:32.000000000 +0200
+++ new-upstream/test/test-utils.sh	2010-05-12 17:12:32.000000000 +0200
@@ -87,9 +87,8 @@ prepare_dmeventd() {
 
 	trap_teardown
 
-	dmeventd -d &
+	dmeventd -f &
 	LOCAL_DMEVENTD="$!"
-	strace -p $LOCAL_DMEVENTD &
 }
 
 prepare_testroot() {

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]