qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 00/16] migration: Remove QEMUFileHooks
@ 2023-05-03 13:18 Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 01/16] migration: Create migrate_rdma() Juan Quintela
                   ` (15 more replies)
  0 siblings, 16 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

Hi

Changes in v2:
- rebased on top of migration-20230428 pull (second try)
- several of the patches on the PULL request
- make clean that we don't use rdma code when we don't use rdma
- create migrate_rdma() to check if we are in rdma migration.

There is no hope for this code. I am trying to cleanup the rest of
rdma calls, but the code is convoluted as hell.  And it lies with the
ram counters as crazy.

Please review.

In this series (v1):
- QEMUFileHooks only had a single user, RDMA migration.  Just remove the
  hooks and create stubs for when RDMA is not compiled in.

- This implies that we have to move all the operations from
  migration/qemu-file.c to migration/rdma.c.

- I now we can still simplify rdma_control_save_page(), but I don't
  have an easy setup for testing.

- Yes, the goal of the whole operations is to be able to move
  ram_file_limit from qemu-file to migration.c.

Please review.

Thanks, Juan.

Juan Quintela (16):
  migration: Create migrate_rdma()
  migration/rdma: Unfold ram_control_before_iterate()
  migration/rdma: Unfold ram_control_after_iterate()
  migration/rdma: simplify ram_control_load_hook()
  migration/rdma: Don't pass the QIOChannelRDMA as an opaque
  migration/rdma: We can calculate the rioc from the QEMUFile
  migration/rdma: It makes no sense to recive that flag without RDMA
  migration: Make RAM_SAVE_FLAG_HOOK a normal case entry
  migration/rdma: Remove all uses of RAM_CONTROL_HOOK
  migration/rdma: Unfold hook_ram_load()
  migration/rdma: Make ram_control_save_page() use exported interfaces
  migration/rdma: Create rdma_control_save_page()
  qemu-file: Remove QEMUFileHooks
  migration/rdma: Move rdma constants from qemu-file.h to rdma.h
  migration/rdma: Remove qemu_ prefix from exported functions
  migration/rdma: If we are in postcopy don't do anything

 migration/migration.h  |   3 +
 migration/options.c    |   7 ++
 migration/options.h    |   1 +
 migration/qemu-file.c  |  77 +-------------------
 migration/qemu-file.h  |  51 --------------
 migration/ram.c        |  60 +++++++++++-----
 migration/rdma.c       | 155 ++++++++++++++++++++++-------------------
 migration/rdma.h       |  36 ++++++++++
 migration/trace-events |  28 ++++----
 9 files changed, 186 insertions(+), 232 deletions(-)

-- 
2.40.0



^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v2 01/16] migration: Create migrate_rdma()
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:34   ` Daniel P. Berrangé
  2023-05-03 13:18 ` [PATCH v2 02/16] migration/rdma: Unfold ram_control_before_iterate() Juan Quintela
                   ` (14 subsequent siblings)
  15 siblings, 1 reply; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

Helper to say if we are doing a migration over rdma.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/migration.h | 3 +++
 migration/options.c   | 7 +++++++
 migration/options.h   | 1 +
 migration/rdma.c      | 4 +++-
 4 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/migration/migration.h b/migration/migration.h
index 3a918514e7..47fe116167 100644
--- a/migration/migration.h
+++ b/migration/migration.h
@@ -432,6 +432,9 @@ struct MigrationState {
 
     /* QEMU_VM_VMDESCRIPTION content filled for all non-iterable devices. */
     JSONWriter *vmdesc;
+
+    /* Is this a rdma migration */
+    bool rdma_migration;
 };
 
 void migrate_set_state(int *state, int old_state, int new_state);
diff --git a/migration/options.c b/migration/options.c
index 53b7fc5d5d..39843f9325 100644
--- a/migration/options.c
+++ b/migration/options.c
@@ -349,6 +349,13 @@ bool migrate_postcopy(void)
     return migrate_postcopy_ram() || migrate_dirty_bitmaps();
 }
 
+bool migrate_rdma(void)
+{
+    MigrationState *s = migrate_get_current();
+
+    return s->rdma_migration;
+}
+
 bool migrate_tls(void)
 {
     MigrationState *s = migrate_get_current();
diff --git a/migration/options.h b/migration/options.h
index 3c322867cd..3c555e28c7 100644
--- a/migration/options.h
+++ b/migration/options.h
@@ -61,6 +61,7 @@ bool migrate_zero_copy_send(void);
 
 bool migrate_multifd_flush_after_each_section(void);
 bool migrate_postcopy(void);
+bool migrate_rdma(void);
 bool migrate_tls(void);
 
 /* capabilities helpers */
diff --git a/migration/rdma.c b/migration/rdma.c
index 7e747b2595..b026e98519 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -4119,6 +4119,7 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp)
     int ret;
     RDMAContext *rdma;
     Error *local_err = NULL;
+    MigrationState *s = migrate_get_current();
 
     trace_rdma_start_incoming_migration();
 
@@ -4149,7 +4150,7 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp)
     }
 
     trace_rdma_start_incoming_migration_after_rdma_listen();
-
+    s->rdma_migration = true;
     qemu_set_fd_handler(rdma->channel->fd, rdma_accept_incoming_migration,
                         NULL, (void *)(intptr_t)rdma);
     return;
