libvirt/SOURCES/libvirt-qemu_snapshot-refactor-qemuSnapshotDeleteExternalPrepare.patch
2023-03-29 09:22:19 +00:00

142 lines
5.6 KiB
Diff

From 7289999ecc435bcc65881c64b49efba9746a9571 Mon Sep 17 00:00:00 2001
Message-Id: <7289999ecc435bcc65881c64b49efba9746a9571@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Tue, 21 Feb 2023 16:52:28 +0100
Subject: [PATCH] qemu_snapshot: refactor qemuSnapshotDeleteExternalPrepare
When user creates external snapshot with making only memory snapshot
without any disks deleting that snapshot failed without reporting any
meaningful error.
The issue is that the qemuSnapshotDeleteExternalPrepare function
returns NULL because the returned list is empty. This will not change
so to make it clear if the function fails or not return int instead and
have another parameter where we can pass the list.
With the fixed memory snapshot deletion it will now correctly delete
memory only snapshot as well.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2170826
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
(cherry picked from commit e3957c22462bc52c37c94ca4d6fe3d26f8202119)
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
src/qemu/qemu_snapshot.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index 5cdcbc6290..cfa531edef 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -2301,9 +2301,10 @@ qemuSnapshotFindParentSnapForDisk(virDomainMomentObj *snap,
}
-static GSList*
+static int
qemuSnapshotDeleteExternalPrepare(virDomainObj *vm,
- virDomainMomentObj *snap)
+ virDomainMomentObj *snap,
+ GSList **externalData)
{
ssize_t i;
virDomainSnapshotDef *snapdef = virDomainSnapshotObjGetDef(snap);
@@ -2320,7 +2321,7 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm,
virReportError(VIR_ERR_OPERATION_INVALID,
_("snapshot disk '%s' was target of not completed snapshot delete"),
snapDisk->name);
- return NULL;
+ return -1;
}
data = g_new0(qemuSnapshotDeleteExternalData, 1);
@@ -2328,18 +2329,18 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm,
data->domDisk = qemuDomainDiskByName(vm->def, snapDisk->name);
if (!data->domDisk)
- return NULL;
+ return -1;
data->diskSrc = virStorageSourceChainLookupBySource(data->domDisk->src,
data->snapDisk->src,
&data->prevDiskSrc);
if (!data->diskSrc)
- return NULL;
+ 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 NULL;
+ return -1;
}
data->parentDomDisk = virDomainDiskByTarget(snapdef->parent.dom,
@@ -2348,7 +2349,7 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm,
virReportError(VIR_ERR_OPERATION_FAILED,
_("failed to find disk '%s' in snapshot VM XML"),
snapDisk->name);
- return NULL;
+ return -1;
}
if (virDomainObjIsActive(vm)) {
@@ -2356,13 +2357,13 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm,
if (!virStorageSourceIsBacking(data->parentDiskSrc)) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("failed to find parent disk source in backing chain"));
- return NULL;
+ return -1;
}
if (!virStorageSourceIsSameLocation(data->parentDiskSrc, data->parentDomDisk->src)) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("snapshot VM disk source and parent disk source are not the same"));
- return NULL;
+ return -1;
}
}
@@ -2371,15 +2372,16 @@ qemuSnapshotDeleteExternalPrepare(virDomainObj *vm,
if (data->parentSnap && !virDomainSnapshotIsExternal(data->parentSnap)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
_("deleting external snapshot that has internal snapshot as parent not supported"));
- return NULL;
+ return -1;
}
ret = g_slist_prepend(ret, g_steal_pointer(&data));
}
ret = g_slist_reverse(ret);
+ *externalData = g_steal_pointer(&ret);
- return g_steal_pointer(&ret);
+ return 0;
}
@@ -3159,7 +3161,7 @@ qemuSnapshotDelete(virDomainObj *vm,
g_autoslist(qemuSnapshotDeleteExternalData) tmpData = NULL;
/* this also serves as validation whether the snapshot can be deleted */
- if (!(tmpData = qemuSnapshotDeleteExternalPrepare(vm, snap)))
+ if (qemuSnapshotDeleteExternalPrepare(vm, snap, &tmpData) < 0)
goto endjob;
if (!virDomainObjIsActive(vm)) {
@@ -3174,7 +3176,7 @@ qemuSnapshotDelete(virDomainObj *vm,
/* Call the prepare again as some data require that the VM is
* running to get everything we need. */
- if (!(externalData = qemuSnapshotDeleteExternalPrepare(vm, snap)))
+ if (qemuSnapshotDeleteExternalPrepare(vm, snap, &externalData) < 0)
goto endjob;
} else {
qemuDomainJobPrivate *jobPriv = vm->job->privateData;
--
2.39.1