master - cleanup: static with _
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=903e9af1b2c197...
Commit: 903e9af1b2c1972a897b7dd61e6e463a03cad648
Parent: e261af52eb26c22aebd62cdbd8bb79c195274ee9
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Thu Oct 8 11:59:11 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:16:56 2015 +0200
cleanup: static with _
Document ? is printing to stderr.
---
daemons/dmeventd/dmeventd.c | 17 +++++++++--------
1 files changed, 9 insertions(+), 8 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index e34c4c1..f775fb9 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -931,7 +931,7 @@ static int _lookup_symbol(void *dl, void **symbol, const char *name)
return 0;
}
-static int lookup_symbols(void *dl, struct dso_data *data)
+static int _lookup_symbols(void *dl, struct dso_data *data)
{
return _lookup_symbol(dl, (void *) &data->process_event,
"process_event") &&
@@ -962,7 +962,7 @@ static struct dso_data *_load_dso(struct message_data *data)
return NULL;
}
- if (!(lookup_symbols(dl, ret))) {
+ if (!(_lookup_symbols(dl, ret))) {
_free_dso_data(ret);
dlclose(dl);
return NULL;
@@ -1931,7 +1931,7 @@ static int _reinstate_registrations(struct dm_event_fifos *fifos)
return 1;
}
-static void restart(void)
+static void _restart_dmeventd(void)
{
struct dm_event_fifos fifos = {
.server = -1,
@@ -2048,13 +2048,14 @@ bad:
exit(EXIT_FAILURE);
}
-static void usage(char *prog, FILE *file)
+static void _usage(char *prog, FILE *file)
{
fprintf(file, "Usage:\n"
"%s [-d [-d [-d]]] [-f] [-h] [-R] [-V] [-?]\n\n"
" -d Log debug messages to syslog (-d, -dd, -ddd)\n"
" -f Don't fork, run in the foreground\n"
- " -h -? Show this help information\n"
+ " -h Show this help information\n"
+ " -? Show this help information on stderr\n"
" -R Restart dmeventd\n"
" -V Show version of dmeventd\n\n", prog);
}
@@ -2077,10 +2078,10 @@ int main(int argc, char *argv[])
while ((opt = getopt(argc, argv, "?fhVdR")) != EOF) {
switch (opt) {
case 'h':
- usage(argv[0], stdout);
+ _usage(argv[0], stdout);
exit(EXIT_SUCCESS);
case '?':
- usage(argv[0], stderr);
+ _usage(argv[0], stderr);
exit(EXIT_SUCCESS);
case 'R':
_restart++;
@@ -2106,7 +2107,7 @@ int main(int argc, char *argv[])
perror("Cannot set LC_ALL to C");
if (_restart)
- restart();
+ _restart_dmeventd();
#ifdef __linux__
_systemd_activation = _systemd_handover(&fifos);
7 years, 8 months
master - dmeventd: handle snapshot overflow
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e261af52eb26c2...
Commit: e261af52eb26c22aebd62cdbd8bb79c195274ee9
Parent: 3f03d46fc13be2274b3c29d4fc97a3306bc33eda
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Oct 9 21:41:50 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:15:44 2015 +0200
dmeventd: handle snapshot overflow
When snapshot reports overflow, handle it in the same way as Invalid.
Until better ideas are implemented.
---
WHATS_NEW_DM | 1 +
.../dmeventd/plugins/snapshot/dmeventd_snapshot.c | 4 ++--
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index ff4ac22..efe8b37 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.110 -
======================================
+ Dmeventd handles snapshot overflow for now equally as invalid.
Convert dmeventd to use common logging macro system from libdm.
Return -ENOMEM when device registration fails instead of 0 (=success).
Enforce writethrough mode for cleaner policy.
diff --git a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
index ffe6666..ae8e308 100644
--- a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
+++ b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
@@ -150,7 +150,7 @@ void process_event(struct dm_task *dmt,
if (!dm_get_status_snapshot(state->mem, params, &status))
goto out;
- if (status->invalid) {
+ if (status->invalid || status->overflow) {
struct dm_info info;
log_error("Snapshot %s is lost.", device);
if (dm_task_get_info(dmt, &info)) {
@@ -170,7 +170,7 @@ void process_event(struct dm_task *dmt,
* If the snapshot has been invalidated or we failed to parse
* the status string. Report the full status string to syslog.
*/
- if (status->invalid || !status->total_sectors) {
+ if (status->invalid || status->overflow || !status->total_sectors) {
log_error("Snapshot %s changed state to: %s.", device, params);
state->percent_check = 0;
goto out;
7 years, 8 months
master - man: dmeventd update
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=3f03d46fc13be2...
Commit: 3f03d46fc13be2274b3c29d4fc97a3306bc33eda
Parent: 0e2721030857088803bc71ccc27644b7b95241ca
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Mon Oct 12 11:35:53 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:15:43 2015 +0200
man: dmeventd update
---
man/dmeventd.8.in | 92 +++++++++++++++++++++++++++++++++++++---------------
1 files changed, 65 insertions(+), 27 deletions(-)
diff --git a/man/dmeventd.8.in b/man/dmeventd.8.in
index 77bbafb..15e003b 100644
--- a/man/dmeventd.8.in
+++ b/man/dmeventd.8.in
@@ -1,7 +1,11 @@
.TH DMEVENTD 8 "DM TOOLS #VERSION#" "Red Hat Inc" \" -*- nroff -*-
+.
.SH NAME
+.
dmeventd \(em Device-mapper event daemon
+.
.SH SYNOPSIS
+.
.B dmeventd
.RB [ \-d
.RB [ \-d
@@ -11,33 +15,53 @@ dmeventd \(em Device-mapper event daemon
.RB [ \-R ]
.RB [ \-V ]
.RB [ \-? ]
+.
.SH DESCRIPTION
+.
dmeventd is the event monitoring daemon for device-mapper devices.
Library plugins can register and carry out actions triggered when
particular events occur.
-.SH
-LVM PLUGINS
-.TP
-.I Mirror
-Attempts to handle device failure automatically. See \fBlvm.conf\fP(5).
-.TP
-.I Raid
-Attempts to handle device failure automatically. See \fBlvm.conf\fP(5).
-.TP
-.I Snapshot
+.
+.SH LVM PLUGINS
+.
+.HP
+.IR Mirror
+.br
+Attempts to handle device failure automatically. See
+.BR lvm.conf (5).
+.
+.HP
+.IR Raid
+.br
+Attempts to handle device failure automatically. See
+.BR lvm.conf (5).
+.
+.HP
+.IR Snapshot
+.br
Monitors how full a snapshot is becoming and emits a warning to
syslog when it exceeds 80% full.
The warning is repeated when 85%, 90% and 95% of the snapshot is filled.
-See \fBlvm.conf\fP(5).
-.TP
-.I Thin
-Monitors how full a thin pool is becoming and emits a warning to
-syslog when it exceeds 80% full.
+See
+.BR lvm.conf (5).
+Snapshot which runs out of space gets invalid and when it is mounted,
+it gets umounted if possible.
+.
+.HP
+.IR Thin
+.br
+Monitors how full a thin pool data and metadata is becoming and emits
+a warning to syslog when it exceeds 80% full.
The warning is repeated when 85%, 90% and 95% of the thin pool is filled.
-See \fBlvm.conf\fP(5).
+See
+.BR lvm.conf (5).
+If the thin-pool runs out of space, thin volumes are umounted if possible.
+.
.SH OPTIONS
-.TP
-.B \-d
+.
+.HP
+.BR \-d
+.br
Repeat from 1 to 3 times (
.BR \-d ,
.BR \-dd ,
@@ -45,21 +69,35 @@ Repeat from 1 to 3 times (
) to increase the detail of
debug messages sent to syslog.
Each extra d adds more debugging information.
-.TP
-.B \-f
+.
+.HP
+.BR \-f
+.br
Don't fork, run in the foreground.
-.TP
-.BR \-h ", " \-?
+.
+.HP
+.BR \-h
+.br
Show help information.
-.TP
-.B \-R
+.
+.HP
+.BR \-?
+.br
+Show help information on stderr.
+.
+.HP
+.BR \-R
+.br
Replace a running dmeventd instance. The running dmeventd must be version
2.02.77 or newer. The new dmeventd instance will obtain a list of devices and
events to monitor from the currently running daemon.
-.TP
-.B \-V
+.
+.HP
+.BR \-V
+.br
Show version of dmeventd.
-
+.
.SH SEE ALSO
+.
.BR lvm (8),
.BR lvm.conf (5)
7 years, 8 months
master - dmeventd: add more debug messages
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0e272103085708...
Commit: 0e2721030857088803bc71ccc27644b7b95241ca
Parent: 13086c2523a00bc8501113f56094312bda4881e1
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Oct 10 16:36:18 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:15:43 2015 +0200
dmeventd: add more debug messages
---
daemons/dmeventd/dmeventd.c | 15 ++++++++++++---
daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c | 4 ++++
.../dmeventd/plugins/snapshot/dmeventd_snapshot.c | 1 +
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 0acb919..e34c4c1 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -874,7 +874,7 @@ static void *_monitor_thread(void *arg)
}
}
- DEBUGLOG("Finished _monitor_thread");
+ DEBUGLOG("Finished _monitor_thread.");
pthread_cleanup_pop(1);
return NULL;
@@ -1120,6 +1120,8 @@ static int _unregister_for_event(struct message_data *message_data)
}
_unlock_mutex();
+ DEBUGLOG("Unregistered uuid:%s.", thread->device.uuid);
+
out:
return ret;
}
@@ -1147,6 +1149,7 @@ static int _registered_device(struct message_data *message_data,
return -ENOMEM;
msg->size = (uint32_t) r;
+ DEBUGLOG("Registered %s.", msg->data);
return 0;
}
@@ -1154,6 +1157,7 @@ static int _registered_device(struct message_data *message_data,
static int _want_registered_device(char *dso_name, char *device_uuid,
struct thread_status *thread)
{
+ DEBUGLOG("Looking for dso:%s uuid:%s.", dso_name, device_uuid);
/* If DSO names and device paths are equal. */
if (dso_name && device_uuid)
return !strcmp(dso_name, thread->dso_data->dso_name) &&
@@ -1175,6 +1179,9 @@ static int _get_registered_dev(struct message_data *message_data, int next)
struct thread_status *thread, *hit = NULL;
int ret = -ENOENT;
+ DEBUGLOG("Get%s dso:%s uuid:%s.", next ? "" : "Next",
+ message_data->dso_name,
+ message_data->device_uuid);
_lock_mutex();
/* Iterate list of threads checking if we want a particular one. */
@@ -1205,8 +1212,10 @@ static int _get_registered_dev(struct message_data *message_data, int next)
goto reg;
}
- if (!hit)
+ if (!hit) {
+ DEBUGLOG("Get%s not registered", next ? "" : "Next");
goto out;
+ }
while (1) {
if (dm_list_end(&_thread_registry, &thread->list))
@@ -1613,9 +1622,9 @@ static void _cleanup_unused_threads(void)
}
if (thread->status == DM_THREAD_DONE) {
- DEBUGLOG("Destroying Thr %x.", (int)thread->thread);
dm_list_del(l);
_unlock_mutex();
+ DEBUGLOG("Destroying Thr %x.", (int)thread->thread);
join_ret = pthread_join(thread->thread, NULL);
_free_thread_status(thread);
_lock_mutex();
diff --git a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
index 0ba3694..e3d8321 100644
--- a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
+++ b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
@@ -74,6 +74,7 @@ int dmeventd_lvm2_init(void)
lvm2_disable_dmeventd_monitoring(_lvm_handle);
/* FIXME Temporary: move to dmeventd core */
lvm2_run(_lvm_handle, "_memlock_inc");
+ log_debug("lvm plugin initilized.");
}
_register_count++;
@@ -89,14 +90,17 @@ void dmeventd_lvm2_exit(void)
pthread_mutex_lock(&_register_mutex);
if (!--_register_count) {
+ log_debug("lvm plugin shuting down.");
lvm2_run(_lvm_handle, "_memlock_dec");
dm_pool_destroy(_mem_pool);
_mem_pool = NULL;
+ log_debug("lvm plugin exiting.");
lvm2_exit(_lvm_handle);
_lvm_handle = NULL;
}
pthread_mutex_unlock(&_register_mutex);
+ log_debug("lvm plugin exited.");
}
struct dm_pool *dmeventd_lvm2_pool(void)
diff --git a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
index f78b8f7..ffe6666 100644
--- a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
+++ b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
@@ -152,6 +152,7 @@ void process_event(struct dm_task *dmt,
if (status->invalid) {
struct dm_info info;
+ log_error("Snapshot %s is lost.", device);
if (dm_task_get_info(dmt, &info)) {
dmeventd_lvm2_unlock();
_umount(device, info.major, info.minor);
7 years, 8 months
master - dmeventd: drop changing logging
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=13086c2523a00b...
Commit: 13086c2523a00bc8501113f56094312bda4881e1
Parent: 42a9c8b4a659a44bef1b3150eb6359d562938ca3
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Oct 9 22:08:01 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:15:43 2015 +0200
dmeventd: drop changing logging
As we now use 'unified' logging macro system - we no longer need
to protect from change of logging function pointer - it's set
once at the start of dmeventd and not change anymore
(as lvm2 library no longer interferers here).
---
daemons/dmeventd/dmeventd.c | 10 ----------
1 files changed, 0 insertions(+), 10 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 6f25379..0acb919 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -648,7 +648,6 @@ static sigset_t _unblock_sigalrm(void)
/* Wait on a device until an event occurs. */
static int _event_wait(struct thread_status *thread, struct dm_task **task)
{
- static unsigned _in_event_counter = 0;
sigset_t set;
int ret = DM_WAIT_RETRY;
struct dm_task *dmt;
@@ -667,16 +666,11 @@ static int _event_wait(struct thread_status *thread, struct dm_task **task)
!dm_task_set_event_nr(dmt, thread->event_nr))
goto out;
- _lock_mutex();
/*
* Check if there are already some waiting events,
* in this case the logging is unmodified.
* TODO: audit libdm thread usage
*/
- if (!_in_event_counter++)
- dm_log_init(_dmeventd_log);
- _unlock_mutex();
-
DEBUGLOG("Starting waitevent task for %s", thread->device.uuid);
/*
* This is so that you can break out of waiting on an event,
@@ -708,10 +702,6 @@ static int _event_wait(struct thread_status *thread, struct dm_task **task)
DEBUGLOG("Completed waitevent task for %s", thread->device.uuid);
pthread_sigmask(SIG_SETMASK, &set, NULL);
- _lock_mutex();
- if (--_in_event_counter == 0)
- dm_log_init(NULL);
- _unlock_mutex();
out:
if (ret == DM_WAIT_FATAL || ret == DM_WAIT_RETRY) {
7 years, 8 months
master - dmeventd: enable new logging
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=42a9c8b4a659a4...
Commit: 42a9c8b4a659a44bef1b3150eb6359d562938ca3
Parent: e50583d7219e01228d697f91a16e91ed1f5efe86
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Tue Oct 13 15:13:28 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:13:28 2015 +0200
dmeventd: enable new logging
---
daemons/dmeventd/dmeventd.c | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 26609db..6f25379 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -674,7 +674,7 @@ static int _event_wait(struct thread_status *thread, struct dm_task **task)
* TODO: audit libdm thread usage
*/
if (!_in_event_counter++)
- dm_log_init(_no_intr_log);
+ dm_log_init(_dmeventd_log);
_unlock_mutex();
DEBUGLOG("Starting waitevent task for %s", thread->device.uuid);
@@ -2118,7 +2118,6 @@ int main(int argc, char *argv[])
openlog("dmeventd", LOG_PID, LOG_DAEMON);
- dm_event_log_set(_debug_level, _use_syslog);
dm_log_init(_dmeventd_log);
(void) dm_prepare_selinux_context(DMEVENTD_PIDFILE, S_IFREG);
7 years, 8 months
master - dmeventd: enable new logging
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e50583d7219e01...
Commit: e50583d7219e01228d697f91a16e91ed1f5efe86
Parent: c90363b585a41de2a65872f9be359db22ee64325
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Oct 10 18:32:53 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:09:35 2015 +0200
dmeventd: enable new logging
---
daemons/dmeventd/dmeventd.c | 40 +++++++++++-----------------------------
1 files changed, 11 insertions(+), 29 deletions(-)
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 581ce18..26609db 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -16,14 +16,13 @@
* dmeventd - dm event daemon to monitor active mapped devices
*/
-#include "tool.h"
-
-//#include "libmultilog.h"
#include "dm-logging.h"
#include "libdevmapper-event.h"
#include "dmeventd.h"
+#include "tool.h"
+
#include <dlfcn.h>
#include <pthread.h>
#include <sys/file.h>
@@ -61,7 +60,6 @@
#endif
-/* FIXME We use syslog for now, because multilog is not yet implemented */
#include <syslog.h>
static volatile sig_atomic_t _exit_now = 0; /* set to '1' when signal is given to exit */
@@ -114,15 +112,14 @@ static char **_initial_registrations = 0;
/* FIXME Make configurable at runtime */
#ifdef DEBUG
-# define DEBUGLOG(fmt, args...) debuglog("[Thr %x]: " fmt, (int)pthread_self(), ## args)
-void debuglog(const char *fmt, ... ) __attribute__ ((format(printf, 1, 2)));
-
-void debuglog(const char *fmt, ...)
+# define DEBUGLOG log_debug
+__attribute__((format(printf, 4, 5)))
+static void _dmeventd_log(int level, const char *file, int line,
+ const char *format, ...)
{
va_list ap;
-
- va_start(ap, fmt);
- vsyslog(LOG_DEBUG, fmt, ap);
+ va_start(ap, format);
+ dm_event_log("dm", level, file, line, 0, format, ap);
va_end(ap);
}
@@ -634,24 +631,6 @@ static void _unregister_for_timeout(struct thread_status *thread)
pthread_mutex_unlock(&_timeout_mutex);
}
-__attribute__((format(printf, 4, 5)))
-static void _no_intr_log(int level, const char *file, int line,
- const char *f, ...)
-{
- va_list ap;
-
- if (errno == EINTR)
- return;
- if (level > _LOG_WARN)
- return;
-
- va_start(ap, f);
- vfprintf((level < _LOG_WARN) ? stderr : stdout, f, ap);
- va_end(ap);
-
- fputc('\n', (level < _LOG_WARN) ? stderr : stdout);
-}
-
static sigset_t _unblock_sigalrm(void)
{
sigset_t set, old;
@@ -2139,6 +2118,9 @@ int main(int argc, char *argv[])
openlog("dmeventd", LOG_PID, LOG_DAEMON);
+ dm_event_log_set(_debug_level, _use_syslog);
+ dm_log_init(_dmeventd_log);
+
(void) dm_prepare_selinux_context(DMEVENTD_PIDFILE, S_IFREG);
if (dm_create_lockfile(DMEVENTD_PIDFILE) == 0)
exit(EXIT_FAILURE);
7 years, 8 months
master - dmeventd: use log_ macros in plugins
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=c90363b585a41d...
Commit: c90363b585a41de2a65872f9be359db22ee64325
Parent: 915f0faac1fa3541f4a01092536fac5f2ab5982f
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Oct 10 16:58:31 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 15:09:03 2015 +0200
dmeventd: use log_ macros in plugins
Convert from syslog to standard log_() macros in plugins.
---
daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c | 53 +++-----------------
daemons/dmeventd/plugins/mirror/dmeventd_mirror.c | 8 +--
daemons/dmeventd/plugins/raid/dmeventd_raid.c | 10 ++--
.../dmeventd/plugins/snapshot/dmeventd_snapshot.c | 9 ++--
daemons/dmeventd/plugins/thin/dmeventd_thin.c | 11 ++--
5 files changed, 23 insertions(+), 68 deletions(-)
diff --git a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
index ecaa058..0ba3694 100644
--- a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
+++ b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2010-2015 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -13,15 +13,11 @@
*/
#include "lib.h"
-#include "log.h"
-
-#include "lvm2cmd.h"
#include "dmeventd_lvm.h"
+#include "libdevmapper-event.h"
+#include "lvm2cmd.h"
#include <pthread.h>
-#include <syslog.h>
-
-extern int dmeventd_debug;
/*
* register_device() is called first and performs initialisation.
@@ -36,48 +32,13 @@ static int _register_count = 0;
static struct dm_pool *_mem_pool = NULL;
static void *_lvm_handle = NULL;
+DM_EVENT_LOG_FN("lvm")
+
/*
* Currently only one event can be processed at a time.
*/
static pthread_mutex_t _event_mutex = PTHREAD_MUTEX_INITIALIZER;
-/*
- * FIXME Do not pass things directly to syslog, rather use the existing logging
- * facilities to sort logging ... however that mechanism needs to be somehow
- * configurable and we don't have that option yet
- */
-static void _temporary_log_fn(int level,
- const char *file __attribute__((unused)),
- int line __attribute__((unused)),
- int dm_errno __attribute__((unused)),
- const char *message)
-{
- level &= ~(_LOG_STDERR | _LOG_ONCE);
-
- 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:
- if (dmeventd_debug >= 1)
- syslog(LOG_NOTICE, "%s", message);
- break;
- case _LOG_WARN:
- syslog(LOG_WARNING, "%s", message);
- break;
- case _LOG_ERR:
- syslog(LOG_ERR, "%s", message);
- break;
- default:
- syslog(LOG_CRIT, "%s", message);
- }
-}
-
void dmeventd_lvm2_lock(void)
{
pthread_mutex_lock(&_event_mutex);
@@ -95,8 +56,8 @@ int dmeventd_lvm2_init(void)
pthread_mutex_lock(&_register_mutex);
if (!_lvm_handle) {
- if (!getenv("LVM_LOG_FILE_EPOCH"))
- lvm2_log_fn(_temporary_log_fn);
+ lvm2_log_fn((lvm2_log_fn_t)print_log);
+
if (!(_lvm_handle = lvm2_init()))
goto out;
diff --git a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
index 288e741..c010794 100644
--- a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
+++ b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2012 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2005-2015 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -13,20 +13,18 @@
*/
#include "lib.h"
-
#include "libdevmapper-event.h"
#include "dmeventd_lvm.h"
#include "defaults.h"
-#include <syslog.h> /* FIXME Replace syslog with multilog */
-/* FIXME Missing openlog? */
-/* FIXME Replace most syslogs with log_error() style messages and add complete context. */
/* FIXME Reformat to 80 char lines. */
#define ME_IGNORE 0
#define ME_INSYNC 1
#define ME_FAILURE 2
+DM_EVENT_LOG_FN("mirr")
+
static int _process_status_code(const char status_code, const char *dev_name,
const char *dev_type, int r)
{
diff --git a/daemons/dmeventd/plugins/raid/dmeventd_raid.c b/daemons/dmeventd/plugins/raid/dmeventd_raid.c
index 055bfc2..822d7c4 100644
--- a/daemons/dmeventd/plugins/raid/dmeventd_raid.c
+++ b/daemons/dmeventd/plugins/raid/dmeventd_raid.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2011 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2005-2015 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -13,13 +13,11 @@
*/
#include "lib.h"
-
-#include "libdevmapper-event.h"
#include "dmeventd_lvm.h"
+#include "libdevmapper-event.h"
+
+DM_EVENT_LOG_FN("raid")
-#include <syslog.h> /* FIXME Replace syslog with multilog */
-/* FIXME Missing openlog? */
-/* FIXME Replace most syslogs with log_error() style messages and add complete context. */
/* FIXME Reformat to 80 char lines. */
/*
diff --git a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
index 1372769..f78b8f7 100644
--- a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
+++ b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007-2011 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2007-2015 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -13,14 +13,11 @@
*/
#include "lib.h"
-
-#include "libdevmapper-event.h"
#include "dmeventd_lvm.h"
+#include "libdevmapper-event.h"
#include <sys/wait.h>
-#include <syslog.h> /* FIXME Replace syslog with multilog */
#include <stdarg.h>
-/* FIXME Missing openlog? */
/* First warning when snapshot is 80% full. */
#define WARNING_THRESH 80
@@ -38,6 +35,8 @@ struct dso_state {
char cmd_str[1024];
};
+DM_EVENT_LOG_FN("snap")
+
static int _run(const char *cmd, ...)
{
va_list ap;
diff --git a/daemons/dmeventd/plugins/thin/dmeventd_thin.c b/daemons/dmeventd/plugins/thin/dmeventd_thin.c
index febf554..f57eb9b 100644
--- a/daemons/dmeventd/plugins/thin/dmeventd_thin.c
+++ b/daemons/dmeventd/plugins/thin/dmeventd_thin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011-2013 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2011-2015 Red Hat, Inc. All rights reserved.
*
* This file is part of LVM2.
*
@@ -12,15 +12,12 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "lib.h"
-
-#include "libdevmapper-event.h"
+#include "lib.h" /* using here lvm log */
#include "dmeventd_lvm.h"
+#include "libdevmapper-event.h"
#include <sys/wait.h>
-#include <syslog.h> /* FIXME Replace syslog with multilog */
#include <stdarg.h>
-/* FIXME Missing openlog? */
/* First warning when thin is 80% full. */
#define WARNING_THRESH 80
@@ -52,6 +49,8 @@ struct dso_state {
# define MKDEV(x,y) makedev((x),(y))
#endif
+DM_EVENT_LOG_FN("thin")
+
/* Get dependencies for device, and try to find matching device */
static int _has_deps(const char *name, int tp_major, int tp_minor, int *dev_minor)
{
7 years, 8 months
master - dmeventd: syslog -> log_xxxxx
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=915f0faac1fa35...
Commit: 915f0faac1fa3541f4a01092536fac5f2ab5982f
Parent: 0641e3a5fd19628db0e08fca252c13f40230ffa2
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri Oct 9 21:57:48 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 14:43:30 2015 +0200
dmeventd: syslog -> log_xxxxx
Convert logging of dmeventd to libdm logging macros.
---
WHATS_NEW_DM | 1 +
daemons/dmeventd/dmeventd.c | 94 +++++++++-----------
daemons/dmeventd/libdevmapper-event.c | 34 ++++----
daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c | 6 +-
daemons/dmeventd/plugins/mirror/dmeventd_mirror.c | 46 +++++-----
daemons/dmeventd/plugins/raid/dmeventd_raid.c | 38 ++++----
.../dmeventd/plugins/snapshot/dmeventd_snapshot.c | 30 ++++---
daemons/dmeventd/plugins/thin/dmeventd_thin.c | 53 ++++++------
8 files changed, 145 insertions(+), 157 deletions(-)
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index a1c121a..ff4ac22 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.110 -
======================================
+ Convert dmeventd to use common logging macro system from libdm.
Return -ENOMEM when device registration fails instead of 0 (=success).
Enforce writethrough mode for cleaner policy.
Add support for recognition and deactivation of MD devices to blkdeactivate.
diff --git a/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c
index 844b2a6..581ce18 100644
--- a/daemons/dmeventd/dmeventd.c
+++ b/daemons/dmeventd/dmeventd.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2005-2015 Red Hat, Inc. All rights reserved.
*
* This file is part of the device-mapper userspace tools.
*
@@ -718,13 +718,12 @@ static int _event_wait(struct thread_status *thread, struct dm_task **task)
} else if (thread->status == DM_THREAD_SHUTDOWN && ioctl_errno == EINTR)
ret = DM_WAIT_FATAL;
else {
- syslog(LOG_NOTICE, "dm_task_run failed, errno = %d, %s",
- ioctl_errno, strerror(ioctl_errno));
if (ioctl_errno == ENXIO) {
- syslog(LOG_ERR, "%s disappeared, detaching",
- thread->device.name);
+ log_error("%s disappeared, detaching.",
+ thread->device.name);
ret = DM_WAIT_FATAL;
- }
+ } else
+ log_sys_error("dm_task_run", "");
}
}
DEBUGLOG("Completed waitevent task for %s", thread->device.uuid);
@@ -778,8 +777,8 @@ static void _monitor_unregister(void *arg)
DEBUGLOG("_monitor_unregister thread cleanup handler running");
if (!_do_unregister_device(thread))
- syslog(LOG_ERR, "%s: %s unregister failed\n", __func__,
- thread->device.name);
+ log_error("%s: %s unregister failed.", __func__,
+ thread->device.name);
if (thread->current_task) {
dm_task_destroy(thread->current_task);
thread->current_task = NULL;
@@ -981,8 +980,8 @@ static struct dso_data *_load_dso(struct message_data *data)
if (!(dl = dlopen(data->dso_name, RTLD_NOW))) {
const char *dlerr = dlerror();
- syslog(LOG_ERR, "dmeventd %s dlopen failed: %s", data->dso_name,
- dlerr);
+ log_error("dmeventd %s dlopen failed: %s.",
+ data->dso_name, dlerr);
data->msg->size =
dm_asprintf(&(data->msg->data), "%s %s dlopen failed: %s",
data->id, data->dso_name, dlerr);
@@ -1309,8 +1308,7 @@ static int _open_fifos(struct dm_event_fifos *fifos)
/* Create client fifo. */
(void) dm_prepare_selinux_context(fifos->client_path, S_IFIFO);
if ((mkfifo(fifos->client_path, 0600) == -1) && errno != EEXIST) {
- syslog(LOG_ERR, "%s: Failed to create client fifo %s: %m.\n",
- __func__, fifos->client_path);
+ log_sys_error("client mkfifo", fifos->client_path);
(void) dm_prepare_selinux_context(NULL, 0);
goto fail;
}
@@ -1318,8 +1316,7 @@ static int _open_fifos(struct dm_event_fifos *fifos)
/* Create server fifo. */
(void) dm_prepare_selinux_context(fifos->server_path, S_IFIFO);
if ((mkfifo(fifos->server_path, 0600) == -1) && errno != EEXIST) {
- syslog(LOG_ERR, "%s: Failed to create server fifo %s: %m.\n",
- __func__, fifos->server_path);
+ log_sys_error("server mkfifo", fifos->server_path);
(void) dm_prepare_selinux_context(NULL, 0);
goto fail;
}
@@ -1328,58 +1325,53 @@ static int _open_fifos(struct dm_event_fifos *fifos)
/* Warn about wrong permissions if applicable */
if ((!stat(fifos->client_path, &st)) && (st.st_mode & 0777) != 0600)
- syslog(LOG_WARNING, "Fixing wrong permissions on %s: %m.\n",
- fifos->client_path);
+ log_warn("WARNING: Fixing wrong permissions on %s: %s.\n",
+ fifos->client_path, strerror(errno));
if ((!stat(fifos->server_path, &st)) && (st.st_mode & 0777) != 0600)
- syslog(LOG_WARNING, "Fixing wrong permissions on %s: %m.\n",
- fifos->server_path);
+ log_warn("WARNING: Fixing wrong permissions on %s: %s.\n",
+ fifos->server_path, strerror(errno));
/* If they were already there, make sure permissions are ok. */
if (chmod(fifos->client_path, 0600)) {
- syslog(LOG_ERR, "Unable to set correct file permissions on %s: %m.\n",
- fifos->client_path);
+ log_sys_error("chmod", fifos->client_path);
goto fail;
}
if (chmod(fifos->server_path, 0600)) {
- syslog(LOG_ERR, "Unable to set correct file permissions on %s: %m.\n",
- fifos->server_path);
+ log_sys_error("chmod", fifos->server_path);
goto fail;
}
/* Need to open read+write or we will block or fail */
if ((fifos->server = open(fifos->server_path, O_RDWR)) < 0) {
- syslog(LOG_ERR, "Failed to open fifo server %s: %m.\n",
- fifos->server_path);
+ log_sys_error("server open", fifos->server_path);
goto fail;
}
if (fcntl(fifos->server, F_SETFD, FD_CLOEXEC) < 0) {
- syslog(LOG_ERR, "Failed to set FD_CLOEXEC for fifo server %s: %m.\n",
- fifos->server_path);
+ log_sys_error("fcntl(FD_CLOEXEC)", fifos->server_path);
goto fail;
}
/* Need to open read+write for select() to work. */
if ((fifos->client = open(fifos->client_path, O_RDWR)) < 0) {
- syslog(LOG_ERR, "Failed to open fifo client %s: %m", fifos->client_path);
+ log_sys_error("client open", fifos->client_path);
goto fail;
}
if (fcntl(fifos->client, F_SETFD, FD_CLOEXEC) < 0) {
- syslog(LOG_ERR, "Failed to set FD_CLOEXEC for fifo client %s: %m.\n",
- fifos->client_path);
+ log_sys_error("fcntl(FD_CLOEXEC)", fifos->client_path);
goto fail;
}
return 1;
fail:
if (fifos->server >= 0 && close(fifos->server))
- syslog(LOG_ERR, "Failed to close fifo server %s: %m", fifos->server_path);
+ log_sys_error("server close", fifos->server_path);
if (fifos->client >= 0 && close(fifos->client))
- syslog(LOG_ERR, "Failed to close fifo client %s: %m", fifos->client_path);
+ log_sys_error("client close", fifos->client_path);
return 0;
}
@@ -1591,7 +1583,7 @@ static void _process_request(struct dm_event_fifos *fifos)
if (die) {
if (unlink(DMEVENTD_PIDFILE))
- perror(DMEVENTD_PIDFILE ": unlink failed");
+ log_sys_error("unlink", DMEVENTD_PIDFILE);
_exit(0);
}
}
@@ -1637,15 +1629,14 @@ static void _cleanup_unused_threads(void)
if (ret == ESRCH) {
thread->status = DM_THREAD_DONE;
} else if (ret) {
- syslog(LOG_ERR, "Unable to terminate thread: %s",
- strerror(ret));
+ log_error("Unable to terminate thread: %s",
+ strerror(ret));
}
break;
}
dm_list_del(l);
- syslog(LOG_ERR,
- "thread can't be on unused list unless !thread->events");
+ log_error("thread can't be on unused list unless !thread->events");
thread->status = DM_THREAD_RUNNING;
LINK_THREAD(thread);
@@ -1665,7 +1656,7 @@ static void _cleanup_unused_threads(void)
_unlock_mutex();
if (join_ret)
- syslog(LOG_ERR, "Failed pthread_join: %s\n", strerror(join_ret));
+ log_error("Failed pthread_join: %s.", strerror(join_ret));
}
static void _sig_alarm(int signum __attribute__((unused)))
@@ -1709,14 +1700,14 @@ static int _set_oom_adj(const char *oom_adj_path, int val)
FILE *fp;
if (!(fp = fopen(oom_adj_path, "w"))) {
- perror("oom_adj: fopen failed");
+ log_sys_error("open", oom_adj_path);
return 0;
}
fprintf(fp, "%i", val);
if (dm_fclose(fp))
- perror("oom_adj: fclose failed");
+ log_sys_error("fclose", oom_adj_path);
return 1;
}
@@ -1730,14 +1721,11 @@ static int _protect_against_oom_killer(void)
if (stat(OOM_ADJ_FILE, &st) == -1) {
if (errno != ENOENT)
- perror(OOM_ADJ_FILE ": stat failed");
+ log_sys_error("stat", OOM_ADJ_FILE);
/* Try old oom_adj interface as a fallback */
if (stat(OOM_ADJ_FILE_OLD, &st) == -1) {
- if (errno == ENOENT)
- perror(OOM_ADJ_FILE_OLD " not found");
- else
- perror(OOM_ADJ_FILE_OLD ": stat failed");
+ log_sys_error("stat", OOM_ADJ_FILE_OLD);
return 1;
}
@@ -1826,14 +1814,14 @@ out:
static void _remove_files_on_exit(void)
{
if (unlink(DMEVENTD_PIDFILE))
- perror(DMEVENTD_PIDFILE ": unlink failed");
+ log_sys_error("unlink", DMEVENTD_PIDFILE);
if (!_systemd_activation) {
if (unlink(DM_EVENT_FIFO_CLIENT))
- perror(DM_EVENT_FIFO_CLIENT " : unlink failed");
+ log_sys_error("unlink", DM_EVENT_FIFO_CLIENT);
if (unlink(DM_EVENT_FIFO_SERVER))
- perror(DM_EVENT_FIFO_SERVER " : unlink failed");
+ log_sys_error("unlink", DM_EVENT_FIFO_SERVER);
}
}
@@ -1855,7 +1843,7 @@ static void _daemonize(void)
switch (pid = fork()) {
case -1:
- perror("fork failed:");
+ log_sys_error("fork", "");
exit(EXIT_FAILURE);
case 0: /* Child */
@@ -2167,7 +2155,7 @@ int main(int argc, char *argv[])
#ifdef __linux__
/* Systemd has adjusted oom killer for us already */
if (!_systemd_activation && !_protect_against_oom_killer())
- syslog(LOG_ERR, "Failed to protect against OOM killer");
+ log_error("Failed to protect against OOM killer.");
#endif
_init_thread_signals();
@@ -2185,7 +2173,7 @@ int main(int argc, char *argv[])
/* Signal parent, letting them know we are ready to go. */
if (!_foreground)
kill(getppid(), SIGTERM);
- syslog(LOG_NOTICE, "dmeventd ready for processing.");
+ log_notice("dmeventd ready for processing.");
if (_initial_registrations)
_process_initial_registrations();
@@ -2204,8 +2192,8 @@ int main(int argc, char *argv[])
_unlock_mutex();
if (nothreads)
break;
- syslog(LOG_ERR, "There are still devices being monitored.");
- syslog(LOG_ERR, "Refusing to exit.");
+ log_error("There are still devices being monitored.");
+ log_error("Refusing to exit.");
}
_process_request(&fifos);
_cleanup_unused_threads();
@@ -2215,7 +2203,7 @@ int main(int argc, char *argv[])
pthread_mutex_destroy(&_global_mutex);
- syslog(LOG_NOTICE, "dmeventd shutting down.");
+ log_notice("dmeventd shutting down.");
closelog();
exit(EXIT_SUCCESS);
diff --git a/daemons/dmeventd/libdevmapper-event.c b/daemons/dmeventd/libdevmapper-event.c
index 9b04b02..ee4a35c 100644
--- a/daemons/dmeventd/libdevmapper-event.c
+++ b/daemons/dmeventd/libdevmapper-event.c
@@ -198,7 +198,7 @@ static int _check_message_id(struct dm_event_daemon_message *msg)
if ((sscanf(msg->data, "%d:%d", &pid, &seq_nr) != 2) ||
(pid != getpid()) || (seq_nr != _sequence_nr)) {
log_error("Ignoring out-of-sequence reply from dmeventd. "
- "Expected %d:%d but received %s", getpid(),
+ "Expected %d:%d but received %s.", getpid(),
_sequence_nr, msg->data);
return 0;
}
@@ -233,7 +233,7 @@ static int _daemon_read(struct dm_event_fifos *fifos,
FD_SET(fifos->server, &fds);
ret = select(fifos->server + 1, &fds, NULL, NULL, &tval);
if (ret < 0 && errno != EINTR) {
- log_error("Unable to read from event server");
+ log_error("Unable to read from event server.");
return 0;
}
if ((ret == 0) && (i > 4) && !bytes) {
@@ -299,7 +299,7 @@ static int _daemon_write(struct dm_event_fifos *fifos,
if (ret < 0) {
if (errno == EINTR)
continue;
- log_error("Unable to talk to event daemon");
+ log_error("Unable to talk to event daemon.");
return 0;
}
if (ret == 0)
@@ -308,7 +308,7 @@ static int _daemon_write(struct dm_event_fifos *fifos,
if (ret < 0) {
if ((errno == EINTR) || (errno == EAGAIN))
continue;
- log_error("Unable to talk to event daemon");
+ log_error("Unable to talk to event daemon.");
return 0;
}
}
@@ -320,7 +320,7 @@ static int _daemon_write(struct dm_event_fifos *fifos,
FD_SET(fifos->client, &fds);
ret = select(fifos->client + 1, NULL, &fds, NULL, NULL);
if ((ret < 0) && (errno != EINTR)) {
- log_error("Unable to talk to event daemon");
+ log_error("Unable to talk to event daemon.");
return 0;
}
} while (ret < 1);
@@ -330,7 +330,7 @@ static int _daemon_write(struct dm_event_fifos *fifos,
if ((errno == EINTR) || (errno == EAGAIN))
continue;
else {
- log_error("Unable to talk to event daemon");
+ log_error("Unable to talk to event daemon.");
return 0;
}
}
@@ -360,7 +360,7 @@ int daemon_talk(struct dm_event_fifos *fifos,
getpid(), _sequence_nr,
dso_name ? : "-", dev_name ? : "-", evmask, timeout)))
< 0) {
- log_error("_daemon_talk: message allocation failed");
+ log_error("_daemon_talk: message allocation failed.");
return -ENOMEM;
}
msg->cmd = cmd;
@@ -448,11 +448,11 @@ static int _start_daemon(char *dmeventd_path, struct dm_event_fifos *fifos)
else if (!pid) {
execvp(args[0], args);
- log_error("Unable to exec dmeventd: %s", strerror(errno));
+ log_error("Unable to exec dmeventd: %s.", strerror(errno));
_exit(EXIT_FAILURE);
} else {
if (waitpid(pid, &status, 0) < 0)
- log_error("Unable to start dmeventd: %s",
+ log_error("Unable to start dmeventd: %s.",
strerror(errno));
else if (WEXITSTATUS(status))
log_error("Unable to start dmeventd.");
@@ -525,7 +525,7 @@ static struct dm_task *_get_device_info(const struct dm_event_handler *dmevh)
struct dm_info info;
if (!(dmt = dm_task_create(DM_DEVICE_INFO))) {
- log_error("_get_device_info: dm_task creation for info failed");
+ log_error("_get_device_info: dm_task creation for info failed.");
return NULL;
}
@@ -543,17 +543,17 @@ static struct dm_task *_get_device_info(const struct dm_event_handler *dmevh)
/* FIXME Add name or uuid or devno to messages */
if (!dm_task_run(dmt)) {
- log_error("_get_device_info: dm_task_run() failed");
+ log_error("_get_device_info: dm_task_run() failed.");
goto bad;
}
if (!dm_task_get_info(dmt, &info)) {
- log_error("_get_device_info: failed to get info for device");
+ log_error("_get_device_info: failed to get info for device.");
goto bad;
}
if (!info.exists) {
- log_error("_get_device_info: %s%s%s%.0d%s%.0d%s%s: device not found",
+ log_error("_get_device_info: %s%s%s%.0d%s%.0d%s%s: device not found.",
dmevh->uuid ? : "",
(!dmevh->uuid && dmevh->dev_name) ? dmevh->dev_name : "",
(!dmevh->uuid && !dmevh->dev_name && dmevh->major > 0) ? "(" : "",
@@ -622,12 +622,12 @@ int dm_event_register_handler(const struct dm_event_handler *dmevh)
!strstr(dmevh->dso, "libdevmapper-event-lvm2snapshot.so") &&
!strstr(dmevh->dso, "libdevmapper-event-lvm2mirror.so") &&
!strstr(dmevh->dso, "libdevmapper-event-lvm2raid.so"))
- log_warn("WARNING: %s: dmeventd plugins are deprecated", dmevh->dso);
+ log_warn("WARNING: %s: dmeventd plugins are deprecated.", dmevh->dso);
if ((err = _do_event(DM_EVENT_CMD_REGISTER_FOR_EVENT, dmevh->dmeventd_path, &msg,
dmevh->dso, uuid, dmevh->mask, dmevh->timeout)) < 0) {
- log_error("%s: event registration failed: %s",
+ log_error("%s: event registration failed: %s.",
dm_task_get_name(dmt),
msg.data ? msg.data : strerror(-err));
ret = 0;
@@ -654,7 +654,7 @@ int dm_event_unregister_handler(const struct dm_event_handler *dmevh)
if ((err = _do_event(DM_EVENT_CMD_UNREGISTER_FOR_EVENT, dmevh->dmeventd_path, &msg,
dmevh->dso, uuid, dmevh->mask, dmevh->timeout)) < 0) {
- log_error("%s: event deregistration failed: %s",
+ log_error("%s: event deregistration failed: %s.",
dm_task_get_name(dmt),
msg.data ? msg.data : strerror(-err));
ret = 0;
@@ -933,7 +933,7 @@ int dm_event_get_timeout(const char *device_path, uint32_t *timeout)
0, 0))) {
char *p = _skip_string(msg.data, ' ');
if (!p) {
- log_error("malformed reply from dmeventd '%s'\n",
+ log_error("Malformed reply from dmeventd '%s'.",
msg.data);
dm_free(msg.data);
return -EIO;
diff --git a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
index 7350623..ecaa058 100644
--- a/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
+++ b/daemons/dmeventd/plugins/lvm2/dmeventd_lvm.c
@@ -155,8 +155,8 @@ int dmeventd_lvm2_command(struct dm_pool *mem, char *buffer, size_t size,
int r;
if (!dm_split_lvm_name(mem, device, &vg, &lv, &layer)) {
- syslog(LOG_ERR, "Unable to determine VG name from %s.\n",
- device);
+ log_error("Unable to determine VG name from %s.",
+ device);
return 0;
}
@@ -170,7 +170,7 @@ int dmeventd_lvm2_command(struct dm_pool *mem, char *buffer, size_t size,
dm_pool_free(mem, vg);
if (r < 0) {
- syslog(LOG_ERR, "Unable to form LVM command. (too long).\n");
+ log_error("Unable to form LVM command. (too long).");
return 0;
}
diff --git a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
index 084be28..288e741 100644
--- a/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
+++ b/daemons/dmeventd/plugins/mirror/dmeventd_mirror.c
@@ -39,18 +39,15 @@ static int _process_status_code(const char status_code, const char *dev_name,
* U => Unclassified failure (bug)
*/
if (status_code == 'F') {
- syslog(LOG_ERR, "%s device %s flush failed.",
- dev_type, dev_name);
+ log_error("%s device %s flush failed.", dev_type, dev_name);
r = ME_FAILURE;
} else if (status_code == 'S')
- syslog(LOG_ERR, "%s device %s sync failed.",
- dev_type, dev_name);
+ log_error("%s device %s sync failed.", dev_type, dev_name);
else if (status_code == 'R')
- syslog(LOG_ERR, "%s device %s read failed.",
- dev_type, dev_name);
+ log_error("%s device %s read failed.", dev_type, dev_name);
else if (status_code != 'A') {
- syslog(LOG_ERR, "%s device %s has failed (%c).",
- dev_type, dev_name, status_code);
+ log_error("%s device %s has failed (%c).",
+ dev_type, dev_name, status_code);
r = ME_FAILURE;
}
@@ -125,7 +122,8 @@ out:
out_parse:
dm_free(args);
- syslog(LOG_ERR, "Unable to parse mirror status string.");
+ log_error("Unable to parse mirror status string.");
+
return ME_IGNORE;
}
@@ -142,7 +140,7 @@ static int _remove_failed_devices(const char *device)
r = dmeventd_lvm2_run(cmd_str);
if (!r)
- syslog(LOG_INFO, "Re-scan of mirror device %s failed.", device);
+ log_info("Re-scan of mirror device %s failed.", device);
if (!dmeventd_lvm2_command(dmeventd_lvm2_pool(), cmd_str, sizeof(cmd_str),
"lvconvert --config devices{ignore_suspended_devices=1} "
@@ -152,8 +150,8 @@ static int _remove_failed_devices(const char *device)
/* if repair goes OK, report success even if lvscan has failed */
r = dmeventd_lvm2_run(cmd_str);
- syslog(LOG_INFO, "Repair of mirrored device %s %s.", device,
- (r) ? "finished successfully" : "failed");
+ log_info("Repair of mirrored device %s %s.", device,
+ (r) ? "finished successfully" : "failed");
return (r) ? 0 : -1;
}
@@ -175,12 +173,12 @@ void process_event(struct dm_task *dmt,
&target_type, ¶ms);
if (!target_type) {
- syslog(LOG_INFO, "%s mapping lost.", device);
+ log_info("%s mapping lost.", device);
continue;
}
if (strcmp(target_type, "mirror")) {
- syslog(LOG_INFO, "%s has unmirrored portion.", device);
+ log_info("%s has unmirrored portion.", device);
continue;
}
@@ -190,25 +188,25 @@ void process_event(struct dm_task *dmt,
_part_ of the device is in sync
Also, this is not an error
*/
- syslog(LOG_NOTICE, "%s is now in-sync.", device);
+ log_notice("%s is now in-sync.", device);
break;
case ME_FAILURE:
- syslog(LOG_ERR, "Device failure in %s.", device);
+ log_error("Device failure in %s.", device);
if (_remove_failed_devices(device))
/* FIXME Why are all the error return codes unused? Get rid of them? */
- syslog(LOG_ERR, "Failed to remove faulty devices in %s.",
- device);
+ log_error("Failed to remove faulty devices in %s.",
+ device);
/* Should check before warning user that device is now linear
else
- syslog(LOG_NOTICE, "%s is now a linear device.\n",
- device);
+ log_notice("%s is now a linear device.",
+ device);
*/
break;
case ME_IGNORE:
break;
default:
/* FIXME Provide value then! */
- syslog(LOG_INFO, "Unknown event received.");
+ log_info("Unknown event received.");
}
} while (next);
@@ -224,7 +222,7 @@ int register_device(const char *device,
if (!dmeventd_lvm2_init())
return 0;
- syslog(LOG_INFO, "Monitoring mirror device %s for events.", device);
+ log_info("Monitoring mirror device %s for events.", device);
return 1;
}
@@ -235,8 +233,8 @@ int unregister_device(const char *device,
int minor __attribute__((unused)),
void **unused __attribute__((unused)))
{
- syslog(LOG_INFO, "No longer monitoring mirror device %s for events.",
- device);
+ log_info("No longer monitoring mirror device %s for events.",
+ device);
dmeventd_lvm2_exit();
return 1;
diff --git a/daemons/dmeventd/plugins/raid/dmeventd_raid.c b/daemons/dmeventd/plugins/raid/dmeventd_raid.c
index 4690cfa..055bfc2 100644
--- a/daemons/dmeventd/plugins/raid/dmeventd_raid.c
+++ b/daemons/dmeventd/plugins/raid/dmeventd_raid.c
@@ -39,7 +39,7 @@ static int run_repair(const char *device)
r = dmeventd_lvm2_run(cmd_str);
if (!r)
- syslog(LOG_INFO, "Re-scan of RAID device %s failed.", device);
+ log_info("Re-scan of RAID device %s failed.", device);
if (!dmeventd_lvm2_command(dmeventd_lvm2_pool(), cmd_str, sizeof(cmd_str),
"lvconvert --config devices{ignore_suspended_devices=1} "
@@ -50,7 +50,7 @@ static int run_repair(const char *device)
r = dmeventd_lvm2_run(cmd_str);
if (!r)
- syslog(LOG_INFO, "Repair of RAID device %s failed.", device);
+ log_info("Repair of RAID device %s failed.", device);
return (r) ? 0 : -1;
}
@@ -69,8 +69,7 @@ static int _process_raid_event(char *params, const char *device)
* <health chars> <resync ratio>
*/
if (!dm_split_words(params, 4, 0, a)) {
- syslog(LOG_ERR, "Failed to process status line for %s\n",
- device);
+ log_error("Failed to process status line for %s.", device);
return -EINVAL;
}
raid_type = a[0];
@@ -79,8 +78,8 @@ static int _process_raid_event(char *params, const char *device)
resync_ratio = a[3];
if (!(n = atoi(num_devices))) {
- syslog(LOG_ERR, "Failed to parse number of devices for %s: %s",
- device, num_devices);
+ log_error("Failed to parse number of devices for %s: %s.",
+ device, num_devices);
return -EINVAL;
}
@@ -92,9 +91,8 @@ static int _process_raid_event(char *params, const char *device)
/* Device is 'a'live, but not yet in-sync */
break;
case 'D':
- syslog(LOG_ERR,
- "Device #%d of %s array, %s, has failed.",
- i, raid_type, device);
+ log_error("Device #%d of %s array, %s, has failed.",
+ i, raid_type, device);
failure++;
break;
default:
@@ -107,13 +105,13 @@ static int _process_raid_event(char *params, const char *device)
p = strstr(resync_ratio, "/");
if (!p) {
- syslog(LOG_ERR, "Failed to parse resync_ratio for %s: %s",
- device, resync_ratio);
+ log_error("Failed to parse resync_ratio for %s: %s.",
+ device, resync_ratio);
return -EINVAL;
}
p[0] = '\0';
- syslog(LOG_INFO, "%s array, %s, is %s in-sync.",
- raid_type, device, strcmp(resync_ratio, p+1) ? "not" : "now");
+ log_info("%s array, %s, is %s in-sync.",
+ raid_type, device, strcmp(resync_ratio, p+1) ? "not" : "now");
return 0;
}
@@ -135,18 +133,18 @@ void process_event(struct dm_task *dmt,
&target_type, ¶ms);
if (!target_type) {
- syslog(LOG_INFO, "%s mapping lost.", device);
+ log_info("%s mapping lost.", device);
continue;
}
if (strcmp(target_type, "raid")) {
- syslog(LOG_INFO, "%s has non-raid portion.", device);
+ log_info("%s has non-raid portion.", device);
continue;
}
if (_process_raid_event(params, device))
- syslog(LOG_ERR, "Failed to process event for %s",
- device);
+ log_error("Failed to process event for %s.",
+ device);
} while (next);
dmeventd_lvm2_unlock();
@@ -161,7 +159,7 @@ int register_device(const char *device,
if (!dmeventd_lvm2_init())
return 0;
- syslog(LOG_INFO, "Monitoring RAID device %s for events.", device);
+ log_info("Monitoring RAID device %s for events.", device);
return 1;
}
@@ -172,8 +170,8 @@ int unregister_device(const char *device,
int minor __attribute__((unused)),
void **unused __attribute__((unused)))
{
- syslog(LOG_INFO, "No longer monitoring RAID device %s for events.",
- device);
+ log_info("No longer monitoring RAID device %s for events.",
+ device);
dmeventd_lvm2_exit();
return 1;
diff --git a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
index 1b1d977..1372769 100644
--- a/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
+++ b/daemons/dmeventd/plugins/snapshot/dmeventd_snapshot.c
@@ -62,7 +62,7 @@ static int _run(const char *cmd, ...)
va_end(ap);
execvp(cmd, (char **)argv);
- syslog(LOG_ERR, "Failed to execute %s: %s.\n", cmd, strerror(errno));
+ log_sys_error("exec", cmd);
exit(127);
}
@@ -90,9 +90,11 @@ static void _umount(const char *device, int major, int minor)
char buffer[4096];
char *words[3];
struct stat st;
+ const char procmounts[] = "/proc/mounts";
- if (!(mounts = fopen("/proc/mounts", "r"))) {
- syslog(LOG_ERR, "Could not read /proc/mounts. Not umounting %s.\n", device);
+ if (!(mounts = fopen(procmounts, "r"))) {
+ log_sys_error("fopen", procmounts);
+ log_error("Not umounting %s.", device);
return;
}
@@ -112,15 +114,15 @@ static void _umount(const char *device, int major, int minor)
if (S_ISBLK(st.st_mode) &&
major(st.st_rdev) == major &&
minor(st.st_rdev) == minor) {
- syslog(LOG_ERR, "Unmounting invalid snapshot %s from %s.\n", device, words[1]);
- if (!_run(UMOUNT_COMMAND, "-fl", words[1], NULL))
- syslog(LOG_ERR, "Failed to umount snapshot %s from %s: %s.\n",
- device, words[1], strerror(errno));
+ log_error("Unmounting invalid snapshot %s from %s.", device, words[1]);
+ if (!_run(UMOUNT_COMMAND, "-fl", words[1], NULL))
+ log_error("Failed to umount snapshot %s from %s: %s.",
+ device, words[1], strerror(errno));
}
}
if (fclose(mounts))
- syslog(LOG_ERR, "Failed to close /proc/mounts.\n");
+ log_sys_error("close", procmounts);
}
void process_event(struct dm_task *dmt,
@@ -169,7 +171,7 @@ void process_event(struct dm_task *dmt,
* the status string. Report the full status string to syslog.
*/
if (status->invalid || !status->total_sectors) {
- syslog(LOG_ERR, "Snapshot %s changed state to: %s\n", device, params);
+ log_error("Snapshot %s changed state to: %s.", device, params);
state->percent_check = 0;
goto out;
}
@@ -181,10 +183,10 @@ void process_event(struct dm_task *dmt,
state->percent_check = (percent / CHECK_STEP) * CHECK_STEP + CHECK_STEP;
if (percent >= WARNING_THRESH) /* Print a warning to syslog. */
- syslog(LOG_WARNING, "Snapshot %s is now %i%% full.\n", device, percent);
+ log_warn("WARNING: Snapshot %s is now %i%% full.", device, percent);
/* Try to extend the snapshot, in accord with user-set policies */
if (!_extend(state->cmd_str))
- syslog(LOG_ERR, "Failed to extend snapshot %s.\n", device);
+ log_error("Failed to extend snapshot %s.", device);
}
out:
@@ -218,7 +220,7 @@ int register_device(const char *device,
state->percent_check = CHECK_MINIMUM;
*private = state;
- syslog(LOG_INFO, "Monitoring snapshot %s\n", device);
+ log_info("Monitoring snapshot %s.", device);
return 1;
bad:
@@ -226,7 +228,7 @@ bad:
dm_pool_destroy(statemem);
dmeventd_lvm2_exit();
out:
- syslog(LOG_ERR, "Failed to monitor snapshot %s.\n", device);
+ log_error("Failed to monitor snapshot %s.", device);
return 0;
}
@@ -239,7 +241,7 @@ int unregister_device(const char *device,
{
struct dso_state *state = *private;
- syslog(LOG_INFO, "No longer monitoring snapshot %s\n", device);
+ log_info("No longer monitoring snapshot %s.", device);
dm_pool_destroy(state->mem);
dmeventd_lvm2_exit();
diff --git a/daemons/dmeventd/plugins/thin/dmeventd_thin.c b/daemons/dmeventd/plugins/thin/dmeventd_thin.c
index 3f057a6..febf554 100644
--- a/daemons/dmeventd/plugins/thin/dmeventd_thin.c
+++ b/daemons/dmeventd/plugins/thin/dmeventd_thin.c
@@ -93,8 +93,8 @@ static int _has_deps(const char *name, int tp_major, int tp_minor, int *dev_mino
{
char dev_name[PATH_MAX];
if (dm_device_get_name(major, minor, 0, dev_name, sizeof(dev_name)))
- syslog(LOG_DEBUG, "Found %s (%u:%u) depends on %s",
- name, major, *dev_minor, dev_name);
+ log_debug("Found %s (%u:%u) depends on %s.",
+ name, major, *dev_minor, dev_name);
}
#endif
r = 1;
@@ -144,7 +144,7 @@ out:
static int _extend(struct dso_state *state)
{
#if THIN_DEBUG
- syslog(LOG_INFO, "dmeventd executes: %s.\n", state->cmd_str);
+ log_info("dmeventd executes: %s.", state->cmd_str);
#endif
return dmeventd_lvm2_run(state->cmd_str);
}
@@ -173,7 +173,7 @@ static int _run(const char *cmd, ...)
va_end(ap);
execvp(cmd, (char **)argv);
- syslog(LOG_ERR, "Failed to execute %s: %s.\n", cmd, strerror(errno));
+ log_sys_error("exec", cmd);
exit(127);
}
@@ -202,11 +202,11 @@ static int _umount_device(char *buffer, unsigned major, unsigned minor,
struct mountinfo_s *data = cb_data;
if ((major == data->info.major) && dm_bit(data->minors, minor)) {
- syslog(LOG_INFO, "Unmounting thin volume %s from %s.\n",
- data->device, target);
+ log_info("Unmounting thin volume %s from %s.",
+ data->device, target);
if (!_run(UMOUNT_COMMAND, "-fl", target, NULL))
- syslog(LOG_ERR, "Failed to umount thin %s from %s: %s.\n",
- data->device, target, strerror(errno));
+ log_error("Failed to umount thin %s from %s: %s.",
+ data->device, target, strerror(errno));
}
return 1;
@@ -230,17 +230,17 @@ static void _umount(struct dm_task *dmt, const char *device)
dmeventd_lvm2_unlock();
if (!(data.minors = dm_bitset_create(NULL, MINORS))) {
- syslog(LOG_ERR, "Failed to allocate bitset. Not unmounting %s.\n", device);
+ log_error("Failed to allocate bitset. Not unmounting %s.", device);
goto out;
}
if (!_find_all_devs(data.minors, data.info.major, data.info.minor)) {
- syslog(LOG_ERR, "Failed to detect mounted volumes for %s.\n", device);
+ log_error("Failed to detect mounted volumes for %s.", device);
goto out;
}
if (!dm_mountinfo_read(_umount_device, &data)) {
- syslog(LOG_ERR, "Could not parse mountinfo file.\n");
+ log_error("Could not parse mountinfo file.");
goto out;
}
@@ -273,21 +273,21 @@ void process_event(struct dm_task *dmt,
dm_get_next_target(dmt, next, &start, &length, &target_type, ¶ms);
if (!target_type || (strcmp(target_type, "thin-pool") != 0)) {
- syslog(LOG_ERR, "Invalid target type.\n");
+ log_error("Invalid target type.");
goto out;
}
if (!dm_get_status_thin_pool(state->mem, params, &tps)) {
- syslog(LOG_ERR, "Failed to parse status.\n");
+ log_error("Failed to parse status.");
_umount(dmt, device);
goto out;
}
#if THIN_DEBUG
- syslog(LOG_INFO, "%p: Got status %" PRIu64 " / %" PRIu64
- " %" PRIu64 " / %" PRIu64 ".\n", state,
- tps->used_metadata_blocks, tps->total_metadata_blocks,
- tps->used_data_blocks, tps->total_data_blocks);
+ log_debug("%p: Got status " FMTu64 " / " FMTu64 " " FMTu64
+ " / " FMTu64 ".", state,
+ tps->used_metadata_blocks, tps->total_metadata_blocks,
+ tps->used_data_blocks, tps->total_data_blocks);
#endif
/* Thin pool size had changed. Clear the threshold. */
@@ -311,12 +311,12 @@ void process_event(struct dm_task *dmt,
/* FIXME: extension of metadata needs to be written! */
if (percent >= WARNING_THRESH) /* Print a warning to syslog. */
- syslog(LOG_WARNING, "Thin metadata %s is now %i%% full.\n",
- device, percent);
+ log_warn("WARNING: Thin metadata %s is now %i%% full.",
+ device, percent);
/* Try to extend the metadata, in accord with user-set policies */
if (!_extend(state)) {
- syslog(LOG_ERR, "Failed to extend thin metadata %s.\n",
- device);
+ log_error("Failed to extend thin metadata %s.",
+ device);
_umount(dmt, device);
}
/* FIXME: hmm READ-ONLY switch should happen in error path */
@@ -331,10 +331,11 @@ void process_event(struct dm_task *dmt,
state->data_percent_check = (percent / CHECK_STEP) * CHECK_STEP + CHECK_STEP;
if (percent >= WARNING_THRESH) /* Print a warning to syslog. */
- syslog(LOG_WARNING, "Thin %s is now %i%% full.\n", device, percent);
+ log_warn("WARNING: Thin %s is now %i%% full.",
+ device, percent);
/* Try to extend the thin data, in accord with user-set policies */
if (!_extend(state)) {
- syslog(LOG_ERR, "Failed to extend thin %s.\n", device);
+ log_error("Failed to extend thin %s.", device);
state->data_percent_check = 0;
_umount(dmt, device);
}
@@ -376,11 +377,11 @@ int register_device(const char *device,
state->data_percent_check = CHECK_MINIMUM;
*private = state;
- syslog(LOG_INFO, "Monitoring thin %s.\n", device);
+ log_info("Monitoring thin %s.", device);
return 1;
bad:
- syslog(LOG_ERR, "Failed to monitor thin %s.\n", device);
+ log_error("Failed to monitor thin %s.", device);
return 0;
}
@@ -393,7 +394,7 @@ int unregister_device(const char *device,
{
struct dso_state *state = *private;
- syslog(LOG_INFO, "No longer monitoring thin %s.\n", device);
+ log_info("No longer monitoring thin %s.", device);
dm_pool_destroy(state->mem);
dmeventd_lvm2_exit();
7 years, 8 months
master - libdmevent: add dm_event_log
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=0641e3a5fd1962...
Commit: 0641e3a5fd19628db0e08fca252c13f40230ffa2
Parent: 11a084cf42e79f130e4389bac57688cfd6657fc1
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Sat Oct 10 16:40:52 2015 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Tue Oct 13 14:40:46 2015 +0200
libdmevent: add dm_event_log
Add dm_event_log() logging function.
Controled by dm_event_log_set().
---
daemons/dmeventd/libdevmapper-event.c | 81 ++++++++++++++++++++++++++++++++-
daemons/dmeventd/libdevmapper-event.h | 21 ++++++++-
2 files changed, 99 insertions(+), 3 deletions(-)
diff --git a/daemons/dmeventd/libdevmapper-event.c b/daemons/dmeventd/libdevmapper-event.c
index 81f18c9..9b04b02 100644
--- a/daemons/dmeventd/libdevmapper-event.c
+++ b/daemons/dmeventd/libdevmapper-event.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2005-2015 Red Hat, Inc. All rights reserved.
*
* This file is part of the device-mapper userspace tools.
*
@@ -12,9 +12,9 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#include "dm-logging.h"
#include "dmlib.h"
#include "libdevmapper-event.h"
-//#include "libmultilog.h"
#include "dmeventd.h"
#include <fcntl.h>
@@ -23,7 +23,11 @@
#include <sys/stat.h>
#include <sys/wait.h>
#include <arpa/inet.h> /* for htonl, ntohl */
+#include <pthread.h>
+#include <syslog.h>
+static int _debug_level = 0;
+static int _use_syslog = 0;
static int _sequence_nr = 0;
struct dm_event_handler {
@@ -823,6 +827,79 @@ int dm_event_get_version(struct dm_event_fifos *fifos, int *version) {
return 1;
}
+void dm_event_log_set(int debug_level, int use_syslog)
+{
+ _debug_level = debug_level;
+ _use_syslog = use_syslog;
+}
+
+void dm_event_log(const char *subsys, int level, const char *file,
+ int line, int dm_errno_or_class,
+ const char *format, va_list ap)
+{
+ static pthread_mutex_t _log_mutex = PTHREAD_MUTEX_INITIALIZER;
+ static time_t start = 0;
+ const char *indent = "";
+ FILE *stream = stdout;
+ int prio = -1;
+ time_t now;
+
+ switch (level & ~(_LOG_STDERR | _LOG_ONCE)) {
+ case _LOG_DEBUG:
+ if (_debug_level < 3)
+ return;
+ prio = LOG_DEBUG;
+ indent = " ";
+ break;
+ case _LOG_INFO:
+ if (_debug_level < 2)
+ return;
+ prio = LOG_INFO;
+ indent = " ";
+ break;
+ case _LOG_NOTICE:
+ if (_debug_level < 1)
+ return;
+ prio = LOG_NOTICE;
+ indent = " ";
+ break;
+ case _LOG_WARN:
+ prio = LOG_WARNING;
+ break;
+ case _LOG_ERR:
+ prio = LOG_ERR;
+ stream = stderr;
+ break;
+ default:
+ prio = LOG_CRIT;
+ }
+
+ /* Serialize to keep lines readable */
+ pthread_mutex_lock(&_log_mutex);
+
+ if (_use_syslog) {
+ vsyslog(prio, format, ap);
+ } else {
+ now = time(NULL);
+ if (!start)
+ start = now;
+ now -= start;
+ fprintf(stream, "[%2d:%02d] %8x:%-6s%s",
+ (int)now / 60, (int)now % 60,
+ // TODO: Maybe use shorter ID
+ // ((int)(pthread_self()) >> 6) & 0xffff,
+ (int)pthread_self(), subsys,
+ (_debug_level > 3) ? "" : indent);
+ if (_debug_level > 3)
+ fprintf(stream, "%28s:%4d %s", file, line, indent);
+ vfprintf(stream, _(format), ap);
+ fputc('\n', stream);
+ fflush(stream);
+ }
+
+ pthread_mutex_unlock(&_log_mutex);
+}
+
#if 0 /* left out for now */
static char *_skip_string(char *src, const int delimiter)
diff --git a/daemons/dmeventd/libdevmapper-event.h b/daemons/dmeventd/libdevmapper-event.h
index 532bebf..a00702a 100644
--- a/daemons/dmeventd/libdevmapper-event.h
+++ b/daemons/dmeventd/libdevmapper-event.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2005-2007 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2005-2015 Red Hat, Inc. All rights reserved.
*
* This file is part of the device-mapper userspace tools.
*
@@ -105,6 +105,25 @@ int dm_event_get_registered_device(struct dm_event_handler *dmevh, int next);
int dm_event_register_handler(const struct dm_event_handler *dmevh);
int dm_event_unregister_handler(const struct dm_event_handler *dmevh);
+/* Set debug level for logging, and whether to log on stdout/stderr or syslog */
+void dm_event_log_set(int debug_level, int use_syslog);
+
+/* Log messages acroding to current debug level */
+__attribute__((format(printf, 6, 0)))
+void dm_event_log(const char *subsys, int level, const char *file,
+ int line, int dm_errno_or_class,
+ const char *format, va_list ap);
+/* Macro to route print_log do dm_event_log() */
+#define DM_EVENT_LOG_FN(subsys) \
+void print_log(int level, const char *file, int line, int dm_errno_or_class,\
+ const char *format, ...)\
+{\
+ va_list ap;\
+ va_start(ap, format);\
+ dm_event_log(subsys, level, file, line, dm_errno_or_class, format, ap);\
+ va_end(ap);\
+}
+
/* Prototypes for DSO interface, see dmeventd.c, struct dso_data for
detailed descriptions. */
// FIXME misuse of bitmask as enum
7 years, 8 months