mrc0mmand / rpms / lvm2

Forked from rpms/lvm2 3 years ago
Clone
Blob Blame History Raw
commit 129b8f8e525126f660fa22f88ee58cd086c5f338
Author: Peter Rajnoha <prajnoha@redhat.com>
Date:   Tue Mar 25 11:01:23 2014 +0100

    lvmcache init
---
 WHATS_NEW                       |  1 +
 lib/cache/lvmcache.c            |  9 ++++++---
 lib/cache/lvmcache.h            |  2 +-
 lib/commands/toolcontext.c      |  4 ++--
 test/shell/pvmove-background.sh | 24 ++++++++++++++++++++++++
 tools/lvmcmdline.c              |  2 +-
 tools/pvscan.c                  |  2 +-
 tools/toollib.c                 |  1 +
 tools/vgrename.c                |  2 +-
 tools/vgscan.c                  |  2 +-
 10 files changed, 39 insertions(+), 10 deletions(-)

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