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

Re: [lvm-devel] [RFC PATCH] Reduce noise about missing devices.



Hi,

Petr Rockai <prockai redhat com> writes:
> Another possible approach (one that I would probably prefer) is to add a
> global log_error_once to log.c that would maintain a dm_hash_table of
> error messages and downgrade already-reported errors to log_debug or
> log_very_verbose automatically. A few error paths could use this.
here's a patch that implements this. I think this is fairly reasonable
and could be checked in. Some minor function renaming might be
necessary.

Yours,
    Petr.

Wed Apr 28 17:16:23 CEST 2010  Petr Rockai <me mornfall net>
  * Provide log_error_once and use it in couple places.
diff -rN -u -p old-upstream/lib/commands/toolcontext.c new-upstream/lib/commands/toolcontext.c
--- old-upstream/lib/commands/toolcontext.c	2010-04-28 17:16:27.000000000 +0200
+++ new-upstream/lib/commands/toolcontext.c	2010-04-28 17:16:27.000000000 +0200
@@ -194,6 +194,7 @@ static void _init_logging(struct cmd_con
 #ifdef DEVMAPPER_SUPPORT
 	dm_log_with_errno_init(print_log);
 #endif
+	reset_log_duplicated();
 }
 
 static int _process_config(struct cmd_context *cmd)
diff -rN -u -p old-upstream/lib/device/dev-io.c new-upstream/lib/device/dev-io.c
--- old-upstream/lib/device/dev-io.c	2010-04-28 17:16:27.000000000 +0200
+++ new-upstream/lib/device/dev-io.c	2010-04-28 17:16:27.000000000 +0200
@@ -95,12 +95,12 @@ static int _io(struct device_area *where
 		while ((n < 0) && ((errno == EINTR) || (errno == EAGAIN)));
 
 		if (n < 0)
-			log_error("%s: %s failed after %" PRIu64 " of %" PRIu64
-				  " at %" PRIu64 ": %s", dev_name(where->dev),
-				  should_write ? "write" : "read",
-				  (uint64_t) total,
-				  (uint64_t) where->size,
-				  (uint64_t) where->start, strerror(errno));
+			log_error_once("%s: %s failed after %" PRIu64 " of %" PRIu64
+				       " at %" PRIu64 ": %s", dev_name(where->dev),
+				       should_write ? "write" : "read",
+				       (uint64_t) total,
+				       (uint64_t) where->size,
+				       (uint64_t) where->start, strerror(errno));
 
 		if (n <= 0)
 			break;
diff -rN -u -p old-upstream/lib/format_text/import_vsn1.c new-upstream/lib/format_text/import_vsn1.c
--- old-upstream/lib/format_text/import_vsn1.c	2010-04-28 17:16:27.000000000 +0200
+++ new-upstream/lib/format_text/import_vsn1.c	2010-04-28 17:16:27.000000000 +0200
@@ -198,7 +198,7 @@ static int _read_pv(struct format_instan
 		if (!id_write_format(&pv->id, buffer, sizeof(buffer)))
 			buffer[0] = '\0';
 		if (report_missing_devices)
-			log_error("Couldn't find device with uuid %s.", buffer);
+			log_error_once("Couldn't find device with uuid %s.", buffer);
 		else
 			log_very_verbose("Couldn't find device with uuid %s.", buffer);
 	}
diff -rN -u -p old-upstream/lib/log/log.c new-upstream/lib/log/log.c
--- old-upstream/lib/log/log.c	2010-04-28 17:16:27.000000000 +0200
+++ new-upstream/lib/log/log.c	2010-04-28 17:16:27.000000000 +0200
@@ -169,6 +169,14 @@ const char *stored_errmsg(void)
 	return _lvm_errmsg ? : "";
 }
 
