From: Fabiano Rosas <farosas@suse.de>
To: Peter Xu <peterx@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH 13/18] migration: Use output visitor in info command
Date: Fri, 04 Sep 2026 10:41:21 -0300 [thread overview]
Message-ID: <87zexx6sn2.fsf@suse.de> (raw)
In-Reply-To: <apqzsh7pIkmKTYYg@x1.local>
Peter Xu <peterx@redhat.com> writes:
> On Wed, Sep 02, 2026 at 07:15:41PM -0300, Fabiano Rosas wrote:
>> The hmp_info_migrate_parameters function currently open-codes the
>> mon_printf calls for each migration parameter. As with the set command
>> in the last patch, this should not be necessary as the QAPI
>> infrastructure already has generated code that takes type and struct
>> member names into account, including converting _ from C into the '-'
>> character as part of parameter names strings.
>>
>> The current code is also quite painful to rebase if a series has been
>> carried for a long time while parameters have been added in master.
>>
>> Replace all of this with a conversion from MigrationParameters to
>> QDict using an output visitor and a loop over the QDict that prints
>> per-QAPI-type formatted strings.
>>
>> Modelled after block/qapi.c:dump_qobject, but with some changes to
>> keep the migration command output formatting.
>>
>> Note that this was not a for-free improvement, the HMP command format
>> output was changed incompatibly in a previous patch. It doesn't output
>> units anymore.
>
> IIUC both qlist and qdict are only used in BitmapMigrationNodeAlias only.
> It would be nice to attach an example of HMP dump before/after the change
> of these two patches, either in previous patch or here (assuming the layout
> changed once). In case HMP has some suggestion in general, I suggest copy
> Dave when repost in case he has something to say.
>
Will do.
>>
>> Signed-off-by: Fabiano Rosas <farosas@suse.de>
>> ---
>> migration/migration-hmp-cmds.c | 243 ++++++++++++++-------------------
>> 1 file changed, 100 insertions(+), 143 deletions(-)
>>
>> diff --git a/migration/migration-hmp-cmds.c b/migration/migration-hmp-cmds.c
>> index 089c6d4ff46..dff69650a0c 100644
>> --- a/migration/migration-hmp-cmds.c
>> +++ b/migration/migration-hmp-cmds.c
>> @@ -25,7 +25,12 @@
>> #include "qapi/qapi-commands-migration.h"
>> #include "qapi/qapi-visit-migration.h"
>> #include "qapi/qobject-input-visitor.h"
>> +#include "qapi/qobject-output-visitor.h"
>> +#include "qobject/qbool.h"
>> #include "qobject/qdict.h"
>> +#include "qobject/qjson.h"
>> +#include "qobject/qlist.h"
>> +#include "qobject/qnum.h"
>> #include "qobject/qstring.h"
>> #include "qapi/string-input-visitor.h"
>> #include "qapi/string-output-visitor.h"
>> @@ -316,170 +321,122 @@ void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
>> qapi_free_MigrationCapabilityStatusList(caps);
>> }
>>
>> -static void monitor_print_cpr_exec_command(Monitor *mon, strList *args)
>> +static QDict *migrate_params_to_dict(MigrationParameters *p, Error **errp)
>> {
>> - monitor_printf(mon, "%s:",
>> - MigrationParameter_str(MIGRATION_PARAMETER_CPR_EXEC_COMMAND));
>> + QObject *obj = NULL;
>> + Visitor *v = qobject_output_visitor_new(&obj);
>>
>> - while (args) {
>> - monitor_printf(mon, " %s", args->value);
>> - args = args->next;
>> + if (visit_type_MigrationParameters(v, NULL, &p, errp)) {
>> + visit_complete(v, &obj);
>> }
>> - monitor_printf(mon, "\n");
>> + visit_free(v);
>> + return qobject_to(QDict, obj);
>> }
>
> This exact function also exists in options.c (with the same name and
> impl). Can reuse.
>
Of course! I just forgot to do it. Thanks.
>>
>> -void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
>> +static void hmp_migrate_print_qobject(Monitor *mon, const char *label,
>> + QObject *obj)
>> {
>> - MigrationParameters *params;
>> - MigrationState *s = migrate_get_current();
>> + const char *sep;
>>
>> - params = qmp_query_migrate_parameters(NULL);
>> + if (!obj) {
>> + return;
>> + }
>>
>> - if (params) {
>> - monitor_printf(mon, "%s: %" PRIu64 "\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
>> - params->announce_initial);
>> - monitor_printf(mon, "%s: %" PRIu64 "\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_MAX),
>> - params->announce_max);
>> - monitor_printf(mon, "%s: %" PRIu64 "\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_ROUNDS),
>> - params->announce_rounds);
>> - monitor_printf(mon, "%s: %" PRIu64 "\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_STEP),
>> - params->announce_step);
>> - assert(params->has_throttle_trigger_threshold);
>> - monitor_printf(mon, "%s: %u\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD),
>> - params->throttle_trigger_threshold);
>> - assert(params->has_cpu_throttle_initial);
>> - monitor_printf(mon, "%s: %u\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL),
>> - params->cpu_throttle_initial);
>> - assert(params->has_cpu_throttle_increment);
>> - monitor_printf(mon, "%s: %u\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
>> - params->cpu_throttle_increment);
>> - assert(params->has_cpu_throttle_tailslow);
>> - monitor_printf(mon, "%s: %s\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW),
>> - params->cpu_throttle_tailslow ? "on" : "off");
>> - assert(params->has_max_cpu_throttle);
>> - monitor_printf(mon, "%s: %u\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_MAX_CPU_THROTTLE),
>> - params->max_cpu_throttle);
>> - assert(params->tls_creds);
>> - monitor_printf(mon, "%s: %s\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
>> - params->tls_creds->u.s);
>> - assert(params->tls_hostname);
>> - monitor_printf(mon, "%s: %s\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
>> - params->tls_hostname->u.s);
>> - assert(params->tls_authz);
>> - monitor_printf(mon, "%s: %s\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
>> - params->tls_authz->u.s);
>> - assert(params->has_max_bandwidth);
>> - monitor_printf(mon, "%s: %" PRIu64 "\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
>> - params->max_bandwidth);
>> - assert(params->has_avail_switchover_bandwidth);
>> - monitor_printf(mon, "%s: %" PRIu64 "\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_AVAIL_SWITCHOVER_BANDWIDTH),
>> - params->avail_switchover_bandwidth);
>> - assert(params->has_max_postcopy_bandwidth);
>> - monitor_printf(mon, "%s: %" PRIu64 "\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
>> - params->max_postcopy_bandwidth);
>> - assert(params->has_downtime_limit);
>> - monitor_printf(mon, "%s: %" PRIu64 "\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
>> - params->downtime_limit);
>> - assert(params->has_x_checkpoint_delay);
>> - monitor_printf(mon, "%s: %u\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
>> - params->x_checkpoint_delay);
>> - monitor_printf(mon, "%s: %u\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_CHANNELS),
>> - params->multifd_channels);
>> - monitor_printf(mon, "%s: %s\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_MULTIFD_COMPRESSION),
>> - MultiFDCompression_str(params->multifd_compression));
>> - assert(params->has_zero_page_detection);
>> - monitor_printf(mon, "%s: %s\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_ZERO_PAGE_DETECTION),
>> - qapi_enum_lookup(&ZeroPageDetection_lookup,
>> - params->zero_page_detection));
>> - monitor_printf(mon, "%s: %" PRIu64 "\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
>> - params->xbzrle_cache_size);
>> + /*
>> + * Put a space after labels
>> + * foo: bar
>> + * ^
>> + */
>> + if (label && label[0] && label[strlen(label) - 1] == ':') {
>> + sep = " ";
>> + } else {
>> + sep = "";
>> + }
>>
>> - if (s->has_block_bitmap_mapping) {
>> - BitmapMigrationNodeAliasList *nal;
>> - BitmapMigrationNodeAlias *na;
>> - BitmapMigrationBitmapAliasList *bal;
>> - BitmapMigrationBitmapAlias *ba;
>> - BitmapMigrationBitmapAliasTransform *bat;
>> + switch (qobject_type(obj)) {
>> + case QTYPE_NONE:
>> + g_assert_not_reached();
>> + case QTYPE_QNULL:
>> + break;
>
> Shall we assert too if we don't expect it?
>
Could be, I'll check.
>> + case QTYPE_QNUM: {
>> + int64_t i64;
>>
>> - monitor_printf(mon, "%s:",
>> - MigrationParameter_str(
>> - MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING));
>> + if (qnum_get_try_int(qobject_to(QNum, obj), &i64)) {
>> + monitor_printf(mon, "%s%s%" PRId64, label, sep, i64);
>
> Should we use qnum_to_string() like what dump_qobject() does?
>
I missed that helper, let me see.
> Logically any size/u64 parameter (which may not be a normal use case..) can
> be set larger than INT64_MAX, so qnum_get_try_int() may return false? Here
> skipping to print anything is benign if it only happens with a malicious
> monitor client, but I think we should try to capture all cases.
>
Yeah, makes sense.
>> + }
>> + break;
>> + }
>> + case QTYPE_QSTRING: {
>> + QString *str = qobject_to(QString, obj);
>>
>> - for (nal = params->block_bitmap_mapping; nal; nal = nal->next)
>> - {
>> - na = nal->value;
>> - monitor_printf(mon, " bitmaps:");
>> - for (bal = na->bitmaps; bal; bal = bal->next) {
>> - ba = bal->value;
>> - bat = ba->transform;
>> + if (str) {
>
> Any chance str==NULL here?
>
Yes. But I get your point, see below.
>> + monitor_printf(mon, "%s%s%s", label, sep, qstring_get_str(str));
>> + }
>> + break;
>> + }
>> + case QTYPE_QDICT: {
>> + QDict *d = qobject_to(QDict, obj);
>> + const QDictEntry *e;
>> + int i = 0;
>>
>> - monitor_printf(mon, " name: %s", ba->name);
>> - if (bat && bat->has_persistent) {
>> - if (bat->persistent) {
>> - monitor_printf(mon, " persistent: on");
>> - } else {
>> - monitor_printf(mon, " persistent: off");
>> - }
>> - }
>> - monitor_printf(mon, " alias: %s", ba->alias);
>> + if (d) {
>> + for (e = qdict_first(d); e; e = qdict_next(d, e), i++) {
>> + g_autofree char *l = g_strdup_printf("%s:", qdict_entry_key(e));
>> + if (i) {
>> + monitor_printf(mon, " ");
>> }
>> - monitor_printf(mon, " node-name: %s alias: %s",
>> - na->node_name, na->alias);
>> + hmp_migrate_print_qobject(mon, l, qdict_entry_value(e));
>> }
>> -
>> - monitor_printf(mon, "\n");
>> }
>> + break;
>> + }
>> + case QTYPE_QLIST: {
>> + QList *l = qobject_to(QList, obj);
>> + const QListEntry *e;
>>
>> - monitor_printf(mon, "%s: %" PRIu64 "\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_X_VCPU_DIRTY_LIMIT_PERIOD),
>> - params->x_vcpu_dirty_limit_period);
>> + if (l) {
>> + monitor_printf(mon, "%s", label);
>>
>> - monitor_printf(mon, "%s: %" PRIu64 "\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_VCPU_DIRTY_LIMIT),
>> - params->vcpu_dirty_limit);
>> + for (e = qlist_first(l); e; e = qlist_next(e)) {
>> + /*
>> + * In the first iteration, this is the space after the
>> + * colon, otherwise it's the space between list
>> + * elements.
>> + */
>> + monitor_printf(mon, " ");
>> + hmp_migrate_print_qobject(mon, "", e->value);
>> + }
>> + }
>> + break;
>> + }
>> + case QTYPE_QBOOL: {
>> + QBool *b = qobject_to(QBool, obj);
>> + if (b) {
>
> Similarly, I'd drop "if" if it will always happen, making qbool_get_bool()
> assert itself by deref.
>
I'd rather not have such asserts in user-facing code. Even with testing,
it's hard to ensure this 'obj' will reach here in integrity.
>> + monitor_printf(mon, "%s%s%s", label, sep,
>> + qbool_get_bool(b) ? "on" : "off");
>> + }
>> + break;
>> + }
>> + default:
>> + g_assert_not_reached();
>> + break;
>> + }
>> +}
>>
>> - assert(params->has_mode);
>> - monitor_printf(mon, "%s: %s\n",
>> - MigrationParameter_str(MIGRATION_PARAMETER_MODE),
>> - qapi_enum_lookup(&MigMode_lookup, params->mode));
>> +void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
>> +{
>> + MigrationParameters *params = qmp_query_migrate_parameters(NULL);
>> + g_autoptr(QDict) d;
>> + const QDictEntry *e;
>>
>> - if (params->has_direct_io) {
>> - monitor_printf(mon, "%s: %s\n",
>> - MigrationParameter_str(
>> - MIGRATION_PARAMETER_DIRECT_IO),
>> - params->direct_io ? "on" : "off");
>> - }
>> + assert(params);
>>
>> - if (params->has_x_rdma_chunk_size) {
>> - monitor_printf(mon, "%s: %" PRIu64 "\n",
>> - MigrationParameter_str(
>> - MIGRATION_PARAMETER_X_RDMA_CHUNK_SIZE),
>> - params->x_rdma_chunk_size);
>> - }
>> + d = migrate_params_to_dict(params, NULL);
>> + for (e = qdict_first(d); e; e = qdict_next(d, e)) {
>> + g_autofree char *label = g_strdup_printf("%s:", qdict_entry_key(e));
>>
>> - assert(params->has_cpr_exec_command);
>> - monitor_print_cpr_exec_command(mon, params->cpr_exec_command);
>> + hmp_migrate_print_qobject(mon, label, qdict_entry_value(e));
>> + monitor_printf(mon, "\n");
>> }
>>
>> qapi_free_MigrationParameters(params);
>> --
>> 2.53.0
>>
next prev parent reply other threads:[~2026-09-04 13:42 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 22:15 [PATCH 00/18] migration: MigrationParameters changes Fabiano Rosas
2026-09-02 22:15 ` [PATCH 01/18] checkpatch: Fix checking of newlines in error messages Fabiano Rosas
2026-09-03 17:37 ` Peter Xu
2026-09-03 17:46 ` Fabiano Rosas
2026-09-03 18:00 ` Peter Xu
2026-09-03 18:35 ` Fabiano Rosas
2026-09-04 8:56 ` Markus Armbruster
2026-09-04 9:15 ` Peter Maydell
2026-09-04 12:09 ` Peter Xu
2026-09-04 14:00 ` Markus Armbruster
2026-09-02 22:15 ` [PATCH 02/18] migration/options.c: Don't export migrate_tls_opts_free Fabiano Rosas
2026-09-02 22:15 ` [PATCH 03/18] migration: Rename variables in qmp_migrate_set_parameters Fabiano Rosas
2026-09-03 17:44 ` Peter Xu
2026-09-02 22:15 ` [PATCH 04/18] migration: Use QAPI_CLONE_MEMBERS in migrate_params_apply Fabiano Rosas
2026-09-02 22:15 ` [PATCH 05/18] migration: Merge parameter structs instead of assigning one by one Fabiano Rosas
2026-09-03 18:20 ` Peter Xu
2026-09-03 19:03 ` Fabiano Rosas
2026-09-02 22:15 ` [PATCH 06/18] migration: Open code migrate_params_apply Fabiano Rosas
2026-09-02 22:15 ` [PATCH 07/18] migration: Stop freeing s->parameters members individually Fabiano Rosas
2026-09-02 22:15 ` [PATCH 08/18] migration: Use migrate_params_free during finalize Fabiano Rosas
2026-09-02 22:15 ` [PATCH 09/18] tests/qtest/migration: Add a test for HMP Fabiano Rosas
2026-09-03 20:38 ` Peter Xu
2026-09-03 20:42 ` Peter Xu
2026-09-02 22:15 ` [PATCH 10/18] migration: Validate that all params are set for query Fabiano Rosas
2026-09-03 18:59 ` Peter Xu
2026-09-04 15:11 ` Fabiano Rosas
2026-09-02 22:15 ` [PATCH 11/18] migration: Use keyval input visitor in HMP set command Fabiano Rosas
2026-09-03 19:44 ` Peter Xu
2026-09-03 20:24 ` Dr. David Alan Gilbert
2026-09-04 15:26 ` Peter Xu
2026-09-04 9:45 ` Markus Armbruster
2026-09-02 22:15 ` [PATCH 12/18] migration: Change HMP 'info migrate_parameters' output Fabiano Rosas
2026-09-03 20:25 ` Peter Xu
2026-09-02 22:15 ` [PATCH 13/18] migration: Use output visitor in info command Fabiano Rosas
2026-09-04 12:04 ` Peter Xu
2026-09-04 13:41 ` Fabiano Rosas [this message]
2026-09-04 14:54 ` Peter Xu
2026-09-04 15:08 ` Fabiano Rosas
2026-09-02 22:15 ` [PATCH 14/18] migration: Rewrite migrate_set_parameter_completion using QDict Fabiano Rosas
2026-09-03 20:23 ` Peter Xu
2026-09-02 22:15 ` [PATCH 15/18] qapi/migration: Remove MigrationParameter Fabiano Rosas
2026-09-04 9:07 ` Markus Armbruster
2026-09-04 12:24 ` Peter Xu
2026-09-04 13:49 ` Fabiano Rosas
2026-09-02 22:15 ` [PATCH 16/18] migration: Add capabilities into MigrationParameters Fabiano Rosas
2026-09-04 9:53 ` Markus Armbruster
2026-09-04 13:58 ` Fabiano Rosas
2026-09-02 22:15 ` [PATCH 17/18] migration: Remove s->capabilities Fabiano Rosas
2026-09-04 12:15 ` Peter Xu
2026-09-02 22:15 ` [PATCH 18/18] qapi/migration: Deprecate capabilities commands 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=87zexx6sn2.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.