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-21 14:03:32 -0500
commit771cf936b80758669ac82a56c088a94097cdbb71 (patch)
tree80ad7d76fb7a444fea2a310bc81529116529410b
parent804c25a81a297753aa60f47f36c21149e9479c22 (diff)
downloadlvm2-dev-dct-notify.tar.gz
lvmnotify: add initial dbus notificationdev-dct-notify
This follows the pattern of lvmlockd, which notifies lvmlockd whenever a VG is updated, providing the VG name and new seqno.
-rw-r--r--lib/Makefile.in2
-rw-r--r--lib/metadata/metadata.c4
-rw-r--r--lib/notify/lvmnotify.c90
-rw-r--r--lib/notify/lvmnotify.h20
-rw-r--r--tools/lvmcmdline.c4
5 files changed, 120 insertions, 0 deletions
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 3e0e6f87e..d881e797b 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 \
@@ -214,6 +215,7 @@ ifeq ($(MAKECMDGOALS),distclean)
format_pool \
snapshot \
mirror \
+ notify \
raid \
replicator \
thin \
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 9bd42c91b..435d2d2bf 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -602,6 +602,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 +3197,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..e2a73f966
--- /dev/null
+++ b/lib/notify/lvmnotify.c
@@ -0,0 +1,90 @@
+/*
+ * 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 LVMNOTIFY_SUPPORT
+
+#include <dbus/dbus.h>
+
+#define NOTIFY_DBUS_PATH "com.lvm"
+#define NOTIFY_DBUS_IFACE "com/lvm"
+
+static DBusConnection *_dbus_con = NULL;
+
+void lvmnotify_init(struct cmd_context *cmd)
+{
+ if (!(_dbus_con = dbus_bus_get_private(DBUS_BUS_SYSTEM, NULL)))
+ log_debug("Failed to connect to dbus");
+}
+
+void lvmnotify_exit(void)
+{
+ if (_dbus_con) {
+ dbus_connection_close(_dbus_con);
+ dbus_connection_unref(_dbus_con);
+ }
+ _dbus_con = NULL;
+}
+
+void notify_vg_update(struct volume_group *vg)
+{
+ DBusMessage *msg = NULL;
+
+ if (_dbus_con && !dbus_connection_read_write(_dbus_con, 1)) {
+ log_debug("Disconnected from dbus");
+ notify_exit();
+ }
+
+ if (!_dbus_con)
+ return;
+
+ if (!(msg = dbus_message_new_signal(NOTIFY_DBUS_PATH,
+ NOTIFY_DBUS_IFACE,
+ "vg_update"))) {
+ log_error("Failed to create dbus signal");
+ goto out;
+ }
+
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_STRING, &vg->name,
+ DBUS_TYPE_INT32, &vg->seqno,
+ DBUS_TYPE_INVALID)) {
+ log_error("Failed to append args to dbus signal");
+ goto out;
+ }
+
+ dbus_connection_send(_dbus_con, msg, NULL);
+ dbus_connection_flush(_dbus_con);
+
+out:
+ if (msg)
+ dbus_message_unref(msg);
+}
+
+#else
+
+void 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..f187358e4
--- /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_init(struct cmd_context *cmd);
+void lvmnotify_exit(void);
+
+void notify_vg_update(struct volume_group *vg);
+
+#endif
+
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
index d3bace743..3bf2ca39b 100644
--- a/tools/lvmcmdline.c
+++ b/tools/lvmcmdline.c
@@ -1639,6 +1639,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 +1658,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: