Skip to contentSkip to conversation

master - lvconvert: support linear <-> striped convenience conversions

PATCH Heinz Mauelshagen 1 participant 1 message Jun 5, 2018

lore
Share & tools
lore
#0 lore raw
Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=bd7cdd0b09ba123b064937fddde08daacbed7dab
Commit:        bd7cdd0b09ba123b064937fddde08daacbed7dab
Parent:        de66704253653305e4513637735a078af00912b7
Author:        Heinz Mauelshagen <[email protected]>
AuthorDate:    Wed May 30 12:49:15 2018 +0200
Committer:     Heinz Mauelshagen <[email protected]>
CommitterDate: Tue Jun 5 16:23:18 2018 +0200

lvconvert: support linear <-> striped convenience conversions

"lvconvert --type {linear|striped|raid*} ..." on a striped/linear LV provides convenience interim type to convert to the requested final layout similar to the given raid* <-> raid* conveninece types.

Whilst on it, add missing raid5_n convenince type from raid5* to raid10.

Resolves: rhbz1439925
Resolves: rhbz1447809
Resolves: rhbz1573255

---
 lib/metadata/raid_manip.c |  172 ++++++++++++++++++++++++++++++---------------
 tools/lvconvert.c         |  110 ++++++++++-------------------
 2 files changed, 154 insertions(+), 128 deletions(-)
lib/metadata/raid_manip.c +114 -56
index 9b4cb83..4d58d74 100644
@@ -4526,17 +4526,18 @@ static struct possible_takeover_reshape_type _possible_takeover_reshape_types[]
 	  .current_areas = 1,
 	  .options = ALLOW_REGION_SIZE },
 
-	{ .current_types  = SEG_STRIPED_TARGET, /* linear, i.e. seg->area_count = 1 */
-	  .possible_types = SEG_RAID0|SEG_RAID0_META,
-	  .current_areas = 1,
-	  .options = ALLOW_STRIPE_SIZE },
-
 	/* raid0* -> raid1 */
 	{ .current_types  = SEG_RAID0|SEG_RAID0_META, /* seg->area_count = 1 */
 	  .possible_types = SEG_RAID1,
 	  .current_areas = 1,
 	  .options = ALLOW_REGION_SIZE },
 
