The inactive external snapshot code replaced the file name in the
virStorageSource but did not touch the backing files. This meant that
after an inactive snapshot the backing chain recorded in the inactive
XML (which is used with -blockdev) would be incorrect.
Fix it by adding a new layer if there is an existing chain and replacing
the virStorageSource struct fully when there is no chain.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_driver.c | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index c969a3d463..c1b404adfa 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -14613,19 +14613,32 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr
driver,
/* update disk definitions */
for (i = 0; i < snapdef->ndisks; i++) {
+ g_autoptr(virStorageSource) newsrc = NULL;
+
snapdisk = &(snapdef->disks[i]);
defdisk = vm->def->disks[snapdisk->idx];
- if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) {
- VIR_FREE(defdisk->src->path);
- defdisk->src->path = g_strdup(snapdisk->src->path);
- defdisk->src->format = snapdisk->src->format;
+ if (snapdisk->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL)
+ continue;
- if (virDomainSaveConfig(cfg->configDir, driver->caps, vm->def) <
0)
- goto cleanup;
+ if (!(newsrc = virStorageSourceCopy(snapdisk->src, false)))
+ goto cleanup;
+
+ if (virStorageSourceInitChainElement(newsrc, defdisk->src, false) < 0)
+ goto cleanup;
+
+ if (virStorageSourceHasBacking(defdisk->src)) {
+ newsrc->backingStore = g_steal_pointer(&defdisk->src);
+ } else {
+ virObjectUnref(defdisk->src);
}
+
+ defdisk->src = g_steal_pointer(&newsrc);
}
+ if (virDomainSaveConfig(cfg->configDir, driver->caps, vm->def) < 0)
+ goto cleanup;
+
ret = 0;
cleanup:
--
2.23.0