migration/multifd: Make multifd_send() thread safe
multifd_send() function is currently not thread safe, make it thread safe by holding a lock during its execution. This way it will be possible to safely call it concurrently from multiple threads. Reviewed-by: Peter Xu <peterx@redhat.com> Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com> Link: https://lore.kernel.org/qemu-devel/dd0f3bcc02ca96a7d523ca58ea69e495a33b453b.1741124640.git.maciej.szmigiero@oracle.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
parent
f588f3c46a
commit
d19cc4dca0
@ -50,6 +50,10 @@ typedef struct {
|
|||||||
|
|
||||||
struct {
|
struct {
|
||||||
MultiFDSendParams *params;
|
MultiFDSendParams *params;
|
||||||
|
|
||||||
|
/* multifd_send() body is not thread safe, needs serialization */
|
||||||
|
QemuMutex multifd_send_mutex;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Global number of generated multifd packets.
|
* Global number of generated multifd packets.
|
||||||
*
|
*
|
||||||
@ -339,6 +343,8 @@ bool multifd_send(MultiFDSendData **send_data)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QEMU_LOCK_GUARD(&multifd_send_state->multifd_send_mutex);
|
||||||
|
|
||||||
/* We wait here, until at least one channel is ready */
|
/* We wait here, until at least one channel is ready */
|
||||||
qemu_sem_wait(&multifd_send_state->channels_ready);
|
qemu_sem_wait(&multifd_send_state->channels_ready);
|
||||||
|
|
||||||
@ -507,6 +513,7 @@ static void multifd_send_cleanup_state(void)
|
|||||||
socket_cleanup_outgoing_migration();
|
socket_cleanup_outgoing_migration();
|
||||||
qemu_sem_destroy(&multifd_send_state->channels_created);
|
qemu_sem_destroy(&multifd_send_state->channels_created);
|
||||||
qemu_sem_destroy(&multifd_send_state->channels_ready);
|
qemu_sem_destroy(&multifd_send_state->channels_ready);
|
||||||
|
qemu_mutex_destroy(&multifd_send_state->multifd_send_mutex);
|
||||||
g_free(multifd_send_state->params);
|
g_free(multifd_send_state->params);
|
||||||
multifd_send_state->params = NULL;
|
multifd_send_state->params = NULL;
|
||||||
g_free(multifd_send_state);
|
g_free(multifd_send_state);
|
||||||
@ -887,6 +894,7 @@ bool multifd_send_setup(void)
|
|||||||
thread_count = migrate_multifd_channels();
|
thread_count = migrate_multifd_channels();
|
||||||
multifd_send_state = g_malloc0(sizeof(*multifd_send_state));
|
multifd_send_state = g_malloc0(sizeof(*multifd_send_state));
|
||||||
multifd_send_state->params = g_new0(MultiFDSendParams, thread_count);
|
multifd_send_state->params = g_new0(MultiFDSendParams, thread_count);
|
||||||
|
qemu_mutex_init(&multifd_send_state->multifd_send_mutex);
|
||||||
qemu_sem_init(&multifd_send_state->channels_created, 0);
|
qemu_sem_init(&multifd_send_state->channels_created, 0);
|
||||||
qemu_sem_init(&multifd_send_state->channels_ready, 0);
|
qemu_sem_init(&multifd_send_state->channels_ready, 0);
|
||||||
qatomic_set(&multifd_send_state->exiting, 0);
|
qatomic_set(&multifd_send_state->exiting, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user