migration: process_incoming_migration_co(): move colo part to colo

Let's make better public interface for COLO: instead of
colo_process_incoming_thread and not trivial logic around creating the
thread let's make simple colo_incoming_co(), hiding implementation from
generic code.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Message-Id: <20230515130640.46035-4-vsementsov@yandex-team.ru>
Signed-off-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
Vladimir Sementsov-Ogievskiy 2023-05-15 16:06:40 +03:00 committed by Juan Quintela
parent dd42ce24a3
commit d0a14a2ba0
4 changed files with 50 additions and 32 deletions

View file

@ -817,7 +817,7 @@ void colo_shutdown(void)
}
}
void *colo_process_incoming_thread(void *opaque)
static void *colo_process_incoming_thread(void *opaque)
{
MigrationIncomingState *mis = opaque;
QEMUFile *fb = NULL;
@ -918,3 +918,40 @@ out:
rcu_unregister_thread();
return NULL;
}
int coroutine_fn colo_incoming_co(void)
{
MigrationIncomingState *mis = migration_incoming_get_current();
Error *local_err = NULL;
QemuThread th;
assert(qemu_mutex_iothread_locked());
if (!migration_incoming_colo_enabled()) {
return 0;
}
/* Make sure all file formats throw away their mutable metadata */
bdrv_activate_all(&local_err);
if (local_err) {
error_report_err(local_err);
return -EINVAL;
}
qemu_thread_create(&th, "COLO incoming", colo_process_incoming_thread,
mis, QEMU_THREAD_JOINABLE);
mis->colo_incoming_co = qemu_coroutine_self();
qemu_coroutine_yield();
mis->colo_incoming_co = NULL;
qemu_mutex_unlock_iothread();
/* Wait checkpoint incoming thread exit before free resource */
qemu_thread_join(&th);
qemu_mutex_lock_iothread();
/* We hold the global iothread lock, so it is safe here */
colo_release_ram_cache();
return 0;
}