]> sourceware.org Git - lvm2.git/commitdiff
Revert previous patch that moved VG_ORPHAN lock inside vg_extend.
authorDave Wysochanski <dwysocha@redhat.com>
Fri, 24 Jul 2009 15:01:43 +0000 (15:01 +0000)
committerDave Wysochanski <dwysocha@redhat.com>
Fri, 24 Jul 2009 15:01:43 +0000 (15:01 +0000)
We must hold the VG_ORPHAN lock until we commit to disk.  Otherwise,
we risk a race condition on vgcreate / vgextend.  Reverts the following
commit:

commit 72a41480ba66d7dc2d05ef8583080b6b08208507
Author: Dave Wysochanski <dwysocha@redhat.com>
Date:   Fri Jul 10 20:09:21 2009 +0000

    Move orphan lock obtain/release inside vg_extend().

    With this change we now have vgcreate/vgextend liblvm functions.
    Note that this changes the lock order of the following functions as the
    orphan lock is now obtained first.  With our policy of non-blocking
    second locks, this should not be a problem.

Signed-off-by: Dave Wysochanski <dwysocha@redhat.com>
WHATS_NEW
lib/metadata/metadata.c
tools/vgcreate.c
tools/vgextend.c

index 217c1adc0e50f9514eb70a5d2f79b876d6d1d490..9a36f32b520221741c724bc8d011191b25a51c78 100644 (file)
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,7 @@
 Version 2.02.50 - 
 ================================
+  Fix race condition with vgcreate and vgextend on same device (2.02.49).
+  Remove redundant validate_name call from vgreduce.
   Add lvm_{pv|vg|lv}_get_{name|uuid} liblvm functions.
   Add lvm_vg_list_pvs and lvm_vg_list_lvs liblvm functions.
   Remove unused handles lvseg, pvseg inside liblvm/lvm.h.
index 03e0810b64209af269df929cc60c382b6ab779cd..62a0291c88927d7fbce4a32c6812f991f3e8df6e 100644 (file)
@@ -518,11 +518,6 @@ int vg_extend(struct volume_group *vg, int pv_count, char **pv_names)
        if (_vg_bad_status_bits(vg, RESIZEABLE_VG))
                return 0;
 
-       if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
-               log_error("Can't get lock for orphan PVs");
-               return 0;
-       }
-
        /* attach each pv */
        for (i = 0; i < pv_count; i++) {
                if (!(pv = pv_by_path(vg->fid->fmt->cmd, pv_names[i]))) {
@@ -536,13 +531,11 @@ int vg_extend(struct volume_group *vg, int pv_count, char **pv_names)
 
 /* FIXME Decide whether to initialise and add new mdahs to format instance */
 
-       unlock_vg(cmd, VG_ORPHANS);
        return 1;
 
       bad:
        log_error("Unable to add physical volume '%s' to "
                  "volume group '%s'.", pv_names[i], vg->name);
-       unlock_vg(cmd, VG_ORPHANS);
        return 0;
 }
 
index c41c50f6006e4d92b93a273c96497d215cab5fac..dff3a5d134e90c166f283ab365bd788ea5db6484 100644 (file)
@@ -57,6 +57,11 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
            !vg_set_alloc_policy(vg, vp_new.alloc))
                goto_bad;
 
+       if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
+               log_error("Can't get lock for orphan PVs");
+               goto bad_orphan;
+       }
+
        /* attach the pv's */
        if (!vg_extend(vg, argc - 1, argv + 1))
                goto_bad;
@@ -106,6 +111,7 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
                goto bad;
        }
 
+       unlock_vg(cmd, VG_ORPHANS);
        unlock_vg(cmd, vp_new.vg_name);
 
        backup(vg);
@@ -117,6 +123,8 @@ int vgcreate(struct cmd_context *cmd, int argc, char **argv)
        return ECMD_PROCESSED;
 
 bad:
+       unlock_vg(cmd, VG_ORPHANS);
+bad_orphan:
        vg_release(vg);
        unlock_vg(cmd, vp_new.vg_name);
        return ECMD_FAILED;
index 1dfbc116f3fe47ea3ff69b3f0f882eafec4cb642..37f4dba9633bead2aba52d7d0dcc63b7d6bbd3c5 100644 (file)
@@ -42,6 +42,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
                vg_release(vg);
                return ECMD_FAILED;
        }
+
 /********** FIXME
        log_print("maximum logical volume size is %s",
                  (dummy = lvm_show_size(LVM_LV_SIZE_MAX(vg) / 2, LONG)));
@@ -52,6 +53,11 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
        if (!archive(vg))
                goto error;
 
+       if (!lock_vol(cmd, VG_ORPHANS, LCK_VG_WRITE)) {
+               log_error("Can't get lock for orphan PVs");
+               return ECMD_FAILED;
+       }
+
        /* extend vg */
        if (!vg_extend(vg, argc, argv))
                goto error;
@@ -69,6 +75,7 @@ int vgextend(struct cmd_context *cmd, int argc, char **argv)
        r = ECMD_PROCESSED;
 
 error:
+       unlock_vg(cmd, VG_ORPHANS);
        unlock_and_release_vg(cmd, vg, vg_name);
        return r;
 }
This page took 0.049511 seconds and 5 git commands to generate.