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

[lvm-devel] [PATCH] (3/5) vgreduce --consolidate



Hi,

this patch adds a new (sub-)command, vgreduce --consolidate, that is a safer
(and now preferred) variant of vgreduce --removemissing, that will only bring
volume group back from partial mode if that does not compromise any logical
volumes residing there (ie. those having extents on missing PVs).

Users should probably use lvremove and lvconvert --repair to get rid of logical
volumes residing on missing PVs (or let dmeventd sort out the latter). The
possibility to use --removemissing is of course still there as well.

Thu May  8 11:38:14 CEST 2008  me mornfall net
  * First shot at documenting vgreduce --consolidate.
Thu May  8 11:31:58 CEST 2008  me mornfall net
  * Fix flag validation for --consolidate.
Thu May  8 11:24:17 CEST 2008  me mornfall net
  * Implement --consolidate, use it from --removemissing to share code.
Thu May  8 11:19:47 CEST 2008  me mornfall net
  * Share code with --removemissing, stub out functionality (for --consolidate).
Thu May  8 11:16:11 CEST 2008  me mornfall net
  * Flag validation in vgreduce for --consolidate.
Thu May  8 11:13:17 CEST 2008  me mornfall net
  * Add a --consolidate argument for vgreduce.
diff -rN -u -p old-hotspare-prime/man/vgreduce.8 new-hotspare-prime/man/vgreduce.8
--- old-hotspare-prime/man/vgreduce.8	2008-07-08 14:24:25.090695012 +0200
+++ new-hotspare-prime/man/vgreduce.8	2008-07-08 14:24:25.142695156 +0200
@@ -32,6 +32,12 @@ If your logical volumes spanned several 
 lost, you might want to try to salvage data first by activating your
 logical volumes with --partial as described in \fBlvm (8)\fP.
 
+.TP
+.I \-\-consolidate
+Removes missing physical volumes from the volume group, if there are no LVs
+allocated on those. This resumes normal operation of the volume group (LVs can
+be created, changed and so on).
+
 .SH SEE ALSO
 .BR lvm (8), 
 .BR vgextend (8)
