diff mbox series

[RFC,08/26] migration: Allow passing migration header in migration channel creation

Message ID c1538bf0593f5e0e46e0c98e91bc1892e6a314b0.1713269378.git.maciej.szmigiero@oracle.com
State New
Headers show
Series Multifd 🔀 device state transfer support with VFIO consumer | expand

Commit Message

Maciej S. Szmigiero April 16, 2024, 2:42 p.m. UTC
From: Avihai Horon <avihaih@nvidia.com>

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

Patch

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);