mrc0mmand / rpms / lvm2

Forked from rpms/lvm2 2 years ago
Clone

Blame SOURCES/lvm2-2_02_106-reinitialise-lvmcache-properly-on-fork-to-fix-premature-polldaemon-exit.patch

4c7ee1
commit 129b8f8e525126f660fa22f88ee58cd086c5f338
4c7ee1
Author: Peter Rajnoha <prajnoha@redhat.com>
4c7ee1
Date:   Tue Mar 25 11:01:23 2014 +0100
4c7ee1
4c7ee1
    lvmcache init
4c7ee1
---
4c7ee1
 WHATS_NEW                       |  1 +
4c7ee1
 lib/cache/lvmcache.c            |  9 ++++++---
4c7ee1
 lib/cache/lvmcache.h            |  2 +-
4c7ee1
 lib/commands/toolcontext.c      |  4 ++--
4c7ee1
 test/shell/pvmove-background.sh | 24 ++++++++++++++++++++++++
4c7ee1
 tools/lvmcmdline.c              |  2 +-
4c7ee1
 tools/pvscan.c                  |  2 +-
4c7ee1
 tools/toollib.c                 |  1 +
4c7ee1
 tools/vgrename.c                |  2 +-
4c7ee1
 tools/vgscan.c                  |  2 +-
4c7ee1
 10 files changed, 39 insertions(+), 10 deletions(-)
4c7ee1
4c7ee1
diff --git a/WHATS_NEW b/WHATS_NEW
4c7ee1
index b5afb19..cf6103d 100644
4c7ee1
--- a/WHATS_NEW
4c7ee1
+++ b/WHATS_NEW
4c7ee1
@@ -1,5 +1,6 @@
4c7ee1
 Version 2.02.106 - 
4c7ee1
 ====================================
4c7ee1
+  Reinitialise lvmcache properly on fork to fix polldaemon exiting prematurely.
4c7ee1
   Use VG read lock during 'pvscan --cache -aay' autoactivation.
4c7ee1
   Issue a VG refresh before autoactivation only if the PV has changed/is new.
4c7ee1
   Add flag to lvmetad protocol to indicate the PV scanned has changed/is new.
4c7ee1
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
4c7ee1
index d40bdce..fe64c8a 100644
4c7ee1
--- a/lib/cache/lvmcache.c
4c7ee1
+++ b/lib/cache/lvmcache.c
4c7ee1
@@ -1609,7 +1609,7 @@ static void _lvmcache_destroy_lockname(struct dm_hash_node *n)
4c7ee1
 			  dm_hash_get_key(_lock_hash, n));
4c7ee1
 }
4c7ee1
 
4c7ee1
-void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans)
4c7ee1
+void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans, int reset)
4c7ee1
 {
4c7ee1
 	struct dm_hash_node *n;
4c7ee1
 	log_verbose("Wiping internal VG cache");
4c7ee1
@@ -1635,8 +1635,11 @@ void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans)
4c7ee1
 	}
4c7ee1
 
4c7ee1
 	if (_lock_hash) {
4c7ee1
-		dm_hash_iterate(n, _lock_hash)
4c7ee1
-			_lvmcache_destroy_lockname(n);
4c7ee1
+		if (reset)
4c7ee1
+			_vg_global_lock_held = 0;
4c7ee1
+		else
4c7ee1
+			dm_hash_iterate(n, _lock_hash)
4c7ee1
+				_lvmcache_destroy_lockname(n);
4c7ee1
 		dm_hash_destroy(_lock_hash);
4c7ee1
 		_lock_hash = NULL;
4c7ee1
 	}
4c7ee1
diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h
4c7ee1
index bf26664..83d561b 100644
4c7ee1
--- a/lib/cache/lvmcache.h
4c7ee1
+++ b/lib/cache/lvmcache.h
4c7ee1
@@ -42,7 +42,7 @@ struct lvmcache_vginfo;
4c7ee1
 int lvmcache_init(void);
4c7ee1
 void lvmcache_allow_reads_with_lvmetad(void);
4c7ee1
 
4c7ee1
-void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans);
4c7ee1
+void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans, int reset);
4c7ee1
 
4c7ee1
 /* Set full_scan to 1 to reread every filtered device label or
4c7ee1
  * 2 to rescan /dev for new devices */
4c7ee1
diff --git a/lib/commands/toolcontext.c b/lib/commands/toolcontext.c
4c7ee1
index a709284..d08ca61 100644
4c7ee1
--- a/lib/commands/toolcontext.c
4c7ee1
+++ b/lib/commands/toolcontext.c
4c7ee1
@@ -1640,7 +1640,7 @@ int refresh_toolcontext(struct cmd_context *cmd)
4c7ee1
 	 */
4c7ee1
 
4c7ee1
 	activation_release();
4c7ee1
-	lvmcache_destroy(cmd, 0);
4c7ee1
+	lvmcache_destroy(cmd, 0, 0);
4c7ee1
 	label_exit();
4c7ee1
 	_destroy_segtypes(&cmd->segtypes);
4c7ee1
 	_destroy_formats(cmd, &cmd->formats);
4c7ee1
@@ -1732,7 +1732,7 @@ void destroy_toolcontext(struct cmd_context *cmd)
4c7ee1
 
4c7ee1
 	archive_exit(cmd);
4c7ee1
 	backup_exit(cmd);
4c7ee1
-	lvmcache_destroy(cmd, 0);
4c7ee1
+	lvmcache_destroy(cmd, 0, 0);
4c7ee1
 	label_exit();
4c7ee1
 	_destroy_segtypes(&cmd->segtypes);
4c7ee1
 	_destroy_formats(cmd, &cmd->formats);
