diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 591864f13231be7266e17341b0b7594b3b3cc225..e2e1a8228b2cd07fbfcebd521e0148e143de2655 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -15284,29 +15284,34 @@ qemuDomainBlockCopy(virDomainObjPtr vm, 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->src.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, vm, dest, O_WRONLY | O_TRUNC | O_CREAT, &need_unlink, NULL); if (fd < 0) goto endjob; VIR_FORCE_CLOSE(fd); - if (!format) - mirrorFormat = disk->src.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 (VIR_STRDUP(mirror, dest) < 0)