@@ -4225,6 +4226,7 @@ void rdma_start_outgoing_migration(void *opaque,
 
     trace_rdma_start_outgoing_migration_after_rdma_connect();
 
+    s->rdma_migration = true;
     s->to_dst_file = qemu_fopen_rdma(rdma, "wb");
     migrate_fd_connect(s, NULL);
     return;
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 02/16] migration/rdma: Unfold ram_control_before_iterate()
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 01/16] migration: Create migrate_rdma() Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 03/16] migration/rdma: Unfold ram_control_after_iterate() Juan Quintela
                   ` (13 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

Once there:
- Remove unused data parameter
- unfold it in its callers.
- change all callers to call qemu_rdma_registration_start()

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/qemu-file.c | 13 +------------
 migration/qemu-file.h |  2 --
 migration/ram.c       | 16 +++++++++++++---
 migration/rdma.c      |  8 +++++---
 migration/rdma.h      |  6 ++++++
 5 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index ee04240a21..b6dca23706 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -30,6 +30,7 @@
 #include "qemu-file.h"
 #include "trace.h"
 #include "qapi/error.h"
+#include "rdma.h"
 
 #define IO_BUF_SIZE 32768
 #define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64)
@@ -314,18 +315,6 @@ void qemu_fflush(QEMUFile *f)
     f->iovcnt = 0;
 }
 
-void ram_control_before_iterate(QEMUFile *f, uint64_t flags)
-{
-    int ret = 0;
-
-    if (f->hooks && f->hooks->before_ram_iterate) {
-        ret = f->hooks->before_ram_iterate(f, flags, NULL);
-        if (ret < 0) {
-            qemu_file_set_error(f, ret);
-        }
-    }
-}
-
 void ram_control_after_iterate(QEMUFile *f, uint64_t flags)
 {
     int ret = 0;
diff --git a/migration/qemu-file.h b/migration/qemu-file.h
index d16cd50448..c898c5c537 100644
--- a/migration/qemu-file.h
+++ b/migration/qemu-file.h
@@ -56,7 +56,6 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f,
                                  uint64_t *bytes_sent);
 
 typedef struct QEMUFileHooks {
-    QEMURamHookFunc *before_ram_iterate;
     QEMURamHookFunc *after_ram_iterate;
     QEMURamHookFunc *hook_ram_load;
     QEMURamSaveFunc *save_page;
@@ -150,7 +149,6 @@ void qemu_fflush(QEMUFile *f);
 void qemu_file_set_blocking(QEMUFile *f, bool block);
 int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size);
 
-void ram_control_before_iterate(QEMUFile *f, uint64_t flags);
 void ram_control_after_iterate(QEMUFile *f, uint64_t flags);
 void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data);
 
diff --git a/migration/ram.c b/migration/ram.c
index 7d81c4a39e..ce5dfc3c86 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -58,6 +58,7 @@
 #include "qemu/iov.h"
 #include "multifd.h"
 #include "sysemu/runstate.h"
+#include "rdma.h"
 #include "options.h"
 
 #include "hw/boards.h" /* for machine_dump_guest_core() */
@@ -3277,7 +3278,10 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
         }
     }
 
-    ram_control_before_iterate(f, RAM_CONTROL_SETUP);
+    ret = qemu_rdma_registration_start(f, RAM_CONTROL_SETUP);
+    if (ret < 0) {
+        qemu_file_set_error(f, ret);
+    }
     ram_control_after_iterate(f, RAM_CONTROL_SETUP);
 
     migration_ops = g_malloc0(sizeof(MigrationOps));
@@ -3337,7 +3341,10 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
         /* Read version before ram_list.blocks */
         smp_rmb();
 
-        ram_control_before_iterate(f, RAM_CONTROL_ROUND);
+        ret = qemu_rdma_registration_start(f, RAM_CONTROL_ROUND);
+        if (ret < 0) {
+            qemu_file_set_error(f, ret);
+        }
 
         t0 = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
         i = 0;
@@ -3442,7 +3449,10 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
             migration_bitmap_sync_precopy(rs);
         }
 
-        ram_control_before_iterate(f, RAM_CONTROL_FINISH);
+        ret = qemu_rdma_registration_start(f, RAM_CONTROL_FINISH);
+        if (ret < 0) {
+            qemu_file_set_error(f, ret);
+        }
 
         /* try transferring iterative blocks of memory */
 
diff --git a/migration/rdma.c b/migration/rdma.c
index b026e98519..d8a194ff26 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -3860,12 +3860,15 @@ static int rdma_load_hook(QEMUFile *f, uint64_t flags, void *data)
     }
 }
 
-static int qemu_rdma_registration_start(QEMUFile *f,
-                                        uint64_t flags, void *data)
+int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags)
 {
     QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f));
     RDMAContext *rdma;
 
+    if (!migrate_rdma()) {
+        return 0;
+    }
+
     RCU_READ_LOCK_GUARD();
     rdma = qatomic_rcu_read(&rioc->rdmaout);
     if (!rdma) {
@@ -4004,7 +4007,6 @@ static const QEMUFileHooks rdma_read_hooks = {
 };
 
 static const QEMUFileHooks rdma_write_hooks = {
-    .before_ram_iterate = qemu_rdma_registration_start,
     .after_ram_iterate  = qemu_rdma_registration_stop,
     .save_page          = qemu_rdma_save_page,
 };
diff --git a/migration/rdma.h b/migration/rdma.h
index de2ba09dc5..901c829c8b 100644
--- a/migration/rdma.h
+++ b/migration/rdma.h
@@ -22,4 +22,10 @@ void rdma_start_outgoing_migration(void *opaque, const char *host_port,
 
 void rdma_start_incoming_migration(const char *host_port, Error **errp);
 
+
+#ifdef CONFIG_RDMA
+int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags);
+#else
+int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) { return 0; }
+#endif
 #endif
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 03/16] migration/rdma: Unfold ram_control_after_iterate()
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 01/16] migration: Create migrate_rdma() Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 02/16] migration/rdma: Unfold ram_control_before_iterate() Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 04/16] migration/rdma: simplify ram_control_load_hook() Juan Quintela
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

Once there:
- Remove unused data parameter
- unfold it in its callers
- change all callers to call qemu_rdma_registration_stop()

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/qemu-file.c | 12 ------------
 migration/qemu-file.h |  2 --
 migration/ram.c       | 17 ++++++++++++++---
 migration/rdma.c      |  8 +++++---
 migration/rdma.h      |  2 ++
 5 files changed, 21 insertions(+), 20 deletions(-)

diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index b6dca23706..22af45a5db 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -315,18 +315,6 @@ void qemu_fflush(QEMUFile *f)
     f->iovcnt = 0;
 }
 
-void ram_control_after_iterate(QEMUFile *f, uint64_t flags)
-{
-    int ret = 0;
-
-    if (f->hooks && f->hooks->after_ram_iterate) {
-        ret = f->hooks->after_ram_iterate(f, flags, NULL);
-        if (ret < 0) {
-            qemu_file_set_error(f, ret);
-        }
-    }
-}
-
 void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data)
 {
     int ret = -EINVAL;
diff --git a/migration/qemu-file.h b/migration/qemu-file.h
index c898c5c537..fac26d7869 100644
--- a/migration/qemu-file.h
+++ b/migration/qemu-file.h
@@ -56,7 +56,6 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f,
                                  uint64_t *bytes_sent);
 
 typedef struct QEMUFileHooks {
-    QEMURamHookFunc *after_ram_iterate;
     QEMURamHookFunc *hook_ram_load;
     QEMURamSaveFunc *save_page;
 } QEMUFileHooks;
@@ -149,7 +148,6 @@ void qemu_fflush(QEMUFile *f);
 void qemu_file_set_blocking(QEMUFile *f, bool block);
 int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size);
 
-void ram_control_after_iterate(QEMUFile *f, uint64_t flags);
 void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data);
 
 /* Whenever this is found in the data stream, the flags
diff --git a/migration/ram.c b/migration/ram.c
index ce5dfc3c86..a5109a0f77 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -3282,7 +3282,11 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
     if (ret < 0) {
         qemu_file_set_error(f, ret);
     }
-    ram_control_after_iterate(f, RAM_CONTROL_SETUP);
+
+    ret = qemu_rdma_registration_stop(f, RAM_CONTROL_SETUP);
+    if (ret < 0) {
+        qemu_file_set_error(f, ret);
+    }
 
     migration_ops = g_malloc0(sizeof(MigrationOps));
     migration_ops->ram_save_target_page = ram_save_target_page_legacy;
@@ -3401,7 +3405,10 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
      * Must occur before EOS (or any QEMUFile operation)
      * because of RDMA protocol.
      */
-    ram_control_after_iterate(f, RAM_CONTROL_ROUND);
+    ret = qemu_rdma_registration_stop(f, RAM_CONTROL_ROUND);
+    if (ret < 0) {
+        qemu_file_set_error(f, ret);
+    }
 
 out:
     if (ret >= 0
@@ -3474,7 +3481,11 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
         qemu_mutex_unlock(&rs->bitmap_mutex);
 
         flush_compressed_data(rs);
-        ram_control_after_iterate(f, RAM_CONTROL_FINISH);
+
+        int ret = qemu_rdma_registration_stop(f, RAM_CONTROL_FINISH);
+        if (ret < 0) {
+            qemu_file_set_error(f, ret);
+        }
     }
 
     if (ret < 0) {
diff --git a/migration/rdma.c b/migration/rdma.c
index d8a194ff26..ca893c0bba 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -3892,14 +3892,17 @@ int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags)
  * Inform dest that dynamic registrations are done for now.
  * First, flush writes, if any.
  */
-static int qemu_rdma_registration_stop(QEMUFile *f,
-                                       uint64_t flags, void *data)
+int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags)
 {
     QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f));
     RDMAContext *rdma;
     RDMAControlHeader head = { .len = 0, .repeat = 1 };
     int ret = 0;
 
+    if (!migrate_rdma()) {
+        return 0;
+    }
+
     RCU_READ_LOCK_GUARD();
     rdma = qatomic_rcu_read(&rioc->rdmaout);
     if (!rdma) {
@@ -4007,7 +4010,6 @@ static const QEMUFileHooks rdma_read_hooks = {
 };
 
 static const QEMUFileHooks rdma_write_hooks = {
-    .after_ram_iterate  = qemu_rdma_registration_stop,
     .save_page          = qemu_rdma_save_page,
 };
 
diff --git a/migration/rdma.h b/migration/rdma.h
index 901c829c8b..a16a8d8bc6 100644
--- a/migration/rdma.h
+++ b/migration/rdma.h
@@ -25,7 +25,9 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp);
 
 #ifdef CONFIG_RDMA
 int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags);
+int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags);
 #else
 int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) { return 0; }
+int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) { return 0; }
 #endif
 #endif
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 04/16] migration/rdma: simplify ram_control_load_hook()
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
                   ` (2 preceding siblings ...)
  2023-05-03 13:18 ` [PATCH v2 03/16] migration/rdma: Unfold ram_control_after_iterate() Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 05/16] migration/rdma: Don't pass the QIOChannelRDMA as an opaque Juan Quintela
                   ` (11 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/qemu-file.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 22af45a5db..9b5e14a2ef 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -317,10 +317,8 @@ void qemu_fflush(QEMUFile *f)
 
 void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data)
 {
-    int ret = -EINVAL;
-
     if (f->hooks && f->hooks->hook_ram_load) {
-        ret = f->hooks->hook_ram_load(f, flags, data);
+        int ret = f->hooks->hook_ram_load(f, flags, data);
         if (ret < 0) {
             qemu_file_set_error(f, ret);
         }
@@ -330,7 +328,7 @@ void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data)
          * that expects there to be a hook on the destination.
          */
         if (flags == RAM_CONTROL_HOOK) {
-            qemu_file_set_error(f, ret);
+            qemu_file_set_error(f, -EINVAL);
         }
     }
 }
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 05/16] migration/rdma: Don't pass the QIOChannelRDMA as an opaque
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
                   ` (3 preceding siblings ...)
  2023-05-03 13:18 ` [PATCH v2 04/16] migration/rdma: simplify ram_control_load_hook() Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:35   ` Daniel P. Berrangé
  2023-05-03 13:18 ` [PATCH v2 06/16] migration/rdma: We can calculate the rioc from the QEMUFile Juan Quintela
                   ` (10 subsequent siblings)
  15 siblings, 1 reply; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

We can calculate it from the QEMUFile like the caller.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/rdma.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/migration/rdma.c b/migration/rdma.c
index ca893c0bba..c37fcab88a 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -3527,7 +3527,7 @@ static int dest_ram_sort_func(const void *a, const void *b)
  *
  * Keep doing this until the source tells us to stop.
  */
-static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque)
+static int qemu_rdma_registration_handle(QEMUFile *f)
 {
     RDMAControlHeader reg_resp = { .len = sizeof(RDMARegisterResult),
                                .type = RDMA_CONTROL_REGISTER_RESULT,
@@ -3539,7 +3539,7 @@ static int qemu_rdma_registration_handle(QEMUFile *f, void *opaque)
                              };
     RDMAControlHeader blocks = { .type = RDMA_CONTROL_RAM_BLOCKS_RESULT,
                                  .repeat = 1 };
-    QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(opaque);
+    QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f));
     RDMAContext *rdma;
     RDMALocalBlocks *local;
     RDMAControlHeader head;
@@ -3852,7 +3852,7 @@ static int rdma_load_hook(QEMUFile *f, uint64_t flags, void *data)
         return rdma_block_notification_handle(rioc, data);
 
     case RAM_CONTROL_HOOK:
-        return qemu_rdma_registration_handle(f, rioc);
+        return qemu_rdma_registration_handle(f);
 
     default:
         /* Shouldn't be called with any other values */
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 06/16] migration/rdma: We can calculate the rioc from the QEMUFile
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
                   ` (4 preceding siblings ...)
  2023-05-03 13:18 ` [PATCH v2 05/16] migration/rdma: Don't pass the QIOChannelRDMA as an opaque Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 07/16] migration/rdma: It makes no sense to recive that flag without RDMA Juan Quintela
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/rdma.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/migration/rdma.c b/migration/rdma.c
index c37fcab88a..11815d1c11 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -3811,9 +3811,10 @@ out:
  * the source.
  */
 static int
-rdma_block_notification_handle(QIOChannelRDMA *rioc, const char *name)
+rdma_block_notification_handle(QEMUFile *f, const char *name)
 {
     RDMAContext *rdma;
+    QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f));
     int curr;
     int found = -1;
 
@@ -3846,10 +3847,9 @@ rdma_block_notification_handle(QIOChannelRDMA *rioc, const char *name)
 
 static int rdma_load_hook(QEMUFile *f, uint64_t flags, void *data)
 {
-    QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f));
     switch (flags) {
     case RAM_CONTROL_BLOCK_REG:
-        return rdma_block_notification_handle(rioc, data);
+        return rdma_block_notification_handle(f, data);
 
     case RAM_CONTROL_HOOK:
         return qemu_rdma_registration_handle(f);
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 07/16] migration/rdma: It makes no sense to recive that flag without RDMA
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
                   ` (5 preceding siblings ...)
  2023-05-03 13:18 ` [PATCH v2 06/16] migration/rdma: We can calculate the rioc from the QEMUFile Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 08/16] migration: Make RAM_SAVE_FLAG_HOOK a normal case entry Juan Quintela
                   ` (8 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

This could only happen if the source send
RAM_SAVE_FLAG_HOOK (i.e. rdma) and destination don't have CONFIG_RDMA.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/qemu-file.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 9b5e14a2ef..014db96984 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -322,14 +322,6 @@ void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data)
         if (ret < 0) {
             qemu_file_set_error(f, ret);
         }
-    } else {
-        /*
-         * Hook is a hook specifically requested by the source sending a flag
-         * that expects there to be a hook on the destination.
-         */
-        if (flags == RAM_CONTROL_HOOK) {
-            qemu_file_set_error(f, -EINVAL);
-        }
     }
 }
 
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 08/16] migration: Make RAM_SAVE_FLAG_HOOK a normal case entry
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
                   ` (6 preceding siblings ...)
  2023-05-03 13:18 ` [PATCH v2 07/16] migration/rdma: It makes no sense to recive that flag without RDMA Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 09/16] migration/rdma: Remove all uses of RAM_CONTROL_HOOK Juan Quintela
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

