render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
032100
From 852927ea725deae6d4ef8a87383a78d9b0b1cd83 Mon Sep 17 00:00:00 2001
032100
Message-Id: <852927ea725deae6d4ef8a87383a78d9b0b1cd83@dist-git>
032100
From: Jiri Denemark <jdenemar@redhat.com>
032100
Date: Thu, 21 Jul 2022 15:59:51 +0200
032100
Subject: [PATCH] qemu_migration_params: Refactor qemuMigrationParamsApply
032100
032100
qemuMigrationParamsApply restricts when capabilities can be set, but
032100
this is not useful in all cases. Let's create new helpers for setting
032100
migration capabilities and parameters which can be reused in more places
032100
without the restriction.
032100
032100
https://bugzilla.redhat.com/show_bug.cgi?id=2107892
032100
032100
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
032100
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
032100
(cherry picked from commit c0824fd03802085db698c10fe62c98cc95a57941)
032100
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
032100
---
032100
 src/qemu/qemu_migration_params.c | 55 +++++++++++++++++++++++---------
032100
 1 file changed, 40 insertions(+), 15 deletions(-)
032100
032100
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
032100
index 0bce358ac3..7b9e5453f6 100644
032100
--- a/src/qemu/qemu_migration_params.c
032100
+++ b/src/qemu/qemu_migration_params.c
032100
@@ -864,6 +864,43 @@ qemuMigrationCapsToJSON(virBitmap *caps,
032100
 }
032100
 
032100
 
032100
+static int
032100
+qemuMigrationParamsApplyCaps(virDomainObj *vm,
032100
+                             virBitmap *states)
032100
+{
032100
+    qemuDomainObjPrivate *priv = vm->privateData;
032100
+    g_autoptr(virJSONValue) json = NULL;
032100
+
032100
+    if (!(json = qemuMigrationCapsToJSON(priv->migrationCaps, states)))
032100
+        return -1;
032100
+
032100
+    if (virJSONValueArraySize(json) > 0 &&
032100
+        qemuMonitorSetMigrationCapabilities(priv->mon, &json) < 0)
032100
+        return -1;
032100
+
032100
+    return 0;
032100
+}
032100
+
032100
+
032100
+static int
032100
+qemuMigrationParamsApplyValues(virDomainObj *vm,
032100
+                               qemuMigrationParams *params,
032100
+                               bool postcopyResume)
032100
+{
032100
+    qemuDomainObjPrivate *priv = vm->privateData;
032100
+    g_autoptr(virJSONValue) json = NULL;
032100
+
032100
+    if (!(json = qemuMigrationParamsToJSON(params, postcopyResume)))
032100
+        return -1;
032100
+
032100
+    if (virJSONValueObjectKeysNumber(json) > 0 &&
032100
+        qemuMonitorSetMigrationParams(priv->mon, &json) < 0)
032100
+        return -1;
032100
+
032100
+    return 0;
032100
+}
032100
+
032100
+
032100
 /**
032100
  * qemuMigrationParamsApply
032100
  * @driver: qemu driver
032100
@@ -885,9 +922,6 @@ qemuMigrationParamsApply(virQEMUDriver *driver,
032100
                          qemuMigrationParams *migParams,
032100
                          unsigned long apiFlags)
032100
 {
032100
-    qemuDomainObjPrivate *priv = vm->privateData;
032100
-    g_autoptr(virJSONValue) params = NULL;
032100
-    g_autoptr(virJSONValue) caps = NULL;
032100
     bool postcopyResume = !!(apiFlags & VIR_MIGRATE_POSTCOPY_RESUME);
032100
     int ret = -1;
032100
 
032100
@@ -905,21 +939,12 @@ qemuMigrationParamsApply(virQEMUDriver *driver,
032100
                                  "a migration job"));
032100
                 goto cleanup;
032100
             }
032100
-        } else {
032100
-            if (!(caps = qemuMigrationCapsToJSON(priv->migrationCaps, migParams->caps)))
032100
-                goto cleanup;
032100
-
032100
-            if (virJSONValueArraySize(caps) > 0 &&
032100
-                qemuMonitorSetMigrationCapabilities(priv->mon, &caps) < 0)
032100
-                goto cleanup;
032100
+        } else if (qemuMigrationParamsApplyCaps(vm, migParams->caps) < 0) {
032100
+            goto cleanup;
032100
         }
032100
     }
032100
 
032100
-    if (!(params = qemuMigrationParamsToJSON(migParams, postcopyResume)))
032100
-        goto cleanup;
032100
-
032100
-    if (virJSONValueObjectKeysNumber(params) > 0 &&
032100
-        qemuMonitorSetMigrationParams(priv->mon, &params) < 0)
032100
+    if (qemuMigrationParamsApplyValues(vm, migParams, postcopyResume) < 0)
032100
         goto cleanup;
032100
 
032100
     ret = 0;
032100
-- 
032100
2.35.1
032100