mirror of
git://sourceware.org/git/lvm2.git
synced 2025-02-28 05:57:49 +03:00
Suppress duplicate error messages about read failures and missing devices.
This commit is contained in:
parent
20399b50d6
commit
9d3faa4753
@ -194,6 +194,7 @@ static void _init_logging(struct cmd_context *cmd)
|
||||
#ifdef DEVMAPPER_SUPPORT
|
||||
dm_log_with_errno_init(print_log);
|
||||
#endif
|
||||
reset_log_duplicated();
|
||||
}
|
||||
|
||||
static int _process_config(struct cmd_context *cmd)
|
||||
@ -1361,6 +1362,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
|
||||
|
||||
release_log_memory();
|
||||
activation_exit();
|
||||
reset_log_duplicated();
|
||||
fin_log();
|
||||
fin_syslog();
|
||||
reset_lvm_errno(0);
|
||||
|
@ -95,12 +95,12 @@ static int _io(struct device_area *where, void *buffer, int should_write)
|
||||
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;
|
||||
|
@ -198,7 +198,7 @@ static int _read_pv(struct format_instance *fid, struct dm_pool *mem,
|
||||
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);
|
||||
}
|
||||
|
@ -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 *file, int line, int dm_errno,
|
||||
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 *file, int line, int dm_errno,
|
||||
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 *file, int line, int dm_errno,
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -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 */
|
||||
|
@ -43,6 +43,7 @@ void init_abort_on_internal_errors(int fatal);
|
||||
|
||||
void fin_log(void);
|
||||
void release_log_memory(void);
|
||||
void reset_log_duplicated(void);
|
||||
|
||||
void init_syslog(int facility);
|
||||
void fin_syslog(void);
|
||||
|
@ -1087,6 +1087,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
|
||||
dm_pool_empty(cmd->mem);
|
||||
|
||||
reset_lvm_errno(1);
|
||||
reset_log_duplicated();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user