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

[lvm-devel] [PATCH] Small lvconvert refactor + BZ 463272 fix



Hi,

the two attached patches should address the issue with "--mirrorlog disk" being
lost on partial down-conversion of mirrors.

I suspect this will conflict horribly with lvconvert --repair, but I'll fix
that up later. The patch should be relatively transparent otherwise. The
refactor makes it much easier (and nicer and safer) to formulate the actual
fix.

Yours,
   Petr.

Mon Mar  2 17:49:20 CET 2009  Petr Rockai <me mornfall net>
  * Slightly refactor mirror log conversions in lvconvert.
diff -rN -u -p old-upstream-1/tools/lvconvert.c new-upstream-1/tools/lvconvert.c
--- old-upstream-1/tools/lvconvert.c	2009-03-02 17:55:05.683696209 +0100
+++ new-upstream-1/tools/lvconvert.c	2009-03-02 17:55:05.935697162 +0100
@@ -375,6 +375,33 @@ static struct logical_volume *_original_
 	return next_lv;
 }
 
+static int _using_corelog(struct logical_volume *lv)
+{
+	return !first_seg(_original_lv(lv))->log_lv;
+}
+
+static int _lv_update_log_type(struct cmd_context *cmd,
+			       struct lvconvert_params *lp,
+			       struct logical_volume *lv,
+			       int corelog)
+{
+	struct logical_volume *original_lv = _original_lv(lv);
+	if (_using_corelog(lv) && !corelog) {
+		if (!add_mirror_log(cmd, original_lv, 1,
+				    adjusted_mirror_region_size(
+					lv->vg->extent_size,
+					lv->le_count,
+					lp->region_size),
+				    lp->pvh, lp->alloc))
+			return_0;
+	} else if (!_using_corelog(lv) && corelog) {
+		if (!remove_mirror_log(cmd, original_lv,
+				       lp->pv_count ? lp->pvh : NULL))
+			return_0;
+	}
+	return 1;
+}
+
 static int lvconvert_mirrors(struct cmd_context * cmd, struct logical_volume * lv,
 			     struct lvconvert_params *lp)
 {
@@ -382,7 +409,6 @@ static int lvconvert_mirrors(struct cmd_
 	uint32_t existing_mirrors;
 	const char *mirrorlog;
 	unsigned corelog = 0;
-	struct logical_volume *original_lv;
 
 	seg = first_seg(lv);
 	existing_mirrors = lv_mirror_count(lv);
@@ -508,24 +534,9 @@ static int lvconvert_mirrors(struct cmd_
 	}
 
 	if (lp->mirrors == existing_mirrors) {
-		/*
-		 * Convert Mirror log type
-		 */
-		original_lv = _original_lv(lv);
-		if (!first_seg(original_lv)->log_lv && !corelog) {
-			if (!add_mirror_log(cmd, original_lv, 1,
-					    adjusted_mirror_region_size(
-							lv->vg->extent_size,
-							lv->le_count,
-							lp->region_size),
-					    lp->pvh, lp->alloc))
-				return_0;
-		} else if (first_seg(original_lv)->log_lv && corelog) {
-			if (!remove_mirror_log(cmd, original_lv,
-					       lp->pv_count ? lp->pvh : NULL))
-				return_0;
-		} else {
-			/* No change */
+		if (_using_corelog(lv) != corelog)
+			_lv_update_log_type(cmd, lp, lv, corelog);
+		else {
 			log_error("Logical volume %s already has %"
 				  PRIu32 " mirror(s).", lv->name,
 				  lp->mirrors - 1);
@@ -544,20 +555,8 @@ static int lvconvert_mirrors(struct cmd_
 		 * insertion to make the end result consistent with
 		 * linear-to-mirror conversion.
 		 */
-		original_lv = _original_lv(lv);
-		if (!first_seg(original_lv)->log_lv && !corelog) {
-			if (!add_mirror_log(cmd, original_lv, 1,
-					    adjusted_mirror_region_size(
-							lv->vg->extent_size,
-							lv->le_count,
-							lp->region_size),
-					    lp->pvh, lp->alloc))
-				return_0;
-		} else if (first_seg(original_lv)->log_lv && corelog) {
-			if (!remove_mirror_log(cmd, original_lv,
-					       lp->pv_count ? lp->pvh : NULL))
-				return_0;
-		}
+		_lv_update_log_type(cmd, lp, lv, corelog);
+
 		/* Insert a temporary layer for syncing,
 		 * only if the original lv is using disk log. */
 		if (seg->log_lv && !_insert_lvconvert_layer(cmd, lv)) {
Mon Mar  2 17:54:32 CET 2009  Petr Rockai <me mornfall net>
  * Fix BZ 463272.
diff -rN -u -p old-upstream-1/test/t-mirror-lvconvert.sh new-upstream-1/test/t-mirror-lvconvert.sh
--- old-upstream-1/test/t-mirror-lvconvert.sh	2009-03-02 17:55:18.343696992 +0100
+++ new-upstream-1/test/t-mirror-lvconvert.sh	2009-03-02 17:55:18.547693100 +0100
@@ -313,3 +313,8 @@ lvconvert -m0 $vg/$lv1
 lvconvert -m1 $vg/$lv1
 lvs --noheadings -o attr $vg/$lv1 | grep '^ *m'
 
+# BZ 463272: disk log mirror convert option is lost if downconvert option is also given
+prepare_lvs_
+lvcreate -l1 -m2 --corelog -n $lv1 $vg
+lvconvert -m1 --mirrorlog disk $vg/$lv1
+check_mirror_log_ $vg/$lv1
diff -rN -u -p old-upstream-1/tools/lvconvert.c new-upstream-1/tools/lvconvert.c
--- old-upstream-1/tools/lvconvert.c	2009-03-02 17:55:18.343696992 +0100
+++ new-upstream-1/tools/lvconvert.c	2009-03-02 17:55:18.563692619 +0100
@@ -580,6 +580,7 @@ static int lvconvert_mirrors(struct cmd_
 				       corelog ? 1U : 0U,
 				       lp->pv_count ? lp->pvh : NULL, 0))
 			return_0;
+		_lv_update_log_type(cmd, lp, lv, corelog);
 	}
 
 commit_changes:
-- 
Peter Rockai | me()mornfall!net | prockai()redhat!com
 http://blog.mornfall.net | http://web.mornfall.net

"In My Egotistical Opinion, most people's C programs should be
 indented six feet downward and covered with dirt."
     -- Blair P. Houghton on the subject of C program indentation

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