[libvirt PATCH 21/30] qemu_snapshot: error out when deleting internal snapshot on non-active disk

Pavel Hrdina phrdina at redhat.com
Thu Dec 8 13:30:57 UTC 2022


Deleting internal snapshot when the currently active disk image is
different then where the internal snapshot was taken doesn't work
correctly.

This applies to a running VM only as we are using QMP command and
talking to the QEMU process that is using different disk.

This works correctly when the VM is shut of as in this case we spawn
qemu-img process to delete the snapshot.

Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
---
 src/qemu/qemu_snapshot.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index a4b45d3ba3..adcd4eb73a 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -2495,9 +2495,30 @@ qemuSnapshotCountExternalInternal(void *payload,
 
 
 static int
-qemuSnapshotDeleteValidate(virDomainMomentObj *snap,
+qemuSnapshotDeleteValidate(virDomainObj *vm,
+                           virDomainMomentObj *snap,
                            unsigned int flags)
 {
+    if (!virDomainSnapshotIsExternal(snap) &&
+        virDomainObjIsActive(vm)) {
+        ssize_t i;
+        virDomainSnapshotDef *snapdef = virDomainSnapshotObjGetDef(snap);
+
+        for (i = 0; i < snapdef->ndisks; i++) {
+            virDomainSnapshotDiskDef *snapDisk = &(snapdef->disks[i]);
+            virDomainDiskDef *vmdisk = NULL;
+            virDomainDiskDef *disk = NULL;
+
+            vmdisk = qemuDomainDiskByName(vm->def, snapDisk->name);
+            disk = qemuDomainDiskByName(snapdef->parent.dom, snapDisk->name);
+
+            if (!virStorageSourceIsSameLocation(vmdisk->src, disk->src)) {
+                virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                               _("deleting internal snapshot for non-active disk is not supported"));
+                return -1;
+            }
+        }
+    }
 
     if (flags & (VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN |
                  VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY)) {
@@ -2551,7 +2572,7 @@ qemuSnapshotDelete(virDomainObj *vm,
         goto endjob;
 
     if (!metadata_only) {
-        if (qemuSnapshotDeleteValidate(snap, flags) < 0)
+        if (qemuSnapshotDeleteValidate(vm, snap, flags) < 0)
             goto endjob;
     }
 
-- 
2.38.1



More information about the libvir-list mailing list