[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[lvm-devel] [PATCH] Relax exit codes for policy-driven lvconvert --repair.



Hi,

due to the interpretation of "replace" policies as "replace if possible,
downconvert otherwise", we should treat successful downconversion as a
success in these cases, even if we were unable to replace the missing
devices with new ones.

The attached patch also makes the "nothing to repair" condition a
non-error (with and without --use-policies... it's arguably not really
an error). This would hopefully address RHBZ 552723, if it is indeed the
case (as it seems) that the problem there is that the missing devices
have already returned by the time that lvconvert --repair kicks in (and
therefore it does not detect anything to repair).

Yours,
   Petr.

Index: tools/lvconvert.c
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/lvconvert.c,v
retrieving revision 1.101
diff -u -p -r1.101 lvconvert.c
--- tools/lvconvert.c	6 Jan 2010 13:27:07 -0000	1.101
+++ tools/lvconvert.c	7 Jan 2010 19:58:02 -0000
@@ -587,6 +587,7 @@ static int _lvconvert_mirrors(struct cmd
 
 	int repair = arg_count(cmd, repair_ARG);
 	int replace_log = 1, replace_mirrors = 1;
+	int failure_code = 0;
 
 	seg = first_seg(lv);
 	existing_mirrors = lv_mirror_count(lv);
@@ -634,7 +635,7 @@ static int _lvconvert_mirrors(struct cmd
 		lp->need_polling = 0;
 		if (!(lv->status & PARTIAL_LV)) {
 			log_error("The mirror is consistent, nothing to repair.");
-			return 0;
+			return 1;
 		}
 		if ((failed_mirrors = _failed_mirrors_count(lv)) < 0)
 			return_0;
@@ -759,8 +760,10 @@ static int _lvconvert_mirrors(struct cmd
 						lv->le_count,
 						lp->region_size),
 				    corelog ? 0U : 1U, lp->pvh, lp->alloc,
-				    MIRROR_BY_LV))
-			return_0;
+				    MIRROR_BY_LV)) {
+			stack;
+			return failure_code;
+		}
 		if (lp->wait_completion)
 			lp->need_polling = 1;
 	} else if (lp->mirrors > existing_mirrors || failed_mirrors) {
@@ -780,7 +783,7 @@ static int _lvconvert_mirrors(struct cmd
 		if (lv_is_origin(lv)) {
 			log_error("Can't add additional mirror images to "
 				  "mirrors that are under snapshots");
-			return 0;
+			return failure_code;
 		}
 
 		/*
@@ -788,8 +791,10 @@ static int _lvconvert_mirrors(struct cmd
 		 * insertion to make the end result consistent with
 		 * linear-to-mirror conversion.
 		 */
-		if (!_lv_update_log_type(cmd, lp, lv, corelog))
-			return_0;
+		if (!_lv_update_log_type(cmd, lp, lv, corelog)) {
+			stack;
+			return failure_code;
+		}
 		/* Insert a temporary layer for syncing,
 		 * only if the original lv is using disk log. */
 		if (seg->log_lv && !_insert_lvconvert_layer(cmd, lv)) {
@@ -816,7 +821,8 @@ static int _lvconvert_mirrors(struct cmd
 					  "and dmsetup may be required.");
 				return 0;
 			}
-			return_0;
+			stack;
+			return failure_code;
 		}
 		lv->status |= CONVERTING;
 		lp->need_polling = 1;
@@ -824,8 +830,10 @@ static int _lvconvert_mirrors(struct cmd
 
 	if (lp->mirrors == existing_mirrors) {
 		if (_using_corelog(lv) != corelog) {
-			if (!_lv_update_log_type(cmd, lp, lv, corelog))
-				return_0;
+			if (!_lv_update_log_type(cmd, lp, lv, corelog)) {
+				stack;
+				return failure_code;
+			}
 		} else {
 			log_error("Logical volume %s already has %"
 				  PRIu32 " mirror(s).", lv->name,
@@ -868,6 +876,13 @@ static int _lvconvert_mirrors(struct cmd
 			lp->mirrors += failed_mirrors;
 		failed_mirrors = 0;
 		existing_mirrors = lv_mirror_count(lv);
+		/*
+		 * Ignore failure in upconversion if this is a policy-driven
+		 * action. If we got this far, only unexpected failures are
+		 * reported.
+		 */
+		if (arg_count(cmd, use_policies_ARG))
+			failure_code = 1;
 		/* Now replace missing devices. */
 		if (replace_log || replace_mirrors)
 			goto restart;
Index: test/t-lvconvert-repair-policy.sh
===================================================================
RCS file: test/t-lvconvert-repair-policy.sh
diff -N test/t-lvconvert-repair-policy.sh
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ test/t-lvconvert-repair-policy.sh	7 Jan 2010 19:58:02 -0000
@@ -0,0 +1,61 @@
+#!/bin/bash
+# Copyright (C) 2008 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
+
+. ./test-utils.sh
+
+prepare_vg 4
+
+cleanup() {
+	vgreduce --removemissing $vg
+	for d in "$@"; do enable_dev $d; done
+	for d in "$@"; do vgextend $vg $d; done
+	lvremove -ff $vg/mirror
+	lvcreate -m 1 -L 1 -n mirror $vg
+}
+
+repair() {
+	lvconvert -i 1 --repair --use-policies --config "$1" $vg/mirror
+}
+
+lvcreate -m 1 -L 1 -n mirror $vg
+lvchange -a n $vg/mirror
+
+disable_dev $dev1
+lvchange --partial -a y $vg/mirror
+repair 'activation { mirror_image_fault_policy = "remove" }'
+lvs | grep -- -wi-a- # non-mirror
+cleanup $dev1
+
+disable_dev $dev1
+repair 'activation { mirror_image_fault_policy = "replace" }'
+lvs | grep -- mwi-a- # mirror
+lvs | grep mirror_mlog
+cleanup $dev1
+
+disable_dev $dev1
+repair 'activation { mirror_device_fault_policy = "replace" }'
+lvs | grep -- mwi-a- # mirror
+lvs | grep mirror_mlog
+cleanup $dev1
+
+disable_dev $dev2 $dev4
+# no room for repair, downconversion should happen
+repair 'activation { mirror_image_fault_policy = "replace" }'
+lvs | grep -- -wi-a-
+cleanup $dev2 $dev4
+
+disable_dev $dev2 $dev4
+# no room for new log, corelog conversion should happen
+repair 'activation { mirror_image_fault_policy = "replace" }'
+lvs
+lvs | grep -- mwi-a-
+lvs | not grep mirror_mlog
+cleanup $dev2 $dev4

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]