On Fri, 9 Jan 2026 at 18:19, Fabiano Rosas <farosas@suse.de> wrote:
> Move this CPR-specific code into a cpr file. While here, give the
> functions more significant names.
>
> This makes the new idea (after cpr-transfer) of having two parts to
> qmp_migrate slightly more obvious: either wait for the hangup or
> continue directly.
>
> Reviewed-by: Peter Xu <peterx@redhat.com>
> Signed-off-by: Fabiano Rosas <farosas@suse.de>
> ---
> include/migration/cpr.h | 5 +++++
> migration/cpr-transfer.c | 23 +++++++++++++++++++++++
> migration/migration.c | 27 +++------------------------
> 3 files changed, 31 insertions(+), 24 deletions(-)
>
> diff --git a/include/migration/cpr.h b/include/migration/cpr.h
> index 027cb98073..5850fd1788 100644
> --- a/include/migration/cpr.h
> +++ b/include/migration/cpr.h
> @@ -9,6 +9,7 @@
> #define MIGRATION_CPR_H
>
> #include "qapi/qapi-types-migration.h"
> +#include "io/channel.h"
> #include "qemu/queue.h"
>
> #define MIG_MODE_NONE -1
> @@ -53,6 +54,10 @@ int cpr_get_fd_param(const char *name, const char *fdname, int index,
> QEMUFile *cpr_transfer_output(MigrationChannel *channel, Error **errp);
> QEMUFile *cpr_transfer_input(MigrationChannel *channel, Error **errp);
>
> +void cpr_transfer_add_hup_watch(MigrationState *s, QIOChannelFunc func,
> + void *opaque);
> +void cpr_transfer_source_destroy(MigrationState *s);
> +
> void cpr_exec_init(void);
> QEMUFile *cpr_exec_output(Error **errp);
> QEMUFile *cpr_exec_input(Error **errp);
> diff --git a/migration/cpr-transfer.c b/migration/cpr-transfer.c
> index 00371d17c3..61d5c9dce2 100644
> --- a/migration/cpr-transfer.c
> +++ b/migration/cpr-transfer.c
> @@ -6,7 +6,10 @@
> */
>
> #include "qemu/osdep.h"
> +#include "qapi/clone-visitor.h"
> #include "qapi/error.h"
> +#include "qapi/qapi-visit-migration.h"
> +#include "io/channel.h"
> #include "io/channel-file.h"
> #include "io/channel-socket.h"
> #include "io/net-listener.h"
> @@ -72,3 +75,23 @@ QEMUFile *cpr_transfer_input(MigrationChannel *channel, Error **errp)
> return NULL;
> }
> }
> +
> +void cpr_transfer_add_hup_watch(MigrationState *s, QIOChannelFunc func,
> + void *opaque)
> +{
> + s->hup_source = qio_channel_create_watch(cpr_state_ioc(), G_IO_HUP);
> + g_source_set_callback(s->hup_source,
> + (GSourceFunc)func,
> + QAPI_CLONE(MigrationAddress, opaque),
> + (GDestroyNotify)qapi_free_MigrationAddress);
> + g_source_attach(s->hup_source, NULL);
> +}
> +
> +void cpr_transfer_source_destroy(MigrationState *s)
> +{
> + if (s->hup_source) {
> + g_source_destroy(s->hup_source);
> + g_source_unref(s->hup_source);
> + s->hup_source = NULL;
> + }
> +}
> diff --git a/migration/migration.c b/migration/migration.c
> index 5167233f76..6be2849326 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -100,7 +100,6 @@ static bool migration_object_check(MigrationState *ms, Error **errp);
> static bool migration_switchover_start(MigrationState *s, Error **errp);
> static bool close_return_path_on_source(MigrationState *s);
> static void migration_completion_end(MigrationState *s);
> -static void migrate_hup_delete(MigrationState *s);
>
> static void migration_downtime_start(MigrationState *s)
> {
> @@ -1297,7 +1296,7 @@ static void migration_cleanup(MigrationState *s)
>
> qemu_savevm_state_cleanup();
> cpr_state_close();
> - migrate_hup_delete(s);
> + cpr_transfer_source_destroy(s);
>
> close_return_path_on_source(s);
>
> @@ -1480,7 +1479,7 @@ void migration_cancel(void)
> migrate_set_state(&s->state, MIGRATION_STATUS_CANCELLING,
> MIGRATION_STATUS_CANCELLED);
> cpr_state_close();
> - migrate_hup_delete(s);
> + cpr_transfer_source_destroy(s);
> }
> }
>
> @@ -2004,25 +2003,6 @@ static bool migrate_prepare(MigrationState *s, bool resume, Error **errp)
>
> static void qmp_migrate_finish(MigrationAddress *addr, Error **errp);
>
> -static void migrate_hup_add(MigrationState *s, QIOChannel *ioc, GSourceFunc cb,
> - void *opaque)
> -{
> - s->hup_source = qio_channel_create_watch(ioc, G_IO_HUP);
> - g_source_set_callback(s->hup_source, cb,
> - QAPI_CLONE(MigrationAddress, opaque),
> - (GDestroyNotify)qapi_free_MigrationAddress);
> - g_source_attach(s->hup_source, NULL);
> -}
> -
> -static void migrate_hup_delete(MigrationState *s)
> -{
> - if (s->hup_source) {
> - g_source_destroy(s->hup_source);
> - g_source_unref(s->hup_source);
> - s->hup_source = NULL;
> - }
> -}
> -
> static gboolean qmp_migrate_finish_cb(QIOChannel *channel,
> GIOCondition cond,
> void *opaque)
> @@ -2083,8 +2063,7 @@ void qmp_migrate(const char *uri, bool has_channels,
> * connection, so qmp_migrate_finish will fail to connect, and then recover.
> */
> if (migrate_mode() == MIG_MODE_CPR_TRANSFER) {
> - migrate_hup_add(s, cpr_state_ioc(), (GSourceFunc)qmp_migrate_finish_cb,
> - main_ch->addr);
> + cpr_transfer_add_hup_watch(s, qmp_migrate_finish_cb, main_ch->addr);
>
> } else {
> qmp_migrate_finish(main_ch->addr, errp);
> --
* Looks okay.
Reviewed-by: Prasad Pandit <pjp@fedoraproject.org>
Thank you.
---
- Prasad