mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 00:03:54 -06:00
migration: Create the postcopy preempt channel asynchronously
This patch allows the postcopy preempt channel to be created asynchronously. The benefit is that when the connection is slow, we won't take the BQL (and potentially block all things like QMP) for a long time without releasing. A function postcopy_preempt_wait_channel() is introduced, allowing the migration thread to be able to wait on the channel creation. The channel is always created by the main thread, in which we'll kick a new semaphore to tell the migration thread that the channel has created. We'll need to wait for the new channel in two places: (1) when there's a new postcopy migration that is starting, or (2) when there's a postcopy migration to resume. For the start of migration, we don't need to wait for this channel until when we want to start postcopy, aka, postcopy_start(). We'll fail the migration if we found that the channel creation failed (which should probably not happen at all in 99% of the cases, because the main channel is using the same network topology). For a postcopy recovery, we'll need to wait in postcopy_pause(). In that case if the channel creation failed, we can't fail the migration or we'll crash the VM, instead we keep in PAUSED state, waiting for yet another recovery. Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Reviewed-by: Manish Mishra <manish.mishra@nutanix.com> Signed-off-by: Peter Xu <peterx@redhat.com> Message-Id: <20220707185509.27311-1-peterx@redhat.com> Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
This commit is contained in:
parent
60bb3c5871
commit
d0edb8a173
4 changed files with 68 additions and 12 deletions
|
@ -1552,10 +1552,50 @@ bool postcopy_preempt_new_channel(MigrationIncomingState *mis, QEMUFile *file)
|
|||
return true;
|
||||
}
|
||||
|
||||
static void
|
||||
postcopy_preempt_send_channel_new(QIOTask *task, gpointer opaque)
|
||||
{
|
||||
MigrationState *s = opaque;
|
||||
QIOChannel *ioc = QIO_CHANNEL(qio_task_get_source(task));
|
||||
Error *local_err = NULL;
|
||||
|
||||
if (qio_task_propagate_error(task, &local_err)) {
|
||||
/* Something wrong happened.. */
|
||||
migrate_set_error(s, local_err);
|
||||
error_free(local_err);
|
||||
} else {
|
||||
migration_ioc_register_yank(ioc);
|
||||
s->postcopy_qemufile_src = qemu_file_new_output(ioc);
|
||||
trace_postcopy_preempt_new_channel();
|
||||
}
|
||||
|
||||
/*
|
||||
* Kick the waiter in all cases. The waiter should check upon
|
||||
* postcopy_qemufile_src to know whether it failed or not.
|
||||
*/
|
||||
qemu_sem_post(&s->postcopy_qemufile_src_sem);
|
||||
object_unref(OBJECT(ioc));
|
||||
}
|
||||
|
||||
/* Returns 0 if channel established, -1 for error. */
|
||||
int postcopy_preempt_wait_channel(MigrationState *s)
|
||||
{
|
||||
/* If preempt not enabled, no need to wait */
|
||||
if (!migrate_postcopy_preempt()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* We need the postcopy preempt channel to be established before
|
||||
* starting doing anything.
|
||||
*/
|
||||
qemu_sem_wait(&s->postcopy_qemufile_src_sem);
|
||||
|
||||
return s->postcopy_qemufile_src ? 0 : -1;
|
||||
}
|
||||
|
||||
int postcopy_preempt_setup(MigrationState *s, Error **errp)
|
||||
{
|
||||
QIOChannel *ioc;
|
||||
|
||||
if (!migrate_postcopy_preempt()) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -1566,16 +1606,8 @@ int postcopy_preempt_setup(MigrationState *s, Error **errp)
|
|||
return -1;
|
||||
}
|
||||
|
||||
ioc = socket_send_channel_create_sync(errp);
|
||||
|
||||
if (ioc == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
migration_ioc_register_yank(ioc);
|
||||
s->postcopy_qemufile_src = qemu_file_new_output(ioc);
|
||||
|
||||
trace_postcopy_preempt_new_channel();
|
||||
/* Kick an async task to connect */
|
||||
socket_send_channel_create(postcopy_preempt_send_channel_new, s);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue