mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-08 22:15:21 +00:00
qemu: copy: Accept 'format' parameter when copying to a non-existing img
We have the following matrix of possible arguments handled by the logic statement touched by this patch: | flags & _REUSE_EXT | !(flags & _REUSE_EXT) -------+--------------------+---------------------- format| (1) | (2) -------+--------------------+---------------------- !format| (3) | (4) -------+--------------------+---------------------- In cases 1 and 2 the user provided a format, in cases 3 and 4 not. The user requests to use a pre-existing image in 1 and 3 and libvirt will create a new image in 2 and 4. The difference between cases 3 and 4 is that for 3 the format is probed from the user-provided image, whereas in 4 we just use the existing disk format. The current code would treat cases 1,3 and 4 correctly but in case 2 the format provided by the user would be ignored. The particular piece of code was broken in commit35c7701c64
but since it was introduced a few commits before that it was never released as working. (cherry picked from commit42619ed05d
) Signed-off-by: Eric Blake <eblake@redhat.com> Conflicts: src/qemu/qemu_driver.c - no refactoring of commits7b7bf001
,4f20226
This commit is contained in:
parent
b915aba392
commit
f4a7efeebc
@ -14306,21 +14306,15 @@ qemuDomainBlockCopy(virDomainObjPtr vm,
|
|||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(flags & VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT)) {
|
if (format) {
|
||||||
int fd = qemuOpenFile(driver, vm, dest, O_WRONLY | O_TRUNC | O_CREAT,
|
if ((mirrorFormat = virStorageFileFormatTypeFromString(format)) <= 0) {
|
||||||
&need_unlink, NULL);
|
|
||||||
if (fd < 0)
|
|
||||||
goto endjob;
|
|
||||||
VIR_FORCE_CLOSE(fd);
|
|
||||||
if (!format)
|
|
||||||
mirrorFormat = disk->format;
|
|
||||||
} else if (format) {
|
|
||||||
mirrorFormat = virStorageFileFormatTypeFromString(format);
|
|
||||||
if (mirrorFormat <= 0) {
|
|
||||||
virReportError(VIR_ERR_INVALID_ARG, _("unrecognized format '%s'"),
|
virReportError(VIR_ERR_INVALID_ARG, _("unrecognized format '%s'"),
|
||||||
format);
|
format);
|
||||||
goto endjob;
|
goto endjob;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (!(flags & VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT)) {
|
||||||
|
mirrorFormat = disk->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
|
||||||
* also passed the RAW flag (and format is non-NULL), or it is
|
* also passed the RAW flag (and format is non-NULL), or it is
|
||||||
@ -14329,6 +14323,17 @@ qemuDomainBlockCopy(virDomainObjPtr vm,
|
|||||||
mirrorFormat = virStorageFileProbeFormat(dest, cfg->user,
|
mirrorFormat = virStorageFileProbeFormat(dest, cfg->user,
|
||||||
cfg->group);
|
cfg->group);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* pre-create the image file */
|
||||||
|
if (!(flags & VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT)) {
|
||||||
|
int fd = qemuOpenFile(driver, vm, dest, O_WRONLY | O_TRUNC | O_CREAT,
|
||||||
|
&need_unlink, NULL);
|
||||||
|
if (fd < 0)
|
||||||
|
goto endjob;
|
||||||
|
VIR_FORCE_CLOSE(fd);
|
||||||
|
}
|
||||||
|
|
||||||
if (!format && mirrorFormat > 0)
|
if (!format && mirrorFormat > 0)
|
||||||
format = virStorageFileFormatTypeToString(mirrorFormat);
|
format = virStorageFileFormatTypeToString(mirrorFormat);
|
||||||
if (VIR_STRDUP(mirror, dest) < 0)
|
if (VIR_STRDUP(mirror, dest) < 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user