[PATCH 7/7] qemuSnapshotCreateActiveExternal: Don't unlink memory snapshot image if it was existing before

Peter Krempa pkrempa at redhat.com
Wed Jun 16 15:05:37 UTC 2021


When writing the memory snapshot into an existing file don't remove it
if the snapshot fails later.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/qemu/qemu_snapshot.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index 99fc4b836f..4e74ddd7f8 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -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);
-- 
2.31.1




More information about the libvir-list mailing list