render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
032100
From b8c791a3fc2767e6d899e3e0c590a93cb0ee7e03 Mon Sep 17 00:00:00 2001
032100
Message-Id: <b8c791a3fc2767e6d899e3e0c590a93cb0ee7e03@dist-git>
032100
From: Jiri Denemark <jdenemar@redhat.com>
032100
Date: Thu, 30 Jun 2022 12:52:38 +0200
032100
Subject: [PATCH] qemu_migration: Apply max-postcopy-bandwidth on post-copy
032100
 resume
032100
032100
When resuming post-copy migration users may want to limit the bandwidth
032100
used by the migration and use a value that is different from the one
032100
specified when the migration was originally started.
032100
032100
Resolves: https://gitlab.com/libvirt/libvirt/-/issues/333
032100
032100
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
032100
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
032100
(cherry picked from commit 766abdc291ba606379a7d197bff477fef25fb508)
032100
032100
https://bugzilla.redhat.com/show_bug.cgi?id=2111070
032100
032100
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
032100
---
032100
 src/qemu/qemu_migration.c            | 12 ++++++--
032100
 src/qemu/qemu_migration_params.c     | 45 ++++++++++++++++++----------
032100
 src/qemu/qemu_migration_paramspriv.h |  3 +-
032100
 tests/qemumigparamstest.c            |  2 +-
032100
 tests/qemumigrationcookiexmltest.c   |  2 +-
032100
 5 files changed, 42 insertions(+), 22 deletions(-)
