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

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