qemu: snapshot: Fix image lock handling when taking a snapshot

When we take a snapshot we must properly remove our locking
infrastructure locks. This was broken by commit 3817fa10c4 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>
This commit is contained in:
Peter Krempa 2019-08-28 09:30:33 +02:00
parent 805b4aa2e9
commit e0720fda12

View 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,