032100
032100
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
032100
index 285a49c5ff..8a2f5b09a1 100644
032100
--- a/src/qemu/qemu_migration.c
032100
+++ b/src/qemu/qemu_migration.c
032100
@@ -5097,12 +5097,13 @@ qemuMigrationSrcRun(virQEMUDriver *driver,
032100
 
032100
 static int
032100
 qemuMigrationSrcResume(virDomainObj *vm,
032100
-                       qemuMigrationParams *migParams G_GNUC_UNUSED,
032100
+                       qemuMigrationParams *migParams,
032100
                        const char *cookiein,
032100
                        int cookieinlen,
032100
                        char **cookieout,
032100
                        int *cookieoutlen,
032100
-                       qemuMigrationSpec *spec)
032100
+                       qemuMigrationSpec *spec,
032100
+                       unsigned long flags)
032100
 {
032100
     qemuDomainObjPrivate *priv = vm->privateData;
032100
     virQEMUDriver *driver = priv->driver;
032100
@@ -5119,6 +5120,10 @@ qemuMigrationSrcResume(virDomainObj *vm,
032100
     if (!mig)
032100
         return -1;
032100
 
032100
+    if (qemuMigrationParamsApply(driver, vm, VIR_ASYNC_JOB_MIGRATION_OUT,
032100
+                                 migParams, flags) < 0)
032100
+        return -1;
032100
+
032100
     if (qemuDomainObjEnterMonitorAsync(driver, vm,
032100
                                        VIR_ASYNC_JOB_MIGRATION_OUT) < 0)
032100
         return -1;
032100
@@ -5200,6 +5205,7 @@ qemuMigrationSrcPerformNative(virQEMUDriver *driver,
032100
 
032100
     if (STREQ(uribits->scheme, "unix")) {
032100
         if ((flags & VIR_MIGRATE_TLS) &&
032100
+            !(flags & VIR_MIGRATE_POSTCOPY_RESUME) &&
032100
             !qemuMigrationParamsTLSHostnameIsSet(migParams)) {
032100
             virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
032100
                            _("Explicit destination hostname is required "
032100
@@ -5231,7 +5237,7 @@ qemuMigrationSrcPerformNative(virQEMUDriver *driver,
032100
 
032100
     if (flags & VIR_MIGRATE_POSTCOPY_RESUME) {
032100
         ret = qemuMigrationSrcResume(vm, migParams, cookiein, cookieinlen,
032100
-                                     cookieout, cookieoutlen, &spec);
032100
+                                     cookieout, cookieoutlen, &spec, flags);
032100
     } else {
032100
         ret = qemuMigrationSrcRun(driver, vm, persist_xml, cookiein, cookieinlen,
032100
                                   cookieout, cookieoutlen, flags, resource,
032100
diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c
032100
index a68aed9aa4..6ea0bde13a 100644
032100
--- a/src/qemu/qemu_migration_params.c
032100
+++ b/src/qemu/qemu_migration_params.c
032100
@@ -141,6 +141,7 @@ struct _qemuMigrationParamsTPMapItem {
032100
 typedef struct _qemuMigrationParamInfoItem qemuMigrationParamInfoItem;
032100
 struct _qemuMigrationParamInfoItem {
032100
     qemuMigrationParamType type;
032100
+    bool applyOnPostcopyResume;
032100
 };
032100
 
032100
 /* Migration capabilities which should always be enabled as long as they
032100
@@ -265,6 +266,7 @@ static const qemuMigrationParamInfoItem qemuMigrationParamInfo[] = {
032100
     },
032100
     [QEMU_MIGRATION_PARAM_MAX_POSTCOPY_BANDWIDTH] = {
032100
         .type = QEMU_MIGRATION_PARAM_TYPE_ULL,
032100
+        .applyOnPostcopyResume = true,
032100
     },
032100
     [QEMU_MIGRATION_PARAM_MULTIFD_CHANNELS] = {
032100
         .type = QEMU_MIGRATION_PARAM_TYPE_INT,
032100
@@ -782,7 +784,8 @@ qemuMigrationParamsFromJSON(virJSONValue *params)
032100
 
032100
 
032100
 virJSONValue *
032100
-qemuMigrationParamsToJSON(qemuMigrationParams *migParams)
032100
+qemuMigrationParamsToJSON(qemuMigrationParams *migParams,
032100
+                          bool postcopyResume)
032100
 {
032100
     g_autoptr(virJSONValue) params = virJSONValueNewObject();
032100
     size_t i;
032100
@@ -795,6 +798,9 @@ qemuMigrationParamsToJSON(qemuMigrationParams *migParams)
032100
         if (!pv->set)
032100
             continue;
032100
 
032100
+        if (postcopyResume && !qemuMigrationParamInfo[i].applyOnPostcopyResume)
032100
+            continue;
032100
+
032100
         switch (qemuMigrationParamInfo[i].type) {
032100
         case QEMU_MIGRATION_PARAM_TYPE_INT:
032100
             rc = virJSONValueObjectAppendNumberInt(params, name, pv->value.i);
032100
@@ -868,6 +874,7 @@ qemuMigrationCapsToJSON(virBitmap *caps,
032100
  *
032100
  * Send parameters stored in @migParams to QEMU. If @apiFlags is non-zero, some
032100
  * parameters that do not make sense for the enabled flags will be ignored.
032100
+ * VIR_MIGRATE_POSTCOPY_RESUME is the only flag checked currently.
032100
  *
032100
  * Returns 0 on success, -1 on failure.
032100
  */
032100
@@ -876,32 +883,38 @@ qemuMigrationParamsApply(virQEMUDriver *driver,
032100
                          virDomainObj *vm,
032100
                          int asyncJob,
032100
                          qemuMigrationParams *migParams,
032100
-                         unsigned long apiFlags G_GNUC_UNUSED)
032100
+                         unsigned long apiFlags)
032100
 {
032100
     qemuDomainObjPrivate *priv = vm->privateData;
032100
     bool xbzrleCacheSize_old = false;
032100
     g_autoptr(virJSONValue) params = NULL;
032100
     g_autoptr(virJSONValue) caps = NULL;
032100
     qemuMigrationParam xbzrle = QEMU_MIGRATION_PARAM_XBZRLE_CACHE_SIZE;
032100
+    bool postcopyResume = !!(apiFlags & VIR_MIGRATE_POSTCOPY_RESUME);
032100
     int ret = -1;
032100
 
032100
     if (qemuDomainObjEnterMonitorAsync(driver, vm, asyncJob) < 0)
032100
         return -1;
032100
 
032100
-    if (asyncJob == VIR_ASYNC_JOB_NONE) {
032100
-        if (!virBitmapIsAllClear(migParams->caps)) {
032100
-            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
032100
-                           _("Migration capabilities can only be set by "
032100
-                             "a migration job"));
032100
-            goto cleanup;
032100
-        }
032100
-    } else {
032100
-        if (!(caps = qemuMigrationCapsToJSON(priv->migrationCaps, migParams->caps)))
032100
-            goto cleanup;
032100
+    /* Changing capabilities is only allowed before migration starts, we need
032100
+     * to skip them when resuming post-copy migration.
032100
+     */
032100
+    if (!postcopyResume) {
032100
+        if (asyncJob == VIR_ASYNC_JOB_NONE) {
032100
+            if (!virBitmapIsAllClear(migParams->caps)) {
032100
+                virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
032100
+                               _("Migration capabilities can only be set by "
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
+            if (virJSONValueArraySize(caps) > 0 &&
032100
+                qemuMonitorSetMigrationCapabilities(priv->mon, &caps) < 0)
032100
+                goto cleanup;
032100
+        }
032100
     }
032100
 
032100
     /* If QEMU is too old to support xbzrle-cache-size migration parameter,
032100
@@ -917,7 +930,7 @@ qemuMigrationParamsApply(virQEMUDriver *driver,
032100
         migParams->params[xbzrle].set = false;
032100
     }
032100
 
032100
-    if (!(params = qemuMigrationParamsToJSON(migParams)))
032100
+    if (!(params = qemuMigrationParamsToJSON(migParams, postcopyResume)))
032100
         goto cleanup;
032100
 
032100
     if (virJSONValueObjectKeysNumber(params) > 0 &&
032100
diff --git a/src/qemu/qemu_migration_paramspriv.h b/src/qemu/qemu_migration_paramspriv.h
032100
index f7e0f51fbd..34d51231ff 100644
032100
--- a/src/qemu/qemu_migration_paramspriv.h
032100
+++ b/src/qemu/qemu_migration_paramspriv.h
032100
@@ -26,7 +26,8 @@
032100
 #pragma once
032100
 
032100
 virJSONValue *
032100
-qemuMigrationParamsToJSON(qemuMigrationParams *migParams);
032100
+qemuMigrationParamsToJSON(qemuMigrationParams *migParams,
032100
+                          bool postcopyResume);
032100
 
032100
 qemuMigrationParams *
032100
 qemuMigrationParamsFromJSON(virJSONValue *params);
032100
diff --git a/tests/qemumigparamstest.c b/tests/qemumigparamstest.c
032100
index bcdee5f32b..5d45a9dd58 100644
032100
--- a/tests/qemumigparamstest.c
032100
+++ b/tests/qemumigparamstest.c
032100
@@ -155,7 +155,7 @@ qemuMigParamsTestJSON(const void *opaque)
032100
     if (!(migParams = qemuMigrationParamsFromJSON(paramsIn)))
032100
         return -1;
032100
 
032100
-    if (!(paramsOut = qemuMigrationParamsToJSON(migParams)) ||
032100
+    if (!(paramsOut = qemuMigrationParamsToJSON(migParams, false)) ||
032100
         !(actualJSON = virJSONValueToString(paramsOut, true)))
032100
         return -1;
032100
 
032100
diff --git a/tests/qemumigrationcookiexmltest.c b/tests/qemumigrationcookiexmltest.c
032100
index 316bfedd15..9731348b53 100644
032100
--- a/tests/qemumigrationcookiexmltest.c
032100
+++ b/tests/qemumigrationcookiexmltest.c
032100
@@ -333,7 +333,7 @@ testQemuMigrationCookieBlockDirtyBitmaps(const void *opaque)
032100
 
032100
     qemuMigrationParamsSetBlockDirtyBitmapMapping(migParams, &migParamsBitmaps);
032100
 
032100
-    if (!(paramsOut = qemuMigrationParamsToJSON(migParams)) ||
032100
+    if (!(paramsOut = qemuMigrationParamsToJSON(migParams, false)) ||
032100
         !(actualJSON = virJSONValueToString(paramsOut, true)))
032100
         return -1;
032100
 
032100
-- 
032100
2.35.1
032100