[PATCH V2 2/4] qemu: Don't ignore dump image format errors

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxx>
---
 src/qemu/qemu_driver.c    | 19 ++++--------
 src/qemu/qemu_saveimage.c | 61 ++++++++++-----------------------------
 src/qemu/qemu_saveimage.h |  3 +-
 src/qemu/qemu_snapshot.c  |  2 +-
 4 files changed, 24 insertions(+), 61 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 80c918312b..ac7c67b3a1 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -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) {
diff --git a/src/qemu/qemu_saveimage.c b/src/qemu/qemu_saveimage.c
index 403e4c9679..9bb76c05f8 100644
--- a/src/qemu/qemu_saveimage.c
+++ b/src/qemu/qemu_saveimage.c
@@ -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;
 }
 
 
diff --git a/src/qemu/qemu_saveimage.h b/src/qemu/qemu_saveimage.h
index 8e755e1eb5..aa905768de 100644
--- a/src/qemu/qemu_saveimage.h
+++ b/src/qemu/qemu_saveimage.h
@@ -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
diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index f7d6272907..c2a98c1296 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -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,
-- 
2.43.0



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux