libvirt/SOURCES/libvirt-qemu_snapshot-create-refactor-external-snapshot-detection.patch

89 lines
3.3 KiB
Diff

From b12f3837ddde95373b39843b8526b55e40d96500 Mon Sep 17 00:00:00 2001
Message-ID: <b12f3837ddde95373b39843b8526b55e40d96500.1707394627.git.jdenemar@redhat.com>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Tue, 30 Jan 2024 11:33:23 +0100
Subject: [PATCH] qemu_snapshot: create: refactor external snapshot detection
Introduce new function qemuSnapshotCreateUseExternal() that will return
true if we will use external snapshots as default location.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
(cherry picked from commit faa2e3bb541e50d719d05e58a129b4443c0c737c)
Resolves: https://issues.redhat.com/browse/RHEL-22797
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
---
src/qemu/qemu_snapshot.c | 39 ++++++++++++++++++++++++++++++---------
1 file changed, 30 insertions(+), 9 deletions(-)
diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index af5f995b0d..871e63c9cd 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -1576,6 +1576,25 @@ qemuSnapshotCreateXMLValidateDef(virDomainObj *vm,
}
+/**
+ * Check if libvirt should use external snapshots as default align_location
+ * that will be used by virDomainSnapshotAlignDisks(). Otherwise we default
+ * to internal snapshots.
+ */
+static bool
+qemuSnapshotCreateUseExternal(virDomainSnapshotDef *def,
+ unsigned int flags)
+{
+ if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY)
+ return true;
+
+ if (def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL)
+ return true;
+
+ return false;
+}
+
+
static int
qemuSnapshotCreateAlignDisks(virDomainObj *vm,
virDomainSnapshotDef *def,
@@ -1584,7 +1603,7 @@ qemuSnapshotCreateAlignDisks(virDomainObj *vm,
{
g_autofree char *xml = NULL;
qemuDomainObjPrivate *priv = vm->privateData;
- virDomainSnapshotLocation align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
+ virDomainSnapshotLocation align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_DEFAULT;
/* Easiest way to clone inactive portion of vm->def is via
* conversion in and back out of xml. */
@@ -1604,17 +1623,19 @@ qemuSnapshotCreateAlignDisks(virDomainObj *vm,
return -1;
}
- if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) {
+ if (qemuSnapshotCreateUseExternal(def, flags)) {
align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
- if (virDomainObjIsActive(vm))
- def->state = VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT;
- else
- def->state = VIR_DOMAIN_SNAPSHOT_SHUTOFF;
- def->memory = VIR_DOMAIN_SNAPSHOT_LOCATION_NO;
- } else if (def->memory == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
def->state = virDomainObjGetState(vm, NULL);
- align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL;
+
+ if (flags & VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY) {
+ if (virDomainObjIsActive(vm))
+ def->state = VIR_DOMAIN_SNAPSHOT_DISK_SNAPSHOT;
+ else
+ def->state = VIR_DOMAIN_SNAPSHOT_SHUTOFF;
+ def->memory = VIR_DOMAIN_SNAPSHOT_LOCATION_NO;
+ }
} else {
+ align_location = VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL;
def->state = virDomainObjGetState(vm, NULL);
if (virDomainObjIsActive(vm) &&
--
2.43.0