diff -rN -u -p old-hotspare-prime/tools/args.h new-hotspare-prime/tools/args.h
--- old-hotspare-prime/tools/args.h	2008-07-08 14:24:25.094694910 +0200
+++ new-hotspare-prime/tools/args.h	2008-07-08 14:24:25.138694490 +0200
@@ -35,6 +35,7 @@ arg(segments_ARG, '\0', "segments", NULL
 arg(units_ARG, '\0', "units", string_arg, 0)
 arg(nosuffix_ARG, '\0', "nosuffix", NULL, 0)
 arg(removemissing_ARG, '\0', "removemissing", NULL, 0)
+arg(consolidate_ARG, '\0', "consolidate", NULL, 0)
 arg(abort_ARG, '\0', "abort", NULL, 0)
 arg(addtag_ARG, '\0', "addtag", tag_arg, 0)
 arg(deltag_ARG, '\0', "deltag", tag_arg, 0)
diff -rN -u -p old-hotspare-prime/tools/commands.h new-hotspare-prime/tools/commands.h
--- old-hotspare-prime/tools/commands.h	2008-07-08 14:24:25.094694910 +0200
+++ new-hotspare-prime/tools/commands.h	2008-07-08 14:24:25.134697106 +0200
@@ -850,13 +850,15 @@ xx(vgreduce,
    "\t[-h|--help]\n"
    "\t[--mirrorsonly]\n"
    "\t[--removemissing]\n"
+   "\t[--consolidate]\n"
    "\t[-t|--test]\n"
    "\t[-v|--verbose]\n"
    "\t[--version]" "\n"
    "\tVolumeGroupName\n"
    "\t[PhysicalVolumePath...]\n",
 
-   all_ARG, autobackup_ARG, mirrorsonly_ARG, removemissing_ARG, test_ARG)
+   all_ARG, autobackup_ARG, mirrorsonly_ARG, removemissing_ARG,
+   consolidate_ARG, test_ARG)
 
 xx(vgremove,
    "Remove volume group(s)",
diff -rN -u -p old-hotspare-prime/tools/vgreduce.c new-hotspare-prime/tools/vgreduce.c
--- old-hotspare-prime/tools/vgreduce.c	2008-07-08 14:24:25.094694910 +0200
+++ new-hotspare-prime/tools/vgreduce.c	2008-07-08 14:24:25.134697106 +0200
@@ -130,6 +130,26 @@ static int _remove_lv(struct cmd_context
 	return 1;
 }
 
+static int _consolidate_vg(struct cmd_context *cmd, struct volume_group *vg)
+{
+	struct list *pvh, *pvht;
+	struct pv_list *pvl;
+	list_iterate_safe(pvh, pvht, &vg->pvs) {
+		pvl = list_item(pvh, struct pv_list);
+		if (pvl->pv->dev && !(pvl->pv->status & MISSING_PV))
+			continue;
+		if (!_remove_pv(vg, pvl))
+			return_0;
+	}
+
+	/* VG is now consistent */
+	vg->status &= ~PARTIAL_VG;
+
+	init_partial(0);
+
+	return 1;
+}
+
 static int _make_vg_consistent(struct cmd_context *cmd, struct volume_group *vg)
 {
 	struct list *pvh, *pvht;
@@ -183,20 +203,8 @@ static int _make_vg_consistent(struct cm
 		return 0;
 	}
 
-	/* Remove missing PVs */
-	list_iterate_safe(pvh, pvht, &vg->pvs) {
-		pvl = list_item(pvh, struct pv_list);
-		if (pvl->pv->dev && !(pvl->pv->status & MISSING_PV))
-			continue;
-		if (!_remove_pv(vg, pvl))
-			return_0;
-	}
-
-	/* VG is now consistent */
-	vg->status &= ~PARTIAL_VG;
-	vg->status |= LVM_WRITE;
-
-	init_partial(0);
+	if (!_consolidate_vg(cmd, vg))
+		return_0;
 
 	/* FIXME Recovery.  For now people must clean up by hand. */
 
@@ -441,14 +449,16 @@ int vgreduce(struct cmd_context *cmd, in
 	char *vg_name;
 	int ret = 1;
 	int consistent = 1;
+	int repairing = arg_count(cmd, removemissing_ARG) ||
+			arg_count(cmd, consolidate_ARG);
 
-	if (!argc && !arg_count(cmd, removemissing_ARG)) {
+	if (!argc && !repairing) {
 		log_error("Please give volume group name and "
 			  "physical volume paths");
 		return EINVALID_CMD_LINE;
 	}
-
-	if (!argc && arg_count(cmd, removemissing_ARG)) {
+	
+	if (!argc && repairing) {
 		log_error("Please give volume group name");
 		return EINVALID_CMD_LINE;
 	}
@@ -459,8 +469,15 @@ int vgreduce(struct cmd_context *cmd, in
 		return EINVALID_CMD_LINE;
 	}
 
-	if (argc == 1 && !arg_count(cmd, all_ARG)
-	    && !arg_count(cmd, removemissing_ARG)) {
+	if (arg_count(cmd, consolidate_ARG)) {
+		if (arg_count(cmd, removemissing_ARG)) {
+			log_error("--removemissing and --consolidate are "
+				  "mutually exclusive");
+			return EINVALID_CMD_LINE;
+		}
+	}
+
+	if (argc == 1 && !arg_count(cmd, all_ARG) && !repairing) {
 		log_error("Please enter physical volume paths or option -a");
 		return EINVALID_CMD_LINE;
 	}
@@ -471,7 +488,7 @@ int vgreduce(struct cmd_context *cmd, in
 		return EINVALID_CMD_LINE;
 	}
 
-	if (argc > 1 && arg_count(cmd, removemissing_ARG)) {
+	if (argc > 1 && repairing) {
 		log_error("Please only specify the volume group");
 		return EINVALID_CMD_LINE;
 	}
@@ -504,7 +521,7 @@ int vgreduce(struct cmd_context *cmd, in
 		return ECMD_FAILED;
 	}
 
-	if (arg_count(cmd, removemissing_ARG)) {
+	if (repairing) {
 		if (vg && consistent && !(vg->status & PARTIAL_VG)) {
 			log_error("Volume group \"%s\" is already consistent",
 				  vg_name);
@@ -529,10 +546,14 @@ int vgreduce(struct cmd_context *cmd, in
 			return ECMD_FAILED;
 		}
 
-		if (!_make_vg_consistent(cmd, vg)) {
-			init_partial(0);
-			unlock_vg(cmd, vg_name);
-			return ECMD_FAILED;
+		if (arg_count(cmd, removemissing_ARG)) {
+			if (!_make_vg_consistent(cmd, vg)) {
+				init_partial(0);
+				unlock_vg(cmd, vg_name);
+				return ECMD_FAILED;
+			}
+		} else {
+			_consolidate_vg(cmd, vg);
 		}
 
 		if (!vg_write(vg) || !vg_commit(vg)) {

-- 
Peter Rockai | me()mornfall!net | prockai()redhat!com
 http://blog.mornfall.net | http://web.mornfall.net

"In My Egotistical Opinion, most people's C programs should be
 indented six feet downward and covered with dirt."
     -- Blair P. Houghton on the subject of C program indentation

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