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

[lvm-devel] [PATCH] Allow incomplete (partial) mirror repairs in lvconvert --repair.



Hi,

this is a third rebase (actually, this is a rewrite, due to intervening
changes to lvconvert) of the RHBZ 560105+560111 fix. Please review...

Petr Rockai <prockai redhat com> writes:
> the attached patch should address RHBZ 560105 and 560111. This changes
> lvconvert --repair as follows:
>
> - downconvert (like before)
> - try to replace everything (like before)
> - if the second step fails, try to reduce number of mirror images (one
>   at a time) until only 2 remain
> - if this still fails and we used to have a disk log, try 2-way + corelog
>
> This should basically give you an LV that is closest to the original
> mirror, in the space constraints of free PV areas.
>
> Failures to replace (part of) the failed devices are now reported as
> warnings.

Yours,
   Petr.

diff -rN -u -p old-upstream/test/t-lvconvert-repair-policy.sh new-upstream/test/t-lvconvert-repair-policy.sh
--- old-upstream/test/t-lvconvert-repair-policy.sh	2010-04-13 16:14:56.000000000 +0200
+++ new-upstream/test/t-lvconvert-repair-policy.sh	2010-04-13 16:14:56.000000000 +0200
@@ -25,25 +25,24 @@ cleanup() {
 }
 
 repair() {
-	lvconvert -i 1 --repair --use-policies --config "$1" $vg/mirror
+	lvconvert --repair --use-policies --config "$1" $vg/mirror
 }
 
 lvcreate -m 1 -L 1 -n mirror $vg
 lvchange -a n $vg/mirror
 
 # Fail a leg of a mirror.
-# Expected result: linear
 disable_dev $dev1
 lvchange --partial -a y $vg/mirror
 repair 'activation { mirror_image_fault_policy = "remove" }'
-lvs | grep -- -wi-a- # non-mirror
+check linear $vg mirror
 cleanup $dev1
 
 # Fail a leg of a mirror.
 # Expected result: Mirror (leg replaced)
 disable_dev $dev1
 repair 'activation { mirror_image_fault_policy = "replace" }'
-lvs | grep -- mwi-a- # mirror
+check mirror $vg mirror
 lvs | grep mirror_mlog
 cleanup $dev1
 
@@ -51,22 +50,22 @@ cleanup $dev1
 # Expected result: Mirror (leg replaced)
 disable_dev $dev1
 repair 'activation { mirror_device_fault_policy = "replace" }'
-lvs | grep -- mwi-a- # mirror
+check mirror $vg mirror
 lvs | grep mirror_mlog
 cleanup $dev1
 
 # Fail a leg of a mirror w/ no available spare
-# Expected result: linear
+# Expected result: 2-way with corelog
 disable_dev $dev2 $dev4
 repair 'activation { mirror_image_fault_policy = "replace" }'
-lvs | grep -- -wi-a-
+check mirror $vg mirror
+lvs | not grep mirror_mlog
 cleanup $dev2 $dev4
 
 # Fail the log device of a mirror w/ no available spare
 # Expected result: mirror w/ corelog
 disable_dev $dev3 $dev4
-repair 'activation { mirror_image_fault_policy = "replace" }'
-lvs
-lvs | grep -- mwi-a-
+lvconvert --repair --use-policies --config 'activation { mirror_image_fault_policy = "replace" }' $vg/mirror
+check mirror $vg mirror
 lvs | not grep mirror_mlog
 cleanup $dev3 $dev4
diff -rN -u -p old-upstream/test/t-lvconvert-repair.sh new-upstream/test/t-lvconvert-repair.sh
--- old-upstream/test/t-lvconvert-repair.sh	2010-04-13 16:14:56.000000000 +0200
+++ new-upstream/test/t-lvconvert-repair.sh	2010-04-13 16:14:56.000000000 +0200
@@ -15,26 +15,26 @@ prepare_vg 5
 
 # fail multiple devices
 
-lvcreate -m 3 --ig -L 1 -n 3way $vg
+lvcreate -m 3 --ig -L 1 -n 4way $vg
 disable_dev $dev2 $dev4
-echo n | lvconvert -i 1 --repair $vg/3way
-lvs -a -o +devices > lvlist
-not grep unknown lvlist
+echo n | lvconvert --repair $vg/4way 2>&1 | tee 4way.out
+lvs -a -o +devices | not grep unknown
 vgreduce --removemissing $vg
 enable_dev $dev2 $dev4