Fixes this commit, clearly a bad merge after a rebase or similar, it
should have been its own case since that point.

commit 5b0e9dd46fbda5152566a4a26fd96bc0d0452bf7
Author: Peter Lieven <pl@kamp.de>
Date:   Tue Jun 24 11:32:36 2014 +0200

    migration: catch unknown flag combinations in ram_load

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/ram.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index a5109a0f77..67ba2d7f7e 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -4466,14 +4466,12 @@ static int ram_load_precopy(QEMUFile *f)
                 multifd_recv_sync_main();
             }
             break;
+        case RAM_SAVE_FLAG_HOOK:
+            ram_control_load_hook(f, RAM_CONTROL_HOOK, NULL);
+            break;
         default:
-            if (flags & RAM_SAVE_FLAG_HOOK) {
-                ram_control_load_hook(f, RAM_CONTROL_HOOK, NULL);
-            } else {
-                error_report("Unknown combination of migration flags: 0x%x",
-                             flags);
-                ret = -EINVAL;
-            }
+            error_report("Unknown combination of migration flags: 0x%x", flags);
+            ret = -EINVAL;
         }
         if (!ret) {
             ret = qemu_file_get_error(f);
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 09/16] migration/rdma: Remove all uses of RAM_CONTROL_HOOK
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
                   ` (7 preceding siblings ...)
  2023-05-03 13:18 ` [PATCH v2 08/16] migration: Make RAM_SAVE_FLAG_HOOK a normal case entry Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 10/16] migration/rdma: Unfold hook_ram_load() Juan Quintela
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

Instead of going trhough ram_control_load_hook(), call
qemu_rdma_registration_handle() directly.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/qemu-file.h | 1 -
 migration/ram.c       | 5 ++++-
 migration/rdma.c      | 9 +++++----
 migration/rdma.h      | 2 ++
 4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/migration/qemu-file.h b/migration/qemu-file.h
index fac26d7869..7623e3c475 100644
--- a/migration/qemu-file.h
+++ b/migration/qemu-file.h
@@ -41,7 +41,6 @@ typedef int (QEMURamHookFunc)(QEMUFile *f, uint64_t flags, void *data);
  */
 #define RAM_CONTROL_SETUP     0
 #define RAM_CONTROL_ROUND     1
-#define RAM_CONTROL_HOOK      2
 #define RAM_CONTROL_FINISH    3
 #define RAM_CONTROL_BLOCK_REG 4
 
diff --git a/migration/ram.c b/migration/ram.c
index 67ba2d7f7e..c0110ca8cb 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -4467,7 +4467,10 @@ static int ram_load_precopy(QEMUFile *f)
             }
             break;
         case RAM_SAVE_FLAG_HOOK:
-            ram_control_load_hook(f, RAM_CONTROL_HOOK, NULL);
+            ret = qemu_rdma_registration_handle(f);
+            if (ret < 0) {
+                qemu_file_set_error(f, ret);
+            }
             break;
         default:
             error_report("Unknown combination of migration flags: 0x%x", flags);
diff --git a/migration/rdma.c b/migration/rdma.c
index 11815d1c11..e0f41a9b97 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -3527,7 +3527,7 @@ static int dest_ram_sort_func(const void *a, const void *b)
  *
  * Keep doing this until the source tells us to stop.
  */
-static int qemu_rdma_registration_handle(QEMUFile *f)
+int qemu_rdma_registration_handle(QEMUFile *f)
 {
     RDMAControlHeader reg_resp = { .len = sizeof(RDMARegisterResult),
                                .type = RDMA_CONTROL_REGISTER_RESULT,
@@ -3554,6 +3554,10 @@ static int qemu_rdma_registration_handle(QEMUFile *f)
     int count = 0;
     int i = 0;
 
+    if (!migrate_rdma()) {
+        return 0;
+    }
+
     RCU_READ_LOCK_GUARD();
     rdma = qatomic_rcu_read(&rioc->rdmain);
 
@@ -3851,9 +3855,6 @@ static int rdma_load_hook(QEMUFile *f, uint64_t flags, void *data)
     case RAM_CONTROL_BLOCK_REG:
         return rdma_block_notification_handle(f, data);
 
-    case RAM_CONTROL_HOOK:
-        return qemu_rdma_registration_handle(f);
-
     default:
         /* Shouldn't be called with any other values */
         abort();
diff --git a/migration/rdma.h b/migration/rdma.h
index a16a8d8bc6..8d0253047c 100644
--- a/migration/rdma.h
+++ b/migration/rdma.h
@@ -24,9 +24,11 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp);
 
 
 #ifdef CONFIG_RDMA
+int qemu_rdma_registration_handle(QEMUFile *f);
 int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags);
 int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags);
 #else
+int qemu_rdma_registration_handle(QEMUFile *f) { return 0; }
 int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) { return 0; }
 int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) { return 0; }
 #endif
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 10/16] migration/rdma: Unfold hook_ram_load()
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
                   ` (8 preceding siblings ...)
  2023-05-03 13:18 ` [PATCH v2 09/16] migration/rdma: Remove all uses of RAM_CONTROL_HOOK Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 11/16] migration/rdma: Make ram_control_save_page() use exported interfaces Juan Quintela
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

There is only one flag called with: RAM_CONTROL_BLOCK_REG.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/qemu-file.c | 10 ----------
 migration/qemu-file.h | 11 -----------
 migration/ram.c       |  6 ++++--
 migration/rdma.c      | 29 +++++++++--------------------
 migration/rdma.h      |  2 ++
 5 files changed, 15 insertions(+), 43 deletions(-)

diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 014db96984..9d86900efe 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -315,16 +315,6 @@ void qemu_fflush(QEMUFile *f)
     f->iovcnt = 0;
 }
 
-void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data)
-{
-    if (f->hooks && f->hooks->hook_ram_load) {
-        int ret = f->hooks->hook_ram_load(f, flags, data);
-        if (ret < 0) {
-            qemu_file_set_error(f, ret);
-        }
-    }
-}
-
 size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,
                              ram_addr_t offset, size_t size,
                              uint64_t *bytes_sent)
diff --git a/migration/qemu-file.h b/migration/qemu-file.h
index 7623e3c475..d69f5d65e8 100644
--- a/migration/qemu-file.h
+++ b/migration/qemu-file.h
@@ -29,20 +29,12 @@
 #include "exec/cpu-common.h"
 #include "io/channel.h"
 
