migration: yank: Move register instance earlier

Move the register_instance call to migrate_prepare() so it can be
paired with the unregister_instance at migration_cleanup(). Otherwise,
the cleanup cannot be run when cpr_state_save() fails because the
instance is registered only after it.

When resuming from a paused postcopy migration, migrate_prepare()
returns early, but migration_cleanup() doesn't run, so the yank will
remain paired.

Reviewed-by: Peter Xu <peterx@redhat.com>
Reviewed-by: Prasad Pandit <pjp@fedoraproject.org>
Link: https://lore.kernel.org/qemu-devel/20260123141656.6765-11-farosas@suse.de
Signed-off-by: Fabiano Rosas <farosas@suse.de>
This commit is contained in:
Fabiano Rosas
2026-01-23 11:16:40 -03:00
parent 2f8ccc5d58
commit 7e71439243

View File

@@ -2177,11 +2177,12 @@ static bool migrate_prepare(MigrationState *s, bool resume, Error **errp)
return false;
}
yank_register_instance(MIGRATION_YANK_INSTANCE, &error_abort);
return true;
}
static void qmp_migrate_finish(MigrationAddress *addr, bool resume_requested,
Error **errp);
static void qmp_migrate_finish(MigrationAddress *addr, Error **errp);
static void migrate_hup_add(MigrationState *s, QIOChannel *ioc, GSourceFunc cb,
void *opaque)
@@ -2206,7 +2207,7 @@ static gboolean qmp_migrate_finish_cb(QIOChannel *channel,
{
MigrationAddress *addr = opaque;
qmp_migrate_finish(addr, false, NULL);
qmp_migrate_finish(addr, NULL);
cpr_state_close();
migrate_hup_delete(migrate_get_current());
@@ -2218,7 +2219,6 @@ void qmp_migrate(const char *uri, bool has_channels,
MigrationChannelList *channels,
bool has_resume, bool resume, Error **errp)
{
bool resume_requested;
Error *local_err = NULL;
MigrationState *s = migrate_get_current();
g_autoptr(MigrationChannel) channel = NULL;
@@ -2271,8 +2271,7 @@ void qmp_migrate(const char *uri, bool has_channels,
return;
}
resume_requested = has_resume && resume;
if (!migrate_prepare(s, resume_requested, errp)) {
if (!migrate_prepare(s, has_resume && resume, errp)) {
/* Error detected, put into errp */
return;
}
@@ -2296,28 +2295,22 @@ void qmp_migrate(const char *uri, bool has_channels,
QAPI_CLONE(MigrationAddress, addr));
} else {
qmp_migrate_finish(addr, resume_requested, errp);
qmp_migrate_finish(addr, errp);
}
out:
if (local_err) {
yank_unregister_instance(MIGRATION_YANK_INSTANCE);
migration_connect_error_propagate(s, error_copy(local_err));
error_propagate(errp, local_err);
}
}
static void qmp_migrate_finish(MigrationAddress *addr, bool resume_requested,
Error **errp)
static void qmp_migrate_finish(MigrationAddress *addr, Error **errp)
{
MigrationState *s = migrate_get_current();
Error *local_err = NULL;
if (!resume_requested) {
if (!yank_register_instance(MIGRATION_YANK_INSTANCE, errp)) {
return;
}
}
if (addr->transport == MIGRATION_ADDRESS_TYPE_SOCKET) {
SocketAddress *saddr = &addr->u.socket;
if (saddr->type == SOCKET_ADDRESS_TYPE_INET ||
@@ -2340,9 +2333,6 @@ static void qmp_migrate_finish(MigrationAddress *addr, bool resume_requested,
}
if (local_err) {
if (!resume_requested) {
yank_unregister_instance(MIGRATION_YANK_INSTANCE);
}
migration_connect_error_propagate(s, error_copy(local_err));
error_propagate(errp, local_err);
return;