diff options
author | David Teigland <teigland@redhat.com> | 2016-02-22 09:42:03 -0600 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2016-03-04 16:40:06 -0600 |
commit | ce7b7aeea224b5d976b0e5c2aa000144640c15cb (patch) | |
tree | 2e77d808a01acb6895d60c29b07bc699a61df5f4 | |
parent | 7b15ca5c9ac3645b8d714014f89dbcd6731b2b04 (diff) | |
download | lvm2-ce7b7aeea224b5d976b0e5c2aa000144640c15cb.tar.gz |
lvmnotify: add dbus notification
When a command modifies a PV or VG, it will send a
dbus notification when the command is finished.
-rw-r--r-- | configure.in | 23 | ||||
-rw-r--r-- | include/.symlinks.in | 1 | ||||
-rw-r--r-- | lib/Makefile.in | 2 | ||||
-rw-r--r-- | lib/commands/toolcontext.h | 3 | ||||
-rw-r--r-- | lib/metadata/metadata.c | 5 | ||||
-rw-r--r-- | lib/notify/lvmnotify.c | 103 | ||||
-rw-r--r-- | lib/notify/lvmnotify.h | 20 | ||||
-rw-r--r-- | tools/lvmcmdline.c | 3 | ||||
-rw-r--r-- | tools/pvchange.c | 2 | ||||
-rw-r--r-- | tools/pvresize.c | 2 | ||||
-rw-r--r-- | tools/toollib.c | 4 | ||||
-rw-r--r-- | tools/tools.h | 1 |
12 files changed, 169 insertions, 0 deletions
diff --git a/configure.in b/configure.in index e8723f4da..33cd0fece 100644 --- a/configure.in +++ b/configure.in @@ -1269,6 +1269,28 @@ AC_DEFINE_UNQUOTED(DEFAULT_USE_LVMPOLLD, [$DEFAULT_USE_LVMPOLLD], [Use lvmpolld by default.]) ################################################################################ +dnl -- Build notifydbus +AC_MSG_CHECKING(whether to build notifydbus) +AC_ARG_ENABLE(notify-dbus, + AC_HELP_STRING([--enable-notify-dbus], + [enable LVM notification using dbus]), + NOTIFYDBUS=$enableval) +AC_MSG_RESULT($NOTIFYDBUS) + +BUILD_NOTIFYDBUS=$NOTIFYDBUS + +if test "$BUILD_NOTIFYDBUS" = yes; then + AC_DEFINE([NOTIFYDBUS_SUPPORT], 1, [Define to 1 to include code that uses dbus notification.]) + LIBS="-lsystemd $LIBS" +fi + +################################################################################ +dnl -- Look for dbus libraries +if test "$BUILD_NOTIFYDBUS" = yes; then + PKG_CHECK_MODULES(NOTIFY_DBUS, systemd >= 221, [HAVE_NOTIFY_DBUS=yes], $bailout) +fi + +################################################################################ dnl -- Enable blkid wiping functionality AC_MSG_CHECKING(whether to enable libblkid detection of signatures when wiping) @@ -1965,6 +1987,7 @@ AC_SUBST(BUILD_LVMPOLLD) AC_SUBST(BUILD_LVMLOCKD) AC_SUBST(BUILD_LOCKDSANLOCK) AC_SUBST(BUILD_LOCKDDLM) +AC_SUBST(BUILD_NOTIFYDBUS) AC_SUBST(CACHE) AC_SUBST(CFLAGS) AC_SUBST(CFLOW_CMD) diff --git a/include/.symlinks.in b/include/.symlinks.in index 98d680483..d1cc8268f 100644 --- a/include/.symlinks.in +++ b/include/.symlinks.in @@ -58,6 +58,7 @@ @top_srcdir@/lib/misc/util.h @top_srcdir@/lib/mm/memlock.h @top_srcdir@/lib/mm/xlate.h +@top_srcdir@/lib/notify/lvmnotify.h @top_srcdir@/lib/properties/prop_common.h @top_srcdir@/lib/report/properties.h @top_srcdir@/lib/report/report.h diff --git a/lib/Makefile.in b/lib/Makefile.in index ece9b1068..467ef9077 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -116,6 +116,7 @@ SOURCES =\ misc/lvm-wrappers.c \ misc/lvm-percent.c \ mm/memlock.c \ + notify/lvmnotify.c \ properties/prop_common.c \ report/properties.c \ report/report.c \ @@ -215,6 +216,7 @@ ifeq ($(MAKECMDGOALS),distclean) format_pool \ snapshot \ mirror \ + notify \ raid \ replicator \ thin \ diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h index 6a6267d1d..c3b9b2ea5 100644 --- a/lib/commands/toolcontext.h +++ b/lib/commands/toolcontext.h @@ -141,6 +141,9 @@ struct cmd_context { unsigned lockd_vg_rescan:1; unsigned lockd_vg_default_sh:1; unsigned lockd_vg_enforce_sh:1; + unsigned vg_notify:1; + unsigned lv_notify:1; + unsigned pv_notify:1; /* * Filtering. diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c index 9700e7324..1330cc019 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -33,6 +33,7 @@ #include "defaults.h" #include "lvmlockd.h" #include "time.h" +#include "lvmnotify.h" #include <math.h> #include <sys/param.h> @@ -604,6 +605,8 @@ int vg_remove_direct(struct volume_group *vg) lockd_vg_update(vg); + set_vg_notify(vg->cmd); + if (!backup_remove(vg->cmd, vg->name)) stack; @@ -3591,6 +3594,8 @@ int vg_commit(struct volume_group *vg) cache_updated = _vg_commit_mdas(vg); + set_vg_notify(vg->cmd); + if (cache_updated) { /* Instruct remote nodes to upgrade cached metadata. */ if (!remote_commit_cached_metadata(vg)) diff --git a/lib/notify/lvmnotify.c b/lib/notify/lvmnotify.c new file mode 100644 index 000000000..24d0ed2ef --- /dev/null +++ b/lib/notify/lvmnotify.c @@ -0,0 +1,103 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * This file is part of LVM2. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License v.2.1. + */ + +#include "lib.h" +#include "toolcontext.h" +#include "metadata.h" +#include "lvmnotify.h" + +#ifdef NOTIFYDBUS_SUPPORT +#include <systemd/sd-bus.h> + +void lvmnotify_send(struct cmd_context *cmd) +{ + sd_bus *bus = NULL; + sd_bus_message *m = NULL; + sd_bus_error error = SD_BUS_ERROR_NULL; + const char *cmd_name; + int ret; + int result = 0; + + if (!cmd->vg_notify && !cmd->lv_notify && !cmd->pv_notify) + return; + + cmd->vg_notify = 0; + cmd->lv_notify = 0; + cmd->pv_notify = 0; + + cmd_name = get_cmd_name(); + + ret = sd_bus_open_system(&bus); + if (ret < 0) { + log_debug("Failed to connect to dbus: %d", ret); + return; + } + + ret = sd_bus_call_method(bus, + "com.redhat.lvmdbus1", + "/com/redhat/lvmdbus1/Manager", + "com.redhat.lvmdbus1.Manager", + "ExternalEvent", + &error, + &m, + "s", + cmd_name); + + if (ret < 0) { + log_warn("WARNING: D-Bus notification failed: %s", error.message); + goto out; + } + + ret = sd_bus_message_read(m, "i", &result); + if (ret < 0) + log_debug("Failed to parse dbus response message: %d", ret); + if (result) + log_debug("Bad return value from dbus service: %d", result); +out: + sd_bus_error_free(&error); + sd_bus_message_unref(m); + sd_bus_unref(bus); +} + +void set_vg_notify(struct cmd_context *cmd) +{ + cmd->vg_notify = 1; +} + +void set_lv_notify(struct cmd_context *cmd) +{ + cmd->lv_notify = 1; +} + +void set_pv_notify(struct cmd_context *cmd) +{ + cmd->pv_notify = 1; +} + +#else + +void lvmnotify_send(struct cmd_context *cmd) +{ +} + +void set_vg_notify(struct cmd_context *cmd) +{ +} + +void set_lv_notify(struct cmd_context *cmd) +{ +} + +void set_pv_notify(struct cmd_context *cmd) +{ +} + +#endif + diff --git a/lib/notify/lvmnotify.h b/lib/notify/lvmnotify.h new file mode 100644 index 000000000..43fffd0da --- /dev/null +++ b/lib/notify/lvmnotify.h @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2015 Red Hat, Inc. + * + * This file is part of LVM2. + * + * This copyrighted material is made available to anyone wishing to use, + * modify, copy, or redistribute it subject to the terms and conditions + * of the GNU Lesser General Public License v.2.1. + */ + +#ifndef _LVMNOTIFY_H +#define _LVMNOTIFY_H + +void lvmnotify_send(struct cmd_context *cmd); +void set_vg_notify(struct cmd_context *cmd); +void set_lv_notify(struct cmd_context *cmd); +void set_pv_notify(struct cmd_context *cmd); + +#endif + diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index 72570f7df..40f204b62 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -1660,6 +1660,9 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv) lvmlockd_disconnect(); fin_locking(); + if (!_cmd_no_meta_proc(cmd)) + lvmnotify_send(cmd); + out: if (test_mode()) { log_verbose("Test mode: Wiping internal cache"); diff --git a/tools/pvchange.c b/tools/pvchange.c index 86c4ac4f0..5f9901687 100644 --- a/tools/pvchange.c +++ b/tools/pvchange.c @@ -228,6 +228,8 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv) } } + set_pv_notify(cmd); + ret = process_each_pv(cmd, argc, argv, NULL, 0, READ_FOR_UPDATE, handle, _pvchange_single); if (!argc) diff --git a/tools/pvresize.c b/tools/pvresize.c index b79098ca9..13122907e 100644 --- a/tools/pvresize.c +++ b/tools/pvresize.c @@ -79,6 +79,8 @@ int pvresize(struct cmd_context *cmd, int argc, char **argv) params.done = 0; params.total = 0; + set_pv_notify(cmd); + if (!(handle = init_processing_handle(cmd))) { log_error("Failed to initialize processing handle."); ret = ECMD_FAILED; diff --git a/tools/toollib.c b/tools/toollib.c index 9e866d6f4..14aca1503 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -1069,6 +1069,8 @@ int lv_change_activate(struct cmd_context *cmd, struct logical_volume *lv, if (!lv_active_change(cmd, lv, activate, 0)) return_0; + set_lv_notify(lv->vg->cmd); + return r; } @@ -4179,6 +4181,8 @@ int pvcreate_each_device(struct cmd_context *cmd, int found; int i; + set_pv_notify(cmd); + dm_list_init(&arg_sort); handle->custom_handle = pp; diff --git a/tools/tools.h b/tools/tools.h index 5875376ba..3762e8eed 100644 --- a/tools/tools.h +++ b/tools/tools.h @@ -42,6 +42,7 @@ #include "str_list.h" #include "toolcontext.h" #include "toollib.h" +#include "lvmnotify.h" #include <ctype.h> #include <sys/types.h> |