1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-03 05:18:29 +03:00

systemd: lvm2-activation-generator: use LOG_DEBUG/ERR severity for kmsg

This commit is contained in:
Peter Rajnoha 2013-07-22 14:04:12 +02:00
parent f1d5f6ae81
commit ea333a894e
2 changed files with 21 additions and 15 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.99 - Version 2.02.99 -
=================================== ===================================
Use LOG_DEBUG/ERR msg severity instead default for lvm2-activation-generator.
Support ARG_GROUPABLE with merge_synonym (for --raidwritemostly). Support ARG_GROUPABLE with merge_synonym (for --raidwritemostly).
Fix segfault when reporting raid_syncaction for older kernels. Fix segfault when reporting raid_syncaction for older kernels.
Add LV reporting fields raid_mismatch_count, raid_sync_action, raid_write_behind. Add LV reporting fields raid_mismatch_count, raid_sync_action, raid_write_behind.

View File

@ -16,6 +16,7 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <stdarg.h> #include <stdarg.h>
#include <syslog.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
@ -31,7 +32,7 @@
static char unit_path[PATH_MAX]; static char unit_path[PATH_MAX];
static char target_path[PATH_MAX]; static char target_path[PATH_MAX];
static char message[PATH_MAX]; static char message[PATH_MAX + 3]; /* +3 for '<n>' where n is the log level */
static int kmsg_fd = -1; static int kmsg_fd = -1;
enum { enum {
@ -46,20 +47,23 @@ static const char *unit_names[] = {
[UNIT_NET] = "lvm2-activation-net.service" [UNIT_NET] = "lvm2-activation-net.service"
}; };
__attribute__ ((format(printf, 1, 2))) __attribute__ ((format(printf, 2, 3)))
static void kmsg(const char *format, ...) static void kmsg(int log_level, const char *format, ...)
{ {
va_list ap; va_list ap;
int n; int n;
snprintf(message, 4, "<%d>", log_level);
va_start(ap, format); va_start(ap, format);
n = vsnprintf(message, sizeof(message), format, ap); n = vsnprintf(message + 3, PATH_MAX, format, ap);
va_end(ap); va_end(ap);
if (kmsg_fd < 0 || (n < 0 || ((unsigned) n + 1 > sizeof(message)))) if (kmsg_fd < 0 || (n < 0 || ((unsigned) n + 1 > PATH_MAX)))
return; return;
(void) write(kmsg_fd, message, n + 1); /* The n+4: +3 for "<n>" prefix and +1 for '\0' suffix */
(void) write(kmsg_fd, message, n + 4);
} }
static int lvm_uses_lvmetad(void) static int lvm_uses_lvmetad(void)
@ -68,7 +72,7 @@ static int lvm_uses_lvmetad(void)
int r; int r;
if (!(lvm = lvm_init(NULL))) { if (!(lvm = lvm_init(NULL))) {
kmsg("LVM: Failed to initialize library context for activation generator.\n"); kmsg(LOG_ERR, "LVM: Failed to initialize library context for activation generator.\n");
return 0; return 0;
} }
r = lvm_config_find_bool(lvm, LVM_CONF_USE_LVMETAD, 0); r = lvm_config_find_bool(lvm, LVM_CONF_USE_LVMETAD, 0);
@ -86,7 +90,7 @@ static int register_unit_with_target(const char *dir, const char *unit, const ch
} }
(void) dm_prepare_selinux_context(target_path, S_IFDIR); (void) dm_prepare_selinux_context(target_path, S_IFDIR);
if (mkdir(target_path, 0755) < 0 && errno != EEXIST) { if (mkdir(target_path, 0755) < 0 && errno != EEXIST) {
kmsg("LVM: Failed to create target directory %s: %m.\n", target_path); kmsg(LOG_ERR, "LVM: Failed to create target directory %s: %m.\n", target_path);
r = 0; goto out; r = 0; goto out;
} }
@ -95,7 +99,7 @@ static int register_unit_with_target(const char *dir, const char *unit, const ch
} }
(void) dm_prepare_selinux_context(target_path, S_IFLNK); (void) dm_prepare_selinux_context(target_path, S_IFLNK);
if (symlink(unit_path, target_path) < 0) { if (symlink(unit_path, target_path) < 0) {
kmsg("LVM: Failed to create symlink for unit %s: %m.\n", unit); kmsg(LOG_ERR, "LVM: Failed to create symlink for unit %s: %m.\n", unit);
r = 0; r = 0;
} }
out: out:
@ -113,7 +117,7 @@ static int generate_unit(const char *dir, int unit)
return 0; return 0;
if (!(f = fopen(unit_path, "wxe"))) { if (!(f = fopen(unit_path, "wxe"))) {
kmsg("LVM: Failed to create unit file %s: %m.\n", unit_name); kmsg(LOG_ERR, "LVM: Failed to create unit file %s: %m.\n", unit_name);
return 0; return 0;
} }
@ -148,12 +152,12 @@ static int generate_unit(const char *dir, int unit)
"Type=oneshot\n", f); "Type=oneshot\n", f);
if (fclose(f) < 0) { if (fclose(f) < 0) {
kmsg("LVM: Failed to write unit file %s: %m.\n", unit_name); kmsg(LOG_ERR, "LVM: Failed to write unit file %s: %m.\n", unit_name);
return 0; return 0;
} }
if (!register_unit_with_target(dir, unit_name, target_name)) { if (!register_unit_with_target(dir, unit_name, target_name)) {
kmsg("LVM: Failed to register unit %s with target %s.\n", unit_name, target_name); kmsg(LOG_ERR, "LVM: Failed to register unit %s with target %s.\n", unit_name, target_name);
return 0; return 0;
} }
@ -168,13 +172,13 @@ int main(int argc, char *argv[])
kmsg_fd = open(KMSG_DEV_PATH, O_WRONLY|O_NOCTTY); kmsg_fd = open(KMSG_DEV_PATH, O_WRONLY|O_NOCTTY);
if (argc > 1 && argc != 4) { if (argc > 1 && argc != 4) {
kmsg("LVM: Activation generator takes three or no arguments.\n"); kmsg(LOG_ERR, "LVM: Activation generator takes three or no arguments.\n");
r = EXIT_FAILURE; goto out; r = EXIT_FAILURE; goto out;
} }
/* If lvmetad used, rely on autoactivation instead of direct activation. */ /* If lvmetad used, rely on autoactivation instead of direct activation. */
if (lvm_uses_lvmetad()) { if (lvm_uses_lvmetad()) {
kmsg("LVM: Logical Volume autoactivation enabled.\n"); kmsg(LOG_DEBUG, "LVM: Logical Volume autoactivation enabled.\n");
goto out; goto out;
} }
@ -185,7 +189,8 @@ int main(int argc, char *argv[])
!generate_unit(dir, UNIT_NET)) !generate_unit(dir, UNIT_NET))
r = EXIT_FAILURE; r = EXIT_FAILURE;
out: out:
kmsg("LVM: Activation generator %s.\n", r ? "failed" : "successfully completed"); kmsg(r ? LOG_ERR : LOG_DEBUG, "LVM: Activation generator %s.\n",
r ? "failed" : "successfully completed");
if (kmsg_fd != -1) if (kmsg_fd != -1)
(void) close(kmsg_fd); (void) close(kmsg_fd);
return r; return r;