On Mon, Jan 05, 2026 at 04:06:31PM -0300, Fabiano Rosas wrote:
> Use the common connection paths for the incoming and outgoing sides of
> rdma migration. This removes one usage of QEMUFile from rdma.c. It
> also allows further unification of the connection code in next
> patches.
>
> Move the channels enum to channel.h so rdma.c can access it. The RDMA
> channel is considered a CH_MAIN channel.
>
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
Reviewed-by: Peter Xu <peterx@redhat.com>
One nitpick inline.
> ---
> migration/channel.h | 7 +++++++
> migration/migration.c | 13 -------------
> migration/migration.h | 1 -
> migration/rdma.c | 23 +++++++++++------------
> 4 files changed, 18 insertions(+), 26 deletions(-)
>
> diff --git a/migration/channel.h b/migration/channel.h
> index ccfeaaef18..93dedbf52b 100644
> --- a/migration/channel.h
> +++ b/migration/channel.h
> @@ -18,6 +18,13 @@
>
> #include "io/channel.h"
>
> +/* Migration channel types */
> +enum {
> + CH_MAIN,
> + CH_MULTIFD,
> + CH_POSTCOPY
> +};
> +
> void migration_channel_process_incoming(QIOChannel *ioc);
>
> void migration_channel_connect(MigrationState *s, QIOChannel *ioc);
> diff --git a/migration/migration.c b/migration/migration.c
> index dc8fe80cf8..906f0bdab3 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -91,9 +91,6 @@ enum mig_rp_message_type {
> MIG_RP_MSG_MAX
> };
>
> -/* Migration channel types */
> -enum { CH_MAIN, CH_MULTIFD, CH_POSTCOPY };
> -
> /* When we add fault tolerance, we could have several
> migrations at once. For now we don't need to add
> dynamic creation of migration */
> @@ -1021,16 +1018,6 @@ void migration_incoming_process(void)
> qemu_coroutine_enter(co);
> }
>
> -void migration_fd_process_incoming(QEMUFile *f)
> -{
> - MigrationIncomingState *mis = migration_incoming_get_current();
> -
> - assert(!mis->from_src_file);
> - mis->from_src_file = f;
> - qemu_file_set_blocking(f, false, &error_abort);
> - migration_incoming_process();
This is removed very soon here.. That's OK.
> -}
> -
> static bool migration_has_main_and_multifd_channels(void)
> {
> MigrationIncomingState *mis = migration_incoming_get_current();
> diff --git a/migration/migration.h b/migration/migration.h
> index 4dcf299719..cd6cfd62ba 100644
> --- a/migration/migration.h
> +++ b/migration/migration.h
> @@ -527,7 +527,6 @@ struct MigrationState {
> void migrate_set_state(MigrationStatus *state, MigrationStatus old_state,
> MigrationStatus new_state);
>
> -void migration_fd_process_incoming(QEMUFile *f);
> void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp);
> void migration_incoming_process(void);
> bool migration_incoming_setup(QIOChannel *ioc, uint8_t channel, Error **errp);
> diff --git a/migration/rdma.c b/migration/rdma.c
> index 596a1aba0b..788ae183c1 100644
> --- a/migration/rdma.c
> +++ b/migration/rdma.c
> @@ -15,6 +15,7 @@
> */
>
> #include "qemu/osdep.h"
> +#include "channel.h"
> #include "qapi/error.h"
> #include "qemu/cutils.h"
> #include "exec/target_page.h"
> @@ -384,7 +385,6 @@ struct QIOChannelRDMA {
> QIOChannel parent;
> RDMAContext *rdmain;
> RDMAContext *rdmaout;
> - QEMUFile *file;
> bool blocking; /* XXX we don't actually honour this yet */
> };
>
> @@ -3836,32 +3836,30 @@ static void qio_channel_rdma_register_types(void)
>
> type_init(qio_channel_rdma_register_types);
>
> -static QEMUFile *rdma_new_input(RDMAContext *rdma)
> +static QIOChannel *rdma_new_input(RDMAContext *rdma)
> {
> QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(object_new(TYPE_QIO_CHANNEL_RDMA));
>
> - rioc->file = qemu_file_new_input(QIO_CHANNEL(rioc));
> rioc->rdmain = rdma;
> rioc->rdmaout = rdma->return_path;
>
> - return rioc->file;
> + return QIO_CHANNEL(rioc);
> }
>
> -static QEMUFile *rdma_new_output(RDMAContext *rdma)
> +static QIOChannel *rdma_new_output(RDMAContext *rdma)
> {
> QIOChannelRDMA *rioc = QIO_CHANNEL_RDMA(object_new(TYPE_QIO_CHANNEL_RDMA));
>
> - rioc->file = qemu_file_new_output(QIO_CHANNEL(rioc));
> rioc->rdmaout = rdma;
> rioc->rdmain = rdma->return_path;
>
> - return rioc->file;
> + return QIO_CHANNEL(rioc);
> }
>
> static void rdma_accept_incoming_migration(void *opaque)
> {
> RDMAContext *rdma = opaque;
> - QEMUFile *f;
> + QIOChannel *ioc;
>
> trace_qemu_rdma_accept_incoming_migration();
> if (qemu_rdma_accept(rdma) < 0) {
> @@ -3875,15 +3873,16 @@ static void rdma_accept_incoming_migration(void *opaque)
> return;
> }
>
> - f = rdma_new_input(rdma);
> - if (f == NULL) {
> + ioc = rdma_new_input(rdma);
> + if (ioc == NULL) {
> error_report("RDMA ERROR: could not open RDMA for input");
> qemu_rdma_cleanup(rdma);
> return;
> }
>
> rdma->migration_started_on_destination = 1;
> - migration_fd_process_incoming(f);
> + migration_incoming_setup(ioc, CH_MAIN, NULL);
Maybe error_abort?
> + migration_incoming_process();
> }
>
> void rdma_start_incoming_migration(InetSocketAddress *host_port,
> @@ -3995,8 +3994,8 @@ void rdma_start_outgoing_migration(void *opaque,
>
> trace_rdma_start_outgoing_migration_after_rdma_connect();
>
> - s->to_dst_file = rdma_new_output(rdma);
> s->rdma_migration = true;
> + migration_outgoing_setup(rdma_new_output(rdma));
> migration_connect(s);
> return;
> return_path_err:
> --
> 2.51.0
>
--
Peter Xu