qemu: snapshot: Fix inactive external snapshots when backing chain is present

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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2019-11-12 17:37:36 +01:00
parent b036834eae
commit f6cccece48

View File

@ -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: