]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Change return value of SaveImageGetCompressionProgram
authorJim Fehlig <jfehlig@suse.com>
Wed, 12 Feb 2025 04:46:59 +0000 (21:46 -0700)
committerJim Fehlig <jfehlig@suse.com>
Mon, 3 Mar 2025 17:05:11 +0000 (10:05 -0700)
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>
src/qemu/qemu_driver.c
src/qemu/qemu_saveimage.c
src/qemu/qemu_saveimage.h
src/qemu/qemu_snapshot.c

index 81f7b822c1b1b2f17272a8f2e929b9ea02fde54d..ceaef9817f5ef7421a46ab176fb8cbdd63dec6c9 100644 (file)
@@ -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 (cfg->dumpImageFormat) {
+        if ((format = qemuSaveFormatTypeFromString(cfg->dumpImageFormat)) < 0)
+            goto cleanup;
+    }
 
-    if (qemuSaveImageGetCompressionProgram(cfg->dumpImageFormat,
-                                           &compressor, "dump") < 0)
+    if (qemuSaveImageGetCompressionProgram(format, &compressor, "dump") < 0)
         goto cleanup;
 
     /* Create an empty file with appropriate ownership.  */
index 9bb76c05f806edbc2d183b8f353f624b83841b40..d940bfb5c3d6b6e11025f671d2bbd02a912de0bf 100644 (file)
@@ -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;
 }
 
 
index aa905768de7fa37971436f2509a64c733b2d53b4..0d8ee542af3ff167623f9e36e3fe0f566c916483 100644 (file)
@@ -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);
index c2a98c1296a1fe344bf957cea46b74caade2ce29..416a772b9281e261ad94f4b91e7b45a20e858d1b 100644 (file)
@@ -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,