All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Wysochanski <dwysocha@redhat.com>
To: lvm-devel@redhat.com
Subject: [PATCH] Convert vgreduce to use vg_read_for_update.
Date: Sat, 24 Jan 2009 19:21:28 -0500	[thread overview]
Message-ID: <1232842888-10752-2-git-send-email-dwysocha@redhat.com> (raw)
In-Reply-To: <1232842888-10752-1-git-send-email-dwysocha@redhat.com>

From: Petr Rockai <prockai@redhat.com>

Fri Jan  9 15:38:20 CET 2009  Petr Rockai <me@mornfall.net>
  * Convert vgreduce to use vg_read_for_update.

Remove incorrect unlock_vg() in vgreduce_single() error path.
If dev_get_size() fails we don't have the orphan lock yet so
don't try to unlock.

Add unlock_vg() after vg_read_for_update() error path.
If vg_read_error() fails we need to unlock the orphan vg.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
---
 tools/vgreduce.c |   55 ++++++++++++++++++++---------------------------------
 1 files changed, 21 insertions(+), 34 deletions(-)

diff --git a/tools/vgreduce.c b/tools/vgreduce.c
index 79bf3e0..3742785 100644
--- a/tools/vgreduce.c
+++ b/tools/vgreduce.c
@@ -382,7 +382,6 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
 {
 	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_context *cmd, struct volume_group *vg,
 		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);
 
@@ -418,7 +410,6 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
 
 	if (!dev_get_size(pv_dev(pv), &pv->size)) {
 		log_error("%s: Couldn't get size.", pv_dev_name(pv));
-		unlock_vg(cmd, VG_ORPHANS);
 		return ECMD_FAILED;
 	}
 
@@ -426,9 +417,10 @@ static int _vgreduce_single(struct cmd_context *cmd, struct volume_group *vg,
 	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");
+	orphan_vg = vg_read_for_update(cmd, vg->fid->fmt->orphan_vg_name,
+				       NULL, NONBLOCKING_LOCK | ORPHAN_LOCK);
+
+	if (vg_read_error(orphan_vg)) {
 		unlock_vg(cmd, VG_ORPHANS);
 		return ECMD_FAILED;
 	}
@@ -468,7 +460,6 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv)
 	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 +506,37 @@ int vgreduce(struct cmd_context *cmd, int argc, char **argv)
 	}
 
 	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;
-- 
1.5.5.1



  reply	other threads:[~2009-01-25  0:21 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-22 10:09 [PATCH] Another take on vg_read Petr Rockai
2009-01-22 10:09 ` [PATCH 1/14] Move vg_read out of the way, renaming it to vg_read_internal Petr Rockai
2009-01-22 10:09   ` [PATCH 2/14] Provide _vg_lock_and_read, a new implementation of lock+vg_read_internal Petr Rockai
2009-01-22 10:09     ` [PATCH 3/14] Properly enforce cluster locking in _vg_lock_and_read Petr Rockai
2009-01-22 10:10       ` [PATCH 4/14] Replace implementation of vg_check_status with a call to _vg_check_status Petr Rockai
2009-01-22 10:10         ` [PATCH 5/14] Implement vg_read and vg_read_for_update Petr Rockai
2009-01-22 10:10           ` [PATCH 6/14] Add vg_read_error and vg_might_exist Petr Rockai
2009-01-22 10:10             ` [PATCH 7/14] Convert the straight instances of vg_lock_and_read to new vg_read(_for_update) Petr Rockai
2009-01-22 10:10               ` [PATCH 8/14] Convert vgreduce to use vg_read_for_update Petr Rockai
2009-01-22 10:10                 ` [PATCH 9/14] Convert vgrename to vg_read_for_update Petr Rockai
2009-01-22 10:10                   ` [PATCH 10/14] Convert vgsplit to use vg_read_for_update Petr Rockai
2009-01-22 10:10                     ` [PATCH 11/14] Rework the toollib interface (process_each_*) on top of new vg_read Petr Rockai
2009-01-22 10:10                       ` [PATCH 12/14] Port process_each_pv to " Petr Rockai
2009-01-22 10:10                         ` [PATCH 13/14] Remove now-unused vg_lock_and_read Petr Rockai
2009-01-22 10:10                           ` [PATCH 14/14] Un-export vg_read_internal Petr Rockai
2009-01-26 16:05                             ` Dave Wysochanski
2009-01-22 16:13                         ` [PATCH 12/14] Port process_each_pv to new vg_read Dave Wysochanski
2009-01-24 21:45                 ` [PATCH updated] Convert vgreduce to use vg_read_for_update Dave Wysochanski
2009-01-24 21:46                   ` [PATCH] " Dave Wysochanski
2009-01-25  0:21                     ` [PATCH update2] " Dave Wysochanski
2009-01-25  0:21                       ` Dave Wysochanski [this message]
2009-01-22 18:17       ` [PATCH 3/14] Properly enforce cluster locking in _vg_lock_and_read Dave Wysochanski
2009-01-22 20:15         ` Petr Rockai
2009-02-06 18:21     ` [PATCH 2/14] Provide _vg_lock_and_read, a new implementation of lock+vg_read_internal Dave Wysochanski
2009-01-22 17:36 ` [PATCH] Another take on vg_read Dave Wysochanski
2009-01-22 17:48   ` Petr Rockai
     [not found] <1232619010-4858-9-git-send-email-prockai>
2009-01-24 21:43 ` [PATCH updated] Convert vgreduce to use vg_read_for_update Dave Wysochanski
2009-01-24 21:43   ` [PATCH] " Dave Wysochanski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1232842888-10752-2-git-send-email-dwysocha@redhat.com \
    --to=dwysocha@redhat.com \
    --cc=lvm-devel@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.