Skip to contentSkip to conversation

stable-2.02 - pvscan: avoid redundant activation

PATCH David Teigland 1 participant 1 message Aug 26, 2019

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=8bcd482cc5fc58c9d5ff5305f1f1bff5d80eaa92
Commit:        8bcd482cc5fc58c9d5ff5305f1f1bff5d80eaa92
Parent:        93de9b59c21e6a3b29ccaa6425fde50a9053bdc2
Author:        David Teigland <[email protected]>
AuthorDate:    Mon Aug 19 14:22:01 2019 -0500
Committer:     David Teigland <[email protected]>
CommitterDate: Mon Aug 26 16:25:18 2019 -0500

pvscan: avoid redundant activation

Use temp files in /run/lvm/vgs_online/ to keep track of when a VG has been autoactivated by pvscan. When pvscan autoactivates a VG, it creates a temp file with the VG's name. Before a subsequent pvscan tries to autoactivate the same VG, it checks if a temp file exists for the VG name, and if so it skips it.

This can commonly happen when many devices appear on the system at once, which generates several concurrent pvscans. In this case the first pvscan does initialization by scanning all devices and activating any complete VGs. The other pvscans would attempt to activate the same complete VGs again. This extra work could create a bottleneck of pvscan commands.

If a VG is deactivated by vgchange, the vg online file is removed. If PVs are then disconnected/reconnected, pvscan will again autoactivate the VG.

Also, this patch disables the VG refresh that could be called from pvscan --cache -aay if lvmetad detects metadata inconsistencies. The role of pvscan should be limited to basic autoactivation, and any refresh scenarios are special cases that are not appropriate for automation.

The warning printed by commands retrying an lvmetad connection has been reduced to once every 10 seconds. New output messages have been added to pvscan to record when pvscan is falling back to direct activation of all VGs.

---
 lib/cache/lvmetad.c |   11 +++--
 tools/pvscan.c      |  108 ++++++++++++++++++++++++++++++++++++++++++++++++--
 tools/vgchange.c    |   13 ++++++
 3 files changed, 123 insertions(+), 9 deletions(-)
lib/cache/lvmetad.c +7 -4
index 86a880a..d7e798d 100644
@@ -248,7 +248,7 @@ int lvmetad_token_matches(struct cmd_context *cmd)
 	const char *daemon_token;
 	unsigned int delay_usec = 0;
 	unsigned int wait_sec = 0;
-	uint64_t now = 0, wait_start = 0;
+	uint64_t now = 0, wait_start = 0, last_warn = 0;
 	int ret = 1;
 
 	wait_sec = (unsigned int)_lvmetad_update_timeout;
@@ -294,12 +294,15 @@ retry:
 			wait_start = now;
 
 		if (now - wait_start > wait_sec) {
-			log_warn("WARNING: Not using lvmetad after %u sec lvmetad_update_wait_time.", wait_sec);
+			log_warn("pvscan[%d] WARNING: Not using lvmetad after %u sec lvmetad_update_wait_time.", getpid(), wait_sec);
 			goto fail;
 		}
 
-		log_warn("WARNING: lvmetad is being updated, retrying (setup) for %u more seconds.",
-			 wait_sec - (unsigned int)(now - wait_start));
+		if (now - last_warn >= 10) {
+			last_warn = now;
+			log_warn("pvscan[%d] WARNING: lvmetad is being updated, retrying (setup) for %u more seconds.",
+				 getpid(), wait_sec - (unsigned int)(now - wait_start));
+		}
 
 		/* Delay a random period between 1 and 2 seconds. */
 		delay_usec = 1000000 + lvm_even_rand(&_lvmetad_cmd->rand_seed, 1000000);
tools/pvscan.c +103 -5

177 lines not on this page · raw message

tools/vgchange.c +13 -0
index e15fca7..52abc11 100644
@@ -20,6 +20,8 @@ struct vgchange_params {
 	unsigned int lock_start_sanlock : 1;
 };
 
+extern void online_vg_file_remove(const char *vgname);
+
 /*
  * Increments *count by the number of _new_ monitored devices.
  */
@@ -259,6 +261,17 @@ int vgchange_activate(struct cmd_context *cmd, struct volume_group *vg,
 		r = 0;
 	}
 
+	if (!do_activate && r) {
+		/*
+		 * While the VG is inactive, the PVs may go offline.
+		 * If the PVs then come back online, pvscan --cache -aay
+		 * which should autoactivate the VG again.  We need
+		 * to remove the vg online file in order for the pvscan
+		 * to autoactivate the VG again.
+		 */
+		online_vg_file_remove(vg->name);
+	}
+
 	/* Print message only if there was not found a missing VG */
 	log_print_unless_silent("%d logical volume(s) in volume group \"%s\" now active",
 				lvs_in_vg_activated(vg), vg->name);