From: Avihai Horon <avih...@nvidia.com>

Signed-off-by: Avihai Horon <avih...@nvidia.com>
[MSS: Rewrite using MFDSendChannelConnectData/PostcopyPChannelConnectData]
Signed-off-by: Maciej S. Szmigiero <maciej.szmigi...@oracle.com>
---
 migration/multifd.c      | 14 ++++++++++++--
 migration/postcopy-ram.c | 14 ++++++++++++--
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/migration/multifd.c b/migration/multifd.c
index 58a18bb1e4a8..8eecda68ac0f 100644
--- a/migration/multifd.c
+++ b/migration/multifd.c
@@ -18,6 +18,7 @@
 #include "exec/ramblock.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
+#include "channel.h"
 #include "file.h"
 #include "migration.h"
 #include "migration-stats.h"
@@ -1014,15 +1015,20 @@ struct MFDSendChannelConnectData {
     unsigned int ref;
     MultiFDSendParams *p;
     QIOChannelTLS *tioc;
+    MigChannelHeader header;
 };
 
-static MFDSendChannelConnectData 
*mfd_send_channel_connect_data_new(MultiFDSendParams *p)
+static MFDSendChannelConnectData 
*mfd_send_channel_connect_data_new(MultiFDSendParams *p,
+                                                                    
MigChannelHeader *header)
 {
     MFDSendChannelConnectData *data;
 
     data = g_malloc0(sizeof(*data));
     data->ref = 1;
     data->p = p;
+    if (header) {
+        memcpy(&data->header, header, sizeof(*header));
+    }
 
     return data;
 }
@@ -1110,6 +1116,10 @@ bool multifd_channel_connect(MFDSendChannelConnectData 
*data, QIOChannel *ioc,
 {
     MultiFDSendParams *p = data->p;
 
+    if (migration_channel_header_send(ioc, &data->header, errp)) {
+        return false;
+    }
+
     qio_channel_set_delay(ioc, false);
 
     migration_ioc_register_yank(ioc);
@@ -1182,7 +1192,7 @@ static bool 
multifd_new_send_channel_create(MultiFDSendParams *p, Error **errp)
 {
     g_autoptr(MFDSendChannelConnectData) data = NULL;
 
-    data = mfd_send_channel_connect_data_new(p);
+    data = mfd_send_channel_connect_data_new(p, NULL);
 
     if (!multifd_use_packets()) {
         return file_send_channel_create(data, errp);
diff --git a/migration/postcopy-ram.c b/migration/postcopy-ram.c
index 94fe872d8251..53c90344acce 100644
--- a/migration/postcopy-ram.c
+++ b/migration/postcopy-ram.c
@@ -19,6 +19,7 @@
 #include "qemu/osdep.h"
 #include "qemu/madvise.h"
 #include "exec/target_page.h"
+#include "channel.h"
 #include "migration.h"
 #include "qemu-file.h"
 #include "savevm.h"
@@ -1620,15 +1621,20 @@ void 
postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *file)
 typedef struct {
     unsigned int ref;
     MigrationState *s;
+    MigChannelHeader header;
 } PostcopyPChannelConnectData;
 
-static PostcopyPChannelConnectData 
*pcopy_preempt_connect_data_new(MigrationState *s)
+static PostcopyPChannelConnectData 
*pcopy_preempt_connect_data_new(MigrationState *s,
+                                                                   
MigChannelHeader *header)
 {
     PostcopyPChannelConnectData *data;
 
     data = g_malloc0(sizeof(*data));
     data->ref = 1;
     data->s = s;
+    if (header) {
+        memcpy(&data->header, header, sizeof(*header));
+    }
 
     return data;
 }
@@ -1673,6 +1679,10 @@ 
postcopy_preempt_send_channel_done(PostcopyPChannelConnectData *data,
 {
     MigrationState *s = data->s;
 
+    if (!local_err) {
+        migration_channel_header_send(ioc, &data->header, &local_err);
+    }
+
     if (local_err) {
         migrate_set_error(s, local_err);
         error_free(local_err);
@@ -1766,7 +1776,7 @@ void postcopy_preempt_setup(MigrationState *s)
 {
     PostcopyPChannelConnectData *data;
 
-    data = pcopy_preempt_connect_data_new(s);
+    data = pcopy_preempt_connect_data_new(s, NULL);
     /* Kick an async task to connect */
     socket_send_channel_create(postcopy_preempt_send_channel_new,
                                data, pcopy_preempt_connect_data_unref);

Reply via email to