1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

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.
This commit is contained in:
David Teigland 2016-03-07 10:50:45 -06:00
parent 2d5dc6512e
commit a8319e62c0
7 changed files with 36 additions and 1 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.146 - Version 2.02.146 -
================================= =================================
Add vgscan --notifydbus to send a dbus notification.
Add dbus notification from commands after a PV/VG/LV changes state. Add dbus notification from commands after a PV/VG/LV changes state.
Version 2.02.145 - 4th March 2016 Version 2.02.145 - 4th March 2016

View File

@ -20,6 +20,11 @@
#ifdef NOTIFYDBUS_SUPPORT #ifdef NOTIFYDBUS_SUPPORT
#include <systemd/sd-bus.h> #include <systemd/sd-bus.h>
int lvmnotify_is_supported(void)
{
return 1;
}
void lvmnotify_send(struct cmd_context *cmd) void lvmnotify_send(struct cmd_context *cmd)
{ {
sd_bus *bus = NULL; sd_bus *bus = NULL;
@ -89,6 +94,11 @@ void set_pv_notify(struct cmd_context *cmd)
#else #else
int lvmnotify_is_supported(void)
{
return 0;
}
void lvmnotify_send(struct cmd_context *cmd) void lvmnotify_send(struct cmd_context *cmd)
{ {
} }

View File

@ -11,6 +11,7 @@
#ifndef _LVMNOTIFY_H #ifndef _LVMNOTIFY_H
#define _LVMNOTIFY_H #define _LVMNOTIFY_H
int lvmnotify_is_supported(void);
void lvmnotify_send(struct cmd_context *cmd); void lvmnotify_send(struct cmd_context *cmd);
void set_vg_notify(struct cmd_context *cmd); void set_vg_notify(struct cmd_context *cmd);
void set_lv_notify(struct cmd_context *cmd); void set_lv_notify(struct cmd_context *cmd);

View File

@ -9,6 +9,7 @@ vgscan \(em scan all disks for volume groups and rebuild caches
.RB [ \-h | \-? | \-\-help ] .RB [ \-h | \-? | \-\-help ]
.RB [ \-\-ignorelockingfailure ] .RB [ \-\-ignorelockingfailure ]
.RB [ \-\-mknodes ] .RB [ \-\-mknodes ]
.RB [ \-\-notifydbus ]
.RB [ \-P | \-\-partial ] .RB [ \-P | \-\-partial ]
.RB [ \-v | \-\-verbose ] .RB [ \-v | \-\-verbose ]
.SH DESCRIPTION .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 Also checks the LVM special files in /dev that are needed for active
logical volumes and creates any missing ones and removes unused ones. logical volumes and creates any missing ones and removes unused ones.
.TP .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 .B \-\-cache
Scan devices for LVM physical volumes and volume groups and instruct Scan devices for LVM physical volumes and volume groups and instruct
the lvmetad daemon to update its cached state accordingly. the lvmetad daemon to update its cached state accordingly.

View File

@ -74,6 +74,7 @@ arg(nolocking_ARG, '\0', "nolocking", NULL, 0)
arg(norestorefile_ARG, '\0', "norestorefile", NULL, 0) arg(norestorefile_ARG, '\0', "norestorefile", NULL, 0)
arg(nosuffix_ARG, '\0', "nosuffix", NULL, 0) arg(nosuffix_ARG, '\0', "nosuffix", NULL, 0)
arg(nosync_ARG, '\0', "nosync", NULL, 0) arg(nosync_ARG, '\0', "nosync", NULL, 0)
arg(notifydbus_ARG, '\0', "notifydbus", NULL, 0)
arg(noudevsync_ARG, '\0', "noudevsync", NULL, 0) arg(noudevsync_ARG, '\0', "noudevsync", NULL, 0)
arg(originname_ARG, '\0', "originname", string_arg, 0) arg(originname_ARG, '\0', "originname", string_arg, 0)
arg(physicalvolumesize_ARG, '\0', "setphysicalvolumesize", size_mb_arg, 0) arg(physicalvolumesize_ARG, '\0', "setphysicalvolumesize", size_mb_arg, 0)

View File

@ -1390,11 +1390,12 @@ xx(vgscan,
"\t[-h|--help]\n" "\t[-h|--help]\n"
"\t[--ignorelockingfailure]\n" "\t[--ignorelockingfailure]\n"
"\t[--mknodes]\n" "\t[--mknodes]\n"
"\t[--notifydbus]\n"
"\t[-P|--partial]\n" "\t[-P|--partial]\n"
"\t[-v|--verbose]\n" "\t[-v|--verbose]\n"
"\t[--version]\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, xx(vgsplit,
"Move physical volumes into a new or existing volume group", "Move physical volumes into a new or existing volume group",

View File

@ -37,6 +37,21 @@ int vgscan(struct cmd_context *cmd, int argc, char **argv)
return EINVALID_CMD_LINE; 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)) { if (!lock_vol(cmd, VG_GLOBAL, LCK_VG_WRITE, NULL)) {
log_error("Unable to obtain global lock."); log_error("Unable to obtain global lock.");
return ECMD_FAILED; return ECMD_FAILED;