Skip to contentSkip to conversation

LVM: add split capability - a more correct approach

PATCH New Jonathan Brassow 1 participant 1 message Nov 11, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 LVM: add split capability - a more correct approach

Changes from previous patch are mentioned in the patch header...

brassow

This patch adds the capability to split off a mirror leg. It is pretty much the same as reducing the number of mirror legs, but we just don't delete it afterwards.

The following command line interface is enforced:
prompt> lvconvert --splitmirror <n> -n <name> <VG>/<LV>
where 'n' is the number of legs to split off, and where 'name' is the name of the newly split off logical volume.

It can be seen that '--splitmirror <n>' is exactly the same as '--mirrors -<n>' (note the minus sign), except there is the additional notion to keep the image being detached from the mirror instead of just throwing it away. So, we _could_ have a '--keep' argument or something that could be used in conjunction with '--mirrors' to denote the fact that we wish to keep the image being detached. It has been suggested that we could have two ways of specifying this action. I have not implemented that here. I am strictly choosing '--splitmirror' and purposefully choosing not to have something additional for '--mirrors'. I think this prevents confusion. The additional argument for '--mirrors' will have to come by way of another patch.

Also, I have chosen to make the '-n <name>' argument manditory. Perhaps in the future when we decide on a useful default name we can relax this enforcement. There is no reason to withhold the capability because we haven't formed a concensous on what a default name should be. [Perhaps we will make a better informed decision on that when we begin to implement '--track_deltas'.]

[This patch differs from the previous version in that both '--splitmirrors <n>' and '--mirrors -<n>' use the function release_lv_segment_area instead of '--splitmirrors' using the alternate function remove_seg_from_segs_using_this_lv. Both patches will produce correct results, but this patch is more correct, and thus more "future proof".]

lib/metadata/mirror.c +74 -11
Index: LVM2/lib/metadata/mirror.c
===================================================================
@@ -472,6 +472,9 @@ static int _is_mirror_image_removable(st
  *                  mirror layer and merge mirrors to the original LV.
  *                  removable_pvs should be NULL and num_removed should be
  *                  seg->area_count - 1.
+ *   split:	    if non-NULL, split the mimage off rather than removing
+ *		    it, making this argument its name (only one leg can be
+ *                  split off at a time).
  *   removed:       if non NULL, the number of removed mirror images is set
  *                  as a result
  *
@@ -487,6 +490,7 @@ static int _remove_mirror_images(struct 
 				 uint32_t num_removed,
 				 struct dm_list *removable_pvs,
 				 unsigned remove_log, unsigned collapse,
+				 const char *split,
 				 uint32_t *removed)
 {
 	uint32_t m;
@@ -535,15 +539,30 @@ static int _remove_mirror_images(struct 
 	/* Remove mimage LVs from the segment */
 	dm_list_init(&tmp_orphan_lvs);
 	for (m = new_area_count; m < mirrored_seg->area_count; m++) {
-		seg_lv(mirrored_seg, m)->status &= ~MIRROR_IMAGE;
-		lv_set_visible(seg_lv(mirrored_seg, m));
-		if (!(lvl = dm_pool_alloc(lv->vg->cmd->mem, sizeof(*lvl)))) {
-			log_error("lv_list alloc failed");
-			return 0;
+		sub_lv = seg_lv(mirrored_seg, m);
+
+		sub_lv->status &= ~MIRROR_IMAGE;
+		lv_set_visible(sub_lv);
+		release_lv_segment_area(mirrored_seg, m,
+					mirrored_seg->area_len);
+		if (split) {
+			sub_lv->name = dm_pool_strdup(lv->vg->cmd->mem, split);
+			if (!sub_lv->name) {
+				log_error("Unable to rename newly split LV");
+				return 0;
+			}
+
+			break;
+		} else {
+			lvl = dm_pool_alloc(lv->vg->cmd->mem, sizeof(*lvl));
+			if (!lvl) {
+				log_error("lv_list alloc failed");
+				return 0;
+			}
+
+			lvl->lv = sub_lv;
+			dm_list_add(&tmp_orphan_lvs, &lvl->list);
 		}
-		lvl->lv = seg_lv(mirrored_seg, m);
-		dm_list_add(&tmp_orphan_lvs, &lvl->list);
-		release_lv_segment_area(mirrored_seg, m, mirrored_seg->area_len);
 	}
 	mirrored_seg->area_count = new_area_count;
 
@@ -671,7 +690,8 @@ int remove_mirror_images(struct logical_
 			removed_once = first_seg(next_lv)->area_count - 1;
 
 		if (!_remove_mirror_images(next_lv, removed_once,
-					   removable_pvs, remove_log, 0, &r))
+					   removable_pvs, remove_log,
+					   0, NULL, &r))
 			return_0;
 
 		if (r < removed_once) {
@@ -745,7 +765,7 @@ int collapse_mirrored_lv(struct logical_
 
 		if (!_remove_mirror_images(mirror_seg->lv,
 					   mirror_seg->area_count - 1,
-					   NULL, 1, 1, NULL)) {
+					   NULL, 1, 1, NULL, NULL)) {
 			log_error("Failed to release mirror images");
 			return 0;
 		}
@@ -866,7 +886,7 @@ int reconfigure_mirror_images(struct lv_
 	init_mirror_in_sync(in_sync);
 
 	r = _remove_mirror_images(mirrored_seg->lv, old_num_mirrors - num_mirrors,
-				  removable_pvs, remove_log, 0, NULL);
+				  removable_pvs, remove_log, 0, NULL, NULL);
 	if (!r)
 		/* Unable to remove bad devices */
 		return 0;
@@ -1586,6 +1606,49 @@ int lv_add_mirrors(struct cmd_context *c
 	return 0;
 }
 
+int lv_split_mirror_images(struct logical_volume *lv, const char *split_lv_name,
+			   uint32_t split_count, struct dm_list *removable_pvs)
+{
+	int r;
+
+	/*
+	 * FIXME: Need ability to split off more than one mirror leg
+	 *
+	 * Right now, we only allow the user to split a single
+	 * leg off at a time.  In the future, we might allow a
+	 * 4-way mirror to be split into 2 2-way mirrors, but
+	 * not right now.
+	 */
+	if (split_count != 1) {
+		log_error("Unable to split more than one leg from a mirror.");
+		return_0;
+	}
+
+	/* Can't split a mirror that is not in-sync... unless force? */
+	if (!_mirrored_lv_in_sync(lv)) {
+		log_error("Unable to split mirror that is not in-sync.");
+		return_0;
+	}
+
+	/*
+	 * FIXME: Generate default name when not supplied.
+	 *
+	 * If we were going to generate a default name, we would
+	 * do it here.  Better to wait for a decision on the form
+	 * of the default name when '--track_deltas' (the ability
+	 * to merge a split leg back in and only copy the changes)
+	 * is being implemented.  For now, we force the user to
+	 * come up with a name for their LV.
+	 */
+	r = _remove_mirror_images(lv, split_count,
+				  removable_pvs, 0, 0,
+				  split_lv_name, NULL);
+	if (!r)
+		return 0;
+
+	return 1;
+}
+
 /*
  * Generic interface for removing mirror and/or mirror log.
  * 'mirror' is the number of mirrors to be removed.
man/lvconvert.8.in +35 -9

70 lines not on this page · raw message

tools/args.h +1 -0
Index: LVM2/tools/args.h
===================================================================
@@ -50,6 +50,7 @@ arg(nosync_ARG, '\0', "nosync", NULL, 0)
 arg(resync_ARG, '\0', "resync", NULL, 0)
 arg(corelog_ARG, '\0', "corelog", NULL, 0)
 arg(mirrorlog_ARG, '\0', "mirrorlog", string_arg, 0)
+arg(splitmirrors_ARG, '\0', "splitmirrors", int_arg, 0)
 arg(repair_ARG, '\0', "repair", NULL, 0)
 arg(use_policies_ARG, '\0', "use-policies", NULL, 0)
 arg(monitor_ARG, '\0', "monitor", yes_no_arg, 0)
tools/commands.h +4 -2
Index: LVM2/tools/commands.h
===================================================================
@@ -96,6 +96,7 @@ xx(lvconvert,
    0,
    "lvconvert "
    "[-m|--mirrors Mirrors [{--mirrorlog {disk|core}|--corelog}]]\n"
+   "[--splitmirrors Images -n SplitLogicalVolumeName]\n"
    "\t[--repair [--use-policies]]\n"
    "\t[-R|--regionsize MirrorLogRegionSize]\n"
    "\t[--alloc AllocationPolicy]\n"
@@ -122,8 +123,9 @@ xx(lvconvert,
    "\tOriginalLogicalVolume[Path] SnapshotLogicalVolume[Path]\n",
 
    alloc_ARG, background_ARG, chunksize_ARG, corelog_ARG, interval_ARG,
-   mirrorlog_ARG, mirrors_ARG, noudevsync_ARG, regionsize_ARG, repair_ARG,
-   snapshot_ARG, test_ARG, use_policies_ARG, yes_ARG, force_ARG, zero_ARG)
+   splitmirrors_ARG, name_ARG, mirrorlog_ARG, mirrors_ARG, noudevsync_ARG,
+   regionsize_ARG, repair_ARG, snapshot_ARG, test_ARG, use_policies_ARG,
+   yes_ARG, force_ARG, zero_ARG)
 
 xx(lvcreate,
    "Create a logical volume",
tools/lvconvert.c +55 -5

98 lines not on this page · raw message