-/*
- * This function provides hooks around different
- * stages of RAM migration.
- * 'data' is call specific data associated with the 'flags' value
- */
-typedef int (QEMURamHookFunc)(QEMUFile *f, uint64_t flags, void *data);
-
 /*
  * Constants used by ram_control_* hooks
  */
 #define RAM_CONTROL_SETUP     0
 #define RAM_CONTROL_ROUND     1
 #define RAM_CONTROL_FINISH    3
-#define RAM_CONTROL_BLOCK_REG 4
 
 /*
  * This function allows override of where the RAM page
@@ -55,7 +47,6 @@ typedef size_t (QEMURamSaveFunc)(QEMUFile *f,
                                  uint64_t *bytes_sent);
 
 typedef struct QEMUFileHooks {
-    QEMURamHookFunc *hook_ram_load;
     QEMURamSaveFunc *save_page;
 } QEMUFileHooks;
 
@@ -147,8 +138,6 @@ void qemu_fflush(QEMUFile *f);
 void qemu_file_set_blocking(QEMUFile *f, bool block);
 int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size);
 
-void ram_control_load_hook(QEMUFile *f, uint64_t flags, void *data);
-
 /* Whenever this is found in the data stream, the flags
  * will be passed to ram_control_load_hook in the incoming-migration
  * side. This lets before_ram_iterate/after_ram_iterate add
diff --git a/migration/ram.c b/migration/ram.c
index c0110ca8cb..d29dd67d5f 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -4418,8 +4418,10 @@ static int ram_load_precopy(QEMUFile *f)
                             ret = -EINVAL;
                         }
                     }
-                    ram_control_load_hook(f, RAM_CONTROL_BLOCK_REG,
-                                          block->idstr);
+                    ret = rdma_block_notification_handle(f, block->idstr);
+                    if (ret < 0) {
+                        qemu_file_set_error(f, ret);
+                    }
                 } else {
                     error_report("Unknown ramblock \"%s\", cannot "
                                  "accept migration", id);
diff --git a/migration/rdma.c b/migration/rdma.c
index e0f41a9b97..a326606fd2 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -3808,20 +3808,22 @@ out:
 }
 
 /* Destination:
- * Called via a ram_control_load_hook during the initial RAM load section which
- * lists the RAMBlocks by name.  This lets us know the order of the RAMBlocks
- * on the source.
- * We've already built our local RAMBlock list, but not yet sent the list to
- * the source.
+ * Called during the initial RAM load section which lists the
+ * RAMBlocks by name.  This lets us know the order of the RAMBlocks on
+ * the source.  We've already built our local RAMBlock list, but not
+ * yet sent the list to the source.
  */
-static int
-rdma_block_notification_handle(QEMUFile *f, const char *name)
+int rdma_block_notification_handle(QEMUFile *f, const char *name)
 {
     RDMAContext *rdma;
     QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f));
     int curr;
     int found = -1;
 
+    if (!migrate_rdma()) {
+        return 0;
+    }
+
     RCU_READ_LOCK_GUARD();
     rdma = qatomic_rcu_read(&rioc->rdmain);
 
@@ -3849,18 +3851,6 @@ rdma_block_notification_handle(QEMUFile *f, const char *name)
     return 0;
 }
 
-static int rdma_load_hook(QEMUFile *f, uint64_t flags, void *data)
-{
-    switch (flags) {
-    case RAM_CONTROL_BLOCK_REG:
-        return rdma_block_notification_handle(f, data);
-
-    default:
-        /* Shouldn't be called with any other values */
-        abort();
-    }
-}
-
 int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags)
 {
     QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f));
@@ -4007,7 +3997,6 @@ err:
 }
 
 static const QEMUFileHooks rdma_read_hooks = {
-    .hook_ram_load = rdma_load_hook,
 };
 
 static const QEMUFileHooks rdma_write_hooks = {
diff --git a/migration/rdma.h b/migration/rdma.h
index 8d0253047c..1266a90e07 100644
--- a/migration/rdma.h
+++ b/migration/rdma.h
@@ -27,9 +27,11 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp);
 int qemu_rdma_registration_handle(QEMUFile *f);
 int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags);
 int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags);
+int rdma_block_notification_handle(QEMUFile *f, const char *name);
 #else
 int qemu_rdma_registration_handle(QEMUFile *f) { return 0; }
 int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) { return 0; }
 int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) { return 0; }
+int rdma_block_notification_handle(QEMUFile *f, const char *name) { return 0; }
 #endif
 #endif
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 11/16] migration/rdma: Make ram_control_save_page() use exported interfaces
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
                   ` (9 preceding siblings ...)
  2023-05-03 13:18 ` [PATCH v2 10/16] migration/rdma: Unfold hook_ram_load() Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 12/16] migration/rdma: Create rdma_control_save_page() Juan Quintela
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/qemu-file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 9d86900efe..17b3c2ea21 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -323,7 +323,7 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,
         int ret = f->hooks->save_page(f, block_offset,
                                       offset, size, bytes_sent);
         if (ret != RAM_SAVE_CONTROL_NOT_SUPP) {
-            f->rate_limit_used += size;
+            qemu_file_acct_rate_limit(f, size);
         }
 
         if (ret != RAM_SAVE_CONTROL_DELAYED &&
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 12/16] migration/rdma: Create rdma_control_save_page()
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
                   ` (10 preceding siblings ...)
  2023-05-03 13:18 ` [PATCH v2 11/16] migration/rdma: Make ram_control_save_page() use exported interfaces Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 13/16] qemu-file: Remove QEMUFileHooks Juan Quintela
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

The only user of ram_control_save_page() and save_page() hook was
rdma. Just move the function to rdma.c, rename it to
rdma_control_save_page().

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/qemu-file.c | 26 --------------------------
 migration/qemu-file.h | 14 --------------
 migration/ram.c       |  4 ++--
 migration/rdma.c      | 26 +++++++++++++++++++++++++-
 migration/rdma.h      |  8 ++++++++
 5 files changed, 35 insertions(+), 43 deletions(-)

diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 17b3c2ea21..8d3f33fe41 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -315,32 +315,6 @@ void qemu_fflush(QEMUFile *f)
     f->iovcnt = 0;
 }
 
-size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,
-                             ram_addr_t offset, size_t size,
-                             uint64_t *bytes_sent)
-{
-    if (f->hooks && f->hooks->save_page) {
-        int ret = f->hooks->save_page(f, block_offset,
-                                      offset, size, bytes_sent);
-        if (ret != RAM_SAVE_CONTROL_NOT_SUPP) {
-            qemu_file_acct_rate_limit(f, size);
-        }
-
-        if (ret != RAM_SAVE_CONTROL_DELAYED &&
-            ret != RAM_SAVE_CONTROL_NOT_SUPP) {
-            if (bytes_sent && *bytes_sent > 0) {
-                qemu_file_credit_transfer(f, *bytes_sent);
-            } else if (ret < 0) {
-                qemu_file_set_error(f, ret);
-            }
-        }
-
-        return ret;
-    }
-
-    return RAM_SAVE_CONTROL_NOT_SUPP;
-}
-
 /*
  * Attempt to fill the buffer from the underlying file
  * Returns the number of bytes read, or negative value for an error.
diff --git a/migration/qemu-file.h b/migration/qemu-file.h
index d69f5d65e8..ae3a704772 100644
--- a/migration/qemu-file.h
+++ b/migration/qemu-file.h
@@ -36,18 +36,7 @@
 #define RAM_CONTROL_ROUND     1
 #define RAM_CONTROL_FINISH    3
 
-/*
- * This function allows override of where the RAM page
- * is saved (such as RDMA, for example.)
- */
-typedef size_t (QEMURamSaveFunc)(QEMUFile *f,
-                                 ram_addr_t block_offset,
-                                 ram_addr_t offset,
-                                 size_t size,
-                                 uint64_t *bytes_sent);
-
 typedef struct QEMUFileHooks {
-    QEMURamSaveFunc *save_page;
 } QEMUFileHooks;
 
 QEMUFile *qemu_file_new_input(QIOChannel *ioc);
@@ -148,9 +137,6 @@ int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size);
 #define RAM_SAVE_CONTROL_NOT_SUPP -1000
 #define RAM_SAVE_CONTROL_DELAYED  -2000
 
-size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,
-                             ram_addr_t offset, size_t size,
-                             uint64_t *bytes_sent);
 QIOChannel *qemu_file_get_ioc(QEMUFile *file);
 
 #endif
diff --git a/migration/ram.c b/migration/ram.c
index d29dd67d5f..a085ce8cae 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -1342,8 +1342,8 @@ static bool control_save_page(PageSearchStatus *pss, RAMBlock *block,
     int ret;
 
     *pages = -1;
-    ret = ram_control_save_page(pss->pss_channel, block->offset, offset,
-                                TARGET_PAGE_SIZE, &bytes_xmit);
+    ret = rdma_control_save_page(pss->pss_channel, block->offset, offset,
+                                 TARGET_PAGE_SIZE, &bytes_xmit);
     if (ret == RAM_SAVE_CONTROL_NOT_SUPP) {
         return false;
     }
diff --git a/migration/rdma.c b/migration/rdma.c
index a326606fd2..c984a2840a 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -3315,6 +3315,31 @@ err:
     return ret;
 }
 
