All of lore.kernel.org
 help / color / mirror / Atom feed
From: Fabiano Rosas <farosas@suse.de>
To: Prasad Pandit <ppandit@redhat.com>
Cc: qemu-devel@nongnu.org, peterx@redhat.com, armbru@redhat.com
Subject: Re: [PATCH 5/5] migration/options: Use QAPI_MERGE in migrate_params_test_apply
Date: Thu, 22 Jan 2026 11:21:20 -0300	[thread overview]
Message-ID: <87qzrhk9sv.fsf@suse.de> (raw)
In-Reply-To: <CAE8KmOwGXSXpmFhLod57R8LE6fPEg0rgbOPki7LQ3FAWnCD3gg@mail.gmail.com>

Prasad Pandit <ppandit@redhat.com> writes:

> Hi,
>
> On Thu, 22 Jan 2026 at 03:41, Fabiano Rosas <farosas@suse.de> wrote:
>> See if the following looks better to you. It's not one single function,
>> but I folded what I could while keeping the distinct function names.
>>
>> static void migrate_params_apply(MigrationParameters *new, Error **errp)
>> {
>>     MigrationState *s = migrate_get_current();
>>     MigrationParameters *cur = &s->parameters;
>>     MigrationParameters *tmp = QAPI_CLONE(MigrationParameters, cur);
>>
>>     QAPI_MERGE(MigrationParameters, tmp, new);
>>
>>     if (!migrate_params_check(tmp, errp)) {
>>         return;
>>     }
>>
>>     migrate_ptr_opts_free(cur);
>>
>>     /* mark all present, so they're all copied */
>>     migrate_mark_all_params_present(params);
>>     QAPI_CLONE_MEMBERS(MigrationParameters, cur, params);
>>
>>     migrate_post_update_params(new, errp);
>> }
>>
>> void qmp_migrate_set_parameters(MigrationParameters *new, Error **errp)
>> {
>>     /*
>>      * Convert QTYPE_QNULL and NULL to the empty string (""). Even
>>      * though NULL is cleaner to deal with in C code, that would force
>>      * query-migrate-parameters to convert it once more to the empty
>>      * string, so avoid that. The migrate_tls_*() helpers that expose
>>      * the options to the rest of the migration code already use
>>      * return NULL when the empty string is found.
>>      */
>>     tls_opt_to_str(new->tls_creds);
>>     tls_opt_to_str(new->tls_hostname);
>>     tls_opt_to_str(new->tls_authz);
>>
>>     migrate_params_apply(new, errp);
>> }
>>
>
> * I'm thinking as:
> ===
> v0:
>
> void qmp_migrate_set_parameters(MigrationParameters *new, Error **errp)
> {
>     /*
>      * Convert QTYPE_QNULL and NULL to the empty string (""). Even
>      * though NULL is cleaner to deal with in C code, that would force
>      * query-migrate-parameters to convert it once more to the empty
>      * string, so avoid that. The migrate_tls_*() helpers that expose
>      * the options to the rest of the migration code already use
>      * return NULL when the empty string is found.
>      */
>     tls_opt_to_str(new->tls_creds);
>     tls_opt_to_str(new->tls_hostname);
>     tls_opt_to_str(new->tls_authz);
>
>     MigrationState *s = migrate_get_current();
>     MigrationParameters *cur = &s->parameters;
>     MigrationParameters *tmp = QAPI_CLONE(MigrationParameters, cur);
>
>     QAPI_MERGE(MigrationParameters, tmp, new);
>
>     if (!migrate_params_check(tmp, errp)) {
>         return;
>     }
>     migrate_ptr_opts_free(cur);
>
>     /* mark all present, so they're all copied */
>     migrate_mark_all_params_present(tpm);
>     QAPI_CLONE_MEMBERS(MigrationParameters, cur, tmp);
>
>     migrate_post_update_params(cur, errp);
> }
> ===
> v1:
>
> void qmp_migrate_set_parameters(MigrationParameters *new, Error **errp)
> {
>     /*
>      * Convert QTYPE_QNULL and NULL to the empty string (""). Even
>      * though NULL is cleaner to deal with in C code, that would force
>      * query-migrate-parameters to convert it once more to the empty
>      * string, so avoid that. The migrate_tls_*() helpers that expose
>      * the options to the rest of the migration code already use
>      * return NULL when the empty string is found.
>      */
>     tls_opt_to_str(new->tls_creds);
>     tls_opt_to_str(new->tls_hostname);
>     tls_opt_to_str(new->tls_authz);
>
>     MigrationState *s = migrate_get_current();
>     MigrationParameters *cur = &s->parameters;
>     MigrationParameters *tmp = QAPI_CLONE(MigrationParameters, cur);      ...[1]
>
>     QAPI_MERGE(MigrationParameters, tmp, new);
>                  ...[2]
>
>     if (!migrate_params_check(tmp, errp)) {
>         return;
>     }
>     migrate_ptr_opts_free(cur);
>
>     /* mark all present, so they're all copied */
>     migrate_mark_all_params_present(tpm);
>     QAPI_CLONE_MEMBERS(MigrationParameters, cur, tmp);
>        ...[3]
>
>     /* update MigrationState after parameters change */
>                      ...[4]
>     if (cur->has_max_bandwidth) {
>         if (s->to_dst_file && !migration_in_postcopy()) {
>             migration_rate_set(cur->max_bandwidth);
>         }
>     }
>     if (cur->has_x_checkpoint_delay) {
>         colo_checkpoint_delay_set();
>     }
>     if (cur->has_xbzrle_cache_size) {
>         xbzrle_cache_resize(cur->xbzrle_cache_size, errp);
>     }
>     if (cur->has_max_postcopy_bandwidth) {
>         if (s->to_dst_file && migration_in_postcopy()) {
>             migration_rate_set(cur->max_postcopy_bandwidth);
>         }
>     }
> }
> ===
>
> * I'd go with v1 above.
> * Reasons for folding migrate_params_apply() and migrate_post_update_params():
>    - Both static functions are called _only_ from
> qmp_migrate_set_parameters(). They are not reusable from elsewhere.
>    - Earlier migrate_params_apply() was quite long due to  if...else
> conditionals, so it made sense to break one long function into 2-3
> smaller ones.
>    - Now with QAPI_CLONE/MERGE changes qmp_migrate_set_parameters() is
> concise and easy to follow.
>    - Reader can see all steps (1,2,3,4 above) together in one function.
>
> * Just sharing my thoughts. You pick what you think is best.
>

