diff options
author | Peter Krempa <pkrempa@redhat.com> | 2014-07-01 13:52:51 +0200 |
---|---|---|
committer | Eric Blake <eblake@redhat.com> | 2014-07-03 06:20:37 -0600 |
commit | e22f1c2e13523c830dc5f26c87e644b4a0dfd1df (patch) | |
tree | b0b14377a4b02ba4ad9c7606de3da9308db4d501 | |
parent | 248d9a49f758d3be3be7e31c7119a0e078b3186b (diff) | |
download | libvirt-e22f1c2e13523c830dc5f26c87e644b4a0dfd1df.tar.gz |
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 commit 35c7701c64508f975dfeb8
but since it was introduced a few commits before that it was never
released as working.
(cherry picked from commit 42619ed05d7924978f3e6e2399522fc6f30607de)
Signed-off-by: Eric Blake <eblake@redhat.com>
Conflicts:
src/qemu/qemu_driver.c - no refactoring of commits 7b7bf001, 4f20226
-rw-r--r-- | src/qemu/qemu_driver.c | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index ff858d3b2c..503a11c762 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13516,29 +13516,34 @@ qemuDomainBlockCopy(virDomainPtr dom, const char *path, goto endjob; } + if (format) { + if ((mirrorFormat = virStorageFileFormatTypeFromString(format)) <= 0) { + virReportError(VIR_ERR_INVALID_ARG, _("unrecognized format '%s'"), + format); + goto endjob; + } + } else { + if (!(flags & VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT)) { + mirrorFormat = disk->format; + } else { + /* If the user passed the REUSE_EXT flag, then either they + * also passed the RAW flag (and format is non-NULL), or it is + * safe for us to probe the format from the file that we will + * be using. */ + mirrorFormat = virStorageFileProbeFormat(dest, cfg->user, + cfg->group); + } + } + + /* pre-create the image file */ if (!(flags & VIR_DOMAIN_BLOCK_REBASE_REUSE_EXT)) { int fd = qemuOpenFile(driver, dest, O_WRONLY | O_TRUNC | O_CREAT, &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'"), - format); - goto endjob; - } - } else { - /* If the user passed the REUSE_EXT flag, then either they - * also passed the RAW flag (and format is non-NULL), or it is - * safe for us to probe the format from the file that we will - * be using. */ - mirrorFormat = virStorageFileProbeFormat(dest, cfg->user, - cfg->group); } + if (!format && mirrorFormat > 0) format = virStorageFileFormatTypeToString(mirrorFormat); if (!(mirror = strdup(dest))) { |