-lvchange -a n $vg/3way
+check mirror $vg 4way
+lvchange -a n $vg/4way
 
 vgremove -ff $vg
 vgcreate -c n $vg $dev1 $dev2 $dev3 $dev4
 
-lvcreate -m 2 --ig -L 1 -n 4way $vg
+lvcreate -m 2 --ig -L 1 -n 3way $vg
 disable_dev $dev1 $dev2
-echo n | lvconvert -i 1 --repair $vg/4way
-lvs -a -o +devices > lvlist
-not grep unknown lvlist
+echo n | lvconvert --repair $vg/3way
+lvs -a -o +devices | not grep unknown
 vgreduce --removemissing $vg
 enable_dev $dev1 $dev2
-lvchange -a n $vg/4way
+check linear $vg 3way
+lvchange -a n $vg/3way
 
 # fail single devices
 
@@ -49,29 +49,20 @@ disable_dev $dev1
 lvchange --partial -a y $vg/mirror
 
 not vgreduce -v --removemissing $vg
-lvconvert -y -i 1 --repair $vg/mirror
+lvconvert -y --repair $vg/mirror
 vgreduce --removemissing $vg
 
 enable_dev $dev1
 vgextend $vg $dev1
 disable_dev $dev2
-lvconvert -y -i 1 --repair $vg/mirror
+lvconvert -y --repair $vg/mirror
 vgreduce --removemissing $vg
 
 enable_dev $dev2
 vgextend $vg $dev2
 disable_dev $dev3
-lvconvert -y -i 1 --repair $vg/mirror
+lvconvert -y --repair $vg/mirror
 vgreduce --removemissing $vg
 enable_dev $dev3
 vgextend $vg $dev3
 lvremove -ff $vg
-
-# Test repair of inactive mirror with log failure
-#  Replacement should fail, but covert should succeed (switch to corelog)
-lvcreate -m 2 --ig -l 2 -n mirror2 $vg $dev1 $dev2 $dev3 $dev4:0
-vgchange -a n $vg
-pvremove -ff -y $dev4
-echo 'y' | lvconvert -y -i 1 --repair $vg/mirror2
-# FIXME: check that mirror ok and log is now 'core'
-vgs
diff -rN -u -p old-upstream/tools/lvconvert.c new-upstream/tools/lvconvert.c
--- old-upstream/tools/lvconvert.c	2010-04-13 16:14:56.000000000 +0200
+++ new-upstream/tools/lvconvert.c	2010-04-13 16:14:56.000000000 +0200
@@ -920,24 +920,19 @@ static int _lvconvert_mirrors_parse_para
  * Add/remove mirror images and adjust log type.  'operable_pvs'
  * are the set of PVs open to removal or allocation - depending
  * on the operation being performed.
