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

[lvm-devel] [PATCH] (7/11) API improvements



Hi,

this patch improves the API somewhat, by restructuring the way errors are
checked for by the client code: a vg_read_error function is provided for that,
and the vg_read(_for_update) has seen some improvements unrelated to that. It
also makes vg_read_for_update a simple front-end to vg_read, as vg_read will be
needed later to have the same capabilities, easily (this is done through the
READ_FOR_UPDATE flag). I admit that this is a little incoherent together in a
single patch, but that's how things winded up.

Yours,
   Petr.

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 14:42:06 CEST 2008  Petr Rockai <me mornfall net>
  * Fix vgdisplay's VG validity check to use vg_read_error.
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
diff -rN -p -u old-lvmlib-b/lib/metadata/metadata.c new-lvmlib-b/lib/metadata/metadata.c
--- old-lvmlib-b/lib/metadata/metadata.c	2008-10-30 18:32:26.373834395 +0100
+++ new-lvmlib-b/lib/metadata/metadata.c	2008-10-30 18:32:26.441834937 +0100
@@ -2407,12 +2407,35 @@ int vg_check_status(const struct volume_
 	return !_vg_check_status(vg, status);
 }
 
-static vg_t *_vg_read_failure(struct cmd_context *cmd, uint32_t flags)
-{
-	struct volume_group *vg;
-	if (!(vg = dm_pool_zalloc(cmd->mem, sizeof(*vg))))
-		return_NULL;
-	vg->failed = flags;
+int vg_read_error(vg_t *vg) {
+	if (!vg)
+		return FAILED_ALLOCATION;
+	if (vg->read_failed & EXISTENCE_CHECK)
+		return vg->read_failed & ~(EXISTENCE_CHECK | FAILED_NOTFOUND);
+	return vg->read_failed;
+}
+
+/* Returns true if the volume group already exists. If unsure, it will return
+   true (it might exist, but we are not sure, as the read failed for some
+   other reason). */
+
+int vg_exists(vg_t *vg) {
+	if (!vg)
+		return 1;
+	log_error("vg_exists: %d != %d?", vg->read_failed, FAILED_NOTFOUND | EXISTENCE_CHECK);
+	if (vg->read_failed == (FAILED_NOTFOUND | EXISTENCE_CHECK))
+		return 0;
+	return 1;
+}
+
+static vg_t *_vg_make_handle(struct cmd_context *cmd,
+			     struct volume_group *vg,
+			     uint32_t failure)
+{
+	if (!vg)
+		if (!(vg = dm_pool_zalloc(cmd->mem, sizeof(*vg))))
+			return_NULL;
+	vg->read_failed = failure;
 	return vg;
 }
 
@@ -2441,9 +2464,26 @@ static vg_t *_vg_read_failure(struct cmd
 vg_t *vg_read_for_update(struct cmd_context *cmd, const char *vg_name,
 			 const char *vgid, uint32_t flags)
 {
-	uint32_t status = CLUSTERED | EXPORTED_VG | LVM_WRITE;
-	uint32_t lock = LCK_VG_WRITE;
-	uint32_t misc = FAIL_INCONSISTENT;
+	return vg_read(cmd, vg_name, vgid, flags | READ_FOR_UPDATE);
+}
+
+/*
+ * FIXME we want vg_read to attempt automatic recovery after acquiring a
+ * temporary write lock -- if that fails, we bail out as usual, with failed &
+ * FAILED_INCONSISTENT. If it works, we are good to go. Code that's been in
+ * toollib just set lock type to LCK_WRITE and called vg_read_internal with
+ * *consistent = 1.
+ */
+vg_t *vg_read(struct cmd_context *cmd, const char *vg_name,
+	      const char *vgid, uint32_t flags)
+{
+	uint32_t status = CLUSTERED;
+	uint32_t lock = LCK_VG_READ;
+
+	if (flags & READ_FOR_UPDATE) {
+		status |= EXPORTED_VG | LVM_WRITE;
+		lock = LCK_VG_WRITE;
+	}
 
 	if (flags & ALLOW_EXPORTED)
 		status &= ~EXPORTED_VG;
@@ -2454,33 +2494,18 @@ vg_t *vg_read_for_update(struct cmd_cont
 	if (flags & NONBLOCKING_LOCK)
 		lock |= LCK_NONBLOCK;
 
-	if (flags & EXISTENCE_CHECK)
-		misc |= EXISTENCE_CHECK;
-
-	if (flags & KEEP_LOCK)
-		misc |= KEEP_LOCK;
-
-	return vg_lock_and_read(cmd, vg_name, vgid, lock, status, misc);
-}
-
-vg_t *vg_read(struct cmd_context *cmd, const char *vg_name,
-	      const char *vgid, uint32_t flags)
-{
-	uint32_t status = CLUSTERED;
-	uint32_t lock = LCK_VG_READ;
-
-	return vg_lock_and_read(cmd, vg_name, vgid, lock, status, 0);
+	return vg_lock_and_read(cmd, vg_name, vgid, lock, status, flags);
 }
 
 /*
  * vg_lock_and_read - consolidate vg locking, reading, and status flag checking
  *
  * misc_flags:
- *  FAIL_INCONSISTENT: treat inconsistency as failure, disables autocorrection
+ *  ALLOW_INCONSISTENT: disable autocorrection
  *  
- * Not setting FAIL_INCONSISTENT and not locking for write will give you
- * inconsistent metadata. There is no other way to get inconsistent metadata
- * from this function. Otherwise, autocorrection will kick in.
+ * Setting ALLOW_INCONSISTENT might give you inconsistent metadata. You will
+ * *still* get FAILED_INCONSISTENT in case the metadata has *really* been
+ * inconsistent. However, you still get the latest version of metadata in VG.
  *
  * Returns:
  * NULL - failure
@@ -2491,11 +2516,13 @@ vg_t *vg_lock_and_read(struct cmd_contex
 		       uint32_t lock_flags, uint32_t status_flags,
 		       uint32_t misc_flags)
 {
-	struct volume_group *vg;
+	struct volume_group *vg = 0;
+	const char *lock;
 	int consistent = 1;
 	int consistent_in;
+	int failure = 0;
 
-	if (misc_flags & FAIL_INCONSISTENT || !(lock_flags & LCK_WRITE))
+	if (misc_flags & ALLOW_INCONSISTENT || !(lock_flags & LCK_WRITE))
 		consistent = 0;
 
 	if (!validate_name(vg_name) && !is_orphan_vg(vg_name)) {
@@ -2504,9 +2531,12 @@ vg_t *vg_lock_and_read(struct cmd_contex
 		return NULL;
 	}
 
-	if (!lock_vol(cmd, vg_name, lock_flags)) {
-		log_error("Can't get lock for %s", vg_name);
-		return _vg_read_failure(cmd, FAILED_LOCKING);
+	lock = (misc_flags & ORPHAN_LOCK ? VG_ORPHANS : vg_name);
+	if (!(misc_flags & DISABLE_LOCK)) {
+		if (!lock_vol(cmd, lock, lock_flags)) {
+			log_error("Can't get lock for %s", vg_name);
+			return _vg_make_handle(cmd, vg, FAILED_LOCKING);
+		}
 	}
 
 	if (misc_flags & ORPHAN_LOCK)
@@ -2517,29 +2547,36 @@ vg_t *vg_lock_and_read(struct cmd_contex
 
 	consistent_in = consistent;
 
-	/* FIXME those log_error's with vg_name rely on vg_name != NULL. */
-
 	/* If consistent == 1, we get NULL here if correction fails. */
 	if (!(vg = vg_read_internal(cmd, vg_name, vgid, &consistent))) {
-		vg = _vg_read_failure(cmd, 0);
 		if (consistent_in && !consistent) {
 			log_error("Volume group \"%s\" inconsistent.", vg_name);
-			vg->failed |= FAILED_INCONSISTENT;
+			failure |= FAILED_INCONSISTENT;
 			goto_bad;
 		}
 		if (!(misc_flags & EXISTENCE_CHECK))
 			log_error("Volume group \"%s\" not found", vg_name);
-		vg->failed |= FAILED_NOTFOUND;
+		failure |= FAILED_NOTFOUND | (misc_flags & EXISTENCE_CHECK);
 		goto_bad;
 	}
 
-	vg->failed |= _vg_check_status(vg, status_flags);
+	/* consistent == 0 when VG is not found, but failed == FAILED_NOTFOUND */
+	if (!consistent && !vg->read_failed) {
+		log_error("Volume group \"%s\" inconsistent.", vg_name);
+		failure |= FAILED_INCONSISTENT;
+		goto_bad;
+	}
 
-	return vg;
+	failure |= _vg_check_status(vg, status_flags);
+	if (failure)
+		goto_bad;
+
+	return _vg_make_handle(cmd, vg, failure);
  bad:
-	if (!(misc_flags & KEEP_LOCK))
-		unlock_vg(cmd, vg_name);
-	return vg;
+	if (failure != (FAILED_NOTFOUND | EXISTENCE_CHECK))
+		if (!(misc_flags & KEEP_LOCK) && !(misc_flags & DISABLE_LOCK))
+			unlock_vg(cmd, lock);
+	return _vg_make_handle(cmd, vg, failure);
 }
 
 /*
diff -rN -p -u old-lvmlib-b/lib/metadata/metadata-exported.h new-lvmlib-b/lib/metadata/metadata-exported.h
--- old-lvmlib-b/lib/metadata/metadata-exported.h	2008-10-30 18:32:26.373834395 +0100
+++ new-lvmlib-b/lib/metadata/metadata-exported.h	2008-10-30 18:32:26.441834937 +0100
@@ -100,22 +100,31 @@ struct pv_segment;
 #define FAIL_INCONSISTENT       0x00000002U /* Fail if metadata inconsistent */
 
 /* vg_read and vg_read_for_update flags */
-#define ALLOW_EXPORTED 0x1
-#define REQUIRE_RESIZEABLE 0x2
-#define EXISTENCE_CHECK 0x4
-#define NONBLOCKING_LOCK 0x8
-#define KEEP_LOCK 0x10
+#define ALLOW_INCONSISTENT 0x1
+#define ALLOW_EXPORTED 0x2
+#define REQUIRE_RESIZEABLE 0x4
+#define EXISTENCE_CHECK 0x8
+
+#define NONBLOCKING_LOCK 0x100
+#define KEEP_LOCK 0x200
+#define DISABLE_LOCK 0x400
+#define ORPHAN_LOCK 0x800
 
-/* vg's "failed" field */
+#define READ_FOR_UPDATE 0x1000
+
+/* vg's "read_failed" field */
 #define FAILED_INCONSISTENT 0x1
 #define FAILED_LOCKING 0x2
 #define FAILED_NOTFOUND 0x4
+// 0x8 is left out for EXISTENCE_CHECK
 
 #define FAILED_READ_ONLY 0x10
 #define FAILED_EXPORTED 0x20
 #define FAILED_RESIZEABLE 0x40
 #define FAILED_CLUSTERED 0x80
 
+#define FAILED_ALLOCATION 0x100
+
 /* Mirror conversion type flags */
 #define MIRROR_BY_SEG		0x00000001U	/* segment-by-segment mirror */
 #define MIRROR_BY_LV		0x00000002U	/* mirror using whole mimage LVs */
@@ -214,7 +223,7 @@ struct volume_group {
 	char *system_id;
 
 	uint32_t status;
-	uint32_t failed;
+	uint32_t read_failed;
 
 	alloc_policy_t alloc;
 
@@ -373,6 +382,8 @@ vg_t *vg_lock_and_read(struct cmd_contex
 		       uint32_t lock_flags, uint32_t status_flags,
 		       uint32_t misc_flags);
 
+int vg_read_error(vg_t *vg);
+int vg_exists(vg_t *vg);
 vg_t *vg_read(struct cmd_context *cmd, const char *vg_name,
 	      const char *vgid, uint32_t flags);
 
diff -rN -p -u old-lvmlib-b/tools/lvconvert.c new-lvmlib-b/tools/lvconvert.c
--- old-lvmlib-b/tools/lvconvert.c	2008-10-30 18:32:26.357833968 +0100
+++ new-lvmlib-b/tools/lvconvert.c	2008-10-30 18:32:26.405838114 +0100
@@ -745,7 +745,7 @@ int lvconvert(struct cmd_context * cmd, 
 	log_verbose("Checking for existing volume group \"%s\"", lp.vg_name);
 
 	vg = vg_read_for_update(cmd, lp.vg_name, NULL, 0);
-	if (!vg || vg->failed)
+	if (vg_read_error(vg))
 		return ECMD_FAILED;
 
 	if (!(lvl = find_lv_in_vg(vg, lp.lv_name))) {
diff -rN -p -u old-lvmlib-b/tools/lvcreate.c new-lvmlib-b/tools/lvcreate.c
--- old-lvmlib-b/tools/lvcreate.c	2008-10-30 18:32:26.357833968 +0100
+++ new-lvmlib-b/tools/lvcreate.c	2008-10-30 18:32:26.405838114 +0100
@@ -897,7 +897,7 @@ int lvcreate(struct cmd_context *cmd, in
 
 	log_verbose("Finding volume group \"%s\"", lp.vg_name);
 	vg = vg_read_for_update(cmd, lp.vg_name, NULL, 0);
-	if (!vg || vg->failed)
+	if (vg_read_error(vg))
 		return ECMD_FAILED;
 
 	if (!_lvcreate(cmd, vg, &lp))
diff -rN -p -u old-lvmlib-b/tools/lvrename.c new-lvmlib-b/tools/lvrename.c
--- old-lvmlib-b/tools/lvrename.c	2008-10-30 18:32:26.357833968 +0100
+++ new-lvmlib-b/tools/lvrename.c	2008-10-30 18:32:26.405838114 +0100
@@ -102,7 +102,7 @@ int lvrename(struct cmd_context *cmd, in
 
 	log_verbose("Checking for existing volume group \"%s\"", vg_name);
 	vg = vg_read_for_update(cmd, vg_name, NULL, 0);
-	if (!vg || vg->failed)
+	if (vg_read_error(vg))
 		return ECMD_FAILED;
 
 	if (!(lvl = find_lv_in_vg(vg, lv_name_old))) {
diff -rN -p -u old-lvmlib-b/tools/lvresize.c new-lvmlib-b/tools/lvresize.c
--- old-lvmlib-b/tools/lvresize.c	2008-10-30 18:32:26.357833968 +0100
+++ new-lvmlib-b/tools/lvresize.c	2008-10-30 18:32:26.405838114 +0100
@@ -662,7 +662,7 @@ int lvresize(struct cmd_context *cmd, in
 
 	log_verbose("Finding volume group %s", lp.vg_name);
 	vg = vg_read_for_update(cmd, lp.vg_name, NULL, 0);
-	if (!vg || vg->failed) {
+	if (vg_read_error(vg)) {
 		stack;
 		return ECMD_FAILED;
 	}
diff -rN -p -u old-lvmlib-b/tools/polldaemon.c new-lvmlib-b/tools/polldaemon.c
--- old-lvmlib-b/tools/polldaemon.c	2008-10-30 18:32:26.357833968 +0100
+++ new-lvmlib-b/tools/polldaemon.c	2008-10-30 18:32:26.405838114 +0100
@@ -148,7 +148,7 @@ static int _wait_for_single_mirror(struc
 
 		/* Locks the (possibly renamed) VG again */
 		vg = parms->poll_fns->get_copy_vg(cmd, name);
-		if (!vg || vg->failed) {
+		if (vg_read_error(vg)) {
 			log_error("ABORTING: Can't reread VG for %s", name);
 			/* What more could we do here? */
 			return 0;
diff -rN -p -u old-lvmlib-b/tools/pvchange.c new-lvmlib-b/tools/pvchange.c
--- old-lvmlib-b/tools/pvchange.c	2008-10-30 18:32:26.357833968 +0100
+++ new-lvmlib-b/tools/pvchange.c	2008-10-30 18:32:26.409835479 +0100
@@ -57,7 +57,7 @@ static int _pvchange_single(struct cmd_c
 		log_verbose("Finding volume group %s of physical volume %s",
 			    vg_name, pv_name);
 		vg = vg_read_for_update(cmd, vg_name, NULL, 0);
-		if (!vg || vg->failed)
+		if (vg_read_error(vg))
 			return_0;
 
 		if (!(pvl = find_pv_in_vg(vg, pv_name))) {
diff -rN -p -u old-lvmlib-b/tools/pvdisplay.c new-lvmlib-b/tools/pvdisplay.c
--- old-lvmlib-b/tools/pvdisplay.c	2008-10-30 18:32:26.357833968 +0100
+++ new-lvmlib-b/tools/pvdisplay.c	2008-10-30 18:32:26.409835479 +0100
@@ -29,9 +29,9 @@ static int _pvdisplay_single(struct cmd_
 	if (!is_orphan(pv) && !vg) {
 		vg_name = pv_vg_name(pv);
 		vg = vg_read(cmd, vg_name, (char *)&pv->vgid, 0);
-		if (!vg || vg->failed) {
+		if (vg_read_error(vg)) {
 		 	log_error("Skipping volume group %s", vg_name);
-			if (vg->failed == FAILED_CLUSTERED)
+			if (vg_read_error(vg) == FAILED_CLUSTERED)
 				return ECMD_PROCESSED;
 		 	return ECMD_FAILED;
 	 	}
diff -rN -p -u old-lvmlib-b/tools/pvmove.c new-lvmlib-b/tools/pvmove.c
--- old-lvmlib-b/tools/pvmove.c	2008-10-30 18:32:26.357833968 +0100
+++ new-lvmlib-b/tools/pvmove.c	2008-10-30 18:32:26.405838114 +0100
@@ -376,7 +376,7 @@ static int _set_up_pvmove(struct cmd_con
 	log_verbose("Finding volume group \"%s\"", pv_vg_name(pv));
 
 	vg = _get_vg(cmd, pv_vg_name(pv));
-	if (!vg || vg->failed) {
+	if (vg_read_error(vg)) {
 		stack;
 		return ECMD_FAILED;
 	}
diff -rN -p -u old-lvmlib-b/tools/pvresize.c new-lvmlib-b/tools/pvresize.c
--- old-lvmlib-b/tools/pvresize.c	2008-10-30 18:32:26.357833968 +0100
+++ new-lvmlib-b/tools/pvresize.c	2008-10-30 18:32:26.401838094 +0100
@@ -58,7 +58,7 @@ static int _pv_resize_single(struct cmd_
 
 		vg = vg_read_for_update(cmd, vg_name, NULL, 0);
 
-		if (!vg || vg->failed)
+		if (vg_read_error(vg))
 			return 0;
 
 		if (!(pvl = find_pv_in_vg(vg, pv_name))) {
diff -rN -p -u old-lvmlib-b/tools/reporter.c new-lvmlib-b/tools/reporter.c
--- old-lvmlib-b/tools/reporter.c	2008-10-30 18:32:26.357833968 +0100
+++ new-lvmlib-b/tools/reporter.c	2008-10-30 18:32:26.405838114 +0100
@@ -126,7 +126,7 @@ static int _pvs_single(struct cmd_contex
 		vg_name = pv_vg_name(pv);
 
 		vg = vg_read(cmd, vg_name, (char *)&pv->vgid, 0);
-		if (!vg || vg->failed) {
+		if (vg_read_error(vg)) {
 			log_error("Skipping volume group %s", vg_name);
 			return ECMD_FAILED;
 		}
diff -rN -p -u old-lvmlib-b/tools/toollib.c new-lvmlib-b/tools/toollib.c
--- old-lvmlib-b/tools/toollib.c	2008-10-30 18:32:26.357833968 +0100
+++ new-lvmlib-b/tools/toollib.c	2008-10-30 18:32:26.409835479 +0100
@@ -428,7 +428,7 @@ int process_each_segment_in_pv(struct cm
 		vg_name = pv_vg_name(pv);
 
 		vg = vg_read(cmd, vg_name, NULL, 0);
-		if (!vg || vg->failed) {
+		if (vg_read_error(vg)) {
 			log_error("Skipping volume group %s", vg_name);
 			return ECMD_FAILED;
 		}
diff -rN -p -u old-lvmlib-b/tools/vgextend.c new-lvmlib-b/tools/vgextend.c
--- old-lvmlib-b/tools/vgextend.c	2008-10-30 18:32:26.357833968 +0100
+++ new-lvmlib-b/tools/vgextend.c	2008-10-30 18:32:26.409835479 +0100
@@ -43,7 +43,7 @@ int vgextend(struct cmd_context *cmd, in
 	log_verbose("Checking for volume group \"%s\"", vg_name);
 	vg = vg_read_for_update(cmd, vg_name, NULL,
 				REQUIRE_RESIZEABLE | NONBLOCKING_LOCK);
-	if (!vg || vg->failed) {
+	if (vg_read_error(vg)) {
 		unlock_vg(cmd, VG_ORPHANS);
 		return ECMD_FAILED;
 	 }
diff -rN -p -u old-lvmlib-b/tools/vgmerge.c new-lvmlib-b/tools/vgmerge.c
--- old-lvmlib-b/tools/vgmerge.c	2008-10-30 18:32:26.357833968 +0100
+++ new-lvmlib-b/tools/vgmerge.c	2008-10-30 18:32:26.405838114 +0100
@@ -28,13 +28,13 @@ static int _vgmerge_single(struct cmd_co
 
 	log_verbose("Checking for volume group \"%s\"", vg_name_to);
 	vg_to = vg_read_for_update(cmd, vg_name_to, NULL, 0);
-	if (!vg_to || vg_to->failed)
+	if (vg_read_error(vg_to))
 		 return ECMD_FAILED;
 
 	log_verbose("Checking for volume group \"%s\"", vg_name_from);
 	vg_from = vg_read_for_update(cmd, vg_name_from, NULL,
 				     NONBLOCKING_LOCK);
-	if (!vg_from || vg_from->failed) {
+	if (vg_read_error(vg_from)) {
 		unlock_vg(cmd, vg_name_to);
 		return ECMD_FAILED;
 	}
diff -rN -p -u old-lvmlib-b/tools/vgrename.c new-lvmlib-b/tools/vgrename.c
--- old-lvmlib-b/tools/vgrename.c	2008-10-30 18:32:26.349834976 +0100
+++ new-lvmlib-b/tools/vgrename.c	2008-10-30 18:32:26.409835479 +0100
@@ -20,7 +20,6 @@ static int vg_rename_path(struct cmd_con
 {
 	char *dev_dir;
 	struct id id;
-	int consistent = 1;
 	int match = 0;
 	int found_id = 0;
 	struct list *vgids;
@@ -73,7 +72,7 @@ static int vg_rename_path(struct cmd_con
 	/* FIXME we used to print an error about EXPORTED, but proceeded
 	   nevertheless. */
 	vg = vg_read_for_update(cmd, vg_name_old, vgid, ALLOW_EXPORTED);
-	if (!vg || vg->failed)
+	if (vg_read_error(vg))
 		return_0;
 
 	if (lvs_in_vg_activated_by_uuid_only(vg)) {
@@ -89,10 +88,10 @@ static int vg_rename_path(struct cmd_con
 	vg_new = vg_read_for_update(cmd, vg_name_new, NULL, KEEP_LOCK |
 				    EXISTENCE_CHECK | NONBLOCKING_LOCK);
 
-	if (!vg_new || (vg_new->failed && !(vg_new->failed & FAILED_NOTFOUND)))
-		goto error;
+	if (vg_read_error(vg_new))
+	    goto error;
 
-	if (!(vg_new->failed & FAILED_NOTFOUND)) {
+	if (vg_exists(vg_new)) {
 		log_error("New volume group \"%s\" already exists",
 			  vg_name_new);
 		goto error;
diff -rN -p -u old-lvmlib-b/tools/vgsplit.c new-lvmlib-b/tools/vgsplit.c
--- old-lvmlib-b/tools/vgsplit.c	2008-10-30 18:32:26.373834395 +0100
+++ new-lvmlib-b/tools/vgsplit.c	2008-10-30 18:32:26.405838114 +0100
@@ -322,7 +322,7 @@ int vgsplit(struct cmd_context *cmd, int
 	log_verbose("Checking for volume group \"%s\"", vg_name_from);
 	vg_from = vg_read_for_update(cmd, vg_name_from, NULL,
 				     REQUIRE_RESIZEABLE);
-	if (!vg_from || vg_from->failed)
+	if (vg_read_error(vg_from))
 		return ECMD_FAILED;
 
 	log_verbose("Checking for new volume group \"%s\"", vg_name_to);
@@ -330,10 +330,10 @@ int vgsplit(struct cmd_context *cmd, int
 				   NONBLOCKING_LOCK | KEEP_LOCK |
 				   EXISTENCE_CHECK);
 
-	if (!vg_to || (vg_to->failed && !(vg_to->failed & FAILED_NOTFOUND)))
+	if (vg_read_error(vg_to))
 		goto_bad;
 
-	if (!(vg_to->failed & FAILED_NOTFOUND)) {
+	if (vg_exists(vg_to)) {
 		existing_vg = 1;
 		if (new_vg_option_specified(cmd)) {
 			log_error("Volume group \"%s\" exists, but new VG "
@@ -449,12 +449,14 @@ int vgsplit(struct cmd_context *cmd, int
 	 * Finally, remove the EXPORTED flag from the new VG and write it out.
 	 */
 	consistent = 1;
-	if (!test_mode() &&
-	    (!(vg_to = vg_read_internal(cmd, vg_name_to, NULL, &consistent)) ||
-	     !consistent)) {
-		log_error("Volume group \"%s\" became inconsistent: please "
-			  "fix manually", vg_name_to);
-		goto_bad;
+	if (!test_mode()) {
+		vg_to = vg_read_for_update(cmd, vg_name_to, NULL,
+					   DISABLE_LOCK | ALLOW_EXPORTED);
+		if (vg_read_error(vg_to)) {
+			log_error("Volume group \"%s\" became inconsistent: "
+				  "please fix manually", vg_name_to);
+			goto_bad;
+		}
 	}
 
 	vg_to->status &= ~EXPORTED_VG;

diff -rN -p -u old-lvmlib-b/tools/vgdisplay.c new-lvmlib-b/tools/vgdisplay.c
--- old-lvmlib-b/tools/vgdisplay.c	2008-10-30 18:40:49.945834398 +0100
+++ new-lvmlib-b/tools/vgdisplay.c	2008-10-30 18:40:49.973834744 +0100
@@ -20,7 +20,7 @@ static int vgdisplay_single(struct cmd_c
 			    void *handle __attribute((unused)))
 {
 	/* FIXME Do the active check here if activevolumegroups_ARG ? */
-	if (!vg)
+	if (vg_read_error(vg))
 		return ECMD_FAILED;
 
 	vg_check_status(vg, EXPORTED_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]