Blame SOURCES/kvm-multifd-multifd_send_sync_main-now-returns-negative-.patch

719b13
From 9d8968ae10e1724198c493646e2bdcd55f205e5e Mon Sep 17 00:00:00 2001
719b13
From: Leonardo Bras <leobras@redhat.com>
719b13
Date: Wed, 18 May 2022 02:52:25 -0300
719b13
Subject: [PATCH 21/34] multifd: multifd_send_sync_main now returns negative on
719b13
 error
719b13
MIME-Version: 1.0
719b13
Content-Type: text/plain; charset=UTF-8
719b13
Content-Transfer-Encoding: 8bit
719b13
719b13
RH-Author: Leonardo Brás <leobras@redhat.com>
719b13
RH-MergeRequest: 185: MSG_ZEROCOPY + Multifd @ rhel8.6
719b13
RH-Commit: [21/34] bef7acbe751fc4871a9ece72ab58b195658d6328
719b13
RH-Bugzilla: 2117252
719b13
RH-Acked-by: quintela1 <quintela@redhat.com>
719b13
RH-Acked-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
719b13
RH-Acked-by: Peter Xu <peterx@redhat.com>
719b13
719b13
Even though multifd_send_sync_main() currently emits error_reports, it's
719b13
callers don't really check it before continuing.
719b13
719b13
Change multifd_send_sync_main() to return -1 on error and 0 on success.
719b13
Also change all it's callers to make use of this change and possibly fail
719b13
earlier.
719b13
719b13
(This change is important to next patch on  multifd zero copy
719b13
implementation, to make it sure an error in zero-copy flush does not go
719b13
unnoticed.
719b13
719b13
Signed-off-by: Leonardo Bras <leobras@redhat.com>
719b13
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
719b13
Reviewed-by: Peter Xu <peterx@redhat.com>
719b13
Message-Id: <20220513062836.965425-7-leobras@redhat.com>
719b13
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
719b13
(cherry picked from commit 33d70973a3a6e8c6b62bcbc64d9e488961981007)
719b13
Signed-off-by: Leonardo Bras <leobras@redhat.com>
719b13
---
719b13
 migration/multifd.c | 10 ++++++----
719b13
 migration/multifd.h |  2 +-
719b13
 migration/ram.c     | 29 ++++++++++++++++++++++-------
719b13
 3 files changed, 29 insertions(+), 12 deletions(-)
719b13
719b13
diff --git a/migration/multifd.c b/migration/multifd.c
719b13
index e53811f04a..1e34e01ebc 100644
719b13
--- a/migration/multifd.c
719b13
+++ b/migration/multifd.c
719b13
@@ -573,17 +573,17 @@ void multifd_save_cleanup(void)
719b13
     multifd_send_state = NULL;
719b13
 }
719b13
 
719b13
-void multifd_send_sync_main(QEMUFile *f)
719b13
+int multifd_send_sync_main(QEMUFile *f)
719b13
 {
719b13
     int i;
719b13
 
719b13
     if (!migrate_use_multifd()) {
719b13
-        return;
719b13
+        return 0;
719b13
     }
719b13
     if (multifd_send_state->pages->num) {
719b13
         if (multifd_send_pages(f) < 0) {
719b13
             error_report("%s: multifd_send_pages fail", __func__);
719b13
-            return;
719b13
+            return -1;
719b13
         }
719b13
     }
719b13
     for (i = 0; i < migrate_multifd_channels(); i++) {
719b13
@@ -596,7 +596,7 @@ void multifd_send_sync_main(QEMUFile *f)
719b13
         if (p->quit) {
719b13
             error_report("%s: channel %d has already quit", __func__, i);
719b13
             qemu_mutex_unlock(&p->mutex);
719b13
-            return;
719b13
+            return -1;
719b13
         }
719b13
 
719b13
         p->packet_num = multifd_send_state->packet_num++;
719b13
@@ -615,6 +615,8 @@ void multifd_send_sync_main(QEMUFile *f)
719b13
         qemu_sem_wait(&p->sem_sync);
719b13
     }
719b13
     trace_multifd_send_sync_main(multifd_send_state->packet_num);
719b13
+
719b13
+    return 0;
719b13
 }
719b13
 
719b13
 static void *multifd_send_thread(void *opaque)
719b13
diff --git a/migration/multifd.h b/migration/multifd.h
719b13
index 7823199dbe..92de878155 100644
719b13
--- a/migration/multifd.h
719b13
+++ b/migration/multifd.h
719b13
@@ -22,7 +22,7 @@ int multifd_load_cleanup(Error **errp);
719b13
 bool multifd_recv_all_channels_created(void);
719b13
 bool multifd_recv_new_channel(QIOChannel *ioc, Error **errp);
719b13
 void multifd_recv_sync_main(void);
719b13
-void multifd_send_sync_main(QEMUFile *f);
719b13
+int multifd_send_sync_main(QEMUFile *f);
719b13
 int multifd_queue_page(QEMUFile *f, RAMBlock *block, ram_addr_t offset);
719b13
 
719b13
 /* Multifd Compression flags */
719b13
diff --git a/migration/ram.c b/migration/ram.c
719b13
index 863035d235..3e208efca7 100644
719b13
--- a/migration/ram.c
719b13
+++ b/migration/ram.c
719b13
@@ -2992,6 +2992,7 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
719b13
 {
719b13
     RAMState **rsp = opaque;
719b13
     RAMBlock *block;
719b13
+    int ret;
719b13
 
719b13
     if (compress_threads_save_setup()) {
719b13
         return -1;
719b13
@@ -3026,7 +3027,11 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
719b13
     ram_control_before_iterate(f, RAM_CONTROL_SETUP);
719b13
     ram_control_after_iterate(f, RAM_CONTROL_SETUP);
719b13
 
719b13
-    multifd_send_sync_main(f);
719b13
+    ret =  multifd_send_sync_main(f);
719b13
+    if (ret < 0) {
719b13
+        return ret;
719b13
+    }
719b13
+
719b13
     qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
719b13
     qemu_fflush(f);
719b13
 
719b13
@@ -3135,7 +3140,11 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
719b13
 out:
719b13
     if (ret >= 0
719b13
         && migration_is_setup_or_active(migrate_get_current()->state)) {
719b13
-        multifd_send_sync_main(rs->f);
719b13
+        ret = multifd_send_sync_main(rs->f);
719b13
+        if (ret < 0) {
719b13
+            return ret;
719b13
+        }
719b13
+
719b13
         qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
719b13
         qemu_fflush(f);
719b13
         ram_counters.transferred += 8;
719b13
@@ -3193,13 +3202,19 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
719b13
         ram_control_after_iterate(f, RAM_CONTROL_FINISH);
719b13
     }
719b13
 
719b13
-    if (ret >= 0) {
719b13
-        multifd_send_sync_main(rs->f);
719b13
-        qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
719b13
-        qemu_fflush(f);
719b13
+    if (ret < 0) {
719b13
+        return ret;
719b13
     }
719b13
 
719b13
-    return ret;
719b13
+    ret = multifd_send_sync_main(rs->f);
719b13
+    if (ret < 0) {
719b13
+        return ret;
719b13
+    }
719b13
+
719b13
+    qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
719b13
+    qemu_fflush(f);
719b13
+
719b13
+    return 0;
719b13
 }
719b13
 
719b13
 static void ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size,
719b13
-- 
719b13
2.35.3
719b13