public inbox for lvm2-cvs@sourceware.org
help / color / mirror / Atom feed
From: wysochanski@sourceware.org
To: lvm-devel@redhat.com, lvm2-cvs@sourceware.org
Subject: LVM2/tools vgrename.c
Date: Wed, 02 Sep 2009 21:29:00 -0000	[thread overview]
Message-ID: <20090902212940.13777.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/lvm2
Module name:	LVM2
Changes by:	wysochanski@sourceware.org	2009-09-02 21:29:40

Modified files:
	tools          : vgrename.c 

Log message:
	Update vgrename to take into account vgname lock ordering.
	
	Should be no functional change.
	
	Author: Dave Wysochanski <dwysocha@redhat.com>

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/tools/vgrename.c.diff?cvsroot=lvm2&r1=1.66&r2=1.67

--- LVM2/tools/vgrename.c	2009/09/02 21:29:23	1.66
+++ LVM2/tools/vgrename.c	2009/09/02 21:29:40	1.67
@@ -74,7 +74,7 @@
 	const char *vgid = NULL, *vg_name, *vg_name_old;
 	char old_path[NAME_LEN], new_path[NAME_LEN];
 	struct volume_group *vg = NULL;
-	uint32_t rc;
+	int lock_vg_old_first = 1;
 
 	vg_name_old = skip_dev_dir(cmd, old_vg_path, NULL);
 	vg_name_new = skip_dev_dir(cmd, new_vg_path, NULL);
@@ -116,13 +116,26 @@
 	} else
 		vgid = NULL;
 
-	vg = vg_rename_old(cmd, vg_name_old, vgid);
-	if (!vg)
-		return 0;
+	if (strcmp(vg_name_new, vg_name_old) < 0)
+		lock_vg_old_first = 0;
 
-	if (!vg_rename_new(cmd, vg_name_new)) {
-		unlock_and_release_vg(cmd, vg, vg_name_old);
-		return 0;
+	if (lock_vg_old_first) {
+		vg = vg_rename_old(cmd, vg_name_old, vgid);
+		if (!vg)
+			return 0;
+
+		if (!vg_rename_new(cmd, vg_name_new)) {
+			unlock_and_release_vg(cmd, vg, vg_name_old);
+			return 0;
+		}
+	} else {
+		if (!vg_rename_new(cmd, vg_name_new)) {
+			return 0;
+		}
+
+		vg = vg_rename_old(cmd, vg_name_old, vgid);
+		if (!vg)
+			return 0;
 	}
 
 	if (!archive(vg))
@@ -176,8 +189,13 @@
 	return 1;
 
       error:
-	unlock_vg(cmd, vg_name_new);
-	unlock_and_release_vg(cmd, vg, vg_name_old);
+	if (lock_vg_old_first) {
+		unlock_vg(cmd, vg_name_new);
+		unlock_and_release_vg(cmd, vg, vg_name_old);
+	} else {
+		unlock_and_release_vg(cmd, vg, vg_name_old);
+		unlock_vg(cmd, vg_name_new);
+	}
 	return 0;
 }
 


             reply	other threads:[~2009-09-02 21:29 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-02 21:29 wysochanski [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-09-02 21:29 wysochanski
2009-07-01 17:02 wysochanski
2009-06-09 14:30 wysochanski
2008-06-06 16:13 agk
2007-08-31 19:09 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=20090902212940.13777.qmail@sourceware.org \
    --to=wysochanski@sourceware.org \
    --cc=lvm-devel@redhat.com \
    --cc=lvm2-cvs@sourceware.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).