diff options
author | David Teigland <teigland@redhat.com> | 2015-09-21 13:50:32 -0500 |
---|---|---|
committer | David Teigland <teigland@redhat.com> | 2016-01-11 12:08:34 -0600 |
commit | db613fd98aaaf69cad2bc249f3232ce20f2169af (patch) | |
tree | 696313ed0a2ee24ab7346c011b672080b6e74bb7 | |
parent | d6cf83968cb0d397faec30ce54839a679e89dd14 (diff) | |
download | lvm2-dev-dct-notify6.tar.gz |
lvmnotify: add initial dbus notificationdev-dct-notify6
Use --enable-notify-dbus in configure.
May need to remove --enable-python-bindings.
-rw-r--r-- | configure.in | 23 | ||||
-rw-r--r-- | daemons/dmeventd/dmeventd.c | 46 | ||||
-rw-r--r-- | daemons/dmeventd/dmeventd.h | 2 | ||||
-rw-r--r-- | daemons/dmeventd/plugins/raid/dmeventd_raid.c | 2 | ||||
-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 | 97 | ||||
-rw-r--r-- | lib/notify/lvmnotify.h | 20 | ||||
-rw-r--r-- | tools/args.h | 1 | ||||
-rw-r--r-- | tools/lvmcmdline.c | 10 | ||||
-rw-r--r-- | tools/pvchange.c | 2 | ||||
-rw-r--r-- | tools/pvcreate.c | 2 | ||||
-rw-r--r-- | tools/pvremove.c | 2 | ||||
-rw-r--r-- | tools/pvresize.c | 2 | ||||
-rw-r--r-- | tools/toollib.c | 2 |
17 files changed, 222 insertions, 0 deletions
diff --git a/configure.in b/configure.in index 8e04782d0..4499d37a6 100644 --- a/configure.in +++ b/configure.in @@ -1268,6 +1268,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) @@ -1912,6 +1934,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/daemons/dmeventd/dmeventd.c b/daemons/dmeventd/dmeventd.c index c093d9164..d1a03faa9 100644 --- a/daemons/dmeventd/dmeventd.c +++ b/daemons/dmeventd/dmeventd.c @@ -2283,3 +2283,49 @@ int main(int argc, char *argv[]) exit(EXIT_SUCCESS); } + +#ifdef NOTIFYDBUS_SUPPORT +#include <systemd/sd-bus.h> + +static void *dbus_callback_data; + +static int dbus_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) +{ + return 0; +} + +void lvmnotify_send_noreply(const char *name) +{ + sd_bus *bus = NULL; + int ret; + + ret = sd_bus_open_system(&bus); + if (ret < 0) { + log_debug("Failed to connect to dbus: %d", ret); + return; + } + + ret = sd_bus_call_method_async(bus, NULL, + "com.redhat.lvmdbus1.Manager", + "/com/redhat/lvmdbus1/Manager", + "com.redhat.lvmdbus1.Manager", + "ExternalEvent", + dbus_callback, + dbus_callback_data, + "s", + name); + + if (ret < 0) + log_debug("Failed to issue dbus method call: %d", ret); + + sd_bus_unref(bus); +} + +#else + +void lvmnotify_send_noreply(const char *name) +{ +} + +#endif + diff --git a/daemons/dmeventd/dmeventd.h b/daemons/dmeventd/dmeventd.h index 25a4bbbb8..a8fd9e4ca 100644 --- a/daemons/dmeventd/dmeventd.h +++ b/daemons/dmeventd/dmeventd.h @@ -73,4 +73,6 @@ int init_fifos(struct dm_event_fifos *fifos); void fini_fifos(struct dm_event_fifos *fifos); int dm_event_get_version(struct dm_event_fifos *fifos, int *version); +void lvmnotify_send_noreply(const char *name); + #endif /* __DMEVENTD_DOT_H__ */ diff --git a/daemons/dmeventd/plugins/raid/dmeventd_raid.c b/daemons/dmeventd/plugins/raid/dmeventd_raid.c index 99f268058..3eee4c2b7 100644 --- a/daemons/dmeventd/plugins/raid/dmeventd_raid.c +++ b/daemons/dmeventd/plugins/raid/dmeventd_raid.c @@ -96,6 +96,8 @@ void process_event(struct dm_task *dmt, log_error("Failed to process event for %s.", device); } while (next); + + lvmnotify_send_noreply("dmeventd_raid"); } int register_device(const char *device, 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 00014c201..43761eee2 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 cd5534882..e323d8d8b 100644 --- a/lib/commands/toolcontext.h +++ b/lib/commands/toolcontext.h @@ -137,6 +137,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 a1d2e2b49..5cfc3af3f 100644 --- a/lib/metadata/metadata.c +++ b/lib/metadata/metadata.c @@ -32,6 +32,7 @@ #include "archiver.h" #include "defaults.h" #include "lvmlockd.h" +#include "lvmnotify.h" #include <math.h> #include <sys/param.h> @@ -602,6 +603,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; @@ -3196,6 +3199,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..bef4214f1 --- /dev/null +++ b/lib/notify/lvmnotify.c @@ -0,0 +1,97 @@ +/* + * 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 *path; + const char *cmd_name; + int ret; + + if (!cmd->vg_notify && !cmd->lv_notify && !cmd->pv_notify) + return; + + 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.Manager", + "/com/redhat/lvmdbus1/Manager", + "com.redhat.lvmdbus1.Manager", + "ExternalEvent", + &error, + NULL, + "s", + cmd_name); + + if (ret < 0) { + log_debug("Failed to issue dbus method call: %s", error.message); + goto out; + } + + ret = sd_bus_message_read(m, "o", &path); + if (ret < 0) + log_debug("Failed to parse dbus response message: %d", ret); +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/args.h b/tools/args.h index f6b10a67e..814554108 100644 --- a/tools/args.h +++ b/tools/args.h @@ -68,6 +68,7 @@ arg(mirrorsonly_ARG, '\0', "mirrorsonly", NULL, 0) arg(mknodes_ARG, '\0', "mknodes", NULL, 0) arg(monitor_ARG, '\0', "monitor", yes_no_arg, 0) arg(nameprefixes_ARG, '\0', "nameprefixes", NULL, 0) +arg(nodbusnotify_ARG, '\0', "nodbusnotify", NULL, 0) arg(noheadings_ARG, '\0', "noheadings", NULL, 0) arg(nolocking_ARG, '\0', "nolocking", NULL, 0) arg(norestorefile_ARG, '\0', "norestorefile", NULL, 0) diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index 657797765..5fb6002fa 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -19,6 +19,7 @@ #include "label.h" #include "lvm-version.h" #include "lvmlockd.h" +#include "lvmnotify.h" #include "stub.h" #include "last-path-component.h" @@ -772,6 +773,7 @@ void lvm_register_commands(void) yes_ARG, \ quiet_ARG, config_ARG, \ commandprofile_ARG, \ + nodbusnotify_ARG, \ profile_ARG, -1); #include "commands.h" #undef xx @@ -1657,6 +1659,14 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv) lvmlockd_disconnect(); fin_locking(); + /* + * FIXME: get rid of nodbusnotify arg and detect when the command + * is being called from a context (or env variable?) where we don't + * want to send notification. + */ + if (!_cmd_no_meta_proc(cmd) && !arg_is_set(cmd, nodbusnotify_ARG)) + 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 91e93c1e7..a47fc87cf 100644 --- a/tools/pvchange.c +++ b/tools/pvchange.c @@ -213,6 +213,8 @@ int pvchange(struct cmd_context *cmd, int argc, char **argv) } } + set_pv_notify(cmd); + ret = process_each_pv(cmd, argc, argv, NULL, READ_FOR_UPDATE, handle, _pvchange_single); if (!argc) diff --git a/tools/pvcreate.c b/tools/pvcreate.c index 1f45ad91d..bc69951f5 100644 --- a/tools/pvcreate.c +++ b/tools/pvcreate.c @@ -109,6 +109,8 @@ int pvcreate(struct cmd_context *cmd, int argc, char **argv) return EINVALID_CMD_LINE; } + set_pv_notify(cmd); + for (i = 0; i < argc; i++) { if (sigint_caught()) return_ECMD_FAILED; diff --git a/tools/pvremove.c b/tools/pvremove.c index e6ae86641..9f12ebd85 100644 --- a/tools/pvremove.c +++ b/tools/pvremove.c @@ -32,6 +32,8 @@ int pvremove(struct cmd_context *cmd, int argc, char **argv) dm_list_init(&pv_names); + set_pv_notify(cmd); + /* Needed to change the set of orphan PVs. */ if (!lockd_gl(cmd, "ex", 0)) return_ECMD_FAILED; diff --git a/tools/pvresize.c b/tools/pvresize.c index 0b055e6ef..04f6e9361 100644 --- a/tools/pvresize.c +++ b/tools/pvresize.c @@ -70,6 +70,8 @@ int pvresize(struct cmd_context *cmd, int argc, char **argv) goto out; } + set_pv_notify(cmd); + params.new_size = arg_uint64_value(cmd, physicalvolumesize_ARG, UINT64_C(0)); diff --git a/tools/toollib.c b/tools/toollib.c index 728e61d4d..73fb3b403 100644 --- a/tools/toollib.c +++ b/tools/toollib.c @@ -1064,6 +1064,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; } |