From: John Ferlan Date: Tue, 13 Sep 2016 14:01:47 +0000 (-0400) Subject: qemu: Introduce helper qemuGetCompressionProgram X-Git-Tag: v2.3.0-rc1~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02d32d2d5d307d264695a65b98656629d53861ba;p=thirdparty%2Flibvirt.git qemu: Introduce helper qemuGetCompressionProgram Split out the guts of getCompressionType to perform the same functionality in the new helper program with a subsequent patch goal to be reusable for other callers making similar checks/calls to ensure the compression type is valid and that the compression program cannot be found. --- diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 956bddd48d..3f03576e2e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3267,36 +3267,61 @@ qemuCompressProgramAvailable(virQEMUSaveFormat compress) } +/* qemuGetCompressionProgram: + * @imageFormat: String representation from qemu.conf for the compression + * image format being used (dump, save, or snapshot). + * + * Returns: + * virQEMUSaveFormat - Integer representation of the compression + * program 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. + */ +static virQEMUSaveFormat +qemuGetCompressionProgram(const char *imageFormat) +{ + virQEMUSaveFormat ret; + + if (!imageFormat) + return QEMU_SAVE_FORMAT_RAW; + + if ((ret = qemuSaveCompressionTypeFromString(imageFormat)) < 0) + goto error; + + if (!qemuCompressProgramAvailable(ret)) + goto error; + + return ret; + + error: + if (ret < 0) + VIR_WARN("%s", _("Invalid dump image format specified in " + "configuration file, using raw")); + else + VIR_WARN("%s", _("Compression program for dump image format " + "in configuration file isn't available, " + "using raw")); + + /* Use "raw" as the format if the specified format is not valid, + * or the compress program is not available. */ + return QEMU_SAVE_FORMAT_RAW; +} + + static virQEMUSaveFormat getCompressionType(virQEMUDriverPtr driver) { - int ret = QEMU_SAVE_FORMAT_RAW; + int ret; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); /* * We reuse "save" flag for "dump" here. Then, we can support the same * format in "save" and "dump". */ - if (cfg->dumpImageFormat) { - ret = qemuSaveCompressionTypeFromString(cfg->dumpImageFormat); - /* Use "raw" as the format if the specified format is not valid, - * or the compress program is not available. - */ - if (ret < 0) { - VIR_WARN("%s", _("Invalid dump image format specified in " - "configuration file, using raw")); - ret = QEMU_SAVE_FORMAT_RAW; - goto cleanup; - } - if (!qemuCompressProgramAvailable(ret)) { - VIR_WARN("%s", _("Compression program for dump image format " - "in configuration file isn't available, " - "using raw")); - ret = QEMU_SAVE_FORMAT_RAW; - goto cleanup; - } - } - cleanup: + ret = qemuGetCompressionProgram(cfg->dumpImageFormat); + virObjectUnref(cfg); return ret; }