+size_t rdma_control_save_page(QEMUFile *f, ram_addr_t block_offset,
+                              ram_addr_t offset, size_t size,
+                              uint64_t *bytes_sent)
+{
+    if (!migrate_rdma()) {
+        return RAM_SAVE_CONTROL_NOT_SUPP;
+    }
+
+    int ret = qemu_rdma_save_page(f, block_offset, offset, size, bytes_sent);
+    if (ret != RAM_SAVE_CONTROL_NOT_SUPP) {
+        qemu_file_acct_rate_limit(f, size);
+    }
+
+    if (ret != RAM_SAVE_CONTROL_DELAYED &&
+        ret != RAM_SAVE_CONTROL_NOT_SUPP) {
+        if (bytes_sent && *bytes_sent > 0) {
+            qemu_file_credit_transfer(f, *bytes_sent);
+        } else if (ret < 0) {
+            qemu_file_set_error(f, ret);
+        }
+    }
+    return ret;
+}
+
+
 static void rdma_accept_incoming_migration(void *opaque);
 
 static void rdma_cm_poll_handler(void *opaque)
@@ -4000,7 +4025,6 @@ static const QEMUFileHooks rdma_read_hooks = {
 };
 
 static const QEMUFileHooks rdma_write_hooks = {
-    .save_page          = qemu_rdma_save_page,
 };
 
 
diff --git a/migration/rdma.h b/migration/rdma.h
index 1266a90e07..ed3650ef67 100644
--- a/migration/rdma.h
+++ b/migration/rdma.h
@@ -17,6 +17,8 @@
 #ifndef QEMU_MIGRATION_RDMA_H
 #define QEMU_MIGRATION_RDMA_H
 
+#include "exec/memory.h"
+
 void rdma_start_outgoing_migration(void *opaque, const char *host_port,
                                    Error **errp);
 
@@ -28,10 +30,16 @@ int qemu_rdma_registration_handle(QEMUFile *f);
 int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags);
 int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags);
 int rdma_block_notification_handle(QEMUFile *f, const char *name);
+size_t rdma_control_save_page(QEMUFile *f, ram_addr_t block_offset,
+                              ram_addr_t offset, size_t size,
+                              uint64_t *bytes_sent);
 #else
 int qemu_rdma_registration_handle(QEMUFile *f) { return 0; }
 int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) { return 0; }
 int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) { return 0; }
 int rdma_block_notification_handle(QEMUFile *f, const char *name) { return 0; }
+size_t rdma_control_save_page(QEMUFile *f, ram_addr_t block_offset,
+                              ram_addr_t offset, size_t size,
+                              uint64_t *bytes_sent) { return false; }
 #endif
 #endif
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 13/16] qemu-file: Remove QEMUFileHooks
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
                   ` (11 preceding siblings ...)
  2023-05-03 13:18 ` [PATCH v2 12/16] migration/rdma: Create rdma_control_save_page() Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 14/16] migration/rdma: Move rdma constants from qemu-file.h to rdma.h Juan Quintela
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

The only user was rdma, and its use is gone.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/qemu-file.c | 6 ------
 migration/qemu-file.h | 4 ----
 migration/rdma.c      | 9 ---------
 3 files changed, 19 deletions(-)

diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 8d3f33fe41..c0c2195a6e 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -36,7 +36,6 @@
 #define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64)
 
 struct QEMUFile {
-    const QEMUFileHooks *hooks;
     QIOChannel *ioc;
     bool is_writable;
 
@@ -160,11 +159,6 @@ QEMUFile *qemu_file_new_input(QIOChannel *ioc)
     return qemu_file_new_impl(ioc, false);
 }
 
-void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks)
-{
-    f->hooks = hooks;
-}
-
 /*
  * Get last error for stream f with optional Error*
  *
diff --git a/migration/qemu-file.h b/migration/qemu-file.h
index ae3a704772..9c99914b21 100644
--- a/migration/qemu-file.h
+++ b/migration/qemu-file.h
@@ -36,12 +36,8 @@
 #define RAM_CONTROL_ROUND     1
 #define RAM_CONTROL_FINISH    3
 
-typedef struct QEMUFileHooks {
-} QEMUFileHooks;
-
 QEMUFile *qemu_file_new_input(QIOChannel *ioc);
 QEMUFile *qemu_file_new_output(QIOChannel *ioc);
-void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks);
 int qemu_fclose(QEMUFile *f);
 
 /*
diff --git a/migration/rdma.c b/migration/rdma.c
index c984a2840a..78d8f5a199 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -4021,13 +4021,6 @@ err:
     return ret;
 }
 
-static const QEMUFileHooks rdma_read_hooks = {
-};
-
-static const QEMUFileHooks rdma_write_hooks = {
-};
-
-
 static void qio_channel_rdma_finalize(Object *obj)
 {
     QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(obj);
@@ -4086,12 +4079,10 @@ static QEMUFile *qemu_fopen_rdma(RDMAContext *rdma, const char *mode)
         rioc->file = qemu_file_new_output(QIO_CHANNEL(rioc));
         rioc->rdmaout = rdma;
         rioc->rdmain = rdma->return_path;
-        qemu_file_set_hooks(rioc->file, &rdma_write_hooks);
     } else {
         rioc->file = qemu_file_new_input(QIO_CHANNEL(rioc));
         rioc->rdmain = rdma;
         rioc->rdmaout = rdma->return_path;
-        qemu_file_set_hooks(rioc->file, &rdma_read_hooks);
     }
 
     return rioc->file;
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 14/16] migration/rdma: Move rdma constants from qemu-file.h to rdma.h
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
                   ` (12 preceding siblings ...)
  2023-05-03 13:18 ` [PATCH v2 13/16] qemu-file: Remove QEMUFileHooks Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 15/16] migration/rdma: Remove qemu_ prefix from exported functions Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 16/16] migration/rdma: If we are in postcopy don't do anything Juan Quintela
  15 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/qemu-file.h | 17 -----------------
 migration/ram.c       |  2 +-
 migration/rdma.h      | 16 ++++++++++++++++
 3 files changed, 17 insertions(+), 18 deletions(-)

diff --git a/migration/qemu-file.h b/migration/qemu-file.h
index 9c99914b21..5129b6f196 100644
--- a/migration/qemu-file.h
+++ b/migration/qemu-file.h
@@ -29,13 +29,6 @@
 #include "exec/cpu-common.h"
 #include "io/channel.h"
 
-/*
- * Constants used by ram_control_* hooks
- */
-#define RAM_CONTROL_SETUP     0
-#define RAM_CONTROL_ROUND     1
-#define RAM_CONTROL_FINISH    3
-
 QEMUFile *qemu_file_new_input(QIOChannel *ioc);
 QEMUFile *qemu_file_new_output(QIOChannel *ioc);
 int qemu_fclose(QEMUFile *f);
@@ -123,16 +116,6 @@ void qemu_fflush(QEMUFile *f);
 void qemu_file_set_blocking(QEMUFile *f, bool block);
 int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size);
 
-/* Whenever this is found in the data stream, the flags
- * will be passed to ram_control_load_hook in the incoming-migration
- * side. This lets before_ram_iterate/after_ram_iterate add
- * transport-specific sections to the RAM migration data.
- */
-#define RAM_SAVE_FLAG_HOOK     0x80
-
-#define RAM_SAVE_CONTROL_NOT_SUPP -1000
-#define RAM_SAVE_CONTROL_DELAYED  -2000
-
 QIOChannel *qemu_file_get_ioc(QEMUFile *file);
 
 #endif
diff --git a/migration/ram.c b/migration/ram.c
index a085ce8cae..ac2296d740 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -86,7 +86,7 @@
 #define RAM_SAVE_FLAG_EOS      0x10
 #define RAM_SAVE_FLAG_CONTINUE 0x20
 #define RAM_SAVE_FLAG_XBZRLE   0x40
-/* 0x80 is reserved in qemu-file.h for RAM_SAVE_FLAG_HOOK */
+/* 0x80 is reserved in rdma.h for RAM_SAVE_FLAG_HOOK */
 #define RAM_SAVE_FLAG_COMPRESS_PAGE    0x100
 #define RAM_SAVE_FLAG_MULTIFD_FLUSH    0x200
 /* We can't use any flag that is bigger than 0x200 */
