summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2016-02-22 09:42:03 -0600
committerDavid Teigland <teigland@redhat.com>2016-02-25 09:46:35 -0600
commit0ebdab3e8021cf086abae4c936953cb6d0db4f30 (patch)
tree2e293759f96539935807739426f890941654d369
parent718a695b0c0fe0c9088758499e5daae2cb0652a2 (diff)
downloadlvm2-dev-dct-notify10.tar.gz
lvmnotify: add dbus notificationdev-dct-notify10
When a command modifies a PV or VG, it will send a dbus notification when the command is finished.
-rw-r--r--configure.in23
-rw-r--r--include/.symlinks.in1
-rw-r--r--lib/Makefile.in2
-rw-r--r--lib/commands/toolcontext.h3
-rw-r--r--lib/metadata/metadata.c5
-rw-r--r--lib/notify/lvmnotify.c99
-rw-r--r--lib/notify/lvmnotify.h20
-rw-r--r--tools/lvmcmdline.c3
-rw-r--r--tools/pvchange.c2
-rw-r--r--tools/pvcreate.c2
-rw-r--r--tools/pvremove.c2
-rw-r--r--tools/pvresize.c2
-rw-r--r--tools/toollib.c2
-rw-r--r--tools/tools.h1
14 files changed, 167 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 5fda9a9b5..47ce39042 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -139,6 +139,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 a41c2278e..d0588b7df 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>
@@ -619,6 +620,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;
@@ -3335,6 +3338,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..72968972b
--- /dev/null
+++ b/lib/notify/lvmnotify.c
@@ -0,0 +1,99 @@
+/*
+ * 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_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_debug("Failed to issue dbus method call: %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 29c1c7eac..6450b7785 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1657,6 +1657,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 7f9aaf8db..9762ccbf2 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, READ_FOR_UPDATE, handle, _pvchange_single);
if (!argc)
diff --git a/tools/pvcreate.c b/tools/pvcreate.c
index 31657c75e..e12a11dbc 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 1d42c6ea4..3566dc796 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 e23c9548b..daf8f0ebf 100644
--- a/tools/pvresize.c
+++ b/tools/pvresize.c
@@ -73,6 +73,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 22c38a171..6d5ee86f1 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1067,6 +1067,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;
}
diff --git a/tools/tools.h b/tools/tools.h
index 979b5e341..8b556c9f9 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>