+	/* raid5_n -> linear through interim raid1 */
+	{ .current_types  = SEG_RAID5_N,
+	  .possible_types = SEG_STRIPED_TARGET,
+	  .current_areas = 2,
+	  .options = ALLOW_NONE },
+
 	/* striped,raid0* <-> striped,raid0* */
 	{ .current_types  = SEG_STRIPED_TARGET|SEG_RAID0|SEG_RAID0_META,
 	  .possible_types = SEG_STRIPED_TARGET|SEG_RAID0|SEG_RAID0_META,
@@ -4547,13 +4548,13 @@ static struct possible_takeover_reshape_type _possible_takeover_reshape_types[]
 	{ .current_types  = SEG_STRIPED_TARGET|SEG_RAID0|SEG_RAID0_META,
 	  .possible_types = SEG_RAID4|SEG_RAID5_N|SEG_RAID6_N_6|SEG_RAID10_NEAR,
 	  .current_areas = ~0U,
-	  .options = ALLOW_REGION_SIZE },
+	  .options = ALLOW_REGION_SIZE|ALLOW_STRIPES },
 
 	/* raid4,raid5_n,raid6_n_6,raid10_near -> striped/raid0* */
 	{ .current_types  = SEG_RAID4|SEG_RAID5_N|SEG_RAID6_N_6|SEG_RAID10_NEAR,
 	  .possible_types = SEG_STRIPED_TARGET|SEG_RAID0|SEG_RAID0_META,
 	  .current_areas = ~0U,
-	  .options = ALLOW_NONE },
+	  .options = ALLOW_STRIPES },
 
 	/* raid4,raid5_n,raid6_n_6 <-> raid4,raid5_n,raid6_n_6 */
 	{ .current_types  = SEG_RAID4|SEG_RAID5_N|SEG_RAID6_N_6,
@@ -4640,7 +4641,8 @@ static struct possible_takeover_reshape_type *_get_possible_takeover_reshape_typ
 	for ( ; pt->current_types; pt++)
 		if ((seg_from->segtype->flags & pt->current_types) &&
 		    (segtype_to ? (segtype_to->flags & pt->possible_types) : 1))
-			if (seg_from->area_count <= pt->current_areas)
+			if ((seg_from->area_count == pt->current_areas) ||
+			    (seg_from->area_count > 1 && seg_from->area_count <= pt->current_areas))
 				return pt;
 
 	return NULL;
@@ -4816,7 +4818,7 @@ typedef int (*takeover_fn_t)(TAKEOVER_FN_ARGS);
 /*
  * Unsupported takeover functions.
  */
-static int _takeover_noop(TAKEOVER_FN_ARGS)
+static int _takeover_same_layout(const struct logical_volume *lv)
 {
 	log_error("Logical volume %s is already of requested type %s.",
 		  display_lvname(lv), lvseg_name(first_seg(lv)));
@@ -4824,6 +4826,11 @@ static int _takeover_noop(TAKEOVER_FN_ARGS)
 	return 0;
 }
 
+static int _takeover_noop(TAKEOVER_FN_ARGS)
+{
+	return _takeover_same_layout(lv);
+}
+
 static int _takeover_unsupported(TAKEOVER_FN_ARGS)
 {
 	struct lv_segment *seg = first_seg(lv);
@@ -5618,7 +5625,9 @@ static int _takeover_from_linear_to_raid0(TAKEOVER_FN_ARGS)
 
 static int _takeover_from_linear_to_raid1(TAKEOVER_FN_ARGS)
 {
-	return _takeover_unsupported_yet(lv, new_stripes, new_segtype);
+	first_seg(lv)->region_size = new_region_size;
+
+	return _lv_raid_change_image_count(lv, 1, 2, allocate_pvs, NULL, 1, 0);
 }
 
 static int _takeover_from_linear_to_raid10(TAKEOVER_FN_ARGS)
@@ -6102,23 +6111,34 @@ static uint64_t _raid_segtype_flag_5_to_6(const struct segment_type *segtype)
 /* FIXME: do this like _conversion_options_allowed()? */
 static int _set_convenient_raid145610_segtype_to(const struct lv_segment *seg_from,
 						 const struct segment_type **segtype,
+						 uint32_t *new_image_count,
+						 uint32_t *stripes,
 						 int yes)
 {
 	uint64_t seg_flag = 0;
 	struct cmd_context *cmd = seg_from->lv->vg->cmd;
 	const struct segment_type *segtype_sav = *segtype;
 
+	/* Linear -> striped request */
+	if (seg_is_striped(seg_from) &&
+	    seg_from->area_count == 1 &&
+	    segtype_is_striped(*segtype))
+		;
 	/* Bail out if same RAID level is requested. */
-	if (_is_same_level(seg_from->segtype, *segtype))
+	else if (_is_same_level(seg_from->segtype, *segtype))
 		return 1;
 
 	log_debug("Checking LV %s requested %s segment type for convenience",
 		  display_lvname(seg_from->lv), (*segtype)->name);
-
 	/* striped/raid0 -> raid5/6 */
 	if (seg_is_striped(seg_from) || seg_is_any_raid0(seg_from)) {
+		/* linear -> raid*, interim/first conversion is to raid1 */
+		if (seg_from->area_count == 1)
+			seg_flag = SEG_RAID1;
+
 		/* If this is any raid5 conversion request -> enforce raid5_n, because we convert from striped */
-		if (segtype_is_any_raid5(*segtype) && !segtype_is_raid5_n(*segtype))
+		else if (((segtype_is_striped(*segtype) && !segtype_is_any_raid0(*segtype)) || segtype_is_any_raid5(*segtype)) &&
+			 !segtype_is_raid5_n(*segtype))
 			seg_flag = SEG_RAID5_N;
 
 		/* If this is any raid6 conversion request -> enforce raid6_n_6, because we convert from striped */
@@ -6143,40 +6163,71 @@ static int _set_convenient_raid145610_segtype_to(const struct lv_segment *seg_fr
 
 	/* raid4/raid5 -> striped/raid0/raid1/raid6/raid10 */
 	} else if (seg_is_raid4(seg_from) || seg_is_any_raid5(seg_from)) {
-		if (segtype_is_raid1(*segtype) &&
-		    seg_from->area_count != 2) {
+		if ((segtype_is_raid1(*segtype) || segtype_is_linear(*segtype)) && seg_is_raid5_n(seg_from)) {
+			if (seg_from->area_count != 2) {
+				log_error("Converting %s LV %s to 2 stripes first.",
+					  lvseg_name(seg_from), display_lvname(seg_from->lv));
+				*new_image_count = 2;
+				seg_flag = SEG_RAID5_N;
+			} else
+				seg_flag = SEG_RAID1;
+
+		} else if (segtype_is_raid1(*segtype) && seg_from->area_count != 2) {
 			log_error("Convert %s LV %s to 2 stripes first (i.e. --stripes 1).",
 				  lvseg_name(seg_from), display_lvname(seg_from->lv));
 			return 0;
-		}
-
-		if (seg_is_raid4(seg_from) &&
-			   segtype_is_any_raid5(*segtype) &&
-			   !segtype_is_raid5_n(*segtype))
-			seg_flag = SEG_RAID5_N;
 
-		else if (seg_is_any_raid5(seg_from) &&
-			 segtype_is_raid4(*segtype) &&
+		} else if (seg_is_raid4(seg_from) &&
+		         (segtype_is_linear(*segtype) || segtype_is_any_raid5(*segtype)) &&
 			 !segtype_is_raid5_n(*segtype))
 			seg_flag = SEG_RAID5_N;
 
-		else if (segtype_is_raid10(*segtype)) {
-			if (seg_from->area_count < 3) {
+		else if (seg_is_raid5_n(seg_from) && seg_from->area_count == 2) {
+			if (*stripes >= 2) {
+				log_error("Converting %s LV %s to %u stripes first.",
+					  lvseg_name(seg_from), display_lvname(seg_from->lv), *stripes);
+				*new_image_count = *stripes + seg_from->segtype->parity_devs;
+				seg_flag = SEG_RAID5_N;
+			} else {
 				log_error("Convert %s LV %s to minimum 3 stripes first (i.e. --stripes 2).",
 					  lvseg_name(seg_from), display_lvname(seg_from->lv));
 				return 0;
 			}
+		} else if (seg_is_any_raid5(seg_from) &&
+		         (segtype_is_linear(*segtype) || segtype_is_raid4(*segtype)) &&
+			 !segtype_is_raid5_n(*segtype))
+			seg_flag = SEG_RAID5_N;
 
-			seg_flag = seg_is_raid5_n(seg_from) ? SEG_RAID0_META : SEG_RAID5_N;
+		else if (segtype_is_raid10(*segtype)) {
+			if (seg_from->area_count < 3) {
+				if (*stripes >= 2) {
+					log_error("Converting %s LV %s to %u stripes first.",
+						  lvseg_name(seg_from), display_lvname(seg_from->lv), *stripes);
+					*new_image_count = *stripes + seg_from->segtype->parity_devs;
+					seg_flag = SEG_RAID5_N;
+				} else {
+					log_error("Convert %s LV %s to minimum 3 stripes first (i.e. --stripes 2).",
+						  lvseg_name(seg_from), display_lvname(seg_from->lv));
+					return 0;
+				}
+			} else
+				seg_flag = seg_is_raid5_n(seg_from) ? SEG_RAID0_META : SEG_RAID5_N;
 
 		} else if (segtype_is_any_raid6(*segtype)) {
-			if (seg_from->area_count < 4) {
-				log_error("Convert %s LV %s to minimum 4 stripes first (i.e. --stripes 3).",
-					  lvseg_name(seg_from), display_lvname(seg_from->lv));
-				return 0;
-			}
+			if (seg_from->area_count < 4 &&
+			    seg_is_any_raid5(seg_from)) {
+				if (*stripes >= 3) {
+					log_error("Converting %s LV %s to %u stripes first.",
+						  lvseg_name(seg_from), display_lvname(seg_from->lv), *stripes);
+					*new_image_count = *stripes + seg_from->segtype->parity_devs;
+					seg_flag = SEG_RAID5_LS;
+				} else {
+					log_error("Convert %s LV %s to minimum 4 stripes first (i.e. --stripes 3).",
+						  lvseg_name(seg_from), display_lvname(seg_from->lv));
+					return 0;
+				}
 
-			if (seg_is_raid4(seg_from) && !segtype_is_raid6_n_6(*segtype))
+			} else if (seg_is_raid4(seg_from) && !segtype_is_raid6_n_6(*segtype))
 				seg_flag = SEG_RAID6_N_6;
 			else
 				seg_flag = _raid_seg_flag_5_to_6(seg_from);
@@ -6193,9 +6244,9 @@ static int _set_convenient_raid145610_segtype_to(const struct lv_segment *seg_fr
 		} else if (segtype_is_any_raid10(*segtype)) {
 			seg_flag = seg_is_raid6_n_6(seg_from) ? SEG_RAID0_META : SEG_RAID6_N_6;
 
-		} else if ((segtype_is_striped(*segtype) || segtype_is_any_raid0(*segtype)) &&
-			   !seg_is_raid6_n_6(seg_from)) {
-			seg_flag = SEG_RAID6_N_6;
+		} else if (segtype_is_striped(*segtype) || segtype_is_any_raid0(*segtype)) {
+			if (!seg_is_raid6_n_6(seg_from))
+				seg_flag = SEG_RAID6_N_6;
 
 		} else if (segtype_is_raid4(*segtype) && !seg_is_raid6_n_6(seg_from)) {
 			seg_flag = SEG_RAID6_N_6;
@@ -6331,41 +6382,48 @@ static int _conversion_options_allowed(const struct lv_segment *seg_from,
 				       int yes,
 				       uint32_t new_image_count,
 				       int new_data_copies, int new_region_size,
-				       int stripes, unsigned new_stripe_size_supplied)
+				       uint32_t *stripes, unsigned new_stripe_size_supplied)
 {
 	int r = 1;
-	uint32_t opts;
+	uint32_t count = new_image_count, opts;
+
+	/* Linear -> linear rejection */
+	if ((seg_is_linear(seg_from) || seg_is_striped(seg_from)) &&
+	    seg_from->area_count == 1 &&
+	    segtype_is_striped(*segtype_to) &&
+	    *stripes < 2)
+		return _takeover_same_layout(seg_from->lv);
 
-	if (!new_image_count && !_set_convenient_raid145610_segtype_to(seg_from, segtype_to, yes))
+	if (!new_image_count && !_set_convenient_raid145610_segtype_to(seg_from, segtype_to, &count, stripes, yes))
 		return_0;
 
+	if (new_image_count != count)
+		*stripes = count - seg_from->segtype->parity_devs;
+
 	if (!_get_allowed_conversion_options(seg_from, *segtype_to, new_image_count, &opts)) {
-		log_error("Unable to convert LV %s from %s to %s.",
-			  display_lvname(seg_from->lv), lvseg_name(seg_from), (*segtype_to)->name);
+		if (strcmp(lvseg_name(seg_from), (*segtype_to)->name))
+			log_error("Unable to convert LV %s from %s to %s.",
+				  display_lvname(seg_from->lv), lvseg_name(seg_from), (*segtype_to)->name);
+		else
+			_takeover_same_layout(seg_from->lv);
+
 		return 0;
 	}
 
-	if (stripes > 1 && !(opts & ALLOW_STRIPES)) {
-		if (!_log_prohibited_option(seg_from, *segtype_to, "--stripes"))
-			stack;
-		r = 0;
+	if (*stripes > 1 && !(opts & ALLOW_STRIPES)) {
+		_log_prohibited_option(seg_from, *segtype_to, "--stripes");
+		*stripes = seg_from->area_count;
 	}
 
-	if (new_stripe_size_supplied && !(opts & ALLOW_STRIPE_SIZE)) {
-		if (!_log_prohibited_option(seg_from, *segtype_to, "-I/--stripesize"))
-			stack;
-		r = 0;
-	}
+	if (new_stripe_size_supplied && !(opts & ALLOW_STRIPE_SIZE))
+		_log_prohibited_option(seg_from, *segtype_to, "-I/--stripesize");
 
-	if (new_region_size && !(opts & ALLOW_REGION_SIZE)) {
-		if (!_log_prohibited_option(seg_from, *segtype_to, "-R/--regionsize"))
-			stack;
-		r = 0;
-	}
+	if (new_region_size && new_region_size != seg_from->region_size && !(opts & ALLOW_REGION_SIZE))
+		_log_prohibited_option(seg_from, *segtype_to, "-R/--regionsize");
 
 	/* Can't reshape stripes or stripe size when performing a takeover! */
 	if (!_is_same_level(seg_from->segtype, *segtype_to)) {
-		if (stripes && stripes != _data_rimages_count(seg_from, seg_from->area_count))
+		if (*stripes && *stripes != _data_rimages_count(seg_from, seg_from->area_count))
 			log_warn("WARNING: ignoring --stripes option on takeover of %s (reshape afterwards).",
 				 display_lvname(seg_from->lv));
 
@@ -6501,7 +6559,7 @@ int lv_raid_convert(struct logical_volume *lv,
 	 */
 	if (!_conversion_options_allowed(seg, &new_segtype, yes,
 					 0 /* Takeover */, 0 /*new_data_copies*/, new_region_size,
-					 new_stripes, new_stripe_size_supplied))
+					 &stripes, new_stripe_size_supplied))
 		return _log_possible_conversion_types(lv, new_segtype);
 
 	/* https://bugzilla.redhat.com/1439399 */
tools/lvconvert.c +39 -71

186 lines not on this page · raw message