Ok, thanks, let's see in what mood I'm in when reposting =)

> Thank you.
> ---
>   - Prasad


      reply	other threads:[~2026-01-22 14:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-14 13:23 [PATCH 0/5] qapi: Use visitors for migration parameters handling Fabiano Rosas
2026-01-14 13:23 ` [PATCH 1/5] migration: Use QAPI_CLONE_MEMBERS in migrate_params_test_apply Fabiano Rosas
2026-01-14 15:10   ` Peter Xu
2026-01-14 18:01     ` Fabiano Rosas
2026-01-15 14:26       ` Fabiano Rosas
2026-01-14 13:23 ` [PATCH 2/5] migration: Use QAPI_CLONE_MEMBERS in migrate_params_apply Fabiano Rosas
2026-01-21 12:00   ` Prasad Pandit
2026-01-21 12:42     ` Fabiano Rosas
2026-01-22 12:37       ` Prasad Pandit
2026-01-22 14:16         ` Fabiano Rosas
2026-01-21 12:20   ` Prasad Pandit
2026-01-21 21:05     ` Fabiano Rosas
2026-01-22  8:14       ` Prasad Pandit
2026-01-22 14:17         ` Fabiano Rosas
2026-01-14 13:23 ` [PATCH 3/5] qapi: Implement qapi_dealloc_present_visitor Fabiano Rosas
2026-01-14 13:23 ` [PATCH 4/5] qapi: Add QAPI_MERGE Fabiano Rosas
2026-01-14 13:23 ` [PATCH 5/5] migration/options: Use QAPI_MERGE in migrate_params_test_apply Fabiano Rosas
2026-01-21 12:56   ` Prasad Pandit
2026-01-21 22:11     ` Fabiano Rosas
2026-01-22  9:24       ` Prasad Pandit
2026-01-22 14:21         ` Fabiano Rosas [this message]

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=87qzrhk9sv.fsf@suse.de \
    --to=farosas@suse.de \
    --cc=armbru@redhat.com \
    --cc=peterx@redhat.com \
    --cc=ppandit@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.