]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_snapshot: fix reverting to inactive snapshot
authorPavel Hrdina <phrdina@redhat.com>
Wed, 1 Nov 2023 13:01:32 +0000 (14:01 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Thu, 16 Nov 2023 14:29:45 +0000 (15:29 +0100)
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 <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
src/qemu/qemu_snapshot.c

index ee06e72b11693624f8dada58c44b85da3d5f916d..73ff5338279516f27153857013c0c7fcaabd6b36 100644 (file)
@@ -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;
 }