mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
qemu: Don't ignore dump image format errors
Long ago, without justification, commit 48cb9f0542 changed qemuGetCompressionProgram (since renamed to qemuSaveImageGetCompressionProgram) to ignore configuration errors for dump operations. Like the other save-related operations, user provided configuration should be verified and an error reported if it cannot be honored. Remove the special handling of configuration errors in qemuSaveImageGetCompressionProgram and change the dump logic to fail when dump image format cannot be supported. Signed-off-by: Jim Fehlig <jfehlig@suse.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
1a5692a6e1
commit
757fa62cfd
@ -2744,8 +2744,7 @@ qemuDomainManagedSaveHelper(virQEMUDriver *driver,
|
||||
|
||||
cfg = virQEMUDriverGetConfig(driver);
|
||||
if ((format = qemuSaveImageGetCompressionProgram(cfg->saveImageFormat,
|
||||
&compressor,
|
||||
"save", false)) < 0)
|
||||
&compressor, "save")) < 0)
|
||||
return -1;
|
||||
|
||||
path = qemuDomainManagedSavePath(driver, vm);
|
||||
@ -2778,8 +2777,7 @@ qemuDomainSaveFlags(virDomainPtr dom, const char *path, const char *dxml,
|
||||
|
||||
cfg = virQEMUDriverGetConfig(driver);
|
||||
if ((format = qemuSaveImageGetCompressionProgram(cfg->saveImageFormat,
|
||||
&compressor,
|
||||
"save", false)) < 0)
|
||||
&compressor, "save")) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(vm = qemuDomainObjFromDomain(dom)))
|
||||
@ -2852,8 +2850,7 @@ qemuDomainSaveParams(virDomainPtr dom,
|
||||
|
||||
cfg = virQEMUDriverGetConfig(driver);
|
||||
if ((format = qemuSaveImageGetCompressionProgram(cfg->saveImageFormat,
|
||||
&compressor,
|
||||
"save", false)) < 0)
|
||||
&compressor, "save")) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
@ -3064,13 +3061,9 @@ doCoreDump(virQEMUDriver *driver,
|
||||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||
g_autoptr(virCommand) compressor = NULL;
|
||||
|
||||
/* We reuse "save" flag for "dump" here. Then, we can support the same
|
||||
* format in "save" and "dump". This path doesn't need the compression
|
||||
* program to exist and can ignore the return value - it only cares to
|
||||
* get the compressor */
|
||||
ignore_value(qemuSaveImageGetCompressionProgram(cfg->dumpImageFormat,
|
||||
&compressor,
|
||||
"dump", true));
|
||||
if (qemuSaveImageGetCompressionProgram(cfg->dumpImageFormat,
|
||||
&compressor, "dump") < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* Create an empty file with appropriate ownership. */
|
||||
if (dump_flags & VIR_DUMP_BYPASS_CACHE) {
|
||||
|
@ -513,24 +513,15 @@ qemuSaveImageCreate(virQEMUDriver *driver,
|
||||
* @compresspath: Pointer to a character string to store the fully qualified
|
||||
* path from virFindFileInPath.
|
||||
* @styleFormat: String representing the style of format (dump, save, snapshot)
|
||||
* @use_raw_on_fail: Boolean indicating how to handle the error path. For
|
||||
* callers that are OK with invalid data or inability to
|
||||
* find the compression program, just return a raw format
|
||||
* and let the path remain as NULL.
|
||||
*
|
||||
* Returns:
|
||||
* virQEMUSaveFormat - Integer representation of the save image
|
||||
* format to be used for particular style
|
||||
* (e.g. dump, save, or snapshot).
|
||||
* QEMU_SAVE_FORMAT_RAW - If there is no qemu.conf imageFormat value or
|
||||
* no there was an error, then just return RAW
|
||||
* indicating none.
|
||||
* On success, returns an integer representation of the save image format to be
|
||||
* used for a particular style (e.g. dump, save, or snapshot). Returns -1 on
|
||||
* failure.
|
||||
*/
|
||||
int
|
||||
qemuSaveImageGetCompressionProgram(const char *imageFormat,
|
||||
virCommand **compressor,
|
||||
const char *styleFormat,
|
||||
bool use_raw_on_fail)
|
||||
const char *styleFormat)
|
||||
{
|
||||
int ret;
|
||||
const char *prog;
|
||||
@ -540,14 +531,22 @@ qemuSaveImageGetCompressionProgram(const char *imageFormat,
|
||||
if (!imageFormat)
|
||||
return QEMU_SAVE_FORMAT_RAW;
|
||||
|
||||
if ((ret = qemuSaveFormatTypeFromString(imageFormat)) < 0)
|
||||
goto error;
|
||||
if ((ret = qemuSaveFormatTypeFromString(imageFormat)) < 0) {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("Invalid %1$s image format specified in configuration file"),
|
||||
styleFormat);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ret == QEMU_SAVE_FORMAT_RAW)
|
||||
return QEMU_SAVE_FORMAT_RAW;
|
||||
|
||||
if (!(prog = virFindFileInPath(imageFormat)))
|
||||
goto error;
|
||||
if (!(prog = virFindFileInPath(imageFormat))) {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("Compression program for %1$s image format in configuration file isn't available"),
|
||||
styleFormat);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*compressor = virCommandNew(prog);
|
||||
virCommandAddArg(*compressor, "-c");
|
||||
@ -555,34 +554,6 @@ qemuSaveImageGetCompressionProgram(const char *imageFormat,
|
||||
virCommandAddArg(*compressor, "-3");
|
||||
|
||||
return ret;
|
||||
|
||||
error:
|
||||
if (ret < 0) {
|
||||
if (use_raw_on_fail)
|
||||
VIR_WARN("Invalid %s image format specified in "
|
||||
"configuration file, using raw",
|
||||
styleFormat);
|
||||
else
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("Invalid %1$s image format specified in configuration file"),
|
||||
styleFormat);
|
||||
} else {
|
||||
if (use_raw_on_fail)
|
||||
VIR_WARN("Compression program for %s image format in "
|
||||
"configuration file isn't available, using raw",
|
||||
styleFormat);
|
||||
else
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
_("Compression program for %1$s image format in configuration file isn't available"),
|
||||
styleFormat);
|
||||
}
|
||||
|
||||
/* Use "raw" as the format if the specified format is not valid,
|
||||
* or the compress program is not available. */
|
||||
if (use_raw_on_fail)
|
||||
return QEMU_SAVE_FORMAT_RAW;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
@ -112,8 +112,7 @@ qemuSaveImageOpen(virQEMUDriver *driver,
|
||||
int
|
||||
qemuSaveImageGetCompressionProgram(const char *imageFormat,
|
||||
virCommand **compressor,
|
||||
const char *styleFormat,
|
||||
bool use_raw_on_fail)
|
||||
const char *styleFormat)
|
||||
ATTRIBUTE_NONNULL(2);
|
||||
|
||||
int
|
||||
|
@ -1676,7 +1676,7 @@ qemuSnapshotCreateActiveExternal(virQEMUDriver *driver,
|
||||
|
||||
if ((format = qemuSaveImageGetCompressionProgram(cfg->snapshotImageFormat,
|
||||
&compressor,
|
||||
"snapshot", false)) < 0)
|
||||
"snapshot")) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(xml = qemuDomainDefFormatLive(driver, priv->qemuCaps,
|
||||
|
Loading…
x
Reference in New Issue
Block a user