]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Don't ignore dump image format errors
authorJim Fehlig <jfehlig@suse.com>
Thu, 20 Feb 2025 01:02:06 +0000 (18:02 -0700)
committerJim Fehlig <jfehlig@suse.com>
Mon, 3 Mar 2025 17:05:06 +0000 (10:05 -0700)
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>
src/qemu/qemu_driver.c
src/qemu/qemu_saveimage.c
src/qemu/qemu_saveimage.h
src/qemu/qemu_snapshot.c

index c69074766b11ea93bf7789799992c27ba9267077..81f7b822c1b1b2f17272a8f2e929b9ea02fde54d 100644 (file)
@@ -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) {
index 403e4c9679999ceb2ce674b9210a93459654a26d..9bb76c05f806edbc2d183b8f353f624b83841b40 100644 (file)
@@ -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;
 }
 
 
index 8e755e1eb5b2d94274bf55a3bbd3b6f2b0e6c32c..aa905768de7fa37971436f2509a64c733b2d53b4 100644 (file)
@@ -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
index f7d62729079fe15b68b05760fdd3ddd451b2126a..c2a98c1296a1fe344bf957cea46b74caade2ce29 100644 (file)
@@ -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,