Blame SOURCES/lvm2-2_02_182-lvconvert-fix-conversion-attempts-to-linear.patch

0d8a0a
From 83b93f9f5a72ac67f63e6be2c25ce4b3919c4c84 Mon Sep 17 00:00:00 2001
0d8a0a
From: Heinz Mauelshagen <heinzm@redhat.com>
0d8a0a
Date: Wed, 22 Aug 2018 16:39:36 +0200
0d8a0a
Subject: [PATCH] lvconvert: fix conversion attempts to linear
0d8a0a
0d8a0a
"lvconvert --type linear RaidLV" on striped and raid4/5/6/10
0d8a0a
have to provide the convenient interim layouts.  Fix involves
0d8a0a
a cleanup to the convenience type function.
0d8a0a
0d8a0a
As a result of testing, add missing sync waits to
0d8a0a
lvconvert-raid-reshape-linear_to_raid6-single-type.sh.
0d8a0a
0d8a0a
Resolves: rhbz1447809
0d8a0a
(cherry picked from commit e83c4f07ca4a84808178d5d22cba655e5e370cd8)
0d8a0a
0d8a0a
Conflicts:
0d8a0a
	WHATS_NEW
0d8a0a
0d8a0a
(cherry picked from commit d910f75d89e02e46cd16f9ddbc8e8358c3c2efd3)
0d8a0a
---
0d8a0a
 WHATS_NEW                                          |   1 +
0d8a0a
 lib/metadata/raid_manip.c                          | 145 +++++++++------------
0d8a0a
 ...ert-raid-reshape-linear_to_raid6-single-type.sh |   2 +
0d8a0a
 3 files changed, 68 insertions(+), 80 deletions(-)
0d8a0a
0d8a0a
diff --git a/WHATS_NEW b/WHATS_NEW
0d8a0a
index e3eee56..92e5c04 100644
0d8a0a
--- a/WHATS_NEW
0d8a0a
+++ b/WHATS_NEW
0d8a0a
@@ -1,5 +1,6 @@
0d8a0a
 Version 2.02.182 - 
0d8a0a
 ==============================
0d8a0a
+  Fix lvconvert conversion attempts to linear.
0d8a0a
   Fix lvconvert raid0/raid0_meta -> striped regression.
0d8a0a
   Fix lvconvert --splitmirror for mirror type (2.02.178).
0d8a0a
   Do not pair cache policy and cache metadata format.
