summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2015-09-21 13:50:32 -0500
committerDavid Teigland <teigland@redhat.com>2015-09-30 14:36:40 -0500
commit9ff0063f1d1a10be0c1aa75056d28e8b04d2731d (patch)
tree355bea97bad57f4b2c767b5538ae14de466b9c5d
parent9d815e5f5a17963a09b103177770e9af80c90e0f (diff)
downloadlvm2-dev-dct-notify2.tar.gz
lvmnotify: add initial dbus notificationdev-dct-notify2
This follows the pattern of lvmlockd, which notifies lvmlockd whenever a VG is updated, providing the VG name and new seqno. Building required setting the GIO_CFLAGS and GIO_LIBS env var explicitly for some reason. Excluding applib from the configure. export GIO_CFLAGS='-pthread -I/usr/include/gio-unix-2.0/ -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include' (pkg-config --cflags gio-unix-2.0) export GIO_LIBS='-lgio-2.0 -lgobject-2.0 -lglib-2.0' (pkg-config --libs gio-unix-2.0) autoreconf ./configure --build=x86_64-redhat-linux-gnu --host=x86_64-redhat-linux-gnu --program-prefix= --disable-dependency-tracking --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --sysconfdir=/etc --datadir=/usr/share --includedir=/usr/include --libdir=/usr/lib64 --libexecdir=/usr/libexec --localstatedir=/var --sharedstatedir=/var/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-default-dm-run-dir=/run --with-default-run-dir=/run/lvm --with-default-pid-dir=/run --with-default-locking-dir=/run/lock/lvm --with-usrlibdir=/usr/lib64 --enable-fsadm --with-pool=internal --enable-write_install --with-user= --with-group= --with-device-uid=0 --with-device-gid=6 --with-device-mode=0660 --enable-pkgconfig --enable-cmdlib --with-cluster=internal --with-clvmd=corosync --with-udevdir=/usr/lib/udev/rules.d --enable-udev_sync --with-thin=internal --with-thin-check=/usr/sbin/thin_check --with-thin-dump=/usr/sbin/thin_dump --with-thin-repair=/usr/sbin/thin_repair --enable-lvmetad --enable-udev-systemd-background-jobs --with-cache=internal --enable-lvmpolld --with-clvmd=none --enable-notify-dbus
-rw-r--r--configure.in26
-rw-r--r--include/.symlinks.in1
-rw-r--r--lib/Makefile.in9
-rw-r--r--lib/metadata/metadata.c5
-rw-r--r--lib/notify/lvmnotify.c104
-rw-r--r--lib/notify/lvmnotify.h20
-rw-r--r--make.tmpl.in3
-rw-r--r--tools/Makefile.in5
-rw-r--r--tools/lvmcmdline.c5
9 files changed, 177 insertions, 1 deletions
diff --git a/configure.in b/configure.in
index c240b4be7..80bc75388 100644
--- a/configure.in
+++ b/configure.in
@@ -854,6 +854,8 @@ if test "$BUILDOPENAIS" = yes; then
CHECKCPG=yes
fi
+PKG_CHECK_MODULES([GIO], [gio-unix-2.0])
+
dnl -- Below are checks for libraries common to more than one build.
dnl -- Check confdb library.
@@ -1276,6 +1278,27 @@ 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.])
+fi
+
+################################################################################
+dnl -- Look for dbus libraries
+if test "$BUILD_NOTIFYDBUS" = yes; then
+ PKG_CHECK_MODULES(NOTIFY_DBUS, gio-unix-2.0, [HAVE_NOTIFY_DBUS=yes], $bailout)
+fi
+
+################################################################################
dnl -- Enable blkid wiping functionality
AC_MSG_CHECKING(whether to enable libblkid detection of signatures when wiping)
@@ -1916,6 +1939,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)
@@ -2009,6 +2033,8 @@ AC_SUBST(SACKPT_CFLAGS)
AC_SUBST(SACKPT_LIBS)
AC_SUBST(SALCK_CFLAGS)
AC_SUBST(SALCK_LIBS)
+AC_SUBST(GIO_CFLAGS)
+AC_SUBST(GIO_LIBS)
AC_SUBST(SELINUX_LIBS)
AC_SUBST(SELINUX_PC)
AC_SUBST(SNAPSHOTS)
diff --git a/include/.symlinks.in b/include/.symlinks.in
index 9b97eb42b..002a73d0e 100644
--- a/include/.symlinks.in
+++ b/include/.symlinks.in
@@ -59,6 +59,7 @@
@top_srcdir@/lib/misc/lvm-wrappers.h
@top_srcdir@/lib/misc/sharedlib.h
@top_srcdir@/lib/misc/util.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 3e0e6f87e..014fbd8cf 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -115,6 +115,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 \
@@ -205,6 +206,11 @@ ifeq ("@DMEVENTD@", "yes")
LIBS += -ldevmapper-event
endif
+ifeq ("@BUILD_NOTIFYDBUS@", "yes")
+ LIBS += $(GIO_LIBS)
+ CFLAGS += $(GIO_CFLAGS)
+endif
+
LIB_NAME = liblvm-internal
LIB_STATIC = $(LIB_NAME).a
@@ -214,6 +220,7 @@ ifeq ($(MAKECMDGOALS),distclean)
format_pool \
snapshot \
mirror \
+ notify \
raid \
replicator \
thin \
@@ -226,7 +233,7 @@ CFLOW_LIST_TARGET = $(LIB_NAME).cflow
include $(top_builddir)/make.tmpl
-CFLAGS += $(BLKID_CFLAGS) $(UDEV_CFLAGS) $(VALGRIND_CFLAGS)
+CFLAGS += $(BLKID_CFLAGS) $(UDEV_CFLAGS) $(VALGRIND_CFLAGS) $(GIO_CFLAGS)
$(SUBDIRS): $(LIB_STATIC)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 9bd42c91b..5e5f2848b 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);
+ notify_vg_update(vg);
+
if (!backup_remove(vg->cmd, vg->name))
stack;
@@ -3195,6 +3198,8 @@ int vg_commit(struct volume_group *vg)
lockd_vg_update(vg);
+ notify_vg_update(vg);
+
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..b98bf9247
--- /dev/null
+++ b/lib/notify/lvmnotify.c
@@ -0,0 +1,104 @@
+/*
+ * 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 <gio/gio.h>
+
+static GDBusProxy *_dbus_con = NULL;
+
+int lvmnotify_init(struct cmd_context *cmd)
+{
+ GError *error = NULL;
+
+ _dbus_con = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ "com.lvm1",
+ "/com/lvm1/Manager",
+ "com.lvm1.Manager",
+ NULL,
+ &error);
+ if (!_dbus_con && error) {
+ log_debug("Failed to connect to dbus %d %s",
+ error->code, error->message);
+ g_error_free(error);
+ return 0;
+ }
+ return 1;
+}
+
+void lvmnotify_exit(void)
+{
+ if (_dbus_con) {
+ g_object_unref(_dbus_con);
+ _dbus_con = NULL;
+ }
+}
+
+void notify_vg_update(struct volume_group *vg)
+{
+ char uuid[64] __attribute__((aligned(8)));
+ GError *error = NULL;
+ GVariant *rc;
+ int result = 0;
+
+ if (!_dbus_con)
+ return;
+
+ if (!id_write_format(&vg->id, uuid, sizeof(uuid)))
+ return;
+
+ rc = g_dbus_proxy_call_sync(_dbus_con,
+ "ExternalEvent",
+ g_variant_new("(sssu)",
+ "vg_update",
+ vg->name,
+ uuid,
+ vg->seqno),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+
+ if (rc) {
+ g_variant_get(rc, "(i)", &result);
+ if (result)
+ log_debug("Error from sending dbus notification %d", result);
+ g_variant_unref(rc);
+
+ } else if (error) {
+ if (error->code != 2)
+ log_debug("Failed to send dbus notification %d %s", error->code, error->message);
+ g_error_free(error);
+
+ } else {
+ log_debug("Undefined dbus result");
+ }
+}
+
+#else
+
+int lvmnotify_init(struct cmd_context *cmd)
+{
+}
+
+void lvmnotify_exit(void)
+{
+}
+
+void notify_vg_update(struct volume_group *vg)
+{
+}
+
+#endif
+
diff --git a/lib/notify/lvmnotify.h b/lib/notify/lvmnotify.h
new file mode 100644
index 000000000..1e6d5b378
--- /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
+
+int lvmnotify_init(struct cmd_context *cmd);
+void lvmnotify_exit(void);
+
+void notify_vg_update(struct volume_group *vg);
+
+#endif
+
diff --git a/make.tmpl.in b/make.tmpl.in
index 121727809..4aeba8c02 100644
--- a/make.tmpl.in
+++ b/make.tmpl.in
@@ -65,6 +65,9 @@ BLKID_LIBS = @BLKID_LIBS@
VALGRIND_CFLAGS = @VALGRIND_CFLAGS@
TESTING = @TESTING@
+GIO_CFLAGS = @GIO_CFLAGS@
+GIO_LIBS = @GIO_LIBS@
+
# Setup directory variables
prefix = @prefix@
exec_prefix = @exec_prefix@
diff --git a/tools/Makefile.in b/tools/Makefile.in
index d6e54f0ac..f531ed0e5 100644
--- a/tools/Makefile.in
+++ b/tools/Makefile.in
@@ -109,6 +109,11 @@ ifeq ("@DMEVENTD@", "yes")
LVMLIBS += -ldevmapper-event
endif
+ifeq ("@BUILD_NOTIFYDBUS@", "yes")
+ EXTRA_EXEC_CFLAGS += $(GIO_CFLAGS)
+ EXTRA_EXEC_LDFLAGS += $(GIO_LIBS)
+endif
+
LVMLIBS += -ldevmapper
EXPORTED_HEADER = $(srcdir)/lvm2cmd.h
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index 657797765..85523bac6 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"
@@ -1639,6 +1640,9 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
goto_out;
}
+ if (!_cmd_no_meta_proc(cmd) && !lvmnotify_init(cmd))
+ log_verbose("Unable to initialize notifications.");
+
/*
* Other hosts might have changed foreign VGs so enforce a rescan
* before processing any command using them.
@@ -1655,6 +1659,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
ret = cmd->command->fn(cmd, argc, argv);
lvmlockd_disconnect();
+ lvmnotify_exit();
fin_locking();
out: