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

[lvm-devel] [PATCH mirror 7/13] Fix lvconvert to use collapsing and mirror counting



This patch changes 2 things in lvconvert:
  1) Add '--collapse' option as an interface for users to
     remove unnecessary mirror layer and collapse the stack.
  2) Use the new lv_mirror_count() to get correct existing_mirrors .

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

Add '--collapse' option to lvconvert.
Properly count the number of existing mirrors for stacked LV
using lv_mirror_count().

Index: LVM2.work/tools/lvconvert.c
===================================================================
--- LVM2.work.orig/tools/lvconvert.c
+++ LVM2.work/tools/lvconvert.c
@@ -18,6 +18,7 @@
 struct lvconvert_params {
 	int snapshot;
 	int zero;
+	int mirror;
 
 	const char *origin;
 	const char *lv_name;
@@ -28,6 +29,7 @@ struct lvconvert_params {
 
 	uint32_t mirrors;
 	sign_t mirrors_sign;
+	uint32_t collapse_mirrors;
 
 	struct segment_type *segtype;
 
@@ -116,6 +118,13 @@ static int _read_params(struct lvconvert
 	if (arg_count(cmd, snapshot_ARG))
 		lp->snapshot = 1;
 
+	if (arg_count(cmd, mirrorlog_ARG) || arg_count(cmd, mirrors_ARG)
+	    || arg_count(cmd, collapse_ARG))
+		lp->mirror = 1;
+
+	if (arg_count(cmd, collapse_ARG))
+		lp->collapse_mirrors = 1;
+
 	if (arg_count(cmd, mirrors_ARG)) {
 		lp->mirrors = arg_uint_value(cmd, mirrors_ARG, 0);
 		lp->mirrors_sign = arg_sign_value(cmd, mirrors_ARG, 0);
@@ -277,7 +286,7 @@ static int lvconvert_mirrors(struct cmd_
 	unsigned corelog = 0;
 
 	seg = first_seg(lv);
-	existing_mirrors = (lv->status & MIRRORED) ? seg->area_count : 1;
+	existing_mirrors = lv_mirror_count(lv);
 
 	/*
 	 * Adjust required number of mirrors
@@ -340,6 +349,15 @@ static int lvconvert_mirrors(struct cmd_
 	}
 
 	/*
+	 * Collapse mirrored LV (removing temporary mirror layers)
+	 */
+	if (lp->collapse_mirrors) {
+		if (!collapse_mirrored_lv(lv))
+			return_0;
+		goto commit_changes;
+	}
+
+	/*
 	 * Converting from mirror to linear
 	 */
 	if ((lp->mirrors == 1)) {
@@ -590,8 +608,7 @@ static int lvconvert_single(struct cmd_c
 		return ECMD_FAILED;
 	}
 
-	if (arg_count(cmd, mirrors_ARG) ||
-	    ((lv->status & MIRRORED) && arg_count(cmd, mirrorlog_ARG))) {
+	if (lp->mirror) {
 		if (!archive(lv->vg))
 			return ECMD_FAILED;
 		if (!lvconvert_mirrors(cmd, lv, lp))
Index: LVM2.work/tools/args.h
===================================================================
--- LVM2.work.orig/tools/args.h
+++ LVM2.work/tools/args.h
@@ -47,6 +47,7 @@ arg(separator_ARG, '\0', "separator", st
 arg(mirrorsonly_ARG, '\0', "mirrorsonly", NULL, 0)
 arg(nosync_ARG, '\0', "nosync", NULL, 0)
 arg(resync_ARG, '\0', "resync", NULL, 0)
+arg(collapse_ARG, '\0', "collapse", NULL, 0)
 arg(corelog_ARG, '\0', "corelog", NULL, 0)
 arg(mirrorlog_ARG, '\0', "mirrorlog", string_arg, 0)
 arg(monitor_ARG, '\0', "monitor", yes_no_arg, 0)
Index: LVM2.work/tools/commands.h
===================================================================
--- LVM2.work.orig/tools/commands.h
+++ LVM2.work/tools/commands.h
@@ -89,6 +89,7 @@ xx(lvconvert,
    "Change logical volume layout",
    "lvconvert "
    "[-m|--mirrors Mirrors [{--mirrorlog {disk|core}|--corelog}]]\n"
+   "\t[--collapse]\n"
    "\t[-R|--regionsize MirrorLogRegionSize]\n"
    "\t[--alloc AllocationPolicy]\n"
    "\t[-d|--debug]\n"
@@ -107,8 +108,8 @@ xx(lvconvert,
    "\t[--version]" "\n"
    "\tOriginalLogicalVolume[Path] SnapshotLogicalVolume[Path]\n",
 
-   alloc_ARG, chunksize_ARG, corelog_ARG, mirrorlog_ARG, mirrors_ARG,
-   regionsize_ARG, snapshot_ARG, test_ARG, zero_ARG)
+   alloc_ARG, chunksize_ARG, collapse_ARG, corelog_ARG, mirrorlog_ARG,
+   mirrors_ARG, regionsize_ARG, snapshot_ARG, test_ARG, zero_ARG)
 
 xx(lvcreate,
    "Create a logical volume",

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