mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 20:51:26 +00:00
qemu: snapshot: split out preparation of a snapshot with blockdev
Separate the blockdev code since it makes the original function lengthy. Signed-off-by: Peter Krempa <pkrempa@redhat.com> ACKed-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
3e2e627287
commit
8a2c37c4f6
@ -15228,6 +15228,58 @@ qemuDomainSnapshotDiskCleanup(qemuDomainSnapshotDiskDataPtr data,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
qemuDomainSnapshotDiskPrepareOneBlockdev(virQEMUDriverPtr driver,
|
||||||
|
virDomainObjPtr vm,
|
||||||
|
qemuDomainSnapshotDiskDataPtr dd,
|
||||||
|
virQEMUDriverConfigPtr cfg,
|
||||||
|
bool reuse,
|
||||||
|
virHashTablePtr blockNamedNodeData,
|
||||||
|
qemuDomainAsyncJob asyncJob)
|
||||||
|
{
|
||||||
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
|
g_autoptr(virStorageSource) terminator = NULL;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* create a terminator for the snapshot disks so that qemu does not try
|
||||||
|
* to open them at first */
|
||||||
|
if (!(terminator = virStorageSourceNew()))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (qemuDomainPrepareStorageSourceBlockdev(dd->disk, dd->src,
|
||||||
|
priv, cfg) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (!(dd->crdata = qemuBuildStorageSourceChainAttachPrepareBlockdevTop(dd->src,
|
||||||
|
terminator,
|
||||||
|
priv->qemuCaps)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (reuse) {
|
||||||
|
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
rc = qemuBlockStorageSourceAttachApply(qemuDomainGetMonitor(vm),
|
||||||
|
dd->crdata->srcdata[0]);
|
||||||
|
|
||||||
|
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
if (qemuBlockStorageSourceCreateDetectSize(blockNamedNodeData,
|
||||||
|
dd->src, dd->disk->src) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (qemuBlockStorageSourceCreate(vm, dd->src, dd->disk->src,
|
||||||
|
NULL, dd->crdata->srcdata[0],
|
||||||
|
asyncJob) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd->blockdevadded = true;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainSnapshotDiskPrepareOne(virQEMUDriverPtr driver,
|
qemuDomainSnapshotDiskPrepareOne(virQEMUDriverPtr driver,
|
||||||
virDomainObjPtr vm,
|
virDomainObjPtr vm,
|
||||||
@ -15240,12 +15292,9 @@ qemuDomainSnapshotDiskPrepareOne(virQEMUDriverPtr driver,
|
|||||||
bool blockdev,
|
bool blockdev,
|
||||||
qemuDomainAsyncJob asyncJob)
|
qemuDomainAsyncJob asyncJob)
|
||||||
{
|
{
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
|
||||||
virDomainDiskDefPtr persistdisk;
|
virDomainDiskDefPtr persistdisk;
|
||||||
g_autoptr(virStorageSource) terminator = NULL;
|
|
||||||
bool supportsCreate;
|
bool supportsCreate;
|
||||||
bool supportsBacking;
|
bool supportsBacking;
|
||||||
int rc;
|
|
||||||
|
|
||||||
dd->disk = disk;
|
dd->disk = disk;
|
||||||
|
|
||||||
@ -15314,43 +15363,10 @@ qemuDomainSnapshotDiskPrepareOne(virQEMUDriverPtr driver,
|
|||||||
|
|
||||||
dd->prepared = true;
|
dd->prepared = true;
|
||||||
|
|
||||||
if (blockdev) {
|
if (blockdev &&
|
||||||
/* create a terminator for the snapshot disks so that qemu does not try
|
qemuDomainSnapshotDiskPrepareOneBlockdev(driver, vm, dd, cfg, reuse,
|
||||||
* to open them at first */
|
blockNamedNodeData, asyncJob) < 0)
|
||||||
if (!(terminator = virStorageSourceNew()))
|
return -1;
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (qemuDomainPrepareStorageSourceBlockdev(dd->disk, dd->src,
|
|
||||||
priv, cfg) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (!(dd->crdata = qemuBuildStorageSourceChainAttachPrepareBlockdevTop(dd->src,
|
|
||||||
terminator,
|
|
||||||
priv->qemuCaps)))
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (reuse) {
|
|
||||||
if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
rc = qemuBlockStorageSourceAttachApply(qemuDomainGetMonitor(vm),
|
|
||||||
dd->crdata->srcdata[0]);
|
|
||||||
|
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
if (qemuBlockStorageSourceCreateDetectSize(blockNamedNodeData,
|
|
||||||
dd->src, dd->disk->src) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (qemuBlockStorageSourceCreate(vm, dd->src, dd->disk->src,
|
|
||||||
NULL, dd->crdata->srcdata[0],
|
|
||||||
asyncJob) < 0)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
dd->blockdevadded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user