0d8a0a
diff --git a/lib/metadata/raid_manip.c b/lib/metadata/raid_manip.c
0d8a0a
index 804f78b..d3e3a20 100644
0d8a0a
--- a/lib/metadata/raid_manip.c
0d8a0a
+++ b/lib/metadata/raid_manip.c
0d8a0a
@@ -6120,8 +6120,7 @@ static int _set_convenient_raid145610_segtype_to(const struct lv_segment *seg_fr
0d8a0a
 	const struct segment_type *segtype_sav = *segtype;
0d8a0a
 
0d8a0a
 	/* Linear -> striped request */
0d8a0a
-	if (seg_is_striped(seg_from) &&
0d8a0a
-	    seg_from->area_count == 1 &&
0d8a0a
+	if (seg_is_linear(seg_from) &&
0d8a0a
 	    segtype_is_striped(*segtype))
0d8a0a
 		;
0d8a0a
 	/* Bail out if same RAID level is requested. */
0d8a0a
@@ -6130,24 +6129,20 @@ static int _set_convenient_raid145610_segtype_to(const struct lv_segment *seg_fr
0d8a0a
 
0d8a0a
 	log_debug("Checking LV %s requested %s segment type for convenience",
0d8a0a
 		  display_lvname(seg_from->lv), (*segtype)->name);
0d8a0a
-	/* striped/raid0 -> raid5/6 */
0d8a0a
-	if (seg_is_striped(seg_from) || seg_is_any_raid0(seg_from)) {
0d8a0a
-		/* linear -> raid*, interim/first conversion is to raid1 */
0d8a0a
-		if (seg_from->area_count == 1)
0d8a0a
-			seg_flag = SEG_RAID1;
0d8a0a
-
0d8a0a
-		else if (seg_is_any_raid0(seg_from) && segtype_is_striped(*segtype))
0d8a0a
-			;
0d8a0a
-
0d8a0a
-		/* If this is any raid5 conversion request -> enforce raid5_n, because we convert from striped */
0d8a0a
-		else if (((segtype_is_striped(*segtype) && !segtype_is_any_raid0(*segtype)) || segtype_is_any_raid5(*segtype)) &&
0d8a0a
-			 !segtype_is_raid5_n(*segtype))
0d8a0a
-			seg_flag = SEG_RAID5_N;
0d8a0a
 
0d8a0a
-		/* If this is any raid6 conversion request -> enforce raid6_n_6, because we convert from striped */
0d8a0a
-		else if (segtype_is_any_raid6(*segtype) && !segtype_is_raid6_n_6(*segtype))
0d8a0a
+	/* linear -> */
0d8a0a
+	if (seg_is_linear(seg_from)) {
0d8a0a
+		seg_flag = SEG_RAID1;
0d8a0a
+
0d8a0a
+	/* striped/raid0 -> */
0d8a0a
+	} else if (seg_is_striped(seg_from) || seg_is_any_raid0(seg_from)) {
0d8a0a
+		if (segtype_is_any_raid6(*segtype))
0d8a0a
 			seg_flag = SEG_RAID6_N_6;
0d8a0a
 
0d8a0a
+		if (segtype_is_linear(*segtype) ||
0d8a0a
+		    (!segtype_is_raid10(*segtype) && !segtype_is_striped(*segtype)))
0d8a0a
+			seg_flag = SEG_RAID5_N;
0d8a0a
+
0d8a0a
 	/* raid1 -> */
0d8a0a
 	} else if (seg_is_raid1(seg_from) && !segtype_is_mirror(*segtype)) {
0d8a0a
 		if (seg_from->area_count != 2) {
0d8a0a
@@ -6157,85 +6152,68 @@ static int _set_convenient_raid145610_segtype_to(const struct lv_segment *seg_fr
0d8a0a
 		}
0d8a0a
 
0d8a0a
 		if (segtype_is_striped(*segtype) ||
0d8a0a
-			   segtype_is_any_raid0(*segtype) ||
0d8a0a
-			   segtype_is_raid10(*segtype))
0d8a0a
+		    segtype_is_any_raid0(*segtype) ||
0d8a0a
+		    segtype_is_raid10(*segtype))
0d8a0a
 			seg_flag = SEG_RAID5_N;
0d8a0a
 
0d8a0a
 		else if (!segtype_is_raid4(*segtype) && !segtype_is_any_raid5(*segtype))
0d8a0a
 			seg_flag = SEG_RAID5_LS;
0d8a0a
 
0d8a0a
-	/* raid4/raid5 -> striped/raid0/raid1/raid6/raid10 */
0d8a0a
-	} else if (seg_is_raid4(seg_from) || seg_is_any_raid5(seg_from)) {
0d8a0a
-		if ((segtype_is_raid1(*segtype) || segtype_is_linear(*segtype)) && seg_is_raid5_n(seg_from)) {
0d8a0a
+	/* raid5* -> */
0d8a0a
+	} else if (seg_is_any_raid5(seg_from)) {
0d8a0a
+		if (segtype_is_raid1(*segtype) || segtype_is_linear(*segtype)) {
0d8a0a
 			if (seg_from->area_count != 2) {
0d8a0a
 				log_error("Converting %s LV %s to 2 stripes first.",
0d8a0a
 					  lvseg_name(seg_from), display_lvname(seg_from->lv));
0d8a0a
 				*new_image_count = 2;
0d8a0a
-				seg_flag = SEG_RAID5_N;
0d8a0a
+				*segtype = seg_from->segtype;
0d8a0a
+				seg_flag = 0;
0d8a0a
 			} else
0d8a0a
 				seg_flag = SEG_RAID1;
0d8a0a
 
0d8a0a
-		} else if (segtype_is_raid1(*segtype) && seg_from->area_count != 2) {
0d8a0a
-			log_error("Convert %s LV %s to 2 stripes first (i.e. --stripes 1).",
0d8a0a
-				  lvseg_name(seg_from), display_lvname(seg_from->lv));
0d8a0a
-			return 0;
0d8a0a
-
0d8a0a
-		} else if (seg_is_raid4(seg_from) &&
0d8a0a
-		         (segtype_is_linear(*segtype) || segtype_is_any_raid5(*segtype)) &&
0d8a0a
-			 !segtype_is_raid5_n(*segtype))
0d8a0a
-			seg_flag = SEG_RAID5_N;
0d8a0a
+		} else if (segtype_is_any_raid6(*segtype)) {
0d8a0a
+			if (seg_from->area_count < 4) {
0d8a0a
+				if (*stripes > 3)
0d8a0a
+					*new_image_count = *stripes + seg_from->segtype->parity_devs;
0d8a0a
+				else
0d8a0a
+					*new_image_count = 4;
0d8a0a
 
0d8a0a
-		else if (seg_is_raid5_n(seg_from) && seg_from->area_count == 2) {
0d8a0a
-			if (*stripes >= 2) {
0d8a0a
+				*segtype = seg_from->segtype;
0d8a0a
 				log_error("Converting %s LV %s to %u stripes first.",
0d8a0a
-					  lvseg_name(seg_from), display_lvname(seg_from->lv), *stripes);
0d8a0a
+					  lvseg_name(seg_from), display_lvname(seg_from->lv), *new_image_count);
0d8a0a
+
0d8a0a
+			} else
0d8a0a
+				seg_flag = _raid_seg_flag_5_to_6(seg_from);
0d8a0a
+
0d8a0a
+		} else if (segtype_is_striped(*segtype) || segtype_is_raid10(*segtype)) {
0d8a0a
+			int change = 0;
0d8a0a
+
0d8a0a
+			if (!seg_is_raid5_n(seg_from)) {
0d8a0a
+				seg_flag = SEG_RAID5_N;
0d8a0a
+
0d8a0a
+			} else if (*stripes > 2 && *stripes != seg_from->area_count - seg_from->segtype->parity_devs) {
0d8a0a
+				change = 1;
0d8a0a
 				*new_image_count = *stripes + seg_from->segtype->parity_devs;
0d8a0a
 				seg_flag = SEG_RAID5_N;
0d8a0a
-			} else {
0d8a0a
-				log_error("Convert %s LV %s to minimum 3 stripes first (i.e. --stripes 2).",
0d8a0a
-					  lvseg_name(seg_from), display_lvname(seg_from->lv));
0d8a0a
-				return 0;
0d8a0a
-			}
0d8a0a
-		} else if (seg_is_any_raid5(seg_from) &&
0d8a0a
-		         (segtype_is_linear(*segtype) || segtype_is_raid4(*segtype)) &&
0d8a0a
-			 !segtype_is_raid5_n(*segtype))
0d8a0a
-			seg_flag = SEG_RAID5_N;
0d8a0a
 
0d8a0a
-		else if (segtype_is_raid10(*segtype)) {
0d8a0a
-			if (seg_from->area_count < 3) {
0d8a0a
-				if (*stripes >= 2) {
0d8a0a
-					log_error("Converting %s LV %s to %u stripes first.",
0d8a0a
-						  lvseg_name(seg_from), display_lvname(seg_from->lv), *stripes);
0d8a0a
-					*new_image_count = *stripes + seg_from->segtype->parity_devs;
0d8a0a
-					seg_flag = SEG_RAID5_N;
0d8a0a
-				} else {
0d8a0a
-					log_error("Convert %s LV %s to minimum 3 stripes first (i.e. --stripes 2).",
0d8a0a
-						  lvseg_name(seg_from), display_lvname(seg_from->lv));
0d8a0a
-					return 0;
0d8a0a
-				}
0d8a0a
-			} else
0d8a0a
-				seg_flag = seg_is_raid5_n(seg_from) ? SEG_RAID0_META : SEG_RAID5_N;
0d8a0a
+			} else if (seg_from->area_count < 3) {
0d8a0a
+				change = 1;
0d8a0a
+				*new_image_count = 3;
0d8a0a
+				seg_flag = SEG_RAID5_N;
0d8a0a
 
0d8a0a
-		} else if (segtype_is_any_raid6(*segtype)) {
0d8a0a
-			if (seg_from->area_count < 4 &&
0d8a0a
-			    seg_is_any_raid5(seg_from)) {
0d8a0a
-				if (*stripes >= 3) {
0d8a0a
-					log_error("Converting %s LV %s to %u stripes first.",
0d8a0a
-						  lvseg_name(seg_from), display_lvname(seg_from->lv), *stripes);
0d8a0a
-					*new_image_count = *stripes + seg_from->segtype->parity_devs;
0d8a0a
-					seg_flag = SEG_RAID5_LS;
0d8a0a
-				} else {
0d8a0a
-					log_error("Convert %s LV %s to minimum 4 stripes first (i.e. --stripes 3).",
0d8a0a
-						  lvseg_name(seg_from), display_lvname(seg_from->lv));
0d8a0a
-					return 0;
0d8a0a
-				}
0d8a0a
+			} else if (!segtype_is_striped(*segtype))
0d8a0a
+				seg_flag = SEG_RAID0_META;
0d8a0a
 
0d8a0a
-			} else if (seg_is_raid4(seg_from) && !segtype_is_raid6_n_6(*segtype))
0d8a0a
-				seg_flag = SEG_RAID6_N_6;
0d8a0a
-			else
0d8a0a
-				seg_flag = _raid_seg_flag_5_to_6(seg_from);
0d8a0a
+			if (change)
0d8a0a
+				log_error("Converting %s LV %s to %u stripes first.",
0d8a0a
+					  lvseg_name(seg_from), display_lvname(seg_from->lv), *new_image_count);
0d8a0a
 		}
0d8a0a
 
0d8a0a
+	/* raid4 -> !raid4/raid5* */
0d8a0a
+	} else if (seg_is_raid4(seg_from) &&
0d8a0a
+		   !segtype_is_raid4(*segtype) && !segtype_is_any_raid5(*segtype)) {
0d8a0a
+		seg_flag = SEG_RAID5_N;
0d8a0a
+
0d8a0a
 	/* raid6 -> striped/raid0/raid5/raid10 */
0d8a0a
 	} else if (seg_is_any_raid6(seg_from)) {
0d8a0a
 		if (segtype_is_raid1(*segtype)) {
0d8a0a
@@ -6247,6 +6225,9 @@ static int _set_convenient_raid145610_segtype_to(const struct lv_segment *seg_fr
0d8a0a
 		} else if (segtype_is_any_raid10(*segtype)) {
0d8a0a
 			seg_flag = seg_is_raid6_n_6(seg_from) ? SEG_RAID0_META : SEG_RAID6_N_6;
0d8a0a
 
0d8a0a
+		} else if (segtype_is_linear(*segtype)) {
0d8a0a
+			seg_flag = seg_is_raid6_n_6(seg_from) ? SEG_RAID5_N : SEG_RAID6_N_6;
0d8a0a
+
0d8a0a
 		} else if (segtype_is_striped(*segtype) || segtype_is_any_raid0(*segtype)) {
0d8a0a
 			if (!seg_is_raid6_n_6(seg_from))
0d8a0a
 				seg_flag = SEG_RAID6_N_6;
0d8a0a
@@ -6277,12 +6258,16 @@ static int _set_convenient_raid145610_segtype_to(const struct lv_segment *seg_fr
0d8a0a
 			return 0;
0d8a0a
 		}
0d8a0a
 
0d8a0a
-	/* raid10 -> ... */
0d8a0a
-	} else if (seg_is_raid10(seg_from) &&
0d8a0a
-		   !segtype_is_striped(*segtype) &&
0d8a0a
-		   !segtype_is_any_raid0(*segtype))
0d8a0a
-		seg_flag = SEG_RAID0_META;
0d8a0a
+	} else if (seg_is_raid10(seg_from)) {
0d8a0a
+		if (segtype_is_linear(*segtype) ||
0d8a0a
+		    (!segtype_is_striped(*segtype) &&
0d8a0a
+		    !segtype_is_any_raid0(*segtype))) {
0d8a0a
+			seg_flag = SEG_RAID0_META;
0d8a0a
+		}
0d8a0a
+	}
0d8a0a
 
0d8a0a
+
0d8a0a
+	/* raid10 -> ... */
0d8a0a
 	if (seg_flag) {
0d8a0a
 		if (!(*segtype = get_segtype_from_flag(cmd, seg_flag)))
0d8a0a
 			return_0;
0d8a0a
diff --git a/test/shell/lvconvert-raid-reshape-linear_to_raid6-single-type.sh b/test/shell/lvconvert-raid-reshape-linear_to_raid6-single-type.sh
0d8a0a
index f01e7ef..05cb616 100644
0d8a0a
--- a/test/shell/lvconvert-raid-reshape-linear_to_raid6-single-type.sh
0d8a0a
+++ b/test/shell/lvconvert-raid-reshape-linear_to_raid6-single-type.sh
0d8a0a
@@ -78,6 +78,7 @@ check lv_first_seg_field $vg/$lv data_stripes 3
0d8a0a
 check lv_first_seg_field $vg/$lv stripesize "64.00k"
0d8a0a
 check lv_first_seg_field $vg/$lv regionsize "128.00k"
0d8a0a
 check lv_first_seg_field $vg/$lv reshape_len_le 0
0d8a0a
+aux wait_for_sync $vg $lv
0d8a0a
 
0d8a0a
 # Convert raid6_ls_6 -> raid6(_zr) (reshape)
0d8a0a
 lvconvert -y --type raid6 --stripes 3 --stripesize 64K --regionsize 128K $vg/$lv
0d8a0a
@@ -88,6 +89,7 @@ check lv_first_seg_field $vg/$lv data_stripes 3
0d8a0a
 check lv_first_seg_field $vg/$lv stripesize "64.00k"
0d8a0a
 check lv_first_seg_field $vg/$lv regionsize "128.00k"
0d8a0a
 check lv_first_seg_field $vg/$lv reshape_len_le 10
0d8a0a
+aux wait_for_sync $vg $lv
0d8a0a
 
0d8a0a
 # Remove reshape space
0d8a0a
 lvconvert -y --type raid6 --stripes 3 --stripesize 64K --regionsize 128K $vg/$lv
0d8a0a
-- 
0d8a0a
1.8.3.1
0d8a0a