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

[lvm-devel] [PATCH] vgextend --restore (BZ 537913)



Hi,

this has been waiting on my machine for a while now, waiting for user
interface feedback (see the relevant BZ). Anyhow, I am sending this with
my stab at the UI, subject to further discussion.

An automated test (tests/t-vgextend-restore.sh) is included in the
patch.

Yours,
   Petr.

Index: tools/vgextend.c
===================================================================
RCS file: /cvs/lvm2/LVM2/tools/vgextend.c,v
retrieving revision 1.59
diff -u -p -r1.59 vgextend.c
--- tools/vgextend.c	7 Jul 2010 21:30:07 -0000	1.59
+++ tools/vgextend.c	4 Oct 2010 15:59:57 -0000
@@ -15,12 +15,36 @@
 
 #include "tools.h"
 
+static int _restore_pv(struct volume_group *vg, char *pv_name)
+{
+	struct pv_list *pvl = NULL;
+	pvl = find_pv_in_vg(vg, pv_name);
+	if (!pvl) {
+		log_warn("WARNING: PV %s not found in VG %s", pv_name, vg->name);
+		return 0;
+	}
+
+	if (!(pvl->pv->status & MISSING_PV)) {
+		log_warn("WARNING: PV %s was not missing in VG %s", pv_name, vg->name);
+		return 0;
+	}
+
+	if (!pvl->pv->dev) {
+		log_warn("WARNING: The PV %s is still missing.", pv_name);
+		return 0;
+	}
+
+	pvl->pv->status &= ~MISSING_PV;
+	return 1;
+}
+
 int vgextend(struct cmd_context *cmd, int argc, char **argv)
 {
 	char *vg_name;
 	struct volume_group *vg = NULL;
 	int r = ECMD_FAILED;
 	struct pvcreate_params pp;
+	int fixed = 0, i = 0;
 
 	if (!argc) {
 		log_error("Please enter volume group name and "
@@ -42,6 +66,9 @@ int vgextend(struct cmd_context *cmd, in
 		return EINVALID_CMD_LINE;
 	}
 
+	if (arg_count(cmd, restore_ARG))
+		cmd->handles_missing_pvs = 1;
+
 	log_verbose("Checking for volume group \"%s\"", vg_name);
 	vg = vg_read_for_update(cmd, vg_name, NULL, 0);
 	if (vg_read_error(vg)) {
@@ -50,42 +77,53 @@ int vgextend(struct cmd_context *cmd, in
 		return ECMD_FAILED;
 	}
 
-	if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
-		log_error("Can't get lock for orphan PVs");
-		unlock_and_release_vg(cmd, vg, vg_name);
-		return ECMD_FAILED;
-	}
-
 	if (!archive(vg))
 		goto_bad;
 
-	if (arg_count(cmd, metadataignore_ARG) &&
-	    (vg_mda_copies(vg) != VGMETADATACOPIES_UNMANAGED) &&
-	    (pp.force == PROMPT) &&
-	    yes_no_prompt("Override preferred number of copies "
+	if (arg_count(cmd, restore_ARG)) {
+		for (i = 0; i < argc; ++i) {
+			if (_restore_pv(vg, argv[i]))
+				++ fixed;
+		}
+		if (!fixed) {
+			log_error("No PV has been restored.");
+			goto_bad;
+		}
+	} else { /* no --restore, normal vgextend */
+		if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
+			log_error("Can't get lock for orphan PVs");
+			unlock_and_release_vg(cmd, vg, vg_name);
+			return ECMD_FAILED;
+		}
+
+		if (arg_count(cmd, metadataignore_ARG) &&
+		    (vg_mda_copies(vg) != VGMETADATACOPIES_UNMANAGED) &&
+		    (pp.force == PROMPT) &&
+		    yes_no_prompt("Override preferred number of copies "
 			  "of VG %s metadata? [y/n]: ",
-			  vg_name) == 'n') {
-		log_error("Volume group %s not changed", vg_name);
-		goto_bad;
-	}
-
-	/* extend vg */
-	if (!vg_extend(vg, argc, argv, &pp))
-		goto_bad;
-
-	if (arg_count(cmd, metadataignore_ARG) &&
-	    (vg_mda_copies(vg) != VGMETADATACOPIES_UNMANAGED) &&
-	    (vg_mda_copies(vg) != vg_mda_used_count(vg))) {
-		log_warn("WARNING: Changing preferred number of copies of VG %s "
+				  vg_name) == 'n') {
+			log_error("Volume group %s not changed", vg_name);
+			goto_bad;
+		}
+
+		/* extend vg */
+		if (!vg_extend(vg, argc, argv, &pp))
+			goto_bad;
+
+		if (arg_count(cmd, metadataignore_ARG) &&
+		    (vg_mda_copies(vg) != VGMETADATACOPIES_UNMANAGED) &&
+		    (vg_mda_copies(vg) != vg_mda_used_count(vg))) {
+			log_warn("WARNING: Changing preferred number of copies of VG %s "
 			 "metadata from %"PRIu32" to %"PRIu32, vg_name,
-			 vg_mda_copies(vg), vg_mda_used_count(vg));
-		vg_set_mda_copies(vg, vg_mda_used_count(vg));
+				 vg_mda_copies(vg), vg_mda_used_count(vg));
+			vg_set_mda_copies(vg, vg_mda_used_count(vg));
+		}
+
+		/* ret > 0 */
+		log_verbose("Volume group \"%s\" will be extended by %d new "
+			    "physical volumes", vg_name, argc);
 	}
 
-	/* ret > 0 */
-	log_verbose("Volume group \"%s\" will be extended by %d new "
-		    "physical volumes", vg_name, argc);
-
 	/* store vg on disk(s) */
 	if (!vg_write(vg) || !vg_commit(vg))
 		goto_bad;
Index: test/t-vgextend-restore.sh
===================================================================
RCS file: test/t-vgextend-restore.sh
diff -N test/t-vgextend-restore.sh
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ test/t-vgextend-restore.sh	4 Oct 2010 15:59:57 -0000
@@ -0,0 +1,30 @@
+#!/bin/bash
+# Copyright (C) 2010 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions
+# of the GNU General Public License v.2.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+. ./test-utils.sh
+
+
+aux prepare_vg 3
+lvcreate -m 1 -l 1 -n mirror $vg
+lvchange -a n $vg/mirror
+lvcreate -l 1 -n lv1 $vg $dev1
+
+# try to just change metadata; we expect the new version (with MISSING_PV set
+# on the reappeared volume) to be written out to the previously missing PV
+disable_dev $dev1
+lvremove $vg/mirror
+enable_dev $dev1
+not vgck $vg 2>&1 | tee log
+grep "missing 1 physical volume" log
+not lvcreate -m 1 -l 1 -n mirror $vg # write operations fail
+vgextend --restore $vg $dev1 # restore the missing device
+vgck $vg
+lvcreate -m 1 -l 1 -n mirror $vg

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