Gitweb:
http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a8319e62c079e8...
Commit: a8319e62c079e807af275f220dbd6ea875b0c0c6
Parent: 2d5dc6512e10924ab68e6a139081d7121bc3f7d6
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon Mar 7 10:50:45 2016 -0600
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Mon Mar 7 10:50:45 2016 -0600
vgscan: add --notifydbus to send a notification
This command option can be used to trigger a D-Bus
notification independent of the usual notifications
that are sent from other commands as an effect of
changes to PV/VG/LV state. If lvm is not built with
dbus notification support or if notify_dbus is disabled
in the config, this command will exit with an error.
---
WHATS_NEW | 1 +
lib/notify/lvmnotify.c | 10 ++++++++++
lib/notify/lvmnotify.h | 1 +
man/vgscan.8.in | 6 ++++++
tools/args.h | 1 +
tools/commands.h | 3 ++-
tools/vgscan.c | 15 +++++++++++++++
7 files changed, 36 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index e2e9462..bf49764 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.146 -
=================================
+ Add vgscan --notifydbus to send a dbus notification.
Add dbus notification from commands after a PV/VG/LV changes state.
Version 2.02.145 - 4th March 2016
diff --git a/lib/notify/lvmnotify.c b/lib/notify/lvmnotify.c
index 0b04ee4..3bcf5ae 100644
--- a/lib/notify/lvmnotify.c
+++ b/lib/notify/lvmnotify.c
@@ -20,6 +20,11 @@
#ifdef NOTIFYDBUS_SUPPORT
#include <systemd/sd-bus.h>
+int lvmnotify_is_supported(void)
+{
+ return 1;
+}
+
void lvmnotify_send(struct cmd_context *cmd)
{
sd_bus *bus = NULL;
@@ -89,6 +94,11 @@ void set_pv_notify(struct cmd_context *cmd)
#else
+int lvmnotify_is_supported(void)
+{
+ return 0;
+}
+
void lvmnotify_send(struct cmd_context *cmd)
{
}
diff --git a/lib/notify/lvmnotify.h b/lib/notify/lvmnotify.h
index 43fffd0..fe56b10 100644
--- a/lib/notify/lvmnotify.h
+++ b/lib/notify/lvmnotify.h
@@ -11,6 +11,7 @@
#ifndef _LVMNOTIFY_H
#define _LVMNOTIFY_H
+int lvmnotify_is_supported(void);
void lvmnotify_send(struct cmd_context *cmd);
void set_vg_notify(struct cmd_context *cmd);
void set_lv_notify(struct cmd_context *cmd);
diff --git a/man/vgscan.8.in b/man/vgscan.8.in
index b9105d8..8c699d1 100644
--- a/man/vgscan.8.in
+++ b/man/vgscan.8.in
@@ -9,6 +9,7 @@ vgscan \(em scan all disks for volume groups and rebuild caches
.RB [ \-h | \-? | \-\-help ]
.RB [ \-\-ignorelockingfailure ]
.RB [ \-\-mknodes ]
+.RB [ \-\-notifydbus ]
.RB [ \-P | \-\-partial ]
.RB [ \-v | \-\-verbose ]
.SH DESCRIPTION
@@ -26,6 +27,11 @@ See \fBlvm\fP(8) for common options.
Also checks the LVM special files in /dev that are needed for active
logical volumes and creates any missing ones and removes unused ones.
.TP
+.B \-\-notifydbus
+Send a notification to D-Bus. The command will exit with an error
+if LVM is not built with support for D-Bus notification, or if the
+notify_dbus config setting is disabled.
+.TP
.B \-\-cache
Scan devices for LVM physical volumes and volume groups and instruct
the lvmetad daemon to update its cached state accordingly.
diff --git a/tools/args.h b/tools/args.h
index dc7b9e1..ebddd2e 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -74,6 +74,7 @@ arg(nolocking_ARG, '\0', "nolocking", NULL, 0)
arg(norestorefile_ARG, '\0', "norestorefile", NULL, 0)
arg(nosuffix_ARG, '\0', "nosuffix", NULL, 0)
arg(nosync_ARG, '\0', "nosync", NULL, 0)
+arg(notifydbus_ARG, '\0', "notifydbus", NULL, 0)
arg(noudevsync_ARG, '\0', "noudevsync", NULL, 0)
arg(originname_ARG, '\0', "originname", string_arg, 0)
arg(physicalvolumesize_ARG, '\0', "setphysicalvolumesize", size_mb_arg,
0)
diff --git a/tools/commands.h b/tools/commands.h
index b3627dd..f676bbe 100644
--- a/tools/commands.h
+++ b/tools/commands.h
@@ -1390,11 +1390,12 @@ xx(vgscan,
"\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n"
"\t[--mknodes]\n"
+ "\t[--notifydbus]\n"
"\t[-P|--partial]\n"
"\t[-v|--verbose]\n"
"\t[--version]\n",
- cache_long_ARG, ignorelockingfailure_ARG, mknodes_ARG, partial_ARG)
+ cache_long_ARG, ignorelockingfailure_ARG, mknodes_ARG, notifydbus_ARG, partial_ARG)
xx(vgsplit,
"Move physical volumes into a new or existing volume group",
diff --git a/tools/vgscan.c b/tools/vgscan.c
index 93c00b8..a5b04a3 100644
--- a/tools/vgscan.c
+++ b/tools/vgscan.c
@@ -37,6 +37,21 @@ int vgscan(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE;
}
+ if (arg_is_set(cmd, notifydbus_ARG)) {
+ if (!lvmnotify_is_supported()) {
+ log_error("Cannot notify dbus: lvm is not built with dbus support.");
+ return ECMD_FAILED;
+ }
+ if (!find_config_tree_bool(cmd, global_notify_dbus_CFG, NULL)) {
+ log_error("Cannot notify dbus: notify_dbus is disabled in lvm config.");
+ return ECMD_FAILED;
+ }
+ set_pv_notify(cmd);
+ set_vg_notify(cmd);
+ set_lv_notify(cmd);
+ return ECMD_PROCESSED;
+ }
+
if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_WRITE, NULL)) {
log_error("Unable to obtain global lock.");
return ECMD_FAILED;