1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

dmeventd: syslog -> log_xxxxx

Convert logging of dmeventd to libdm logging macros.
This commit is contained in:
Zdenek Kabelac 2015-10-09 21:57:48 +02:00
parent 0641e3a5fd
commit 915f0faac1
8 changed files with 145 additions and 157 deletions

View File

@ -1,5 +1,6 @@
Version 1.02.110 - Version 1.02.110 -
====================================== ======================================
Convert dmeventd to use common logging macro system from libdm.
Return -ENOMEM when device registration fails instead of 0 (=success). Return -ENOMEM when device registration fails instead of 0 (=success).
Enforce writethrough mode for cleaner policy. Enforce writethrough mode for cleaner policy.
Add support for recognition and deactivation of MD devices to blkdeactivate. Add support for recognition and deactivation of MD devices to blkdeactivate.

View File

@ -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. * 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) } else if (thread->status == DM_THREAD_SHUTDOWN && ioctl_errno == EINTR)
ret = DM_WAIT_FATAL; ret = DM_WAIT_FATAL;
else { else {
syslog(LOG_NOTICE, "dm_task_run failed, errno = %d, %s",
ioctl_errno, strerror(ioctl_errno));
if (ioctl_errno == ENXIO) { if (ioctl_errno == ENXIO) {
syslog(LOG_ERR, "%s disappeared, detaching", log_error("%s disappeared, detaching.",
thread->device.name); thread->device.name);
ret = DM_WAIT_FATAL; ret = DM_WAIT_FATAL;
} } else
log_sys_error("dm_task_run", "");
} }
} }
DEBUGLOG("Completed waitevent task for %s", thread->device.uuid); 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"); DEBUGLOG("_monitor_unregister thread cleanup handler running");
if (!_do_unregister_device(thread)) if (!_do_unregister_device(thread))
syslog(LOG_ERR, "%s: %s unregister failed\n", __func__, log_error("%s: %s unregister failed.", __func__,
thread->device.name); thread->device.name);
if (thread->current_task) { if (thread->current_task) {
dm_task_destroy(thread->current_task); dm_task_destroy(thread->current_task);
thread->current_task = NULL; 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))) { if (!(dl = dlopen(data->dso_name, RTLD_NOW))) {
const char *dlerr = dlerror(); const char *dlerr = dlerror();
syslog(LOG_ERR, "dmeventd %s dlopen failed: %s", data->dso_name, log_error("dmeventd %s dlopen failed: %s.",
dlerr); data->dso_name, dlerr);
data->msg->size = data->msg->size =
dm_asprintf(&(data->msg->data), "%s %s dlopen failed: %s", dm_asprintf(&(data->msg->data), "%s %s dlopen failed: %s",
data->id, data->dso_name, dlerr); data->id, data->dso_name, dlerr);
@ -1309,8 +1308,7 @@ static int _open_fifos(struct dm_event_fifos *fifos)
/* Create client fifo. */ /* Create client fifo. */
(void) dm_prepare_selinux_context(fifos->client_path, S_IFIFO); (void) dm_prepare_selinux_context(fifos->client_path, S_IFIFO);
if ((mkfifo(fifos->client_path, 0600) == -1) && errno != EEXIST) { if ((mkfifo(fifos->client_path, 0600) == -1) && errno != EEXIST) {
syslog(LOG_ERR, "%s: Failed to create client fifo %s: %m.\n", log_sys_error("client mkfifo", fifos->client_path);
__func__, fifos->client_path);
(void) dm_prepare_selinux_context(NULL, 0); (void) dm_prepare_selinux_context(NULL, 0);
goto fail; goto fail;
} }
@ -1318,8 +1316,7 @@ static int _open_fifos(struct dm_event_fifos *fifos)
/* Create server fifo. */ /* Create server fifo. */
(void) dm_prepare_selinux_context(fifos->server_path, S_IFIFO); (void) dm_prepare_selinux_context(fifos->server_path, S_IFIFO);
if ((mkfifo(fifos->server_path, 0600) == -1) && errno != EEXIST) { if ((mkfifo(fifos->server_path, 0600) == -1) && errno != EEXIST) {
syslog(LOG_ERR, "%s: Failed to create server fifo %s: %m.\n", log_sys_error("server mkfifo", fifos->server_path);
__func__, fifos->server_path);
(void) dm_prepare_selinux_context(NULL, 0); (void) dm_prepare_selinux_context(NULL, 0);
goto fail; goto fail;
} }
@ -1328,58 +1325,53 @@ static int _open_fifos(struct dm_event_fifos *fifos)
/* Warn about wrong permissions if applicable */ /* Warn about wrong permissions if applicable */
if ((!stat(fifos->client_path, &st)) && (st.st_mode & 0777) != 0600) if ((!stat(fifos->client_path, &st)) && (st.st_mode & 0777) != 0600)
syslog(LOG_WARNING, "Fixing wrong permissions on %s: %m.\n", log_warn("WARNING: Fixing wrong permissions on %s: %s.\n",
fifos->client_path); fifos->client_path, strerror(errno));
if ((!stat(fifos->server_path, &st)) && (st.st_mode & 0777) != 0600) if ((!stat(fifos->server_path, &st)) && (st.st_mode & 0777) != 0600)
syslog(LOG_WARNING, "Fixing wrong permissions on %s: %m.\n", log_warn("WARNING: Fixing wrong permissions on %s: %s.\n",
fifos->server_path); fifos->server_path, strerror(errno));
/* If they were already there, make sure permissions are ok. */ /* If they were already there, make sure permissions are ok. */
if (chmod(fifos->client_path, 0600)) { if (chmod(fifos->client_path, 0600)) {
syslog(LOG_ERR, "Unable to set correct file permissions on %s: %m.\n", log_sys_error("chmod", fifos->client_path);
fifos->client_path);
goto fail; goto fail;
} }
if (chmod(fifos->server_path, 0600)) { if (chmod(fifos->server_path, 0600)) {
syslog(LOG_ERR, "Unable to set correct file permissions on %s: %m.\n", log_sys_error("chmod", fifos->server_path);
fifos->server_path);
goto fail; goto fail;
} }
/* Need to open read+write or we will block or fail */ /* Need to open read+write or we will block or fail */
if ((fifos->server = open(fifos->server_path, O_RDWR)) < 0) { if ((fifos->server = open(fifos->server_path, O_RDWR)) < 0) {
syslog(LOG_ERR, "Failed to open fifo server %s: %m.\n", log_sys_error("server open", fifos->server_path);
fifos->server_path);
goto fail; goto fail;
} }
if (fcntl(fifos->server, F_SETFD, FD_CLOEXEC) < 0) { if (fcntl(fifos->server, F_SETFD, FD_CLOEXEC) < 0) {
syslog(LOG_ERR, "Failed to set FD_CLOEXEC for fifo server %s: %m.\n", log_sys_error("fcntl(FD_CLOEXEC)", fifos->server_path);
fifos->server_path);
goto fail; goto fail;
} }
/* Need to open read+write for select() to work. */ /* Need to open read+write for select() to work. */
if ((fifos->client = open(fifos->client_path, O_RDWR)) < 0) { 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; goto fail;
} }
if (fcntl(fifos->client, F_SETFD, FD_CLOEXEC) < 0) { if (fcntl(fifos->client, F_SETFD, FD_CLOEXEC) < 0) {
syslog(LOG_ERR, "Failed to set FD_CLOEXEC for fifo client %s: %m.\n", log_sys_error("fcntl(FD_CLOEXEC)", fifos->client_path);
fifos->client_path);
goto fail; goto fail;
} }
return 1; return 1;
fail: fail:
if (fifos->server >= 0 && close(fifos->server)) 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)) 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; return 0;
} }
@ -1591,7 +1583,7 @@ static void _process_request(struct dm_event_fifos *fifos)
if (die) { if (die) {
if (unlink(DMEVENTD_PIDFILE)) if (unlink(DMEVENTD_PIDFILE))
perror(DMEVENTD_PIDFILE ": unlink failed"); log_sys_error("unlink", DMEVENTD_PIDFILE);
_exit(0); _exit(0);
} }
} }
@ -1637,15 +1629,14 @@ static void _cleanup_unused_threads(void)
if (ret == ESRCH) { if (ret == ESRCH) {
thread->status = DM_THREAD_DONE; thread->status = DM_THREAD_DONE;
} else if (ret) { } else if (ret) {
syslog(LOG_ERR, "Unable to terminate thread: %s", log_error("Unable to terminate thread: %s",
strerror(ret)); strerror(ret));
} }
break; break;
} }
dm_list_del(l); dm_list_del(l);
syslog(LOG_ERR, log_error("thread can't be on unused list unless !thread->events");
"thread can't be on unused list unless !thread->events");
thread->status = DM_THREAD_RUNNING; thread->status = DM_THREAD_RUNNING;
LINK_THREAD(thread); LINK_THREAD(thread);
@ -1665,7 +1656,7 @@ static void _cleanup_unused_threads(void)
_unlock_mutex(); _unlock_mutex();
if (join_ret) 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))) 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; FILE *fp;
if (!(fp = fopen(oom_adj_path, "w"))) { if (!(fp = fopen(oom_adj_path, "w"))) {
perror("oom_adj: fopen failed"); log_sys_error("open", oom_adj_path);
return 0; return 0;
} }
fprintf(fp, "%i", val); fprintf(fp, "%i", val);
if (dm_fclose(fp)) if (dm_fclose(fp))
perror("oom_adj: fclose failed"); log_sys_error("fclose", oom_adj_path);
return 1; return 1;
} }
@ -1730,14 +1721,11 @@ static int _protect_against_oom_killer(void)
if (stat(OOM_ADJ_FILE, &st) == -1) { if (stat(OOM_ADJ_FILE, &st) == -1) {
if (errno != ENOENT) if (errno != ENOENT)
perror(OOM_ADJ_FILE ": stat failed"); log_sys_error("stat", OOM_ADJ_FILE);
/* Try old oom_adj interface as a fallback */ /* Try old oom_adj interface as a fallback */
if (stat(OOM_ADJ_FILE_OLD, &st) == -1) { if (stat(OOM_ADJ_FILE_OLD, &st) == -1) {
if (errno == ENOENT) log_sys_error("stat", OOM_ADJ_FILE_OLD);
perror(OOM_ADJ_FILE_OLD " not found");
else
perror(OOM_ADJ_FILE_OLD ": stat failed");
return 1; return 1;
} }
@ -1826,14 +1814,14 @@ out:
static void _remove_files_on_exit(void) static void _remove_files_on_exit(void)
{ {
if (unlink(DMEVENTD_PIDFILE)) if (unlink(DMEVENTD_PIDFILE))
perror(DMEVENTD_PIDFILE ": unlink failed"); log_sys_error("unlink", DMEVENTD_PIDFILE);
if (!_systemd_activation) { if (!_systemd_activation) {
if (unlink(DM_EVENT_FIFO_CLIENT)) 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)) 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()) { switch (pid = fork()) {
case -1: case -1:
perror("fork failed:"); log_sys_error("fork", "");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
case 0: /* Child */ case 0: /* Child */
@ -2167,7 +2155,7 @@ int main(int argc, char *argv[])
#ifdef __linux__ #ifdef __linux__
/* Systemd has adjusted oom killer for us already */ /* Systemd has adjusted oom killer for us already */
if (!_systemd_activation && !_protect_against_oom_killer()) 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 #endif
_init_thread_signals(); _init_thread_signals();
@ -2185,7 +2173,7 @@ int main(int argc, char *argv[])
/* Signal parent, letting them know we are ready to go. */ /* Signal parent, letting them know we are ready to go. */
if (!_foreground) if (!_foreground)
kill(getppid(), SIGTERM); kill(getppid(), SIGTERM);
syslog(LOG_NOTICE, "dmeventd ready for processing."); log_notice("dmeventd ready for processing.");
if (_initial_registrations) if (_initial_registrations)
_process_initial_registrations(); _process_initial_registrations();
@ -2204,8 +2192,8 @@ int main(int argc, char *argv[])
_unlock_mutex(); _unlock_mutex();
if (nothreads) if (nothreads)
break; break;
syslog(LOG_ERR, "There are still devices being monitored."); log_error("There are still devices being monitored.");
syslog(LOG_ERR, "Refusing to exit."); log_error("Refusing to exit.");
} }
_process_request(&fifos); _process_request(&fifos);
_cleanup_unused_threads(); _cleanup_unused_threads();
@ -2215,7 +2203,7 @@ int main(int argc, char *argv[])
pthread_mutex_destroy(&_global_mutex); pthread_mutex_destroy(&_global_mutex);
syslog(LOG_NOTICE, "dmeventd shutting down."); log_notice("dmeventd shutting down.");
closelog(); closelog();
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);

View File

@ -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) || if ((sscanf(msg->data, "%d:%d", &pid, &seq_nr) != 2) ||
(pid != getpid()) || (seq_nr != _sequence_nr)) { (pid != getpid()) || (seq_nr != _sequence_nr)) {
log_error("Ignoring out-of-sequence reply from dmeventd. " 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); _sequence_nr, msg->data);
return 0; return 0;
} }
@ -233,7 +233,7 @@ static int _daemon_read(struct dm_event_fifos *fifos,
FD_SET(fifos->server, &fds); FD_SET(fifos->server, &fds);
ret = select(fifos->server + 1, &fds, NULL, NULL, &tval); ret = select(fifos->server + 1, &fds, NULL, NULL, &tval);
if (ret < 0 && errno != EINTR) { if (ret < 0 && errno != EINTR) {
log_error("Unable to read from event server"); log_error("Unable to read from event server.");
return 0; return 0;
} }
if ((ret == 0) && (i > 4) && !bytes) { if ((ret == 0) && (i > 4) && !bytes) {
@ -299,7 +299,7 @@ static int _daemon_write(struct dm_event_fifos *fifos,
if (ret < 0) { if (ret < 0) {
if (errno == EINTR) if (errno == EINTR)
continue; continue;
log_error("Unable to talk to event daemon"); log_error("Unable to talk to event daemon.");
return 0; return 0;
} }
if (ret == 0) if (ret == 0)
@ -308,7 +308,7 @@ static int _daemon_write(struct dm_event_fifos *fifos,
if (ret < 0) { if (ret < 0) {
if ((errno == EINTR) || (errno == EAGAIN)) if ((errno == EINTR) || (errno == EAGAIN))
continue; continue;
log_error("Unable to talk to event daemon"); log_error("Unable to talk to event daemon.");
return 0; return 0;
} }
} }
@ -320,7 +320,7 @@ static int _daemon_write(struct dm_event_fifos *fifos,
FD_SET(fifos->client, &fds); FD_SET(fifos->client, &fds);
ret = select(fifos->client + 1, NULL, &fds, NULL, NULL); ret = select(fifos->client + 1, NULL, &fds, NULL, NULL);
if ((ret < 0) && (errno != EINTR)) { if ((ret < 0) && (errno != EINTR)) {
log_error("Unable to talk to event daemon"); log_error("Unable to talk to event daemon.");
return 0; return 0;
} }
} while (ret < 1); } while (ret < 1);
@ -330,7 +330,7 @@ static int _daemon_write(struct dm_event_fifos *fifos,
if ((errno == EINTR) || (errno == EAGAIN)) if ((errno == EINTR) || (errno == EAGAIN))
continue; continue;
else { else {
log_error("Unable to talk to event daemon"); log_error("Unable to talk to event daemon.");
return 0; return 0;
} }
} }
@ -360,7 +360,7 @@ int daemon_talk(struct dm_event_fifos *fifos,
getpid(), _sequence_nr, getpid(), _sequence_nr,
dso_name ? : "-", dev_name ? : "-", evmask, timeout))) dso_name ? : "-", dev_name ? : "-", evmask, timeout)))
< 0) { < 0) {
log_error("_daemon_talk: message allocation failed"); log_error("_daemon_talk: message allocation failed.");
return -ENOMEM; return -ENOMEM;
} }
msg->cmd = cmd; msg->cmd = cmd;
@ -448,11 +448,11 @@ static int _start_daemon(char *dmeventd_path, struct dm_event_fifos *fifos)
else if (!pid) { else if (!pid) {
execvp(args[0], args); 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); _exit(EXIT_FAILURE);
} else { } else {
if (waitpid(pid, &status, 0) < 0) if (waitpid(pid, &status, 0) < 0)
log_error("Unable to start dmeventd: %s", log_error("Unable to start dmeventd: %s.",
strerror(errno)); strerror(errno));
else if (WEXITSTATUS(status)) else if (WEXITSTATUS(status))
log_error("Unable to start dmeventd."); 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; struct dm_info info;
if (!(dmt = dm_task_create(DM_DEVICE_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; 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 */ /* FIXME Add name or uuid or devno to messages */
if (!dm_task_run(dmt)) { 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; goto bad;
} }
if (!dm_task_get_info(dmt, &info)) { 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; goto bad;
} }
if (!info.exists) { 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->uuid && dmevh->dev_name) ? dmevh->dev_name : "", (!dmevh->uuid && dmevh->dev_name) ? dmevh->dev_name : "",
(!dmevh->uuid && !dmevh->dev_name && dmevh->major > 0) ? "(" : "", (!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-lvm2snapshot.so") &&
!strstr(dmevh->dso, "libdevmapper-event-lvm2mirror.so") && !strstr(dmevh->dso, "libdevmapper-event-lvm2mirror.so") &&
!strstr(dmevh->dso, "libdevmapper-event-lvm2raid.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, if ((err = _do_event(DM_EVENT_CMD_REGISTER_FOR_EVENT, dmevh->dmeventd_path, &msg,
dmevh->dso, uuid, dmevh->mask, dmevh->timeout)) < 0) { 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), dm_task_get_name(dmt),
msg.data ? msg.data : strerror(-err)); msg.data ? msg.data : strerror(-err));
ret = 0; 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, if ((err = _do_event(DM_EVENT_CMD_UNREGISTER_FOR_EVENT, dmevh->dmeventd_path, &msg,
dmevh->dso, uuid, dmevh->mask, dmevh->timeout)) < 0) { 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), dm_task_get_name(dmt),
msg.data ? msg.data : strerror(-err)); msg.data ? msg.data : strerror(-err));
ret = 0; ret = 0;
@ -933,7 +933,7 @@ int dm_event_get_timeout(const char *device_path, uint32_t *timeout)
0, 0))) { 0, 0))) {
char *p = _skip_string(msg.data, ' '); char *p = _skip_string(msg.data, ' ');
if (!p) { if (!p) {
log_error("malformed reply from dmeventd '%s'\n", log_error("Malformed reply from dmeventd '%s'.",
msg.data); msg.data);
dm_free(msg.data); dm_free(msg.data);
return -EIO; return -EIO;

View File

@ -155,8 +155,8 @@ int dmeventd_lvm2_command(struct dm_pool *mem, char *buffer, size_t size,
int r; int r;
if (!dm_split_lvm_name(mem, device, &vg, &lv, &layer)) { if (!dm_split_lvm_name(mem, device, &vg, &lv, &layer)) {
syslog(LOG_ERR, "Unable to determine VG name from %s.\n", log_error("Unable to determine VG name from %s.",
device); device);
return 0; return 0;
} }
@ -170,7 +170,7 @@ int dmeventd_lvm2_command(struct dm_pool *mem, char *buffer, size_t size,
dm_pool_free(mem, vg); dm_pool_free(mem, vg);
if (r < 0) { 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; return 0;
} }

View File

@ -39,18 +39,15 @@ static int _process_status_code(const char status_code, const char *dev_name,
* U => Unclassified failure (bug) * U => Unclassified failure (bug)
*/ */
if (status_code == 'F') { if (status_code == 'F') {
syslog(LOG_ERR, "%s device %s flush failed.", log_error("%s device %s flush failed.", dev_type, dev_name);
dev_type, dev_name);
r = ME_FAILURE; r = ME_FAILURE;
} else if (status_code == 'S') } else if (status_code == 'S')
syslog(LOG_ERR, "%s device %s sync failed.", log_error("%s device %s sync failed.", dev_type, dev_name);
dev_type, dev_name);
else if (status_code == 'R') else if (status_code == 'R')
syslog(LOG_ERR, "%s device %s read failed.", log_error("%s device %s read failed.", dev_type, dev_name);
dev_type, dev_name);
else if (status_code != 'A') { else if (status_code != 'A') {
syslog(LOG_ERR, "%s device %s has failed (%c).", log_error("%s device %s has failed (%c).",
dev_type, dev_name, status_code); dev_type, dev_name, status_code);
r = ME_FAILURE; r = ME_FAILURE;
} }
@ -125,7 +122,8 @@ out:
out_parse: out_parse:
dm_free(args); dm_free(args);
syslog(LOG_ERR, "Unable to parse mirror status string."); log_error("Unable to parse mirror status string.");
return ME_IGNORE; return ME_IGNORE;
} }
@ -142,7 +140,7 @@ static int _remove_failed_devices(const char *device)
r = dmeventd_lvm2_run(cmd_str); r = dmeventd_lvm2_run(cmd_str);
if (!r) 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), if (!dmeventd_lvm2_command(dmeventd_lvm2_pool(), cmd_str, sizeof(cmd_str),
"lvconvert --config devices{ignore_suspended_devices=1} " "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 */ /* if repair goes OK, report success even if lvscan has failed */
r = dmeventd_lvm2_run(cmd_str); r = dmeventd_lvm2_run(cmd_str);
syslog(LOG_INFO, "Repair of mirrored device %s %s.", device, log_info("Repair of mirrored device %s %s.", device,
(r) ? "finished successfully" : "failed"); (r) ? "finished successfully" : "failed");
return (r) ? 0 : -1; return (r) ? 0 : -1;
} }
@ -175,12 +173,12 @@ void process_event(struct dm_task *dmt,
&target_type, &params); &target_type, &params);
if (!target_type) { if (!target_type) {
syslog(LOG_INFO, "%s mapping lost.", device); log_info("%s mapping lost.", device);
continue; continue;
} }
if (strcmp(target_type, "mirror")) { if (strcmp(target_type, "mirror")) {
syslog(LOG_INFO, "%s has unmirrored portion.", device); log_info("%s has unmirrored portion.", device);
continue; continue;
} }
@ -190,25 +188,25 @@ void process_event(struct dm_task *dmt,
_part_ of the device is in sync _part_ of the device is in sync
Also, this is not an error Also, this is not an error
*/ */
syslog(LOG_NOTICE, "%s is now in-sync.", device); log_notice("%s is now in-sync.", device);
break; break;
case ME_FAILURE: case ME_FAILURE:
syslog(LOG_ERR, "Device failure in %s.", device); log_error("Device failure in %s.", device);
if (_remove_failed_devices(device)) if (_remove_failed_devices(device))
/* FIXME Why are all the error return codes unused? Get rid of them? */ /* FIXME Why are all the error return codes unused? Get rid of them? */
syslog(LOG_ERR, "Failed to remove faulty devices in %s.", log_error("Failed to remove faulty devices in %s.",
device); device);
/* Should check before warning user that device is now linear /* Should check before warning user that device is now linear
else else
syslog(LOG_NOTICE, "%s is now a linear device.\n", log_notice("%s is now a linear device.",
device); device);
*/ */
break; break;
case ME_IGNORE: case ME_IGNORE:
break; break;
default: default:
/* FIXME Provide value then! */ /* FIXME Provide value then! */
syslog(LOG_INFO, "Unknown event received."); log_info("Unknown event received.");
} }
} while (next); } while (next);
@ -224,7 +222,7 @@ int register_device(const char *device,
if (!dmeventd_lvm2_init()) if (!dmeventd_lvm2_init())
return 0; return 0;
syslog(LOG_INFO, "Monitoring mirror device %s for events.", device); log_info("Monitoring mirror device %s for events.", device);
return 1; return 1;
} }
@ -235,8 +233,8 @@ int unregister_device(const char *device,
int minor __attribute__((unused)), int minor __attribute__((unused)),
void **unused __attribute__((unused))) void **unused __attribute__((unused)))
{ {
syslog(LOG_INFO, "No longer monitoring mirror device %s for events.", log_info("No longer monitoring mirror device %s for events.",
device); device);
dmeventd_lvm2_exit(); dmeventd_lvm2_exit();
return 1; return 1;

View File

@ -39,7 +39,7 @@ static int run_repair(const char *device)
r = dmeventd_lvm2_run(cmd_str); r = dmeventd_lvm2_run(cmd_str);
if (!r) 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), if (!dmeventd_lvm2_command(dmeventd_lvm2_pool(), cmd_str, sizeof(cmd_str),
"lvconvert --config devices{ignore_suspended_devices=1} " "lvconvert --config devices{ignore_suspended_devices=1} "
@ -50,7 +50,7 @@ static int run_repair(const char *device)
r = dmeventd_lvm2_run(cmd_str); r = dmeventd_lvm2_run(cmd_str);
if (!r) 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; return (r) ? 0 : -1;
} }
@ -69,8 +69,7 @@ static int _process_raid_event(char *params, const char *device)
* <health chars> <resync ratio> * <health chars> <resync ratio>
*/ */
if (!dm_split_words(params, 4, 0, a)) { if (!dm_split_words(params, 4, 0, a)) {
syslog(LOG_ERR, "Failed to process status line for %s\n", log_error("Failed to process status line for %s.", device);
device);
return -EINVAL; return -EINVAL;
} }
raid_type = a[0]; raid_type = a[0];
@ -79,8 +78,8 @@ static int _process_raid_event(char *params, const char *device)
resync_ratio = a[3]; resync_ratio = a[3];
if (!(n = atoi(num_devices))) { if (!(n = atoi(num_devices))) {
syslog(LOG_ERR, "Failed to parse number of devices for %s: %s", log_error("Failed to parse number of devices for %s: %s.",
device, num_devices); device, num_devices);
return -EINVAL; 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 */ /* Device is 'a'live, but not yet in-sync */
break; break;
case 'D': case 'D':
syslog(LOG_ERR, log_error("Device #%d of %s array, %s, has failed.",
"Device #%d of %s array, %s, has failed.", i, raid_type, device);
i, raid_type, device);
failure++; failure++;
break; break;
default: default:
@ -107,13 +105,13 @@ static int _process_raid_event(char *params, const char *device)
p = strstr(resync_ratio, "/"); p = strstr(resync_ratio, "/");
if (!p) { if (!p) {
syslog(LOG_ERR, "Failed to parse resync_ratio for %s: %s", log_error("Failed to parse resync_ratio for %s: %s.",
device, resync_ratio); device, resync_ratio);
return -EINVAL; return -EINVAL;
} }
p[0] = '\0'; p[0] = '\0';
syslog(LOG_INFO, "%s array, %s, is %s in-sync.", log_info("%s array, %s, is %s in-sync.",
raid_type, device, strcmp(resync_ratio, p+1) ? "not" : "now"); raid_type, device, strcmp(resync_ratio, p+1) ? "not" : "now");
return 0; return 0;
} }
@ -135,18 +133,18 @@ void process_event(struct dm_task *dmt,
&target_type, &params); &target_type, &params);
if (!target_type) { if (!target_type) {
syslog(LOG_INFO, "%s mapping lost.", device); log_info("%s mapping lost.", device);
continue; continue;
} }
if (strcmp(target_type, "raid")) { if (strcmp(target_type, "raid")) {
syslog(LOG_INFO, "%s has non-raid portion.", device); log_info("%s has non-raid portion.", device);
continue; continue;
} }
if (_process_raid_event(params, device)) if (_process_raid_event(params, device))
syslog(LOG_ERR, "Failed to process event for %s", log_error("Failed to process event for %s.",
device); device);
} while (next); } while (next);
dmeventd_lvm2_unlock(); dmeventd_lvm2_unlock();
@ -161,7 +159,7 @@ int register_device(const char *device,
if (!dmeventd_lvm2_init()) if (!dmeventd_lvm2_init())
return 0; return 0;
syslog(LOG_INFO, "Monitoring RAID device %s for events.", device); log_info("Monitoring RAID device %s for events.", device);
return 1; return 1;
} }
@ -172,8 +170,8 @@ int unregister_device(const char *device,
int minor __attribute__((unused)), int minor __attribute__((unused)),
void **unused __attribute__((unused))) void **unused __attribute__((unused)))
{ {
syslog(LOG_INFO, "No longer monitoring RAID device %s for events.", log_info("No longer monitoring RAID device %s for events.",
device); device);
dmeventd_lvm2_exit(); dmeventd_lvm2_exit();
return 1; return 1;

View File

@ -62,7 +62,7 @@ static int _run(const char *cmd, ...)
va_end(ap); va_end(ap);
execvp(cmd, (char **)argv); execvp(cmd, (char **)argv);
syslog(LOG_ERR, "Failed to execute %s: %s.\n", cmd, strerror(errno)); log_sys_error("exec", cmd);
exit(127); exit(127);
} }
@ -90,9 +90,11 @@ static void _umount(const char *device, int major, int minor)
char buffer[4096]; char buffer[4096];
char *words[3]; char *words[3];
struct stat st; struct stat st;
const char procmounts[] = "/proc/mounts";
if (!(mounts = fopen("/proc/mounts", "r"))) { if (!(mounts = fopen(procmounts, "r"))) {
syslog(LOG_ERR, "Could not read /proc/mounts. Not umounting %s.\n", device); log_sys_error("fopen", procmounts);
log_error("Not umounting %s.", device);
return; return;
} }
@ -112,15 +114,15 @@ static void _umount(const char *device, int major, int minor)
if (S_ISBLK(st.st_mode) && if (S_ISBLK(st.st_mode) &&
major(st.st_rdev) == major && major(st.st_rdev) == major &&
minor(st.st_rdev) == minor) { minor(st.st_rdev) == minor) {
syslog(LOG_ERR, "Unmounting invalid snapshot %s from %s.\n", device, words[1]); log_error("Unmounting invalid snapshot %s from %s.", device, words[1]);
if (!_run(UMOUNT_COMMAND, "-fl", words[1], NULL)) if (!_run(UMOUNT_COMMAND, "-fl", words[1], NULL))
syslog(LOG_ERR, "Failed to umount snapshot %s from %s: %s.\n", log_error("Failed to umount snapshot %s from %s: %s.",
device, words[1], strerror(errno)); device, words[1], strerror(errno));
} }
} }
if (fclose(mounts)) if (fclose(mounts))
syslog(LOG_ERR, "Failed to close /proc/mounts.\n"); log_sys_error("close", procmounts);
} }
void process_event(struct dm_task *dmt, 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. * the status string. Report the full status string to syslog.
*/ */
if (status->invalid || !status->total_sectors) { 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; state->percent_check = 0;
goto out; goto out;
} }
@ -181,10 +183,10 @@ void process_event(struct dm_task *dmt,
state->percent_check = (percent / CHECK_STEP) * CHECK_STEP + CHECK_STEP; state->percent_check = (percent / CHECK_STEP) * CHECK_STEP + CHECK_STEP;
if (percent >= WARNING_THRESH) /* Print a warning to syslog. */ 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 */ /* Try to extend the snapshot, in accord with user-set policies */
if (!_extend(state->cmd_str)) if (!_extend(state->cmd_str))
syslog(LOG_ERR, "Failed to extend snapshot %s.\n", device); log_error("Failed to extend snapshot %s.", device);
} }
out: out:
@ -218,7 +220,7 @@ int register_device(const char *device,
state->percent_check = CHECK_MINIMUM; state->percent_check = CHECK_MINIMUM;
*private = state; *private = state;
syslog(LOG_INFO, "Monitoring snapshot %s\n", device); log_info("Monitoring snapshot %s.", device);
return 1; return 1;
bad: bad:
@ -226,7 +228,7 @@ bad:
dm_pool_destroy(statemem); dm_pool_destroy(statemem);
dmeventd_lvm2_exit(); dmeventd_lvm2_exit();
out: out:
syslog(LOG_ERR, "Failed to monitor snapshot %s.\n", device); log_error("Failed to monitor snapshot %s.", device);
return 0; return 0;
} }
@ -239,7 +241,7 @@ int unregister_device(const char *device,
{ {
struct dso_state *state = *private; 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); dm_pool_destroy(state->mem);
dmeventd_lvm2_exit(); dmeventd_lvm2_exit();

View File

@ -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]; char dev_name[PATH_MAX];
if (dm_device_get_name(major, minor, 0, dev_name, sizeof(dev_name))) if (dm_device_get_name(major, minor, 0, dev_name, sizeof(dev_name)))
syslog(LOG_DEBUG, "Found %s (%u:%u) depends on %s", log_debug("Found %s (%u:%u) depends on %s.",
name, major, *dev_minor, dev_name); name, major, *dev_minor, dev_name);
} }
#endif #endif
r = 1; r = 1;
@ -144,7 +144,7 @@ out:
static int _extend(struct dso_state *state) static int _extend(struct dso_state *state)
{ {
#if THIN_DEBUG #if THIN_DEBUG
syslog(LOG_INFO, "dmeventd executes: %s.\n", state->cmd_str); log_info("dmeventd executes: %s.", state->cmd_str);
#endif #endif
return dmeventd_lvm2_run(state->cmd_str); return dmeventd_lvm2_run(state->cmd_str);
} }
@ -173,7 +173,7 @@ static int _run(const char *cmd, ...)
va_end(ap); va_end(ap);
execvp(cmd, (char **)argv); execvp(cmd, (char **)argv);
syslog(LOG_ERR, "Failed to execute %s: %s.\n", cmd, strerror(errno)); log_sys_error("exec", cmd);
exit(127); exit(127);
} }
@ -202,11 +202,11 @@ static int _umount_device(char *buffer, unsigned major, unsigned minor,
struct mountinfo_s *data = cb_data; struct mountinfo_s *data = cb_data;
if ((major == data->info.major) && dm_bit(data->minors, minor)) { if ((major == data->info.major) && dm_bit(data->minors, minor)) {
syslog(LOG_INFO, "Unmounting thin volume %s from %s.\n", log_info("Unmounting thin volume %s from %s.",
data->device, target); data->device, target);
if (!_run(UMOUNT_COMMAND, "-fl", target, NULL)) if (!_run(UMOUNT_COMMAND, "-fl", target, NULL))
syslog(LOG_ERR, "Failed to umount thin %s from %s: %s.\n", log_error("Failed to umount thin %s from %s: %s.",
data->device, target, strerror(errno)); data->device, target, strerror(errno));
} }
return 1; return 1;
@ -230,17 +230,17 @@ static void _umount(struct dm_task *dmt, const char *device)
dmeventd_lvm2_unlock(); dmeventd_lvm2_unlock();
if (!(data.minors = dm_bitset_create(NULL, MINORS))) { 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; goto out;
} }
if (!_find_all_devs(data.minors, data.info.major, data.info.minor)) { 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; goto out;
} }
if (!dm_mountinfo_read(_umount_device, &data)) { 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; goto out;
} }
@ -273,21 +273,21 @@ void process_event(struct dm_task *dmt,
dm_get_next_target(dmt, next, &start, &length, &target_type, &params); dm_get_next_target(dmt, next, &start, &length, &target_type, &params);
if (!target_type || (strcmp(target_type, "thin-pool") != 0)) { if (!target_type || (strcmp(target_type, "thin-pool") != 0)) {
syslog(LOG_ERR, "Invalid target type.\n"); log_error("Invalid target type.");
goto out; goto out;
} }
if (!dm_get_status_thin_pool(state->mem, params, &tps)) { 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); _umount(dmt, device);
goto out; goto out;
} }
#if THIN_DEBUG #if THIN_DEBUG
syslog(LOG_INFO, "%p: Got status %" PRIu64 " / %" PRIu64 log_debug("%p: Got status " FMTu64 " / " FMTu64 " " FMTu64
" %" PRIu64 " / %" PRIu64 ".\n", state, " / " FMTu64 ".", state,
tps->used_metadata_blocks, tps->total_metadata_blocks, tps->used_metadata_blocks, tps->total_metadata_blocks,
tps->used_data_blocks, tps->total_data_blocks); tps->used_data_blocks, tps->total_data_blocks);
#endif #endif
/* Thin pool size had changed. Clear the threshold. */ /* 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! */ /* FIXME: extension of metadata needs to be written! */
if (percent >= WARNING_THRESH) /* Print a warning to syslog. */ if (percent >= WARNING_THRESH) /* Print a warning to syslog. */
syslog(LOG_WARNING, "Thin metadata %s is now %i%% full.\n", log_warn("WARNING: Thin metadata %s is now %i%% full.",
device, percent); device, percent);
/* Try to extend the metadata, in accord with user-set policies */ /* Try to extend the metadata, in accord with user-set policies */
if (!_extend(state)) { if (!_extend(state)) {
syslog(LOG_ERR, "Failed to extend thin metadata %s.\n", log_error("Failed to extend thin metadata %s.",
device); device);
_umount(dmt, device); _umount(dmt, device);
} }
/* FIXME: hmm READ-ONLY switch should happen in error path */ /* 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; state->data_percent_check = (percent / CHECK_STEP) * CHECK_STEP + CHECK_STEP;
if (percent >= WARNING_THRESH) /* Print a warning to syslog. */ 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 */ /* Try to extend the thin data, in accord with user-set policies */
if (!_extend(state)) { 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; state->data_percent_check = 0;
_umount(dmt, device); _umount(dmt, device);
} }
@ -376,11 +377,11 @@ int register_device(const char *device,
state->data_percent_check = CHECK_MINIMUM; state->data_percent_check = CHECK_MINIMUM;
*private = state; *private = state;
syslog(LOG_INFO, "Monitoring thin %s.\n", device); log_info("Monitoring thin %s.", device);
return 1; return 1;
bad: bad:
syslog(LOG_ERR, "Failed to monitor thin %s.\n", device); log_error("Failed to monitor thin %s.", device);
return 0; return 0;
} }
@ -393,7 +394,7 @@ int unregister_device(const char *device,
{ {
struct dso_state *state = *private; 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); dm_pool_destroy(state->mem);
dmeventd_lvm2_exit(); dmeventd_lvm2_exit();