mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-05 22:05:47 +00:00
qemu_snapshot: introduce qemuSnapshotDomainDefUpdateDisk
Extract the code that updates disks in domain definition while creating external snapshots. We will use it later in the external snapshot revert code. Signed-off-by: Pavel Hrdina <phrdina@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
8f9d96199d
commit
4edd9e297a
@ -142,6 +142,42 @@ qemuSnapshotFSThaw(virDomainObj *vm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuSnapshotDomainDefUpdateDisk(virDomainDef *domdef,
|
||||||
|
virDomainSnapshotDef *snapdef,
|
||||||
|
bool reuse)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < snapdef->ndisks; i++) {
|
||||||
|
g_autoptr(virStorageSource) newsrc = NULL;
|
||||||
|
virDomainSnapshotDiskDef *snapdisk = &(snapdef->disks[i]);
|
||||||
|
virDomainDiskDef *defdisk = domdef->disks[i];
|
||||||
|
|
||||||
|
if (snapdisk->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!(newsrc = virStorageSourceCopy(snapdisk->src, false)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (virStorageSourceInitChainElement(newsrc, defdisk->src, false) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!reuse &&
|
||||||
|
virStorageSourceHasBacking(defdisk->src)) {
|
||||||
|
defdisk->src->readonly = true;
|
||||||
|
newsrc->backingStore = g_steal_pointer(&defdisk->src);
|
||||||
|
} else {
|
||||||
|
virObjectUnref(defdisk->src);
|
||||||
|
}
|
||||||
|
|
||||||
|
defdisk->src = g_steal_pointer(&newsrc);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* The domain is expected to be locked and inactive. */
|
/* The domain is expected to be locked and inactive. */
|
||||||
static int
|
static int
|
||||||
qemuSnapshotCreateInactiveInternal(virQEMUDriver *driver,
|
qemuSnapshotCreateInactiveInternal(virQEMUDriver *driver,
|
||||||
@ -216,32 +252,9 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriver *driver,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* update disk definitions */
|
/* update disk definitions */
|
||||||
for (i = 0; i < snapdef->ndisks; i++) {
|
if (qemuSnapshotDomainDefUpdateDisk(vm->def, snapdef, reuse) < 0)
|
||||||
g_autoptr(virStorageSource) newsrc = NULL;
|
|
||||||
|
|
||||||
snapdisk = &(snapdef->disks[i]);
|
|
||||||
defdisk = vm->def->disks[i];
|
|
||||||
|
|
||||||
if (snapdisk->snapshot != VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (!(newsrc = virStorageSourceCopy(snapdisk->src, false)))
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virStorageSourceInitChainElement(newsrc, defdisk->src, false) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
if (!reuse &&
|
|
||||||
virStorageSourceHasBacking(defdisk->src)) {
|
|
||||||
defdisk->src->readonly = true;
|
|
||||||
newsrc->backingStore = g_steal_pointer(&defdisk->src);
|
|
||||||
} else {
|
|
||||||
virObjectUnref(defdisk->src);
|
|
||||||
}
|
|
||||||
|
|
||||||
defdisk->src = g_steal_pointer(&newsrc);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virDomainDefSave(vm->def, driver->xmlopt, cfg->configDir) < 0)
|
if (virDomainDefSave(vm->def, driver->xmlopt, cfg->configDir) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user