]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuSnapshotCreateActiveExternal: Don't unlink memory snapshot image if it was existi...
authorPeter Krempa <pkrempa@redhat.com>
Wed, 16 Jun 2021 14:56:56 +0000 (16:56 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 18 Jun 2021 07:16:16 +0000 (09:16 +0200)
When writing the memory snapshot into an existing file don't remove it
if the snapshot fails later.

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

index 99fc4b836f35af217b1277ba23672d7e5bbe2ceb..4e74ddd7f86c5bde3733f477a8f8bec970ae9c0d 100644 (file)
@@ -1356,6 +1356,7 @@ qemuSnapshotCreateActiveExternal(virQEMUDriver *driver,
     virDomainSnapshotDef *snapdef = virDomainSnapshotObjGetDef(snap);
     bool memory = snapdef->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
     bool memory_unlink = false;
+    bool memory_existing = false;
     bool thaw = false;
     bool pmsuspended = false;
     int compressed;
@@ -1451,13 +1452,16 @@ qemuSnapshotCreateActiveExternal(virQEMUDriver *driver,
             goto cleanup;
         xml = NULL;
 
+        memory_existing = virFileExists(snapdef->memorysnapshotfile);
+
         if ((ret = qemuSaveImageCreate(driver, vm, snapdef->memorysnapshotfile,
                                        data, compressor, 0,
                                        QEMU_ASYNC_JOB_SNAPSHOT)) < 0)
             goto cleanup;
 
         /* the memory image was created, remove it on errors */
-        memory_unlink = true;
+        if (!memory_existing)
+            memory_unlink = true;
 
         /* forbid any further manipulation */
         qemuDomainObjSetAsyncJobMask(vm, QEMU_JOB_DEFAULT_MASK);