render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
4372d3
From 8cccd9634ecd91a5b7343eddc037e0fa7de2f9f6 Mon Sep 17 00:00:00 2001
4372d3
Message-Id: <8cccd9634ecd91a5b7343eddc037e0fa7de2f9f6@dist-git>
11fcb6
From: Jiri Denemark <jdenemar@redhat.com>
11fcb6
Date: Wed, 22 Jun 2022 16:12:02 +0200
11fcb6
Subject: [PATCH] qemu_migration: Restore original memory locking limit
11fcb6
MIME-Version: 1.0
11fcb6
Content-Type: text/plain; charset=UTF-8
11fcb6
Content-Transfer-Encoding: 8bit
11fcb6
11fcb6
For RDMA migration we update memory locking limit, but never set it back
11fcb6
once migration finishes (on the destination host) or aborts (on the
11fcb6
source host).
11fcb6
11fcb6
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11fcb6
Reviewed-by: Ján Tomko <jtomko@redhat.com>
11fcb6
(cherry picked from commit d4d3bb813031275c2c7cf72724b83c97ce82ab7a)
11fcb6
4372d3
https://bugzilla.redhat.com/show_bug.cgi?id=2089433
11fcb6
11fcb6
Conflicts:
11fcb6
	src/qemu/qemu_migration.c
11fcb6
            - post-copy resovery not backported
11fcb6
11fcb6
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
11fcb6
---
11fcb6
 src/qemu/qemu_domain.c    | 12 ++++++++++++
11fcb6
 src/qemu/qemu_domain.h    |  3 +++
4372d3
 src/qemu/qemu_migration.c | 10 ++++++++--
4372d3
 3 files changed, 23 insertions(+), 2 deletions(-)
11fcb6
11fcb6
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
11fcb6
index a81789f194..c24d1e4d53 100644
11fcb6
--- a/src/qemu/qemu_domain.c
11fcb6
+++ b/src/qemu/qemu_domain.c
11fcb6
@@ -2389,6 +2389,11 @@ qemuDomainObjPrivateXMLFormat(virBuffer *buf,
11fcb6
                           priv->originalMemlock);
11fcb6
     }
11fcb6
 
11fcb6
+    if (priv->preMigrationMemlock > 0) {
11fcb6
+        virBufferAsprintf(buf, "<preMigrationMemlock>%llu</preMigrationMemlock>\n",
11fcb6
+                          priv->preMigrationMemlock);
11fcb6
+    }
11fcb6
+
11fcb6
     return 0;
11fcb6
 }
11fcb6
 
11fcb6
@@ -3117,6 +3122,13 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
11fcb6
         goto error;
11fcb6
     }
11fcb6
 
11fcb6
+    if (virXPathULongLong("string(./preMigrationMemlock)", ctxt,
11fcb6
+                          &priv->preMigrationMemlock) == -2) {
11fcb6
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
11fcb6
+                       _("failed to parse pre-migration memlock limit"));
11fcb6
+        return -1;
11fcb6
+    }
11fcb6
+
11fcb6
     return 0;
11fcb6
 
11fcb6
  error:
11fcb6
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
11fcb6
index 6d1d23439a..d6e8a7a0fb 100644
11fcb6
--- a/src/qemu/qemu_domain.h
11fcb6
+++ b/src/qemu/qemu_domain.h
11fcb6
@@ -146,6 +146,9 @@ struct _qemuDomainObjPrivate {
11fcb6
     int nbdPort; /* Port used for migration with NBD */
11fcb6
     unsigned short migrationPort;
11fcb6
     int preMigrationState;
11fcb6
+    unsigned long long preMigrationMemlock; /* Original RLIMIT_MEMLOCK in case
11fcb6
+                                               it was changed for the current
11fcb6
+                                               migration job. */
11fcb6
 
11fcb6
     virChrdevs *devs;
11fcb6
 
11fcb6
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
4372d3
index 10338f8e87..35ad201580 100644
11fcb6
--- a/src/qemu/qemu_migration.c
11fcb6
+++ b/src/qemu/qemu_migration.c
11fcb6
@@ -2974,7 +2974,8 @@ qemuMigrationDstPrepareAny(virQEMUDriver *driver,
11fcb6
 
11fcb6
     if (STREQ_NULLABLE(protocol, "rdma") &&
11fcb6
         vm->def->mem.hard_limit > 0 &&
11fcb6
-        qemuDomainSetMaxMemLock(vm, vm->def->mem.hard_limit << 10, NULL) < 0) {
11fcb6
+        qemuDomainSetMaxMemLock(vm, vm->def->mem.hard_limit << 10,
11fcb6
+                                &priv->preMigrationMemlock) < 0) {
11fcb6
         goto stopjob;
11fcb6
     }
11fcb6
 
11fcb6
@@ -3451,6 +3452,7 @@ qemuMigrationSrcConfirmPhase(virQEMUDriver *driver,
11fcb6
                                          VIR_DOMAIN_EVENT_STOPPED_MIGRATED);
11fcb6
         virObjectEventStateQueue(driver->domainEventState, event);
11fcb6
         qemuDomainEventEmitJobCompleted(driver, vm);
11fcb6
+        priv->preMigrationMemlock = 0;
11fcb6
     } else {
11fcb6
         virErrorPtr orig_err;
11fcb6
         int reason;
11fcb6
@@ -3471,6 +3473,7 @@ qemuMigrationSrcConfirmPhase(virQEMUDriver *driver,
11fcb6
 
11fcb6
         qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
11fcb6
                                  jobPriv->migParams, priv->job.apiFlags);
11fcb6
+        qemuDomainSetMaxMemLock(vm, 0, &priv->preMigrationMemlock);
11fcb6
 
11fcb6
         qemuDomainSaveStatus(vm);
11fcb6
     }
11fcb6
@@ -4224,7 +4227,8 @@ qemuMigrationSrcRun(virQEMUDriver *driver,
11fcb6
     case MIGRATION_DEST_HOST:
11fcb6
         if (STREQ(spec->dest.host.protocol, "rdma") &&
11fcb6
             vm->def->mem.hard_limit > 0 &&
11fcb6
-            qemuDomainSetMaxMemLock(vm, vm->def->mem.hard_limit << 10, NULL) < 0) {
11fcb6
+            qemuDomainSetMaxMemLock(vm, vm->def->mem.hard_limit << 10,
11fcb6
+                                    &priv->preMigrationMemlock) < 0) {
11fcb6
             goto exit_monitor;
11fcb6
         }
11fcb6
         rc = qemuMonitorMigrateToHost(priv->mon, migrate_flags,
11fcb6
@@ -5408,6 +5412,7 @@ qemuMigrationSrcPerformPhase(virQEMUDriver *driver,
11fcb6
     if (ret < 0) {
11fcb6
         qemuMigrationParamsReset(driver, vm, QEMU_ASYNC_JOB_MIGRATION_OUT,
11fcb6
                                  jobPriv->migParams, priv->job.apiFlags);
11fcb6
+        qemuDomainSetMaxMemLock(vm, 0, &priv->preMigrationMemlock);
11fcb6
         qemuMigrationJobFinish(driver, vm);
11fcb6
     } else {
11fcb6
         qemuMigrationJobContinue(vm);
4372d3
@@ -5881,6 +5886,7 @@ qemuMigrationDstFinish(virQEMUDriver *driver,
4372d3
  cleanup:
4372d3
     g_clear_pointer(&jobInfo, qemuDomainJobInfoFree);
4372d3
     virPortAllocatorRelease(port);
4372d3
+    qemuDomainSetMaxMemLock(vm, 0, &priv->preMigrationMemlock);
4372d3
     if (priv->mon)
4372d3
         qemuMonitorSetDomainLog(priv->mon, NULL, NULL, NULL);
4372d3
     VIR_FREE(priv->origname);
11fcb6
-- 
11fcb6
2.35.1
11fcb6