+static struct dm_hash_table *_duplicated = NULL;
+
+void reset_log_duplicated(void) {
+	if (_duplicated)
+		dm_hash_destroy(_duplicated);
+	_duplicated = NULL;
+}
+
 void print_log(int level, const char *file, int line, int dm_errno,
 	       const char *format, ...)
 {
@@ -179,9 +187,10 @@ void print_log(int level, const char *fi
 	const char *trformat;		/* Translated format string */
 	char *newbuf;
 	int use_stderr = level & _LOG_STDERR;
+	int log_once = level & _LOG_ONCE;
 	int fatal_internal_error = 0;
 
-	level &= ~_LOG_STDERR;
+	level &= ~(_LOG_STDERR|_LOG_ONCE);
 
 	if (_abort_on_internal_errors &&
 	    !strncmp(format, INTERNAL_ERROR,
@@ -203,7 +212,9 @@ void print_log(int level, const char *fi
 	if (dm_errno && !_lvm_errno)
 		_lvm_errno = dm_errno;
 
-	if (_lvm2_log_fn || (_store_errmsg && (level <= _LOG_ERR))) {
+	if (_lvm2_log_fn ||
+	    (_store_errmsg && (level <= _LOG_ERR)) ||
+	    log_once) {
 		va_start(ap, format);
 		n = vsnprintf(buf2, sizeof(buf2) - 1, trformat, ap);
 		va_end(ap);
@@ -229,6 +240,16 @@ void print_log(int level, const char *fi
 		}
 	}
 
+	if (log_once) {
+		if (!_duplicated)
+			_duplicated = dm_hash_create(128);
+		if (_duplicated) {
+			if (dm_hash_lookup(_duplicated, message))
+				level = _LOG_NOTICE;
+			dm_hash_insert(_duplicated, message, (void*)1);
+		}
+	}
+
 	if (_lvm2_log_fn) {
 		_lvm2_log_fn(level, file, line, 0, message);
 		if (fatal_internal_error)
diff -rN -u -p old-upstream/lib/log/log.h new-upstream/lib/log/log.h
--- old-upstream/lib/log/log.h	2010-04-28 17:16:27.000000000 +0200
+++ new-upstream/lib/log/log.h	2010-04-28 17:16:27.000000000 +0200
@@ -47,6 +47,7 @@
 
 #define _LOG_STDERR 128 /* force things to go to stderr, even if loglevel
 			   would make them go to stdout */
+#define _LOG_ONCE 256 /* downgrade to NOTICE if this has been already logged */
 #define _LOG_DEBUG 7
 #define _LOG_INFO 6
 #define _LOG_NOTICE 5
@@ -62,6 +63,7 @@
 #define log_warn_suppress(s, x...) LOG_LINE(s ? _LOG_NOTICE : _LOG_WARN | _LOG_STDERR, x)
 #define log_err(x...) LOG_LINE_WITH_ERRNO(_LOG_ERR, EUNCLASSIFIED, x)
 #define log_err_suppress(s, x...) LOG_LINE_WITH_ERRNO(s ? _LOG_NOTICE : _LOG_ERR, EUNCLASSIFIED, x)
+#define log_err_once(x...) LOG_LINE_WITH_ERRNO(_LOG_ERR | _LOG_ONCE, EUNCLASSIFIED, x)
 #define log_fatal(x...) LOG_LINE_WITH_ERRNO(_LOG_FATAL, EUNCLASSIFIED, x)
 
 #define stack log_debug("<backtrace>")	/* Backtrace on error */
@@ -70,6 +72,7 @@
 #define log_print(args...) LOG_LINE(_LOG_WARN, args)
 #define log_error(args...) log_err(args)
 #define log_error_suppress(s, args...) log_err_suppress(s, args)
+#define log_error_once(args...) log_err_once(args)
 #define log_errno(args...) LOG_LINE_WITH_ERRNO(_LOG_ERR, args)
 
 /* System call equivalents */
diff -rN -u -p old-upstream/lib/log/lvm-logging.h new-upstream/lib/log/lvm-logging.h
--- old-upstream/lib/log/lvm-logging.h	2010-04-28 17:16:27.000000000 +0200
+++ new-upstream/lib/log/lvm-logging.h	2010-04-28 17:16:27.000000000 +0200
@@ -23,6 +23,9 @@ void print_log(int level, const char *fi
 #define LOG_LINE(l, x...) \
     print_log(l, __FILE__, __LINE__ , 0, ## x)
 
+#define LOG_LINE_ONCE(l, x...) \
+    print_log_once(l, __FILE__, __LINE__ , 0, ## x)
+
 #define LOG_LINE_WITH_ERRNO(l, e, x...) \
     print_log(l, __FILE__, __LINE__ , e, ## x)
 
@@ -43,6 +46,7 @@ void init_abort_on_internal_errors(int f
 
 void fin_log(void);
 void release_log_memory(void);
+void reset_log_duplicated(void);
 
 void init_syslog(int facility);
 void fin_syslog(void);

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