render / rpms / libvirt

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