diff --git a/migration/rdma.h b/migration/rdma.h
index ed3650ef67..96ec2cc8f0 100644
--- a/migration/rdma.h
+++ b/migration/rdma.h
@@ -24,6 +24,22 @@ void rdma_start_outgoing_migration(void *opaque, const char *host_port,
 
 void rdma_start_incoming_migration(const char *host_port, Error **errp);
 
+/*
+ * Constants used by rdma return codes
+ */
+#define RAM_CONTROL_SETUP     0
+#define RAM_CONTROL_ROUND     1
+#define RAM_CONTROL_FINISH    3
+
+/*
+ * Whenever this is found in the data stream, the flags
+ * will be passed to rdma functions in the incoming-migration
+ * side.
+ */
+#define RAM_SAVE_FLAG_HOOK     0x80
+
+#define RAM_SAVE_CONTROL_NOT_SUPP -1000
+#define RAM_SAVE_CONTROL_DELAYED  -2000
 
 #ifdef CONFIG_RDMA
 int qemu_rdma_registration_handle(QEMUFile *f);
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 15/16] migration/rdma: Remove qemu_ prefix from exported functions
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
                   ` (13 preceding siblings ...)
  2023-05-03 13:18 ` [PATCH v2 14/16] migration/rdma: Move rdma constants from qemu-file.h to rdma.h Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  2023-05-03 13:18 ` [PATCH v2 16/16] migration/rdma: If we are in postcopy don't do anything Juan Quintela
  15 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

Functions are long enough even without this.

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/ram.c        | 14 +++++++-------
 migration/rdma.c       | 40 +++++++++++++++++++---------------------
 migration/rdma.h       | 12 ++++++------
 migration/trace-events | 28 ++++++++++++++--------------
 4 files changed, 46 insertions(+), 48 deletions(-)

diff --git a/migration/ram.c b/migration/ram.c
index ac2296d740..0694b9dfec 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -3278,12 +3278,12 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
         }
     }
 
-    ret = qemu_rdma_registration_start(f, RAM_CONTROL_SETUP);
+    ret = rdma_registration_start(f, RAM_CONTROL_SETUP);
     if (ret < 0) {
         qemu_file_set_error(f, ret);
     }
 
-    ret = qemu_rdma_registration_stop(f, RAM_CONTROL_SETUP);
+    ret = rdma_registration_stop(f, RAM_CONTROL_SETUP);
     if (ret < 0) {
         qemu_file_set_error(f, ret);
     }
@@ -3345,7 +3345,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
         /* Read version before ram_list.blocks */
         smp_rmb();
 
-        ret = qemu_rdma_registration_start(f, RAM_CONTROL_ROUND);
+        ret = rdma_registration_start(f, RAM_CONTROL_ROUND);
         if (ret < 0) {
             qemu_file_set_error(f, ret);
         }
@@ -3405,7 +3405,7 @@ static int ram_save_iterate(QEMUFile *f, void *opaque)
      * Must occur before EOS (or any QEMUFile operation)
      * because of RDMA protocol.
      */
-    ret = qemu_rdma_registration_stop(f, RAM_CONTROL_ROUND);
+    ret = rdma_registration_stop(f, RAM_CONTROL_ROUND);
     if (ret < 0) {
         qemu_file_set_error(f, ret);
     }
@@ -3456,7 +3456,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
             migration_bitmap_sync_precopy(rs);
         }
 
-        ret = qemu_rdma_registration_start(f, RAM_CONTROL_FINISH);
+        ret = rdma_registration_start(f, RAM_CONTROL_FINISH);
         if (ret < 0) {
             qemu_file_set_error(f, ret);
         }
@@ -3482,7 +3482,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
 
         flush_compressed_data(rs);
 
-        int ret = qemu_rdma_registration_stop(f, RAM_CONTROL_FINISH);
+        int ret = rdma_registration_stop(f, RAM_CONTROL_FINISH);
         if (ret < 0) {
             qemu_file_set_error(f, ret);
         }
@@ -4469,7 +4469,7 @@ static int ram_load_precopy(QEMUFile *f)
             }
             break;
         case RAM_SAVE_FLAG_HOOK:
-            ret = qemu_rdma_registration_handle(f);
+            ret = rdma_registration_handle(f);
             if (ret < 0) {
                 qemu_file_set_error(f, ret);
             }
diff --git a/migration/rdma.c b/migration/rdma.c
index 78d8f5a199..d6b4398620 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -3552,7 +3552,7 @@ static int dest_ram_sort_func(const void *a, const void *b)
  *
  * Keep doing this until the source tells us to stop.
  */
-int qemu_rdma_registration_handle(QEMUFile *f)
+int rdma_registration_handle(QEMUFile *f)
 {
     RDMAControlHeader reg_resp = { .len = sizeof(RDMARegisterResult),
                                .type = RDMA_CONTROL_REGISTER_RESULT,
@@ -3594,7 +3594,7 @@ int qemu_rdma_registration_handle(QEMUFile *f)
 
     local = &rdma->local_ram_blocks;
     do {
-        trace_qemu_rdma_registration_handle_wait();
+        trace_rdma_registration_handle_wait();
 
         ret = qemu_rdma_exchange_recv(rdma, &head, RDMA_CONTROL_NONE);
 
@@ -3614,9 +3614,9 @@ int qemu_rdma_registration_handle(QEMUFile *f)
             comp = (RDMACompress *) rdma->wr_data[idx].control_curr;
             network_to_compress(comp);
 
-            trace_qemu_rdma_registration_handle_compress(comp->length,
-                                                         comp->block_idx,
-                                                         comp->offset);
+            trace_rdma_registration_handle_compress(comp->length,
+                                                    comp->block_idx,
+                                                    comp->offset);
             if (comp->block_idx >= rdma->local_ram_blocks.nb_blocks) {
                 error_report("rdma: 'compress' bad block index %u (vs %d)",
                              (unsigned int)comp->block_idx,
@@ -3633,11 +3633,11 @@ int qemu_rdma_registration_handle(QEMUFile *f)
             break;
 
         case RDMA_CONTROL_REGISTER_FINISHED:
-            trace_qemu_rdma_registration_handle_finished();
+            trace_rdma_registration_handle_finished();
             goto out;
 
         case RDMA_CONTROL_RAM_BLOCKS_REQUEST:
-            trace_qemu_rdma_registration_handle_ram_blocks();
+            trace_rdma_registration_handle_ram_blocks();
 
             /* Sort our local RAM Block list so it's the same as the source,
              * we can do this since we've filled in a src_index in the list
@@ -3677,7 +3677,7 @@ int qemu_rdma_registration_handle(QEMUFile *f)
                 rdma->dest_blocks[i].length = local->block[i].length;
 
                 dest_block_to_network(&rdma->dest_blocks[i]);
-                trace_qemu_rdma_registration_handle_ram_blocks_loop(
+                trace_rdma_registration_handle_ram_blocks_loop(
                     local->block[i].block_name,
                     local->block[i].offset,
                     local->block[i].length,
@@ -3699,7 +3699,7 @@ int qemu_rdma_registration_handle(QEMUFile *f)
 
             break;
         case RDMA_CONTROL_REGISTER_REQUEST:
-            trace_qemu_rdma_registration_handle_register(head.repeat);
+            trace_rdma_registration_handle_register(head.repeat);
 
             reg_resp.repeat = head.repeat;
             registers = (RDMARegister *) rdma->wr_data[idx].control_curr;
@@ -3713,7 +3713,7 @@ int qemu_rdma_registration_handle(QEMUFile *f)
 
                 reg_result = &results[count];
 
-                trace_qemu_rdma_registration_handle_register_loop(count,
+                trace_rdma_registration_handle_register_loop(count,
                          reg->current_index, reg->key.current_addr, reg->chunks);
 
                 if (reg->current_index >= rdma->local_ram_blocks.nb_blocks) {
@@ -3765,8 +3765,7 @@ int qemu_rdma_registration_handle(QEMUFile *f)
 
                 reg_result->host_addr = (uintptr_t)block->local_host_addr;
 
-                trace_qemu_rdma_registration_handle_register_rkey(
-                                                           reg_result->rkey);
+                trace_rdma_registration_handle_register_rkey(reg_result->rkey);
 
                 result_to_network(reg_result);
             }
@@ -3780,7 +3779,7 @@ int qemu_rdma_registration_handle(QEMUFile *f)
             }
             break;
         case RDMA_CONTROL_UNREGISTER_REQUEST:
-            trace_qemu_rdma_registration_handle_unregister(head.repeat);
+            trace_rdma_registration_handle_unregister(head.repeat);
             unreg_resp.repeat = head.repeat;
             registers = (RDMARegister *) rdma->wr_data[idx].control_curr;
 
@@ -3788,7 +3787,7 @@ int qemu_rdma_registration_handle(QEMUFile *f)
                 reg = &registers[count];
                 network_to_register(reg);
 
-                trace_qemu_rdma_registration_handle_unregister_loop(count,
+                trace_rdma_registration_handle_unregister_loop(count,
                            reg->current_index, reg->key.chunk);
 
                 block = &(rdma->local_ram_blocks.block[reg->current_index]);
@@ -3804,8 +3803,7 @@ int qemu_rdma_registration_handle(QEMUFile *f)
 
                 rdma->total_registrations--;
 
-                trace_qemu_rdma_registration_handle_unregister_success(
-                                                       reg->key.chunk);
+                trace_rdma_registration_handle_unregister_success(reg->key.chunk);
             }
 
             ret = qemu_rdma_post_send_control(rdma, NULL, &unreg_resp);
@@ -3876,7 +3874,7 @@ int rdma_block_notification_handle(QEMUFile *f, const char *name)
     return 0;
 }
 
-int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags)
+int rdma_registration_start(QEMUFile *f, uint64_t flags)
 {
     QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f));
     RDMAContext *rdma;
@@ -3897,7 +3895,7 @@ int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags)
         return 0;
     }
 
-    trace_qemu_rdma_registration_start(flags);
+    trace_rdma_registration_start(flags);
     qemu_put_be64(f, RAM_SAVE_FLAG_HOOK);
     qemu_fflush(f);
 
@@ -3908,7 +3906,7 @@ int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags)
  * Inform dest that dynamic registrations are done for now.
  * First, flush writes, if any.
  */
-int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags)
+int rdma_registration_stop(QEMUFile *f, uint64_t flags)
 {
     QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(qemu_file_get_ioc(f));
     RDMAContext *rdma;
@@ -3944,7 +3942,7 @@ int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags)
         int reg_result_idx, i, nb_dest_blocks;
 
         head.type = RDMA_CONTROL_RAM_BLOCKS_REQUEST;
-        trace_qemu_rdma_registration_stop_ram();
+        trace_rdma_registration_stop_ram();
 
         /*
          * Make sure that we parallelize the pinning on both sides.
@@ -4006,7 +4004,7 @@ int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags)
         }
     }
 
-    trace_qemu_rdma_registration_stop(flags);
+    trace_rdma_registration_stop(flags);
 
     head.type = RDMA_CONTROL_REGISTER_FINISHED;
     ret = qemu_rdma_exchange_send(rdma, &head, NULL, NULL, NULL, NULL);
diff --git a/migration/rdma.h b/migration/rdma.h
index 96ec2cc8f0..982063abc0 100644
--- a/migration/rdma.h
+++ b/migration/rdma.h
@@ -42,17 +42,17 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp);
 #define RAM_SAVE_CONTROL_DELAYED  -2000
 
 #ifdef CONFIG_RDMA
-int qemu_rdma_registration_handle(QEMUFile *f);
-int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags);
-int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags);
+int rdma_registration_handle(QEMUFile *f);
+int rdma_registration_start(QEMUFile *f, uint64_t flags);
+int rdma_registration_stop(QEMUFile *f, uint64_t flags);
 int rdma_block_notification_handle(QEMUFile *f, const char *name);
 size_t rdma_control_save_page(QEMUFile *f, ram_addr_t block_offset,
                               ram_addr_t offset, size_t size,
                               uint64_t *bytes_sent);
 #else
-int qemu_rdma_registration_handle(QEMUFile *f) { return 0; }
-int qemu_rdma_registration_start(QEMUFile *f, uint64_t flags) { return 0; }
-int qemu_rdma_registration_stop(QEMUFile *f, uint64_t flags) { return 0; }
+int rdma_registration_handle(QEMUFile *f) { return 0; }
+int rdma_registration_start(QEMUFile *f, uint64_t flags) { return 0; }
+int rdma_registration_stop(QEMUFile *f, uint64_t flags) { return 0; }
 int rdma_block_notification_handle(QEMUFile *f, const char *name) { return 0; }
 size_t rdma_control_save_page(QEMUFile *f, ram_addr_t block_offset,
                               ram_addr_t offset, size_t size,
diff --git a/migration/trace-events b/migration/trace-events
index 92161eeac5..7aa6d2b2fc 100644
--- a/migration/trace-events
+++ b/migration/trace-events
@@ -221,20 +221,6 @@ qemu_rdma_post_send_control(const char *desc) "CONTROL: sending %s.."
 qemu_rdma_register_and_get_keys(uint64_t len, void *start) "Registering %" PRIu64 " bytes @ %p"
 qemu_rdma_register_odp_mr(const char *name) "Try to register On-Demand Paging memory region: %s"
 qemu_rdma_advise_mr(const char *name, uint32_t len, uint64_t addr, const char *res) "Try to advise block %s prefetch at %" PRIu32 "@0x%" PRIx64 ": %s"
-qemu_rdma_registration_handle_compress(int64_t length, int index, int64_t offset) "Zapping zero chunk: %" PRId64 " bytes, index %d, offset %" PRId64
-qemu_rdma_registration_handle_finished(void) ""
-qemu_rdma_registration_handle_ram_blocks(void) ""
-qemu_rdma_registration_handle_ram_blocks_loop(const char *name, uint64_t offset, uint64_t length, void *local_host_addr, unsigned int src_index) "%s: @0x%" PRIx64 "/%" PRIu64 " host:@%p src_index: %u"
-qemu_rdma_registration_handle_register(int requests) "%d requests"
-qemu_rdma_registration_handle_register_loop(int req, int index, uint64_t addr, uint64_t chunks) "Registration request (%d): index %d, current_addr %" PRIu64 " chunks: %" PRIu64
-qemu_rdma_registration_handle_register_rkey(int rkey) "0x%x"
-qemu_rdma_registration_handle_unregister(int requests) "%d requests"
-qemu_rdma_registration_handle_unregister_loop(int count, int index, uint64_t chunk) "Unregistration request (%d): index %d, chunk %" PRIu64
-qemu_rdma_registration_handle_unregister_success(uint64_t chunk) "%" PRIu64
-qemu_rdma_registration_handle_wait(void) ""
-qemu_rdma_registration_start(uint64_t flags) "%" PRIu64
-qemu_rdma_registration_stop(uint64_t flags) "%" PRIu64
-qemu_rdma_registration_stop_ram(void) ""
 qemu_rdma_resolve_host_trying(const char *host, const char *ip) "Trying %s => %s"
 qemu_rdma_signal_unregister_append(uint64_t chunk, int pos) "Appending unregister chunk %" PRIu64 " at position %d"
 qemu_rdma_signal_unregister_already(uint64_t chunk) "Unregister chunk %" PRIu64 " already in queue"
@@ -253,6 +239,20 @@ qemu_rdma_write_one_zero(uint64_t chunk, int len, int index, int64_t offset) "En
 rdma_add_block(const char *block_name, int block, uint64_t addr, uint64_t offset, uint64_t len, uint64_t end, uint64_t bits, int chunks) "Added Block: '%s':%d, addr: %" PRIu64 ", offset: %" PRIu64 " length: %" PRIu64 " end: %" PRIu64 " bits %" PRIu64 " chunks %d"
 rdma_block_notification_handle(const char *name, int index) "%s at %d"
 rdma_delete_block(void *block, uint64_t addr, uint64_t offset, uint64_t len, uint64_t end, uint64_t bits, int chunks) "Deleted Block: %p, addr: %" PRIu64 ", offset: %" PRIu64 " length: %" PRIu64 " end: %" PRIu64 " bits %" PRIu64 " chunks %d"
+rdma_registration_handle_compress(int64_t length, int index, int64_t offset) "Zapping zero chunk: %" PRId64 " bytes, index %d, offset %" PRId64
+rdma_registration_handle_finished(void) ""
+rdma_registration_handle_ram_blocks(void) ""
+rdma_registration_handle_ram_blocks_loop(const char *name, uint64_t offset, uint64_t length, void *local_host_addr, unsigned int src_index) "%s: @0x%" PRIx64 "/%" PRIu64 " host:@%p src_index: %u"
+rdma_registration_handle_register(int requests) "%d requests"
+rdma_registration_handle_register_loop(int req, int index, uint64_t addr, uint64_t chunks) "Registration request (%d): index %d, current_addr %" PRIu64 " chunks: %" PRIu64
+rdma_registration_handle_register_rkey(int rkey) "0x%x"
+rdma_registration_handle_unregister(int requests) "%d requests"
+rdma_registration_handle_unregister_loop(int count, int index, uint64_t chunk) "Unregistration request (%d): index %d, chunk %" PRIu64
+rdma_registration_handle_unregister_success(uint64_t chunk) "%" PRIu64
+rdma_registration_handle_wait(void) ""
+rdma_registration_start(uint64_t flags) "%" PRIu64
+rdma_registration_stop(uint64_t flags) "%" PRIu64
+rdma_registration_stop_ram(void) ""
 rdma_start_incoming_migration(void) ""
 rdma_start_incoming_migration_after_dest_init(void) ""
 rdma_start_incoming_migration_after_rdma_listen(void) ""
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 16/16] migration/rdma: If we are in postcopy don't do anything
  2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
                   ` (14 preceding siblings ...)
  2023-05-03 13:18 ` [PATCH v2 15/16] migration/rdma: Remove qemu_ prefix from exported functions Juan Quintela
@ 2023-05-03 13:18 ` Juan Quintela
  15 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 13:18 UTC (permalink / raw)
  To: qemu-devel; +Cc: Peter Xu, Juan Quintela, Leonardo Bras

