]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: blockjob: Fix locking of block copy/active block commit
authorPeter Krempa <pkrempa@redhat.com>
Fri, 16 Dec 2016 15:06:57 +0000 (16:06 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 10 Jan 2017 18:12:19 +0000 (19:12 +0100)
For the blockjobs, where libvirt is able to track the state internally
we can fix locking of images we can remove the appropriate locks.

Also when doing a pivoting operation we should not acquire the lock on
any of those images since both are actually locked already.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1302168

src/qemu/qemu_blockjob.c
src/qemu/qemu_driver.c

index 83a5a3f7c33907e075267931bbd0dd56aa9a6160..4ada4cd277d420e0f84095e3ce4360336b3ffc6c 100644 (file)
@@ -33,6 +33,7 @@
 #include "virstoragefile.h"
 #include "virthread.h"
 #include "virtime.h"
+#include "locking/domain_lock.h"
 
 #define VIR_FROM_THIS VIR_FROM_QEMU
 
@@ -139,17 +140,19 @@ qemuBlockJobEventProcess(virQEMUDriverPtr driver,
                 }
             }
 
-            /* XXX We want to revoke security labels and disk
-             * lease, as well as audit that revocation, before
-             * dropping the original source.  But it gets tricky
-             * if both source and mirror share common backing
-             * files (we want to only revoke the non-shared
-             * portion of the chain); so for now, we leak the
-             * access to the original.  */
+            /* XXX We want to revoke security labels as well as audit that
+             * revocation, before dropping the original source.  But it gets
+             * tricky if both source and mirror share common backing files (we
+             * want to only revoke the non-shared portion of the chain); so for
+             * now, we leak the access to the original.  */
+            virDomainLockImageDetach(driver->lockManager, vm, disk->src);
             virStorageSourceFree(disk->src);
             disk->src = disk->mirror;
         } else {
-            virStorageSourceFree(disk->mirror);
+            if (disk->mirror) {
+                virDomainLockImageDetach(driver->lockManager, vm, disk->mirror);
+                virStorageSourceFree(disk->mirror);
+            }
         }
 
         /* Recompute the cached backing chain to match our
@@ -172,8 +175,11 @@ qemuBlockJobEventProcess(virQEMUDriverPtr driver,
 
     case VIR_DOMAIN_BLOCK_JOB_FAILED:
     case VIR_DOMAIN_BLOCK_JOB_CANCELED:
-        virStorageSourceFree(disk->mirror);
-        disk->mirror = NULL;
+        if (disk->mirror) {
+            virDomainLockImageDetach(driver->lockManager, vm, disk->mirror);
+            virStorageSourceFree(disk->mirror);
+            disk->mirror = NULL;
+        }
         disk->mirrorState = VIR_DOMAIN_DISK_MIRROR_STATE_NONE;
         disk->mirrorJob = VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN;
         save = true;
index da49088bd007a2903a8aeacf2b064e8f76287707..42f9889651096dbe657990622a4989cea2c239eb 100644 (file)
@@ -16244,9 +16244,7 @@ qemuDomainBlockPivot(virQEMUDriverPtr driver,
 
         if (disk->mirror->format &&
             disk->mirror->format != VIR_STORAGE_FILE_RAW &&
-            (virDomainLockDiskAttach(driver->lockManager, cfg->uri, vm,
-                                     disk) < 0 ||
-             qemuDomainNamespaceSetupDisk(driver, vm, disk) < 0 ||
+            (qemuDomainNamespaceSetupDisk(driver, vm, disk) < 0 ||
              qemuSetupDiskCgroup(vm, disk) < 0 ||
              qemuSecuritySetDiskLabel(driver, vm, disk) < 0))
             goto cleanup;