- *
- * If 'allocation_failures_ok' is set, and there is a failure to
- * convert due to space, success will be returned.
  */
 static int _lvconvert_mirrors_aux(struct cmd_context *cmd,
 				  struct logical_volume *lv,
 				  struct lvconvert_params *lp,
 				  struct dm_list *operable_pvs,
 				  uint32_t new_mimage_count,
-				  uint32_t new_log_count,
-				  int allocation_failures_ok)
+				  uint32_t new_log_count)
 {
 	uint32_t region_size;
 	struct lv_segment *seg;
 	struct logical_volume *layer_lv;
 	uint32_t old_mimage_count = lv_mirror_count(lv);
 	uint32_t old_log_count = _get_log_count(lv);
-	int failure_code = (allocation_failures_ok) ? 1 : 0;
 
 	if ((lp->mirrors == 1) && !(lv->status & MIRRORED)) {
 		log_error("Logical volume %s is already not mirrored.",
@@ -969,7 +964,7 @@ static int _lvconvert_mirrors_aux(struct
 				    lp->stripe_size, region_size, new_log_count, operable_pvs,
 				    lp->alloc, MIRROR_BY_LV)) {
 			stack;
-			return failure_code;
+			return 0;
 		}
 		if (lp->wait_completion)
 			lp->need_polling = 1;
@@ -997,7 +992,7 @@ static int _lvconvert_mirrors_aux(struct
 		if (lv_is_origin(lv)) {
 			log_error("Can't add additional mirror images to "
 				  "mirrors that are under snapshots");
-			return failure_code;
+			return 0;
 		}
 
 		/*
@@ -1008,7 +1003,7 @@ static int _lvconvert_mirrors_aux(struct
 		if (!_lv_update_log_type(cmd, lp, lv,
 					 operable_pvs, new_log_count)) {
 			stack;
-			return failure_code;
+			return 0;
 		}
 
 		/* Insert a temporary layer for syncing,
@@ -1036,7 +1031,7 @@ static int _lvconvert_mirrors_aux(struct
 				return 0;
 			}
 			stack;
-			return failure_code;
+			return 0;
 		}
 		if (seg->log_lv)
 			lv->status |= CONVERTING;
@@ -1074,7 +1069,7 @@ out:
 		if (!_lv_update_log_type(cmd, lp, lv,
 					 operable_pvs, new_log_count)) {
 			stack;
-			return failure_code;
+			return 0;
 		}
 	}
 
@@ -1127,7 +1122,7 @@ static int _lvconvert_mirrors_repair(str
 	int failed_mirrors = 0;
 	int replace_log = 0;
 	int replace_mirrors = 0;
-	uint32_t new_log_count;
+	uint32_t new_log_count, log_count;
 	struct dm_list *failed_pvs = NULL;
 	struct logical_volume *log_lv;
 
@@ -1192,38 +1187,44 @@ static int _lvconvert_mirrors_repair(str
 		return 0;
 
 	if (!_lvconvert_mirrors_aux(cmd, lv, lp, failed_pvs,
-				    lp->mirrors, new_log_count, 0))
+				    lp->mirrors, new_log_count))
 		return 0;
 
 	/*
 	 * Second phase - replace faulty devices
-	 *
-	 * FIXME: It would be nice to do this all in one step, but
-	 *        for simplicity, we replace mimages first and then
-	 *        work on the log.
 	 */
-	if (replace_mirrors && (old_mimage_count != lp->mirrors)) {
+
+	if (replace_mirrors)
 		lp->mirrors = old_mimage_count;
-		if (!_lvconvert_mirrors_aux(cmd, lv, lp, NULL,
-					    old_mimage_count, new_log_count, 1))
-			return 0;
-	}
 
-	log_lv = first_seg(lv)->log_lv;
-	if (replace_log && (old_log_count != new_log_count)) {
-		/*
-		 * If we are up-converting the log from linear to
-		 * mirrored, then we must use '_lvconvert_mirrors_aux'
-		 */
-		if ((new_log_count == 1) && (old_log_count > 1)) {
-			if (!_lvconvert_mirrors_aux(cmd, log_lv, lp, NULL,
-						    old_log_count, 0, 1))
-				return 0;
-		} else if (!_lv_update_log_type(cmd, lp, lv,
-						lp->pvh, new_log_count))
-			return 0;
+	log_count = replace_log ? old_log_count : new_log_count;
+
+	while (replace_mirrors || replace_log) {
+		log_warn("Trying to up-convert to %d images, %d logs.", lp->mirrors, log_count);
+		if (_lvconvert_mirrors_aux(cmd, lv, lp, NULL,
+					   lp->mirrors, log_count))
+			break;
+		else {
+			if (lp->mirrors > 2)
+				-- lp->mirrors;
+			else if (log_count > 0)
+				-- log_count;
+			else
+				break; /* nowhere to go, anymore... */
+		}
 	}
 
+	if (lp->mirrors != old_mimage_count)
+		log_warn("WARNING: Failed to replace %d of %d images in volume %s",
+			 old_mimage_count - lp->mirrors, old_mimage_count, lv->name);
+	if (log_count != old_log_count)
+		log_warn("WARNING: Failed to replace %d of %d logs in volume %s",
+			 old_log_count - log_count, old_log_count, lv->name);
+
+	/* if (!arg_count(cmd, use_policies_ARG) && (lp->mirrors != old_mimage_count
+						  || log_count != old_log_count))
+						  return 0; */
+
 	return 1;
 }
 
@@ -1260,7 +1261,7 @@ static int _lvconvert_mirrors(struct cmd
 						 old_log_count);
 
 	if (!_lvconvert_mirrors_aux(cmd, lv, lp, NULL,
-				    new_mimage_count, new_log_count, 0))
+				    new_mimage_count, new_log_count))
 		return 0;
 
 	if (!lp->need_polling)

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