Signed-off-by: Juan Quintela <quintela@redhat.com>
---
 migration/rdma.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/migration/rdma.c b/migration/rdma.c
index d6b4398620..4bc9c5cb91 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -3243,10 +3243,6 @@ static size_t qemu_rdma_save_page(QEMUFile *f,
 
     CHECK_ERROR_STATE();
 
-    if (migration_in_postcopy()) {
-        return RAM_SAVE_CONTROL_NOT_SUPP;
-    }
-
     qemu_fflush(f);
 
     /*
@@ -3323,6 +3319,10 @@ size_t rdma_control_save_page(QEMUFile *f, ram_addr_t block_offset,
         return RAM_SAVE_CONTROL_NOT_SUPP;
     }
 
+    if (migration_in_postcopy()) {
+        return RAM_SAVE_CONTROL_NOT_SUPP;
+    }
+
     int ret = qemu_rdma_save_page(f, block_offset, offset, size, bytes_sent);
     if (ret != RAM_SAVE_CONTROL_NOT_SUPP) {
         qemu_file_acct_rate_limit(f, size);
@@ -3883,6 +3883,10 @@ int rdma_registration_start(QEMUFile *f, uint64_t flags)
         return 0;
     }
 
+    if (migration_in_postcopy()) {
+        return 0;
+    }
+
     RCU_READ_LOCK_GUARD();
     rdma = qatomic_rcu_read(&rioc->rdmaout);
     if (!rdma) {
@@ -3891,10 +3895,6 @@ int rdma_registration_start(QEMUFile *f, uint64_t flags)
 
     CHECK_ERROR_STATE();
 
-    if (migration_in_postcopy()) {
-        return 0;
-    }
-
     trace_rdma_registration_start(flags);
     qemu_put_be64(f, RAM_SAVE_FLAG_HOOK);
     qemu_fflush(f);
@@ -3917,6 +3917,10 @@ int rdma_registration_stop(QEMUFile *f, uint64_t flags)
         return 0;
     }
 
+    if (migration_in_postcopy()) {
+        return 0;
+    }
+
     RCU_READ_LOCK_GUARD();
     rdma = qatomic_rcu_read(&rioc->rdmaout);
     if (!rdma) {
@@ -3925,10 +3929,6 @@ int rdma_registration_stop(QEMUFile *f, uint64_t flags)
 
     CHECK_ERROR_STATE();
 
-    if (migration_in_postcopy()) {
-        return 0;
-    }
-
     qemu_fflush(f);
     ret = qemu_rdma_drain_cq(f, rdma);
 
-- 
2.40.0



^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 01/16] migration: Create migrate_rdma()
  2023-05-03 13:18 ` [PATCH v2 01/16] migration: Create migrate_rdma() Juan Quintela
@ 2023-05-03 13:34   ` Daniel P. Berrangé
  2023-05-03 14:01     ` Juan Quintela
  0 siblings, 1 reply; 20+ messages in thread
From: Daniel P. Berrangé @ 2023-05-03 13:34 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel, Peter Xu, Leonardo Bras

On Wed, May 03, 2023 at 03:18:32PM +0200, Juan Quintela wrote:
> Helper to say if we are doing a migration over rdma.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  migration/migration.h | 3 +++
>  migration/options.c   | 7 +++++++
>  migration/options.h   | 1 +
>  migration/rdma.c      | 4 +++-
>  4 files changed, 14 insertions(+), 1 deletion(-)
> 
> diff --git a/migration/migration.h b/migration/migration.h
> index 3a918514e7..47fe116167 100644
> --- a/migration/migration.h
> +++ b/migration/migration.h
> @@ -432,6 +432,9 @@ struct MigrationState {
>  
>      /* QEMU_VM_VMDESCRIPTION content filled for all non-iterable devices. */
>      JSONWriter *vmdesc;
> +
> +    /* Is this a rdma migration */
> +    bool rdma_migration;
>  };
>  
>  void migrate_set_state(int *state, int old_state, int new_state);
> diff --git a/migration/options.c b/migration/options.c
> index 53b7fc5d5d..39843f9325 100644
> --- a/migration/options.c
> +++ b/migration/options.c
> @@ -349,6 +349,13 @@ bool migrate_postcopy(void)
>      return migrate_postcopy_ram() || migrate_dirty_bitmaps();
>  }
>  
> +bool migrate_rdma(void)
> +{
> +    MigrationState *s = migrate_get_current();
> +
> +    return s->rdma_migration;
> +}
> +
>  bool migrate_tls(void)
>  {
>      MigrationState *s = migrate_get_current();
> diff --git a/migration/options.h b/migration/options.h
> index 3c322867cd..3c555e28c7 100644
> --- a/migration/options.h
> +++ b/migration/options.h
> @@ -61,6 +61,7 @@ bool migrate_zero_copy_send(void);
>  
>  bool migrate_multifd_flush_after_each_section(void);
>  bool migrate_postcopy(void);
> +bool migrate_rdma(void);
>  bool migrate_tls(void);
>  
>  /* capabilities helpers */
> diff --git a/migration/rdma.c b/migration/rdma.c
> index 7e747b2595..b026e98519 100644
> --- a/migration/rdma.c
> +++ b/migration/rdma.c
> @@ -4119,6 +4119,7 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp)
>      int ret;
>      RDMAContext *rdma;
>      Error *local_err = NULL;
> +    MigrationState *s = migrate_get_current();
>  
>      trace_rdma_start_incoming_migration();
>  
> @@ -4149,7 +4150,7 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp)
>      }
>  
>      trace_rdma_start_incoming_migration_after_rdma_listen();
> -
> +    s->rdma_migration = true;
>      qemu_set_fd_handler(rdma->channel->fd, rdma_accept_incoming_migration,
>                          NULL, (void *)(intptr_t)rdma);
>      return;
> @@ -4225,6 +4226,7 @@ void rdma_start_outgoing_migration(void *opaque,
>  
>      trace_rdma_start_outgoing_migration_after_rdma_connect();
>  
> +    s->rdma_migration = true;
>      s->to_dst_file = qemu_fopen_rdma(rdma, "wb");
>      migrate_fd_connect(s, NULL);
>      return;

Is the "MigrationState" allocated freshly for every incoming
or outgoing migration ?  If it is reused, then something
needs to set 's->rdma_migration = false' in non-RDMA code
paths.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 05/16] migration/rdma: Don't pass the QIOChannelRDMA as an opaque
  2023-05-03 13:18 ` [PATCH v2 05/16] migration/rdma: Don't pass the QIOChannelRDMA as an opaque Juan Quintela
@ 2023-05-03 13:35   ` Daniel P. Berrangé
  0 siblings, 0 replies; 20+ messages in thread