4c7ee1
diff --git a/test/shell/pvmove-background.sh b/test/shell/pvmove-background.sh
4c7ee1
new file mode 100644
4c7ee1
index 0000000..0f657be
4c7ee1
--- /dev/null
4c7ee1
+++ b/test/shell/pvmove-background.sh
4c7ee1
@@ -0,0 +1,24 @@
4c7ee1
+#!/bin/sh
4c7ee1
+# Copyright (C) 2014 Red Hat, Inc. All rights reserved.
4c7ee1
+#
4c7ee1
+# This copyrighted material is made available to anyone wishing to use,
4c7ee1
+# modify, copy, or redistribute it subject to the terms and conditions
4c7ee1
+# of the GNU General Public License v.2.
4c7ee1
+#
4c7ee1
+# You should have received a copy of the GNU General Public License
4c7ee1
+# along with this program; if not, write to the Free Software Foundation,
4c7ee1
+# Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4c7ee1
+
4c7ee1
+# Check pvmove behavior when it's progress and machine is rebooted
4c7ee1
+
4c7ee1
+. lib/test
4c7ee1
+
4c7ee1
+aux prepare_vg 3
4c7ee1
+
4c7ee1
+lvcreate -l1 -n $lv1 $vg "$dev1"
4c7ee1
+
4c7ee1
+lvs -o +devices | grep $dev1
4c7ee1
+pvmove -i 1 -b "$dev1" "$dev2"
4c7ee1
+sleep 5 # arbitrary...
4c7ee1
+lvs -o +devices | not grep "pvmove"
4c7ee1
+lvs -o +devices | grep "$dev2"
4c7ee1
diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c
4c7ee1
index 6fe4670..e70e64a 100644
4c7ee1
--- a/tools/lvmcmdline.c
4c7ee1
+++ b/tools/lvmcmdline.c
4c7ee1
@@ -1183,7 +1183,7 @@ int lvm_run_command(struct cmd_context *cmd, int argc, char **argv)
4c7ee1
       out:
4c7ee1
 	if (test_mode()) {
4c7ee1
 		log_verbose("Test mode: Wiping internal cache");
4c7ee1
-		lvmcache_destroy(cmd, 1);
4c7ee1
+		lvmcache_destroy(cmd, 1, 0);
4c7ee1
 	}
4c7ee1
 
4c7ee1
 	if ((old_cft = remove_config_tree_by_source(cmd, CONFIG_STRING))) {
4c7ee1
diff --git a/tools/pvscan.c b/tools/pvscan.c
4c7ee1
index 5db627a..af834fe 100644
4c7ee1
--- a/tools/pvscan.c
4c7ee1
+++ b/tools/pvscan.c
4c7ee1
@@ -373,7 +373,7 @@ int pvscan(struct cmd_context *cmd, int argc, char **argv)
4c7ee1
 
4c7ee1
 	if (cmd->filter->wipe)
4c7ee1
 		cmd->filter->wipe(cmd->filter);
4c7ee1
-	lvmcache_destroy(cmd, 1);
4c7ee1
+	lvmcache_destroy(cmd, 1, 0);
4c7ee1
 
4c7ee1
 	/* populate lvmcache */
4c7ee1
 	if (!lvmetad_vg_list_to_lvmcache(cmd))
4c7ee1
diff --git a/tools/toollib.c b/tools/toollib.c
4c7ee1
index 91b0559..6b68f55 100644
4c7ee1
--- a/tools/toollib.c
4c7ee1
+++ b/tools/toollib.c
4c7ee1
@@ -92,6 +92,7 @@ int become_daemon(struct cmd_context *cmd, int skip_lvm)
4c7ee1
 
4c7ee1
 	if (!skip_lvm) {
4c7ee1
 		reset_locking();
4c7ee1
+		lvmcache_destroy(cmd, 1, 1);
4c7ee1
 		if (!lvmcache_init())
4c7ee1
 			/* FIXME Clean up properly here */
4c7ee1
 			_exit(ECMD_FAILED);
4c7ee1
diff --git a/tools/vgrename.c b/tools/vgrename.c
4c7ee1
index b5e778f..d97b871 100644
4c7ee1
--- a/tools/vgrename.c
4c7ee1
+++ b/tools/vgrename.c
4c7ee1
@@ -185,7 +185,7 @@ static int vg_rename_path(struct cmd_context *cmd, const char *old_vg_path,
4c7ee1
 	/* FIXME lvmcache corruption - vginfo duplicated instead of renamed */
4c7ee1
 	if (cmd->filter->wipe)
4c7ee1
 		cmd->filter->wipe(cmd->filter);
4c7ee1
-	lvmcache_destroy(cmd, 1);
4c7ee1
+	lvmcache_destroy(cmd, 1, 0);
4c7ee1
 
4c7ee1
 	return 1;
4c7ee1
 
4c7ee1
diff --git a/tools/vgscan.c b/tools/vgscan.c
4c7ee1
index baf25b0..fff0e89 100644
4c7ee1
--- a/tools/vgscan.c
4c7ee1
+++ b/tools/vgscan.c
4c7ee1
@@ -44,7 +44,7 @@ int vgscan(struct cmd_context *cmd, int argc, char **argv)
4c7ee1
 
4c7ee1
 	if (cmd->filter->wipe)
4c7ee1
 		cmd->filter->wipe(cmd->filter);
4c7ee1
-	lvmcache_destroy(cmd, 1);
4c7ee1
+	lvmcache_destroy(cmd, 1, 0);
4c7ee1
 
4c7ee1
 	if (arg_count(cmd, cache_ARG)) {
4c7ee1
 		if (lvmetad_active()) {