yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-migration-move-wait-unplug-loop-to-its-own-function.patch

a83cc2
From e9848f4a4f45960bff1a2a7bc4a4670670de37a5 Mon Sep 17 00:00:00 2001
a83cc2
From: Laurent Vivier <lvivier@redhat.com>
a83cc2
Date: Wed, 4 Aug 2021 07:10:12 -0400
a83cc2
Subject: [PATCH 21/39] migration: move wait-unplug loop to its own function
a83cc2
a83cc2
RH-Author: Miroslav Rezanina <mrezanin@redhat.com>
a83cc2
RH-MergeRequest: 32: Synchronize with RHEL-AV 8.5 release 27 to RHEL 9
a83cc2
RH-Commit: [13/15] ab3f26a86e4ea955678323608512e54af2a7c83b (mrezanin/centos-src-qemu-kvm)
a83cc2
RH-Bugzilla: 1957194
a83cc2
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
a83cc2
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
a83cc2
RH-Acked-by: Igor Mammedov <imammedo@redhat.com>
a83cc2
RH-Acked-by: Andrew Jones <drjones@redhat.com>
a83cc2
a83cc2
The loop is used in migration_thread() and bg_migration_thread(),
a83cc2
so we can move it to its own function and call it from these both places.
a83cc2
a83cc2
Moreover, in migration_thread() we have a wrong state transition from
a83cc2
SETUP to ACTIVE while state could be WAIT_UNPLUG. This is correctly
a83cc2
managed in bg_migration_thread() so use this code instead.
a83cc2
a83cc2
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
a83cc2
Message-Id: <20210629155007.629086-2-lvivier@redhat.com>
a83cc2
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
a83cc2
Reviewed-by: Juan Quintela <quintela@redhat.com>
a83cc2
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
a83cc2
(cherry picked from commit fde93d99d9c208c07e2dcc24cd04e824d2b65b35)
a83cc2
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
a83cc2
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
a83cc2
---
a83cc2
 migration/migration.c | 54 +++++++++++++++++++++----------------------
a83cc2
 1 file changed, 26 insertions(+), 28 deletions(-)
a83cc2
a83cc2
diff --git a/migration/migration.c b/migration/migration.c
a83cc2
index 9cf1cde39d..58df1dac05 100644
a83cc2
--- a/migration/migration.c
a83cc2
+++ b/migration/migration.c
a83cc2
@@ -3681,6 +3681,28 @@ bool migration_rate_limit(void)
a83cc2
     return urgent;
a83cc2
 }
a83cc2
 
a83cc2
+/*
a83cc2
+ * if failover devices are present, wait they are completely
a83cc2
+ * unplugged
a83cc2
+ */
a83cc2
+
a83cc2
+static void qemu_savevm_wait_unplug(MigrationState *s, int old_state,
a83cc2
+                                    int new_state)
a83cc2
+{
a83cc2
+    if (qemu_savevm_state_guest_unplug_pending()) {
a83cc2
+        migrate_set_state(&s->state, old_state, MIGRATION_STATUS_WAIT_UNPLUG);
a83cc2
+
a83cc2
+        while (s->state == MIGRATION_STATUS_WAIT_UNPLUG &&
a83cc2
+               qemu_savevm_state_guest_unplug_pending()) {
a83cc2
+            qemu_sem_timedwait(&s->wait_unplug_sem, 250);
a83cc2
+        }
a83cc2
+
a83cc2
+        migrate_set_state(&s->state, MIGRATION_STATUS_WAIT_UNPLUG, new_state);
a83cc2
+    } else {
a83cc2
+        migrate_set_state(&s->state, old_state, new_state);
a83cc2
+    }
a83cc2
+}
a83cc2
+
a83cc2
 /*
a83cc2
  * Master migration thread on the source VM.
a83cc2
  * It drives the migration and pumps the data down the outgoing channel.
a83cc2
@@ -3727,22 +3749,10 @@ static void *migration_thread(void *opaque)
a83cc2
 
a83cc2
     qemu_savevm_state_setup(s->to_dst_file);
a83cc2
 
a83cc2
-    if (qemu_savevm_state_guest_unplug_pending()) {
a83cc2
-        migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
a83cc2
-                          MIGRATION_STATUS_WAIT_UNPLUG);
a83cc2
-
a83cc2
-        while (s->state == MIGRATION_STATUS_WAIT_UNPLUG &&
a83cc2
-               qemu_savevm_state_guest_unplug_pending()) {
a83cc2
-            qemu_sem_timedwait(&s->wait_unplug_sem, 250);
a83cc2
-        }
a83cc2
-
a83cc2
-        migrate_set_state(&s->state, MIGRATION_STATUS_WAIT_UNPLUG,
a83cc2
-                MIGRATION_STATUS_ACTIVE);
a83cc2
-    }
a83cc2
+    qemu_savevm_wait_unplug(s, MIGRATION_STATUS_SETUP,
a83cc2
+                               MIGRATION_STATUS_ACTIVE);
a83cc2
 
a83cc2
     s->setup_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start;
a83cc2
-    migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
a83cc2
-                      MIGRATION_STATUS_ACTIVE);
a83cc2
 
a83cc2
     trace_migration_thread_setup_complete();
a83cc2
 
a83cc2
@@ -3850,21 +3860,9 @@ static void *bg_migration_thread(void *opaque)
a83cc2
     qemu_savevm_state_header(s->to_dst_file);
a83cc2
     qemu_savevm_state_setup(s->to_dst_file);
a83cc2
 
a83cc2
-    if (qemu_savevm_state_guest_unplug_pending()) {
a83cc2
-        migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
a83cc2
-                          MIGRATION_STATUS_WAIT_UNPLUG);
a83cc2
-
a83cc2
-        while (s->state == MIGRATION_STATUS_WAIT_UNPLUG &&
a83cc2
-               qemu_savevm_state_guest_unplug_pending()) {
a83cc2
-            qemu_sem_timedwait(&s->wait_unplug_sem, 250);
a83cc2
-        }
a83cc2
+    qemu_savevm_wait_unplug(s, MIGRATION_STATUS_SETUP,
a83cc2
+                               MIGRATION_STATUS_ACTIVE);
a83cc2
 
a83cc2
-        migrate_set_state(&s->state, MIGRATION_STATUS_WAIT_UNPLUG,
a83cc2
-                          MIGRATION_STATUS_ACTIVE);
a83cc2
-    } else {
a83cc2
-        migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
a83cc2
-                MIGRATION_STATUS_ACTIVE);
a83cc2
-    }
a83cc2
     s->setup_time = qemu_clock_get_ms(QEMU_CLOCK_HOST) - setup_start;
a83cc2
 
a83cc2
     trace_migration_thread_setup_complete();
a83cc2
-- 
a83cc2
2.27.0
a83cc2