mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 06:50:22 +03:00
qemu: Change return value of SaveImageGetCompressionProgram
qemuSaveImageGetCompressionProgram is a bit overloaded. Along with getting a compression program, it checks the validity of the image format and returns the integer representation of the format. Change the function to only handle retrieving the specified compression program, returning success or failure. Checking the validity of the image format can be left to the calling functions. Signed-off-by: Jim Fehlig <jfehlig@suse.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
757fa62cfd
commit
1564607cd0
@ -2731,7 +2731,7 @@ qemuDomainManagedSaveHelper(virQEMUDriver *driver,
|
||||
g_autoptr(virQEMUDriverConfig) cfg = NULL;
|
||||
g_autoptr(virCommand) compressor = NULL;
|
||||
g_autofree char *path = NULL;
|
||||
int format;
|
||||
int format = QEMU_SAVE_FORMAT_RAW;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
return -1;
|
||||
@ -2743,8 +2743,11 @@ qemuDomainManagedSaveHelper(virQEMUDriver *driver,
|
||||
}
|
||||
|
||||
cfg = virQEMUDriverGetConfig(driver);
|
||||
if ((format = qemuSaveImageGetCompressionProgram(cfg->saveImageFormat,
|
||||
&compressor, "save")) < 0)
|
||||
if (cfg->saveImageFormat &&
|
||||
(format = qemuSaveFormatTypeFromString(cfg->saveImageFormat)) < 0)
|
||||
return -1;
|
||||
|
||||
if (qemuSaveImageGetCompressionProgram(format, &compressor, "save") < 0)
|
||||
return -1;
|
||||
|
||||
path = qemuDomainManagedSavePath(driver, vm);
|
||||
@ -2765,7 +2768,7 @@ qemuDomainSaveFlags(virDomainPtr dom, const char *path, const char *dxml,
|
||||
unsigned int flags)
|
||||
{
|
||||
virQEMUDriver *driver = dom->conn->privateData;
|
||||
int format;
|
||||
int format = QEMU_SAVE_FORMAT_RAW;
|
||||
g_autoptr(virCommand) compressor = NULL;
|
||||
int ret = -1;
|
||||
virDomainObj *vm = NULL;
|
||||
@ -2776,8 +2779,11 @@ qemuDomainSaveFlags(virDomainPtr dom, const char *path, const char *dxml,
|
||||
VIR_DOMAIN_SAVE_PAUSED, -1);
|
||||
|
||||
cfg = virQEMUDriverGetConfig(driver);
|
||||
if ((format = qemuSaveImageGetCompressionProgram(cfg->saveImageFormat,
|
||||
&compressor, "save")) < 0)
|
||||
if (cfg->saveImageFormat &&
|
||||
(format = qemuSaveFormatTypeFromString(cfg->saveImageFormat)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuSaveImageGetCompressionProgram(format, &compressor, "save") < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(vm = qemuDomainObjFromDomain(dom)))
|
||||
@ -2815,7 +2821,7 @@ qemuDomainSaveParams(virDomainPtr dom,
|
||||
g_autoptr(virCommand) compressor = NULL;
|
||||
const char *to = NULL;
|
||||
const char *dxml = NULL;
|
||||
int format;
|
||||
int format = QEMU_SAVE_FORMAT_RAW;
|
||||
int ret = -1;
|
||||
|
||||
virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE |
|
||||
@ -2849,8 +2855,11 @@ qemuDomainSaveParams(virDomainPtr dom,
|
||||
}
|
||||
|
||||
cfg = virQEMUDriverGetConfig(driver);
|
||||
if ((format = qemuSaveImageGetCompressionProgram(cfg->saveImageFormat,
|
||||
&compressor, "save")) < 0)
|
||||
if (cfg->saveImageFormat &&
|
||||
(format = qemuSaveFormatTypeFromString(cfg->saveImageFormat)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuSaveImageGetCompressionProgram(format, &compressor, "save") < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainObjCheckActive(vm) < 0)
|
||||
@ -3060,9 +3069,14 @@ doCoreDump(virQEMUDriver *driver,
|
||||
const char *memory_dump_format = NULL;
|
||||
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
|
||||
g_autoptr(virCommand) compressor = NULL;
|
||||
int format = QEMU_SAVE_FORMAT_RAW;
|
||||
|
||||
if (qemuSaveImageGetCompressionProgram(cfg->dumpImageFormat,
|
||||
&compressor, "dump") < 0)
|
||||
if (cfg->dumpImageFormat) {
|
||||
if ((format = qemuSaveFormatTypeFromString(cfg->dumpImageFormat)) < 0)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (qemuSaveImageGetCompressionProgram(format, &compressor, "dump") < 0)
|
||||
goto cleanup;
|
||||
|
||||
/* Create an empty file with appropriate ownership. */
|
||||
|
@ -508,38 +508,26 @@ qemuSaveImageCreate(virQEMUDriver *driver,
|
||||
|
||||
|
||||
/* qemuSaveImageGetCompressionProgram:
|
||||
* @imageFormat: String representation from qemu.conf of the image format
|
||||
* being used (dump, save, or snapshot).
|
||||
* @format: Integer representation of the image format being used
|
||||
* (dump, save, or snapshot).
|
||||
* @compresspath: Pointer to a character string to store the fully qualified
|
||||
* path from virFindFileInPath.
|
||||
* @styleFormat: String representing the style of format (dump, save, snapshot)
|
||||
*
|
||||
* 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.
|
||||
* Returns -1 on failure, 0 on success.
|
||||
*/
|
||||
int
|
||||
qemuSaveImageGetCompressionProgram(const char *imageFormat,
|
||||
qemuSaveImageGetCompressionProgram(int format,
|
||||
virCommand **compressor,
|
||||
const char *styleFormat)
|
||||
{
|
||||
int ret;
|
||||
const char *imageFormat = qemuSaveFormatTypeToString(format);
|
||||
const char *prog;
|
||||
|
||||
*compressor = NULL;
|
||||
|
||||
if (!imageFormat)
|
||||
return QEMU_SAVE_FORMAT_RAW;
|
||||
|
||||
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 (format == QEMU_SAVE_FORMAT_RAW)
|
||||
return 0;
|
||||
|
||||
if (!(prog = virFindFileInPath(imageFormat))) {
|
||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||
@ -550,10 +538,10 @@ qemuSaveImageGetCompressionProgram(const char *imageFormat,
|
||||
|
||||
*compressor = virCommandNew(prog);
|
||||
virCommandAddArg(*compressor, "-c");
|
||||
if (ret == QEMU_SAVE_FORMAT_XZ)
|
||||
if (format == QEMU_SAVE_FORMAT_XZ)
|
||||
virCommandAddArg(*compressor, "-3");
|
||||
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
@ -110,7 +110,7 @@ qemuSaveImageOpen(virQEMUDriver *driver,
|
||||
ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4);
|
||||
|
||||
int
|
||||
qemuSaveImageGetCompressionProgram(const char *imageFormat,
|
||||
qemuSaveImageGetCompressionProgram(int format,
|
||||
virCommand **compressor,
|
||||
const char *styleFormat)
|
||||
ATTRIBUTE_NONNULL(2);
|
||||
|
@ -1597,7 +1597,7 @@ qemuSnapshotCreateActiveExternal(virQEMUDriver *driver,
|
||||
bool memory_existing = false;
|
||||
bool thaw = false;
|
||||
bool pmsuspended = false;
|
||||
int format;
|
||||
int format = QEMU_SAVE_FORMAT_RAW;
|
||||
g_autoptr(virCommand) compressor = NULL;
|
||||
virQEMUSaveData *data = NULL;
|
||||
g_autoptr(GHashTable) blockNamedNodeData = NULL;
|
||||
@ -1674,9 +1674,12 @@ qemuSnapshotCreateActiveExternal(virQEMUDriver *driver,
|
||||
JOB_MASK(VIR_JOB_SUSPEND) |
|
||||
JOB_MASK(VIR_JOB_MIGRATION_OP)));
|
||||
|
||||
if ((format = qemuSaveImageGetCompressionProgram(cfg->snapshotImageFormat,
|
||||
&compressor,
|
||||
"snapshot")) < 0)
|
||||
if (cfg->snapshotImageFormat &&
|
||||
(format = qemuSaveFormatTypeFromString(cfg->snapshotImageFormat)) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuSaveImageGetCompressionProgram(format, &compressor,
|
||||
"snapshot") < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!(xml = qemuDomainDefFormatLive(driver, priv->qemuCaps,
|
||||
|
Loading…
x
Reference in New Issue
Block a user