migration/multifd: General cleanups
cover migration/multifd: General cleanups
Hi,
Just a small series with some cleanups.
First patch is related to fixed ram work. If we're going to add other transports to multifd such as the "file", we need to stop using "socket" in the code.
Second patch is a consolidation of error paths that I think will make the code more robust.
Third patch is a refactoring to improve Error handling. We're currently doing some gymnastics that are not necessary.
Thanks!
Fabiano Rosas (3):
migration/multifd: Remove direct "socket" references migration/multifd: Unify multifd_send_thread error paths migration/multifd: Clarify Error usage in multifd_channel_connect
migration/multifd.c | 92 +++++++++++++++++++++--------------------- migration/trace-events | 3 +- 2 files changed, 48 insertions(+), 47 deletions(-)
Signature · 1 line
2.35.3
PATCH 1/3 migration/multifd: Remove direct "socket" references
We're about to enable support for other transports in multifd, so remove direct references to sockets.
--- migration/multifd.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
migration/multifd.c +16 -6
@@ -510,6 +510,11 @@ static void multifd_send_terminate_threads(Error *err) } } +static int multifd_send_channel_destroy (QIOChannel *send) +{ +return socket_send_channel_destroy (send); +} +void multifd_save_cleanup (void ) {int i;
@@ -532,7 +537,7 @@ void multifd_save_cleanup(void)if (p->registered_yank) {migration_ioc_unregister_yank (p->c); } -socket_send_channel_destroy (p->c); +multifd_send_channel_destroy (p->c); p->c =NULL ;qemu_mutex_destroy (&p->mutex);qemu_sem_destroy (&p->sem);
@@ -889,20 +894,25 @@ static void multifd_new_send_channel_cleanup(MultiFDSendParams *p,static void multifd_new_send_channel_async (QIOTask *task,gpointer opaque) {MultiFDSendParams *p = opaque; -QIOChannel *sioc =QIO_CHANNEL (qio_task_get_source (task)); +QIOChannel *ioc =QIO_CHANNEL (qio_task_get_source (task));Error *local_err =NULL ;trace_multifd_new_send_channel_async (p->id);if (!qio_task_propagate_error (task, &local_err)) { - p->c = sioc; + p->c = ioc;qio_channel_set_delay (p->c, false); p->running = true; -if (multifd_channel_connect (p, sioc, local_err)) { +if (multifd_channel_connect (p, ioc, local_err)) {return ; } } -multifd_new_send_channel_cleanup (p, sioc, local_err); +multifd_new_send_channel_cleanup (p, ioc, local_err); +} + +static void multifd_new_send_channel_create (gpointer opaque) +{ +socket_send_channel_create (multifd_new_send_channel_async, opaque); }int multifd_save_setup (Error **errp)
@@ -951,7 +961,7 @@ int multifd_save_setup(Error **errp) p->write_flags =0 ; } -socket_send_channel_create (multifd_new_send_channel_async, p); +multifd_new_send_channel_create (p); }for (i =0 ; i < thread_count; i++) {
Signature · 1 line
2.35.3
Re: [PATCH 1/3] migration/multifd: Remove direct "socket" references
Quoted 7 lines · Fabiano Rosas
We're about to enable support for other transports in multifd, so remove direct references to sockets.
Signed-off-by Fabiano Rosas <[email protected]>--- migration/multifd.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-)
Re: [PATCH 1/3] migration/multifd: Remove direct "socket" references
In reply to Fabiano RosasQuoted 4 lines · Fabiano Rosas
We're about to enable support for other transports in multifd, so remove direct references to sockets.
Signed-off-by Fabiano Rosas <[email protected]>
queued.
PATCH 2/3 migration/multifd: Unify multifd_send_thread error paths
In reply to Fabiano RosasThe preferred usage of the Error type is to always set both the return code and the error when a failure happens. As all code called from the send thread follows this pattern, we'll always have the return code and the error set at the same time.
Aside from the convention, in this piece of code this must be the case, otherwise the if (ret != 0) would be exiting the thread without calling multifd_send_terminate_threads() which is incorrect.
Unify both paths to make it clear that both are taken when there's an error.
--- migration/multifd.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-)
migration/multifd.c +3 -9
@@ -752,19 +752,13 @@ static void *multifd_send_thread(void *opaque) } out: -if (local_err) { +if (ret) { +assert (local_err);trace_multifd_send_error (p->id);multifd_send_terminate_threads (local_err); -error_free (local_err); - } - -/* -* Error happen, I will exit, but I can't just leave, tell -* who pay attention to me. -*/ -if (ret !=0 ) {qemu_sem_post (&p->sem_sync);qemu_sem_post (&multifd_send_state->channels_ready); +error_free (local_err); }qemu_mutex_lock (&p->mutex);
Signature · 1 line
2.35.3
Re: [PATCH 2/3] migration/multifd: Unify multifd_send_thread error paths
Quoted 5 lines · Fabiano Rosas
The preferred usage of the Error type is to always set both the return code and the error when a failure happens. As all code called from the send thread follows this pattern, we'll always have the return code and the error set at the same time.
Quoted 8 lines
Aside from the convention, in this piece of code this must be the case, otherwise the if (ret != 0) would be exiting the thread without calling
multifd_send_terminate_threads()which is incorrect.Unify both paths to make it clear that both are taken when there's an error.
Signed-off-by Fabiano Rosas <[email protected]>
queued.
PATCH 3/3 migration/multifd: Clarify Error usage in multifd_channel_connect
In reply to Fabiano RosasThe function is currently called from two sites, one always gives it a NULL Error and the other always gives it a non-NULL Error.
In the non-NULL case, all it does it trace the error and return. One of the callers already have tracing, add a tracepoint to the other and stop passing the error into the function.
--- migration/multifd.c | 60 ++++++++++++++++++++---------------------- migration/trace-events | 3 ++- 2 files changed, 30 insertions(+), 33 deletions(-)
migration/multifd.c +28 -32
@@ -774,7 +774,7 @@ out:static bool multifd_channel_connect (MultiFDSendParams *p,QIOChannel *ioc, -Error *error); +Error **errp);static void multifd_tls_outgoing_handshake (QIOTask *task,gpointer opaque)
@@ -783,21 +783,22 @@ static void multifd_tls_outgoing_handshake(QIOTask *task,QIOChannel *ioc =QIO_CHANNEL (qio_task_get_source (task));Error *err =NULL ; -if (qio_task_propagate_error (task, &err)) { -trace_multifd_tls_outgoing_handshake_error (ioc,error_get_pretty (err)); - }else { +if (!qio_task_propagate_error (task, &err)) {trace_multifd_tls_outgoing_handshake_complete (ioc); +if (multifd_channel_connect (p, ioc, &err)) { +return ; + } } -if (!multifd_channel_connect (p, ioc, err)) { -/* -* Error happen, mark multifd_send_thread status as 'quit' although it -* is not created, and then tell who pay attention to me. -*/ - p->quit = true; -qemu_sem_post (&multifd_send_state->channels_ready); -qemu_sem_post (&p->sem_sync); - } +trace_multifd_tls_outgoing_handshake_error (ioc,error_get_pretty (err)); + +/* +* Error happen, mark multifd_send_thread status as 'quit' although it +* is not created, and then tell who pay attention to me. +*/ + p->quit = true; +qemu_sem_post (&multifd_send_state->channels_ready); +qemu_sem_post (&p->sem_sync); }static void *multifd_tls_handshake_thread (void *opaque)
@@ -813,7 +814,7 @@ static void *multifd_tls_handshake_thread(void *opaque)return NULL ; } -static void multifd_tls_channel_connect (MultiFDSendParams *p, +static bool multifd_tls_channel_connect (MultiFDSendParams *p,QIOChannel *ioc,Error **errp) {
@@ -823,7 +824,7 @@ static void multifd_tls_channel_connect(MultiFDSendParams *p, tioc =migration_tls_client_create (ioc, hostname, errp);if (!tioc) { -return ; +return false; }object_unref (OBJECT (ioc));
@@ -833,31 +834,25 @@ static void multifd_tls_channel_connect(MultiFDSendParams *p,qemu_thread_create (&p->thread,"multifd-tls-handshake-worker" , multifd_tls_handshake_thread, p,QEMU_THREAD_JOINABLE ); +return true; }static bool multifd_channel_connect (MultiFDSendParams *p,QIOChannel *ioc, -Error *error) +Error **errp) {trace_multifd_set_outgoing_channel ( ioc,object_get_typename (OBJECT (ioc)), -migrate_get_current ()->hostname, error); +migrate_get_current ()->hostname); -if (error) { -return false; - }if (migrate_channel_requires_tls_upgrade (ioc)) { -multifd_tls_channel_connect (p, ioc, &error); -if (!error) { -/* -* tls_channel_connect will call back to this -* function after the TLS handshake, -* so we mustn't call multifd_send_thread until then -*/ -return true; - }else { -return false; - } +/* +* tls_channel_connect will call back to this +* function after the TLS handshake, +* so we mustn't call multifd_send_thread until then +*/ +return multifd_tls_channel_connect (p, ioc, errp); + }else {migration_ioc_register_yank (ioc); p->registered_yank = true;
@@ -896,11 +891,12 @@ static void multifd_new_send_channel_async(QIOTask *task, gpointer opaque) p->c = ioc;qio_channel_set_delay (p->c, false); p->running = true; -if (multifd_channel_connect (p, ioc, local_err)) { +if (multifd_channel_connect (p, ioc, &local_err)) {return ; } } +trace_multifd_new_send_channel_async_error (p->id, local_err);multifd_new_send_channel_cleanup (p, ioc, local_err); }
migration/trace-events +2 -1
@@ -125,6 +125,7 @@ postcopy_preempt_reset_channel(void) "" # multifd.c multifd_new_send_channel_async(uint8_t id) "channel %u" +multifd_new_send_channel_async_error(uint8_t id, void *err) "channel=%u err=%p" multifd_recv(uint8_t id, uint64_t packet_num, uint32_t used, uint32_t flags, uint32_t next_packet_size) "channel %u packet_num %" PRIu64 " pages %u flags 0x%x next packet size %u" multifd_recv_new_channel(uint8_t id) "channel %u" multifd_recv_sync_main(long packet_num) "packet num %ld"
@@ -144,7 +145,7 @@ multifd_send_thread_start(uint8_t id) "%u" multifd_tls_outgoing_handshake_start(void *ioc, void *tioc, const char *hostname) "ioc=%p tioc=%p hostname=%s" multifd_tls_outgoing_handshake_error(void *ioc, const char *err) "ioc=%p err=%s" multifd_tls_outgoing_handshake_complete(void *ioc) "ioc=%p" -multifd_set_outgoing_channel(void *ioc, const char *ioctype, const char *hostname, void *err) "ioc=%p ioctype=%s hostname=%s err=%p" +multifd_set_outgoing_channel(void *ioc, const char *ioctype, const char *hostname) "ioc=%p ioctype=%s hostname=%s" # migration.c await_return_path_close_on_source_close(void) ""
Signature · 1 line
2.35.3
Re: [PATCH 3/3] migration/multifd: Clarify Error usage in multifd_channel_connect
Quoted 7 lines · Fabiano Rosas
The function is currently called from two sites, one always gives it a NULL Error and the other always gives it a non-NULL Error.
In the non-NULL case, all it does it trace the error and return. One of the callers already have tracing, add a tracepoint to the other and stop passing the error into the function.
Quoted 6 lines
Cc Markus Armbruster <[email protected]>Signed-off-by Fabiano Rosas <[email protected]>--- migration/multifd.c | 60 ++++++++++++++++++++---------------------- migration/trace-events | 3 ++- 2 files changed, 30 insertions(+), 33 deletions(-)
Re: [PATCH 3/3] migration/multifd: Clarify Error usage in multifd_channel_connect
In reply to Fabiano RosasQuoted 9 lines · Fabiano Rosas
The function is currently called from two sites, one always gives it a NULL Error and the other always gives it a non-NULL Error.
In the non-NULL case, all it does it trace the error and return. One of the callers already have tracing, add a tracepoint to the other and stop passing the error into the function.
Cc Markus Armbruster <[email protected]>Signed-off-by Fabiano Rosas <[email protected]>
queued.