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

[lvm-devel] [PATCH mirror 13/13] Allow resizing of mirrored LV with temporary layer



This patch changes 2 things related to resizing mirror.
  1) Use lv_mirror_count() to calculate the number of existing mirrors
  2) lv_extend() will walk down recursively mirrored LV
     to add allocated extents for each mirror image.

Thanks,
-- 
Jun'ichi Nomura, NEC Corporation of America

Mirrored LV could include temporary layers.

Index: LVM2.work/lib/metadata/lv_manip.c
===================================================================
--- LVM2.work.orig/lib/metadata/lv_manip.c
+++ LVM2.work/lib/metadata/lv_manip.c
@@ -1467,6 +1467,39 @@ int lv_add_more_mirrored_areas(struct lo
 	return 1;
 }
 
+static int _lv_extend_mirror(struct alloc_handle *ah,
+			     struct logical_volume *lv,
+			     uint32_t extents, uint32_t first_area)
+{
+	struct lv_segment *seg;
+	uint32_t m, s;
+
+	seg = first_seg(lv);
+	for (m = first_area, s = 0; s < seg->area_count; s++) {
+		if (is_temporary_mirror_layer(seg_lv(seg, s))) {
+			if (!_lv_extend_mirror(ah, seg_lv(seg, s), extents, m))
+				return_0;
+			m += lv_mirror_count(seg_lv(seg, s));
+			continue;
+		}
+
+		if (!lv_add_segment(ah, m++, 1, seg_lv(seg, s),
+				    get_segtype_from_string(lv->vg->cmd,
+							    "striped"),
+				    0, 0, 0, NULL)) {
+			log_error("Aborting. Failed to extend %s.",
+				  seg_lv(seg, s)->name);
+			return 0;
+		}
+	}
+	seg->area_len += extents;
+	seg->len += extents;
+	lv->le_count += extents;
+	lv->size += (uint64_t) extents *lv->vg->extent_size;
+
+	return 1;
+}
+
 /*
  * Entry point for single-step LV allocation + extension.
  */
@@ -1478,9 +1511,7 @@ int lv_extend(struct logical_volume *lv,
 	      alloc_policy_t alloc)
 {
 	int r = 1;
-	uint32_t m;
 	struct alloc_handle *ah;
-	struct lv_segment *seg;
 
 	if (segtype_is_virtual(segtype))
 		return lv_add_virtual_segment(lv, status, extents, segtype);
@@ -1498,21 +1529,8 @@ int lv_extend(struct logical_volume *lv,
 			goto out;
 		}
 	} else {
-		seg = first_seg(lv);
-		for (m = 0; m < mirrors; m++) {
-			if (!lv_add_segment(ah, m, 1, seg_lv(seg, m),
-					    get_segtype_from_string(lv->vg->cmd,
-								    "striped"),
-					    0, 0, 0, NULL)) {
-				log_error("Aborting. Failed to extend %s.",
-					  seg_lv(seg, m)->name);
-				return 0;
-			}
-		}
-		seg->area_len += extents;
-		seg->len += extents;
-		lv->le_count += extents;
-		lv->size += (uint64_t) extents *lv->vg->extent_size;
+		if (!_lv_extend_mirror(ah, lv, extents, 0))
+			return_0;
 	}
 
       out:
Index: LVM2.work/tools/lvresize.c
===================================================================
--- LVM2.work.orig/tools/lvresize.c
+++ LVM2.work/tools/lvresize.c
@@ -435,7 +435,7 @@ static int _lvresize(struct cmd_context 
 	if ((lp->extents > lv->le_count)) {
 		list_iterate_back_items(seg, &lv->segments) {
 			if (seg_is_mirrored(seg))
-				seg_mirrors = seg->area_count;
+				seg_mirrors = lv_mirror_count(seg->lv);
 			else
 				seg_mirrors = 0;
 			break;
@@ -469,7 +469,7 @@ static int _lvresize(struct cmd_context 
 			}
 
 			if (seg_is_mirrored(seg))
-				seg_mirrors = seg->area_count;
+				seg_mirrors = lv_mirror_count(seg->lv);
 			else
 				seg_mirrors = 0;
 

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