thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-migration-Make-sure-that-we-don-t-call-write-in-case.patch

22c213
From 71b05ab5782aa1e38c016be6264a14f5650d2a87 Mon Sep 17 00:00:00 2001
22c213
From: Juan Quintela <quintela@redhat.com>
22c213
Date: Tue, 3 Mar 2020 14:51:35 +0000
22c213
Subject: [PATCH 03/18] migration: Make sure that we don't call write() in case
22c213
 of error
22c213
22c213
RH-Author: Juan Quintela <quintela@redhat.com>
22c213
Message-id: <20200303145143.149290-3-quintela@redhat.com>
22c213
Patchwork-id: 94113
22c213
O-Subject: [RHEL-AV-8.2.0 qemu-kvm PATCH v2 02/10] migration: Make sure that we don't call write() in case of error
22c213
Bugzilla: 1738451
22c213
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
22c213
RH-Acked-by: Peter Xu <peterx@redhat.com>
22c213
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
22c213
If we are exiting due to an error/finish/.... Just don't try to even
22c213
touch the channel with one IO operation.
22c213
22c213
Signed-off-by: Juan Quintela <quintela@redhat.com>
22c213
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
Signed-off-by: Juan Quintela <quintela@redhat.com>
22c213
(cherry picked from commit 4d65a6216bfc44891ac298b74a6921d479805131)
22c213
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
22c213
---
22c213
 migration/ram.c | 25 +++++++++++++++++++++++++
22c213
 1 file changed, 25 insertions(+)
22c213
22c213
diff --git a/migration/ram.c b/migration/ram.c
22c213
index 65580e3..8c783b3 100644
22c213
--- a/migration/ram.c
22c213
+++ b/migration/ram.c
22c213
@@ -899,6 +899,12 @@ struct {
22c213
     uint64_t packet_num;
22c213
     /* send channels ready */
22c213
     QemuSemaphore channels_ready;
22c213
+    /*
22c213
+     * Have we already run terminate threads.  There is a race when it
22c213
+     * happens that we got one error while we are exiting.
22c213
+     * We will use atomic operations.  Only valid values are 0 and 1.
22c213
+     */
22c213
+    int exiting;
22c213
 } *multifd_send_state;
22c213
 
22c213
 /*
22c213
@@ -927,6 +933,10 @@ static int multifd_send_pages(RAMState *rs)
22c213
     MultiFDPages_t *pages = multifd_send_state->pages;
22c213
     uint64_t transferred;
22c213
 
22c213
+    if (atomic_read(&multifd_send_state->exiting)) {
22c213
+        return -1;
22c213
+    }
22c213
+
22c213
     qemu_sem_wait(&multifd_send_state->channels_ready);
22c213
     for (i = next_channel;; i = (i + 1) % migrate_multifd_channels()) {
22c213
         p = &multifd_send_state->params[i];
22c213
@@ -1008,6 +1018,16 @@ static void multifd_send_terminate_threads(Error *err)
22c213
         }
22c213
     }
22c213
 
22c213
+    /*
22c213
+     * We don't want to exit each threads twice.  Depending on where
22c213
+     * we get the error, or if there are two independent errors in two
22c213
+     * threads at the same time, we can end calling this function
22c213
+     * twice.
22c213
+     */
22c213
+    if (atomic_xchg(&multifd_send_state->exiting, 1)) {
22c213
+        return;
22c213
+    }
22c213
+
22c213
     for (i = 0; i < migrate_multifd_channels(); i++) {
22c213
         MultiFDSendParams *p = &multifd_send_state->params[i];
22c213
 
22c213
@@ -1117,6 +1137,10 @@ static void *multifd_send_thread(void *opaque)
22c213
 
22c213
     while (true) {
22c213
         qemu_sem_wait(&p->sem);
22c213
+
22c213
+        if (atomic_read(&multifd_send_state->exiting)) {
22c213
+            break;
22c213
+        }
22c213
         qemu_mutex_lock(&p->mutex);
22c213
 
22c213
         if (p->pending_job) {
22c213
@@ -1225,6 +1249,7 @@ int multifd_save_setup(void)
22c213
     multifd_send_state->params = g_new0(MultiFDSendParams, thread_count);
22c213
     multifd_send_state->pages = multifd_pages_init(page_count);
22c213
     qemu_sem_init(&multifd_send_state->channels_ready, 0);
22c213
+    atomic_set(&multifd_send_state->exiting, 0);
22c213
 
22c213
     for (i = 0; i < thread_count; i++) {
22c213
         MultiFDSendParams *p = &multifd_send_state->params[i];
22c213
-- 
22c213
1.8.3.1
22c213