* [PATCH 0/3] migration/multifd: General cleanups @ 2023-10-12 13:43 Fabiano Rosas 2023-10-12 13:43 ` [PATCH 1/3] migration/multifd: Remove direct "socket" references Fabiano Rosas ` (2 more replies) 0 siblings, 3 replies; 9+ messages in thread From: Fabiano Rosas @ 2023-10-12 13:43 UTC (permalink / raw) To: qemu-devel; +Cc: Juan Quintela, Peter Xu 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(-) -- 2.35.3 ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/3] migration/multifd: Remove direct "socket" references 2023-10-12 13:43 [PATCH 0/3] migration/multifd: General cleanups Fabiano Rosas @ 2023-10-12 13:43 ` Fabiano Rosas 2023-10-12 13:53 ` Philippe Mathieu-Daudé 2023-10-16 8:45 ` Juan Quintela 2023-10-12 13:43 ` [PATCH 2/3] migration/multifd: Unify multifd_send_thread error paths Fabiano Rosas 2023-10-12 13:43 ` [PATCH 3/3] migration/multifd: Clarify Error usage in multifd_channel_connect Fabiano Rosas 2 siblings, 2 replies; 9+ messages in thread From: Fabiano Rosas @ 2023-10-12 13:43 UTC (permalink / raw) To: qemu-devel; +Cc: Juan Quintela, Peter Xu, Leonardo Bras We're about to enable support for other transports in multifd, so remove direct references to sockets. Signed-off-by: Fabiano Rosas <farosas@suse.de> --- migration/multifd.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index 0f6b203877..a7c7a947e3 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -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++) { -- 2.35.3 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] migration/multifd: Remove direct "socket" references 2023-10-12 13:43 ` [PATCH 1/3] migration/multifd: Remove direct "socket" references Fabiano Rosas @ 2023-10-12 13:53 ` Philippe Mathieu-Daudé 2023-10-16 8:45 ` Juan Quintela 1 sibling, 0 replies; 9+ messages in thread From: Philippe Mathieu-Daudé @ 2023-10-12 13:53 UTC (permalink / raw) To: Fabiano Rosas, qemu-devel; +Cc: Juan Quintela, Peter Xu, Leonardo Bras On 12/10/23 15:43, Fabiano Rosas wrote: > We're about to enable support for other transports in multifd, so > remove direct references to sockets. > > Signed-off-by: Fabiano Rosas <farosas@suse.de> > --- > migration/multifd.c | 22 ++++++++++++++++------ > 1 file changed, 16 insertions(+), 6 deletions(-) Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] migration/multifd: Remove direct "socket" references 2023-10-12 13:43 ` [PATCH 1/3] migration/multifd: Remove direct "socket" references Fabiano Rosas 2023-10-12 13:53 ` Philippe Mathieu-Daudé @ 2023-10-16 8:45 ` Juan Quintela 1 sibling, 0 replies; 9+ messages in thread From: Juan Quintela @ 2023-10-16 8:45 UTC (permalink / raw) To: Fabiano Rosas; +Cc: qemu-devel, Peter Xu, Leonardo Bras Fabiano Rosas <farosas@suse.de> wrote: > We're about to enable support for other transports in multifd, so > remove direct references to sockets. > > Signed-off-by: Fabiano Rosas <farosas@suse.de> Reviewed-by: Juan Quintela <quintela@redhat.com> queued. ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/3] migration/multifd: Unify multifd_send_thread error paths 2023-10-12 13:43 [PATCH 0/3] migration/multifd: General cleanups Fabiano Rosas 2023-10-12 13:43 ` [PATCH 1/3] migration/multifd: Remove direct "socket" references Fabiano Rosas @ 2023-10-12 13:43 ` Fabiano Rosas 2023-10-16 8:48 ` Juan Quintela 2023-10-12 13:43 ` [PATCH 3/3] migration/multifd: Clarify Error usage in multifd_channel_connect Fabiano Rosas 2 siblings, 1 reply; 9+ messages in thread From: Fabiano Rosas @ 2023-10-12 13:43 UTC (permalink / raw) To: qemu-devel; +Cc: Juan Quintela, Peter Xu, Leonardo Bras 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. 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 <farosas@suse.de> --- migration/multifd.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index a7c7a947e3..bc3994c567 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -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); -- 2.35.3 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/3] migration/multifd: Unify multifd_send_thread error paths 2023-10-12 13:43 ` [PATCH 2/3] migration/multifd: Unify multifd_send_thread error paths Fabiano Rosas @ 2023-10-16 8:48 ` Juan Quintela 0 siblings, 0 replies; 9+ messages in thread From: Juan Quintela @ 2023-10-16 8:48 UTC (permalink / raw) To: Fabiano Rosas; +Cc: qemu-devel, Peter Xu, Leonardo Bras Fabiano Rosas <farosas@suse.de> wrote: > 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. > > 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 <farosas@suse.de> Reviewed-by: Juan Quintela <quintela@redhat.com> queued. ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 3/3] migration/multifd: Clarify Error usage in multifd_channel_connect 2023-10-12 13:43 [PATCH 0/3] migration/multifd: General cleanups Fabiano Rosas 2023-10-12 13:43 ` [PATCH 1/3] migration/multifd: Remove direct "socket" references Fabiano Rosas 2023-10-12 13:43 ` [PATCH 2/3] migration/multifd: Unify multifd_send_thread error paths Fabiano Rosas @ 2023-10-12 13:43 ` Fabiano Rosas 2023-10-12 13:53 ` Philippe Mathieu-Daudé 2023-10-16 8:50 ` Juan Quintela 2 siblings, 2 replies; 9+ messages in thread From: Fabiano Rosas @ 2023-10-12 13:43 UTC (permalink / raw) To: qemu-devel; +Cc: Juan Quintela, Peter Xu, Markus Armbruster, Leonardo Bras 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 <armbru@redhat.com> Signed-off-by: Fabiano Rosas <farosas@suse.de> --- migration/multifd.c | 60 ++++++++++++++++++++---------------------- migration/trace-events | 3 ++- 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/migration/multifd.c b/migration/multifd.c index bc3994c567..2947a99dc0 100644 --- a/migration/multifd.c +++ b/migration/multifd.c @@ -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); } diff --git a/migration/trace-events b/migration/trace-events index ee9c8f4d63..0b442cc7cc 100644 --- a/migration/trace-events +++ b/migration/trace-events @@ -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) "" -- 2.35.3 ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] migration/multifd: Clarify Error usage in multifd_channel_connect 2023-10-12 13:43 ` [PATCH 3/3] migration/multifd: Clarify Error usage in multifd_channel_connect Fabiano Rosas @ 2023-10-12 13:53 ` Philippe Mathieu-Daudé 2023-10-16 8:50 ` Juan Quintela 1 sibling, 0 replies; 9+ messages in thread From: Philippe Mathieu-Daudé @ 2023-10-12 13:53 UTC (permalink / raw) To: Fabiano Rosas, qemu-devel Cc: Juan Quintela, Peter Xu, Markus Armbruster, Leonardo Bras On 12/10/23 15:43, Fabiano Rosas wrote: > 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 <armbru@redhat.com> > Signed-off-by: Fabiano Rosas <farosas@suse.de> > --- > migration/multifd.c | 60 ++++++++++++++++++++---------------------- > migration/trace-events | 3 ++- > 2 files changed, 30 insertions(+), 33 deletions(-) Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] migration/multifd: Clarify Error usage in multifd_channel_connect 2023-10-12 13:43 ` [PATCH 3/3] migration/multifd: Clarify Error usage in multifd_channel_connect Fabiano Rosas 2023-10-12 13:53 ` Philippe Mathieu-Daudé @ 2023-10-16 8:50 ` Juan Quintela 1 sibling, 0 replies; 9+ messages in thread From: Juan Quintela @ 2023-10-16 8:50 UTC (permalink / raw) To: Fabiano Rosas; +Cc: qemu-devel, Peter Xu, Markus Armbruster, Leonardo Bras Fabiano Rosas <farosas@suse.de> wrote: > 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 <armbru@redhat.com> > Signed-off-by: Fabiano Rosas <farosas@suse.de> Reviewed-by: Juan Quintela <quintela@redhat.com> queued. ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2023-10-16 8:51 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-10-12 13:43 [PATCH 0/3] migration/multifd: General cleanups Fabiano Rosas 2023-10-12 13:43 ` [PATCH 1/3] migration/multifd: Remove direct "socket" references Fabiano Rosas 2023-10-12 13:53 ` Philippe Mathieu-Daudé 2023-10-16 8:45 ` Juan Quintela 2023-10-12 13:43 ` [PATCH 2/3] migration/multifd: Unify multifd_send_thread error paths Fabiano Rosas 2023-10-16 8:48 ` Juan Quintela 2023-10-12 13:43 ` [PATCH 3/3] migration/multifd: Clarify Error usage in multifd_channel_connect Fabiano Rosas 2023-10-12 13:53 ` Philippe Mathieu-Daudé 2023-10-16 8:50 ` Juan Quintela
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).