Skip to contentSkip to conversation

master - metadata: Fix unlock on VG recovery error path.

PATCH Alasdair Kergon 1 participant 1 message Apr 18, 2014

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=17e304e0ac24ba0d1887badfb51afa731aa138e9
Commit:        17e304e0ac24ba0d1887badfb51afa731aa138e9
Parent:        177ece01a9b67c60818049084555a877f9e236e0
Author:        Alasdair G Kergon <[email protected]>
AuthorDate:    Fri Apr 18 02:27:16 2014 +0100
Committer:     Alasdair G Kergon <[email protected]>
CommitterDate: Fri Apr 18 02:27:16 2014 +0100

metadata: Fix unlock on VG recovery error path.

If lock conversion failed it tried to unlock VG that was no longer locked.

---
 WHATS_NEW               |    1 +
 lib/metadata/metadata.c |   11 +++++++++--
 2 files changed, 10 insertions(+), 2 deletions(-)
WHATS_NEW +1 -0
index 62f0959..ac18601 100644
@@ -1,5 +1,6 @@
 Version 2.02.107 - 
 ==================================
+  Fix _recover_vg() error path when lock conversion fails.
   Use X for LV attributes that are unknown when activation disabled.
   Only output lvdisplay 'LV Status' field when activation is enabled.
   Use lvmetad_used() in pvscan instead of config_tree.
lib/metadata/metadata.c +9 -2
index 643613f..6bc7e3a 100644
@@ -4105,6 +4105,9 @@ int vg_check_status(const struct volume_group *vg, uint64_t status)
 	return !_vg_bad_status_bits(vg, status);
 }
 
+/*
+ * VG is left unlocked on failure
+ */
 static struct volume_group *_recover_vg(struct cmd_context *cmd,
 			 const char *vg_name, const char *vgid)
 {
@@ -4118,11 +4121,14 @@ static struct volume_group *_recover_vg(struct cmd_context *cmd,
 	if (!lock_vol(cmd, vg_name, LCK_VG_WRITE, NULL))
 		return_NULL;
 
-	if (!(vg = vg_read_internal(cmd, vg_name, vgid, 1, &consistent)))
+	if (!(vg = vg_read_internal(cmd, vg_name, vgid, 1, &consistent))) {
+		unlock_vg(cmd, vg_name);
 		return_NULL;
+	}
 
 	if (!consistent) {
 		release_vg(vg);
+		unlock_vg(cmd, vg_name);
 		return_NULL;
 	}
 
@@ -4202,7 +4208,7 @@ static struct volume_group *_vg_lock_and_read(struct cmd_context *cmd, const cha
 			log_error("Recovery of volume group \"%s\" failed.",
 				  vg_name);
 			failure |= FAILED_INCONSISTENT;
-			goto bad;
+			goto bad_no_unlock;
 		}
 	}
 
@@ -4237,6 +4243,7 @@ bad:
 	if (!already_locked && !(misc_flags & READ_WITHOUT_LOCK))
 		unlock_vg(cmd, vg_name);
 
+bad_no_unlock:
 	return _vg_make_handle(cmd, vg, failure);
 }