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

[lvm-devel] [PATCH] (9/11) bring vgreduce up to date with API changes



Hi,

this here accumulates the changes over vgreduce, since those had some conflicts
with the hotspare branch that has been running sort of parallel to this. It
should be fairly straightforward here. Mostly just removes uses of
vg_read_internal and replaces them with new-style API.

Yours,
   Petr.

Tue Sep 30 23:40:01 CEST 2008  me mornfall net
  * Fix a botched error check in vgreduce.
Tue Sep 30 23:39:20 CEST 2008  me mornfall net
  * Verbose: say we are about to open a VG for recovery in vgreduce.
Tue Sep 30 23:39:09 CEST 2008  me mornfall net
  * Minor formatting change.
Tue Sep 30 14:42:37 CEST 2008  me mornfall net
  * Resolve conflicts with upstream.
Thu Oct 30 18:35:24 CET 2008  Petr Rockai <me mornfall net>
  tagged base 8-6
Thu Jul 24 16:50:48 CEST 2008  me mornfall net
  * Merge the toollib changes with the vg_read_error ones.
Sat Jul 12 16:34:57 CEST 2008  me mornfall net
  * Reimplement process_each_vg, process_each_lv using new vg_read.
  
  This touches a huge number of files, changing parameters to new-style vg_read
  instead of the old lock_type (and in case of each_vg the "consistent"
  parameter). It also abolishes the recover_vg toollib facility, as that should
  become part of new vg_read (and could be possibly disabled by a flag, if there
  are cases where we want to explicitly disallow it).
Mon Oct 27 12:30:20 CET 2008  Petr Rockai <me mornfall net>
  * Fix uninitialised use of char *lock in vg_lock_and_read.
Tue Oct 14 22:51:25 CEST 2008  Petr Rockai <me mornfall net>
  * Keep locks on non-existent volume groups when doing an EXISTENCE_CHECK.
Tue Oct 14 14:41:27 CEST 2008  Petr Rockai <me mornfall net>
  * Do not forget to unlock volume group upon a late failure in vg_read.
Tue Oct 14 14:40:34 CEST 2008  Petr Rockai <me mornfall net>
  * Grab the right lock when dealing with orphan VG.
Tue Sep 30 23:34:56 CEST 2008  me mornfall net
  * Remove a spurious early return from vg_read which caused flag mis-processing.
Tue Sep 30 23:34:41 CEST 2008  me mornfall net
  * Fix vg_exists to give proper results.
Sat Jul 12 16:40:43 CEST 2008  me mornfall net
  * Fix thinko (no "repairing" in this version fo vgreduce).
Fri Jul 18 16:06:30 CEST 2008  me mornfall net
  * Slap a new API on top of the existing implementation.
  
  The new API has these calls:
  vg_read -- like before, returning vg_t *
  vg_read_error -- returns true (and reason) when an error has happened (any
                   error)... If EXISTENCE_CHECK has been supplied to vg_read,
                   FAILED_NOTFOUND is *not* an error
  vg_exists -- returns true if the result of vg_read is that the volume *might*
               exist (in case of failures, it may in fact not, but we play safe
               here)
Sat Jul 12 16:34:11 CEST 2008  me mornfall net
  * Add missed log_error to vg_lock_and_read.
Sat Jul 12 16:33:42 CEST 2008  me mornfall net
  * Compile... (typo fix).
Sat Jul 12 16:32:42 CEST 2008  me mornfall net
  * Add READ_FOR_UPDATE flag, make vg_read_for_update alias for vg_read(..., READ_FOR_UPDATE | flags).
Sat Jul 12 15:31:07 CEST 2008  me mornfall net
  * Implement ORPHAN_LOCK for vg_read_for_update, use it in vgreduce.
Sat Jul 12 15:29:07 CEST 2008  me mornfall net
  * Add ALLOW_INCONSISTENT and use it in vgreduce --removemissing.
Sat Jul 12 14:55:01 CEST 2008  me mornfall net
  * Add DISABLE_LOCK to vg_read_for_update, use it to convert vg_read_internal use in vgsplit.
Thu Oct 30 18:17:47 CET 2008  Petr Rockai <me mornfall net>
  tagged base 8-5
Sat Jul 12 14:50:51 CEST 2008  me mornfall net
  * Add vg_read for read-only VG access and use it.
Thu Oct 30 18:17:09 CET 2008  Petr Rockai <me mornfall net>
  tagged base 8-4
