From: Pavel Hrdina Date: Wed, 1 Nov 2023 13:01:32 +0000 (+0100) Subject: qemu_snapshot: fix reverting to inactive snapshot X-Git-Tag: v9.10.0-rc1~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ad5817053aa779c9536a624f260774b7afb64f6;p=thirdparty%2Flibvirt.git qemu_snapshot: fix reverting to inactive snapshot When reverting to inactive snapshot updating the domain definition needs to happen after the new overlays are created otherwise qemu-img will correctly fail with error: Trying to create an image with the same filename as the backing file Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index ee06e72b11..73ff533827 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2157,13 +2157,20 @@ qemuSnapshotRevertExternalInactive(virDomainObj *vm, { virQEMUDriver *driver = QEMU_DOMAIN_PRIVATE(vm)->driver; g_autoptr(virBitmap) created = NULL; + int ret = -1; created = virBitmapNew(tmpsnapdef->ndisks); + if (qemuSnapshotCreateQcow2Files(driver, domdef, tmpsnapdef, created) < 0) + goto cleanup; + if (qemuSnapshotDomainDefUpdateDisk(domdef, tmpsnapdef, false) < 0) - return -1; + goto cleanup; + + ret = 0; - if (qemuSnapshotCreateQcow2Files(driver, domdef, tmpsnapdef, created) < 0) { + cleanup: + if (ret < 0 && created) { ssize_t bit = -1; virErrorPtr err = NULL; @@ -2180,11 +2187,9 @@ qemuSnapshotRevertExternalInactive(virDomainObj *vm, } virErrorRestore(&err); - - return -1; } - return 0; + return ret; }