[libvirt PATCH 2/3] qemu_snapshot: fix external snapshot deletion for non-active snapshots

Pavel Hrdina phrdina at redhat.com
Wed Mar 8 13:29:21 UTC 2023


For shutoff VMs we don't have the storage source backing chain
populated so it will fail this check and error out. Move it to
part that is done only when VM is running.

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

diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index 7207b5879a..7aa4195f04 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -2331,18 +2331,6 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm,
         if (!data->domDisk)
             return -1;
 
-        data->diskSrc = virStorageSourceChainLookupBySource(data->domDisk->src,
-                                                            data->snapDisk->src,
-                                                            &data->prevDiskSrc);
-        if (!data->diskSrc)
-            return -1;
-
-        if (!virStorageSourceIsSameLocation(data->diskSrc, data->snapDisk->src)) {
-            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
-                           _("VM disk source and snapshot disk source are not the same"));
-            return -1;
-        }
-
         data->parentDomDisk = virDomainDiskByTarget(snapdef->parent.dom,
                                                     data->snapDisk->name);
         if (!data->parentDomDisk) {
@@ -2353,6 +2341,18 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm,
         }
 
         if (virDomainObjIsActive(vm)) {
+            data->diskSrc = virStorageSourceChainLookupBySource(data->domDisk->src,
+                                                                data->snapDisk->src,
+                                                                &data->prevDiskSrc);
+            if (!data->diskSrc)
+                return -1;
+
+            if (!virStorageSourceIsSameLocation(data->diskSrc, data->snapDisk->src)) {
+                virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                               _("VM disk source and snapshot disk source are not the same"));
+                return -1;
+            }
+
             data->parentDiskSrc = data->diskSrc->backingStore;
             if (!virStorageSourceIsBacking(data->parentDiskSrc)) {
                 virReportError(VIR_ERR_OPERATION_FAILED, "%s",
-- 
2.39.2



More information about the libvir-list mailing list