--- old-lvmlib-b/tools/vgreduce.c	2008-10-30 18:37:14.649834906 +0100
+++ new-lvmlib-b/tools/vgreduce.c	2008-10-30 18:37:14.669833748 +0100
@@ -382,7 +382,6 @@ static int _vgreduce_single(struct cmd_c
 {
 	struct pv_list *pvl;
 	struct volume_group *orphan_vg;
-	int consistent = 1;
 	const char *name = pv_dev_name(pv);
 
 	if (pv_pe_alloc_count(pv)) {
@@ -396,17 +395,10 @@ static int _vgreduce_single(struct cmd_c
 		return ECMD_FAILED;
 	}
 
-	if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE | LCK_NONBLOCK)) {
-		log_error("Can't get lock for orphan PVs");
-		return ECMD_FAILED;
-	}
-
 	pvl = find_pv_in_vg(vg, name);
 
-	if (!archive(vg)) {
-		unlock_vg(cmd, VG_ORPHANS);
+	if (!archive(vg))
 		return ECMD_FAILED;
-	}
 
 	log_verbose("Removing \"%s\" from volume group \"%s\"", name, vg->name);
 
@@ -426,12 +418,11 @@ static int _vgreduce_single(struct cmd_c
 	vg->free_count -= pv_pe_count(pv) - pv_pe_alloc_count(pv);
 	vg->extent_count -= pv_pe_count(pv);
 
-	if(!(orphan_vg = vg_read_internal(cmd, vg->fid->fmt->orphan_vg_name, NULL, &consistent)) ||
-	   !consistent) {
-		log_error("Unable to read existing orphan PVs");
-		unlock_vg(cmd, VG_ORPHANS);
+	orphan_vg = vg_read_for_update(cmd, vg->fid->fmt->orphan_vg_name,
+				       NULL, NONBLOCKING_LOCK | ORPHAN_LOCK);
+
+	if (vg_read_error(orphan_vg))
 		return ECMD_FAILED;
-	}
 
 	if (!vg_split_mdas(cmd, vg, orphan_vg) || !vg->pv_count) {
 		log_error("Cannot remove final metadata area on \"%s\" from \"%s\"",
@@ -468,7 +459,6 @@ int vgreduce(struct cmd_context *cmd, in
 	struct volume_group *vg;
 	char *vg_name;
 	int ret = 1;
-	int consistent = 1;
 	int fixed = 1;
 	int repairing = arg_count(cmd, removemissing_ARG);
 
@@ -515,41 +505,37 @@ int vgreduce(struct cmd_context *cmd, in
 	}
 
 	log_verbose("Finding volume group \"%s\"", vg_name);
-	if (!lock_vol(cmd, vg_name, LCK_VG_WRITE)) {
-		log_error("Can't get lock for %s", vg_name);
-		return ECMD_FAILED;
-	}
 
-	if ((!(vg = vg_read_internal(cmd, vg_name, NULL, &consistent)) || !consistent)
-	    && !repairing) {
-		log_error("Volume group \"%s\" doesn't exist", vg_name);
-		unlock_vg(cmd, vg_name);
+	vg = vg_read_for_update(cmd, vg_name, NULL, ALLOW_EXPORTED);
+	if (vg_read_error(vg) == FAILED_ALLOCATION ||
+	    vg_read_error(vg) == FAILED_NOTFOUND)
 		return ECMD_FAILED;
-	}
 
-	if (vg && !vg_check_status(vg, CLUSTERED)) {
-		unlock_vg(cmd, vg_name);
+	/* FIXME We want to allow read-only VGs to be changed here? */
+	if (vg_read_error(vg) && vg_read_error(vg) != FAILED_READ_ONLY
+	    && !arg_count(cmd, removemissing_ARG))
 		return ECMD_FAILED;
-	}
 
 	if (repairing) {
-		if (vg && consistent && !vg_missing_pv_count(vg)) {
+		if (!vg_read_error(vg) && !vg_missing_pv_count(vg)) {
 			log_error("Volume group \"%s\" is already consistent",
 				  vg_name);
 			unlock_vg(cmd, vg_name);
 			return ECMD_PROCESSED;
 		}
 
-		consistent = !arg_count(cmd, force_ARG);
-		if (!(vg = vg_read_internal(cmd, vg_name, NULL, &consistent))) {
-			log_error("Volume group \"%s\" not found", vg_name);
-			unlock_vg(cmd, vg_name);
-			return ECMD_FAILED;
-		}
-		if (!vg_check_status(vg, CLUSTERED)) {
+		log_verbose("Trying to open VG %s for recovery...", vg_name);
+
+		vg = vg_read_for_update(cmd, vg_name, NULL,
+					ALLOW_INCONSISTENT | DISABLE_LOCK
+					| ALLOW_EXPORTED);
+
+		if (vg_read_error(vg) && vg_read_error(vg) != FAILED_READ_ONLY
+		    && vg_read_error(vg) != FAILED_INCONSISTENT) {
 			unlock_vg(cmd, vg_name);
 			return ECMD_FAILED;
 		}
+
 		if (!archive(vg)) {
 			unlock_vg(cmd, vg_name);
 			return ECMD_FAILED;

-- 
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]