In some cases such as when creating an internal inactive snapshot we
know that the domain definition in the snapshot is equivalent to the
current definition. Additionally we set up the current definition for
the snapshotting but not the one contained in the snapshot. Thus in some
cases the caller knows better which def to use.
Make qemuDomainSnapshotForEachQcow2 take the definition by the caller
and copy the logic for selecting the definition to callers where we
don't know for sure that the above claim applies.
This fixes internal inactive snapshots when <disk type='volume'> is used
as we translate the pool/vol combo only in the current def.
Resolves:
https://gitlab.com/libvirt/libvirt/-/issues/97
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_domain.c | 22 +++++++++++-----------
src/qemu/qemu_domain.h | 2 +-
src/qemu/qemu_snapshot.c | 16 +++++++++++++---
3 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c782810839..663c0af867 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -6560,18 +6560,11 @@ qemuDomainSnapshotForEachQcow2Raw(virQEMUDriverPtr driver,
* failure, 1 if we skipped a disk due to try_all. */
int
qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
+ virDomainDefPtr def,
virDomainMomentObjPtr snap,
const char *op,
bool try_all)
{
- /* Prefer action on the disks in use at the time the snapshot was
- * created; but fall back to current definition if dealing with a
- * snapshot created prior to libvirt 0.9.5. */
- virDomainDefPtr def = snap->def->dom;
-
- if (!def)
- def = vm->def;
return qemuDomainSnapshotForEachQcow2Raw(driver, def, snap->def->name,
op, try_all, def->ndisks);
}
@@ -6592,9 +6585,16 @@ qemuDomainSnapshotDiscard(virQEMUDriverPtr driver,
if (!metadata_only) {
if (!virDomainObjIsActive(vm)) {
/* Ignore any skipped disks */
- if (qemuDomainSnapshotForEachQcow2(driver, vm, snap, "-d",
- true) < 0)
- return -1;
+
+ /* Prefer action on the disks in use at the time the snapshot was
+ * created; but fall back to current definition if dealing with a
+ * snapshot created prior to libvirt 0.9.5. */
+ virDomainDefPtr def = snap->def->dom;
+
+ if (!def)
+ def = vm->def;
+
+ return qemuDomainSnapshotForEachQcow2(driver, def, snap, "-d",
true);
} else {
priv = vm->privateData;
qemuDomainObjEnterMonitor(driver, vm);
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 6b75b828c0..010bae285d 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -613,7 +613,7 @@ int qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
const char *snapshotDir);
int qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
+ virDomainDefPtr def,
virDomainMomentObjPtr snap,
const char *op,
bool try_all);
diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index 057b94e5b8..1c58ac8acf 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -138,7 +138,7 @@ qemuSnapshotCreateInactiveInternal(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainMomentObjPtr snap)
{
- return qemuDomainSnapshotForEachQcow2(driver, vm, snap, "-c", false);
+ return qemuDomainSnapshotForEachQcow2(driver, vm->def, snap, "-c",
false);
}
@@ -1813,9 +1813,19 @@ qemuSnapshotRevertInactive(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainMomentObjPtr snap)
{
+ /* Prefer action on the disks in use at the time the snapshot was
+ * created; but fall back to current definition if dealing with a
+ * snapshot created prior to libvirt 0.9.5. */
+ virDomainDefPtr def = snap->def->dom;
+
+ if (!def)
+ def = vm->def;
+
/* Try all disks, but report failure if we skipped any. */
- int ret = qemuDomainSnapshotForEachQcow2(driver, vm, snap, "-a", true);
- return ret > 0 ? -1 : ret;
+ if (qemuDomainSnapshotForEachQcow2(driver, def, snap, "-a", true) != 0)
+ return -1;
+
+ return 0;
}
--
2.28.0