mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-02 01:45:17 +00:00
qemu: driver: Split out access to VIR_DOMAIN_BLOCK_COPY_REUSE_EXT
Extract the presence of the flag into a boolean to simplify conditions and allow further manipulation of the state of the flag.
This commit is contained in:
parent
75107ae516
commit
a805320b67
@ -16708,6 +16708,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
|
|||||||
const char *format = NULL;
|
const char *format = NULL;
|
||||||
int desttype = virStorageSourceGetActualType(mirror);
|
int desttype = virStorageSourceGetActualType(mirror);
|
||||||
virErrorPtr monitor_error = NULL;
|
virErrorPtr monitor_error = NULL;
|
||||||
|
bool reuse = !!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT);
|
||||||
|
|
||||||
/* Preliminaries: find the disk we are editing, sanity checks */
|
/* Preliminaries: find the disk we are editing, sanity checks */
|
||||||
virCheckFlags(VIR_DOMAIN_BLOCK_COPY_SHALLOW |
|
virCheckFlags(VIR_DOMAIN_BLOCK_COPY_SHALLOW |
|
||||||
@ -16768,8 +16769,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) &&
|
if ((flags & VIR_DOMAIN_BLOCK_COPY_SHALLOW) && !reuse &&
|
||||||
!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT) &&
|
|
||||||
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 "
|
||||||
@ -16790,15 +16790,14 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
|
|||||||
virReportSystemError(errno, _("unable to stat for disk %s: %s"),
|
virReportSystemError(errno, _("unable to stat for disk %s: %s"),
|
||||||
disk->dst, mirror->path);
|
disk->dst, mirror->path);
|
||||||
goto endjob;
|
goto endjob;
|
||||||
} else if (flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT ||
|
} else if (reuse || desttype == VIR_STORAGE_TYPE_BLOCK) {
|
||||||
desttype == VIR_STORAGE_TYPE_BLOCK) {
|
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
_("missing destination file for disk %s: %s"),
|
_("missing destination file for disk %s: %s"),
|
||||||
disk->dst, mirror->path);
|
disk->dst, mirror->path);
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
} else if (!S_ISBLK(st.st_mode)) {
|
} else if (!S_ISBLK(st.st_mode)) {
|
||||||
if (st.st_size && !(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) {
|
if (st.st_size && !reuse) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
_("external destination file for disk %s already "
|
_("external destination file for disk %s already "
|
||||||
"exists and is not a block device: %s"),
|
"exists and is not a block device: %s"),
|
||||||
@ -16815,7 +16814,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!mirror->format) {
|
if (!mirror->format) {
|
||||||
if (!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) {
|
if (!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
|
||||||
@ -16828,7 +16827,7 @@ qemuDomainBlockCopyCommon(virDomainObjPtr vm,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* pre-create the image file */
|
/* pre-create the image file */
|
||||||
if (!(flags & VIR_DOMAIN_BLOCK_COPY_REUSE_EXT)) {
|
if (!reuse) {
|
||||||
int fd = qemuOpenFile(driver, vm, mirror->path,
|
int fd = qemuOpenFile(driver, vm, mirror->path,
|
||||||
O_WRONLY | O_TRUNC | O_CREAT,
|
O_WRONLY | O_TRUNC | O_CREAT,
|
||||||
&need_unlink, NULL);
|
&need_unlink, NULL);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user