mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
qemu: Refactor variables for extracting flags in qemuDomainBlockCopyCommon
Add separate booleans for extracting VIR_DOMAIN_BLOCK_COPY_REUSE_EXT and VIR_DOMAIN_BLOCK_COPY_SHALLOW from '@flags' and also change 'reuse' into 'existing'. qemuMonitorDriveMirror requires the unmodified state of the flags to pass to qemu and also we use the value a few times internally. Extract it separately now. The 'reuse' flag did not indicate reusing of the file as much as the fact that the storage is existing and thus should not be created, so modify the name to reflect this. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
0db5912617
commit
16ca234b56
@ -17516,7 +17516,9 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
|
|||||||
bool need_unlink = false;
|
bool need_unlink = false;
|
||||||
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
|
VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg = virQEMUDriverGetConfig(driver);
|
||||||
const char *format = NULL;
|
const char *format = NULL;
|
||||||
bool reuse = !!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT);
|
bool mirror_reuse = !!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT);
|
||||||
|
bool mirror_shallow = !!(flags & VIR_DOMAIN_BLOCK_COPY_SHALLOW);
|
||||||
|
bool existing = mirror_reuse;
|
||||||
qemuBlockJobDataPtr job = NULL;
|
qemuBlockJobDataPtr job = NULL;
|
||||||
VIR_AUTOUNREF(virStorageSourcePtr) mirror = mirrorsrc;
|
VIR_AUTOUNREF(virStorageSourcePtr) mirror = mirrorsrc;
|
||||||
bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
|
bool blockdev = virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV);
|
||||||
@ -17580,8 +17582,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
|
|||||||
|
|
||||||
/* unless the user provides a pre-created file, shallow copy into a raw
|
/* unless the user provides a pre-created file, shallow copy into a raw
|
||||||
* file is not possible */
|
* file is not possible */
|
||||||
if ((flags & VIR_DOMAIN_BLOCK_COPY_SHALLOW) && !reuse &&
|
if (mirror_shallow && !existing && mirror->format == VIR_STORAGE_FILE_RAW) {
|
||||||
mirror->format == VIR_STORAGE_FILE_RAW) {
|
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("shallow copy of disk '%s' into a raw file "
|
_("shallow copy of disk '%s' into a raw file "
|
||||||
"is not possible"),
|
"is not possible"),
|
||||||
@ -17600,11 +17601,11 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
|
|||||||
if (qemuDomainStorageFileInit(driver, vm, mirror, NULL) < 0)
|
if (qemuDomainStorageFileInit(driver, vm, mirror, NULL) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (qemuDomainBlockCopyValidateMirror(mirror, disk->dst, &reuse) < 0)
|
if (qemuDomainBlockCopyValidateMirror(mirror, disk->dst, &existing) < 0)
|
||||||
goto endjob;
|
goto endjob;
|
||||||
|
|
||||||
if (!mirror->format) {
|
if (!mirror->format) {
|
||||||
if (!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) {
|
if (!mirror_reuse) {
|
||||||
mirror->format = disk->src->format;
|
mirror->format = disk->src->format;
|
||||||
} else {
|
} else {
|
||||||
/* If the user passed the REUSE_EXT flag, then either they
|
/* If the user passed the REUSE_EXT flag, then either they
|
||||||
@ -17627,7 +17628,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* pre-create the image file */
|
/* pre-create the image file */
|
||||||
if (!reuse) {
|
if (!existing) {
|
||||||
if (virStorageFileCreate(mirror) < 0) {
|
if (virStorageFileCreate(mirror) < 0) {
|
||||||
virReportSystemError(errno, "%s", _("failed to create copy target"));
|
virReportSystemError(errno, "%s", _("failed to create copy target"));
|
||||||
goto endjob;
|
goto endjob;
|
||||||
@ -17645,7 +17646,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
|
|||||||
|
|
||||||
/* If reusing an external image that includes a backing file but the user
|
/* If reusing an external image that includes a backing file but the user
|
||||||
* did not enumerate the chain in the XML we need to detect the chain */
|
* did not enumerate the chain in the XML we need to detect the chain */
|
||||||
if (flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT &&
|
if (mirror_reuse &&
|
||||||
mirror->format >= VIR_STORAGE_FILE_BACKING &&
|
mirror->format >= VIR_STORAGE_FILE_BACKING &&
|
||||||
mirror->backingStore == NULL &&
|
mirror->backingStore == NULL &&
|
||||||
qemuDomainDetermineDiskChain(driver, vm, disk, mirror, true) < 0)
|
qemuDomainDetermineDiskChain(driver, vm, disk, mirror, true) < 0)
|
||||||
@ -17662,11 +17663,10 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
|
|||||||
/* Actually start the mirroring */
|
/* Actually start the mirroring */
|
||||||
qemuDomainObjEnterMonitor(driver, vm);
|
qemuDomainObjEnterMonitor(driver, vm);
|
||||||
/* qemuMonitorDriveMirror needs to honor the REUSE_EXT flag as specified
|
/* qemuMonitorDriveMirror needs to honor the REUSE_EXT flag as specified
|
||||||
* by the user regardless of how @reuse was modified */
|
* by the user */
|
||||||
ret = qemuMonitorDriveMirror(priv->mon, device, mirror->path, format,
|
ret = qemuMonitorDriveMirror(priv->mon, device, mirror->path, format,
|
||||||
bandwidth, granularity, buf_size,
|
bandwidth, granularity, buf_size,
|
||||||
flags & VIR_DOMAIN_BLOCK_COPY_SHALLOW,
|
mirror_shallow, mirror_reuse);
|
||||||
flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT);
|
|
||||||
virDomainAuditDisk(vm, NULL, mirror, "mirror", ret >= 0);
|
virDomainAuditDisk(vm, NULL, mirror, "mirror", ret >= 0);
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||||
ret = -1;
|
ret = -1;
|
||||||
|
Loading…
Reference in New Issue
Block a user