migration: Move CPR HUP watch to cpr-transfer.c
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> Reviewed-by: Prasad Pandit <pjp@fedoraproject.org> Link: https://lore.kernel.org/qemu-devel/20260123141656.6765-24-farosas@suse.de Signed-off-by: Fabiano Rosas <farosas@suse.de>
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,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)
|
||||
{
|
||||
@@ -1296,7 +1295,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);
|
||||
|
||||
@@ -1477,7 +1476,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2001,25 +2000,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)
|
||||
@@ -2075,8 +2055,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);
|
||||
|
||||
Reference in New Issue
Block a user