mrc0mmand / rpms / lvm2

Forked from rpms/lvm2 2 years ago
Clone

Blame SOURCES/lvm2-2_02_104-add-dev-block-major-minor-device-systemd-alias-and-pvscan-cache-shortcut.patch

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