a1c947
From a1d825e5dcb8cbe0854fa852d25e5997a52d57cd Mon Sep 17 00:00:00 2001
a1c947
Message-Id: <a1d825e5dcb8cbe0854fa852d25e5997a52d57cd@dist-git>
a1c947
From: Jiri Denemark <jdenemar@redhat.com>
a1c947
Date: Wed, 27 Jul 2022 14:33:23 +0200
a1c947
Subject: [PATCH] qemu: Restore original memory locking limit on reconnect
a1c947
a1c947
Commit v8.4.0-287-gd4d3bb8130 tried to make sure the original
a1c947
pre-migration memory locking limit is restored at the end of migration,
a1c947
but it missed the case when libvirt daemon is restarted during
a1c947
migration which needs to be aborted on reconnect.
a1c947
a1c947
And if this was not enough, I forgot to actually save the status XML
a1c947
after setting the field in priv (in the commit mentioned above and also
a1c947
in v8.4.0-291-gd375993ab3).
a1c947
a1c947
https://bugzilla.redhat.com/show_bug.cgi?id=2107424
a1c947
a1c947
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a1c947
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
a1c947
(cherry picked from commit bb9badb9168ad0d40bca86b6463ef504624f096d)
a1c947
a1c947
Conflicts:
a1c947
	src/qemu/qemu_migration.c
a1c947
            - commit v8.5.0-2-gf9dcc01a0f not backported
a1c947
a1c947
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
a1c947
---
a1c947
 src/qemu/qemu_migration.c | 13 +++++++++----
a1c947
 src/qemu/qemu_process.c   |  2 ++
a1c947
 2 files changed, 11 insertions(+), 4 deletions(-)
a1c947
a1c947
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
a1c947
index 9289df81eb..61fcaf4258 100644
a1c947
--- a/src/qemu/qemu_migration.c
a1c947
+++ b/src/qemu/qemu_migration.c
a1c947
@@ -4672,10 +4672,12 @@ qemuMigrationSrcStart(virDomainObj *vm,
a1c947
     switch (spec->destType) {
a1c947
     case MIGRATION_DEST_HOST:
a1c947
         if (STREQ(spec->dest.host.protocol, "rdma") &&
a1c947
-            vm->def->mem.hard_limit > 0 &&
a1c947
-            qemuDomainSetMaxMemLock(vm, vm->def->mem.hard_limit << 10,
a1c947
-                                    &priv->preMigrationMemlock) < 0) {
a1c947
-            return -1;
a1c947
+            vm->def->mem.hard_limit > 0) {
a1c947
+            if (qemuDomainSetMaxMemLock(vm, vm->def->mem.hard_limit << 10,
a1c947
+                                        &priv->preMigrationMemlock) < 0)
a1c947
+                return -1;
a1c947
+            /* Store the original memory locking limit */
a1c947
+            qemuDomainSaveStatus(vm);
a1c947
         }
a1c947
         return qemuMonitorMigrateToHost(priv->mon, migrateFlags,
a1c947
                                         spec->dest.host.protocol,
a1c947
@@ -4870,6 +4872,9 @@ qemuMigrationSrcRun(virQEMUDriver *driver,
a1c947
 
a1c947
         if (qemuDomainSetMaxMemLock(vm, limit << 10, &priv->preMigrationMemlock) < 0)
a1c947
             goto error;
a1c947
+
a1c947
+        /* Store the original memory locking limit */
a1c947
+        qemuDomainSaveStatus(vm);
a1c947
     }
a1c947
 
a1c947
     if (storageMigration) {
a1c947
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
a1c947
index 771a623ef7..1c28d4b102 100644
a1c947
--- a/src/qemu/qemu_process.c
a1c947
+++ b/src/qemu/qemu_process.c
a1c947
@@ -3677,6 +3677,7 @@ qemuProcessRecoverMigration(virQEMUDriver *driver,
a1c947
 {
a1c947
     virDomainJobStatus migStatus = VIR_DOMAIN_JOB_STATUS_NONE;
a1c947
     qemuDomainJobPrivate *jobPriv = job->privateData;
a1c947
+    qemuDomainObjPrivate *priv = vm->privateData;
a1c947
     virDomainState state;
a1c947
     int reason;
a1c947
     int rc;
a1c947
@@ -3726,6 +3727,7 @@ qemuProcessRecoverMigration(virQEMUDriver *driver,
a1c947
 
a1c947
     qemuMigrationParamsReset(driver, vm, VIR_ASYNC_JOB_NONE,
a1c947
                              jobPriv->migParams, job->apiFlags);
a1c947
+    qemuDomainSetMaxMemLock(vm, 0, &priv->preMigrationMemlock);
a1c947
 
a1c947
     return 0;
a1c947
 }
a1c947
-- 
a1c947
2.35.1
a1c947