From: Fabiano Rosas <farosas@suse.de>
To: Peter Xu <peterx@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [RFC PATCH 12/25] migration: Fold migration_cleanup() into migration_connect_error_propagate()
Date: Mon, 29 Dec 2025 16:26:50 -0300 [thread overview]
Message-ID: <87ikdp84xx.fsf@suse.de> (raw)
In-Reply-To: <aVLLeZQm376POJ0t@x1.local>
Peter Xu <peterx@redhat.com> writes:
> On Fri, Dec 26, 2025 at 06:19:14PM -0300, Fabiano Rosas wrote:
>> Whenever an error occurs between migrate_init() and the start of
>> migration_thread, do cleanup immediately after.
>>
>> This allows the special casing for resume to be removed from
>> migration_connect(), that check is now done at
>> migration_connect_error_propagate() which already had a case for
>> resume.
>>
>> Signed-off-by: Fabiano Rosas <farosas@suse.de>
>
> Didn't spot anything wrong,
>
> Reviewed-by: Peter Xu <peterx@redhat.com>
>
> One nitpick below,
>
>> ---
>> migration/migration.c | 42 +++++++++++++++++++++++++++---------------
>> 1 file changed, 27 insertions(+), 15 deletions(-)
>>
>> diff --git a/migration/migration.c b/migration/migration.c
>> index 0f1644b276..a66b2d7aaf 100644
>> --- a/migration/migration.c
>> +++ b/migration/migration.c
>> @@ -1576,15 +1576,21 @@ static void migration_connect_error_propagate(MigrationState *s, Error *error)
>> {
>> MigrationStatus current = s->state;
>> MigrationStatus next = MIGRATION_STATUS_NONE;
>> + bool resume = false;
>>
>> switch (current) {
>> case MIGRATION_STATUS_SETUP:
>> next = MIGRATION_STATUS_FAILED;
>> break;
>>
>> + case MIGRATION_STATUS_POSTCOPY_PAUSED:
>> + resume = true;
>> + break;
>> +
>> case MIGRATION_STATUS_POSTCOPY_RECOVER_SETUP:
>> /* Never fail a postcopy migration; switch back to PAUSED instead */
>> next = MIGRATION_STATUS_POSTCOPY_PAUSED;
>> + resume = true;
>> break;
>>
>> case MIGRATION_STATUS_CANCELLING:
>> @@ -1609,6 +1615,10 @@ static void migration_connect_error_propagate(MigrationState *s, Error *error)
>> }
>>
>> migrate_error_propagate(s, error);
>> +
>> + if (!resume) {
>> + migration_cleanup(s);
>> + }
>> }
>>
>> void migration_cancel(void)
>> @@ -2209,12 +2219,19 @@ static gboolean qmp_migrate_finish_cb(QIOChannel *channel,
>> GIOCondition cond,
>> void *opaque)
>> {
>> + MigrationState *s = migrate_get_current();
>> MigrationAddress *addr = opaque;
>> + Error *local_err = NULL;
>> +
>> + qmp_migrate_finish(addr, &local_err);
>> +
>> + if (local_err) {
>> + migration_connect_error_propagate(s, local_err);
>> + }
>>
>> - qmp_migrate_finish(addr, NULL);
>>
>> cpr_state_close();
>> - migrate_hup_delete(migrate_get_current());
>> + migrate_hup_delete(s);
>
> IMHO we should drop these two lines. For error cases, now they'll be done
> in migration_cleanup() above. Actually for success, it's the same, but in
> the cleanup BH.
>
Hmm that would be good, I'll look into it.
> Maybe there're other cases where we can clean the code a bit on cpr;
> there're codes that always does "if (xxx)" and calling them all over the
> places, so it's easy to write such code when drafting a feature, but hard
> to maintain, because it'll be obscure when it'll really trigger, like this
> one. We can leave the rest for later if there're applicable similar
> cleanups.
>
>> qapi_free_MigrationAddress(addr);
>> return G_SOURCE_REMOVE;
>> }
>> @@ -2223,7 +2240,6 @@ void qmp_migrate(const char *uri, bool has_channels,
>> MigrationChannelList *channels, bool has_detach, bool detach,
>> bool has_resume, bool resume, Error **errp)
>> {
>> - Error *local_err = NULL;
>> MigrationState *s = migrate_get_current();
>> g_autoptr(MigrationChannel) channel = NULL;
>> MigrationAddress *addr = NULL;
>> @@ -2280,6 +2296,13 @@ void qmp_migrate(const char *uri, bool has_channels,
>> return;
>> }
>>
>> + /*
>> + * The migrate_prepare() above calls migrate_init(). From this
>> + * point on, until the end of migration, make sure any failures
>> + * eventually result in a call to migration_cleanup().
>> + */
>> + Error *local_err = NULL;
>> +
>> if (!cpr_state_save(cpr_channel, &local_err)) {
>> goto out;
>> }
>> @@ -2299,12 +2322,11 @@ void qmp_migrate(const char *uri, bool has_channels,
>> QAPI_CLONE(MigrationAddress, addr));
>>
>> } else {
>> - qmp_migrate_finish(addr, errp);
>> + qmp_migrate_finish(addr, &local_err);
>> }
>>
>> out:
>> if (local_err) {
>> - yank_unregister_instance(MIGRATION_YANK_INSTANCE);
>> migration_connect_error_propagate(s, error_copy(local_err));
>> error_propagate(errp, local_err);
>> }
>> @@ -2335,12 +2357,6 @@ static void qmp_migrate_finish(MigrationAddress *addr, Error **errp)
>> } else {
>> error_setg(&local_err, "uri is not a valid migration protocol");
>> }
>> -
>> - if (local_err) {
>> - migration_connect_error_propagate(s, error_copy(local_err));
>> - error_propagate(errp, local_err);
>> - return;
>> - }
>> }
>>
>> void qmp_migrate_cancel(Error **errp)
>> @@ -4027,9 +4043,6 @@ void migration_connect(MigrationState *s, Error *error_in)
>> s->expected_downtime = migrate_downtime_limit();
>> if (error_in) {
>> migration_connect_error_propagate(s, error_in);
>> - if (!resume) {
>> - migration_cleanup(s);
>> - }
>> if (s->error) {
>> error_report_err(error_copy(s->error));
>> }
>> @@ -4108,7 +4121,6 @@ void migration_connect(MigrationState *s, Error *error_in)
>>
>> fail:
>> migration_connect_error_propagate(s, local_err);
>> - migration_cleanup(s);
>> if (s->error) {
>> error_report_err(error_copy(s->error));
>> }
>> --
>> 2.51.0
>>
next prev parent reply other threads:[~2025-12-29 19:27 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-26 21:19 [RFC PATCH 00/25] migration: Cleanup early connection code Fabiano Rosas
2025-12-26 21:19 ` [RFC PATCH 01/25] migration: Remove redundant state change Fabiano Rosas
2025-12-29 15:22 ` Peter Xu
2025-12-26 21:19 ` [RFC PATCH 02/25] migration: Fix state change at migration_channel_process_incoming Fabiano Rosas
2025-12-29 15:32 ` Peter Xu
2025-12-26 21:19 ` [RFC PATCH 03/25] migration/tls: Remove unused parameter Fabiano Rosas
2025-12-29 15:33 ` Peter Xu
2025-12-26 21:19 ` [RFC PATCH 04/25] migration: Move multifd_recv_setup call Fabiano Rosas
2025-12-29 15:51 ` Peter Xu
2025-12-29 19:21 ` Fabiano Rosas
2025-12-26 21:19 ` [RFC PATCH 05/25] migration: Cleanup TLS handshake hostname passing Fabiano Rosas
2025-12-29 16:12 ` Peter Xu
2025-12-29 19:38 ` Fabiano Rosas
2025-12-26 21:19 ` [RFC PATCH 06/25] migration: Move postcopy_try_recover into migration_incoming_process Fabiano Rosas
2025-12-29 16:15 ` Peter Xu
2025-12-26 21:19 ` [RFC PATCH 07/25] migration: Use migrate_mode() to query for cpr-transfer Fabiano Rosas
2025-12-29 16:33 ` Peter Xu
2025-12-29 19:23 ` Fabiano Rosas
2025-12-26 21:19 ` [RFC PATCH 08/25] migration: Free the error earlier in the resume case Fabiano Rosas
2025-12-29 16:39 ` [RFC PATCH 08/25] migration: Free the error earlier in the resume case' Peter Xu
2025-12-26 21:19 ` [RFC PATCH 09/25] migration: Move error reporting out of migration_cleanup Fabiano Rosas
2025-12-29 16:45 ` Peter Xu
2025-12-26 21:19 ` [RFC PATCH 10/25] migration: Expand migration_connect_error_propagate to cover cancelling Fabiano Rosas
2025-12-29 17:12 ` Peter Xu
2025-12-26 21:19 ` [RFC PATCH 11/25] migration: yank: Move register instance earlier Fabiano Rosas
2025-12-29 17:17 ` Peter Xu
2025-12-26 21:19 ` [RFC PATCH 12/25] migration: Fold migration_cleanup() into migration_connect_error_propagate() Fabiano Rosas
2025-12-29 18:42 ` Peter Xu
2025-12-29 19:26 ` Fabiano Rosas [this message]
2025-12-26 21:19 ` [RFC PATCH 13/25] migration: Handle error in the early async paths Fabiano Rosas
2025-12-29 19:08 ` Peter Xu
2025-12-29 19:35 ` Fabiano Rosas
2025-12-26 21:19 ` [RFC PATCH 14/25] migration: Remove QEMUFile from channel.c Fabiano Rosas
2025-12-29 19:36 ` Peter Xu
2025-12-29 19:51 ` Fabiano Rosas
2025-12-26 21:19 ` [RFC PATCH 15/25] migration/channel: Rename migration_channel_connect Fabiano Rosas
2025-12-29 19:40 ` Peter Xu
2025-12-26 21:19 ` [RFC PATCH 16/25] migration: Rename instances of start Fabiano Rosas
2025-12-26 21:19 ` [RFC PATCH 17/25] migration: Move channel code to channel.c Fabiano Rosas
2025-12-26 21:19 ` [RFC PATCH 18/25] migration: Move transport connection code into channel.c Fabiano Rosas
2025-12-26 21:19 ` [RFC PATCH 19/25] migration/channel: Make synchronous calls evident Fabiano Rosas
2025-12-26 21:19 ` [RFC PATCH 20/25] migration/channel: Use switch statements in outgoing code Fabiano Rosas
2025-12-26 21:19 ` [RFC PATCH 21/25] migration/channel: Cleanup early passing of MigrationState Fabiano Rosas
2025-12-26 21:19 ` [RFC PATCH 22/25] migration/channel: Merge both sides of the connection initiation code Fabiano Rosas
2025-12-29 20:06 ` Peter Xu
2025-12-29 21:14 ` Fabiano Rosas
2025-12-29 22:05 ` Peter Xu
2025-12-26 21:19 ` [RFC PATCH 23/25] migration: Move channel parsing to channel.c Fabiano Rosas
2025-12-29 21:01 ` Peter Xu
2025-12-26 21:19 ` [RFC PATCH 24/25] migration: Move URI " Fabiano Rosas
2025-12-29 21:08 ` Peter Xu
2025-12-29 21:22 ` Fabiano Rosas
2025-12-29 22:11 ` Peter Xu
2025-12-26 21:19 ` [RFC PATCH 25/25] migration: Remove qmp_migrate_finish Fabiano Rosas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ikdp84xx.fsf@suse.de \
--to=farosas@suse.de \
--cc=peterx@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.