]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: snapshot: Fix image lock handling when taking a snapshot
authorPeter Krempa <pkrempa@redhat.com>
Wed, 28 Aug 2019 07:30:33 +0000 (09:30 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 6 Sep 2019 06:12:21 +0000 (08:12 +0200)
When we take a snapshot we must properly remove our locking
infrastructure locks. This was broken by commit 3817fa10c4ad9 which
attempted to properly track the readonly state for the image as the
locking code was executed after this change. Since we forced the image
which was locked as read-write to read-only prior to unlocking it the
write lock was not dropped.

Fix it by moving the locking code prior to modifying the readonly flag.

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

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_driver.c

index b862f727b73d3da6958c5be1eea92d6374e9bedc..c4b32a73a5b065c149091257bbd69ee908db4476 100644 (file)
@@ -15435,6 +15435,13 @@ qemuDomainSnapshotUpdateDiskSources(virQEMUDriverPtr driver,
     if (qemuSecurityMoveImageMetadata(driver, vm, dd->disk->src, dd->src) < 0)
         VIR_WARN("Unable to move disk metadata on vm %s", vm->def->name);
 
+    /* unlock the write lock on the original image as qemu will no longer write to it */
+    virDomainLockImageDetach(driver->lockManager, vm, dd->disk->src);
+
+    /* unlock also the new image if the VM is paused to follow the locking semantics */
+    if (virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING)
+        virDomainLockImageDetach(driver->lockManager, vm, dd->src);
+
     /* the old disk image is now readonly */
     dd->disk->src->readonly = true;
 
@@ -15553,23 +15560,8 @@ qemuDomainSnapshotCreateDiskActive(virQEMUDriverPtr driver,
     ret = 0;
 
  cleanup:
-    if (ret < 0) {
+    if (ret < 0)
         virErrorPreserveLast(&orig_err);
-    } else {
-        /* on successful snapshot we need to remove locks from the now-old
-         * disks and if the VM is paused release locks on the images since qemu
-         * stopped using them*/
-        bool paused = virDomainObjGetState(vm, NULL) != VIR_DOMAIN_RUNNING;
-
-        for (i = 0; i < ndiskdata; i++) {
-            if (paused)
-                virDomainLockImageDetach(driver->lockManager, vm,
-                                         diskdata[i].disk->src);
-
-            virDomainLockImageDetach(driver->lockManager, vm,
-                                     diskdata[i].disk->src->backingStore);
-        }
-    }
 
     if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0 ||
         (vm->newDef && virDomainSaveConfig(cfg->configDir, driver->caps,