summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Teigland <teigland@redhat.com>2016-03-07 10:50:45 -0600
committerDavid Teigland <teigland@redhat.com>2016-03-07 10:50:45 -0600
commita8319e62c079e807af275f220dbd6ea875b0c0c6 (patch)
tree666c45981d9a42c128ff74c98d777d2c1b236a66
parent2d5dc6512e10924ab68e6a139081d7121bc3f7d6 (diff)
downloadlvm2-a8319e62c079e807af275f220dbd6ea875b0c0c6.tar.gz
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.
-rw-r--r--WHATS_NEW1
-rw-r--r--lib/notify/lvmnotify.c10
-rw-r--r--lib/notify/lvmnotify.h1
-rw-r--r--man/vgscan.8.in6
-rw-r--r--tools/args.h1
-rw-r--r--tools/commands.h3
-rw-r--r--tools/vgscan.c15
7 files changed, 36 insertions, 1 deletions
diff --git a/WHATS_NEW b/WHATS_NEW
index e2e946295..bf497640f 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 0b04ee4ba..3bcf5aefc 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 43fffd0da..fe56b106a 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 b9105d890..8c699d128 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 dc7b9e15c..ebddd2ec4 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 b3627dd73..f676bbe30 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 93c00b84b..a5b04a33f 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;