WHATS_NEW | 2 +
man/pvscan.8.in | 4 +-
scripts/Makefile.in | 2 +-
scripts/lvm2_pvscan_systemd_red_hat@.service.in | 11 +++--
tools/pvscan.c | 61 +++++++++++++++++++------
udev/Makefile.in | 2 +-
6 files changed, 60 insertions(+), 22 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 5d3bb8b..aabfc78 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,7 @@
Version 2.02.104 -
===================================
+ Add dev-block-<major>:<minor>.device systemd alias for complete PV tracking.
+ Use major:minor as short form of --major and --minor arg for pvscan --cache.
Fix lvconvert swap of poolmetadata volume for active thin pool.
Add configure --enable-udev-systemd-background-jobs.
Add lvm2-pvscan@.service to run pvscan as a service for lvmetad/autoactivation.
diff --git a/man/pvscan.8.in b/man/pvscan.8.in
index 211c82b..37ecaaf 100644
--- a/man/pvscan.8.in
+++ b/man/pvscan.8.in
@@ -25,7 +25,9 @@ pvscan \- scan all disks for physical volumes
.B \-\-minor
.I minor
|
-.IR DevicePath ]...
+.IR DevicePath
+|
+.IR major:minor ]...
.SH DESCRIPTION
pvscan scans all supported LVM block devices in the system for
physical volumes.
diff --git a/scripts/Makefile.in b/scripts/Makefile.in
index fac7e40..3616afa 100644
--- a/scripts/Makefile.in
+++ b/scripts/Makefile.in
@@ -119,7 +119,7 @@ DISTCLEAN_TARGETS += clvmd_init_red_hat cmirrord_init_red_hat \
dm_event_systemd_red_hat.socket dm_event_systemd_red_hat.service \
lvm2_monitoring_systemd_red_hat.service \
lvm2_lvmetad_systemd_red_hat.socket lvm2_lvmetad_systemd_red_hat.service \
- lvm2_lvmetad_systemd_red_hat@.service \
+ lvm2_pvscan_systemd_red_hat@.service \
lvm2_tmpfiles_red_hat.conf blk_availability_init_red_hat \
blk_availability_systemd_red_hat.service \
blkdeactivate.sh
diff --git a/scripts/lvm2_pvscan_systemd_red_hat@.service.in b/scripts/lvm2_pvscan_systemd_red_hat@.service.in
index 9d91b5e..4225982 100644
--- a/scripts/lvm2_pvscan_systemd_red_hat@.service.in
+++ b/scripts/lvm2_pvscan_systemd_red_hat@.service.in
@@ -1,11 +1,14 @@
[Unit]
-Description=LVM2 PV scan on %I
+Description=LVM2 PV scan on device %i
Documentation=man:pvscan(8)
DefaultDependencies=no
-After=lvm2-lvmetad.socket %i.device
+BindsTo=dev-block-%i.device
+After=lvm2-lvmetad.socket
Before=shutdown.target
Conflicts=shutdown.target
[Service]
-Type=simple
-ExecStart=@sbindir@/pvscan --cache --activate ay %I
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=@sbindir@/pvscan --cache --activate ay /dev/block/%i
+ExecStop=@sbindir@/pvscan --cache %i
diff --git a/tools/pvscan.c b/tools/pvscan.c
index 3f16b05..b6a07bd 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -132,6 +132,27 @@ out:
return r;
}
+static int _clear_dev_from_lvmetad_cache(dev_t devno, int32_t major, int32_t minor,
+ activation_handler handler)
+{
+ char *buf;
+
+ if (!dm_asprintf(&buf, "%" PRIi32 ":%" PRIi32, major, minor))
+ stack;
+ if (!lvmetad_pv_gone(devno, buf ? : "", handler)) {
+ if (buf)
+ dm_free(buf);
+ return 0;
+ }
+
+ log_print_unless_silent("Device %s not found. "
+ "Cleared from lvmetad cache.", buf ? : "");
+ if (buf)
+ dm_free(buf);
+
+ return 1;
+}
+
static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
{
int ret = ECMD_PROCESSED;
@@ -142,7 +163,6 @@ static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
int devno_args = 0;
struct arg_value_group_list *current_group;
dev_t devno;
- char *buf;
activation_handler handler = NULL;
/*
@@ -193,11 +213,30 @@ static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
/* Process any command line PVs first. */
while (argc--) {
pv_name = *argv++;
- dev = dev_cache_get(pv_name, cmd->lvmetad_filter);
- if (!dev) {
- log_error("Physical Volume %s not found.", pv_name);
- ret = ECMD_FAILED;
- continue;
+ if (pv_name[0] == '/') {
+ /* device path */
+ if (!(dev = dev_cache_get(pv_name, cmd->lvmetad_filter))) {
+ log_error("Physical Volume %s not found.", pv_name);
+ ret = ECMD_FAILED;
+ continue;
+ }
+ }
+ else {
+ /* device major:minor */
+ if (sscanf(pv_name, "%d:%d", &major, &minor) != 2) {
+ log_error("Failed to parse major:minor from %s", pv_name);
+ ret = ECMD_FAILED;
+ continue;
+ }
+ devno = MKDEV((dev_t)major, minor);
+ if (!(dev = dev_cache_get_by_devt(devno, cmd->lvmetad_filter))) {
+ if (!(_clear_dev_from_lvmetad_cache(devno, major, minor, handler))) {
+ stack;
+ ret = ECMD_FAILED;
+ break;
+ }
+ continue;
+ }
}
if (sigint_caught()) {
ret = ECMD_FAILED;
@@ -225,19 +264,11 @@ static int _pvscan_lvmetad(struct cmd_context *cmd, int argc, char **argv)
devno = MKDEV((dev_t)major, minor);
if (!(dev = dev_cache_get_by_devt(devno, cmd->lvmetad_filter))) {
- if (!dm_asprintf(&buf, "%" PRIi32 ":%" PRIi32, major, minor))
+ if (!(_clear_dev_from_lvmetad_cache(devno, major, minor, handler))) {
stack;
- if (!lvmetad_pv_gone(devno, buf ? : "", handler)) {
ret = ECMD_FAILED;
- if (buf)
- dm_free(buf);
break;
}
-
- log_print_unless_silent("Device %s not found. "
- "Cleared from lvmetad cache.", buf ? : "");
- if (buf)
- dm_free(buf);
continue;
}
if (sigint_caught()) {
diff --git a/udev/Makefile.in b/udev/Makefile.in
index fdf43df..40a4671 100644
--- a/udev/Makefile.in
+++ b/udev/Makefile.in
@@ -47,7 +47,7 @@ BLKID_RULE=IMPORT{program}=\"${SBIN}\/blkid -o udev -p \$$tempnode\"
endif
ifeq ("@UDEV_SYSTEMD_BACKGROUND_JOBS@", "yes")
-PVSCAN_RULE=ENV{SYSTEMD_WANTS}=\"lvm2-pvscan@\$$devnode.service\"
+PVSCAN_RULE=ENV{SYSTEMD_ALIAS}=\"\/dev\/block\/\$$major:\$$minor\"\nENV{ID_MODEL}=\"LVM PV \$$env{ID_FS_UUID_ENC} on \/dev\/\$$name\"\nENV{SYSTEMD_WANTS}=\"lvm2-pvscan@\$$major:\$$minor.service\"
else
PVSCAN_RULE=RUN\+\=\"$(LVM_EXEC)/lvm pvscan --background --cache --activate ay --major \$$major --minor \$$minor\", ENV{LVM_SCANNED}=\"1\"
endif