From: Daniel P. Berrangé @ 2023-05-03 13:35 UTC (permalink / raw)
  To: Juan Quintela; +Cc: qemu-devel, Peter Xu, Leonardo Bras

On Wed, May 03, 2023 at 03:18:36PM +0200, Juan Quintela wrote:
> We can calculate it from the QEMUFile like the caller.
> 
> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  migration/rdma.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 01/16] migration: Create migrate_rdma()
  2023-05-03 13:34   ` Daniel P. Berrangé
@ 2023-05-03 14:01     ` Juan Quintela
  0 siblings, 0 replies; 20+ messages in thread
From: Juan Quintela @ 2023-05-03 14:01 UTC (permalink / raw)
  To: Daniel P. Berrangé; +Cc: qemu-devel, Peter Xu, Leonardo Bras

Daniel P. Berrangé <berrange@redhat.com> wrote:
> On Wed, May 03, 2023 at 03:18:32PM +0200, Juan Quintela wrote:
>> Helper to say if we are doing a migration over rdma.
>
> Is the "MigrationState" allocated freshly for every incoming
> or outgoing migration ?  If it is reused, then something
> needs to set 's->rdma_migration = false' in non-RDMA code
> paths.

for (i = 0; i < 1000; i++)
    printf("never trust memory, check the code.\n");

You are right, the function that we call is:
migrate_init()

but we clear each statistic by hand, not a memset().

And now I have to review that we are not missing any other field to
reset.

Thanks, Juan.



^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2023-05-03 14:01 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-03 13:18 [PATCH v2 00/16] migration: Remove QEMUFileHooks Juan Quintela
2023-05-03 13:18 ` [PATCH v2 01/16] migration: Create migrate_rdma() Juan Quintela
2023-05-03 13:34   ` Daniel P. Berrangé
2023-05-03 14:01     ` Juan Quintela
2023-05-03 13:18 ` [PATCH v2 02/16] migration/rdma: Unfold ram_control_before_iterate() Juan Quintela
2023-05-03 13:18 ` [PATCH v2 03/16] migration/rdma: Unfold ram_control_after_iterate() Juan Quintela
2023-05-03 13:18 ` [PATCH v2 04/16] migration/rdma: simplify ram_control_load_hook() Juan Quintela
2023-05-03 13:18 ` [PATCH v2 05/16] migration/rdma: Don't pass the QIOChannelRDMA as an opaque Juan Quintela
2023-05-03 13:35   ` Daniel P. Berrangé
2023-05-03 13:18 ` [PATCH v2 06/16] migration/rdma: We can calculate the rioc from the QEMUFile Juan Quintela
2023-05-03 13:18 ` [PATCH v2 07/16] migration/rdma: It makes no sense to recive that flag without RDMA Juan Quintela
2023-05-03 13:18 ` [PATCH v2 08/16] migration: Make RAM_SAVE_FLAG_HOOK a normal case entry Juan Quintela
2023-05-03 13:18 ` [PATCH v2 09/16] migration/rdma: Remove all uses of RAM_CONTROL_HOOK Juan Quintela
2023-05-03 13:18 ` [PATCH v2 10/16] migration/rdma: Unfold hook_ram_load() Juan Quintela
2023-05-03 13:18 ` [PATCH v2 11/16] migration/rdma: Make ram_control_save_page() use exported interfaces Juan Quintela
2023-05-03 13:18 ` [PATCH v2 12/16] migration/rdma: Create rdma_control_save_page() Juan Quintela
2023-05-03 13:18 ` [PATCH v2 13/16] qemu-file: Remove QEMUFileHooks Juan Quintela
2023-05-03 13:18 ` [PATCH v2 14/16] migration/rdma: Move rdma constants from qemu-file.h to rdma.h Juan Quintela
2023-05-03 13:18 ` [PATCH v2 15/16] migration/rdma: Remove qemu_ prefix from exported functions Juan Quintela
2023-05-03 13:18 ` [PATCH v2 16/16] migration/rdma: If we are in postcopy don't do anything Juan Quintela

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).