Blame SOURCES/kvm-migration-Maybe-VM-is-paused-when-migration-is-cance.patch

902636
From 3c4f6f0c2bf5562f2aa26f964848ae53e6ac4790 Mon Sep 17 00:00:00 2001
902636
From: Juan Quintela <quintela@redhat.com>
902636
Date: Tue, 3 Mar 2020 14:51:43 +0000
902636
Subject: [PATCH 11/18] migration: Maybe VM is paused when migration is
902636
 cancelled
902636
902636
RH-Author: Juan Quintela <quintela@redhat.com>
902636
Message-id: <20200303145143.149290-11-quintela@redhat.com>
902636
Patchwork-id: 94120
902636
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 10/10] migration: Maybe VM is paused when migration is cancelled
902636
Bugzilla: 1738451
902636
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
902636
RH-Acked-by: Peter Xu <peterx@redhat.com>
902636
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
902636
902636
From: Zhimin Feng <fengzhimin1@huawei.com>
902636
902636
If the migration is cancelled when it is in the completion phase,
902636
the migration state is set to MIGRATION_STATUS_CANCELLING.
902636
The VM maybe wait for the 'pause_sem' semaphore in migration_maybe_pause
902636
function, so that VM always is paused.
902636
902636
Reported-by: Euler Robot <euler.robot@huawei.com>
902636
Signed-off-by: Zhimin Feng <fengzhimin1@huawei.com>
902636
Reviewed-by: Juan Quintela <quintela@redhat.com>
902636
Signed-off-by: Juan Quintela <quintela@redhat.com>
902636
(cherry picked from commit 8958338b10abcb346b54a8038a491fda2db1c853)
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 migration/migration.c | 24 ++++++++++++++++--------
902636
 1 file changed, 16 insertions(+), 8 deletions(-)
902636
902636
diff --git a/migration/migration.c b/migration/migration.c
902636
index eb50d77..ed18c59 100644
902636
--- a/migration/migration.c
902636
+++ b/migration/migration.c
902636
@@ -2786,14 +2786,22 @@ static int migration_maybe_pause(MigrationState *s,
902636
         /* This block intentionally left blank */
902636
     }
902636
 
902636
-    qemu_mutex_unlock_iothread();
902636
-    migrate_set_state(&s->state, *current_active_state,
902636
-                      MIGRATION_STATUS_PRE_SWITCHOVER);
902636
-    qemu_sem_wait(&s->pause_sem);
902636
-    migrate_set_state(&s->state, MIGRATION_STATUS_PRE_SWITCHOVER,
902636
-                      new_state);
902636
-    *current_active_state = new_state;
902636
-    qemu_mutex_lock_iothread();
902636
+    /*
902636
+     * If the migration is cancelled when it is in the completion phase,
902636
+     * the migration state is set to MIGRATION_STATUS_CANCELLING.
902636
+     * So we don't need to wait a semaphore, otherwise we would always
902636
+     * wait for the 'pause_sem' semaphore.
902636
+     */
902636
+    if (s->state != MIGRATION_STATUS_CANCELLING) {
902636
+        qemu_mutex_unlock_iothread();
902636
+        migrate_set_state(&s->state, *current_active_state,
902636
+                          MIGRATION_STATUS_PRE_SWITCHOVER);
902636
+        qemu_sem_wait(&s->pause_sem);
902636
+        migrate_set_state(&s->state, MIGRATION_STATUS_PRE_SWITCHOVER,
902636
+                          new_state);
902636
+        *current_active_state = new_state;
902636
+        qemu_mutex_lock_iothread();
902636
+    }
902636
 
902636
     return s->state == new_state ? 0 : -EINVAL;
902636
 }
902636
-- 
902636
1.8.3.1
902636