[libvirt PATCH 2/3] qemu_migration_params: Refactor qemuMigrationParamsApply

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

 



qemuMigrationParamsApply restricts when capabilities can be set, but
this is not useful in all cases. Let's create new helpers for setting
migration capabilities and parameters which can be reused in more places
without the restriction.

https://bugzilla.redhat.com/show_bug.cgi?id=2107892

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---
 src/qemu/qemu_migration_params.c | 55 +++++++++++++++++++++++---------
 1 file changed, 40 insertions(+), 15 deletions(-)

diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
index 1fd0c55905..dcfb30b56f 100644
--- a/src/qemu/qemu_migration_params.c
+++ b/src/qemu/qemu_migration_params.c
@@ -864,6 +864,43 @@ qemuMigrationCapsToJSON(virBitmap *caps,
 }
 
 
+static int
+qemuMigrationParamsApplyCaps(virDomainObj *vm,
+                             virBitmap *states)
+{
+    qemuDomainObjPrivate *priv = vm->privateData;
+    g_autoptr(virJSONValue) json = NULL;
+
+    if (!(json = qemuMigrationCapsToJSON(priv->migrationCaps, states)))
+        return -1;
+
+    if (virJSONValueArraySize(json) > 0 &&
+        qemuMonitorSetMigrationCapabilities(priv->mon, &json) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+static int
+qemuMigrationParamsApplyValues(virDomainObj *vm,
+                               qemuMigrationParams *params,
+                               bool postcopyResume)
+{
+    qemuDomainObjPrivate *priv = vm->privateData;
+    g_autoptr(virJSONValue) json = NULL;
+
+    if (!(json = qemuMigrationParamsToJSON(params, postcopyResume)))
+        return -1;
+
+    if (virJSONValueObjectKeysNumber(json) > 0 &&
+        qemuMonitorSetMigrationParams(priv->mon, &json) < 0)
+        return -1;
+
+    return 0;
+}
+
+
 /**
  * qemuMigrationParamsApply
  * @driver: qemu driver
@@ -885,9 +922,6 @@ qemuMigrationParamsApply(virQEMUDriver *driver,
                          qemuMigrationParams *migParams,
                          unsigned long apiFlags)
 {
-    qemuDomainObjPrivate *priv = vm->privateData;
-    g_autoptr(virJSONValue) params = NULL;
-    g_autoptr(virJSONValue) caps = NULL;
     bool postcopyResume = !!(apiFlags & VIR_MIGRATE_POSTCOPY_RESUME);
     int ret = -1;
 
@@ -905,21 +939,12 @@ qemuMigrationParamsApply(virQEMUDriver *driver,
                                  "a migration job"));
                 goto cleanup;
             }
-        } else {
-            if (!(caps = qemuMigrationCapsToJSON(priv->migrationCaps, migParams->caps)))
-                goto cleanup;
-
-            if (virJSONValueArraySize(caps) > 0 &&
-                qemuMonitorSetMigrationCapabilities(priv->mon, &caps) < 0)
-                goto cleanup;
+        } else if (qemuMigrationParamsApplyCaps(vm, migParams->caps) < 0) {
+            goto cleanup;
         }
     }
 
-    if (!(params = qemuMigrationParamsToJSON(migParams, postcopyResume)))
-        goto cleanup;
-
-    if (virJSONValueObjectKeysNumber(params) > 0 &&
-        qemuMonitorSetMigrationParams(priv->mon, &params) < 0)
+    if (qemuMigrationParamsApplyValues(vm, migParams, postcopyResume) < 0)
         goto cleanup;
 
     ret = 0;
-- 
2.35.1




[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