Skip to contentSkip to conversation

migration: Unify capabilities and parameters

PATCH Superseded Fabiano Rosas 5 participants 83 messages Jun 3, 2025 – Jul 1, 2025

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover migration: Unify capabilities and parameters

Hi,

Thanks for the reviews in the last round. Your feedback has allowed me to reduce the complexity of the series and the code considerably.

Changes in this v2:

- Followed the suggestion to unify the TLS strings as StrOrNull. This allows the complete removal of the MigrateSetParameters type. Therefore, no need for playing tricks with base types.

- I figured out that block_bitmap_mapping was set as optional in qmp_query_migrate_parameters in error. Fixing that allows to simplify that function somewhat.

- The suggestion of not checking the has_* fields when setting the parameters also led to great simplification. Now there's no need to open-code the setting of every single parameter.

- Deprecated the capabilities commands.

- Removed some redundant documentation from migration.json. Now there's only 1 (one) place where migration parameters need to be documented.

The series:
- passes CI: https://gitlab.com/farosas/qemu/-/pipelines/1849885920
- passes the migration tests in the ASAN build.
- passes the migration compat tests against each of the 3 last QEMU versions.
- passes the iotest 300 (related to block_bitmap_mapping).

v1:
https://lore.kernel.org/r/[email protected]

Fabiano Rosas (21):
migration: Normalize tls arguments
migration: Remove MigrateSetParameters
qapi/migration: Don't document MigrationParameter
migration: Run a post update routine after setting parameters
migration: Add a flag to track block-bitmap-mapping input
migration: Remove checks for s->parameters has_* fields
migration: Set block_bitmap_mapping unconditionally in
query-migrate-parameters
migration: Do away with usage of QERR_INVALID_PARAMETER_VALUE
migration: Extract code to mark all parameters as present
migration: Use QAPI_CLONE_MEMBERS in query_migrate_parameters
migration: Use QAPI_CLONE_MEMBERS in migrate_params_test_apply
migration: Use QAPI_CLONE_MEMBERS in migrate_params_apply
migration: Use visitors in migrate_params_test_apply
migration: Cleanup hmp_info_migrate_parameters
migration: Add capabilities into MigrationParameters qapi/migration: Mark that query/set-migrate-parameters support
capabilities
migration: Remove s->capabilities
qapi/migration: Deprecate capabilities commands
migration: Allow migrate commands to provide the migration config
libqtest: Add a function to check whether a QMP command supports a
feature
tests/qtest/migration: Add a test for config passing

 docs/about/deprecated.rst          |   12 +
 migration/migration-hmp-cmds.c     |  484 ++++++++----
 migration/migration.c              |   50 +-
 migration/migration.h              |    9 +-
 migration/options.c                | 1090 +++++++++++++---------------
 migration/options.h                |   29 +-
 migration/page_cache.c             |    6 +-
 migration/ram.c                    |    5 +-
 migration/savevm.c                 |    8 +-
 migration/tls.c                    |    2 +-
 qapi/migration.json                |  573 ++++++---------
 qapi/pragma.json                   |    3 +-
 system/vl.c                        |    3 +-
 tests/qtest/libqtest.c             |   42 ++
 tests/qtest/libqtest.h             |   12 +
 tests/qtest/migration/framework.h  |    2 +
 tests/qtest/migration/misc-tests.c |   39 +
 17 files changed, 1243 insertions(+), 1126 deletions(-)
Signature · 1 line
2.35.3
#1 lore raw

PATCH 1/21 migration: Normalize tls arguments

The migration parameters tls_creds, tls_authz and tls_hostname currently have a non-uniform handling. When used as arguments to migrate-set-parameters, their type is StrOrNull and when used as return value from query-migrate-parameters, their type is a plain string.

Not only having to convert between the types is cumbersome, but it also creates the issue of requiring two different QAPI types to be used, one for each command. MigrateSetParameters is used for migrate-set-parameters with the TLS arguments as StrOrNull while MigrationParameters is used for query-migrate-parameters with the TLS arguments as str.

Since StrOrNull could be considered a superset of str, change the type of the TLS arguments in MigrationParameters to StrOrNull and add a helper to ensure they're never actually used as QTYPE_QNULL.

This will allow the type duplication to be removed in the next patches.

---
 migration/migration-hmp-cmds.c |   8 +-
 migration/migration.c          |   2 +
 migration/options.c            | 149 ++++++++++++++++++++-------------
 migration/options.h            |   1 +
 migration/tls.c                |   2 +-
 qapi/migration.json            |   6 +-
 6 files changed, 99 insertions(+), 69 deletions(-)
migration/migration-hmp-cmds.c +3 -5
index e8a563c7d8..bc8179c582 100644
@@ -276,14 +276,12 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         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);
-        assert(params->tls_hostname);
+                       params->tls_creds ? params->tls_creds->u.s : "");
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
-            params->tls_hostname);
+                       params->tls_hostname ? params->tls_hostname->u.s : "");
         assert(params->has_max_bandwidth);
         monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
             MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
@@ -319,7 +317,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
             params->max_postcopy_bandwidth);
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
-            params->tls_authz);
+                       params->tls_authz ? params->tls_authz->u.s : "");
 
         if (params->has_block_bitmap_mapping) {
             const BitmapMigrationNodeAliasList *bmnal;
migration/migration.c +2 -0
index 4697732bef..f65cb81b6d 100644
@@ -4053,6 +4053,8 @@ static void migration_instance_finalize(Object *obj)
 {
     MigrationState *ms = MIGRATION_OBJ(obj);
 
+    migrate_tls_opts_free(&ms->parameters);
+
     qemu_mutex_destroy(&ms->error_mutex);
     qemu_mutex_destroy(&ms->qemu_file_lock);
     qemu_sem_destroy(&ms->wait_unplug_sem);
migration/options.c +89 -60

235 lines not on this page · raw message

migration/options.h +1 -0
index 82d839709e..999eee6f3b 100644
@@ -91,4 +91,5 @@ ZeroPageDetection migrate_zero_page_detection(void);
 
 bool migrate_params_check(MigrationParameters *params, Error **errp);
 void migrate_params_init(MigrationParameters *params);
+void migrate_tls_opts_free(MigrationParameters *params);
 #endif
migration/tls.c +1 -1
index 5cbf952383..8a89d3f767 100644
@@ -126,7 +126,7 @@ QIOChannelTLS *migration_tls_client_create(QIOChannel *ioc,
     }
 
     const char *tls_hostname = migrate_tls_hostname();
-    if (tls_hostname && *tls_hostname) {
+    if (tls_hostname) {
         hostname = tls_hostname;
     }
 
qapi/migration.json +3 -3
index 41826bde45..fa42d94810 100644
@@ -1293,9 +1293,9 @@
             '*cpu-throttle-initial': 'uint8',
             '*cpu-throttle-increment': 'uint8',
             '*cpu-throttle-tailslow': 'bool',
-            '*tls-creds': 'str',
-            '*tls-hostname': 'str',
-            '*tls-authz': 'str',
+            '*tls-creds': 'StrOrNull',
+            '*tls-hostname': 'StrOrNull',
+            '*tls-authz': 'StrOrNull',
             '*max-bandwidth': 'size',
             '*avail-switchover-bandwidth': 'size',
             '*downtime-limit': 'uint64',
Signature · 1 line
2.35.3
#2 lore raw

Re: [PATCH 01/21] migration: Normalize tls arguments

Quoted 13 lines · Fabiano Rosas

The migration parameters tls_creds, tls_authz and tls_hostname currently have a non-uniform handling. When used as arguments to migrate-set-parameters, their type is StrOrNull and when used as return value from query-migrate-parameters, their type is a plain string.

Not only having to convert between the types is cumbersome, but it also creates the issue of requiring two different QAPI types to be used, one for each command. MigrateSetParameters is used for migrate-set-parameters with the TLS arguments as StrOrNull while MigrationParameters is used for query-migrate-parameters with the TLS arguments as str.

Quoted 6 lines

Since StrOrNull could be considered a superset of str, change the type of the TLS arguments in MigrationParameters to StrOrNull and add a helper to ensure they're never actually used as QTYPE_QNULL.

This will allow the type duplication to be removed in the next patches.

Definitely a progress if we can finally merge the two!

Quoted 46 lines
---
 migration/migration-hmp-cmds.c |   8 +-
 migration/migration.c          |   2 +
 migration/options.c            | 149 ++++++++++++++++++++-------------
 migration/options.h            |   1 +
 migration/tls.c                |   2 +-
 qapi/migration.json            |   6 +-
 6 files changed, 99 insertions(+), 69 deletions(-)
migration/migration-hmp-cmds.c +3 -5
index e8a563c7d8..bc8179c582 100644
@@ -276,14 +276,12 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         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);
-        assert(params->tls_hostname);
+                       params->tls_creds ? params->tls_creds->u.s : "");
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
-            params->tls_hostname);
+                       params->tls_hostname ? params->tls_hostname->u.s : "");
         assert(params->has_max_bandwidth);
         monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
             MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
@@ -319,7 +317,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
             params->max_postcopy_bandwidth);
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
-            params->tls_authz);
+                       params->tls_authz ? params->tls_authz->u.s : "");
 
         if (params->has_block_bitmap_mapping) {
             const BitmapMigrationNodeAliasList *bmnal;
migration/migration.c +0 -0
index 4697732bef..f65cb81b6d 100644

migration/migration.c static void migration_instance_finalize(Object *obj) · line 4056

Quoted 4 lines
migration/migration.c +1 -0
@@ -4053,6 +4053,8 @@ static void migration_instance_finalize(Object *obj)
 {
     MigrationState *ms = MIGRATION_OBJ(obj);
 
+    migrate_tls_opts_free(&ms->parameters);

Does this line imply that maybe it's time we make MigrationState.parameters a pointer instead of embeded struct anymore?

We already used to have tls_* strings hence that idea should be already applicable even before.. but this work just made me think about it more.

So instead of freeing sub-fields if we add more to MigrationParameters, we could then do:

  g_clear_pointer(&ms->parameters, qapi_free_MigrationParameters);
Quoted 38 lines
migration/migration.c +1 -0
+
     qemu_mutex_destroy(&ms->error_mutex);
     qemu_mutex_destroy(&ms->qemu_file_lock);
     qemu_sem_destroy(&ms->wait_unplug_sem);
migration/options.c +5 -10
index 162c72cda4..45a95dc6da 100644
@@ -162,9 +162,11 @@ const Property migration_properties[] = {
     DEFINE_PROP_SIZE("announce-step", MigrationState,
                       parameters.announce_step,
                       DEFAULT_MIGRATE_ANNOUNCE_STEP),
-    DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds),
-    DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname),
-    DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz),
+    /*
+     * tls-creds, tls-hostname and tls-authz are of type StrOrNull,
+     * which can't be easily handled (if at all) by qdev. So these
+     * will not be exposed as global migration options (-global).
+     */
     DEFINE_PROP_UINT64("x-vcpu-dirty-limit-period", MigrationState,
                        parameters.x_vcpu_dirty_limit_period,
                        DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD),
@@ -379,13 +381,6 @@ bool migrate_rdma(void)
     return s->rdma_migration;
 }
 
-bool migrate_tls(void)
-{
-    MigrationState *s = migrate_get_current();
-
-    return s->parameters.tls_creds && *s->parameters.tls_creds;
-}
-
 typedef enum WriteTrackingSupport {
     WT_SUPPORT_UNKNOWN = 0,
     WT_SUPPORT_ABSENT,

migration/options.c const char *migrate_tls_authz(void) · line 836

Quoted 9 lines
migration/options.c +5 -1
@@ -834,21 +829,44 @@ const char *migrate_tls_authz(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.tls_authz;
+    if (s->parameters.tls_authz &&
+        s->parameters.tls_authz->type == QTYPE_QSTRING &&
+        *s->parameters.tls_authz->u.s) {
+        return s->parameters.tls_authz->u.s;
+    }

Nitpick: some deduplication would be nice? E.g.

  bool StrOrNull_str_valid(StrOrNull *obj)
  {
      return obj && obj->type == QTYPE_QSTRING && *obj->u.s;
  }

  const char *StrOrNull_str_get(StrOrNull *obj)
  {
      assert(obj && obj->type == QTYPE_QSTRING);
      return obj->u.s;
  }

  const char *StrOrNull_to_str(StrOrNull *obj)
  {
      return StrOrNull_str_valid(obj) ? StrOrNull_str_get(obj) : NULL;
  }

Then:

const char *migrate_tls_authz(void)

{
    return StrOrNull_to_str(s->parameters.tls_authz);
}

Then apply below.

Quoted 41 lines
migration/options.c +21 -2
+
+    return NULL;
 }
 
 const char *migrate_tls_creds(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.tls_creds;
+    if (s->parameters.tls_creds &&
+        s->parameters.tls_creds->type == QTYPE_QSTRING &&
+        *s->parameters.tls_creds->u.s) {
+        return s->parameters.tls_creds->u.s;
+    }
+
+    return NULL;
 }
 
 const char *migrate_tls_hostname(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.tls_hostname;
+    if (s->parameters.tls_hostname &&
+        s->parameters.tls_hostname->type == QTYPE_QSTRING &&
+        *s->parameters.tls_hostname->u.s) {
+        return s->parameters.tls_hostname->u.s;
+    }
+
+    return NULL;
+}
+
+bool migrate_tls(void)
+{
+    return !!migrate_tls_creds();
 }
 
 uint64_t migrate_vcpu_dirty_limit_period(void)
@@ -888,6 +906,36 @@ AnnounceParameters *migrate_announce_params(void)
     return ≈
 }

migration/options.c AnnounceParameters *migrate_announce_params(void) · line 917

Quoted 10 lines
migration/options.c +9 -0
 
+void migrate_tls_opts_free(MigrationParameters *params)
+{
+    qapi_free_StrOrNull(params->tls_creds);
+    qapi_free_StrOrNull(params->tls_hostname);
+    qapi_free_StrOrNull(params->tls_authz);
+}
+
+/* needs BQL if dst is part of s->parameters */
+static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)

Nitpick: set_str made me think that the internal objects will be stolen. Maybe tls_option_copy()?

Quoted 51 lines
migration/options.c +26 -7
+{
+    StrOrNull *dst = *dstp;
+
+    assert(!dst);
+
+    dst = *dstp = g_new0(StrOrNull, 1);
+    dst->type = QTYPE_QSTRING;
+
+    if (!src) {
+        dst->u.s = g_strdup("");
+        return;
+    }
+
+    if (src->type == QTYPE_QSTRING) {
+        dst->u.s = g_strdup(src->u.s);
+    } else {
+        assert(src->type == QTYPE_QNULL);
+        dst->u.s = g_strdup("");
+    }
+}
+
 MigrationParameters *qmp_query_migrate_parameters(Error **errp)
 {
     MigrationParameters *params;
@@ -903,10 +951,11 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
     params->has_cpu_throttle_tailslow = true;
     params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
-    params->tls_creds = g_strdup(s->parameters.tls_creds);
-    params->tls_hostname = g_strdup(s->parameters.tls_hostname);
-    params->tls_authz = g_strdup(s->parameters.tls_authz ?
-                                 s->parameters.tls_authz : "");
+
+    tls_option_set_str(&params->tls_creds, s->parameters.tls_creds);
+    tls_option_set_str(&params->tls_hostname, s->parameters.tls_hostname);
+    tls_option_set_str(&params->tls_authz, s->parameters.tls_authz);
+
     params->has_max_bandwidth = true;
     params->max_bandwidth = s->parameters.max_bandwidth;
     params->has_avail_switchover_bandwidth = true;
@@ -963,9 +1012,6 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
 
 void migrate_params_init(MigrationParameters *params)
 {
-    params->tls_hostname = g_strdup("");
-    params->tls_creds = g_strdup("");
-
     /* Set has_* up only for parameter checks */
     params->has_throttle_trigger_threshold = true;
     params->has_cpu_throttle_initial = true;

migration/options.c bool migrate_params_check(MigrationParameters *params, Error **errp) · line 1192

Quoted 6 lines
migration/options.c +2 -1
@@ -1142,7 +1188,8 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)
 #ifdef CONFIG_LINUX
     if (migrate_zero_copy_send() &&
         ((params->has_multifd_compression && params->multifd_compression) ||
-         (params->tls_creds && *params->tls_creds))) {
+         (params->tls_creds && params->tls_creds->type == QTYPE_QSTRING &&
+          *params->tls_creds->u.s))) {

Nitpick: StrOrNull_str_valid() candidate.

Quoted 4 lines
migration/options.c +0 -0
         error_setg(errp,
                    "Zero copy only available for non-compressed non-TLS multifd migration");
         return false;

migration/options.c static void migrate_params_test_apply(MigrateSetParameters *params, · line 1258

Quoted 10 lines
migration/options.c +4 -2
@@ -1204,18 +1251,24 @@ static void migrate_params_test_apply(MigrateSetParameters *params,
     }
 
     if (params->tls_creds) {
-        assert(params->tls_creds->type == QTYPE_QSTRING);
-        dest->tls_creds = params->tls_creds->u.s;
+        tls_option_set_str(&dest->tls_creds, params->tls_creds);
+    } else {
+        /* drop the reference, it's owned by s->parameters */
+        dest->tls_creds = NULL;
     }

This looks ok, but smells tricky, because before this line, "params" can contain something that it doesn't own..

If above idea of "making MigrationState->parameters a real QAPI object" works out, here IIUC we can also make "params" a real QAPI object by QAPI_CLONE(MigrationState->parameters), then when reaching here:

       if (params->tls_creds) {
          qapi_free_StrOrNull(params->tls_creds);
          params->tls_creds = QAPI_CLONE(params->tls_creds);
       }

It avoids the tricky "else" where we need to remember to clear something it doesn't ever own. Same to the rest.

Quoted 21 lines
migration/options.c +8 -4
     if (params->tls_hostname) {
-        assert(params->tls_hostname->type == QTYPE_QSTRING);
-        dest->tls_hostname = params->tls_hostname->u.s;
+        tls_option_set_str(&dest->tls_hostname, params->tls_hostname);
+    } else {
+        /* drop the reference, it's owned by s->parameters */
+        dest->tls_hostname = NULL;
     }
 
     if (params->tls_authz) {
-        assert(params->tls_authz->type == QTYPE_QSTRING);
-        dest->tls_authz = params->tls_authz->u.s;
+        tls_option_set_str(&dest->tls_authz, params->tls_authz);
+    } else {
+        /* drop the reference, it's owned by s->parameters */
+        dest->tls_authz = NULL;
     }
 
     if (params->has_max_bandwidth) {

migration/options.c static void migrate_params_apply(MigrateSetParameters *params, Error **errp) · line 1377

Quoted 8 lines
migration/options.c +2 -3
@@ -1320,21 +1373,18 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
     }
 
     if (params->tls_creds) {
-        g_free(s->parameters.tls_creds);
-        assert(params->tls_creds->type == QTYPE_QSTRING);
-        s->parameters.tls_creds = g_strdup(params->tls_creds->u.s);
+        qapi_free_StrOrNull(s->parameters.tls_creds);
+        tls_option_set_str(&s->parameters.tls_creds, params->tls_creds);

Yeah, exactly like this one..

Quoted 98 lines
migration/options.c +7 -30
     }
 
     if (params->tls_hostname) {
-        g_free(s->parameters.tls_hostname);
-        assert(params->tls_hostname->type == QTYPE_QSTRING);
-        s->parameters.tls_hostname = g_strdup(params->tls_hostname->u.s);
+        qapi_free_StrOrNull(s->parameters.tls_hostname);
+        tls_option_set_str(&s->parameters.tls_hostname, params->tls_hostname);
     }
 
     if (params->tls_authz) {
-        g_free(s->parameters.tls_authz);
-        assert(params->tls_authz->type == QTYPE_QSTRING);
-        s->parameters.tls_authz = g_strdup(params->tls_authz->u.s);
+        qapi_free_StrOrNull(s->parameters.tls_authz);
+        tls_option_set_str(&s->parameters.tls_authz, params->tls_authz);
     }
 
     if (params->has_max_bandwidth) {
@@ -1433,32 +1483,11 @@ void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
 {
     MigrationParameters tmp;
 
-    /* TODO Rewrite "" to null instead for all three tls_* parameters */
-    if (params->tls_creds
-        && params->tls_creds->type == QTYPE_QNULL) {
-        qobject_unref(params->tls_creds->u.n);
-        params->tls_creds->type = QTYPE_QSTRING;
-        params->tls_creds->u.s = strdup("");
-    }
-    if (params->tls_hostname
-        && params->tls_hostname->type == QTYPE_QNULL) {
-        qobject_unref(params->tls_hostname->u.n);
-        params->tls_hostname->type = QTYPE_QSTRING;
-        params->tls_hostname->u.s = strdup("");
-    }
-    if (params->tls_authz
-        && params->tls_authz->type == QTYPE_QNULL) {
-        qobject_unref(params->tls_authz->u.n);
-        params->tls_authz->type = QTYPE_QSTRING;
-        params->tls_authz->u.s = strdup("");
-    }
-
     migrate_params_test_apply(params, &tmp);
 
-    if (!migrate_params_check(&tmp, errp)) {
-        /* Invalid parameter */
-        return;
+    if (migrate_params_check(&tmp, errp)) {
+        migrate_params_apply(params, errp);
     }
 
-    migrate_params_apply(params, errp);
+    migrate_tls_opts_free(&tmp);
 }
migration/options.h +1 -0
index 82d839709e..999eee6f3b 100644
@@ -91,4 +91,5 @@ ZeroPageDetection migrate_zero_page_detection(void);
 
 bool migrate_params_check(MigrationParameters *params, Error **errp);
 void migrate_params_init(MigrationParameters *params);
+void migrate_tls_opts_free(MigrationParameters *params);
 #endif
migration/tls.c +1 -1
index 5cbf952383..8a89d3f767 100644
@@ -126,7 +126,7 @@ QIOChannelTLS *migration_tls_client_create(QIOChannel *ioc,
     }
 
     const char *tls_hostname = migrate_tls_hostname();
-    if (tls_hostname && *tls_hostname) {
+    if (tls_hostname) {
         hostname = tls_hostname;
     }
 
qapi/migration.json +3 -3
index 41826bde45..fa42d94810 100644
@@ -1293,9 +1293,9 @@
             '*cpu-throttle-initial': 'uint8',
             '*cpu-throttle-increment': 'uint8',
             '*cpu-throttle-tailslow': 'bool',
-            '*tls-creds': 'str',
-            '*tls-hostname': 'str',
-            '*tls-authz': 'str',
+            '*tls-creds': 'StrOrNull',
+            '*tls-hostname': 'StrOrNull',
+            '*tls-authz': 'StrOrNull',
             '*max-bandwidth': 'size',
             '*avail-switchover-bandwidth': 'size',
             '*downtime-limit': 'uint64',
Signature · 1 line
2.35.3
Signature · 1 line
Peter Xu
#3 lore raw

Re: [PATCH 01/21] migration: Normalize tls arguments

Quoted 77 lines · Peter Xu
Quoted 13 lines · Fabiano Rosas

The migration parameters tls_creds, tls_authz and tls_hostname currently have a non-uniform handling. When used as arguments to migrate-set-parameters, their type is StrOrNull and when used as return value from query-migrate-parameters, their type is a plain string.

Not only having to convert between the types is cumbersome, but it also creates the issue of requiring two different QAPI types to be used, one for each command. MigrateSetParameters is used for migrate-set-parameters with the TLS arguments as StrOrNull while MigrationParameters is used for query-migrate-parameters with the TLS arguments as str.

Quoted 6 lines

Since StrOrNull could be considered a superset of str, change the type of the TLS arguments in MigrationParameters to StrOrNull and add a helper to ensure they're never actually used as QTYPE_QNULL.

This will allow the type duplication to be removed in the next patches.

Definitely a progress if we can finally merge the two!

Quoted 46 lines
---
 migration/migration-hmp-cmds.c |   8 +-
 migration/migration.c          |   2 +
 migration/options.c            | 149 ++++++++++++++++++++-------------
 migration/options.h            |   1 +
 migration/tls.c                |   2 +-
 qapi/migration.json            |   6 +-
 6 files changed, 99 insertions(+), 69 deletions(-)
migration/migration-hmp-cmds.c +3 -5
index e8a563c7d8..bc8179c582 100644
@@ -276,14 +276,12 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         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);
-        assert(params->tls_hostname);
+                       params->tls_creds ? params->tls_creds->u.s : "");
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
-            params->tls_hostname);
+                       params->tls_hostname ? params->tls_hostname->u.s : "");
         assert(params->has_max_bandwidth);
         monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
             MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
@@ -319,7 +317,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
             params->max_postcopy_bandwidth);
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
-            params->tls_authz);
+                       params->tls_authz ? params->tls_authz->u.s : "");
 
         if (params->has_block_bitmap_mapping) {
             const BitmapMigrationNodeAliasList *bmnal;
migration/migration.c +0 -0
index 4697732bef..f65cb81b6d 100644

migration/migration.c static void migration_instance_finalize(Object *obj) · line 4056

Quoted 4 lines
migration/migration.c +1 -0
@@ -4053,6 +4053,8 @@ static void migration_instance_finalize(Object *obj)
 {
     MigrationState *ms = MIGRATION_OBJ(obj);
 
+    migrate_tls_opts_free(&ms->parameters);

Does this line imply that maybe it's time we make MigrationState.parameters a pointer instead of embeded struct anymore?

Quoted 8 lines

We already used to have tls_* strings hence that idea should be already applicable even before.. but this work just made me think about it more.

So instead of freeing sub-fields if we add more to MigrationParameters, we could then do:

  g_clear_pointer(&ms->parameters, qapi_free_MigrationParameters);

I don't see why not. I can add a patch at the end doing the conversion globally.

Quoted 66 lines
Quoted 38 lines
migration/migration.c +1 -0
+
     qemu_mutex_destroy(&ms->error_mutex);
     qemu_mutex_destroy(&ms->qemu_file_lock);
     qemu_sem_destroy(&ms->wait_unplug_sem);
migration/options.c +5 -10
index 162c72cda4..45a95dc6da 100644
@@ -162,9 +162,11 @@ const Property migration_properties[] = {
     DEFINE_PROP_SIZE("announce-step", MigrationState,
                       parameters.announce_step,
                       DEFAULT_MIGRATE_ANNOUNCE_STEP),
-    DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds),
-    DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname),
-    DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz),
+    /*
+     * tls-creds, tls-hostname and tls-authz are of type StrOrNull,
+     * which can't be easily handled (if at all) by qdev. So these
+     * will not be exposed as global migration options (-global).
+     */
     DEFINE_PROP_UINT64("x-vcpu-dirty-limit-period", MigrationState,
                        parameters.x_vcpu_dirty_limit_period,
                        DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD),
@@ -379,13 +381,6 @@ bool migrate_rdma(void)
     return s->rdma_migration;
 }
 
-bool migrate_tls(void)
-{
-    MigrationState *s = migrate_get_current();
-
-    return s->parameters.tls_creds && *s->parameters.tls_creds;
-}
-
 typedef enum WriteTrackingSupport {
     WT_SUPPORT_UNKNOWN = 0,
     WT_SUPPORT_ABSENT,

migration/options.c const char *migrate_tls_authz(void) · line 836

Quoted 9 lines
migration/options.c +5 -1
@@ -834,21 +829,44 @@ const char *migrate_tls_authz(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.tls_authz;
+    if (s->parameters.tls_authz &&
+        s->parameters.tls_authz->type == QTYPE_QSTRING &&
+        *s->parameters.tls_authz->u.s) {
+        return s->parameters.tls_authz->u.s;
+    }

Nitpick: some deduplication would be nice? E.g.

  bool StrOrNull_str_valid(StrOrNull *obj)
  {
      return obj && obj->type == QTYPE_QSTRING && *obj->u.s;
  }

  const char *StrOrNull_str_get(StrOrNull *obj)
  {
      assert(obj && obj->type == QTYPE_QSTRING);
      return obj->u.s;
  }

  const char *StrOrNull_to_str(StrOrNull *obj)
  {
      return StrOrNull_str_valid(obj) ? StrOrNull_str_get(obj) : NULL;
  }
Quoted 9 lines

Then:

const char *migrate_tls_authz(void)

{
    return StrOrNull_to_str(s->parameters.tls_authz);
}

Then apply below.

Sure.

Quoted 42 lines
Quoted 42 lines
migration/options.c +21 -2
+
+    return NULL;
 }
 
 const char *migrate_tls_creds(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.tls_creds;
+    if (s->parameters.tls_creds &&
+        s->parameters.tls_creds->type == QTYPE_QSTRING &&
+        *s->parameters.tls_creds->u.s) {
+        return s->parameters.tls_creds->u.s;
+    }
+
+    return NULL;
 }
 
 const char *migrate_tls_hostname(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.tls_hostname;
+    if (s->parameters.tls_hostname &&
+        s->parameters.tls_hostname->type == QTYPE_QSTRING &&
+        *s->parameters.tls_hostname->u.s) {
+        return s->parameters.tls_hostname->u.s;
+    }
+
+    return NULL;
+}
+
+bool migrate_tls(void)
+{
+    return !!migrate_tls_creds();
 }
 
 uint64_t migrate_vcpu_dirty_limit_period(void)
@@ -888,6 +906,36 @@ AnnounceParameters *migrate_announce_params(void)
     return ≈
 }
 
Quoted 13 lines

migration/options.c AnnounceParameters *migrate_announce_params(void) · line 917

Quoted 9 lines
migration/options.c +9 -0
+void migrate_tls_opts_free(MigrationParameters *params)
+{
+    qapi_free_StrOrNull(params->tls_creds);
+    qapi_free_StrOrNull(params->tls_hostname);
+    qapi_free_StrOrNull(params->tls_authz);
+}
+
+/* needs BQL if dst is part of s->parameters */
+static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)

Nitpick: set_str made me think that the internal objects will be stolen. Maybe tls_option_copy()?

Yeah, the idea was "set the TLS option and make sure it's a string".

Quoted 66 lines
Quoted 51 lines
migration/options.c +26 -7
+{
+    StrOrNull *dst = *dstp;
+
+    assert(!dst);
+
+    dst = *dstp = g_new0(StrOrNull, 1);
+    dst->type = QTYPE_QSTRING;
+
+    if (!src) {
+        dst->u.s = g_strdup("");
+        return;
+    }
+
+    if (src->type == QTYPE_QSTRING) {
+        dst->u.s = g_strdup(src->u.s);
+    } else {
+        assert(src->type == QTYPE_QNULL);
+        dst->u.s = g_strdup("");
+    }
+}
+
 MigrationParameters *qmp_query_migrate_parameters(Error **errp)
 {
     MigrationParameters *params;
@@ -903,10 +951,11 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
     params->has_cpu_throttle_tailslow = true;
     params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
-    params->tls_creds = g_strdup(s->parameters.tls_creds);
-    params->tls_hostname = g_strdup(s->parameters.tls_hostname);
-    params->tls_authz = g_strdup(s->parameters.tls_authz ?
-                                 s->parameters.tls_authz : "");
+
+    tls_option_set_str(&params->tls_creds, s->parameters.tls_creds);
+    tls_option_set_str(&params->tls_hostname, s->parameters.tls_hostname);
+    tls_option_set_str(&params->tls_authz, s->parameters.tls_authz);
+
     params->has_max_bandwidth = true;
     params->max_bandwidth = s->parameters.max_bandwidth;
     params->has_avail_switchover_bandwidth = true;
@@ -963,9 +1012,6 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
 
 void migrate_params_init(MigrationParameters *params)
 {
-    params->tls_hostname = g_strdup("");
-    params->tls_creds = g_strdup("");
-
     /* Set has_* up only for parameter checks */
     params->has_throttle_trigger_threshold = true;
     params->has_cpu_throttle_initial = true;

migration/options.c bool migrate_params_check(MigrationParameters *params, Error **errp) · line 1192

Quoted 6 lines
migration/options.c +2 -1
@@ -1142,7 +1188,8 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)
 #ifdef CONFIG_LINUX
     if (migrate_zero_copy_send() &&
         ((params->has_multifd_compression && params->multifd_compression) ||
-         (params->tls_creds && *params->tls_creds))) {
+         (params->tls_creds && params->tls_creds->type == QTYPE_QSTRING &&
+          *params->tls_creds->u.s))) {

Nitpick: StrOrNull_str_valid() candidate.

Quoted 6 lines
migration/options.c +0 -0
         error_setg(errp,
                    "Zero copy only available for non-compressed non-TLS multifd migration");
         return false;
@@ -1204,18 +1251,24 @@ static void migrate_params_test_apply(MigrateSetParameters *params,
     }
 
Quoted 12 lines

migration/options.c static void migrate_params_test_apply(MigrateSetParameters *params, · line 1258

Quoted 8 lines
migration/options.c +4 -2
     if (params->tls_creds) {
-        assert(params->tls_creds->type == QTYPE_QSTRING);
-        dest->tls_creds = params->tls_creds->u.s;
+        tls_option_set_str(&dest->tls_creds, params->tls_creds);
+    } else {
+        /* drop the reference, it's owned by s->parameters */
+        dest->tls_creds = NULL;
     }

This looks ok, but smells tricky, because before this line, "params" can contain something that it doesn't own..

This else actually goes away in patch 11. I'm taking small steps to get there to make the diffs easier to review.

Quoted 9 lines

If above idea of "making MigrationState->parameters a real QAPI object" works out, here IIUC we can also make "params" a real QAPI object by QAPI_CLONE(MigrationState->parameters), then when reaching here:

       if (params->tls_creds) {
          qapi_free_StrOrNull(params->tls_creds);
          params->tls_creds = QAPI_CLONE(params->tls_creds);
       }

Patches 10-13 clean this situation up and use QAPI_CLONE* all over.

Quoted 133 lines

It avoids the tricky "else" where we need to remember to clear something it doesn't ever own. Same to the rest.

Quoted 21 lines
migration/options.c +8 -4
     if (params->tls_hostname) {
-        assert(params->tls_hostname->type == QTYPE_QSTRING);
-        dest->tls_hostname = params->tls_hostname->u.s;
+        tls_option_set_str(&dest->tls_hostname, params->tls_hostname);
+    } else {
+        /* drop the reference, it's owned by s->parameters */
+        dest->tls_hostname = NULL;
     }
 
     if (params->tls_authz) {
-        assert(params->tls_authz->type == QTYPE_QSTRING);
-        dest->tls_authz = params->tls_authz->u.s;
+        tls_option_set_str(&dest->tls_authz, params->tls_authz);
+    } else {
+        /* drop the reference, it's owned by s->parameters */
+        dest->tls_authz = NULL;
     }
 
     if (params->has_max_bandwidth) {

migration/options.c static void migrate_params_apply(MigrateSetParameters *params, Error **errp) · line 1377

Quoted 8 lines
migration/options.c +2 -3
@@ -1320,21 +1373,18 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
     }
 
     if (params->tls_creds) {
-        g_free(s->parameters.tls_creds);
-        assert(params->tls_creds->type == QTYPE_QSTRING);
-        s->parameters.tls_creds = g_strdup(params->tls_creds->u.s);
+        qapi_free_StrOrNull(s->parameters.tls_creds);
+        tls_option_set_str(&s->parameters.tls_creds, params->tls_creds);

Yeah, exactly like this one..

Quoted 98 lines
migration/options.c +7 -30
     }
 
     if (params->tls_hostname) {
-        g_free(s->parameters.tls_hostname);
-        assert(params->tls_hostname->type == QTYPE_QSTRING);
-        s->parameters.tls_hostname = g_strdup(params->tls_hostname->u.s);
+        qapi_free_StrOrNull(s->parameters.tls_hostname);
+        tls_option_set_str(&s->parameters.tls_hostname, params->tls_hostname);
     }
 
     if (params->tls_authz) {
-        g_free(s->parameters.tls_authz);
-        assert(params->tls_authz->type == QTYPE_QSTRING);
-        s->parameters.tls_authz = g_strdup(params->tls_authz->u.s);
+        qapi_free_StrOrNull(s->parameters.tls_authz);
+        tls_option_set_str(&s->parameters.tls_authz, params->tls_authz);
     }
 
     if (params->has_max_bandwidth) {
@@ -1433,32 +1483,11 @@ void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
 {
     MigrationParameters tmp;
 
-    /* TODO Rewrite "" to null instead for all three tls_* parameters */
-    if (params->tls_creds
-        && params->tls_creds->type == QTYPE_QNULL) {
-        qobject_unref(params->tls_creds->u.n);
-        params->tls_creds->type = QTYPE_QSTRING;
-        params->tls_creds->u.s = strdup("");
-    }
-    if (params->tls_hostname
-        && params->tls_hostname->type == QTYPE_QNULL) {
-        qobject_unref(params->tls_hostname->u.n);
-        params->tls_hostname->type = QTYPE_QSTRING;
-        params->tls_hostname->u.s = strdup("");
-    }
-    if (params->tls_authz
-        && params->tls_authz->type == QTYPE_QNULL) {
-        qobject_unref(params->tls_authz->u.n);
-        params->tls_authz->type = QTYPE_QSTRING;
-        params->tls_authz->u.s = strdup("");
-    }
-
     migrate_params_test_apply(params, &tmp);
 
-    if (!migrate_params_check(&tmp, errp)) {
-        /* Invalid parameter */
-        return;
+    if (migrate_params_check(&tmp, errp)) {
+        migrate_params_apply(params, errp);
     }
 
-    migrate_params_apply(params, errp);
+    migrate_tls_opts_free(&tmp);
 }
migration/options.h +1 -0
index 82d839709e..999eee6f3b 100644
@@ -91,4 +91,5 @@ ZeroPageDetection migrate_zero_page_detection(void);
 
 bool migrate_params_check(MigrationParameters *params, Error **errp);
 void migrate_params_init(MigrationParameters *params);
+void migrate_tls_opts_free(MigrationParameters *params);
 #endif
migration/tls.c +1 -1
index 5cbf952383..8a89d3f767 100644
@@ -126,7 +126,7 @@ QIOChannelTLS *migration_tls_client_create(QIOChannel *ioc,
     }
 
     const char *tls_hostname = migrate_tls_hostname();
-    if (tls_hostname && *tls_hostname) {
+    if (tls_hostname) {
         hostname = tls_hostname;
     }
 
qapi/migration.json +3 -3
index 41826bde45..fa42d94810 100644
@@ -1293,9 +1293,9 @@
             '*cpu-throttle-initial': 'uint8',
             '*cpu-throttle-increment': 'uint8',
             '*cpu-throttle-tailslow': 'bool',
-            '*tls-creds': 'str',
-            '*tls-hostname': 'str',
-            '*tls-authz': 'str',
+            '*tls-creds': 'StrOrNull',
+            '*tls-hostname': 'StrOrNull',
+            '*tls-authz': 'StrOrNull',
             '*max-bandwidth': 'size',
             '*avail-switchover-bandwidth': 'size',
             '*downtime-limit': 'uint64',
Signature · 1 line
2.35.3
#4 lore raw

Re: [PATCH 01/21] migration: Normalize tls arguments

In reply to Fabiano Rosas
Quoted 13 lines · Fabiano Rosas

The migration parameters tls_creds, tls_authz and tls_hostname currently have a non-uniform handling. When used as arguments to migrate-set-parameters, their type is StrOrNull and when used as return value from query-migrate-parameters, their type is a plain string.

Not only having to convert between the types is cumbersome, but it also creates the issue of requiring two different QAPI types to be used, one for each command. MigrateSetParameters is used for migrate-set-parameters with the TLS arguments as StrOrNull while MigrationParameters is used for query-migrate-parameters with the TLS arguments as str.

Quoted 3 lines

Since StrOrNull could be considered a superset of str, change the type of the TLS arguments in MigrationParameters to StrOrNull and add a helper to ensure they're never actually used as QTYPE_QNULL.

The type of @tls_creds, @tls-hostname, @tls-authz changes from str to StrOrNull in introspection query-migrate-parameters. Loss of precision. Introspection is already imprecise: it shows the members optional even though they aren't. We accept the loss of precision to enable de-duplication.

This should be worked into the commit message.

Quoted 35 lines

This will allow the type duplication to be removed in the next patches.

---
 migration/migration-hmp-cmds.c |   8 +-
 migration/migration.c          |   2 +
 migration/options.c            | 149 ++++++++++++++++++++-------------
 migration/options.h            |   1 +
 migration/tls.c                |   2 +-
 qapi/migration.json            |   6 +-
 6 files changed, 99 insertions(+), 69 deletions(-)
migration/migration-hmp-cmds.c +2 -4
index e8a563c7d8..bc8179c582 100644
@@ -276,14 +276,12 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         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);
-        assert(params->tls_hostname);
+                       params->tls_creds ? params->tls_creds->u.s : "");
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
-            params->tls_hostname);
+                       params->tls_hostname ? params->tls_hostname->u.s : "");
         assert(params->has_max_bandwidth);
         monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
             MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),

migration/migration-hmp-cmds.c void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) · line 323

Quoted 8 lines
migration/migration-hmp-cmds.c +1 -1
@@ -319,7 +317,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
             params->max_postcopy_bandwidth);
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
-            params->tls_authz);
+                       params->tls_authz ? params->tls_authz->u.s : "");
 
         if (params->has_block_bitmap_mapping) {
             const BitmapMigrationNodeAliasList *bmnal;

Before, the code assumes ->tls_creds, ->tls_hostname, and ->tls_authz are non-null. It assert its assumption for the first two.

Afterwards, it maps null to "". Why is that necessary? Hmm, see below.

migration/migration.c static void migration_instance_finalize(Object *obj) · line 4056

Quoted 9 lines
migration/migration.c +1 -0
index 4697732bef..f65cb81b6d 100644
@@ -4053,6 +4053,8 @@ static void migration_instance_finalize(Object *obj)
 {
     MigrationState *ms = MIGRATION_OBJ(obj);
 
+    migrate_tls_opts_free(&ms->parameters);

Is this a bug fix?

As far as I can tell, the object gets destroyed only on QEMU shutdown. Freeing resources then is unnecessary, except it may help leak detection tools.

Quoted 10 lines
migration/migration.c +1 -0
+
     qemu_mutex_destroy(&ms->error_mutex);
     qemu_mutex_destroy(&ms->qemu_file_lock);
     qemu_sem_destroy(&ms->wait_unplug_sem);
migration/options.c +0 -0
index 162c72cda4..45a95dc6da 100644
@@ -162,9 +162,11 @@ const Property migration_properties[] = {
     DEFINE_PROP_SIZE("announce-step", MigrationState,

migration/options.c const Property migration_properties[] = { · line 169

Quoted 10 lines
migration/options.c +5 -3
                       parameters.announce_step,
                       DEFAULT_MIGRATE_ANNOUNCE_STEP),
-    DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds),
-    DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname),
-    DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz),
+    /*
+     * tls-creds, tls-hostname and tls-authz are of type StrOrNull,
+     * which can't be easily handled (if at all) by qdev. So these
+     * will not be exposed as global migration options (-global).
+     */

This is a compatibility break.

The orthodox way to break it is deprecate, let the grace period expire, break. Record in docs/about/deprecated.rst at the beginning, move the record to docs/about/removed-features.rst at the end.

An argument could be made that the interface in question is accidental[*], not actually used by anything, and therefore breaking it without a grace period is fine. But even then we should record the breakage in docs/about/removed-features.rst.

Aside: the interface in question is a hack (making the migration object a device) piled onto a hack (the way compat properties work, and how they spill into -global). Past sins catching up with us...

Quoted 48 lines
migration/options.c +14 -9
     DEFINE_PROP_UINT64("x-vcpu-dirty-limit-period", MigrationState,
                        parameters.x_vcpu_dirty_limit_period,
                        DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD),
@@ -379,13 +381,6 @@ bool migrate_rdma(void)
     return s->rdma_migration;
 }
 
-bool migrate_tls(void)
-{
-    MigrationState *s = migrate_get_current();
-
-    return s->parameters.tls_creds && *s->parameters.tls_creds;
-}
-
 typedef enum WriteTrackingSupport {
     WT_SUPPORT_UNKNOWN = 0,
     WT_SUPPORT_ABSENT,
@@ -834,21 +829,44 @@ const char *migrate_tls_authz(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.tls_authz;
+    if (s->parameters.tls_authz &&
+        s->parameters.tls_authz->type == QTYPE_QSTRING &&
+        *s->parameters.tls_authz->u.s) {
+        return s->parameters.tls_authz->u.s;
+    }
+
+    return NULL;
 }
 
 const char *migrate_tls_creds(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.tls_creds;
+    if (s->parameters.tls_creds &&
+        s->parameters.tls_creds->type == QTYPE_QSTRING &&
+        *s->parameters.tls_creds->u.s) {
+        return s->parameters.tls_creds->u.s;
+    }
+
+    return NULL;
 }
 
 const char *migrate_tls_hostname(void)
 {
     MigrationState *s = migrate_get_current();

migration/options.c const char *migrate_tls_authz(void) · line 865

Quoted 10 lines
migration/options.c +8 -1
 
-    return s->parameters.tls_hostname;
+    if (s->parameters.tls_hostname &&
+        s->parameters.tls_hostname->type == QTYPE_QSTRING &&
+        *s->parameters.tls_hostname->u.s) {
+        return s->parameters.tls_hostname->u.s;
+    }
+
+    return NULL;
+}

Again, the code changes to cope with null. Why is that necessary? Again, see below.

Quoted 30 lines
migration/options.c +23 -0
+
+bool migrate_tls(void)
+{
+    return !!migrate_tls_creds();
 }
 
 uint64_t migrate_vcpu_dirty_limit_period(void)
@@ -888,6 +906,36 @@ AnnounceParameters *migrate_announce_params(void)
     return ≈
 }
 
+void migrate_tls_opts_free(MigrationParameters *params)
+{
+    qapi_free_StrOrNull(params->tls_creds);
+    qapi_free_StrOrNull(params->tls_hostname);
+    qapi_free_StrOrNull(params->tls_authz);
+}
+
+/* needs BQL if dst is part of s->parameters */
+static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)
+{
+    StrOrNull *dst = *dstp;
+
+    assert(!dst);
+
+    dst = *dstp = g_new0(StrOrNull, 1);
+    dst->type = QTYPE_QSTRING;
+
+    if (!src) {
+        dst->u.s = g_strdup("");

migration/options.c AnnounceParameters *migrate_announce_params(void) · line 937

Quoted 10 lines
migration/options.c +10 -0
+        return;
+    }
+
+    if (src->type == QTYPE_QSTRING) {
+        dst->u.s = g_strdup(src->u.s);
+    } else {
+        assert(src->type == QTYPE_QNULL);
+        dst->u.s = g_strdup("");
+    }
+}

Postcondition: dstp points to a StrOrNull containing a str, i.e. QTYPE_QSTRING. Makes sense.

I'd prefer something like

       StrOrNull *dst = g_new0(StrOrNull, 1);

       ... fill in members ...

       assert(!*dstp);
       *dstp = dst;
Quoted 21 lines
migration/options.c +6 -4
+
 MigrationParameters *qmp_query_migrate_parameters(Error **errp)
 {
     MigrationParameters *params;
@@ -903,10 +951,11 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
     params->has_cpu_throttle_tailslow = true;
     params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
-    params->tls_creds = g_strdup(s->parameters.tls_creds);
-    params->tls_hostname = g_strdup(s->parameters.tls_hostname);
-    params->tls_authz = g_strdup(s->parameters.tls_authz ?
-                                 s->parameters.tls_authz : "");
+
+    tls_option_set_str(&params->tls_creds, s->parameters.tls_creds);
+    tls_option_set_str(&params->tls_hostname, s->parameters.tls_hostname);
+    tls_option_set_str(&params->tls_authz, s->parameters.tls_authz);
+
     params->has_max_bandwidth = true;
     params->max_bandwidth = s->parameters.max_bandwidth;
     params->has_avail_switchover_bandwidth = true;

migration/options.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 968

Quoted 6 lines
migration/options.c +0 -3
@@ -963,9 +1012,6 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
 
 void migrate_params_init(MigrationParameters *params)
 {
-    params->tls_hostname = g_strdup("");
-    params->tls_creds = g_strdup("");
-

Is this the reason why the code now needs to deal with null?

I'm not objecting, just pointing out that the commit message didn't prepare me for such a change.

migration/options.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 1017

Quoted 3 lines
migration/options.c +0 -0
     /* Set has_* up only for parameter checks */
     params->has_throttle_trigger_threshold = true;
     params->has_cpu_throttle_initial = true;

I'm stopping here to ask: how exactly does the patch change quasi-global state, namely current_migration->parameters->tls_*?

[...]

[*] We have oh so many accidental external interfaces.

#5 lore raw

Re: [PATCH 01/21] migration: Normalize tls arguments

Quoted 19 lines · Markus Armbruster
Quoted 13 lines · Fabiano Rosas

The migration parameters tls_creds, tls_authz and tls_hostname currently have a non-uniform handling. When used as arguments to migrate-set-parameters, their type is StrOrNull and when used as return value from query-migrate-parameters, their type is a plain string.

Not only having to convert between the types is cumbersome, but it also creates the issue of requiring two different QAPI types to be used, one for each command. MigrateSetParameters is used for migrate-set-parameters with the TLS arguments as StrOrNull while MigrationParameters is used for query-migrate-parameters with the TLS arguments as str.

Quoted 3 lines

Since StrOrNull could be considered a superset of str, change the type of the TLS arguments in MigrationParameters to StrOrNull and add a helper to ensure they're never actually used as QTYPE_QNULL.

Quoted 8 lines

The type of @tls_creds, @tls-hostname, @tls-authz changes from str to StrOrNull in introspection query-migrate-parameters. Loss of precision. Introspection is already imprecise: it shows the members optional even though they aren't. We accept the loss of precision to enable de-duplication.

This should be worked into the commit message.

Ack.

Quoted 41 lines
Quoted 41 lines

This will allow the type duplication to be removed in the next patches.

---
 migration/migration-hmp-cmds.c |   8 +-
 migration/migration.c          |   2 +
 migration/options.c            | 149 ++++++++++++++++++++-------------
 migration/options.h            |   1 +
 migration/tls.c                |   2 +-
 qapi/migration.json            |   6 +-
 6 files changed, 99 insertions(+), 69 deletions(-)
migration/migration-hmp-cmds.c +3 -5
index e8a563c7d8..bc8179c582 100644
@@ -276,14 +276,12 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         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);
-        assert(params->tls_hostname);
+                       params->tls_creds ? params->tls_creds->u.s : "");
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
-            params->tls_hostname);
+                       params->tls_hostname ? params->tls_hostname->u.s : "");
         assert(params->has_max_bandwidth);
         monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
             MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
@@ -319,7 +317,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
             params->max_postcopy_bandwidth);
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
-            params->tls_authz);
+                       params->tls_authz ? params->tls_authz->u.s : "");
 
Quoted 8 lines

migration/migration-hmp-cmds.c void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) · line 323

Quoted 2 lines
migration/migration-hmp-cmds.c +0 -0
         if (params->has_block_bitmap_mapping) {
             const BitmapMigrationNodeAliasList *bmnal;

Before, the code assumes ->tls_creds, ->tls_hostname, and ->tls_authz are non-null. It assert its assumption for the first two.

Afterwards, it maps null to "". Why is that necessary? Hmm, see below.

Maps NULL to "" because the intermediate type, MigrationParameters, has been changed from str to StrOrNull. For the purposes of info migrate_parameters and query-migrate-parameters the only valid values are a non-empty string or an empty string.

Quoted 8 lines
Quoted 8 lines
migration/migration.c +0 -0
index 4697732bef..f65cb81b6d 100644
@@ -4053,6 +4053,8 @@ static void migration_instance_finalize(Object *obj)
 {
     MigrationState *ms = MIGRATION_OBJ(obj);
 
Quoted 4 lines

migration/migration.c static void migration_instance_finalize(Object *obj) · line 4056

Quoted 1 line
migration/migration.c +1 -0
+    migrate_tls_opts_free(&ms->parameters);

Is this a bug fix?

My new version is a little different, but I can make it a separate patch if that happens to be the case.

Quoted 4 lines

As far as I can tell, the object gets destroyed only on QEMU shutdown. Freeing resources then is unnecessary, except it may help leak detection tools.

From a maintenance perspective I consider any leak as a bug because I don't have control over what kinds of leak detection tools are ran on the code. To avoid spending time looking at such bug reports I have ASAN automated in my testing and I fix early any leaks that it founds.

Quoted 23 lines
Quoted 10 lines
migration/migration.c +1 -0
+
     qemu_mutex_destroy(&ms->error_mutex);
     qemu_mutex_destroy(&ms->qemu_file_lock);
     qemu_sem_destroy(&ms->wait_unplug_sem);
migration/options.c +0 -0
index 162c72cda4..45a95dc6da 100644
@@ -162,9 +162,11 @@ const Property migration_properties[] = {
     DEFINE_PROP_SIZE("announce-step", MigrationState,

migration/options.c const Property migration_properties[] = { · line 169

Quoted 10 lines
migration/options.c +5 -3
                       parameters.announce_step,
                       DEFAULT_MIGRATE_ANNOUNCE_STEP),
-    DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds),
-    DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname),
-    DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz),
+    /*
+     * tls-creds, tls-hostname and tls-authz are of type StrOrNull,
+     * which can't be easily handled (if at all) by qdev. So these
+     * will not be exposed as global migration options (-global).
+     */

This is a compatibility break.

Quoted 9 lines

The orthodox way to break it is deprecate, let the grace period expire, break. Record in docs/about/deprecated.rst at the beginning, move the record to docs/about/removed-features.rst at the end.

An argument could be made that the interface in question is accidental[*], not actually used by anything, and therefore breaking it without a grace period is fine. But even then we should record the breakage in docs/about/removed-features.rst.

Ok. Alternatively I could try a little harder to keep these options. I'll see what I can do.

Quoted 4 lines

Aside: the interface in question is a hack (making the migration object a device) piled onto a hack (the way compat properties work, and how they spill into -global). Past sins catching up with us...

Hm, I've been experimenting with adding new objects (still TYPE_DEVICE) to hold the compatibility options and parameters only. Not the entire migration state. The MigrationState object would then be converted into a regular struct.

MigrationState => internal type holding migration state (a better name could be used)
MigrationOptionsState => -global migration-options.foo=on MigrationCompatState => -global migration foo=on

But it's getting a little tricky due to s->parameters *also* containing compat options, namely zero-page-detection.

Quoted 49 lines
Quoted 49 lines
migration/options.c +14 -9
     DEFINE_PROP_UINT64("x-vcpu-dirty-limit-period", MigrationState,
                        parameters.x_vcpu_dirty_limit_period,
                        DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD),
@@ -379,13 +381,6 @@ bool migrate_rdma(void)
     return s->rdma_migration;
 }
 
-bool migrate_tls(void)
-{
-    MigrationState *s = migrate_get_current();
-
-    return s->parameters.tls_creds && *s->parameters.tls_creds;
-}
-
 typedef enum WriteTrackingSupport {
     WT_SUPPORT_UNKNOWN = 0,
     WT_SUPPORT_ABSENT,
@@ -834,21 +829,44 @@ const char *migrate_tls_authz(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.tls_authz;
+    if (s->parameters.tls_authz &&
+        s->parameters.tls_authz->type == QTYPE_QSTRING &&
+        *s->parameters.tls_authz->u.s) {
+        return s->parameters.tls_authz->u.s;
+    }
+
+    return NULL;
 }
 
 const char *migrate_tls_creds(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.tls_creds;
+    if (s->parameters.tls_creds &&
+        s->parameters.tls_creds->type == QTYPE_QSTRING &&
+        *s->parameters.tls_creds->u.s) {
+        return s->parameters.tls_creds->u.s;
+    }
+
+    return NULL;
 }
 
 const char *migrate_tls_hostname(void)
 {
     MigrationState *s = migrate_get_current();
 
Quoted 13 lines

migration/options.c const char *migrate_tls_authz(void) · line 865

Quoted 9 lines
migration/options.c +8 -1
-    return s->parameters.tls_hostname;
+    if (s->parameters.tls_hostname &&
+        s->parameters.tls_hostname->type == QTYPE_QSTRING &&
+        *s->parameters.tls_hostname->u.s) {
+        return s->parameters.tls_hostname->u.s;
+    }
+
+    return NULL;
+}

Again, the code changes to cope with null. Why is that necessary? Again, see below.

This is actually a bit roundabout indeed. In my new version I do:

- migrate-set-parameters: always write either NULL or a non-empty QTYPE_QSTRING to s->parameters.

- query-migrate-parameters: always return a (possibly empty) QTYPE_QSTRING.

With this, internal representation is: NULL for not present, non-empty string for present.

Quoted 44 lines
Quoted 30 lines
migration/options.c +23 -0
+
+bool migrate_tls(void)
+{
+    return !!migrate_tls_creds();
 }
 
 uint64_t migrate_vcpu_dirty_limit_period(void)
@@ -888,6 +906,36 @@ AnnounceParameters *migrate_announce_params(void)
     return ≈
 }
 
+void migrate_tls_opts_free(MigrationParameters *params)
+{
+    qapi_free_StrOrNull(params->tls_creds);
+    qapi_free_StrOrNull(params->tls_hostname);
+    qapi_free_StrOrNull(params->tls_authz);
+}
+
+/* needs BQL if dst is part of s->parameters */
+static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)
+{
+    StrOrNull *dst = *dstp;
+
+    assert(!dst);
+
+    dst = *dstp = g_new0(StrOrNull, 1);
+    dst->type = QTYPE_QSTRING;
+
+    if (!src) {
+        dst->u.s = g_strdup("");

migration/options.c AnnounceParameters *migrate_announce_params(void) · line 937

Quoted 10 lines
migration/options.c +10 -0
+        return;
+    }
+
+    if (src->type == QTYPE_QSTRING) {
+        dst->u.s = g_strdup(src->u.s);
+    } else {
+        assert(src->type == QTYPE_QNULL);
+        dst->u.s = g_strdup("");
+    }
+}

Postcondition: dstp points to a StrOrNull containing a str, i.e. QTYPE_QSTRING. Makes sense.

Quoted 9 lines

I'd prefer something like

       StrOrNull *dst = g_new0(StrOrNull, 1);

       ... fill in members ...

       assert(!*dstp);
       *dstp = dst;

This code is also reworked a bit on the next version, I'll see whether the comment still applies.

Quoted 30 lines
Quoted 21 lines
migration/options.c +6 -4
+
 MigrationParameters *qmp_query_migrate_parameters(Error **errp)
 {
     MigrationParameters *params;
@@ -903,10 +951,11 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
     params->has_cpu_throttle_tailslow = true;
     params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
-    params->tls_creds = g_strdup(s->parameters.tls_creds);
-    params->tls_hostname = g_strdup(s->parameters.tls_hostname);
-    params->tls_authz = g_strdup(s->parameters.tls_authz ?
-                                 s->parameters.tls_authz : "");
+
+    tls_option_set_str(&params->tls_creds, s->parameters.tls_creds);
+    tls_option_set_str(&params->tls_hostname, s->parameters.tls_hostname);
+    tls_option_set_str(&params->tls_authz, s->parameters.tls_authz);
+
     params->has_max_bandwidth = true;
     params->max_bandwidth = s->parameters.max_bandwidth;
     params->has_avail_switchover_bandwidth = true;

migration/options.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 968

Quoted 6 lines
migration/options.c +0 -3
@@ -963,9 +1012,6 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
 
 void migrate_params_init(MigrationParameters *params)
 {
-    params->tls_hostname = g_strdup("");
-    params->tls_creds = g_strdup("");
-

Is this the reason why the code now needs to deal with null?

Quoted 3 lines

I'm not objecting, just pointing out that the commit message didn't prepare me for such a change.

I'll document it.

Quoted 7 lines

migration/options.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 1017

Quoted 3 lines
migration/options.c +0 -0
     /* Set has_* up only for parameter checks */
     params->has_throttle_trigger_threshold = true;
     params->has_cpu_throttle_initial = true;

I'm stopping here to ask: how exactly does the patch change quasi-global state, namely current_migration->parameters->tls_*?

It makes sure the current_migration->parameters->tls_* options are always QTYPE_QSTRING and either a non-empty or an empty string.

The next version of the patch will instead use non-empty QTYPE_QSTRING or NULL, which is cleaner from a C perspective.

Both versions ensure the query-* and set-* commands continue to expose the same values. Query only shows non-empty or empty string and Set accepts all values of a StrOrNull type.

Quoted 4 lines

[...]

[*] We have oh so many accidental external interfaces.

#6 lore raw

Re: [PATCH 01/21] migration: Normalize tls arguments

Quoted 79 lines · Fabiano Rosas
Quoted 19 lines · Markus Armbruster
Quoted 13 lines · Fabiano Rosas

The migration parameters tls_creds, tls_authz and tls_hostname currently have a non-uniform handling. When used as arguments to migrate-set-parameters, their type is StrOrNull and when used as return value from query-migrate-parameters, their type is a plain string.

Not only having to convert between the types is cumbersome, but it also creates the issue of requiring two different QAPI types to be used, one for each command. MigrateSetParameters is used for migrate-set-parameters with the TLS arguments as StrOrNull while MigrationParameters is used for query-migrate-parameters with the TLS arguments as str.

Quoted 3 lines

Since StrOrNull could be considered a superset of str, change the type of the TLS arguments in MigrationParameters to StrOrNull and add a helper to ensure they're never actually used as QTYPE_QNULL.

Quoted 8 lines

The type of @tls_creds, @tls-hostname, @tls-authz changes from str to StrOrNull in introspection query-migrate-parameters. Loss of precision. Introspection is already imprecise: it shows the members optional even though they aren't. We accept the loss of precision to enable de-duplication.

This should be worked into the commit message.

Ack.

Quoted 47 lines
Quoted 35 lines

This will allow the type duplication to be removed in the next patches.

---
 migration/migration-hmp-cmds.c |   8 +-
 migration/migration.c          |   2 +
 migration/options.c            | 149 ++++++++++++++++++++-------------
 migration/options.h            |   1 +
 migration/tls.c                |   2 +-
 qapi/migration.json            |   6 +-
 6 files changed, 99 insertions(+), 69 deletions(-)
migration/migration-hmp-cmds.c +2 -4
index e8a563c7d8..bc8179c582 100644
@@ -276,14 +276,12 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         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);
-        assert(params->tls_hostname);
+                       params->tls_creds ? params->tls_creds->u.s : "");
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
-            params->tls_hostname);
+                       params->tls_hostname ? params->tls_hostname->u.s : "");
         assert(params->has_max_bandwidth);
         monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
             MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),

migration/migration-hmp-cmds.c void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) · line 323

Quoted 8 lines
migration/migration-hmp-cmds.c +1 -1
@@ -319,7 +317,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
             params->max_postcopy_bandwidth);
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
-            params->tls_authz);
+                       params->tls_authz ? params->tls_authz->u.s : "");
 
         if (params->has_block_bitmap_mapping) {
             const BitmapMigrationNodeAliasList *bmnal;

Before, the code assumes ->tls_creds, ->tls_hostname, and ->tls_authz are non-null. It assert its assumption for the first two.

Quoted 7 lines
Quoted 2 lines

Afterwards, it maps null to "". Why is that necessary? Hmm, see below.

Maps NULL to "" because the intermediate type, MigrationParameters, has been changed from str to StrOrNull. For the purposes of info migrate_parameters and query-migrate-parameters the only valid values are a non-empty string or an empty string.

But is NULL possible? If you just change the type from str to StrOrNull and no more, it isn't.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
migration/migration.c +0 -0
index 4697732bef..f65cb81b6d 100644
@@ -4053,6 +4053,8 @@ static void migration_instance_finalize(Object *obj)
 {
     MigrationState *ms = MIGRATION_OBJ(obj);
 
Quoted 7 lines
Quoted 4 lines

migration/migration.c static void migration_instance_finalize(Object *obj) · line 4056

Quoted 1 line
migration/migration.c +1 -0
+    migrate_tls_opts_free(&ms->parameters);

Is this a bug fix?

My new version is a little different, but I can make it a separate patch if that happens to be the case.

Yes, please.

Quoted 37 lines
Quoted 4 lines

As far as I can tell, the object gets destroyed only on QEMU shutdown. Freeing resources then is unnecessary, except it may help leak detection tools.

From a maintenance perspective I consider any leak as a bug because I don't have control over what kinds of leak detection tools are ran on the code. To avoid spending time looking at such bug reports I have ASAN automated in my testing and I fix early any leaks that it founds.

Quoted 27 lines
Quoted 10 lines
migration/migration.c +1 -0
+
     qemu_mutex_destroy(&ms->error_mutex);
     qemu_mutex_destroy(&ms->qemu_file_lock);
     qemu_sem_destroy(&ms->wait_unplug_sem);
migration/options.c +0 -0
index 162c72cda4..45a95dc6da 100644
@@ -162,9 +162,11 @@ const Property migration_properties[] = {
     DEFINE_PROP_SIZE("announce-step", MigrationState,

migration/options.c const Property migration_properties[] = { · line 169

Quoted 10 lines
migration/options.c +5 -3
                       parameters.announce_step,
                       DEFAULT_MIGRATE_ANNOUNCE_STEP),
-    DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds),
-    DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname),
-    DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz),
+    /*
+     * tls-creds, tls-hostname and tls-authz are of type StrOrNull,
+     * which can't be easily handled (if at all) by qdev. So these
+     * will not be exposed as global migration options (-global).
+     */

This is a compatibility break.

The orthodox way to break it is deprecate, let the grace period expire, break. Record in docs/about/deprecated.rst at the beginning, move the record to docs/about/removed-features.rst at the end.

Quoted 8 lines
Quoted 5 lines

An argument could be made that the interface in question is accidental[*], not actually used by anything, and therefore breaking it without a grace period is fine. But even then we should record the breakage in docs/about/removed-features.rst.

Ok. Alternatively I could try a little harder to keep these options. I'll see what I can do.

What do we think about this external interface?

If we think it's accidental and unused, then putting in more work to keep it makes no sense.

If we think it's deliberate and/or used, we should either keep it, or replace it the orthodox way.

Trouble is a common answer for use of accidental interfaces is "beats me". I wish we'd stop creating them.

Quoted 10 lines
Quoted 4 lines

Aside: the interface in question is a hack (making the migration object a device) piled onto a hack (the way compat properties work, and how they spill into -global). Past sins catching up with us...

Hm, I've been experimenting with adding new objects (still TYPE_DEVICE) to hold the compatibility options and parameters only. Not the entire migration state. The MigrationState object would then be converted into a regular struct.

Quoted 7 lines

MigrationState => internal type holding migration state (a better name could be used)
MigrationOptionsState => -global migration-options.foo=on MigrationCompatState => -global migration foo=on

But it's getting a little tricky due to s->parameters *also* containing compat options, namely zero-page-detection.

-global is a trap. Heck, global configuration state is a trap. See discussion in review of RFC v3.

We can't always fill in the our spiked pits. Sometimes the best we can do is to plank them and put up some "here be danger" signs.

Quoted 175 lines
Quoted 49 lines
Quoted 49 lines
migration/options.c +14 -9
     DEFINE_PROP_UINT64("x-vcpu-dirty-limit-period", MigrationState,
                        parameters.x_vcpu_dirty_limit_period,
                        DEFAULT_MIGRATE_VCPU_DIRTY_LIMIT_PERIOD),
@@ -379,13 +381,6 @@ bool migrate_rdma(void)
     return s->rdma_migration;
 }
 
-bool migrate_tls(void)
-{
-    MigrationState *s = migrate_get_current();
-
-    return s->parameters.tls_creds && *s->parameters.tls_creds;
-}
-
 typedef enum WriteTrackingSupport {
     WT_SUPPORT_UNKNOWN = 0,
     WT_SUPPORT_ABSENT,
@@ -834,21 +829,44 @@ const char *migrate_tls_authz(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.tls_authz;
+    if (s->parameters.tls_authz &&
+        s->parameters.tls_authz->type == QTYPE_QSTRING &&
+        *s->parameters.tls_authz->u.s) {
+        return s->parameters.tls_authz->u.s;
+    }
+
+    return NULL;
 }
 
 const char *migrate_tls_creds(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.tls_creds;
+    if (s->parameters.tls_creds &&
+        s->parameters.tls_creds->type == QTYPE_QSTRING &&
+        *s->parameters.tls_creds->u.s) {
+        return s->parameters.tls_creds->u.s;
+    }
+
+    return NULL;
 }
 
 const char *migrate_tls_hostname(void)
 {
     MigrationState *s = migrate_get_current();
 
Quoted 13 lines

migration/options.c const char *migrate_tls_authz(void) · line 865

Quoted 9 lines
migration/options.c +8 -1
-    return s->parameters.tls_hostname;
+    if (s->parameters.tls_hostname &&
+        s->parameters.tls_hostname->type == QTYPE_QSTRING &&
+        *s->parameters.tls_hostname->u.s) {
+        return s->parameters.tls_hostname->u.s;
+    }
+
+    return NULL;
+}

Again, the code changes to cope with null. Why is that necessary? Again, see below.

This is actually a bit roundabout indeed. In my new version I do:

- migrate-set-parameters: always write either NULL or a non-empty QTYPE_QSTRING to s->parameters.

- query-migrate-parameters: always return a (possibly empty) QTYPE_QSTRING.

With this, internal representation is: NULL for not present, non-empty string for present.

Quoted 44 lines
Quoted 30 lines
migration/options.c +23 -0
+
+bool migrate_tls(void)
+{
+    return !!migrate_tls_creds();
 }
 
 uint64_t migrate_vcpu_dirty_limit_period(void)
@@ -888,6 +906,36 @@ AnnounceParameters *migrate_announce_params(void)
     return ≈
 }
 
+void migrate_tls_opts_free(MigrationParameters *params)
+{
+    qapi_free_StrOrNull(params->tls_creds);
+    qapi_free_StrOrNull(params->tls_hostname);
+    qapi_free_StrOrNull(params->tls_authz);
+}
+
+/* needs BQL if dst is part of s->parameters */
+static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)
+{
+    StrOrNull *dst = *dstp;
+
+    assert(!dst);
+
+    dst = *dstp = g_new0(StrOrNull, 1);
+    dst->type = QTYPE_QSTRING;
+
+    if (!src) {
+        dst->u.s = g_strdup("");

migration/options.c AnnounceParameters *migrate_announce_params(void) · line 937

Quoted 10 lines
migration/options.c +10 -0
+        return;
+    }
+
+    if (src->type == QTYPE_QSTRING) {
+        dst->u.s = g_strdup(src->u.s);
+    } else {
+        assert(src->type == QTYPE_QNULL);
+        dst->u.s = g_strdup("");
+    }
+}

Postcondition: dstp points to a StrOrNull containing a str, i.e. QTYPE_QSTRING. Makes sense.

Quoted 9 lines

I'd prefer something like

       StrOrNull *dst = g_new0(StrOrNull, 1);

       ... fill in members ...

       assert(!*dstp);
       *dstp = dst;

This code is also reworked a bit on the next version, I'll see whether the comment still applies.

Quoted 30 lines
Quoted 21 lines
migration/options.c +6 -4
+
 MigrationParameters *qmp_query_migrate_parameters(Error **errp)
 {
     MigrationParameters *params;
@@ -903,10 +951,11 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
     params->has_cpu_throttle_tailslow = true;
     params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
-    params->tls_creds = g_strdup(s->parameters.tls_creds);
-    params->tls_hostname = g_strdup(s->parameters.tls_hostname);
-    params->tls_authz = g_strdup(s->parameters.tls_authz ?
-                                 s->parameters.tls_authz : "");
+
+    tls_option_set_str(&params->tls_creds, s->parameters.tls_creds);
+    tls_option_set_str(&params->tls_hostname, s->parameters.tls_hostname);
+    tls_option_set_str(&params->tls_authz, s->parameters.tls_authz);
+
     params->has_max_bandwidth = true;
     params->max_bandwidth = s->parameters.max_bandwidth;
     params->has_avail_switchover_bandwidth = true;

migration/options.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 968

Quoted 6 lines
migration/options.c +0 -3
@@ -963,9 +1012,6 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
 
 void migrate_params_init(MigrationParameters *params)
 {
-    params->tls_hostname = g_strdup("");
-    params->tls_creds = g_strdup("");
-

Is this the reason why the code now needs to deal with null?

Quoted 3 lines

I'm not objecting, just pointing out that the commit message didn't prepare me for such a change.

I'll document it.

Quoted 7 lines

migration/options.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 1017

Quoted 3 lines
migration/options.c +0 -0
     /* Set has_* up only for parameter checks */
     params->has_throttle_trigger_threshold = true;
     params->has_cpu_throttle_initial = true;

I'm stopping here to ask: how exactly does the patch change quasi-global state, namely current_migration->parameters->tls_*?

Quoted 5 lines

It makes sure the current_migration->parameters->tls_* options are always QTYPE_QSTRING and either a non-empty or an empty string.

The next version of the patch will instead use non-empty QTYPE_QSTRING or NULL, which is cleaner from a C perspective.

Agree.

The struct members will have type StrOrNull, but only certain values can
occur: non-empty string, and NULL. Worth a comment, I think. Also consider assertions.

Quoted 8 lines

Both versions ensure the query-* and set-* commands continue to expose the same values. Query only shows non-empty or empty string and Set accepts all values of a StrOrNull type.

Quoted 4 lines

[...]

[*] We have oh so many accidental external interfaces.

#7 lore raw

Re: [PATCH 01/21] migration: Normalize tls arguments

Quoted 84 lines · Markus Armbruster
Quoted 82 lines · Fabiano Rosas
Quoted 19 lines · Markus Armbruster
Quoted 13 lines · Fabiano Rosas

The migration parameters tls_creds, tls_authz and tls_hostname currently have a non-uniform handling. When used as arguments to migrate-set-parameters, their type is StrOrNull and when used as return value from query-migrate-parameters, their type is a plain string.

Not only having to convert between the types is cumbersome, but it also creates the issue of requiring two different QAPI types to be used, one for each command. MigrateSetParameters is used for migrate-set-parameters with the TLS arguments as StrOrNull while MigrationParameters is used for query-migrate-parameters with the TLS arguments as str.

Quoted 3 lines

Since StrOrNull could be considered a superset of str, change the type of the TLS arguments in MigrationParameters to StrOrNull and add a helper to ensure they're never actually used as QTYPE_QNULL.

Quoted 8 lines

The type of @tls_creds, @tls-hostname, @tls-authz changes from str to StrOrNull in introspection query-migrate-parameters. Loss of precision. Introspection is already imprecise: it shows the members optional even though they aren't. We accept the loss of precision to enable de-duplication.

This should be worked into the commit message.

Ack.

Quoted 49 lines
Quoted 35 lines

This will allow the type duplication to be removed in the next patches.

---
 migration/migration-hmp-cmds.c |   8 +-
 migration/migration.c          |   2 +
 migration/options.c            | 149 ++++++++++++++++++++-------------
 migration/options.h            |   1 +
 migration/tls.c                |   2 +-
 qapi/migration.json            |   6 +-
 6 files changed, 99 insertions(+), 69 deletions(-)
migration/migration-hmp-cmds.c +2 -4
index e8a563c7d8..bc8179c582 100644
@@ -276,14 +276,12 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         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);
-        assert(params->tls_hostname);
+                       params->tls_creds ? params->tls_creds->u.s : "");
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
-            params->tls_hostname);
+                       params->tls_hostname ? params->tls_hostname->u.s : "");
         assert(params->has_max_bandwidth);
         monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
             MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),

migration/migration-hmp-cmds.c void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) · line 323

Quoted 8 lines
migration/migration-hmp-cmds.c +1 -1
@@ -319,7 +317,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
             params->max_postcopy_bandwidth);
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
-            params->tls_authz);
+                       params->tls_authz ? params->tls_authz->u.s : "");
 
         if (params->has_block_bitmap_mapping) {
             const BitmapMigrationNodeAliasList *bmnal;

Before, the code assumes ->tls_creds, ->tls_hostname, and ->tls_authz are non-null. It assert its assumption for the first two.

Afterwards, it maps null to "". Why is that necessary? Hmm, see below.

Quoted 8 lines
Quoted 4 lines

Maps NULL to "" because the intermediate type, MigrationParameters, has been changed from str to StrOrNull. For the purposes of info migrate_parameters and query-migrate-parameters the only valid values are a non-empty string or an empty string.

But is NULL possible? If you just change the type from str to StrOrNull and no more, it isn't.

Since the TLS options don't have a qdev property anymore, they also don't get set a default value. So s->parameters can indeed have the NULL value in it.

I could initialize them in migrate_params_init. It's all about choosing where to move the complexity. I'm leaning towards keeping it in the
interface: query-migrate converts them to whatever it needs to output and set-migrate writes a normalized version into s->parameters.

Quoted 64 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
migration/migration.c +0 -0
index 4697732bef..f65cb81b6d 100644
@@ -4053,6 +4053,8 @@ static void migration_instance_finalize(Object *obj)
 {
     MigrationState *ms = MIGRATION_OBJ(obj);
 
Quoted 7 lines
Quoted 4 lines

migration/migration.c static void migration_instance_finalize(Object *obj) · line 4056

Quoted 1 line
migration/migration.c +1 -0
+    migrate_tls_opts_free(&ms->parameters);

Is this a bug fix?

My new version is a little different, but I can make it a separate patch if that happens to be the case.

Yes, please.

Quoted 37 lines
Quoted 4 lines

As far as I can tell, the object gets destroyed only on QEMU shutdown. Freeing resources then is unnecessary, except it may help leak detection tools.

From a maintenance perspective I consider any leak as a bug because I don't have control over what kinds of leak detection tools are ran on the code. To avoid spending time looking at such bug reports I have ASAN automated in my testing and I fix early any leaks that it founds.

Quoted 27 lines
Quoted 10 lines
migration/migration.c +1 -0
+
     qemu_mutex_destroy(&ms->error_mutex);
     qemu_mutex_destroy(&ms->qemu_file_lock);
     qemu_sem_destroy(&ms->wait_unplug_sem);
migration/options.c +0 -0
index 162c72cda4..45a95dc6da 100644
@@ -162,9 +162,11 @@ const Property migration_properties[] = {
     DEFINE_PROP_SIZE("announce-step", MigrationState,

migration/options.c const Property migration_properties[] = { · line 169

Quoted 10 lines
migration/options.c +5 -3
                       parameters.announce_step,
                       DEFAULT_MIGRATE_ANNOUNCE_STEP),
-    DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds),
-    DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname),
-    DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz),
+    /*
+     * tls-creds, tls-hostname and tls-authz are of type StrOrNull,
+     * which can't be easily handled (if at all) by qdev. So these
+     * will not be exposed as global migration options (-global).
+     */

This is a compatibility break.

The orthodox way to break it is deprecate, let the grace period expire, break. Record in docs/about/deprecated.rst at the beginning, move the record to docs/about/removed-features.rst at the end.

Quoted 8 lines
Quoted 5 lines

An argument could be made that the interface in question is accidental[*], not actually used by anything, and therefore breaking it without a grace period is fine. But even then we should record the breakage in docs/about/removed-features.rst.

Ok. Alternatively I could try a little harder to keep these options. I'll see what I can do.

Quoted 8 lines

What do we think about this external interface?

If we think it's accidental and unused, then putting in more work to keep it makes no sense.

If we think it's deliberate and/or used, we should either keep it, or replace it the orthodox way.

There are two external interfaces actually.

-global migration.some_compat_option=on (stored in MigrationState):

seems intentional and I believe we'd lose the ability to get out of some tricky situations if we ditched it.

-global migation.some_random_option=on (stored in MigrationParameters):

has become a debugging *feature*, which I personally don't use, but others do. And worse: we don't know if anyone uses it in production.

We also arbitrarily put x- in front of options for some reason. There is an argument to drop those because x- is scary and no one should be using them.

I think it would be good to at least separate the responsibilities so when the time comes we can deprecate/remove/replace the offending interfaces. But I won't go into that now, there's already too much change going on for this release.

Reviewed-by Juan Quintela Reviewed-by John Snow
#8 lore raw

Re: [PATCH 01/21] migration: Normalize tls arguments

Quoted 95 lines · Fabiano Rosas
Quoted 84 lines · Markus Armbruster
Quoted 82 lines · Fabiano Rosas
Quoted 19 lines · Markus Armbruster
Quoted 13 lines · Fabiano Rosas

The migration parameters tls_creds, tls_authz and tls_hostname currently have a non-uniform handling. When used as arguments to migrate-set-parameters, their type is StrOrNull and when used as return value from query-migrate-parameters, their type is a plain string.

Not only having to convert between the types is cumbersome, but it also creates the issue of requiring two different QAPI types to be used, one for each command. MigrateSetParameters is used for migrate-set-parameters with the TLS arguments as StrOrNull while MigrationParameters is used for query-migrate-parameters with the TLS arguments as str.

Quoted 3 lines

Since StrOrNull could be considered a superset of str, change the type of the TLS arguments in MigrationParameters to StrOrNull and add a helper to ensure they're never actually used as QTYPE_QNULL.

Quoted 8 lines

The type of @tls_creds, @tls-hostname, @tls-authz changes from str to StrOrNull in introspection query-migrate-parameters. Loss of precision. Introspection is already imprecise: it shows the members optional even though they aren't. We accept the loss of precision to enable de-duplication.

This should be worked into the commit message.

Ack.

Quoted 49 lines
Quoted 35 lines

This will allow the type duplication to be removed in the next patches.

---
 migration/migration-hmp-cmds.c |   8 +-
 migration/migration.c          |   2 +
 migration/options.c            | 149 ++++++++++++++++++++-------------
 migration/options.h            |   1 +
 migration/tls.c                |   2 +-
 qapi/migration.json            |   6 +-
 6 files changed, 99 insertions(+), 69 deletions(-)
migration/migration-hmp-cmds.c +2 -4
index e8a563c7d8..bc8179c582 100644
@@ -276,14 +276,12 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         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);
-        assert(params->tls_hostname);
+                       params->tls_creds ? params->tls_creds->u.s : "");
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
-            params->tls_hostname);
+                       params->tls_hostname ? params->tls_hostname->u.s : "");
         assert(params->has_max_bandwidth);
         monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
             MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),

migration/migration-hmp-cmds.c void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) · line 323

Quoted 8 lines
migration/migration-hmp-cmds.c +1 -1
@@ -319,7 +317,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
             params->max_postcopy_bandwidth);
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
-            params->tls_authz);
+                       params->tls_authz ? params->tls_authz->u.s : "");
 
         if (params->has_block_bitmap_mapping) {
             const BitmapMigrationNodeAliasList *bmnal;

Before, the code assumes ->tls_creds, ->tls_hostname, and ->tls_authz are non-null. It assert its assumption for the first two.

Afterwards, it maps null to "". Why is that necessary? Hmm, see below.

Quoted 8 lines
Quoted 4 lines

Maps NULL to "" because the intermediate type, MigrationParameters, has been changed from str to StrOrNull. For the purposes of info migrate_parameters and query-migrate-parameters the only valid values are a non-empty string or an empty string.

But is NULL possible? If you just change the type from str to StrOrNull and no more, it isn't.

Quoted 6 lines

Since the TLS options don't have a qdev property anymore, they also don't get set a default value. So s->parameters can indeed have the NULL value in it.

I could initialize them in migrate_params_init. It's all about choosing where to move the complexity.

True!

Quoted 3 lines

I'm leaning towards keeping it in the
interface: query-migrate converts them to whatever it needs to output and set-migrate writes a normalized version into s->parameters.

There more than one way to skin this cat. I like to keep state normalized.

State is an optional StrOrNull. Possible values:

* NULL

* QNull, i.e. non-NULL, ->type is QTYPE_QNULL

* Empty string, i.e. non-NULL, ->type is QTYPE_QSTRING, ->u.s is ""

* Non-empty string, i.e. non-NULL, -> type is QTYPE_QSTRING, ->u.s is not "" (and cannot be NULL)

As far as I understand, we have just two cases semantically:

* Set, value is a non-empty string (empty makes no sense)

* Unset

I'd normalize the state to "either NULL, or (non-empty) string".

When writing state, we need to normalize.

When reading state, we can rely on it being normalized. Asserting it is seems prudent, and should help readers.

[...]

Quoted 45 lines
Quoted 32 lines
Quoted 23 lines
Quoted 23 lines
Quoted 6 lines
migration/options.c +0 -0
index 162c72cda4..45a95dc6da 100644
@@ -162,9 +162,11 @@ const Property migration_properties[] = {
     DEFINE_PROP_SIZE("announce-step", MigrationState,

migration/options.c const Property migration_properties[] = { · line 169

Quoted 10 lines
migration/options.c +5 -3
                       parameters.announce_step,
                       DEFAULT_MIGRATE_ANNOUNCE_STEP),
-    DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds),
-    DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname),
-    DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz),
+    /*
+     * tls-creds, tls-hostname and tls-authz are of type StrOrNull,
+     * which can't be easily handled (if at all) by qdev. So these
+     * will not be exposed as global migration options (-global).
+     */

This is a compatibility break.

The orthodox way to break it is deprecate, let the grace period expire, break. Record in docs/about/deprecated.rst at the beginning, move the record to docs/about/removed-features.rst at the end.

Quoted 8 lines
Quoted 5 lines

An argument could be made that the interface in question is accidental[*], not actually used by anything, and therefore breaking it without a grace period is fine. But even then we should record the breakage in docs/about/removed-features.rst.

Ok. Alternatively I could try a little harder to keep these options. I'll see what I can do.

Quoted 8 lines

What do we think about this external interface?

If we think it's accidental and unused, then putting in more work to keep it makes no sense.

If we think it's deliberate and/or used, we should either keep it, or replace it the orthodox way.

There are two external interfaces actually.

-global migration.some_compat_option=on (stored in MigrationState):

Quoted 7 lines

seems intentional and I believe we'd lose the ability to get out of some tricky situations if we ditched it.

-global migation.some_random_option=on (stored in MigrationParameters):

has become a debugging *feature*, which I personally don't use, but others do. And worse: we don't know if anyone uses it in production.

Accidental external interface.

Quoted 3 lines

We also arbitrarily put x- in front of options for some reason. There is an argument to drop those because x- is scary and no one should be using them.

We pretty much ditched the x- convention in the QAPI schema. docs/devel/qapi-code-gen.rst:

Names beginning with ``x-`` used to signify "experimental". This convention has been replaced by special feature "unstable".

Goes back to

commit a3c45b3e62962f99338716b1347cfb0d427cea44

Author: Markus Armbruster <[email protected]>
Date:   Thu Oct 28 12:25:12 2021 +0200

qapi: New special feature flag "unstable"

By convention, names starting with "x-" are experimental. The parts of external interfaces so named may be withdrawn or changed incompatibly in future releases.

The naming convention makes unstable interfaces easy to recognize. Promoting something from experimental to stable involves a name change. Client code needs to be updated. Occasionally bothersome.

Worse, the convention is not universally observed:

* QOM type "input-barrier" has properties "x-origin", "y-origin". Looks accidental, but it's ABI since 4.2.

* QOM types "memory-backend-file", "memory-backend-memfd", "memory-backend-ram", and "memory-backend-epc" have a property "x-use-canonical-path-for-ramblock-id" that is documented to be stable despite its name.

We could document these exceptions, but documentation helps only humans. We want to recognize "unstable" in code, like "deprecated".

So support recognizing it the same way: introduce new special feature flag "unstable". It will be treated specially by the QAPI generator, like the existing feature flag "deprecated", and unlike regular feature flags.

This commit updates documentation and prepares tests. The next commit updates the QAPI schema. The remaining patches update the QAPI generator and wire up -compat policy checking.

Management applications can then use query-qmp-schema and -compat to manage or guard against use of unstable interfaces the same way as for deprecated interfaces.

docs/devel/qapi-code-gen.txt no longer mandates the naming convention. Using it anyway might help writers of programs that aren't full-fledged management applications. Not using it can save us bothersome renames. We'll see how that shakes out.

Message-Id: <[email protected]>

The x- convention lives on in external interfaces that bypass QAPI, in particular QOM/qdev properties.

Quoted 4 lines

I think it would be good to at least separate the responsibilities so when the time comes we can deprecate/remove/replace the offending interfaces. But I won't go into that now, there's already too much change going on for this release.

Makes sense.

#9 lore raw

Re: [PATCH 01/21] migration: Normalize tls arguments

Quoted 124 lines · Markus Armbruster
Quoted 95 lines · Fabiano Rosas
Quoted 84 lines · Markus Armbruster
Quoted 82 lines · Fabiano Rosas
Quoted 19 lines · Markus Armbruster
Quoted 13 lines · Fabiano Rosas

The migration parameters tls_creds, tls_authz and tls_hostname currently have a non-uniform handling. When used as arguments to migrate-set-parameters, their type is StrOrNull and when used as return value from query-migrate-parameters, their type is a plain string.

Not only having to convert between the types is cumbersome, but it also creates the issue of requiring two different QAPI types to be used, one for each command. MigrateSetParameters is used for migrate-set-parameters with the TLS arguments as StrOrNull while MigrationParameters is used for query-migrate-parameters with the TLS arguments as str.

Quoted 3 lines

Since StrOrNull could be considered a superset of str, change the type of the TLS arguments in MigrationParameters to StrOrNull and add a helper to ensure they're never actually used as QTYPE_QNULL.

Quoted 8 lines

The type of @tls_creds, @tls-hostname, @tls-authz changes from str to StrOrNull in introspection query-migrate-parameters. Loss of precision. Introspection is already imprecise: it shows the members optional even though they aren't. We accept the loss of precision to enable de-duplication.

This should be worked into the commit message.

Ack.

Quoted 49 lines
Quoted 35 lines

This will allow the type duplication to be removed in the next patches.

---
 migration/migration-hmp-cmds.c |   8 +-
 migration/migration.c          |   2 +
 migration/options.c            | 149 ++++++++++++++++++++-------------
 migration/options.h            |   1 +
 migration/tls.c                |   2 +-
 qapi/migration.json            |   6 +-
 6 files changed, 99 insertions(+), 69 deletions(-)
migration/migration-hmp-cmds.c +2 -4
index e8a563c7d8..bc8179c582 100644
@@ -276,14 +276,12 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
         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);
-        assert(params->tls_hostname);
+                       params->tls_creds ? params->tls_creds->u.s : "");
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
-            params->tls_hostname);
+                       params->tls_hostname ? params->tls_hostname->u.s : "");
         assert(params->has_max_bandwidth);
         monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
             MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),

migration/migration-hmp-cmds.c void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict) · line 323

Quoted 8 lines
migration/migration-hmp-cmds.c +1 -1
@@ -319,7 +317,7 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
             params->max_postcopy_bandwidth);
         monitor_printf(mon, "%s: '%s'\n",
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
-            params->tls_authz);
+                       params->tls_authz ? params->tls_authz->u.s : "");
 
         if (params->has_block_bitmap_mapping) {
             const BitmapMigrationNodeAliasList *bmnal;

Before, the code assumes ->tls_creds, ->tls_hostname, and ->tls_authz are non-null. It assert its assumption for the first two.

Afterwards, it maps null to "". Why is that necessary? Hmm, see below.

Quoted 8 lines
Quoted 4 lines

Maps NULL to "" because the intermediate type, MigrationParameters, has been changed from str to StrOrNull. For the purposes of info migrate_parameters and query-migrate-parameters the only valid values are a non-empty string or an empty string.

But is NULL possible? If you just change the type from str to StrOrNull and no more, it isn't.

Quoted 6 lines

Since the TLS options don't have a qdev property anymore, they also don't get set a default value. So s->parameters can indeed have the NULL value in it.

I could initialize them in migrate_params_init. It's all about choosing where to move the complexity.

True!

Quoted 3 lines

I'm leaning towards keeping it in the
interface: query-migrate converts them to whatever it needs to output and set-migrate writes a normalized version into s->parameters.

There more than one way to skin this cat. I like to keep state normalized.

State is an optional StrOrNull. Possible values:

* NULL

* QNull, i.e. non-NULL, ->type is QTYPE_QNULL

* Empty string, i.e. non-NULL, ->type is QTYPE_QSTRING, ->u.s is ""

* Non-empty string, i.e. non-NULL, -> type is QTYPE_QSTRING, ->u.s is not "" (and cannot be NULL)

Quoted 8 lines

As far as I understand, we have just two cases semantically:

* Set, value is a non-empty string (empty makes no sense)

* Unset

I'd normalize the state to "either NULL, or (non-empty) string".

This is what I wanted to do (in the next version), but it results in more complex and less readable code:

A) "abc"|NULL

hmp_info_migrate_parameters:

    monitor_printf(..., params->tls_creds ? params->tls_creds->u.s : "");

migrate_tls_creds:

    if (s->parameters.tls_creds) {
        return s->parameters.tls_creds->u.s;
    }
    return NULL;

migrate_params_check:

    if (migrate_zero_copy_send() && params->tls_creds ...

qmp_migrate_set_parameters:

    migrate_params_test_apply(params);
    if (migrate_params_check(tmp)) {
        migrate_params_apply(params);
        tls_normalize_qnull_empty_str_to_null(&s->parameters);  <-- [1]
    }

qmp_query_migrate_parameters:

    params = QAPI_CLONE(MigrationParameters, &s->parameters);
    tls_normalize_null_back_to_empty_str();   <-- [2]

Issues here are that in [1] we can't normalize earlier because we need QTYPE_QNULL to know whether the option was ever set and in [2], since s->parameters may contain NULL, we need another conversion step to be able to return "". Overall, this makes the normalization step not very useful because we need to keep track of which parts of the code are normalized or not.

If we instead normalize to "either non-empty string or empty string" then:

B) "abc"|""

hmp_info_migrate_parameters:

    monitor_printf(..., params->tls_creds);

migrate_tls_creds:

    if (*s->parameters.tls_creds->u.s) {
        return s->parameters.tls_creds->u.s;
    }
    return NULL;   <-- [1]

migrate_params_check:

    if (migrate_zero_copy_send() && *params->tls_creds->u.s ...

qmp_migrate_set_parameters:

    tls_normalize_qnull_null_to_str(&s->parameters);  <-- [2]
    migrate_params_test_apply(params);
    if (migrate_params_check(tmp)) {
        migrate_params_apply(params);
    }

qmp_query_migrate_parameters:

    params = QAPI_CLONE(MigrationParameters, &s->parameters);

The query methods get simpler because s->parameters already contains data in the format they expect, we can normalize earlier in [2], which means data is always in the same format throughout qmp_migrate_set_parameters() and lastly, we already have the getter methods [1] which can expose "abc"|NULL to the rest of the code anyway.

Quoted 5 lines

When writing state, we need to normalize.

When reading state, we can rely on it being normalized. Asserting it is seems prudent, and should help readers.

My main concern is that reading can rely on it being normalized, but the query methods cannot, so they need to do an "extra conversion", which from the reader's POV, will look nonsensical. It's not as simple as using a ternary because the StrOrNull object needs to be allocated.

Quoted 12 lines

[...]

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
migration/options.c +0 -2
index 162c72cda4..45a95dc6da 100644
@@ -162,9 +162,11 @@ const Property migration_properties[] = {
     DEFINE_PROP_SIZE("announce-step", MigrationState,
                       parameters.announce_step,
                       DEFAULT_MIGRATE_ANNOUNCE_STEP),
-    DEFINE_PROP_STRING("tls-creds", MigrationState, parameters.tls_creds),
-    DEFINE_PROP_STRING("tls-hostname", MigrationState, parameters.tls_hostname),
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

migration/options.c const Property migration_properties[] = { · line 169

Quoted 6 lines
migration/options.c +5 -1
-    DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz),
+    /*
+     * tls-creds, tls-hostname and tls-authz are of type StrOrNull,
+     * which can't be easily handled (if at all) by qdev. So these
+     * will not be exposed as global migration options (-global).
+     */

This is a compatibility break.

Coming back to this, I implemented a DEFINE_PROP_STR_OR_NULL. It's way better than removing the options, because this allows a default to be set, which means query-migrate-parameters() doesn't need to deal with an initial NULL value anymore (if query is called before set).

Quoted 50 lines
Quoted 27 lines
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines

The orthodox way to break it is deprecate, let the grace period expire, break. Record in docs/about/deprecated.rst at the beginning, move the record to docs/about/removed-features.rst at the end.

Quoted 8 lines
Quoted 5 lines

An argument could be made that the interface in question is accidental[*], not actually used by anything, and therefore breaking it without a grace period is fine. But even then we should record the breakage in docs/about/removed-features.rst.

Ok. Alternatively I could try a little harder to keep these options. I'll see what I can do.

Quoted 8 lines

What do we think about this external interface?

If we think it's accidental and unused, then putting in more work to keep it makes no sense.

If we think it's deliberate and/or used, we should either keep it, or replace it the orthodox way.

There are two external interfaces actually.

-global migration.some_compat_option=on (stored in MigrationState):

Quoted 7 lines

seems intentional and I believe we'd lose the ability to get out of some tricky situations if we ditched it.

-global migation.some_random_option=on (stored in MigrationParameters):

has become a debugging *feature*, which I personally don't use, but others do. And worse: we don't know if anyone uses it in production.

Accidental external interface.

Quoted 3 lines

We also arbitrarily put x- in front of options for some reason. There is an argument to drop those because x- is scary and no one should be using them.

We pretty much ditched the x- convention in the QAPI schema. docs/devel/qapi-code-gen.rst:

Names beginning with ``x-`` used to signify "experimental". This convention has been replaced by special feature "unstable".

Goes back to

commit a3c45b3e62962f99338716b1347cfb0d427cea44

Quoted 8 lines
Author: Markus Armbruster <[email protected]>
Date:   Thu Oct 28 12:25:12 2021 +0200

qapi: New special feature flag "unstable"

By convention, names starting with "x-" are experimental. The parts of external interfaces so named may be withdrawn or changed incompatibly in future releases.

This allows dropping about half of the parameters we expose. Deprecate the other half, move the remaining legitimate compat options into MigrationParameters, (which can be set by migrate-set-parameters) and maybe we can remove the TYPE_DEVICE from MigrationState anytime this decade.

Moving all qdev properties to their own TYPE_DEVICE object and putting it under --enable-debug is also an idea.

I'm willing to do the work if we ever reach a consensus about this.

Quoted 50 lines

The naming convention makes unstable interfaces easy to recognize. Promoting something from experimental to stable involves a name change. Client code needs to be updated. Occasionally bothersome.

Worse, the convention is not universally observed:

* QOM type "input-barrier" has properties "x-origin", "y-origin". Looks accidental, but it's ABI since 4.2.

* QOM types "memory-backend-file", "memory-backend-memfd", "memory-backend-ram", and "memory-backend-epc" have a property "x-use-canonical-path-for-ramblock-id" that is documented to be stable despite its name.

We could document these exceptions, but documentation helps only humans. We want to recognize "unstable" in code, like "deprecated".

So support recognizing it the same way: introduce new special feature flag "unstable". It will be treated specially by the QAPI generator, like the existing feature flag "deprecated", and unlike regular feature flags.

This commit updates documentation and prepares tests. The next commit updates the QAPI schema. The remaining patches update the QAPI generator and wire up -compat policy checking.

Management applications can then use query-qmp-schema and -compat to manage or guard against use of unstable interfaces the same way as for deprecated interfaces.

docs/devel/qapi-code-gen.txt no longer mandates the naming convention. Using it anyway might help writers of programs that aren't full-fledged management applications. Not using it can save us bothersome renames. We'll see how that shakes out.

Message-Id: <[email protected]>

The x- convention lives on in external interfaces that bypass QAPI, in particular QOM/qdev properties.

Quoted 4 lines

I think it would be good to at least separate the responsibilities so when the time comes we can deprecate/remove/replace the offending interfaces. But I won't go into that now, there's already too much change going on for this release.

Makes sense.

#10 lore raw

Re: [PATCH 01/21] migration: Normalize tls arguments

Quoted 11 lines · Fabiano Rosas
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Fabiano Rosas
Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Fabiano Rosas
Quoted 1 line · Markus Armbruster

Fabiano Rosas <[email protected]> writes:

[...]

Quoted 25 lines
Quoted 14 lines

There more than one way to skin this cat. I like to keep state normalized.

State is an optional StrOrNull. Possible values:

* NULL

* QNull, i.e. non-NULL, ->type is QTYPE_QNULL

* Empty string, i.e. non-NULL, ->type is QTYPE_QSTRING, ->u.s is ""

* Non-empty string, i.e. non-NULL, -> type is QTYPE_QSTRING, ->u.s is not "" (and cannot be NULL)

Quoted 8 lines

As far as I understand, we have just two cases semantically:

* Set, value is a non-empty string (empty makes no sense)

* Unset

I'd normalize the state to "either NULL, or (non-empty) string".

This is what I wanted to do (in the next version), but it results in more complex and less readable code:

[...]

Quoted 2 lines

If we instead normalize to "either non-empty string or empty string" then:

[...]

Quoted 5 lines

The query methods get simpler because s->parameters already contains data in the format they expect, we can normalize earlier in [2], which means data is always in the same format throughout qmp_migrate_set_parameters() and lastly, we already have the getter methods [1] which can expose "abc"|NULL to the rest of the code anyway.

I'd like the possible states to be clearly visible, and suggest to guard them with assertions. Details, such as how exactly the states are encoded, are up to you. You're in a better position to judge them than I am.

Quoted 10 lines
Quoted 5 lines

When writing state, we need to normalize.

When reading state, we can rely on it being normalized. Asserting it is seems prudent, and should help readers.

My main concern is that reading can rely on it being normalized, but the query methods cannot, so they need to do an "extra conversion", which from the reader's POV, will look nonsensical. It's not as simple as using a ternary because the StrOrNull object needs to be allocated.

[...]

Quoted 36 lines
Quoted 27 lines
Quoted 11 lines

There are two external interfaces actually.

-global migration.some_compat_option=on (stored in MigrationState):

seems intentional and I believe we'd lose the ability to get out of some tricky situations if we ditched it.

-global migation.some_random_option=on (stored in MigrationParameters):

has become a debugging *feature*, which I personally don't use, but others do. And worse: we don't know if anyone uses it in production.

Accidental external interface.

Quoted 3 lines

We also arbitrarily put x- in front of options for some reason. There is an argument to drop those because x- is scary and no one should be using them.

We pretty much ditched the x- convention in the QAPI schema. docs/devel/qapi-code-gen.rst:

Names beginning with ``x-`` used to signify "experimental". This convention has been replaced by special feature "unstable".

Goes back to

commit a3c45b3e62962f99338716b1347cfb0d427cea44

Quoted 8 lines
Author: Markus Armbruster <[email protected]>
Date:   Thu Oct 28 12:25:12 2021 +0200

qapi: New special feature flag "unstable"

By convention, names starting with "x-" are experimental. The parts of external interfaces so named may be withdrawn or changed incompatibly in future releases.

Quoted 5 lines

This allows dropping about half of the parameters we expose. Deprecate the other half, move the remaining legitimate compat options into MigrationParameters, (which can be set by migrate-set-parameters) and maybe we can remove the TYPE_DEVICE from MigrationState anytime this decade.

I'd love to get rid of the pseudo-device.

Quoted 4 lines

Moving all qdev properties to their own TYPE_DEVICE object and putting it under --enable-debug is also an idea.

I'm willing to do the work if we ever reach a consensus about this.

I'd like migration to work more like other long-running tasks: pass the entire configuration with the command starting it, provide commands and events to manage the task while it runs.

This is advice, not a demand. I'm not going to block change the migration maintainers want. I may ask you to do the QAPI schema part in certain ways, but that's detail.

[...]

#11 lore raw

Re: [PATCH 01/21] migration: Normalize tls arguments

Quoted 122 lines · Markus Armbruster
Quoted 11 lines · Fabiano Rosas
Quoted 9 lines · Markus Armbruster
Quoted 7 lines · Fabiano Rosas
Quoted 5 lines · Markus Armbruster
Quoted 3 lines · Fabiano Rosas
Quoted 1 line · Markus Armbruster

Fabiano Rosas <[email protected]> writes:

[...]

Quoted 25 lines
Quoted 14 lines

There more than one way to skin this cat. I like to keep state normalized.

State is an optional StrOrNull. Possible values:

* NULL

* QNull, i.e. non-NULL, ->type is QTYPE_QNULL

* Empty string, i.e. non-NULL, ->type is QTYPE_QSTRING, ->u.s is ""

* Non-empty string, i.e. non-NULL, -> type is QTYPE_QSTRING, ->u.s is not "" (and cannot be NULL)

Quoted 8 lines

As far as I understand, we have just two cases semantically:

* Set, value is a non-empty string (empty makes no sense)

* Unset

I'd normalize the state to "either NULL, or (non-empty) string".

This is what I wanted to do (in the next version), but it results in more complex and less readable code:

[...]

Quoted 2 lines

If we instead normalize to "either non-empty string or empty string" then:

[...]

Quoted 5 lines

The query methods get simpler because s->parameters already contains data in the format they expect, we can normalize earlier in [2], which means data is always in the same format throughout qmp_migrate_set_parameters() and lastly, we already have the getter methods [1] which can expose "abc"|NULL to the rest of the code anyway.

I'd like the possible states to be clearly visible, and suggest to guard them with assertions. Details, such as how exactly the states are encoded, are up to you. You're in a better position to judge them than I am.

Quoted 10 lines
Quoted 5 lines

When writing state, we need to normalize.

When reading state, we can rely on it being normalized. Asserting it is seems prudent, and should help readers.

My main concern is that reading can rely on it being normalized, but the query methods cannot, so they need to do an "extra conversion", which from the reader's POV, will look nonsensical. It's not as simple as using a ternary because the StrOrNull object needs to be allocated.

[...]

Quoted 36 lines
Quoted 27 lines
Quoted 11 lines

There are two external interfaces actually.

-global migration.some_compat_option=on (stored in MigrationState):

seems intentional and I believe we'd lose the ability to get out of some tricky situations if we ditched it.

-global migation.some_random_option=on (stored in MigrationParameters):

has become a debugging *feature*, which I personally don't use, but others do. And worse: we don't know if anyone uses it in production.

Accidental external interface.

Quoted 3 lines

We also arbitrarily put x- in front of options for some reason. There is an argument to drop those because x- is scary and no one should be using them.

We pretty much ditched the x- convention in the QAPI schema. docs/devel/qapi-code-gen.rst:

Names beginning with ``x-`` used to signify "experimental". This convention has been replaced by special feature "unstable".

Goes back to

commit a3c45b3e62962f99338716b1347cfb0d427cea44

Quoted 8 lines
Author: Markus Armbruster <[email protected]>
Date:   Thu Oct 28 12:25:12 2021 +0200

qapi: New special feature flag "unstable"

By convention, names starting with "x-" are experimental. The parts of external interfaces so named may be withdrawn or changed incompatibly in future releases.

Quoted 5 lines

This allows dropping about half of the parameters we expose. Deprecate the other half, move the remaining legitimate compat options into MigrationParameters, (which can be set by migrate-set-parameters) and maybe we can remove the TYPE_DEVICE from MigrationState anytime this decade.

I'd love to get rid of the pseudo-device.

Quoted 4 lines

Moving all qdev properties to their own TYPE_DEVICE object and putting it under --enable-debug is also an idea.

I'm willing to do the work if we ever reach a consensus about this.

Quoted 7 lines

I'd like migration to work more like other long-running tasks: pass the entire configuration with the command starting it, provide commands and events to manage the task while it runs.

This is advice, not a demand. I'm not going to block change the migration maintainers want. I may ask you to do the QAPI schema part in certain ways, but that's detail.

This should be doable as IIUC at the end of this series, the QMP 'migrate-incoming' command parameters can express all the required data for accepting an incoming migration. As such, that parameter struct could be exposed on the CLI with the CLI json syntax to accept complex args in a way that wasn't possible historically with -incoming.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#12 lore raw

PATCH 2/21 migration: Remove MigrateSetParameters

In reply to Fabiano Rosas

Now that the TLS options have been made the same between migrate-set-parameters and query-migrate-parameters, a single type can be used. Remove MigrateSetParameters.

The TLS options documentation from MigrationParameters were replaced with the ones from MigrateSetParameters which was more complete.

I'm choosing to somewhat ignore any ambiguity between "query" and "set" because other options' docs are already ambiguous in that regard.

---
 migration/migration-hmp-cmds.c |   4 +-
 migration/options.c            |   6 +-
 qapi/migration.json            | 221 +++------------------------------
 3 files changed, 20 insertions(+), 211 deletions(-)
migration/migration-hmp-cmds.c +2 -2
index bc8179c582..aacffdc532 100644
@@ -490,7 +490,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     const char *param = qdict_get_str(qdict, "parameter");
     const char *valuestr = qdict_get_str(qdict, "value");
     Visitor *v = string_input_visitor_new(valuestr);
-    MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
+    MigrationParameters *p = g_new0(MigrationParameters, 1);
     uint64_t valuebw = 0;
     uint64_t cache_size;
     Error *err = NULL;
@@ -656,7 +656,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_parameters(p, &err);
 
  cleanup:
-    qapi_free_MigrateSetParameters(p);
+    qapi_free_MigrationParameters(p);
     visit_free(v);
     hmp_handle_error(mon, err);
 }
migration/options.c +3 -3
index 45a95dc6da..e49d584a99 100644
@@ -1227,7 +1227,7 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)
     return true;
 }
 
-static void migrate_params_test_apply(MigrateSetParameters *params,
+static void migrate_params_test_apply(MigrationParameters *params,
                                       MigrationParameters *dest)
 {
     *dest = migrate_get_current()->parameters;
@@ -1350,7 +1350,7 @@ static void migrate_params_test_apply(MigrateSetParameters *params,
     }
 }
 
-static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
+static void migrate_params_apply(MigrationParameters *params, Error **errp)
 {
     MigrationState *s = migrate_get_current();
 
@@ -1479,7 +1479,7 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
     }
 }
 
-void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
+void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
 {
     MigrationParameters tmp;
 
qapi/migration.json +15 -206

250 lines not on this page · raw message

Signature · 1 line
2.35.3
Reviewed-by on v1 2/21
#13 lore raw

Re: [PATCH 02/21] migration: Remove MigrateSetParameters

Quoted 4 lines · Fabiano Rosas

Now that the TLS options have been made the same between migrate-set-parameters and query-migrate-parameters, a single type can be used. Remove MigrateSetParameters.

Quoted 8 lines

The TLS options documentation from MigrationParameters were replaced with the ones from MigrateSetParameters which was more complete.

I'm choosing to somewhat ignore any ambiguity between "query" and "set" because other options' docs are already ambiguous in that regard.

It's like some wish is going to come true..

Signature · 1 line
Peter Xu
#14 lore raw

Re: [PATCH 02/21] migration: Remove MigrateSetParameters

In reply to Fabiano Rosas
Quoted 76 lines · Fabiano Rosas

Now that the TLS options have been made the same between migrate-set-parameters and query-migrate-parameters, a single type can be used. Remove MigrateSetParameters.

The TLS options documentation from MigrationParameters were replaced with the ones from MigrateSetParameters which was more complete.

I'm choosing to somewhat ignore any ambiguity between "query" and "set" because other options' docs are already ambiguous in that regard.

---
 migration/migration-hmp-cmds.c |   4 +-
 migration/options.c            |   6 +-
 qapi/migration.json            | 221 +++------------------------------
 3 files changed, 20 insertions(+), 211 deletions(-)
migration/migration-hmp-cmds.c +2 -2
index bc8179c582..aacffdc532 100644
@@ -490,7 +490,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     const char *param = qdict_get_str(qdict, "parameter");
     const char *valuestr = qdict_get_str(qdict, "value");
     Visitor *v = string_input_visitor_new(valuestr);
-    MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
+    MigrationParameters *p = g_new0(MigrationParameters, 1);
     uint64_t valuebw = 0;
     uint64_t cache_size;
     Error *err = NULL;
@@ -656,7 +656,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_parameters(p, &err);
 
  cleanup:
-    qapi_free_MigrateSetParameters(p);
+    qapi_free_MigrationParameters(p);
     visit_free(v);
     hmp_handle_error(mon, err);
 }
migration/options.c +3 -3
index 45a95dc6da..e49d584a99 100644
@@ -1227,7 +1227,7 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)
     return true;
 }
 
-static void migrate_params_test_apply(MigrateSetParameters *params,
+static void migrate_params_test_apply(MigrationParameters *params,
                                       MigrationParameters *dest)
 {
     *dest = migrate_get_current()->parameters;
@@ -1350,7 +1350,7 @@ static void migrate_params_test_apply(MigrateSetParameters *params,
     }
 }
 
-static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
+static void migrate_params_apply(MigrationParameters *params, Error **errp)
 {
     MigrationState *s = migrate_get_current();
 
@@ -1479,7 +1479,7 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
     }
 }
 
-void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
+void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
 {
     MigrationParameters tmp;
 
qapi/migration.json +0 -0
index fa42d94810..080968993a 100644

qapi/migration.json line 918

Quoted 5 lines
qapi/migration.json +0 -2
@@ -914,202 +914,6 @@
            'zero-page-detection',
            'direct-io'] }
 
-##
-# @MigrateSetParameters:

Only use is argument type of migrate-set-parameters. You're replacing it by MigrationParameters there. Let's compare the deleted docs to their replacement. I'll quote replacement docs exactly where they differ.

# @MigrationParameters:
#
# Migration parameters. Optional members are optional when used with

   # an input command, otherwise mandatory.

Figuring out which commands are input commands is left to the reader. Why not simply "optional with migrate-set-parameters"?

However, it doesn't end there. The paragraph creates a problem with John Snow's "inliner", which I hope to merge later this year. Let me explain.

Generated command documentation normally looks like this:

Command migrate-set-capabilities (Since: 1.2)

Enable/Disable the following migration capabilities (like xbzrle)

Arguments:
* **capabilities** ("[""MigrationCapabilityStatus""]") -- json array of capability modifications to make

Except when we happen to use a named type for the arguments. This should be an implementation detail, and it is, except for generated documentation, which looks like

Command migrate-set-parameters (Since: 2.4)

Set various migration parameters.

Arguments:
* The members of "MigrationParameters".

The arguments are hidden behind a link. The "inliner" will show the them normally *always*, for better usability. It will not, however, inline the introductory paragraph above. I can explain why if necessary.

To compensate for the loss of that paragraph, we'll have to add suitable text to migrate-set-parameters's doc comment.

I think we could just as well do that *now*: scratch the paragraph here, add a suitable paragraph there.

Quoted 11 lines
qapi/migration.json +0 -11
-#
-# @announce-initial: Initial delay (in milliseconds) before sending
-#     the first announce (Since 4.0)
-#
-# @announce-max: Maximum delay (in milliseconds) between packets in
-#     the announcement (Since 4.0)
-#
-# @announce-rounds: Number of self-announce packets sent after
-#     migration (Since 4.0)
-#
-# @announce-step: Increase in delay (in milliseconds) between

qapi/migration.json line 939

Quoted 10 lines
qapi/migration.json +0 -10
-#     subsequent packets in the announcement (Since 4.0)
-#
-# @throttle-trigger-threshold: The ratio of bytes_dirty_period and
-#     bytes_xfer_period to trigger throttling.  It is expressed as
-#     percentage.  The default value is 50.  (Since 5.0)
-#
-# @cpu-throttle-initial: Initial percentage of time guest cpus are
-#     throttled when migration auto-converge is activated.  The
-#     default value is 20.  (Since 2.7)
-#

# @cpu-throttle-initial: Initial percentage of time guest cpus are
# throttled when migration auto-converge is activated. (Since
# 2.7)

We no longer document the default value.

qapi/migration.json line 942

Quoted 3 lines
qapi/migration.json +0 -3
-# @cpu-throttle-increment: throttle percentage increase each time
-#     auto-converge detects that migration is not making progress.
-#     The default value is 10.  (Since 2.7)

# @cpu-throttle-increment: throttle percentage increase each time
# auto-converge detects that migration is not making progress.
# (Since 2.7)

Likewise.

Quoted 47 lines
qapi/migration.json +0 -47
-#
-# @cpu-throttle-tailslow: Make CPU throttling slower at tail stage At
-#     the tail stage of throttling, the Guest is very sensitive to CPU
-#     percentage while the @cpu-throttle -increment is excessive
-#     usually at tail stage.  If this parameter is true, we will
-#     compute the ideal CPU percentage used by the Guest, which may
-#     exactly make the dirty rate match the dirty rate threshold.
-#     Then we will choose a smaller throttle increment between the one
-#     specified by @cpu-throttle-increment and the one generated by
-#     ideal CPU percentage.  Therefore, it is compatible to
-#     traditional throttling, meanwhile the throttle increment won't
-#     be excessive at tail stage.  The default value is false.  (Since
-#     5.1)
-#
-# @tls-creds: ID of the 'tls-creds' object that provides credentials
-#     for establishing a TLS connection over the migration data
-#     channel.  On the outgoing side of the migration, the credentials
-#     must be for a 'client' endpoint, while for the incoming side the
-#     credentials must be for a 'server' endpoint.  Setting this to a
-#     non-empty string enables TLS for all migrations.  An empty
-#     string means that QEMU will use plain text mode for migration,
-#     rather than TLS.  This is the default.  (Since 2.7)
-#
-# @tls-hostname: migration target's hostname for validating the
-#     server's x509 certificate identity.  If empty, QEMU will use the
-#     hostname from the migration URI, if any.  A non-empty value is
-#     required when using x509 based TLS credentials and the migration
-#     URI does not include a hostname, such as fd: or exec: based
-#     migration.  (Since 2.7)
-#
-#     Note: empty value works only since 2.9.
-#
-# @tls-authz: ID of the 'authz' object subclass that provides access
-#     control checking of the TLS x509 certificate distinguished name.
-#     This object is only resolved at time of use, so can be deleted
-#     and recreated on the fly while the migration server is active.
-#     If missing, it will default to denying access (Since 4.0)
-#
-# @max-bandwidth: maximum speed for migration, in bytes per second.
-#     (Since 2.8)
-#
-# @avail-switchover-bandwidth: to set the available bandwidth that
-#     migration can use during switchover phase.  NOTE!  This does not
-#     limit the bandwidth during switchover, but only for calculations
-#     when making decisions to switchover.  By default, this value is
-#     zero, which means QEMU will estimate the bandwidth
-#     automatically.  This can be set when the estimated value is not

qapi/migration.json line 999

Quoted 10 lines
qapi/migration.json +0 -10
-#     accurate, while the user is able to guarantee such bandwidth is
-#     available when switching over.  When specified correctly, this
-#     can make the switchover decision much more accurate.
-#     (Since 8.2)
-#
-# @downtime-limit: set maximum tolerated downtime for migration.
-#     maximum downtime in milliseconds (Since 2.8)
-#
-# @x-checkpoint-delay: The delay time (in ms) between two COLO
-#     checkpoints in periodic mode.  (Since 2.8)

# @x-checkpoint-delay: the delay time between two COLO checkpoints.
# (Since 2.8)

We no longer mention periodic mode.

Quoted 67 lines
qapi/migration.json +0 -67
-#
-# @multifd-channels: Number of channels used to migrate data in
-#     parallel.  This is the same number that the number of sockets
-#     used for migration.  The default value is 2 (since 4.0)
-#
-# @xbzrle-cache-size: cache size to be used by XBZRLE migration.  It
-#     needs to be a multiple of the target page size and a power of 2
-#     (Since 2.11)
-#
-# @max-postcopy-bandwidth: Background transfer bandwidth during
-#     postcopy.  Defaults to 0 (unlimited).  In bytes per second.
-#     (Since 3.0)
-#
-# @max-cpu-throttle: maximum cpu throttle percentage.  Defaults to 99.
-#     (Since 3.1)
-#
-# @multifd-compression: Which compression method to use.  Defaults to
-#     none.  (Since 5.0)
-#
-# @multifd-zlib-level: Set the compression level to be used in live
-#     migration, the compression level is an integer between 0 and 9,
-#     where 0 means no compression, 1 means the best compression
-#     speed, and 9 means best compression ratio which will consume
-#     more CPU.  Defaults to 1.  (Since 5.0)
-#
-# @multifd-qatzip-level: Set the compression level to be used in live
-#     migration. The level is an integer between 1 and 9, where 1 means
-#     the best compression speed, and 9 means the best compression
-#     ratio which will consume more CPU. Defaults to 1.  (Since 9.2)
-#
-# @multifd-zstd-level: Set the compression level to be used in live
-#     migration, the compression level is an integer between 0 and 20,
-#     where 0 means no compression, 1 means the best compression
-#     speed, and 20 means best compression ratio which will consume
-#     more CPU.  Defaults to 1.  (Since 5.0)
-#
-# @block-bitmap-mapping: Maps block nodes and bitmaps on them to
-#     aliases for the purpose of dirty bitmap migration.  Such aliases
-#     may for example be the corresponding names on the opposite site.
-#     The mapping must be one-to-one, but not necessarily complete: On
-#     the source, unmapped bitmaps and all bitmaps on unmapped nodes
-#     will be ignored.  On the destination, encountering an unmapped
-#     alias in the incoming migration stream will result in a report,
-#     and all further bitmap migration data will then be discarded.
-#     Note that the destination does not know about bitmaps it does
-#     not receive, so there is no limitation or requirement regarding
-#     the number of bitmaps received, or how they are named, or on
-#     which nodes they are placed.  By default (when this parameter
-#     has never been set), bitmap names are mapped to themselves.
-#     Nodes are mapped to their block device name if there is one, and
-#     to their node name otherwise.  (Since 5.2)
-#
-# @x-vcpu-dirty-limit-period: Periodic time (in milliseconds) of dirty
-#     limit during live migration.  Should be in the range 1 to
-#     1000ms.  Defaults to 1000ms.  (Since 8.1)
-#
-# @vcpu-dirty-limit: Dirtyrate limit (MB/s) during live migration.
-#     Defaults to 1.  (Since 8.1)
-#
-# @mode: Migration mode.  See description in @MigMode.  Default is
-#     'normal'.  (Since 8.2)
-#
-# @zero-page-detection: Whether and how to detect zero pages.
-#     See description in @ZeroPageDetection.  Default is 'multifd'.
-#     (since 9.0)
-#
-# @direct-io: Open migration files with O_DIRECT when possible.  This

qapi/migration.json line 1076

Quoted 10 lines
qapi/migration.json +0 -10
-#     only has effect if the @mapped-ram capability is enabled.
-#     (Since 9.1)
-#
-# Features:
-#
-# @unstable: Members @x-checkpoint-delay and
-#     @x-vcpu-dirty-limit-period are experimental.
-#
-# TODO: either fuse back into MigrationParameters, or make
-#     MigrationParameters members mandatory

The TODO is gone. Makes sense.

Quoted 89 lines
qapi/migration.json +15 -46
-#
-# Since: 2.4
-##
-{ 'struct': 'MigrateSetParameters',
-  'data': { '*announce-initial': 'size',
-            '*announce-max': 'size',
-            '*announce-rounds': 'size',
-            '*announce-step': 'size',
-            '*throttle-trigger-threshold': 'uint8',
-            '*cpu-throttle-initial': 'uint8',
-            '*cpu-throttle-increment': 'uint8',
-            '*cpu-throttle-tailslow': 'bool',
-            '*tls-creds': 'StrOrNull',
-            '*tls-hostname': 'StrOrNull',
-            '*tls-authz': 'StrOrNull',
-            '*max-bandwidth': 'size',
-            '*avail-switchover-bandwidth': 'size',
-            '*downtime-limit': 'uint64',
-            '*x-checkpoint-delay': { 'type': 'uint32',
-                                     'features': [ 'unstable' ] },
-            '*multifd-channels': 'uint8',
-            '*xbzrle-cache-size': 'size',
-            '*max-postcopy-bandwidth': 'size',
-            '*max-cpu-throttle': 'uint8',
-            '*multifd-compression': 'MultiFDCompression',
-            '*multifd-zlib-level': 'uint8',
-            '*multifd-qatzip-level': 'uint8',
-            '*multifd-zstd-level': 'uint8',
-            '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ],
-            '*x-vcpu-dirty-limit-period': { 'type': 'uint64',
-                                            'features': [ 'unstable' ] },
-            '*vcpu-dirty-limit': 'uint64',
-            '*mode': 'MigMode',
-            '*zero-page-detection': 'ZeroPageDetection',
-            '*direct-io': 'bool' } }
-
 ##
 # @migrate-set-parameters:
 #
@@ -1124,12 +928,13 @@
 #     <- { "return": {} }
 ##
 { 'command': 'migrate-set-parameters', 'boxed': true,
-  'data': 'MigrateSetParameters' }
+  'data': 'MigrationParameters' }
 
 ##
 # @MigrationParameters:
 #
-# The optional members aren't actually optional.
+# Migration parameters. Optional members are optional when used with
+# an input command, otherwise mandatory.
 #
 # @announce-initial: Initial delay (in milliseconds) before sending
 #     the first announce (Since 4.0)
@@ -1172,21 +977,25 @@
 #     for establishing a TLS connection over the migration data
 #     channel.  On the outgoing side of the migration, the credentials
 #     must be for a 'client' endpoint, while for the incoming side the
-#     credentials must be for a 'server' endpoint.  An empty string
-#     means that QEMU will use plain text mode for migration, rather
-#     than TLS.  (Since 2.7)
-#
-#     Note: 2.8 omits empty @tls-creds instead.
+#     credentials must be for a 'server' endpoint.  Setting this to a
+#     non-empty string enables TLS for all migrations.  An empty
+#     string means that QEMU will use plain text mode for migration,
+#     rather than TLS.  This is the default.  (Since 2.7)
 #
 # @tls-hostname: migration target's hostname for validating the
 #     server's x509 certificate identity.  If empty, QEMU will use the
-#     hostname from the migration URI, if any.  (Since 2.7)
+#     hostname from the migration URI, if any.  A non-empty value is
+#     required when using x509 based TLS credentials and the migration
+#     URI does not include a hostname, such as fd: or exec: based
+#     migration.  (Since 2.7)
 #
-#     Note: 2.8 omits empty @tls-hostname instead.
+#     Note: empty value works only since 2.9.
 #
 # @tls-authz: ID of the 'authz' object subclass that provides access
 #     control checking of the TLS x509 certificate distinguished name.
-#     (Since 4.0)
+#     This object is only resolved at time of use, so can be deleted
+#     and recreated on the fly while the migration server is active.
+#     If missing, it will default to denying access (Since 4.0)
 #
 # @max-bandwidth: maximum speed for migration, in bytes per second.
 #     (Since 2.8)
#15 lore raw

Re: [PATCH 02/21] migration: Remove MigrateSetParameters

Quoted 89 lines · Markus Armbruster
Quoted 76 lines · Fabiano Rosas

Now that the TLS options have been made the same between migrate-set-parameters and query-migrate-parameters, a single type can be used. Remove MigrateSetParameters.

The TLS options documentation from MigrationParameters were replaced with the ones from MigrateSetParameters which was more complete.

I'm choosing to somewhat ignore any ambiguity between "query" and "set" because other options' docs are already ambiguous in that regard.

---
 migration/migration-hmp-cmds.c |   4 +-
 migration/options.c            |   6 +-
 qapi/migration.json            | 221 +++------------------------------
 3 files changed, 20 insertions(+), 211 deletions(-)
migration/migration-hmp-cmds.c +2 -2
index bc8179c582..aacffdc532 100644
@@ -490,7 +490,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     const char *param = qdict_get_str(qdict, "parameter");
     const char *valuestr = qdict_get_str(qdict, "value");
     Visitor *v = string_input_visitor_new(valuestr);
-    MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
+    MigrationParameters *p = g_new0(MigrationParameters, 1);
     uint64_t valuebw = 0;
     uint64_t cache_size;
     Error *err = NULL;
@@ -656,7 +656,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_parameters(p, &err);
 
  cleanup:
-    qapi_free_MigrateSetParameters(p);
+    qapi_free_MigrationParameters(p);
     visit_free(v);
     hmp_handle_error(mon, err);
 }
migration/options.c +3 -3
index 45a95dc6da..e49d584a99 100644
@@ -1227,7 +1227,7 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)
     return true;
 }
 
-static void migrate_params_test_apply(MigrateSetParameters *params,
+static void migrate_params_test_apply(MigrationParameters *params,
                                       MigrationParameters *dest)
 {
     *dest = migrate_get_current()->parameters;
@@ -1350,7 +1350,7 @@ static void migrate_params_test_apply(MigrateSetParameters *params,
     }
 }
 
-static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
+static void migrate_params_apply(MigrationParameters *params, Error **errp)
 {
     MigrationState *s = migrate_get_current();
 
@@ -1479,7 +1479,7 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
     }
 }
 
-void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
+void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
 {
     MigrationParameters tmp;
 
qapi/migration.json +0 -0
index fa42d94810..080968993a 100644

qapi/migration.json line 918

Quoted 5 lines
qapi/migration.json +0 -2
@@ -914,202 +914,6 @@
            'zero-page-detection',
            'direct-io'] }
 
-##
-# @MigrateSetParameters:

Only use is argument type of migrate-set-parameters. You're replacing it by MigrationParameters there. Let's compare the deleted docs to their replacement. I'll quote replacement docs exactly where they differ.

Quoted 8 lines

# @MigrationParameters:
#
# Migration parameters. Optional members are optional when used with

   # an input command, otherwise mandatory.

Figuring out which commands are input commands is left to the reader. Why not simply "optional with migrate-set-parameters"?

Future patches include migrate and migrate-incoming. I can enumerate them if that's better.

Quoted 30 lines

However, it doesn't end there. The paragraph creates a problem with John Snow's "inliner", which I hope to merge later this year. Let me explain.

Generated command documentation normally looks like this:

Command migrate-set-capabilities (Since: 1.2)

Enable/Disable the following migration capabilities (like xbzrle)

Arguments:
* **capabilities** ("[""MigrationCapabilityStatus""]") -- json array of capability modifications to make

Except when we happen to use a named type for the arguments. This should be an implementation detail, and it is, except for generated documentation, which looks like

Command migrate-set-parameters (Since: 2.4)

Set various migration parameters.

Arguments:
* The members of "MigrationParameters".

The arguments are hidden behind a link. The "inliner" will show the them normally *always*, for better usability. It will not, however, inline the introductory paragraph above. I can explain why if necessary.

Quoted 6 lines

To compensate for the loss of that paragraph, we'll have to add suitable text to migrate-set-parameters's doc comment.

I think we could just as well do that *now*: scratch the paragraph here, add a suitable paragraph there.

Ok, no worries.

Quoted 26 lines
Quoted 11 lines
qapi/migration.json +0 -11
-#
-# @announce-initial: Initial delay (in milliseconds) before sending
-#     the first announce (Since 4.0)
-#
-# @announce-max: Maximum delay (in milliseconds) between packets in
-#     the announcement (Since 4.0)
-#
-# @announce-rounds: Number of self-announce packets sent after
-#     migration (Since 4.0)
-#
-# @announce-step: Increase in delay (in milliseconds) between

qapi/migration.json line 939

Quoted 10 lines
qapi/migration.json +0 -10
-#     subsequent packets in the announcement (Since 4.0)
-#
-# @throttle-trigger-threshold: The ratio of bytes_dirty_period and
-#     bytes_xfer_period to trigger throttling.  It is expressed as
-#     percentage.  The default value is 50.  (Since 5.0)
-#
-# @cpu-throttle-initial: Initial percentage of time guest cpus are
-#     throttled when migration auto-converge is activated.  The
-#     default value is 20.  (Since 2.7)
-#

# @cpu-throttle-initial: Initial percentage of time guest cpus are
# throttled when migration auto-converge is activated. (Since
# 2.7)

Quoted 2 lines

We no longer document the default value.

Rebase blunder, I believe the defaults were added recently.

Quoted 10 lines

qapi/migration.json line 942

Quoted 3 lines
qapi/migration.json +0 -3
-# @cpu-throttle-increment: throttle percentage increase each time
-#     auto-converge detects that migration is not making progress.
-#     The default value is 10.  (Since 2.7)

# @cpu-throttle-increment: throttle percentage increase each time
# auto-converge detects that migration is not making progress.
# (Since 2.7)

Likewise.

Here as well.

Quoted 61 lines
Quoted 47 lines
qapi/migration.json +0 -47
-#
-# @cpu-throttle-tailslow: Make CPU throttling slower at tail stage At
-#     the tail stage of throttling, the Guest is very sensitive to CPU
-#     percentage while the @cpu-throttle -increment is excessive
-#     usually at tail stage.  If this parameter is true, we will
-#     compute the ideal CPU percentage used by the Guest, which may
-#     exactly make the dirty rate match the dirty rate threshold.
-#     Then we will choose a smaller throttle increment between the one
-#     specified by @cpu-throttle-increment and the one generated by
-#     ideal CPU percentage.  Therefore, it is compatible to
-#     traditional throttling, meanwhile the throttle increment won't
-#     be excessive at tail stage.  The default value is false.  (Since
-#     5.1)
-#
-# @tls-creds: ID of the 'tls-creds' object that provides credentials
-#     for establishing a TLS connection over the migration data
-#     channel.  On the outgoing side of the migration, the credentials
-#     must be for a 'client' endpoint, while for the incoming side the
-#     credentials must be for a 'server' endpoint.  Setting this to a
-#     non-empty string enables TLS for all migrations.  An empty
-#     string means that QEMU will use plain text mode for migration,
-#     rather than TLS.  This is the default.  (Since 2.7)
-#
-# @tls-hostname: migration target's hostname for validating the
-#     server's x509 certificate identity.  If empty, QEMU will use the
-#     hostname from the migration URI, if any.  A non-empty value is
-#     required when using x509 based TLS credentials and the migration
-#     URI does not include a hostname, such as fd: or exec: based
-#     migration.  (Since 2.7)
-#
-#     Note: empty value works only since 2.9.
-#
-# @tls-authz: ID of the 'authz' object subclass that provides access
-#     control checking of the TLS x509 certificate distinguished name.
-#     This object is only resolved at time of use, so can be deleted
-#     and recreated on the fly while the migration server is active.
-#     If missing, it will default to denying access (Since 4.0)
-#
-# @max-bandwidth: maximum speed for migration, in bytes per second.
-#     (Since 2.8)
-#
-# @avail-switchover-bandwidth: to set the available bandwidth that
-#     migration can use during switchover phase.  NOTE!  This does not
-#     limit the bandwidth during switchover, but only for calculations
-#     when making decisions to switchover.  By default, this value is
-#     zero, which means QEMU will estimate the bandwidth
-#     automatically.  This can be set when the estimated value is not

qapi/migration.json line 999

Quoted 10 lines
qapi/migration.json +0 -10
-#     accurate, while the user is able to guarantee such bandwidth is
-#     available when switching over.  When specified correctly, this
-#     can make the switchover decision much more accurate.
-#     (Since 8.2)
-#
-# @downtime-limit: set maximum tolerated downtime for migration.
-#     maximum downtime in milliseconds (Since 2.8)
-#
-# @x-checkpoint-delay: The delay time (in ms) between two COLO
-#     checkpoints in periodic mode.  (Since 2.8)

# @x-checkpoint-delay: the delay time between two COLO checkpoints.
# (Since 2.8)

Quoted 2 lines

We no longer mention periodic mode.

I'll fix it.

Quoted 169 lines
Quoted 67 lines
qapi/migration.json +0 -67
-#
-# @multifd-channels: Number of channels used to migrate data in
-#     parallel.  This is the same number that the number of sockets
-#     used for migration.  The default value is 2 (since 4.0)
-#
-# @xbzrle-cache-size: cache size to be used by XBZRLE migration.  It
-#     needs to be a multiple of the target page size and a power of 2
-#     (Since 2.11)
-#
-# @max-postcopy-bandwidth: Background transfer bandwidth during
-#     postcopy.  Defaults to 0 (unlimited).  In bytes per second.
-#     (Since 3.0)
-#
-# @max-cpu-throttle: maximum cpu throttle percentage.  Defaults to 99.
-#     (Since 3.1)
-#
-# @multifd-compression: Which compression method to use.  Defaults to
-#     none.  (Since 5.0)
-#
-# @multifd-zlib-level: Set the compression level to be used in live
-#     migration, the compression level is an integer between 0 and 9,
-#     where 0 means no compression, 1 means the best compression
-#     speed, and 9 means best compression ratio which will consume
-#     more CPU.  Defaults to 1.  (Since 5.0)
-#
-# @multifd-qatzip-level: Set the compression level to be used in live
-#     migration. The level is an integer between 1 and 9, where 1 means
-#     the best compression speed, and 9 means the best compression
-#     ratio which will consume more CPU. Defaults to 1.  (Since 9.2)
-#
-# @multifd-zstd-level: Set the compression level to be used in live
-#     migration, the compression level is an integer between 0 and 20,
-#     where 0 means no compression, 1 means the best compression
-#     speed, and 20 means best compression ratio which will consume
-#     more CPU.  Defaults to 1.  (Since 5.0)
-#
-# @block-bitmap-mapping: Maps block nodes and bitmaps on them to
-#     aliases for the purpose of dirty bitmap migration.  Such aliases
-#     may for example be the corresponding names on the opposite site.
-#     The mapping must be one-to-one, but not necessarily complete: On
-#     the source, unmapped bitmaps and all bitmaps on unmapped nodes
-#     will be ignored.  On the destination, encountering an unmapped
-#     alias in the incoming migration stream will result in a report,
-#     and all further bitmap migration data will then be discarded.
-#     Note that the destination does not know about bitmaps it does
-#     not receive, so there is no limitation or requirement regarding
-#     the number of bitmaps received, or how they are named, or on
-#     which nodes they are placed.  By default (when this parameter
-#     has never been set), bitmap names are mapped to themselves.
-#     Nodes are mapped to their block device name if there is one, and
-#     to their node name otherwise.  (Since 5.2)
-#
-# @x-vcpu-dirty-limit-period: Periodic time (in milliseconds) of dirty
-#     limit during live migration.  Should be in the range 1 to
-#     1000ms.  Defaults to 1000ms.  (Since 8.1)
-#
-# @vcpu-dirty-limit: Dirtyrate limit (MB/s) during live migration.
-#     Defaults to 1.  (Since 8.1)
-#
-# @mode: Migration mode.  See description in @MigMode.  Default is
-#     'normal'.  (Since 8.2)
-#
-# @zero-page-detection: Whether and how to detect zero pages.
-#     See description in @ZeroPageDetection.  Default is 'multifd'.
-#     (since 9.0)
-#
-# @direct-io: Open migration files with O_DIRECT when possible.  This

qapi/migration.json line 1076

Quoted 10 lines
qapi/migration.json +0 -10
-#     only has effect if the @mapped-ram capability is enabled.
-#     (Since 9.1)
-#
-# Features:
-#
-# @unstable: Members @x-checkpoint-delay and
-#     @x-vcpu-dirty-limit-period are experimental.
-#
-# TODO: either fuse back into MigrationParameters, or make
-#     MigrationParameters members mandatory

The TODO is gone. Makes sense.

Quoted 89 lines
qapi/migration.json +15 -46
-#
-# Since: 2.4
-##
-{ 'struct': 'MigrateSetParameters',
-  'data': { '*announce-initial': 'size',
-            '*announce-max': 'size',
-            '*announce-rounds': 'size',
-            '*announce-step': 'size',
-            '*throttle-trigger-threshold': 'uint8',
-            '*cpu-throttle-initial': 'uint8',
-            '*cpu-throttle-increment': 'uint8',
-            '*cpu-throttle-tailslow': 'bool',
-            '*tls-creds': 'StrOrNull',
-            '*tls-hostname': 'StrOrNull',
-            '*tls-authz': 'StrOrNull',
-            '*max-bandwidth': 'size',
-            '*avail-switchover-bandwidth': 'size',
-            '*downtime-limit': 'uint64',
-            '*x-checkpoint-delay': { 'type': 'uint32',
-                                     'features': [ 'unstable' ] },
-            '*multifd-channels': 'uint8',
-            '*xbzrle-cache-size': 'size',
-            '*max-postcopy-bandwidth': 'size',
-            '*max-cpu-throttle': 'uint8',
-            '*multifd-compression': 'MultiFDCompression',
-            '*multifd-zlib-level': 'uint8',
-            '*multifd-qatzip-level': 'uint8',
-            '*multifd-zstd-level': 'uint8',
-            '*block-bitmap-mapping': [ 'BitmapMigrationNodeAlias' ],
-            '*x-vcpu-dirty-limit-period': { 'type': 'uint64',
-                                            'features': [ 'unstable' ] },
-            '*vcpu-dirty-limit': 'uint64',
-            '*mode': 'MigMode',
-            '*zero-page-detection': 'ZeroPageDetection',
-            '*direct-io': 'bool' } }
-
 ##
 # @migrate-set-parameters:
 #
@@ -1124,12 +928,13 @@
 #     <- { "return": {} }
 ##
 { 'command': 'migrate-set-parameters', 'boxed': true,
-  'data': 'MigrateSetParameters' }
+  'data': 'MigrationParameters' }
 
 ##
 # @MigrationParameters:
 #
-# The optional members aren't actually optional.
+# Migration parameters. Optional members are optional when used with
+# an input command, otherwise mandatory.
 #
 # @announce-initial: Initial delay (in milliseconds) before sending
 #     the first announce (Since 4.0)
@@ -1172,21 +977,25 @@
 #     for establishing a TLS connection over the migration data
 #     channel.  On the outgoing side of the migration, the credentials
 #     must be for a 'client' endpoint, while for the incoming side the
-#     credentials must be for a 'server' endpoint.  An empty string
-#     means that QEMU will use plain text mode for migration, rather
-#     than TLS.  (Since 2.7)
-#
-#     Note: 2.8 omits empty @tls-creds instead.
+#     credentials must be for a 'server' endpoint.  Setting this to a
+#     non-empty string enables TLS for all migrations.  An empty
+#     string means that QEMU will use plain text mode for migration,
+#     rather than TLS.  This is the default.  (Since 2.7)
 #
 # @tls-hostname: migration target's hostname for validating the
 #     server's x509 certificate identity.  If empty, QEMU will use the
-#     hostname from the migration URI, if any.  (Since 2.7)
+#     hostname from the migration URI, if any.  A non-empty value is
+#     required when using x509 based TLS credentials and the migration
+#     URI does not include a hostname, such as fd: or exec: based
+#     migration.  (Since 2.7)
 #
-#     Note: 2.8 omits empty @tls-hostname instead.
+#     Note: empty value works only since 2.9.
 #
 # @tls-authz: ID of the 'authz' object subclass that provides access
 #     control checking of the TLS x509 certificate distinguished name.
-#     (Since 4.0)
+#     This object is only resolved at time of use, so can be deleted
+#     and recreated on the fly while the migration server is active.
+#     If missing, it will default to denying access (Since 4.0)
 #
 # @max-bandwidth: maximum speed for migration, in bytes per second.
 #     (Since 2.8)
#16 lore raw

Re: [PATCH 02/21] migration: Remove MigrateSetParameters

Quoted 96 lines · Fabiano Rosas
Quoted 94 lines · Markus Armbruster
Quoted 76 lines · Fabiano Rosas

Now that the TLS options have been made the same between migrate-set-parameters and query-migrate-parameters, a single type can be used. Remove MigrateSetParameters.

The TLS options documentation from MigrationParameters were replaced with the ones from MigrateSetParameters which was more complete.

I'm choosing to somewhat ignore any ambiguity between "query" and "set" because other options' docs are already ambiguous in that regard.

---
 migration/migration-hmp-cmds.c |   4 +-
 migration/options.c            |   6 +-
 qapi/migration.json            | 221 +++------------------------------
 3 files changed, 20 insertions(+), 211 deletions(-)
migration/migration-hmp-cmds.c +2 -2
index bc8179c582..aacffdc532 100644
@@ -490,7 +490,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     const char *param = qdict_get_str(qdict, "parameter");
     const char *valuestr = qdict_get_str(qdict, "value");
     Visitor *v = string_input_visitor_new(valuestr);
-    MigrateSetParameters *p = g_new0(MigrateSetParameters, 1);
+    MigrationParameters *p = g_new0(MigrationParameters, 1);
     uint64_t valuebw = 0;
     uint64_t cache_size;
     Error *err = NULL;
@@ -656,7 +656,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
     qmp_migrate_set_parameters(p, &err);
 
  cleanup:
-    qapi_free_MigrateSetParameters(p);
+    qapi_free_MigrationParameters(p);
     visit_free(v);
     hmp_handle_error(mon, err);
 }
migration/options.c +3 -3
index 45a95dc6da..e49d584a99 100644
@@ -1227,7 +1227,7 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)
     return true;
 }
 
-static void migrate_params_test_apply(MigrateSetParameters *params,
+static void migrate_params_test_apply(MigrationParameters *params,
                                       MigrationParameters *dest)
 {
     *dest = migrate_get_current()->parameters;
@@ -1350,7 +1350,7 @@ static void migrate_params_test_apply(MigrateSetParameters *params,
     }
 }
 
-static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
+static void migrate_params_apply(MigrationParameters *params, Error **errp)
 {
     MigrationState *s = migrate_get_current();
 
@@ -1479,7 +1479,7 @@ static void migrate_params_apply(MigrateSetParameters *params, Error **errp)
     }
 }
 
-void qmp_migrate_set_parameters(MigrateSetParameters *params, Error **errp)
+void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
 {
     MigrationParameters tmp;
 
qapi/migration.json +0 -0
index fa42d94810..080968993a 100644

qapi/migration.json line 918

Quoted 5 lines
qapi/migration.json +0 -2
@@ -914,202 +914,6 @@
            'zero-page-detection',
            'direct-io'] }
 
-##
-# @MigrateSetParameters:

Only use is argument type of migrate-set-parameters. You're replacing it by MigrationParameters there. Let's compare the deleted docs to their replacement. I'll quote replacement docs exactly where they differ.

# @MigrationParameters:
#
# Migration parameters. Optional members are optional when used with

   # an input command, otherwise mandatory.
Quoted 6 lines
Quoted 3 lines

Figuring out which commands are input commands is left to the reader. Why not simply "optional with migrate-set-parameters"?

Future patches include migrate and migrate-incoming. I can enumerate them if that's better.

Not necessary if you move the note to commands as discussed below.

Quoted 38 lines
Quoted 30 lines

However, it doesn't end there. The paragraph creates a problem with John Snow's "inliner", which I hope to merge later this year. Let me explain.

Generated command documentation normally looks like this:

Command migrate-set-capabilities (Since: 1.2)

Enable/Disable the following migration capabilities (like xbzrle)

Arguments:
* **capabilities** ("[""MigrationCapabilityStatus""]") -- json array of capability modifications to make

Except when we happen to use a named type for the arguments. This should be an implementation detail, and it is, except for generated documentation, which looks like

Command migrate-set-parameters (Since: 2.4)

Set various migration parameters.

Arguments:
* The members of "MigrationParameters".

The arguments are hidden behind a link. The "inliner" will show the them normally *always*, for better usability. It will not, however, inline the introductory paragraph above. I can explain why if necessary.

Quoted 6 lines

To compensate for the loss of that paragraph, we'll have to add suitable text to migrate-set-parameters's doc comment.

I think we could just as well do that *now*: scratch the paragraph here, add a suitable paragraph there.

Ok, no worries.

[...]

#17 lore raw

PATCH 3/21 qapi/migration: Don't document MigrationParameter

In reply to Fabiano Rosas

The MigrationParameter (singular) enumeration is not part of the migration QMP API, it's only used for nicely converting HMP strings into MigrationParameters (plural) members and for providing readline completion.

Documenting this enum only serves to duplicate documentation between MigrationParameter and MigrationParameters.

Add an exception to QAPIs pragma.json and stop documenting it.

---
 qapi/migration.json | 152 +-------------------------------------------
 qapi/pragma.json    |   3 +-
 2 files changed, 3 insertions(+), 152 deletions(-)
qapi/migration.json +1 -151
index 080968993a..452e6dedaa 100644
@@ -734,157 +734,7 @@
 ##
 # @MigrationParameter:
 #
-# Migration parameters enumeration
-#
-# @announce-initial: Initial delay (in milliseconds) before sending
-#     the first announce (Since 4.0)
-#
-# @announce-max: Maximum delay (in milliseconds) between packets in
-#     the announcement (Since 4.0)
-#
-# @announce-rounds: Number of self-announce packets sent after
-#     migration (Since 4.0)
-#
-# @announce-step: Increase in delay (in milliseconds) between
-#     subsequent packets in the announcement (Since 4.0)
-#
-# @throttle-trigger-threshold: The ratio of bytes_dirty_period and
-#     bytes_xfer_period to trigger throttling.  It is expressed as
-#     percentage.  The default value is 50.  (Since 5.0)
-#
-# @cpu-throttle-initial: Initial percentage of time guest cpus are
-#     throttled when migration auto-converge is activated.  The
-#     default value is 20.  (Since 2.7)
-#
-# @cpu-throttle-increment: throttle percentage increase each time
-#     auto-converge detects that migration is not making progress.
-#     The default value is 10.  (Since 2.7)
-#
-# @cpu-throttle-tailslow: Make CPU throttling slower at tail stage At
-#     the tail stage of throttling, the Guest is very sensitive to CPU
-#     percentage while the @cpu-throttle -increment is excessive
-#     usually at tail stage.  If this parameter is true, we will
-#     compute the ideal CPU percentage used by the Guest, which may
-#     exactly make the dirty rate match the dirty rate threshold.
-#     Then we will choose a smaller throttle increment between the one
-#     specified by @cpu-throttle-increment and the one generated by
-#     ideal CPU percentage.  Therefore, it is compatible to
-#     traditional throttling, meanwhile the throttle increment won't
-#     be excessive at tail stage.  The default value is false.  (Since
-#     5.1)
-#
-# @tls-creds: ID of the 'tls-creds' object that provides credentials
-#     for establishing a TLS connection over the migration data
-#     channel.  On the outgoing side of the migration, the credentials
-#     must be for a 'client' endpoint, while for the incoming side the
-#     credentials must be for a 'server' endpoint.  Setting this to a
-#     non-empty string enables TLS for all migrations.  An empty
-#     string means that QEMU will use plain text mode for migration,
-#     rather than TLS.  (Since 2.7)
-#
-# @tls-hostname: migration target's hostname for validating the
-#     server's x509 certificate identity.  If empty, QEMU will use the
-#     hostname from the migration URI, if any.  A non-empty value is
-#     required when using x509 based TLS credentials and the migration
-#     URI does not include a hostname, such as fd: or exec: based
-#     migration.  (Since 2.7)
-#
-#     Note: empty value works only since 2.9.
-#
-# @tls-authz: ID of the 'authz' object subclass that provides access
-#     control checking of the TLS x509 certificate distinguished name.
-#     This object is only resolved at time of use, so can be deleted
-#     and recreated on the fly while the migration server is active.
-#     If missing, it will default to denying access (Since 4.0)
-#
-# @max-bandwidth: maximum speed for migration, in bytes per second.
-#     (Since 2.8)
-#
-# @avail-switchover-bandwidth: to set the available bandwidth that
-#     migration can use during switchover phase.  NOTE!  This does not
-#     limit the bandwidth during switchover, but only for calculations
-#     when making decisions to switchover.  By default, this value is
-#     zero, which means QEMU will estimate the bandwidth
-#     automatically.  This can be set when the estimated value is not
-#     accurate, while the user is able to guarantee such bandwidth is
-#     available when switching over.  When specified correctly, this
-#     can make the switchover decision much more accurate.
-#     (Since 8.2)
-#
-# @downtime-limit: set maximum tolerated downtime for migration.
-#     maximum downtime in milliseconds (Since 2.8)
-#
-# @x-checkpoint-delay: The delay time (in ms) between two COLO
-#     checkpoints in periodic mode.  (Since 2.8)
-#
-# @multifd-channels: Number of channels used to migrate data in
-#     parallel.  This is the same number that the number of sockets
-#     used for migration.  The default value is 2 (since 4.0)
-#
-# @xbzrle-cache-size: cache size to be used by XBZRLE migration.  It
-#     needs to be a multiple of the target page size and a power of 2
-#     (Since 2.11)
-#
-# @max-postcopy-bandwidth: Background transfer bandwidth during
-#     postcopy.  Defaults to 0 (unlimited).  In bytes per second.
-#     (Since 3.0)
-#
-# @max-cpu-throttle: maximum cpu throttle percentage.  Defaults to 99.
-#     (Since 3.1)
-#
-# @multifd-compression: Which compression method to use.  Defaults to
-#     none.  (Since 5.0)
-#
-# @multifd-zlib-level: Set the compression level to be used in live
-#     migration, the compression level is an integer between 0 and 9,
-#     where 0 means no compression, 1 means the best compression
-#     speed, and 9 means best compression ratio which will consume
-#     more CPU.  Defaults to 1.  (Since 5.0)
-#
-# @multifd-qatzip-level: Set the compression level to be used in live
-#     migration. The level is an integer between 1 and 9, where 1 means
-#     the best compression speed, and 9 means the best compression
-#     ratio which will consume more CPU. Defaults to 1.  (Since 9.2)
-#
-# @multifd-zstd-level: Set the compression level to be used in live
-#     migration, the compression level is an integer between 0 and 20,
-#     where 0 means no compression, 1 means the best compression
-#     speed, and 20 means best compression ratio which will consume
-#     more CPU.  Defaults to 1.  (Since 5.0)
-#
-# @block-bitmap-mapping: Maps block nodes and bitmaps on them to
-#     aliases for the purpose of dirty bitmap migration.  Such aliases
-#     may for example be the corresponding names on the opposite site.
-#     The mapping must be one-to-one, but not necessarily complete: On
-#     the source, unmapped bitmaps and all bitmaps on unmapped nodes
-#     will be ignored.  On the destination, encountering an unmapped
-#     alias in the incoming migration stream will result in a report,
-#     and all further bitmap migration data will then be discarded.
-#     Note that the destination does not know about bitmaps it does
-#     not receive, so there is no limitation or requirement regarding
-#     the number of bitmaps received, or how they are named, or on
-#     which nodes they are placed.  By default (when this parameter
-#     has never been set), bitmap names are mapped to themselves.
-#     Nodes are mapped to their block device name if there is one, and
-#     to their node name otherwise.  (Since 5.2)
-#
-# @x-vcpu-dirty-limit-period: Periodic time (in milliseconds) of dirty
-#     limit during live migration.  Should be in the range 1 to
-#     1000ms.  Defaults to 1000ms.  (Since 8.1)
-#
-# @vcpu-dirty-limit: Dirtyrate limit (MB/s) during live migration.
-#     Defaults to 1.  (Since 8.1)
-#
-# @mode: Migration mode.  See description in @MigMode.  Default is
-#     'normal'.  (Since 8.2)
-#
-# @zero-page-detection: Whether and how to detect zero pages.
-#     See description in @ZeroPageDetection.  Default is 'multifd'.
-#     (since 9.0)
-#
-# @direct-io: Open migration files with O_DIRECT when possible.  This
-#     only has effect if the @mapped-ram capability is enabled.
-#     (Since 9.1)
+# Migration parameters enumeration. See @MigrationParameters for more info.
 #
 # Features:
 #
qapi/pragma.json +2 -1
index 023a2ef7bc..58133907b6 100644
@@ -76,7 +76,8 @@
         'X86CPURegister32',
         'XDbgBlockGraph',
         'YankInstanceType',
-        'blockdev-reopen' ],
+        'blockdev-reopen',
+        'MigrationParameter'],
     # Externally visible types whose member names may use uppercase
     'member-name-exceptions': [     # visible in:
         'ACPISlotType',             # query-acpi-ospm-status
Signature · 1 line
2.35.3
Acked-by on v1 3/21
#18 lore raw

Re: [PATCH 03/21] qapi/migration: Don't document MigrationParameter

Quoted 11 lines · Fabiano Rosas

The MigrationParameter (singular) enumeration is not part of the migration QMP API, it's only used for nicely converting HMP strings into MigrationParameters (plural) members and for providing readline completion.

Documenting this enum only serves to duplicate documentation between MigrationParameter and MigrationParameters.

Add an exception to QAPIs pragma.json and stop documenting it.

Signature · 1 line
Peter Xu
#19 lore raw

Re: [PATCH 03/21] qapi/migration: Don't document MigrationParameter

In reply to Fabiano Rosas
Quoted 30 lines · Fabiano Rosas

The MigrationParameter (singular) enumeration is not part of the migration QMP API, it's only used for nicely converting HMP strings into MigrationParameters (plural) members and for providing readline completion.

Documenting this enum only serves to duplicate documentation between MigrationParameter and MigrationParameters.

Add an exception to QAPIs pragma.json and stop documenting it.

---
 qapi/migration.json | 152 +-------------------------------------------
 qapi/pragma.json    |   3 +-
 2 files changed, 3 insertions(+), 152 deletions(-)
qapi/migration.json +0 -4
index 080968993a..452e6dedaa 100644
@@ -734,157 +734,7 @@
 ##
 # @MigrationParameter:
 #
-# Migration parameters enumeration
-#
-# @announce-initial: Initial delay (in milliseconds) before sending
-#     the first announce (Since 4.0)

[...]

qapi/migration.json line 737

Quoted 4 lines
qapi/migration.json +1 -3
-# @direct-io: Open migration files with O_DIRECT when possible.  This
-#     only has effect if the @mapped-ram capability is enabled.
-#     (Since 9.1)
+# Migration parameters enumeration. See @MigrationParameters for more info.

Suggest something like

# The enumeration values mirror the members of MigrationParameters,

   # which see.

I could compare the deleted docs with MigrationParameters docs, but I doubt it's worthwhile: the type is only ever used internally. That it appears in the QEMU QMP Reference Manual anyway is a defect. There are quite a few more like it (list appended).

If I remember correctly, John Snow's doc generator work will fix this defect.

Quoted 8 lines

#
# Features:
#

qapi/pragma.json +0 -0
index 023a2ef7bc..58133907b6 100644

qapi/pragma.json line 80

Quoted 6 lines
qapi/pragma.json +2 -1
@@ -76,7 +76,8 @@
         'X86CPURegister32',
         'XDbgBlockGraph',
         'YankInstanceType',
-        'blockdev-reopen' ],
+        'blockdev-reopen',
+        'MigrationParameter'],

Please keep this list sorted alphabetically.

qapi/pragma.json line 83

Quoted 3 lines
qapi/pragma.json +0 -0
     # Externally visible types whose member names may use uppercase
     'member-name-exceptions': [     # visible in:
         'ACPISlotType',             # query-acpi-ospm-status

Types documented in the QEMU QMP Reference Manual that don't occur in QMP introspection:

AcpiTableOptions
BiosAtaTranslation
BlockChildInfo
BlockGraphInfo
BlockMeasureInfo
BootConfiguration
COLOMessage
CXLFMWProperties
CXLFixedMemoryWindowOptions
CacheLevelAndType
CompatPolicy
CompatPolicyInput
CompatPolicyOutput
CompressionStats
CpuTopologyLevel
DummyBlockCoreForceArrays
DummyForceArrays
DummyVirtioForceArrays
EndianMode
FailoverStatus
FloppyDriveType
GranuleMode
IOThreadVirtQueueMapping
ImageCheck
JobVerb
LostTickPolicy
MapEntry
MemorySizeConfiguration
MigrationParameter
MonitorMode
MonitorOptions
NbdServerOptions
NotifyVmexitOption
OffAutoPCIBAR
OnOffSplit
PCIELinkSpeed
PCIELinkWidth
QCryptoAkCipherAlgo
QCryptoAkCipherKeyType
QCryptoAkCipherOptions
QCryptoAkCipherOptionsRSA
QCryptoBlockInfo
QCryptoBlockOpenOptions
QCryptoRSAPaddingAlgo
QCryptodevBackendAlgoType
QapiErrorClass
SMPConfiguration
SgxEPC
SgxEPCProperties
SmbiosEntryPointType
SmpCacheProperties
SmpCachePropertiesWrapper
UefiVarStore
UefiVariable
VMAppleVirtioBlkVariant
X86CPUFeatureWordInfo
X86CPURegister32

#20 lore raw

Re: [PATCH 03/21] qapi/migration: Don't document MigrationParameter

Quoted 45 lines · Markus Armbruster
Quoted 30 lines · Fabiano Rosas

The MigrationParameter (singular) enumeration is not part of the migration QMP API, it's only used for nicely converting HMP strings into MigrationParameters (plural) members and for providing readline completion.

Documenting this enum only serves to duplicate documentation between MigrationParameter and MigrationParameters.

Add an exception to QAPIs pragma.json and stop documenting it.

---
 qapi/migration.json | 152 +-------------------------------------------
 qapi/pragma.json    |   3 +-
 2 files changed, 3 insertions(+), 152 deletions(-)
qapi/migration.json +0 -4
index 080968993a..452e6dedaa 100644
@@ -734,157 +734,7 @@
 ##
 # @MigrationParameter:
 #
-# Migration parameters enumeration
-#
-# @announce-initial: Initial delay (in milliseconds) before sending
-#     the first announce (Since 4.0)

[...]

qapi/migration.json line 737

Quoted 4 lines
qapi/migration.json +1 -3
-# @direct-io: Open migration files with O_DIRECT when possible.  This
-#     only has effect if the @mapped-ram capability is enabled.
-#     (Since 9.1)
+# Migration parameters enumeration. See @MigrationParameters for more info.

Suggest something like

# The enumeration values mirror the members of MigrationParameters,

   # which see.
Quoted 7 lines

I could compare the deleted docs with MigrationParameters docs, but I doubt it's worthwhile: the type is only ever used internally. That it appears in the QEMU QMP Reference Manual anyway is a defect. There are quite a few more like it (list appended).

If I remember correctly, John Snow's doc generator work will fix this defect.

Until then, this patch has a drawback: the manual now shows all the members as "Not documented" . Ugly and a bit embarrassing. Maybe even confusing.

[...]

#21 lore raw

Re: [PATCH 03/21] qapi/migration: Don't document MigrationParameter

Quoted 52 lines · Markus Armbruster
Quoted 50 lines · Markus Armbruster
Quoted 30 lines · Fabiano Rosas

The MigrationParameter (singular) enumeration is not part of the migration QMP API, it's only used for nicely converting HMP strings into MigrationParameters (plural) members and for providing readline completion.

Documenting this enum only serves to duplicate documentation between MigrationParameter and MigrationParameters.

Add an exception to QAPIs pragma.json and stop documenting it.

---
 qapi/migration.json | 152 +-------------------------------------------
 qapi/pragma.json    |   3 +-
 2 files changed, 3 insertions(+), 152 deletions(-)
qapi/migration.json +0 -4
index 080968993a..452e6dedaa 100644
@@ -734,157 +734,7 @@
 ##
 # @MigrationParameter:
 #
-# Migration parameters enumeration
-#
-# @announce-initial: Initial delay (in milliseconds) before sending
-#     the first announce (Since 4.0)

[...]

qapi/migration.json line 737

Quoted 4 lines
qapi/migration.json +1 -3
-# @direct-io: Open migration files with O_DIRECT when possible.  This
-#     only has effect if the @mapped-ram capability is enabled.
-#     (Since 9.1)
+# Migration parameters enumeration. See @MigrationParameters for more info.

Suggest something like

# The enumeration values mirror the members of MigrationParameters,

   # which see.

I could compare the deleted docs with MigrationParameters docs, but I doubt it's worthwhile: the type is only ever used internally. That it appears in the QEMU QMP Reference Manual anyway is a defect. There are quite a few more like it (list appended).

Quoted 7 lines
Quoted 2 lines

If I remember correctly, John Snow's doc generator work will fix this defect.

Until then, this patch has a drawback: the manual now shows all the members as "Not documented" . Ugly and a bit embarrassing. Maybe even confusing.

I expect the part about checking @MigrationParameters to be clear enough in explaining why the members are "Not documented".

I could live with the enum being documented still, but there's always churn when people touch migration.json and get something wrong due to the duplication. I'd rather not have it.

#22 lore raw

PATCH 4/21 migration: Run a post update routine after setting parameters

In reply to Fabiano Rosas

Some migration parameters are updated immediately once they are set via migrate-set-parameters. Move that work outside of migrate_params_apply() and leave that function with the single responsibility of setting s->parameters and not doing any side-effects.

---
 migration/options.c | 38 ++++++++++++++++++++++++++++----------
 migration/ram.c     |  2 +-
 2 files changed, 29 insertions(+), 11 deletions(-)
migration/options.c +28 -10
index e49d584a99..f64e141394 100644
@@ -1039,6 +1039,31 @@ void migrate_params_init(MigrationParameters *params)
     params->has_direct_io = true;
 }
 
+static void migrate_post_update_params(MigrationParameters *new, Error **errp)
+{
+    MigrationState *s = migrate_get_current();
+
+    if (new->has_max_bandwidth) {
+        if (s->to_dst_file && !migration_in_postcopy()) {
+            migration_rate_set(new->max_bandwidth);
+        }
+    }
+
+    if (new->has_x_checkpoint_delay) {
+        colo_checkpoint_delay_set();
+    }
+
+    if (new->has_xbzrle_cache_size) {
+        xbzrle_cache_resize(new->xbzrle_cache_size, errp);
+    }
+
+    if (new->has_max_postcopy_bandwidth) {
+        if (s->to_dst_file && migration_in_postcopy()) {
+            migration_rate_set(new->max_postcopy_bandwidth);
+        }
+    }
+}
+
 /*
  * Check whether the parameters are valid. Error will be put into errp
  * (if provided). Return true if valid, otherwise false.
@@ -1350,7 +1375,7 @@ static void migrate_params_test_apply(MigrationParameters *params,
     }
 }
 
-static void migrate_params_apply(MigrationParameters *params, Error **errp)
+static void migrate_params_apply(MigrationParameters *params)
 {
     MigrationState *s = migrate_get_current();
 
@@ -1389,9 +1414,6 @@ static void migrate_params_apply(MigrationParameters *params, Error **errp)
 
     if (params->has_max_bandwidth) {
         s->parameters.max_bandwidth = params->max_bandwidth;
-        if (s->to_dst_file && !migration_in_postcopy()) {
-            migration_rate_set(s->parameters.max_bandwidth);
-        }
     }
 
     if (params->has_avail_switchover_bandwidth) {
@@ -1404,7 +1426,6 @@ static void migrate_params_apply(MigrationParameters *params, Error **errp)
 
     if (params->has_x_checkpoint_delay) {
         s->parameters.x_checkpoint_delay = params->x_checkpoint_delay;
-        colo_checkpoint_delay_set();
     }
 
     if (params->has_multifd_channels) {
@@ -1424,13 +1445,9 @@ static void migrate_params_apply(MigrationParameters *params, Error **errp)
     }
     if (params->has_xbzrle_cache_size) {
         s->parameters.xbzrle_cache_size = params->xbzrle_cache_size;
-        xbzrle_cache_resize(params->xbzrle_cache_size, errp);
     }
     if (params->has_max_postcopy_bandwidth) {
         s->parameters.max_postcopy_bandwidth = params->max_postcopy_bandwidth;
-        if (s->to_dst_file && migration_in_postcopy()) {
-            migration_rate_set(s->parameters.max_postcopy_bandwidth);
-        }
     }
     if (params->has_max_cpu_throttle) {
         s->parameters.max_cpu_throttle = params->max_cpu_throttle;
@@ -1486,7 +1503,8 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
     migrate_params_test_apply(params, &tmp);
 
     if (migrate_params_check(&tmp, errp)) {
-        migrate_params_apply(params, errp);
+        migrate_params_apply(params);
+        migrate_post_update_params(params, errp);
     }
 
     migrate_tls_opts_free(&tmp);
migration/ram.c +1 -1
index d26dbd37c4..22e462bf72 100644
@@ -174,7 +174,7 @@ static void XBZRLE_cache_unlock(void)
 /**
  * xbzrle_cache_resize: resize the xbzrle cache
  *
- * This function is called from migrate_params_apply in main
+ * This function is called from migrate_post_update_config in main
  * thread, possibly while a migration is in progress.  A running
  * migration may be using the cache and might finish during this call,
  * hence changes to the cache are protected by XBZRLE.lock().
Signature · 1 line
2.35.3
#23 lore raw

PATCH 5/21 migration: Add a flag to track block-bitmap-mapping input

In reply to Fabiano Rosas

The QAPI converts an empty list on the block-bitmap-mapping input into a NULL BitmapMigrationNodeAliasList. The empty list is a valid input for the block-bitmap-mapping option, so commit 3cba22c9ad ("migration:
Fix block_bitmap_mapping migration") started using the s->parameters.has_block_bitmap_mapping field to tell when the user has passed in an empty list vs. when no list has been passed at all.

However, using the has_block_bitmap_mapping field of s->parameters is only possible because MigrationParameters has had its members made optional due to historical reasons.

In order to make improvements to the way configuration options are set for a migration, we'd like to reduce the usage of the has_* fields of the global configuration object (s->parameters).

Add a separate boolean to track the status of the block_bitmap_mapping option.

(this was verified to not regress iotest 300, which is the test that 3cba22c9ad refers to)

---
 migration/migration.h | 7 +++++++
 migration/options.c   | 6 +++---
 2 files changed, 10 insertions(+), 3 deletions(-)
migration/migration.h +7 -0
index d53f7cad84..ab797540b0 100644
@@ -510,6 +510,13 @@ struct MigrationState {
     bool rdma_migration;
 
     GSource *hup_source;
+
+    /*
+     * The block-bitmap-mapping option is allowed to be an emtpy list,
+     * therefore we need a way to know wheter the user has given
+     * anything as input.
+     */
+    bool has_block_bitmap_mapping;
 };
 
 void migrate_set_state(MigrationStatus *state, MigrationStatus old_state,
migration/options.c +3 -3
index f64e141394..cf77826204 100644
@@ -685,7 +685,7 @@ bool migrate_has_block_bitmap_mapping(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.has_block_bitmap_mapping;
+    return s->has_block_bitmap_mapping;
 }
 
 uint32_t migrate_checkpoint_delay(void)
@@ -989,7 +989,7 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->has_announce_step = true;
     params->announce_step = s->parameters.announce_step;
 
-    if (s->parameters.has_block_bitmap_mapping) {
+    if (s->has_block_bitmap_mapping) {
         params->has_block_bitmap_mapping = true;
         params->block_bitmap_mapping =
             QAPI_CLONE(BitmapMigrationNodeAliasList,
@@ -1469,7 +1469,7 @@ static void migrate_params_apply(MigrationParameters *params)
         qapi_free_BitmapMigrationNodeAliasList(
             s->parameters.block_bitmap_mapping);
 
-        s->parameters.has_block_bitmap_mapping = true;
+        s->has_block_bitmap_mapping = true;
         s->parameters.block_bitmap_mapping =
             QAPI_CLONE(BitmapMigrationNodeAliasList,
                        params->block_bitmap_mapping);
Signature · 1 line
2.35.3
#24 lore raw

Re: [PATCH 05/21] migration: Add a flag to track block-bitmap-mapping input

Quoted 79 lines · Fabiano Rosas

The QAPI converts an empty list on the block-bitmap-mapping input into a NULL BitmapMigrationNodeAliasList. The empty list is a valid input for the block-bitmap-mapping option, so commit 3cba22c9ad ("migration:
Fix block_bitmap_mapping migration") started using the s->parameters.has_block_bitmap_mapping field to tell when the user has passed in an empty list vs. when no list has been passed at all.

However, using the has_block_bitmap_mapping field of s->parameters is only possible because MigrationParameters has had its members made optional due to historical reasons.

In order to make improvements to the way configuration options are set for a migration, we'd like to reduce the usage of the has_* fields of the global configuration object (s->parameters).

Add a separate boolean to track the status of the block_bitmap_mapping option.

(this was verified to not regress iotest 300, which is the test that 3cba22c9ad refers to)

---
 migration/migration.h | 7 +++++++
 migration/options.c   | 6 +++---
 2 files changed, 10 insertions(+), 3 deletions(-)
migration/migration.h +7 -0
index d53f7cad84..ab797540b0 100644
@@ -510,6 +510,13 @@ struct MigrationState {
     bool rdma_migration;
 
     GSource *hup_source;
+
+    /*
+     * The block-bitmap-mapping option is allowed to be an emtpy list,
+     * therefore we need a way to know wheter the user has given
+     * anything as input.
+     */
+    bool has_block_bitmap_mapping;
 };
 
 void migrate_set_state(MigrationStatus *state, MigrationStatus old_state,
migration/options.c +3 -3
index f64e141394..cf77826204 100644
@@ -685,7 +685,7 @@ bool migrate_has_block_bitmap_mapping(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.has_block_bitmap_mapping;
+    return s->has_block_bitmap_mapping;
 }
 
 uint32_t migrate_checkpoint_delay(void)
@@ -989,7 +989,7 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->has_announce_step = true;
     params->announce_step = s->parameters.announce_step;
 
-    if (s->parameters.has_block_bitmap_mapping) {
+    if (s->has_block_bitmap_mapping) {
         params->has_block_bitmap_mapping = true;
         params->block_bitmap_mapping =
             QAPI_CLONE(BitmapMigrationNodeAliasList,
@@ -1469,7 +1469,7 @@ static void migrate_params_apply(MigrationParameters *params)
         qapi_free_BitmapMigrationNodeAliasList(
             s->parameters.block_bitmap_mapping);
 
-        s->parameters.has_block_bitmap_mapping = true;
+        s->has_block_bitmap_mapping = true;
         s->parameters.block_bitmap_mapping =
             QAPI_CLONE(BitmapMigrationNodeAliasList,
                        params->block_bitmap_mapping);
Signature · 1 line
2.35.3

This is definitely unfortunate, and I'm still scratching my head on understanding why it's necessary.

E.g. I tried to revert this patch manually and iotest 300 passed, with:

===8<===
From a952479805d8bdfe532ad4e0c0092f758991af08 Mon Sep 17 00:00:00 2001
From: Peter Xu <[email protected]>
Date: Fri, 6 Jun 2025 10:44:37 -0400
Subject: [PATCH] Revert "migration: Add a flag to track block-bitmap-mapping
input"

This reverts commit fd755a53c0e4ce9739d20d7cdd69400b2a37102c.

---
 migration/migration.h | 7 -------
 migration/options.c   | 4 ++--
 2 files changed, 2 insertions(+), 9 deletions(-)
migration/migration.h +0 -7
index 49761f4699..e710c421f8 100644
@@ -510,13 +510,6 @@ struct MigrationState {
     bool rdma_migration;
 
     GSource *hup_source;
-
-    /*
-     * The block-bitmap-mapping option is allowed to be an emtpy list,
-     * therefore we need a way to know wheter the user has given
-     * anything as input.
-     */
-    bool has_block_bitmap_mapping;
 };
 
 void migrate_set_state(MigrationStatus *state, MigrationStatus old_state,
migration/options.c +2 -2
index dd2288187d..e71a57764d 100644
@@ -765,7 +765,7 @@ bool migrate_has_block_bitmap_mapping(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->has_block_bitmap_mapping;
+    return s->parameters.has_block_bitmap_mapping;
 }
 
 uint32_t migrate_checkpoint_delay(void)
@@ -1376,7 +1376,7 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
      * params structure with the user input around.
      */
     if (params->has_block_bitmap_mapping) {
-        migrate_get_current()->has_block_bitmap_mapping = true;
+        migrate_get_current()->parameters.has_block_bitmap_mapping = true;
     }
 
     if (migrate_params_check(tmp, errp)) {
Signature · 40 lines
2.49.0
===8<===

I'm staring at commit 3cba22c9ad now, looks like what it wants to do is
making sure construct_alias_map() will be invoked even if the block bitmap
mapping is NULL itself.  But then right below the code, it has:

static int init_dirty_bitmap_migration(DBMSaveState *s, Error **errp)
{
    ...
    if (migrate_has_block_bitmap_mapping()) {
        alias_map = construct_alias_map(migrate_block_bitmap_mapping(), true,
                                        &error_abort);
    }
    ...
    if (!alias_map) {
    ...
    }
}

Looks like it's also ready for !alias_map anyway.  I'm definitely puzzled
by this code.

Even if so, IIUC the question can still be asked on whether we can always
assume has_block_bitmap_mapping to be always true, then here instead of:

    if (migrate_has_block_bitmap_mapping()) {
        alias_map = construct_alias_map(migrate_block_bitmap_mapping(), true,
                                        &error_abort);
    }

We do:

    alias_map = construct_alias_map(migrate_block_bitmap_mapping(), true,
                                    &error_abort);

After all it looks like construct_alias_map() takes NULL too..

-- 
Peter Xu
#25 lore raw

Re: [PATCH 05/21] migration: Add a flag to track block-bitmap-mapping input

Quoted 84 lines · Peter Xu
Quoted 79 lines · Fabiano Rosas

The QAPI converts an empty list on the block-bitmap-mapping input into a NULL BitmapMigrationNodeAliasList. The empty list is a valid input for the block-bitmap-mapping option, so commit 3cba22c9ad ("migration:
Fix block_bitmap_mapping migration") started using the s->parameters.has_block_bitmap_mapping field to tell when the user has passed in an empty list vs. when no list has been passed at all.

However, using the has_block_bitmap_mapping field of s->parameters is only possible because MigrationParameters has had its members made optional due to historical reasons.

In order to make improvements to the way configuration options are set for a migration, we'd like to reduce the usage of the has_* fields of the global configuration object (s->parameters).

Add a separate boolean to track the status of the block_bitmap_mapping option.

(this was verified to not regress iotest 300, which is the test that 3cba22c9ad refers to)

---
 migration/migration.h | 7 +++++++
 migration/options.c   | 6 +++---
 2 files changed, 10 insertions(+), 3 deletions(-)
migration/migration.h +7 -0
index d53f7cad84..ab797540b0 100644
@@ -510,6 +510,13 @@ struct MigrationState {
     bool rdma_migration;
 
     GSource *hup_source;
+
+    /*
+     * The block-bitmap-mapping option is allowed to be an emtpy list,
+     * therefore we need a way to know wheter the user has given
+     * anything as input.
+     */
+    bool has_block_bitmap_mapping;
 };
 
 void migrate_set_state(MigrationStatus *state, MigrationStatus old_state,
migration/options.c +3 -3
index f64e141394..cf77826204 100644
@@ -685,7 +685,7 @@ bool migrate_has_block_bitmap_mapping(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.has_block_bitmap_mapping;
+    return s->has_block_bitmap_mapping;
 }
 
 uint32_t migrate_checkpoint_delay(void)
@@ -989,7 +989,7 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->has_announce_step = true;
     params->announce_step = s->parameters.announce_step;
 
-    if (s->parameters.has_block_bitmap_mapping) {
+    if (s->has_block_bitmap_mapping) {
         params->has_block_bitmap_mapping = true;
         params->block_bitmap_mapping =
             QAPI_CLONE(BitmapMigrationNodeAliasList,
@@ -1469,7 +1469,7 @@ static void migrate_params_apply(MigrationParameters *params)
         qapi_free_BitmapMigrationNodeAliasList(
             s->parameters.block_bitmap_mapping);
 
-        s->parameters.has_block_bitmap_mapping = true;
+        s->has_block_bitmap_mapping = true;
         s->parameters.block_bitmap_mapping =
             QAPI_CLONE(BitmapMigrationNodeAliasList,
                        params->block_bitmap_mapping);
Signature · 1 line
2.35.3

This is definitely unfortunate, and I'm still scratching my head on understanding why it's necessary.

Quoted 1 line

E.g. I tried to revert this patch manually and iotest 300 passed, with:

This (mine) patch is not needed per-se. I want it so we stop using s->parameters.has_* altogether. If we think we need a flag to track whether the user has passed some value or not, then we add one to some migration specific state, say MigrationState.

This decouples the migration internal usage from the QAPI. Today we use MigrationParameters as defined by the QAPI, we might in the future want something else. And that something else might not come with has_* fields. So it's simple enough now to add this one flag to the MigrationState and be able to me completely independent from the QAPI-generated has_ fields.

Quoted 94 lines

===8<===
From a952479805d8bdfe532ad4e0c0092f758991af08 Mon Sep 17 00:00:00 2001
From: Peter Xu <[email protected]>
Date: Fri, 6 Jun 2025 10:44:37 -0400
Subject: [PATCH] Revert "migration: Add a flag to track block-bitmap-mapping
input"

This reverts commit fd755a53c0e4ce9739d20d7cdd69400b2a37102c.

---
 migration/migration.h | 7 -------
 migration/options.c   | 4 ++--
 2 files changed, 2 insertions(+), 9 deletions(-)
migration/migration.h +0 -7
index 49761f4699..e710c421f8 100644
@@ -510,13 +510,6 @@ struct MigrationState {
     bool rdma_migration;
 
     GSource *hup_source;
-
-    /*
-     * The block-bitmap-mapping option is allowed to be an emtpy list,
-     * therefore we need a way to know wheter the user has given
-     * anything as input.
-     */
-    bool has_block_bitmap_mapping;
 };
 
 void migrate_set_state(MigrationStatus *state, MigrationStatus old_state,
migration/options.c +2 -2
index dd2288187d..e71a57764d 100644
@@ -765,7 +765,7 @@ bool migrate_has_block_bitmap_mapping(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->has_block_bitmap_mapping;
+    return s->parameters.has_block_bitmap_mapping;
 }
 
 uint32_t migrate_checkpoint_delay(void)
@@ -1376,7 +1376,7 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
      * params structure with the user input around.
      */
     if (params->has_block_bitmap_mapping) {
-        migrate_get_current()->has_block_bitmap_mapping = true;
+        migrate_get_current()->parameters.has_block_bitmap_mapping = true;
     }
 
     if (migrate_params_check(tmp, errp)) {
Signature · 37 lines
2.49.0
===8<===

I'm staring at commit 3cba22c9ad now, looks like what it wants to do is
making sure construct_alias_map() will be invoked even if the block bitmap
mapping is NULL itself.  But then right below the code, it has:

static int init_dirty_bitmap_migration(DBMSaveState *s, Error **errp)
{
    ...
    if (migrate_has_block_bitmap_mapping()) {
        alias_map = construct_alias_map(migrate_block_bitmap_mapping(), true,
                                        &error_abort);
    }
    ...
    if (!alias_map) {
    ...
    }
}

Looks like it's also ready for !alias_map anyway.  I'm definitely puzzled
by this code.

Even if so, IIUC the question can still be asked on whether we can always
assume has_block_bitmap_mapping to be always true, then here instead of:

    if (migrate_has_block_bitmap_mapping()) {
        alias_map = construct_alias_map(migrate_block_bitmap_mapping(), true,
                                        &error_abort);
    }

We do:

    alias_map = construct_alias_map(migrate_block_bitmap_mapping(), true,
                                    &error_abort);

After all it looks like construct_alias_map() takes NULL too..

The point is that construct_alias_map always returns a hashtable. It might be empty if the user passes [], and that's ok according to 3cba22c9ad. So they needed some flag to say: "the user has tried to use block-bitmap-mapping".

I don't know why it needs to be like that and I honestly don't want to go into details of block migration just to be able to do a refactoring. All I want is that this code stop using s->parameters.has_* so we can do nice tricks with QAPI_CLONE later on and not bother about this.

I fully support we chase this, but keep in mind this patch (mine) is just gingerly moving the problem to the side so we can make progress with this series.

#26 lore raw

Re: [PATCH 05/21] migration: Add a flag to track block-bitmap-mapping input

Quoted 206 lines · Fabiano Rosas
Quoted 84 lines · Peter Xu
Quoted 79 lines · Fabiano Rosas

The QAPI converts an empty list on the block-bitmap-mapping input into a NULL BitmapMigrationNodeAliasList. The empty list is a valid input for the block-bitmap-mapping option, so commit 3cba22c9ad ("migration:
Fix block_bitmap_mapping migration") started using the s->parameters.has_block_bitmap_mapping field to tell when the user has passed in an empty list vs. when no list has been passed at all.

However, using the has_block_bitmap_mapping field of s->parameters is only possible because MigrationParameters has had its members made optional due to historical reasons.

In order to make improvements to the way configuration options are set for a migration, we'd like to reduce the usage of the has_* fields of the global configuration object (s->parameters).

Add a separate boolean to track the status of the block_bitmap_mapping option.

(this was verified to not regress iotest 300, which is the test that 3cba22c9ad refers to)

---
 migration/migration.h | 7 +++++++
 migration/options.c   | 6 +++---
 2 files changed, 10 insertions(+), 3 deletions(-)
migration/migration.h +7 -0
index d53f7cad84..ab797540b0 100644
@@ -510,6 +510,13 @@ struct MigrationState {
     bool rdma_migration;
 
     GSource *hup_source;
+
+    /*
+     * The block-bitmap-mapping option is allowed to be an emtpy list,
+     * therefore we need a way to know wheter the user has given
+     * anything as input.
+     */
+    bool has_block_bitmap_mapping;
 };
 
 void migrate_set_state(MigrationStatus *state, MigrationStatus old_state,
migration/options.c +3 -3
index f64e141394..cf77826204 100644
@@ -685,7 +685,7 @@ bool migrate_has_block_bitmap_mapping(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.has_block_bitmap_mapping;
+    return s->has_block_bitmap_mapping;
 }
 
 uint32_t migrate_checkpoint_delay(void)
@@ -989,7 +989,7 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->has_announce_step = true;
     params->announce_step = s->parameters.announce_step;
 
-    if (s->parameters.has_block_bitmap_mapping) {
+    if (s->has_block_bitmap_mapping) {
         params->has_block_bitmap_mapping = true;
         params->block_bitmap_mapping =
             QAPI_CLONE(BitmapMigrationNodeAliasList,
@@ -1469,7 +1469,7 @@ static void migrate_params_apply(MigrationParameters *params)
         qapi_free_BitmapMigrationNodeAliasList(
             s->parameters.block_bitmap_mapping);
 
-        s->parameters.has_block_bitmap_mapping = true;
+        s->has_block_bitmap_mapping = true;
         s->parameters.block_bitmap_mapping =
             QAPI_CLONE(BitmapMigrationNodeAliasList,
                        params->block_bitmap_mapping);
Signature · 1 line
2.35.3

This is definitely unfortunate, and I'm still scratching my head on understanding why it's necessary.

Quoted 1 line

E.g. I tried to revert this patch manually and iotest 300 passed, with:

This (mine) patch is not needed per-se. I want it so we stop using s->parameters.has_* altogether. If we think we need a flag to track whether the user has passed some value or not, then we add one to some migration specific state, say MigrationState.

This decouples the migration internal usage from the QAPI. Today we use MigrationParameters as defined by the QAPI, we might in the future want something else. And that something else might not come with has_* fields. So it's simple enough now to add this one flag to the MigrationState and be able to me completely independent from the QAPI-generated has_ fields.

Quoted 94 lines

===8<===
From a952479805d8bdfe532ad4e0c0092f758991af08 Mon Sep 17 00:00:00 2001
From: Peter Xu <[email protected]>
Date: Fri, 6 Jun 2025 10:44:37 -0400
Subject: [PATCH] Revert "migration: Add a flag to track block-bitmap-mapping
input"

This reverts commit fd755a53c0e4ce9739d20d7cdd69400b2a37102c.

---
 migration/migration.h | 7 -------
 migration/options.c   | 4 ++--
 2 files changed, 2 insertions(+), 9 deletions(-)
migration/migration.h +0 -7
index 49761f4699..e710c421f8 100644
@@ -510,13 +510,6 @@ struct MigrationState {
     bool rdma_migration;
 
     GSource *hup_source;
-
-    /*
-     * The block-bitmap-mapping option is allowed to be an emtpy list,
-     * therefore we need a way to know wheter the user has given
-     * anything as input.
-     */
-    bool has_block_bitmap_mapping;
 };
 
 void migrate_set_state(MigrationStatus *state, MigrationStatus old_state,
migration/options.c +2 -2
index dd2288187d..e71a57764d 100644
@@ -765,7 +765,7 @@ bool migrate_has_block_bitmap_mapping(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->has_block_bitmap_mapping;
+    return s->parameters.has_block_bitmap_mapping;
 }
 
 uint32_t migrate_checkpoint_delay(void)
@@ -1376,7 +1376,7 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
      * params structure with the user input around.
      */
     if (params->has_block_bitmap_mapping) {
-        migrate_get_current()->has_block_bitmap_mapping = true;
+        migrate_get_current()->parameters.has_block_bitmap_mapping = true;
     }
 
     if (migrate_params_check(tmp, errp)) {
Signature · 37 lines
2.49.0
===8<===

I'm staring at commit 3cba22c9ad now, looks like what it wants to do is
making sure construct_alias_map() will be invoked even if the block bitmap
mapping is NULL itself.  But then right below the code, it has:

static int init_dirty_bitmap_migration(DBMSaveState *s, Error **errp)
{
    ...
    if (migrate_has_block_bitmap_mapping()) {
        alias_map = construct_alias_map(migrate_block_bitmap_mapping(), true,
                                        &error_abort);
    }
    ...
    if (!alias_map) {
    ...
    }
}

Looks like it's also ready for !alias_map anyway.  I'm definitely puzzled
by this code.

Even if so, IIUC the question can still be asked on whether we can always
assume has_block_bitmap_mapping to be always true, then here instead of:

    if (migrate_has_block_bitmap_mapping()) {
        alias_map = construct_alias_map(migrate_block_bitmap_mapping(), true,
                                        &error_abort);
    }

We do:

    alias_map = construct_alias_map(migrate_block_bitmap_mapping(), true,
                                    &error_abort);

After all it looks like construct_alias_map() takes NULL too..

The point is that construct_alias_map always returns a hashtable. It might be empty if the user passes [], and that's ok according to 3cba22c9ad. So they needed some flag to say: "the user has tried to use block-bitmap-mapping".

I don't know why it needs to be like that and I honestly don't want to go into details of block migration just to be able to do a refactoring. All I want is that this code stop using s->parameters.has_* so we can do nice tricks with QAPI_CLONE later on and not bother about this.

Quoted 3 lines

I fully support we chase this, but keep in mind this patch (mine) is just gingerly moving the problem to the side so we can make progress with this series.

Yep that makes sense.

I'm thinking whether we have other better ways to move on without digging another hole for ourselves, e.g. make migrate_has_block_bitmap_mapping() to constantly return true? We can cc the block people on that patch, assuming we'd always better copy them when touching this part, including the current patch.

AFAIU, as long as it takes NULL for the real parameter it'll just work.

Then if all tests can pass and no one is unhappy, we go with that. We can always add this var back when someone reports a break, then we at least know this is needed and why.

That's what I'll do, but feel free to choose yours. In all cases, I'd still suggest we copy block developers on similar changes.

Signature · 1 line
Peter Xu
#27 lore raw

Re: [PATCH 05/21] migration: Add a flag to track block-bitmap-mapping input

Quoted 211 lines · Peter Xu
Quoted 206 lines · Fabiano Rosas
Quoted 84 lines · Peter Xu
Quoted 79 lines · Fabiano Rosas

The QAPI converts an empty list on the block-bitmap-mapping input into a NULL BitmapMigrationNodeAliasList. The empty list is a valid input for the block-bitmap-mapping option, so commit 3cba22c9ad ("migration:
Fix block_bitmap_mapping migration") started using the s->parameters.has_block_bitmap_mapping field to tell when the user has passed in an empty list vs. when no list has been passed at all.

However, using the has_block_bitmap_mapping field of s->parameters is only possible because MigrationParameters has had its members made optional due to historical reasons.

In order to make improvements to the way configuration options are set for a migration, we'd like to reduce the usage of the has_* fields of the global configuration object (s->parameters).

Add a separate boolean to track the status of the block_bitmap_mapping option.

(this was verified to not regress iotest 300, which is the test that 3cba22c9ad refers to)

---
 migration/migration.h | 7 +++++++
 migration/options.c   | 6 +++---
 2 files changed, 10 insertions(+), 3 deletions(-)
migration/migration.h +7 -0
index d53f7cad84..ab797540b0 100644
@@ -510,6 +510,13 @@ struct MigrationState {
     bool rdma_migration;
 
     GSource *hup_source;
+
+    /*
+     * The block-bitmap-mapping option is allowed to be an emtpy list,
+     * therefore we need a way to know wheter the user has given
+     * anything as input.
+     */
+    bool has_block_bitmap_mapping;
 };
 
 void migrate_set_state(MigrationStatus *state, MigrationStatus old_state,
migration/options.c +3 -3
index f64e141394..cf77826204 100644
@@ -685,7 +685,7 @@ bool migrate_has_block_bitmap_mapping(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->parameters.has_block_bitmap_mapping;
+    return s->has_block_bitmap_mapping;
 }
 
 uint32_t migrate_checkpoint_delay(void)
@@ -989,7 +989,7 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->has_announce_step = true;
     params->announce_step = s->parameters.announce_step;
 
-    if (s->parameters.has_block_bitmap_mapping) {
+    if (s->has_block_bitmap_mapping) {
         params->has_block_bitmap_mapping = true;
         params->block_bitmap_mapping =
             QAPI_CLONE(BitmapMigrationNodeAliasList,
@@ -1469,7 +1469,7 @@ static void migrate_params_apply(MigrationParameters *params)
         qapi_free_BitmapMigrationNodeAliasList(
             s->parameters.block_bitmap_mapping);
 
-        s->parameters.has_block_bitmap_mapping = true;
+        s->has_block_bitmap_mapping = true;
         s->parameters.block_bitmap_mapping =
             QAPI_CLONE(BitmapMigrationNodeAliasList,
                        params->block_bitmap_mapping);
Signature · 1 line
2.35.3

This is definitely unfortunate, and I'm still scratching my head on understanding why it's necessary.

Quoted 1 line

E.g. I tried to revert this patch manually and iotest 300 passed, with:

This (mine) patch is not needed per-se. I want it so we stop using s->parameters.has_* altogether. If we think we need a flag to track whether the user has passed some value or not, then we add one to some migration specific state, say MigrationState.

This decouples the migration internal usage from the QAPI. Today we use MigrationParameters as defined by the QAPI, we might in the future want something else. And that something else might not come with has_* fields. So it's simple enough now to add this one flag to the MigrationState and be able to me completely independent from the QAPI-generated has_ fields.

Quoted 94 lines

===8<===
From a952479805d8bdfe532ad4e0c0092f758991af08 Mon Sep 17 00:00:00 2001
From: Peter Xu <[email protected]>
Date: Fri, 6 Jun 2025 10:44:37 -0400
Subject: [PATCH] Revert "migration: Add a flag to track block-bitmap-mapping
input"

This reverts commit fd755a53c0e4ce9739d20d7cdd69400b2a37102c.

---
 migration/migration.h | 7 -------
 migration/options.c   | 4 ++--
 2 files changed, 2 insertions(+), 9 deletions(-)
migration/migration.h +0 -7
index 49761f4699..e710c421f8 100644
@@ -510,13 +510,6 @@ struct MigrationState {
     bool rdma_migration;
 
     GSource *hup_source;
-
-    /*
-     * The block-bitmap-mapping option is allowed to be an emtpy list,
-     * therefore we need a way to know wheter the user has given
-     * anything as input.
-     */
-    bool has_block_bitmap_mapping;
 };
 
 void migrate_set_state(MigrationStatus *state, MigrationStatus old_state,
migration/options.c +2 -2
index dd2288187d..e71a57764d 100644
@@ -765,7 +765,7 @@ bool migrate_has_block_bitmap_mapping(void)
 {
     MigrationState *s = migrate_get_current();
 
-    return s->has_block_bitmap_mapping;
+    return s->parameters.has_block_bitmap_mapping;
 }
 
 uint32_t migrate_checkpoint_delay(void)
@@ -1376,7 +1376,7 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
      * params structure with the user input around.
      */
     if (params->has_block_bitmap_mapping) {
-        migrate_get_current()->has_block_bitmap_mapping = true;
+        migrate_get_current()->parameters.has_block_bitmap_mapping = true;
     }
 
     if (migrate_params_check(tmp, errp)) {
Signature · 37 lines
2.49.0
===8<===

I'm staring at commit 3cba22c9ad now, looks like what it wants to do is
making sure construct_alias_map() will be invoked even if the block bitmap
mapping is NULL itself.  But then right below the code, it has:

static int init_dirty_bitmap_migration(DBMSaveState *s, Error **errp)
{
    ...
    if (migrate_has_block_bitmap_mapping()) {
        alias_map = construct_alias_map(migrate_block_bitmap_mapping(), true,
                                        &error_abort);
    }
    ...
    if (!alias_map) {
    ...
    }
}

Looks like it's also ready for !alias_map anyway.  I'm definitely puzzled
by this code.

Even if so, IIUC the question can still be asked on whether we can always
assume has_block_bitmap_mapping to be always true, then here instead of:

    if (migrate_has_block_bitmap_mapping()) {
        alias_map = construct_alias_map(migrate_block_bitmap_mapping(), true,
                                        &error_abort);
    }

We do:

    alias_map = construct_alias_map(migrate_block_bitmap_mapping(), true,
                                    &error_abort);

After all it looks like construct_alias_map() takes NULL too..

The point is that construct_alias_map always returns a hashtable. It might be empty if the user passes [], and that's ok according to 3cba22c9ad. So they needed some flag to say: "the user has tried to use block-bitmap-mapping".

I don't know why it needs to be like that and I honestly don't want to go into details of block migration just to be able to do a refactoring. All I want is that this code stop using s->parameters.has_* so we can do nice tricks with QAPI_CLONE later on and not bother about this.

Quoted 3 lines

I fully support we chase this, but keep in mind this patch (mine) is just gingerly moving the problem to the side so we can make progress with this series.

Quoted 5 lines

Yep that makes sense.

I'm thinking whether we have other better ways to move on without digging another hole for ourselves, e.g. make migrate_has_block_bitmap_mapping() to constantly return true?

Your concept of what it takes to dig a hole is quite different from mine.

Quoted 3 lines

We can cc the block people on that patch, assuming
we'd always better copy them when touching this part, including the current patch.

I think I messed up the get_maintainers usage.

Quoted 3 lines

AFAIU, as long as it takes NULL for the real parameter it'll just work.

But that's what 3cba22c9ad was fixing. I belive the !alias_map is the key, it'll be NULL if has_block_bitmap is false, no matter the actual value of the parameters.

Quoted 4 lines

Then if all tests can pass and no one is unhappy, we go with that. We can always add this var back when someone reports a break, then we at least know this is needed and why.

Ok, this part is a sticking point of the series indeed. I'll try to clear this up. Let's not make this another "TLS options" situation.

Quoted 2 lines

That's what I'll do, but feel free to choose yours. In all cases, I'd still suggest we copy block developers on similar changes.

#28 lore raw

PATCH 6/21 migration: Remove checks for s->parameters has_* fields

In reply to Fabiano Rosas

The migration parameters validation produces a temporary structure which is the merge of the current parameter values (s->parameters, MigrationParameters) with the new parameters set by the user (MigrateSetParameters).

When copying the values from s->parameters into the temporary structure, the has_* fields are copied along, but when merging the user-input values (MigrateSetParameters) they are not.

During migrate_params_check(), only the parameters that have the corresponding has_* field will be checked, so only the parameters that were initialized in migrate_params_init() will be validated.

This causes (almost) all of the migration parameters to be validated every time a parameter is set, regardless of which fields the user touched, but it also skips validation of any values that are not set in migrate_params_init().

It's not clear what was the intention of the original code, whether to validate all fields always, or only validate what the user input changed. Since the current situation is closer to the former option, make the choice of validating all parameters by removing the checks for the has_* fields when validating.

Note that bringing the user input into the temporary structure for validation still needs to look at the has_* fields, otherwise any parameters not set by the user (i.e. 0) would override the corresponding value in s->parameters.

---
 migration/migration.c |   2 -
 migration/options.c   | 104 ++++++++++++------------------------------
 2 files changed, 29 insertions(+), 77 deletions(-)
migration/migration.c +0 -2
index f65cb81b6d..45e15ffeb6 100644
@@ -4077,8 +4077,6 @@ static void migration_instance_init(Object *obj)
     qemu_sem_init(&ms->pause_sem, 0);
     qemu_mutex_init(&ms->error_mutex);
 
-    migrate_params_init(&ms->parameters);
-
     qemu_sem_init(&ms->postcopy_pause_sem, 0);
     qemu_sem_init(&ms->rp_state.rp_sem, 0);
     qemu_sem_init(&ms->rp_state.rp_pong_acks, 0);
migration/options.c +29 -75

229 lines not on this page · raw message

Signature · 1 line
2.35.3
Reviewed-by on v1 6/21
#29 lore raw

Re: [PATCH 06/21] migration: Remove checks for s->parameters has_* fields

Quoted 24 lines · Fabiano Rosas

The migration parameters validation produces a temporary structure which is the merge of the current parameter values (s->parameters, MigrationParameters) with the new parameters set by the user (MigrateSetParameters).

When copying the values from s->parameters into the temporary structure, the has_* fields are copied along, but when merging the user-input values (MigrateSetParameters) they are not.

During migrate_params_check(), only the parameters that have the corresponding has_* field will be checked, so only the parameters that were initialized in migrate_params_init() will be validated.

This causes (almost) all of the migration parameters to be validated every time a parameter is set, regardless of which fields the user touched, but it also skips validation of any values that are not set in migrate_params_init().

It's not clear what was the intention of the original code, whether to validate all fields always, or only validate what the user input changed. Since the current situation is closer to the former option, make the choice of validating all parameters by removing the checks for the has_* fields when validating.

Quoted 6 lines

Note that bringing the user input into the temporary structure for validation still needs to look at the has_* fields, otherwise any parameters not set by the user (i.e. 0) would override the corresponding value in s->parameters.

Signature · 1 line
Peter Xu
#30 lore raw

PATCH 7/21 migration: Set block_bitmap_mapping unconditionally in query-migrate-parameters

In reply to Fabiano Rosas

The response type of query-migrate-parameters is MigrationParameters, the members of which are marked as optional in migration.json. However, the design of query-migrate-parameters is that all members are to be non-optional.

The optionality is an attempt at compatibility with MigrateSetParameters, which needs it to allow migrate-set-parameters to be given only a subset of parameters.

To satisfy the design of query-migrate-parameters, the qmp_query_migrate_parameters function sets all (but one) has_* fields of MigrationParameters to true before returning. The block-bitmap-mapping parameter is instead set conditionally. This is incorrect.

Since block-bitmap-mapping is allowed to be passed as input by the user as an empty list, technically the empty list value output in query-migrate-parameters has always been valid for that parameter. Make the parameter non-optional like the rest of MigrationParameters.

---
 migration/migration-hmp-cmds.c | 36 ++++++++++++++++------------------
 migration/options.c            | 10 ++++------
 2 files changed, 21 insertions(+), 25 deletions(-)
migration/migration-hmp-cmds.c +17 -19
index aacffdc532..685c8ebd53 100644
@@ -240,6 +240,7 @@ void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
 void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
 {
     MigrationParameters *params;
+    const BitmapMigrationNodeAliasList *bmnal;
 
     params = qmp_query_migrate_parameters(NULL);
 
@@ -319,29 +320,26 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
             MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
                        params->tls_authz ? params->tls_authz->u.s : "");
 
-        if (params->has_block_bitmap_mapping) {
-            const BitmapMigrationNodeAliasList *bmnal;
+        assert(params->has_block_bitmap_mapping);
+        monitor_printf(mon, "%s:\n",
+                       MigrationParameter_str(
+                           MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING));
 
-            monitor_printf(mon, "%s:\n",
-                           MigrationParameter_str(
-                               MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING));
+        for (bmnal = params->block_bitmap_mapping;
+             bmnal;
+             bmnal = bmnal->next)
+        {
+            const BitmapMigrationNodeAlias *bmna = bmnal->value;
+            const BitmapMigrationBitmapAliasList *bmbal;
 
-            for (bmnal = params->block_bitmap_mapping;
-                 bmnal;
-                 bmnal = bmnal->next)
-            {
-                const BitmapMigrationNodeAlias *bmna = bmnal->value;
-                const BitmapMigrationBitmapAliasList *bmbal;
+            monitor_printf(mon, "  '%s' -> '%s'\n",
+                           bmna->node_name, bmna->alias);
 
-                monitor_printf(mon, "  '%s' -> '%s'\n",
-                               bmna->node_name, bmna->alias);
+            for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) {
+                const BitmapMigrationBitmapAlias *bmba = bmbal->value;
 
-                for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) {
-                    const BitmapMigrationBitmapAlias *bmba = bmbal->value;
-
-                    monitor_printf(mon, "    '%s' -> '%s'\n",
-                                   bmba->name, bmba->alias);
-                }
+                monitor_printf(mon, "    '%s' -> '%s'\n",
+                               bmba->name, bmba->alias);
             }
         }
 
migration/options.c +4 -6
index d4021bc520..190001f8ac 100644
@@ -989,12 +989,10 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     params->has_announce_step = true;
     params->announce_step = s->parameters.announce_step;
 
-    if (s->has_block_bitmap_mapping) {
-        params->has_block_bitmap_mapping = true;
-        params->block_bitmap_mapping =
-            QAPI_CLONE(BitmapMigrationNodeAliasList,
-                       s->parameters.block_bitmap_mapping);
-    }
+    params->has_block_bitmap_mapping = true;
+    params->block_bitmap_mapping =
+        QAPI_CLONE(BitmapMigrationNodeAliasList,
+                   s->parameters.block_bitmap_mapping);
 
     params->has_x_vcpu_dirty_limit_period = true;
     params->x_vcpu_dirty_limit_period = s->parameters.x_vcpu_dirty_limit_period;
Signature · 1 line
2.35.3
#31 lore raw

PATCH 8/21 migration: Do away with usage of QERR_INVALID_PARAMETER_VALUE

In reply to Fabiano Rosas

The QERR_INVALID_PARAMETER_VALUE macro is documented as not to be used in new code. Remove the usage from migration/options.c.

---
 migration/migration.c  |  3 +--
 migration/options.c    | 56 +++++++++++++++---------------------------
 migration/page_cache.c |  6 ++---
 migration/ram.c        |  3 +--
 4 files changed, 24 insertions(+), 44 deletions(-)
migration/migration.c +1 -2
index 45e15ffeb6..031a5f8ede 100644
@@ -2302,8 +2302,7 @@ static void qmp_migrate_finish(MigrationAddress *addr, bool resume_requested,
     } else if (addr->transport == MIGRATION_ADDRESS_TYPE_FILE) {
         file_start_outgoing_migration(s, &addr->u.file, &local_err);
     } else {
-        error_setg(&local_err, QERR_INVALID_PARAMETER_VALUE, "uri",
-                   "a valid migration protocol");
+        error_setg(&local_err, "uri is not a valid migration protocol");
         migrate_set_state(&s->state, MIGRATION_STATUS_SETUP,
                           MIGRATION_STATUS_FAILED);
     }
migration/options.c +20 -36

148 lines not on this page · raw message

migration/page_cache.c +2 -4
index 6d4f7a9bbc..650b15e48c 100644
@@ -45,15 +45,13 @@ PageCache *cache_init(uint64_t new_size, size_t page_size, Error **errp)
     PageCache *cache;
 
     if (new_size < page_size) {
-        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
-                   "is smaller than one target page size");
+        error_setg(errp, "cache size is smaller than target page size");
         return NULL;
     }
 
     /* round down to the nearest power of 2 */
     if (!is_power_of_2(num_pages)) {
-        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
-                   "is not a power of two number of pages");
+        error_setg(errp, "number of pages is not a power of two");
         return NULL;
     }
 
migration/ram.c +1 -2
index 22e462bf72..028358ef0d 100644
@@ -191,8 +191,7 @@ int xbzrle_cache_resize(uint64_t new_size, Error **errp)
 
     /* Check for truncation */
     if (new_size != (size_t)new_size) {
-        error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "cache size",
-                   "exceeding address space");
+        error_setg(errp, "xbzrle cache size integer overflow");
         return -1;
     }
 
Signature · 1 line
2.35.3
Reviewed-by on v1 8/21
#32 lore raw

Re: [PATCH 08/21] migration: Do away with usage of QERR_INVALID_PARAMETER_VALUE

Quoted 4 lines · Fabiano Rosas

The QERR_INVALID_PARAMETER_VALUE macro is documented as not to be used in new code. Remove the usage from migration/options.c.

Signature · 1 line
Peter Xu
#33 lore raw

PATCH 9/21 migration: Extract code to mark all parameters as present

In reply to Fabiano Rosas

MigrationParameters needs to have all of its has_* fields marked as true when used as the return of query_migrate_parameters because the corresponding QMP command has all of its members non-optional by design, despite them being marked as optional in migration.json.

Extract this code into a function and make it assert if any field is missing. With this we ensure future changes will not inadvertently leave any parameters missing.

Also assert that s->parameters _does not_ have any of its has_* fields set. This structure is internal to the migration code and it should not rely on the QAPI-generate has_* fields. We might want to store migration parameters differently in the future.

---
 migration/options.c | 74 ++++++++++++++++++++++++++++-----------------
 1 file changed, 46 insertions(+), 28 deletions(-)
migration/options.c +46 -28
index e2e3ab717f..dd62e726cb 100644
@@ -936,6 +936,40 @@ static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)
     }
 }
 
+static void migrate_mark_all_params_present(MigrationParameters *p)
+{
+    int len, n_str_args = 3; /* tls-creds, tls-hostname, tls-authz */
+    bool *has_fields[] = {
+        &p->has_throttle_trigger_threshold, &p->has_cpu_throttle_initial,
+        &p->has_cpu_throttle_increment, &p->has_cpu_throttle_tailslow,
+        &p->has_max_bandwidth, &p->has_avail_switchover_bandwidth,
+        &p->has_downtime_limit, &p->has_x_checkpoint_delay,
+        &p->has_multifd_channels, &p->has_multifd_compression,
+        &p->has_multifd_zlib_level, &p->has_multifd_qatzip_level,
+        &p->has_multifd_zstd_level, &p->has_xbzrle_cache_size,
+        &p->has_max_postcopy_bandwidth, &p->has_max_cpu_throttle,
+        &p->has_announce_initial, &p->has_announce_max, &p->has_announce_rounds,
+        &p->has_announce_step, &p->has_block_bitmap_mapping,
+        &p->has_x_vcpu_dirty_limit_period, &p->has_vcpu_dirty_limit,
+        &p->has_mode, &p->has_zero_page_detection, &p->has_direct_io,
+    };
+
+    /*
+     * The has_* fields of MigrationParameters are used by QAPI to
+     * inform whether an optional struct member is present. Keep this
+     * decoupled from the internal usage (not QAPI) by leaving the
+     * has_* fields of s->parameters unused.
+     */
+    assert(p != &(migrate_get_current())->parameters);
+
+    len = ARRAY_SIZE(has_fields);
+    assert(len + n_str_args == MIGRATION_PARAMETER__MAX);
+
+    for (int i = 0; i < len; i++) {
+        *has_fields[i] = true;
+    }
+}
+
 MigrationParameters *qmp_query_migrate_parameters(Error **errp)
 {
     MigrationParameters *params;
@@ -943,68 +977,52 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
 
     /* TODO use QAPI_CLONE() instead of duplicating it inline */
     params = g_malloc0(sizeof(*params));
-    params->has_throttle_trigger_threshold = true;
+
     params->throttle_trigger_threshold = s->parameters.throttle_trigger_threshold;
-    params->has_cpu_throttle_initial = true;
     params->cpu_throttle_initial = s->parameters.cpu_throttle_initial;
-    params->has_cpu_throttle_increment = true;
     params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
-    params->has_cpu_throttle_tailslow = true;
     params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
 
     tls_option_set_str(&params->tls_creds, s->parameters.tls_creds);
     tls_option_set_str(&params->tls_hostname, s->parameters.tls_hostname);
     tls_option_set_str(&params->tls_authz, s->parameters.tls_authz);
 
-    params->has_max_bandwidth = true;
     params->max_bandwidth = s->parameters.max_bandwidth;
-    params->has_avail_switchover_bandwidth = true;
     params->avail_switchover_bandwidth = s->parameters.avail_switchover_bandwidth;
-    params->has_downtime_limit = true;
     params->downtime_limit = s->parameters.downtime_limit;
-    params->has_x_checkpoint_delay = true;
     params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
-    params->has_multifd_channels = true;
     params->multifd_channels = s->parameters.multifd_channels;
-    params->has_multifd_compression = true;
     params->multifd_compression = s->parameters.multifd_compression;
-    params->has_multifd_zlib_level = true;
     params->multifd_zlib_level = s->parameters.multifd_zlib_level;
-    params->has_multifd_qatzip_level = true;
     params->multifd_qatzip_level = s->parameters.multifd_qatzip_level;
-    params->has_multifd_zstd_level = true;
     params->multifd_zstd_level = s->parameters.multifd_zstd_level;
-    params->has_xbzrle_cache_size = true;
     params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
-    params->has_max_postcopy_bandwidth = true;
     params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth;
-    params->has_max_cpu_throttle = true;
     params->max_cpu_throttle = s->parameters.max_cpu_throttle;
-    params->has_announce_initial = true;
     params->announce_initial = s->parameters.announce_initial;
-    params->has_announce_max = true;
     params->announce_max = s->parameters.announce_max;
-    params->has_announce_rounds = true;
     params->announce_rounds = s->parameters.announce_rounds;
-    params->has_announce_step = true;
     params->announce_step = s->parameters.announce_step;
-
-    params->has_block_bitmap_mapping = true;
     params->block_bitmap_mapping =
         QAPI_CLONE(BitmapMigrationNodeAliasList,
                    s->parameters.block_bitmap_mapping);
-
-    params->has_x_vcpu_dirty_limit_period = true;
     params->x_vcpu_dirty_limit_period = s->parameters.x_vcpu_dirty_limit_period;
-    params->has_vcpu_dirty_limit = true;
     params->vcpu_dirty_limit = s->parameters.vcpu_dirty_limit;
-    params->has_mode = true;
     params->mode = s->parameters.mode;
-    params->has_zero_page_detection = true;
     params->zero_page_detection = s->parameters.zero_page_detection;
-    params->has_direct_io = true;
     params->direct_io = s->parameters.direct_io;
 
+    /*
+     * query-migrate-parameters expects all members of
+     * MigrationParameters to be present, but we cannot mark them
+     * non-optional in QAPI because the structure is also used for
+     * migrate-set-parameters, which needs the optionality. Force all
+     * parameters to be seen as present now. Note that this depends on
+     * some form of default being set for every member of
+     * MigrationParameters, currently done during qdev init using
+     * migration_properties defined in this file.
+     */
+    migrate_mark_all_params_present(params);
     return params;
 }
 
Signature · 1 line
2.35.3
#34 lore raw

Re: [PATCH 09/21] migration: Extract code to mark all parameters as present

Quoted 24 lines · Fabiano Rosas

MigrationParameters needs to have all of its has_* fields marked as true when used as the return of query_migrate_parameters because the corresponding QMP command has all of its members non-optional by design, despite them being marked as optional in migration.json.

Extract this code into a function and make it assert if any field is missing. With this we ensure future changes will not inadvertently leave any parameters missing.

Also assert that s->parameters _does not_ have any of its has_* fields set. This structure is internal to the migration code and it should not rely on the QAPI-generate has_* fields. We might want to store migration parameters differently in the future.

---
 migration/options.c | 74 ++++++++++++++++++++++++++++-----------------
 1 file changed, 46 insertions(+), 28 deletions(-)
migration/options.c +0 -0
index e2e3ab717f..dd62e726cb 100644

migration/options.c static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src) · line 941

Quoted 6 lines
migration/options.c +3 -0
@@ -936,6 +936,40 @@ static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)
     }
 }
 
+static void migrate_mark_all_params_present(MigrationParameters *p)
+{
+    int len, n_str_args = 3; /* tls-creds, tls-hostname, tls-authz */

Could you remind me why we don't set has_*=true for these three?

Quoted 12 lines
migration/options.c +12 -0
+    bool *has_fields[] = {
+        &p->has_throttle_trigger_threshold, &p->has_cpu_throttle_initial,
+        &p->has_cpu_throttle_increment, &p->has_cpu_throttle_tailslow,
+        &p->has_max_bandwidth, &p->has_avail_switchover_bandwidth,
+        &p->has_downtime_limit, &p->has_x_checkpoint_delay,
+        &p->has_multifd_channels, &p->has_multifd_compression,
+        &p->has_multifd_zlib_level, &p->has_multifd_qatzip_level,
+        &p->has_multifd_zstd_level, &p->has_xbzrle_cache_size,
+        &p->has_max_postcopy_bandwidth, &p->has_max_cpu_throttle,
+        &p->has_announce_initial, &p->has_announce_max, &p->has_announce_rounds,
+        &p->has_announce_step, &p->has_block_bitmap_mapping,
+        &p->has_x_vcpu_dirty_limit_period, &p->has_vcpu_dirty_limit,

migration/options.c static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src) · line 963

Quoted 10 lines
migration/options.c +10 -0
+        &p->has_mode, &p->has_zero_page_detection, &p->has_direct_io,
+    };
+
+    /*
+     * The has_* fields of MigrationParameters are used by QAPI to
+     * inform whether an optional struct member is present. Keep this
+     * decoupled from the internal usage (not QAPI) by leaving the
+     * has_* fields of s->parameters unused.
+     */
+    assert(p != &(migrate_get_current())->parameters);

This is OK, I'm not sure whether we're over-cautious though.. but..

migration/options.c static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src) · line 966

Quoted 3 lines
migration/options.c +3 -0
+
+    len = ARRAY_SIZE(has_fields);
+    assert(len + n_str_args == MIGRATION_PARAMETER__MAX);

.. I definitely like this assert.

Quoted 93 lines
migration/options.c +18 -28
+
+    for (int i = 0; i < len; i++) {
+        *has_fields[i] = true;
+    }
+}
+
 MigrationParameters *qmp_query_migrate_parameters(Error **errp)
 {
     MigrationParameters *params;
@@ -943,68 +977,52 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
 
     /* TODO use QAPI_CLONE() instead of duplicating it inline */
     params = g_malloc0(sizeof(*params));
-    params->has_throttle_trigger_threshold = true;
+
     params->throttle_trigger_threshold = s->parameters.throttle_trigger_threshold;
-    params->has_cpu_throttle_initial = true;
     params->cpu_throttle_initial = s->parameters.cpu_throttle_initial;
-    params->has_cpu_throttle_increment = true;
     params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
-    params->has_cpu_throttle_tailslow = true;
     params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
 
     tls_option_set_str(&params->tls_creds, s->parameters.tls_creds);
     tls_option_set_str(&params->tls_hostname, s->parameters.tls_hostname);
     tls_option_set_str(&params->tls_authz, s->parameters.tls_authz);
 
-    params->has_max_bandwidth = true;
     params->max_bandwidth = s->parameters.max_bandwidth;
-    params->has_avail_switchover_bandwidth = true;
     params->avail_switchover_bandwidth = s->parameters.avail_switchover_bandwidth;
-    params->has_downtime_limit = true;
     params->downtime_limit = s->parameters.downtime_limit;
-    params->has_x_checkpoint_delay = true;
     params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
-    params->has_multifd_channels = true;
     params->multifd_channels = s->parameters.multifd_channels;
-    params->has_multifd_compression = true;
     params->multifd_compression = s->parameters.multifd_compression;
-    params->has_multifd_zlib_level = true;
     params->multifd_zlib_level = s->parameters.multifd_zlib_level;
-    params->has_multifd_qatzip_level = true;
     params->multifd_qatzip_level = s->parameters.multifd_qatzip_level;
-    params->has_multifd_zstd_level = true;
     params->multifd_zstd_level = s->parameters.multifd_zstd_level;
-    params->has_xbzrle_cache_size = true;
     params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
-    params->has_max_postcopy_bandwidth = true;
     params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth;
-    params->has_max_cpu_throttle = true;
     params->max_cpu_throttle = s->parameters.max_cpu_throttle;
-    params->has_announce_initial = true;
     params->announce_initial = s->parameters.announce_initial;
-    params->has_announce_max = true;
     params->announce_max = s->parameters.announce_max;
-    params->has_announce_rounds = true;
     params->announce_rounds = s->parameters.announce_rounds;
-    params->has_announce_step = true;
     params->announce_step = s->parameters.announce_step;
-
-    params->has_block_bitmap_mapping = true;
     params->block_bitmap_mapping =
         QAPI_CLONE(BitmapMigrationNodeAliasList,
                    s->parameters.block_bitmap_mapping);
-
-    params->has_x_vcpu_dirty_limit_period = true;
     params->x_vcpu_dirty_limit_period = s->parameters.x_vcpu_dirty_limit_period;
-    params->has_vcpu_dirty_limit = true;
     params->vcpu_dirty_limit = s->parameters.vcpu_dirty_limit;
-    params->has_mode = true;
     params->mode = s->parameters.mode;
-    params->has_zero_page_detection = true;
     params->zero_page_detection = s->parameters.zero_page_detection;
-    params->has_direct_io = true;
     params->direct_io = s->parameters.direct_io;
 
+    /*
+     * query-migrate-parameters expects all members of
+     * MigrationParameters to be present, but we cannot mark them
+     * non-optional in QAPI because the structure is also used for
+     * migrate-set-parameters, which needs the optionality. Force all
+     * parameters to be seen as present now. Note that this depends on
+     * some form of default being set for every member of
+     * MigrationParameters, currently done during qdev init using
+     * migration_properties defined in this file.
+     */
+    migrate_mark_all_params_present(params);
     return params;
 }
 
Signature · 1 line
2.35.3
Signature · 1 line
Peter Xu
#35 lore raw

Re: [PATCH 09/21] migration: Extract code to mark all parameters as present

Quoted 28 lines · Peter Xu
Quoted 27 lines · Fabiano Rosas

MigrationParameters needs to have all of its has_* fields marked as true when used as the return of query_migrate_parameters because the corresponding QMP command has all of its members non-optional by design, despite them being marked as optional in migration.json.

Extract this code into a function and make it assert if any field is missing. With this we ensure future changes will not inadvertently leave any parameters missing.

Also assert that s->parameters _does not_ have any of its has_* fields set. This structure is internal to the migration code and it should not rely on the QAPI-generate has_* fields. We might want to store migration parameters differently in the future.

---
 migration/options.c | 74 ++++++++++++++++++++++++++++-----------------
 1 file changed, 46 insertions(+), 28 deletions(-)
migration/options.c +0 -0
index e2e3ab717f..dd62e726cb 100644
@@ -936,6 +936,40 @@ static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)
     }
 }
 
Quoted 6 lines

migration/options.c static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src) · line 941

Quoted 3 lines
migration/options.c +3 -0
+static void migrate_mark_all_params_present(MigrationParameters *p)
+{
+    int len, n_str_args = 3; /* tls-creds, tls-hostname, tls-authz */

Could you remind me why we don't set has_*=true for these three?

I doesn't exist. These are StrOrNull so their presence is supposed to be determined by checking against NULL pointer.

Quoted 23 lines
Quoted 12 lines
migration/options.c +12 -0
+    bool *has_fields[] = {
+        &p->has_throttle_trigger_threshold, &p->has_cpu_throttle_initial,
+        &p->has_cpu_throttle_increment, &p->has_cpu_throttle_tailslow,
+        &p->has_max_bandwidth, &p->has_avail_switchover_bandwidth,
+        &p->has_downtime_limit, &p->has_x_checkpoint_delay,
+        &p->has_multifd_channels, &p->has_multifd_compression,
+        &p->has_multifd_zlib_level, &p->has_multifd_qatzip_level,
+        &p->has_multifd_zstd_level, &p->has_xbzrle_cache_size,
+        &p->has_max_postcopy_bandwidth, &p->has_max_cpu_throttle,
+        &p->has_announce_initial, &p->has_announce_max, &p->has_announce_rounds,
+        &p->has_announce_step, &p->has_block_bitmap_mapping,
+        &p->has_x_vcpu_dirty_limit_period, &p->has_vcpu_dirty_limit,

migration/options.c static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src) · line 963

Quoted 10 lines
migration/options.c +10 -0
+        &p->has_mode, &p->has_zero_page_detection, &p->has_direct_io,
+    };
+
+    /*
+     * The has_* fields of MigrationParameters are used by QAPI to
+     * inform whether an optional struct member is present. Keep this
+     * decoupled from the internal usage (not QAPI) by leaving the
+     * has_* fields of s->parameters unused.
+     */
+    assert(p != &(migrate_get_current())->parameters);
Quoted 2 lines

This is OK, I'm not sure whether we're over-cautious though.. but..

Hopefully after this series the code will be encapsulated enough that we don't need to think about this, but before this series the situation is definitely confusing enough that we need to know which fields are used for what.

I don't want to see people passing s->parameters into here thinking it's all the same, because it isn't. The has_* fields should be used only for QAPI stuff, user input validation, etc, while s->parameters is the thing that stores all that after validation and there's not reason to be messing with has_* since we know that's just an consequence of the fact that we're choosing to use the same QAPI type for user input/output and internal storage.

I guess what I'm trying to do is take the pain points where I got confused while working on the current code and introduce some hard rules to it.

Quoted 6 lines

migration/options.c static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src) · line 966

Quoted 3 lines
migration/options.c +3 -0
+
+    len = ARRAY_SIZE(has_fields);
+    assert(len + n_str_args == MIGRATION_PARAMETER__MAX);

.. I definitely like this assert.

Yep, we can't at the moment get rid of the enum because HMP needs it, so let's put it to good use. I think this is specially useful for new contributors, so they don't need to guess what needs to be changed when adding a new parameter.

#36 lore raw

Re: [PATCH 09/21] migration: Extract code to mark all parameters as present

Quoted 79 lines · Fabiano Rosas
Quoted 28 lines · Peter Xu
Quoted 27 lines · Fabiano Rosas

MigrationParameters needs to have all of its has_* fields marked as true when used as the return of query_migrate_parameters because the corresponding QMP command has all of its members non-optional by design, despite them being marked as optional in migration.json.

Extract this code into a function and make it assert if any field is missing. With this we ensure future changes will not inadvertently leave any parameters missing.

Also assert that s->parameters _does not_ have any of its has_* fields set. This structure is internal to the migration code and it should not rely on the QAPI-generate has_* fields. We might want to store migration parameters differently in the future.

---
 migration/options.c | 74 ++++++++++++++++++++++++++++-----------------
 1 file changed, 46 insertions(+), 28 deletions(-)
migration/options.c +0 -0
index e2e3ab717f..dd62e726cb 100644
@@ -936,6 +936,40 @@ static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)
     }
 }
 
Quoted 6 lines

migration/options.c static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src) · line 941

Quoted 3 lines
migration/options.c +3 -0
+static void migrate_mark_all_params_present(MigrationParameters *p)
+{
+    int len, n_str_args = 3; /* tls-creds, tls-hostname, tls-authz */

Could you remind me why we don't set has_*=true for these three?

I doesn't exist. These are StrOrNull so their presence is supposed to be determined by checking against NULL pointer.

Quoted 23 lines
Quoted 12 lines
migration/options.c +12 -0
+    bool *has_fields[] = {
+        &p->has_throttle_trigger_threshold, &p->has_cpu_throttle_initial,
+        &p->has_cpu_throttle_increment, &p->has_cpu_throttle_tailslow,
+        &p->has_max_bandwidth, &p->has_avail_switchover_bandwidth,
+        &p->has_downtime_limit, &p->has_x_checkpoint_delay,
+        &p->has_multifd_channels, &p->has_multifd_compression,
+        &p->has_multifd_zlib_level, &p->has_multifd_qatzip_level,
+        &p->has_multifd_zstd_level, &p->has_xbzrle_cache_size,
+        &p->has_max_postcopy_bandwidth, &p->has_max_cpu_throttle,
+        &p->has_announce_initial, &p->has_announce_max, &p->has_announce_rounds,
+        &p->has_announce_step, &p->has_block_bitmap_mapping,
+        &p->has_x_vcpu_dirty_limit_period, &p->has_vcpu_dirty_limit,

migration/options.c static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src) · line 963

Quoted 10 lines
migration/options.c +10 -0
+        &p->has_mode, &p->has_zero_page_detection, &p->has_direct_io,
+    };
+
+    /*
+     * The has_* fields of MigrationParameters are used by QAPI to
+     * inform whether an optional struct member is present. Keep this
+     * decoupled from the internal usage (not QAPI) by leaving the
+     * has_* fields of s->parameters unused.
+     */
+    assert(p != &(migrate_get_current())->parameters);
Quoted 2 lines

This is OK, I'm not sure whether we're over-cautious though.. but..

Hopefully after this series the code will be encapsulated enough that we don't need to think about this, but before this series the situation is definitely confusing enough that we need to know which fields are used for what.

I don't want to see people passing s->parameters into here thinking it's all the same, because it isn't. The has_* fields should be used only for QAPI stuff, user input validation, etc, while s->parameters is the thing that stores all that after validation and there's not reason to be messing with has_* since we know that's just an consequence of the fact that we're choosing to use the same QAPI type for user input/output and internal storage.

Quoted 3 lines

I guess what I'm trying to do is take the pain points where I got confused while working on the current code and introduce some hard rules to it.

Yes, this makes sense.

Signature · 1 line
Peter Xu
#37 lore raw

PATCH 10/21 migration: Use QAPI_CLONE_MEMBERS in query_migrate_parameters

In reply to Fabiano Rosas

QAPI_CLONE_MEMBERS is a better option than copying parameters one by one because it operates on the entire struct and follows pointers. It also avoids the need to alter this function every time a new parameter is added.

Note, since this is a deep clone, now we must free the TLS strings before assignment.

---
 migration/options.c | 31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)
migration/options.c +4 -27
index dd62e726cb..0a2a3050ec 100644
@@ -918,7 +918,9 @@ static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)
 {
     StrOrNull *dst = *dstp;
 
-    assert(!dst);
+    if (dst) {
+        qapi_free_StrOrNull(dst);
+    }
 
     dst = *dstp = g_new0(StrOrNull, 1);
     dst->type = QTYPE_QSTRING;
@@ -975,42 +977,17 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     MigrationParameters *params;
     MigrationState *s = migrate_get_current();
 
-    /* TODO use QAPI_CLONE() instead of duplicating it inline */
     params = g_malloc0(sizeof(*params));
 
-    params->throttle_trigger_threshold = s->parameters.throttle_trigger_threshold;
-    params->cpu_throttle_initial = s->parameters.cpu_throttle_initial;
-    params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
-    params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
+    QAPI_CLONE_MEMBERS(MigrationParameters, params, &s->parameters);
 
     tls_option_set_str(&params->tls_creds, s->parameters.tls_creds);
     tls_option_set_str(&params->tls_hostname, s->parameters.tls_hostname);
     tls_option_set_str(&params->tls_authz, s->parameters.tls_authz);
 
-    params->max_bandwidth = s->parameters.max_bandwidth;
-    params->avail_switchover_bandwidth = s->parameters.avail_switchover_bandwidth;
-    params->downtime_limit = s->parameters.downtime_limit;
-    params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
-    params->multifd_channels = s->parameters.multifd_channels;
-    params->multifd_compression = s->parameters.multifd_compression;
-    params->multifd_zlib_level = s->parameters.multifd_zlib_level;
-    params->multifd_qatzip_level = s->parameters.multifd_qatzip_level;
-    params->multifd_zstd_level = s->parameters.multifd_zstd_level;
-    params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
-    params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth;
-    params->max_cpu_throttle = s->parameters.max_cpu_throttle;
-    params->announce_initial = s->parameters.announce_initial;
-    params->announce_max = s->parameters.announce_max;
-    params->announce_rounds = s->parameters.announce_rounds;
-    params->announce_step = s->parameters.announce_step;
     params->block_bitmap_mapping =
         QAPI_CLONE(BitmapMigrationNodeAliasList,
                    s->parameters.block_bitmap_mapping);
-    params->x_vcpu_dirty_limit_period = s->parameters.x_vcpu_dirty_limit_period;
-    params->vcpu_dirty_limit = s->parameters.vcpu_dirty_limit;
-    params->mode = s->parameters.mode;
-    params->zero_page_detection = s->parameters.zero_page_detection;
-    params->direct_io = s->parameters.direct_io;
 
     /*
      * query-migrate-parameters expects all members of
Signature · 1 line
2.35.3
#38 lore raw

Re: [PATCH 10/21] migration: Use QAPI_CLONE_MEMBERS in query_migrate_parameters

Quoted 54 lines · Fabiano Rosas

QAPI_CLONE_MEMBERS is a better option than copying parameters one by one because it operates on the entire struct and follows pointers. It also avoids the need to alter this function every time a new parameter is added.

Note, since this is a deep clone, now we must free the TLS strings before assignment.

---
 migration/options.c | 31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)
migration/options.c +4 -15
index dd62e726cb..0a2a3050ec 100644
@@ -918,7 +918,9 @@ static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)
 {
     StrOrNull *dst = *dstp;
 
-    assert(!dst);
+    if (dst) {
+        qapi_free_StrOrNull(dst);
+    }
 
     dst = *dstp = g_new0(StrOrNull, 1);
     dst->type = QTYPE_QSTRING;
@@ -975,42 +977,17 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     MigrationParameters *params;
     MigrationState *s = migrate_get_current();
 
-    /* TODO use QAPI_CLONE() instead of duplicating it inline */
     params = g_malloc0(sizeof(*params));
 
-    params->throttle_trigger_threshold = s->parameters.throttle_trigger_threshold;
-    params->cpu_throttle_initial = s->parameters.cpu_throttle_initial;
-    params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
-    params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
+    QAPI_CLONE_MEMBERS(MigrationParameters, params, &s->parameters);
 
     tls_option_set_str(&params->tls_creds, s->parameters.tls_creds);
     tls_option_set_str(&params->tls_hostname, s->parameters.tls_hostname);
     tls_option_set_str(&params->tls_authz, s->parameters.tls_authz);
 
-    params->max_bandwidth = s->parameters.max_bandwidth;
-    params->avail_switchover_bandwidth = s->parameters.avail_switchover_bandwidth;
-    params->downtime_limit = s->parameters.downtime_limit;
-    params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
-    params->multifd_channels = s->parameters.multifd_channels;
-    params->multifd_compression = s->parameters.multifd_compression;
-    params->multifd_zlib_level = s->parameters.multifd_zlib_level;
-    params->multifd_qatzip_level = s->parameters.multifd_qatzip_level;
-    params->multifd_zstd_level = s->parameters.multifd_zstd_level;

migration/options.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 990

Quoted 10 lines
migration/options.c +0 -7
-    params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
-    params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth;
-    params->max_cpu_throttle = s->parameters.max_cpu_throttle;
-    params->announce_initial = s->parameters.announce_initial;
-    params->announce_max = s->parameters.announce_max;
-    params->announce_rounds = s->parameters.announce_rounds;
-    params->announce_step = s->parameters.announce_step;
     params->block_bitmap_mapping =
         QAPI_CLONE(BitmapMigrationNodeAliasList,
                    s->parameters.block_bitmap_mapping);

Wouldn't the QAPI_CLONE_MEMBERS() have deep cloned this too?

Quoted 11 lines
migration/options.c +0 -5
-    params->x_vcpu_dirty_limit_period = s->parameters.x_vcpu_dirty_limit_period;
-    params->vcpu_dirty_limit = s->parameters.vcpu_dirty_limit;
-    params->mode = s->parameters.mode;
-    params->zero_page_detection = s->parameters.zero_page_detection;
-    params->direct_io = s->parameters.direct_io;
 
     /*
      * query-migrate-parameters expects all members of
Signature · 1 line
2.35.3
Signature · 1 line
Peter Xu
#39 lore raw

Re: [PATCH 10/21] migration: Use QAPI_CLONE_MEMBERS in query_migrate_parameters

Quoted 59 lines · Peter Xu
Quoted 58 lines · Fabiano Rosas

QAPI_CLONE_MEMBERS is a better option than copying parameters one by one because it operates on the entire struct and follows pointers. It also avoids the need to alter this function every time a new parameter is added.

Note, since this is a deep clone, now we must free the TLS strings before assignment.

---
 migration/options.c | 31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)
migration/options.c +4 -19
index dd62e726cb..0a2a3050ec 100644
@@ -918,7 +918,9 @@ static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)
 {
     StrOrNull *dst = *dstp;
 
-    assert(!dst);
+    if (dst) {
+        qapi_free_StrOrNull(dst);
+    }
 
     dst = *dstp = g_new0(StrOrNull, 1);
     dst->type = QTYPE_QSTRING;
@@ -975,42 +977,17 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     MigrationParameters *params;
     MigrationState *s = migrate_get_current();
 
-    /* TODO use QAPI_CLONE() instead of duplicating it inline */
     params = g_malloc0(sizeof(*params));
 
-    params->throttle_trigger_threshold = s->parameters.throttle_trigger_threshold;
-    params->cpu_throttle_initial = s->parameters.cpu_throttle_initial;
-    params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
-    params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
+    QAPI_CLONE_MEMBERS(MigrationParameters, params, &s->parameters);
 
     tls_option_set_str(&params->tls_creds, s->parameters.tls_creds);
     tls_option_set_str(&params->tls_hostname, s->parameters.tls_hostname);
     tls_option_set_str(&params->tls_authz, s->parameters.tls_authz);
 
-    params->max_bandwidth = s->parameters.max_bandwidth;
-    params->avail_switchover_bandwidth = s->parameters.avail_switchover_bandwidth;
-    params->downtime_limit = s->parameters.downtime_limit;
-    params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
-    params->multifd_channels = s->parameters.multifd_channels;
-    params->multifd_compression = s->parameters.multifd_compression;
-    params->multifd_zlib_level = s->parameters.multifd_zlib_level;
-    params->multifd_qatzip_level = s->parameters.multifd_qatzip_level;
-    params->multifd_zstd_level = s->parameters.multifd_zstd_level;
-    params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
-    params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth;
-    params->max_cpu_throttle = s->parameters.max_cpu_throttle;
-    params->announce_initial = s->parameters.announce_initial;
Quoted 9 lines

migration/options.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 990

Quoted 6 lines
migration/options.c +0 -3
-    params->announce_max = s->parameters.announce_max;
-    params->announce_rounds = s->parameters.announce_rounds;
-    params->announce_step = s->parameters.announce_step;
     params->block_bitmap_mapping =
         QAPI_CLONE(BitmapMigrationNodeAliasList,
                    s->parameters.block_bitmap_mapping);

Wouldn't the QAPI_CLONE_MEMBERS() have deep cloned this too?

Hmm, I think it should. But it definitely broke something without this line. I'll double check.

Quoted 11 lines
Quoted 11 lines
migration/options.c +0 -5
-    params->x_vcpu_dirty_limit_period = s->parameters.x_vcpu_dirty_limit_period;
-    params->vcpu_dirty_limit = s->parameters.vcpu_dirty_limit;
-    params->mode = s->parameters.mode;
-    params->zero_page_detection = s->parameters.zero_page_detection;
-    params->direct_io = s->parameters.direct_io;
 
     /*
      * query-migrate-parameters expects all members of
Signature · 1 line
2.35.3
#40 lore raw

Re: [PATCH 10/21] migration: Use QAPI_CLONE_MEMBERS in query_migrate_parameters

Quoted 71 lines · Fabiano Rosas
Quoted 59 lines · Peter Xu
Quoted 58 lines · Fabiano Rosas

QAPI_CLONE_MEMBERS is a better option than copying parameters one by one because it operates on the entire struct and follows pointers. It also avoids the need to alter this function every time a new parameter is added.

Note, since this is a deep clone, now we must free the TLS strings before assignment.

---
 migration/options.c | 31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)
migration/options.c +4 -19
index dd62e726cb..0a2a3050ec 100644
@@ -918,7 +918,9 @@ static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)
 {
     StrOrNull *dst = *dstp;
 
-    assert(!dst);
+    if (dst) {
+        qapi_free_StrOrNull(dst);
+    }
 
     dst = *dstp = g_new0(StrOrNull, 1);
     dst->type = QTYPE_QSTRING;
@@ -975,42 +977,17 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     MigrationParameters *params;
     MigrationState *s = migrate_get_current();
 
-    /* TODO use QAPI_CLONE() instead of duplicating it inline */
     params = g_malloc0(sizeof(*params));
 
-    params->throttle_trigger_threshold = s->parameters.throttle_trigger_threshold;
-    params->cpu_throttle_initial = s->parameters.cpu_throttle_initial;
-    params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
-    params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
+    QAPI_CLONE_MEMBERS(MigrationParameters, params, &s->parameters);
 
     tls_option_set_str(&params->tls_creds, s->parameters.tls_creds);
     tls_option_set_str(&params->tls_hostname, s->parameters.tls_hostname);
     tls_option_set_str(&params->tls_authz, s->parameters.tls_authz);
 
-    params->max_bandwidth = s->parameters.max_bandwidth;
-    params->avail_switchover_bandwidth = s->parameters.avail_switchover_bandwidth;
-    params->downtime_limit = s->parameters.downtime_limit;
-    params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
-    params->multifd_channels = s->parameters.multifd_channels;
-    params->multifd_compression = s->parameters.multifd_compression;
-    params->multifd_zlib_level = s->parameters.multifd_zlib_level;
-    params->multifd_qatzip_level = s->parameters.multifd_qatzip_level;
-    params->multifd_zstd_level = s->parameters.multifd_zstd_level;
-    params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
-    params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth;
-    params->max_cpu_throttle = s->parameters.max_cpu_throttle;
-    params->announce_initial = s->parameters.announce_initial;
Quoted 9 lines

migration/options.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 990

Quoted 6 lines
migration/options.c +0 -3
-    params->announce_max = s->parameters.announce_max;
-    params->announce_rounds = s->parameters.announce_rounds;
-    params->announce_step = s->parameters.announce_step;
     params->block_bitmap_mapping =
         QAPI_CLONE(BitmapMigrationNodeAliasList,
                    s->parameters.block_bitmap_mapping);

Wouldn't the QAPI_CLONE_MEMBERS() have deep cloned this too?

Quoted 3 lines

Hmm, I think it should. But it definitely broke something without this line. I'll double check.

Thanks for the question, this was indeed wrong. QAPI_CLONE_MEMBERS depend on the has_* fields on src, otherwise it's just a glorified assignment (*dst = src). The reason I got this wrong is that I was using the TLS strings to test and they have a different handling in QAPI:

visit_type_MigrationParameters_members():

    bool has_tls_creds = !!obj->tls_creds;

So the code was working for them, but not for block_bitmap_mapping, for which the QAPI has:

if (visit_optional(v, "block-bitmap-mapping", &obj->has_block_bitmap_mapping)) {
                                                    ^
    if (!visit_type_BitmapMigrationNodeAliasList(v, "block-bitmap-mapping",
        &obj->block_bitmap_mapping, errp)) {
        return false;
    }
}

IOW, the QAPI_CLONE routines depend on the has_ fields (in retrospect:
obviously).

That assert you didn't like will have to go then and s->parameters will have to have all has_* fields permanently set. Not a huge deal, but it undermines my argument of keeping it free from QAPI details.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
migration/options.c +0 -5
-    params->x_vcpu_dirty_limit_period = s->parameters.x_vcpu_dirty_limit_period;
-    params->vcpu_dirty_limit = s->parameters.vcpu_dirty_limit;
-    params->mode = s->parameters.mode;
-    params->zero_page_detection = s->parameters.zero_page_detection;
-    params->direct_io = s->parameters.direct_io;
 
     /*
      * query-migrate-parameters expects all members of
Signature · 1 line
2.35.3
#41 lore raw

Re: [PATCH 10/21] migration: Use QAPI_CLONE_MEMBERS in query_migrate_parameters

Quoted 46 lines · Fabiano Rosas
Quoted 44 lines · Fabiano Rosas
Quoted 42 lines · Peter Xu
Quoted 41 lines · Fabiano Rosas

QAPI_CLONE_MEMBERS is a better option than copying parameters one by one because it operates on the entire struct and follows pointers. It also avoids the need to alter this function every time a new parameter is added.

Note, since this is a deep clone, now we must free the TLS strings before assignment.

---
 migration/options.c | 31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)
migration/options.c +4 -6
index dd62e726cb..0a2a3050ec 100644
@@ -918,7 +918,9 @@ static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)
 {
     StrOrNull *dst = *dstp;
 
-    assert(!dst);
+    if (dst) {
+        qapi_free_StrOrNull(dst);
+    }
 
     dst = *dstp = g_new0(StrOrNull, 1);
     dst->type = QTYPE_QSTRING;
@@ -975,42 +977,17 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     MigrationParameters *params;
     MigrationState *s = migrate_get_current();
 
-    /* TODO use QAPI_CLONE() instead of duplicating it inline */
     params = g_malloc0(sizeof(*params));
 
-    params->throttle_trigger_threshold = s->parameters.throttle_trigger_threshold;
-    params->cpu_throttle_initial = s->parameters.cpu_throttle_initial;
-    params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
-    params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
+    QAPI_CLONE_MEMBERS(MigrationParameters, params, &s->parameters);
 
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

migration/options.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 986

Quoted 3 lines
migration/options.c +0 -0
     tls_option_set_str(&params->tls_creds, s->parameters.tls_creds);
     tls_option_set_str(&params->tls_hostname, s->parameters.tls_hostname);
     tls_option_set_str(&params->tls_authz, s->parameters.tls_authz);

[1]

Quoted 28 lines
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
migration/options.c +0 -16
-    params->max_bandwidth = s->parameters.max_bandwidth;
-    params->avail_switchover_bandwidth = s->parameters.avail_switchover_bandwidth;
-    params->downtime_limit = s->parameters.downtime_limit;
-    params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
-    params->multifd_channels = s->parameters.multifd_channels;
-    params->multifd_compression = s->parameters.multifd_compression;
-    params->multifd_zlib_level = s->parameters.multifd_zlib_level;
-    params->multifd_qatzip_level = s->parameters.multifd_qatzip_level;
-    params->multifd_zstd_level = s->parameters.multifd_zstd_level;
-    params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
-    params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth;
-    params->max_cpu_throttle = s->parameters.max_cpu_throttle;
-    params->announce_initial = s->parameters.announce_initial;
-    params->announce_max = s->parameters.announce_max;
-    params->announce_rounds = s->parameters.announce_rounds;
-    params->announce_step = s->parameters.announce_step;
     params->block_bitmap_mapping =
         QAPI_CLONE(BitmapMigrationNodeAliasList,
                    s->parameters.block_bitmap_mapping);
Quoted 6 lines
Quoted 2 lines

Wouldn't the QAPI_CLONE_MEMBERS() have deep cloned this too?

Hmm, I think it should. But it definitely broke something without this line. I'll double check.

Quoted 8 lines

Thanks for the question, this was indeed wrong. QAPI_CLONE_MEMBERS depend on the has_* fields on src, otherwise it's just a glorified assignment (*dst = src). The reason I got this wrong is that I was using the TLS strings to test and they have a different handling in QAPI:

visit_type_MigrationParameters_members():

    bool has_tls_creds = !!obj->tls_creds;

[2]

Quoted 12 lines

So the code was working for them, but not for block_bitmap_mapping, for which the QAPI has:

if (visit_optional(v, "block-bitmap-mapping", &obj->has_block_bitmap_mapping)) {
                                                    ^
    if (!visit_type_BitmapMigrationNodeAliasList(v, "block-bitmap-mapping",
        &obj->block_bitmap_mapping, errp)) {
        return false;
    }
}
Quoted 6 lines

IOW, the QAPI_CLONE routines depend on the has_ fields (in retrospect:
obviously).

That assert you didn't like will have to go then and s->parameters will have to have all has_* fields permanently set. Not a huge deal, but it undermines my argument of keeping it free from QAPI details.

Oops, indeed. Now you have that function to set all has_*, hopefully this is trivial now to still do so.

Since you mentioned tls_* won't have has_*, but they will get properly cloned IIUC as you mentioned above [2]. Does it mean we can also drop the three lines at [1] too?

In general, I am curious why we can't already use QAPI_CLONE() like:

  params = QAPI_CLONE(&s->parameters);

And if my wish came true once more on having it a pointer (meanwhile if it even happened before this patch):

  params = QAPI_CLONE(s->parameters);

I thought with that, any of "g_malloc0(), copying of tls_*, copying of block_bitmap things" are all not needed?

Signature · 1 line
Peter Xu
#42 lore raw

Re: [PATCH 10/21] migration: Use QAPI_CLONE_MEMBERS in query_migrate_parameters

Quoted 107 lines · Peter Xu
Quoted 46 lines · Fabiano Rosas
Quoted 44 lines · Fabiano Rosas
Quoted 42 lines · Peter Xu
Quoted 41 lines · Fabiano Rosas

QAPI_CLONE_MEMBERS is a better option than copying parameters one by one because it operates on the entire struct and follows pointers. It also avoids the need to alter this function every time a new parameter is added.

Note, since this is a deep clone, now we must free the TLS strings before assignment.

---
 migration/options.c | 31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)
migration/options.c +4 -6
index dd62e726cb..0a2a3050ec 100644
@@ -918,7 +918,9 @@ static void tls_option_set_str(StrOrNull **dstp, StrOrNull *src)
 {
     StrOrNull *dst = *dstp;
 
-    assert(!dst);
+    if (dst) {
+        qapi_free_StrOrNull(dst);
+    }
 
     dst = *dstp = g_new0(StrOrNull, 1);
     dst->type = QTYPE_QSTRING;
@@ -975,42 +977,17 @@ MigrationParameters *qmp_query_migrate_parameters(Error **errp)
     MigrationParameters *params;
     MigrationState *s = migrate_get_current();
 
-    /* TODO use QAPI_CLONE() instead of duplicating it inline */
     params = g_malloc0(sizeof(*params));
 
-    params->throttle_trigger_threshold = s->parameters.throttle_trigger_threshold;
-    params->cpu_throttle_initial = s->parameters.cpu_throttle_initial;
-    params->cpu_throttle_increment = s->parameters.cpu_throttle_increment;
-    params->cpu_throttle_tailslow = s->parameters.cpu_throttle_tailslow;
+    QAPI_CLONE_MEMBERS(MigrationParameters, params, &s->parameters);
 
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

migration/options.c MigrationParameters *qmp_query_migrate_parameters(Error **errp) · line 986

Quoted 3 lines
migration/options.c +0 -0
     tls_option_set_str(&params->tls_creds, s->parameters.tls_creds);
     tls_option_set_str(&params->tls_hostname, s->parameters.tls_hostname);
     tls_option_set_str(&params->tls_authz, s->parameters.tls_authz);

[1]

Quoted 28 lines
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
migration/options.c +0 -16
-    params->max_bandwidth = s->parameters.max_bandwidth;
-    params->avail_switchover_bandwidth = s->parameters.avail_switchover_bandwidth;
-    params->downtime_limit = s->parameters.downtime_limit;
-    params->x_checkpoint_delay = s->parameters.x_checkpoint_delay;
-    params->multifd_channels = s->parameters.multifd_channels;
-    params->multifd_compression = s->parameters.multifd_compression;
-    params->multifd_zlib_level = s->parameters.multifd_zlib_level;
-    params->multifd_qatzip_level = s->parameters.multifd_qatzip_level;
-    params->multifd_zstd_level = s->parameters.multifd_zstd_level;
-    params->xbzrle_cache_size = s->parameters.xbzrle_cache_size;
-    params->max_postcopy_bandwidth = s->parameters.max_postcopy_bandwidth;
-    params->max_cpu_throttle = s->parameters.max_cpu_throttle;
-    params->announce_initial = s->parameters.announce_initial;
-    params->announce_max = s->parameters.announce_max;
-    params->announce_rounds = s->parameters.announce_rounds;
-    params->announce_step = s->parameters.announce_step;
     params->block_bitmap_mapping =
         QAPI_CLONE(BitmapMigrationNodeAliasList,
                    s->parameters.block_bitmap_mapping);
Quoted 6 lines
Quoted 2 lines

Wouldn't the QAPI_CLONE_MEMBERS() have deep cloned this too?

Hmm, I think it should. But it definitely broke something without this line. I'll double check.

Quoted 8 lines

Thanks for the question, this was indeed wrong. QAPI_CLONE_MEMBERS depend on the has_* fields on src, otherwise it's just a glorified assignment (*dst = src). The reason I got this wrong is that I was using the TLS strings to test and they have a different handling in QAPI:

visit_type_MigrationParameters_members():

    bool has_tls_creds = !!obj->tls_creds;

[2]

Quoted 15 lines

So the code was working for them, but not for block_bitmap_mapping, for which the QAPI has:

if (visit_optional(v, "block-bitmap-mapping", &obj->has_block_bitmap_mapping)) {
                                                    ^
    if (!visit_type_BitmapMigrationNodeAliasList(v, "block-bitmap-mapping",
        &obj->block_bitmap_mapping, errp)) {
        return false;
    }
}

IOW, the QAPI_CLONE routines depend on the has_ fields (in retrospect:
obviously).

Quoted 7 lines
Quoted 3 lines

That assert you didn't like will have to go then and s->parameters will have to have all has_* fields permanently set. Not a huge deal, but it undermines my argument of keeping it free from QAPI details.

Oops, indeed. Now you have that function to set all has_*, hopefully this is trivial now to still do so.

Yes.

Quoted 4 lines

Since you mentioned tls_* won't have has_*, but they will get properly cloned IIUC as you mentioned above [2]. Does it mean we can also drop the three lines at [1] too?

I'm thinking yes as well, still woking on it.

Quoted 11 lines

In general, I am curious why we can't already use QAPI_CLONE() like:

  params = QAPI_CLONE(&s->parameters);

And if my wish came true once more on having it a pointer (meanwhile if it even happened before this patch):

  params = QAPI_CLONE(s->parameters);

I thought with that, any of "g_malloc0(), copying of tls_*, copying of block_bitmap things" are all not needed?

Same here.

#43 lore raw

PATCH 11/21 migration: Use QAPI_CLONE_MEMBERS in migrate_params_test_apply

In reply to Fabiano Rosas

Use QAPI_CLONE_MEMBERS instead of making an assignment. The QAPI method makes the handling of the TLS strings more intuitive because it clones them as well.

---
 migration/options.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
migration/options.c +10 -12
index 0a2a3050ec..4453933c4c 100644
@@ -1186,9 +1186,9 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)
 static void migrate_params_test_apply(MigrationParameters *params,
                                       MigrationParameters *dest)
 {
-    *dest = migrate_get_current()->parameters;
+    MigrationState *s = migrate_get_current();
 
-    /* TODO use QAPI_CLONE() instead of duplicating it inline */
+    QAPI_CLONE_MEMBERS(MigrationParameters, dest, &s->parameters);
 
     if (params->has_throttle_trigger_threshold) {
         dest->throttle_trigger_threshold = params->throttle_trigger_threshold;
@@ -1208,23 +1208,14 @@ static void migrate_params_test_apply(MigrationParameters *params,
 
     if (params->tls_creds) {
         tls_option_set_str(&dest->tls_creds, params->tls_creds);
-    } else {
-        /* drop the reference, it's owned by s->parameters */
-        dest->tls_creds = NULL;
     }
 
     if (params->tls_hostname) {
         tls_option_set_str(&dest->tls_hostname, params->tls_hostname);
-    } else {
-        /* drop the reference, it's owned by s->parameters */
-        dest->tls_hostname = NULL;
     }
 
     if (params->tls_authz) {
         tls_option_set_str(&dest->tls_authz, params->tls_authz);
-    } else {
-        /* drop the reference, it's owned by s->parameters */
-        dest->tls_authz = NULL;
     }
 
     if (params->has_max_bandwidth) {
@@ -1281,7 +1272,6 @@ static void migrate_params_test_apply(MigrationParameters *params,
     }
 
     if (params->has_block_bitmap_mapping) {
-        dest->has_block_bitmap_mapping = true;
         dest->block_bitmap_mapping = params->block_bitmap_mapping;
     }
 
@@ -1433,6 +1423,14 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
 
     migrate_params_test_apply(params, &tmp);
 
+    /*
+     * Mark block_bitmap_mapping as present now while we have the
+     * params structure with the user input around.
+     */
+    if (params->has_block_bitmap_mapping) {
+        migrate_get_current()->has_block_bitmap_mapping = true;
+    }
+
     if (migrate_params_check(&tmp, errp)) {
         migrate_params_apply(params);
         migrate_post_update_params(params, errp);
Signature · 1 line
2.35.3
#44 lore raw

PATCH 12/21 migration: Use QAPI_CLONE_MEMBERS in migrate_params_apply

In reply to Fabiano Rosas

Instead of setting parameters one by one, use the temporary object, which already contains the current migration parameters plus the new ones and was just validated by migration_params_check(). Use cloning to overwrite it.

This avoids the need to alter this function every time a new parameter is added.

Note that s->parameters is part of MigrationState, so it doesn't require freeing, but the TLS strings do.

---
 migration/options.c | 122 ++++----------------------------------------
 1 file changed, 9 insertions(+), 113 deletions(-)
migration/options.c +9 -113
index 4453933c4c..27b5f549f9 100644
@@ -13,6 +13,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/error-report.h"
+#include "qemu/main-loop.h"
 #include "exec/target_page.h"
 #include "qapi/clone-visitor.h"
 #include "qapi/error.h"
@@ -1299,122 +1300,17 @@ static void migrate_params_test_apply(MigrationParameters *params,
 static void migrate_params_apply(MigrationParameters *params)
 {
     MigrationState *s = migrate_get_current();
+    MigrationParameters *cur = &s->parameters;
 
-    /* TODO use QAPI_CLONE() instead of duplicating it inline */
+    assert(bql_locked());
 
-    if (params->has_throttle_trigger_threshold) {
-        s->parameters.throttle_trigger_threshold = params->throttle_trigger_threshold;
-    }
+    migrate_tls_opts_free(cur);
+    qapi_free_BitmapMigrationNodeAliasList(cur->block_bitmap_mapping);
 
-    if (params->has_cpu_throttle_initial) {
-        s->parameters.cpu_throttle_initial = params->cpu_throttle_initial;
-    }
+    QAPI_CLONE_MEMBERS(MigrationParameters, cur, params);
 
-    if (params->has_cpu_throttle_increment) {
-        s->parameters.cpu_throttle_increment = params->cpu_throttle_increment;
-    }
-
-    if (params->has_cpu_throttle_tailslow) {
-        s->parameters.cpu_throttle_tailslow = params->cpu_throttle_tailslow;
-    }
-
-    if (params->tls_creds) {
-        qapi_free_StrOrNull(s->parameters.tls_creds);
-        tls_option_set_str(&s->parameters.tls_creds, params->tls_creds);
-    }
-
-    if (params->tls_hostname) {
-        qapi_free_StrOrNull(s->parameters.tls_hostname);
-        tls_option_set_str(&s->parameters.tls_hostname, params->tls_hostname);
-    }
-
-    if (params->tls_authz) {
-        qapi_free_StrOrNull(s->parameters.tls_authz);
-        tls_option_set_str(&s->parameters.tls_authz, params->tls_authz);
-    }
-
-    if (params->has_max_bandwidth) {
-        s->parameters.max_bandwidth = params->max_bandwidth;
-    }
-
-    if (params->has_avail_switchover_bandwidth) {
-        s->parameters.avail_switchover_bandwidth = params->avail_switchover_bandwidth;
-    }
-
-    if (params->has_downtime_limit) {
-        s->parameters.downtime_limit = params->downtime_limit;
-    }
-
-    if (params->has_x_checkpoint_delay) {
-        s->parameters.x_checkpoint_delay = params->x_checkpoint_delay;
-    }
-
-    if (params->has_multifd_channels) {
-        s->parameters.multifd_channels = params->multifd_channels;
-    }
-    if (params->has_multifd_compression) {
-        s->parameters.multifd_compression = params->multifd_compression;
-    }
-    if (params->has_multifd_qatzip_level) {
-        s->parameters.multifd_qatzip_level = params->multifd_qatzip_level;
-    }
-    if (params->has_multifd_zlib_level) {
-        s->parameters.multifd_zlib_level = params->multifd_zlib_level;
-    }
-    if (params->has_multifd_zstd_level) {
-        s->parameters.multifd_zstd_level = params->multifd_zstd_level;
-    }
-    if (params->has_xbzrle_cache_size) {
-        s->parameters.xbzrle_cache_size = params->xbzrle_cache_size;
-    }
-    if (params->has_max_postcopy_bandwidth) {
-        s->parameters.max_postcopy_bandwidth = params->max_postcopy_bandwidth;
-    }
-    if (params->has_max_cpu_throttle) {
-        s->parameters.max_cpu_throttle = params->max_cpu_throttle;
-    }
-    if (params->has_announce_initial) {
-        s->parameters.announce_initial = params->announce_initial;
-    }
-    if (params->has_announce_max) {
-        s->parameters.announce_max = params->announce_max;
-    }
-    if (params->has_announce_rounds) {
-        s->parameters.announce_rounds = params->announce_rounds;
-    }
-    if (params->has_announce_step) {
-        s->parameters.announce_step = params->announce_step;
-    }
-
-    if (params->has_block_bitmap_mapping) {
-        qapi_free_BitmapMigrationNodeAliasList(
-            s->parameters.block_bitmap_mapping);
-
-        s->has_block_bitmap_mapping = true;
-        s->parameters.block_bitmap_mapping =
-            QAPI_CLONE(BitmapMigrationNodeAliasList,
-                       params->block_bitmap_mapping);
-    }
-
-    if (params->has_x_vcpu_dirty_limit_period) {
-        s->parameters.x_vcpu_dirty_limit_period =
-            params->x_vcpu_dirty_limit_period;
-    }
-    if (params->has_vcpu_dirty_limit) {
-        s->parameters.vcpu_dirty_limit = params->vcpu_dirty_limit;
-    }
-
-    if (params->has_mode) {
-        s->parameters.mode = params->mode;
-    }
-
-    if (params->has_zero_page_detection) {
-        s->parameters.zero_page_detection = params->zero_page_detection;
-    }
-
-    if (params->has_direct_io) {
-        s->parameters.direct_io = params->direct_io;
-    }
+    cur->block_bitmap_mapping = QAPI_CLONE(BitmapMigrationNodeAliasList,
+                                           params->block_bitmap_mapping);
 }
 
 void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
@@ -1432,7 +1328,7 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
     }
 
     if (migrate_params_check(&tmp, errp)) {
-        migrate_params_apply(params);
+        migrate_params_apply(&tmp);
         migrate_post_update_params(params, errp);
     }
 
Signature · 1 line
2.35.3
#45 lore raw

PATCH 13/21 migration: Use visitors in migrate_params_test_apply

In reply to Fabiano Rosas

Convert the code in migrate_params_test_apply() from an open-coded copy of every migration parameter to a copy using visitors.

This hides the details of QAPI from the migration code and avoids the need to update migrate_params_test_apply() every time a new migration parameter is added. Both were very confusing and while the visitor code can become a bit involved, there is no need for new contributors to ever touch it.

---
 migration/options.c | 143 ++++++++++++--------------------------------
 1 file changed, 39 insertions(+), 104 deletions(-)
migration/options.c +39 -104
index 27b5f549f9..ac4b06da7e 100644
@@ -20,6 +20,10 @@
 #include "qapi/qapi-commands-migration.h"
 #include "qapi/qapi-visit-migration.h"
 #include "qapi/qmp/qerror.h"
+#include "qapi/qobject-input-visitor.h"
+#include "qapi/qobject-output-visitor.h"
+#include "qapi/visitor.h"
+#include "qobject/qdict.h"
 #include "qobject/qnull.h"
 #include "system/runstate.h"
 #include "migration/colo.h"
@@ -1184,117 +1188,46 @@ bool migrate_params_check(MigrationParameters *params, Error **errp)
     return true;
 }
 
-static void migrate_params_test_apply(MigrationParameters *params,
-                                      MigrationParameters *dest)
+static bool migrate_params_test_apply(MigrationParameters *params,
+                                      MigrationParameters *dest, Error **errp)
 {
     MigrationState *s = migrate_get_current();
+    QObject *ret_out = NULL;
+    Visitor *v;
+    bool ok;
 
     QAPI_CLONE_MEMBERS(MigrationParameters, dest, &s->parameters);
 
-    if (params->has_throttle_trigger_threshold) {
-        dest->throttle_trigger_threshold = params->throttle_trigger_threshold;
+    /* read in from params */
+    v = qobject_output_visitor_new(&ret_out);
+    ok = visit_type_MigrationParameters(v, NULL, &params, errp);
+    if (!ok) {
+        goto out;
     }
+    visit_complete(v, &ret_out);
+    visit_free(v);
 
-    if (params->has_cpu_throttle_initial) {
-        dest->cpu_throttle_initial = params->cpu_throttle_initial;
+    /* write out to dest */
+    v = qobject_input_visitor_new(ret_out);
+    ok = visit_start_struct(v, NULL, NULL, 0, errp);
+    if (!ok) {
+        goto out;
     }
-
-    if (params->has_cpu_throttle_increment) {
-        dest->cpu_throttle_increment = params->cpu_throttle_increment;
-    }
-
-    if (params->has_cpu_throttle_tailslow) {
-        dest->cpu_throttle_tailslow = params->cpu_throttle_tailslow;
-    }
-
-    if (params->tls_creds) {
-        tls_option_set_str(&dest->tls_creds, params->tls_creds);
-    }
-
-    if (params->tls_hostname) {
-        tls_option_set_str(&dest->tls_hostname, params->tls_hostname);
-    }
-
-    if (params->tls_authz) {
-        tls_option_set_str(&dest->tls_authz, params->tls_authz);
-    }
-
-    if (params->has_max_bandwidth) {
-        dest->max_bandwidth = params->max_bandwidth;
-    }
-
-    if (params->has_avail_switchover_bandwidth) {
-        dest->avail_switchover_bandwidth = params->avail_switchover_bandwidth;
-    }
-
-    if (params->has_downtime_limit) {
-        dest->downtime_limit = params->downtime_limit;
-    }
-
-    if (params->has_x_checkpoint_delay) {
-        dest->x_checkpoint_delay = params->x_checkpoint_delay;
-    }
-
-    if (params->has_multifd_channels) {
-        dest->multifd_channels = params->multifd_channels;
+    ok = visit_type_MigrationParameters_members(v, dest, errp);
+    if (!ok) {
+        goto out;
     }
-    if (params->has_multifd_compression) {
-        dest->multifd_compression = params->multifd_compression;
-    }
-    if (params->has_multifd_qatzip_level) {
-        dest->multifd_qatzip_level = params->multifd_qatzip_level;
-    }
-    if (params->has_multifd_zlib_level) {
-        dest->multifd_zlib_level = params->multifd_zlib_level;
-    }
-    if (params->has_multifd_zstd_level) {
-        dest->multifd_zstd_level = params->multifd_zstd_level;
-    }
-    if (params->has_xbzrle_cache_size) {
-        dest->xbzrle_cache_size = params->xbzrle_cache_size;
-    }
-    if (params->has_max_postcopy_bandwidth) {
-        dest->max_postcopy_bandwidth = params->max_postcopy_bandwidth;
-    }
-    if (params->has_max_cpu_throttle) {
-        dest->max_cpu_throttle = params->max_cpu_throttle;
-    }
-    if (params->has_announce_initial) {
-        dest->announce_initial = params->announce_initial;
-    }
-    if (params->has_announce_max) {
-        dest->announce_max = params->announce_max;
-    }
-    if (params->has_announce_rounds) {
-        dest->announce_rounds = params->announce_rounds;
-    }
-    if (params->has_announce_step) {
-        dest->announce_step = params->announce_step;
+    ok = visit_check_struct(v, errp);
+    visit_end_struct(v, NULL);
+    if (!ok) {
+        goto out;
     }
 
-    if (params->has_block_bitmap_mapping) {
-        dest->block_bitmap_mapping = params->block_bitmap_mapping;
-    }
+out:
+    visit_free(v);
+    qobject_unref(ret_out);
 
-    if (params->has_x_vcpu_dirty_limit_period) {
-        dest->x_vcpu_dirty_limit_period =
-            params->x_vcpu_dirty_limit_period;
-    }
-    if (params->has_vcpu_dirty_limit) {
-        dest->vcpu_dirty_limit = params->vcpu_dirty_limit;
-    }
-
-    if (params->has_mode) {
-        dest->mode = params->mode;
-    }
-
-    if (params->has_zero_page_detection) {
-        dest->zero_page_detection = params->zero_page_detection;
-    }
-
-    if (params->has_direct_io) {
-        dest->direct_io = params->direct_io;
-    }
+    return ok;
 }
 
 static void migrate_params_apply(MigrationParameters *params)
@@ -1315,9 +1248,11 @@ static void migrate_params_apply(MigrationParameters *params)
 
 void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
 {
-    MigrationParameters tmp;
+    MigrationParameters *tmp = g_new0(MigrationParameters, 1);
 
-    migrate_params_test_apply(params, &tmp);
+    if (!migrate_params_test_apply(params, tmp, errp)) {
+        return;
+    }
 
     /*
      * Mark block_bitmap_mapping as present now while we have the
@@ -1327,10 +1262,10 @@ void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
         migrate_get_current()->has_block_bitmap_mapping = true;
     }
 
-    if (migrate_params_check(&tmp, errp)) {
-        migrate_params_apply(&tmp);
+    if (migrate_params_check(tmp, errp)) {
+        migrate_params_apply(tmp);
         migrate_post_update_params(params, errp);
     }
 
-    migrate_tls_opts_free(&tmp);
+    qapi_free_MigrationParameters(tmp);
 }
Signature · 1 line
2.35.3
#46 lore raw

PATCH 14/21 migration: Cleanup hmp_info_migrate_parameters

In reply to Fabiano Rosas

Do a cleanup of hmp_info_migrate_parameters() before adding more lines into it:

- Make sure every parameter asserts that the has_* field is set. qmp_query_migrate_parameters should have set them all.

- Remove the if (params), qmp_query_migrate_parameters never returns NULL.

- Add a macro to encapsulate boilerplate.

- Line breaks for legibility.

---
 migration/migration-hmp-cmds.c | 265 ++++++++++++++++++---------------
 1 file changed, 148 insertions(+), 117 deletions(-)
migration/migration-hmp-cmds.c +148 -117
index 685c8ebd53..4f68719eda 100644
@@ -33,6 +33,11 @@
 #include "options.h"
 #include "migration.h"
 
+#define PARAM_INFO(_a, _f, _e, _v) do {                                \
+        assert(_a);                                                     \
+        monitor_printf(mon, _f, MigrationParameter_str(_e), _v);        \
+    } while (0)
+
 static void migration_global_dump(Monitor *mon)
 {
     MigrationState *ms = migrate_get_current();
@@ -243,127 +248,153 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
     const BitmapMigrationNodeAliasList *bmnal;
 
     params = qmp_query_migrate_parameters(NULL);
+    assert(params);
 
-    if (params) {
-        monitor_printf(mon, "%s: %" PRIu64 " ms\n",
-            MigrationParameter_str(MIGRATION_PARAMETER_ANNOUNCE_INITIAL),
-            params->announce_initial);
-        monitor_printf(mon, "%s: %" PRIu64 " ms\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 " ms\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);
-        monitor_printf(mon, "%s: '%s'\n",
-            MigrationParameter_str(MIGRATION_PARAMETER_TLS_CREDS),
-                       params->tls_creds ? params->tls_creds->u.s : "");
-        monitor_printf(mon, "%s: '%s'\n",
-            MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
-                       params->tls_hostname ? params->tls_hostname->u.s : "");
-        assert(params->has_max_bandwidth);
-        monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
-            MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
-            params->max_bandwidth);
-        assert(params->has_avail_switchover_bandwidth);
-        monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
-            MigrationParameter_str(MIGRATION_PARAMETER_AVAIL_SWITCHOVER_BANDWIDTH),
-            params->avail_switchover_bandwidth);
-        assert(params->has_downtime_limit);
-        monitor_printf(mon, "%s: %" PRIu64 " ms\n",
-            MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
-            params->downtime_limit);
-        assert(params->has_x_checkpoint_delay);
-        monitor_printf(mon, "%s: %u ms\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 " bytes\n",
-            MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
-            params->xbzrle_cache_size);
-        monitor_printf(mon, "%s: %" PRIu64 "\n",
-            MigrationParameter_str(MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH),
-            params->max_postcopy_bandwidth);
-        monitor_printf(mon, "%s: '%s'\n",
-            MigrationParameter_str(MIGRATION_PARAMETER_TLS_AUTHZ),
-                       params->tls_authz ? params->tls_authz->u.s : "");
-
-        assert(params->has_block_bitmap_mapping);
-        monitor_printf(mon, "%s:\n",
-                       MigrationParameter_str(
-                           MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING));
-
-        for (bmnal = params->block_bitmap_mapping;
-             bmnal;
-             bmnal = bmnal->next)
-        {
-            const BitmapMigrationNodeAlias *bmna = bmnal->value;
-            const BitmapMigrationBitmapAliasList *bmbal;
-
-            monitor_printf(mon, "  '%s' -> '%s'\n",
-                           bmna->node_name, bmna->alias);
-
-            for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) {
-                const BitmapMigrationBitmapAlias *bmba = bmbal->value;
-
-                monitor_printf(mon, "    '%s' -> '%s'\n",
-                               bmba->name, bmba->alias);
-            }
-        }
-
-        monitor_printf(mon, "%s: %" PRIu64 " ms\n",
-        MigrationParameter_str(MIGRATION_PARAMETER_X_VCPU_DIRTY_LIMIT_PERIOD),
-        params->x_vcpu_dirty_limit_period);
-
-        monitor_printf(mon, "%s: %" PRIu64 " MB/s\n",
-            MigrationParameter_str(MIGRATION_PARAMETER_VCPU_DIRTY_LIMIT),
-            params->vcpu_dirty_limit);
-
-        assert(params->has_mode);
-        monitor_printf(mon, "%s: %s\n",
-            MigrationParameter_str(MIGRATION_PARAMETER_MODE),
-            qapi_enum_lookup(&MigMode_lookup, params->mode));
-
-        if (params->has_direct_io) {
-            monitor_printf(mon, "%s: %s\n",
-                           MigrationParameter_str(
-                               MIGRATION_PARAMETER_DIRECT_IO),
-                           params->direct_io ? "on" : "off");
+    PARAM_INFO(params->has_announce_initial,
+               "%s: %" PRIu64 " ms\n",
+               MIGRATION_PARAMETER_ANNOUNCE_INITIAL,
+               params->announce_initial);
+
+    PARAM_INFO(params->has_announce_max,
+               "%s: %" PRIu64 " ms\n",
+               MIGRATION_PARAMETER_ANNOUNCE_MAX,
+               params->announce_max);
+
+    PARAM_INFO(params->has_announce_rounds,
+               "%s: %" PRIu64 "\n",
+               MIGRATION_PARAMETER_ANNOUNCE_ROUNDS,
+               params->announce_rounds);
+
+    PARAM_INFO(params->has_announce_step,
+               "%s: %" PRIu64 " ms\n",
+               MIGRATION_PARAMETER_ANNOUNCE_STEP,
+               params->announce_step);
+
+    PARAM_INFO(params->has_throttle_trigger_threshold,
+               "%s: %u\n",
+               MIGRATION_PARAMETER_THROTTLE_TRIGGER_THRESHOLD,
+               params->throttle_trigger_threshold);
+
+    PARAM_INFO(params->has_cpu_throttle_initial,
+               "%s: %u\n",
+               MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL,
+               params->cpu_throttle_initial);
+
+    PARAM_INFO(params->has_cpu_throttle_increment,
+               "%s: %u\n",
+               MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT,
+               params->cpu_throttle_increment);
+
+    PARAM_INFO(params->has_cpu_throttle_tailslow,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_CPU_THROTTLE_TAILSLOW,
+               params->cpu_throttle_tailslow ? "on" : "off");
+
+    PARAM_INFO(params->has_max_cpu_throttle,
+               "%s: %u\n",
+               MIGRATION_PARAMETER_MAX_CPU_THROTTLE,
+               params->max_cpu_throttle);
+
+    PARAM_INFO(params->tls_creds,
+               "%s: '%s'\n",
+               MIGRATION_PARAMETER_TLS_CREDS,
+               params->tls_creds->u.s);
+
+    PARAM_INFO(params->tls_hostname,
+               "%s: '%s'\n",
+               MIGRATION_PARAMETER_TLS_HOSTNAME,
+               params->tls_hostname->u.s);
+
+    PARAM_INFO(params->has_max_bandwidth,
+               "%s: %" PRIu64 " bytes/second\n",
+               MIGRATION_PARAMETER_MAX_BANDWIDTH,
+               params->max_bandwidth);
+
+    PARAM_INFO(params->has_avail_switchover_bandwidth,
+               "%s: %" PRIu64 " bytes/second\n",
+               MIGRATION_PARAMETER_AVAIL_SWITCHOVER_BANDWIDTH,
+               params->avail_switchover_bandwidth);
+
+    PARAM_INFO(params->has_downtime_limit,
+               "%s: %" PRIu64 " ms\n",
+               MIGRATION_PARAMETER_DOWNTIME_LIMIT,
+               params->downtime_limit);
+
+    PARAM_INFO(params->has_x_checkpoint_delay,
+               "%s: %u ms\n",
+               MIGRATION_PARAMETER_X_CHECKPOINT_DELAY,
+               params->x_checkpoint_delay);
+
+    PARAM_INFO(params->has_multifd_channels,
+               "%s: %u\n",
+               MIGRATION_PARAMETER_MULTIFD_CHANNELS,
+               params->multifd_channels);
+
+    PARAM_INFO(params->has_multifd_compression,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_MULTIFD_COMPRESSION,
+               qapi_enum_lookup(&MultiFDCompression_lookup,
+                                params->multifd_compression));
+
+    PARAM_INFO(params->has_zero_page_detection,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_ZERO_PAGE_DETECTION,
+               qapi_enum_lookup(&ZeroPageDetection_lookup,
+                                params->zero_page_detection));
+
+    PARAM_INFO(params->has_xbzrle_cache_size,
+               "%s: %" PRIu64 " bytes\n",
+               MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE,
+               params->xbzrle_cache_size);
+
+    PARAM_INFO(params->has_max_postcopy_bandwidth,
+               "%s: %" PRIu64 "\n",
+               MIGRATION_PARAMETER_MAX_POSTCOPY_BANDWIDTH,
+               params->max_postcopy_bandwidth);
+
+    PARAM_INFO(params->tls_authz,
+               "%s: '%s'\n",
+               MIGRATION_PARAMETER_TLS_AUTHZ,
+               params->tls_authz->u.s);
+
+    PARAM_INFO(params->has_block_bitmap_mapping,
+               "%s:%s\n",
+               MIGRATION_PARAMETER_BLOCK_BITMAP_MAPPING,
+               "");
+
+    for (bmnal = params->block_bitmap_mapping; bmnal; bmnal = bmnal->next) {
+        const BitmapMigrationNodeAlias *bmna = bmnal->value;
+        const BitmapMigrationBitmapAliasList *bmbal;
+
+        monitor_printf(mon, "  '%s' -> '%s'\n", bmna->node_name, bmna->alias);
+
+        for (bmbal = bmna->bitmaps; bmbal; bmbal = bmbal->next) {
+            const BitmapMigrationBitmapAlias *bmba = bmbal->value;
+
+            monitor_printf(mon, "    '%s' -> '%s'\n", bmba->name, bmba->alias);
         }
     }
 
+    PARAM_INFO(params->has_x_vcpu_dirty_limit_period,
+               "%s: %" PRIu64 " ms\n",
+               MIGRATION_PARAMETER_X_VCPU_DIRTY_LIMIT_PERIOD,
+               params->x_vcpu_dirty_limit_period);
+
+    PARAM_INFO(params->has_vcpu_dirty_limit,
+               "%s: %" PRIu64 " MB/s\n",
+               MIGRATION_PARAMETER_VCPU_DIRTY_LIMIT,
+               params->vcpu_dirty_limit);
+
+    PARAM_INFO(params->has_mode,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_MODE,
+               qapi_enum_lookup(&MigMode_lookup, params->mode));
+
+    PARAM_INFO(params->has_direct_io,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_DIRECT_IO,
+               params->direct_io ? "on" : "off");
+
     qapi_free_MigrationParameters(params);
 }
 
Signature · 1 line
2.35.3
Reviewed-by on v1 14/21
#47 lore raw

Re: [PATCH 14/21] migration: Cleanup hmp_info_migrate_parameters

Quoted 6 lines · Fabiano Rosas

Do a cleanup of hmp_info_migrate_parameters() before adding more lines into it:

- Make sure every parameter asserts that the has_* field is set. qmp_query_migrate_parameters should have set them all.

Quoted 8 lines

- Remove the if (params), qmp_query_migrate_parameters never returns NULL.

- Add a macro to encapsulate boilerplate.

- Line breaks for legibility.

Signature · 1 line
Peter Xu
#48 lore raw

PATCH 15/21 migration: Add capabilities into MigrationParameters

In reply to Fabiano Rosas

Add capabilities to MigrationParameters. This structure will hold all migration options. Capabilities will go away in the next patch.

Also add capabilities to MigrationParameter as the enum needs to be kept in sync with MigrationParameters. This affects the parsing of migration HMP commands so make the necessary additions there too.

From this point on, both QMP and HMP versions of migrate-set-parameters and query-migrate-parameters gain the ability to work with capabilities.

With MigrationParameters now having members for each capability, the migration capabilities commands (query-migrate-capabilities, migrate-set-capabilities) will soon be deprecated. Add a set of helpers to convert between the old MigrationCapability representation and the new representation as members of MigrationParameters.

---
 migration/migration-hmp-cmds.c | 198 +++++++++++++++++++++++++++++++++
 migration/migration.c          |   8 ++
 migration/options.c            | 130 ++++++++++++++++++++++
 migration/options.h            |   5 +
 qapi/migration.json            | 135 +++++++++++++++++++++-
 5 files changed, 472 insertions(+), 4 deletions(-)
migration/migration-hmp-cmds.c +198 -0
index 4f68719eda..6d8d189b81 100644
@@ -395,6 +395,116 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
                MIGRATION_PARAMETER_DIRECT_IO,
                params->direct_io ? "on" : "off");
 
+    PARAM_INFO(params->has_xbzrle,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_XBZRLE,
+               params->xbzrle ? "on" : "off");
+
+    PARAM_INFO(params->has_rdma_pin_all,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_RDMA_PIN_ALL,
+               params->rdma_pin_all ? "on" : "off");
+
+    PARAM_INFO(params->has_auto_converge,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_AUTO_CONVERGE,
+               params->auto_converge ? "on" : "off");
+
+    PARAM_INFO(params->has_zero_blocks,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_ZERO_BLOCKS,
+               params->zero_blocks ? "on" : "off");
+
+    PARAM_INFO(params->has_events,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_EVENTS,
+               params->events ? "on" : "off");
+
+    PARAM_INFO(params->has_postcopy_ram,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_POSTCOPY_RAM,
+               params->postcopy_ram ? "on" : "off");
+
+    PARAM_INFO(params->has_x_colo,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_X_COLO,
+               params->x_colo ? "on" : "off");
+
+    PARAM_INFO(params->has_release_ram,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_RELEASE_RAM,
+               params->release_ram ? "on" : "off");
+
+    PARAM_INFO(params->has_return_path,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_RETURN_PATH,
+               params->return_path ? "on" : "off");
+
+    PARAM_INFO(params->has_pause_before_switchover,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_PAUSE_BEFORE_SWITCHOVER,
+               params->pause_before_switchover ? "on" : "off");
+
+    PARAM_INFO(params->has_multifd,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_MULTIFD,
+               params->multifd ? "on" : "off");
+
+    PARAM_INFO(params->has_dirty_bitmaps,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_DIRTY_BITMAPS,
+               params->dirty_bitmaps ? "on" : "off");
+
+    PARAM_INFO(params->has_postcopy_blocktime,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_POSTCOPY_BLOCKTIME,
+               params->postcopy_blocktime ? "on" : "off");
+
+    PARAM_INFO(params->has_late_block_activate,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_LATE_BLOCK_ACTIVATE,
+               params->late_block_activate ? "on" : "off");
+
+    PARAM_INFO(params->has_x_ignore_shared,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_X_IGNORE_SHARED,
+               params->x_ignore_shared ? "on" : "off");
+
+    PARAM_INFO(params->has_validate_uuid,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_VALIDATE_UUID,
+               params->validate_uuid ? "on" : "off");
+
+    PARAM_INFO(params->has_background_snapshot,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_BACKGROUND_SNAPSHOT,
+               params->background_snapshot ? "on" : "off");
+
+    PARAM_INFO(params->has_zero_copy_send,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_ZERO_COPY_SEND,
+               params->zero_copy_send ? "on" : "off");
+
+    PARAM_INFO(params->has_postcopy_preempt,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_POSTCOPY_PREEMPT,
+               params->postcopy_preempt ? "on" : "off");
+
+    PARAM_INFO(params->has_switchover_ack,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_SWITCHOVER_ACK,
+               params->switchover_ack ? "on" : "off");
+
+    PARAM_INFO(params->has_dirty_limit,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_DIRTY_LIMIT,
+               params->dirty_limit ? "on" : "off");
+
+    PARAM_INFO(params->has_mapped_ram,
+               "%s: %s\n",
+               MIGRATION_PARAMETER_MAPPED_RAM,
+               params->mapped_ram ? "on" : "off");
+
     qapi_free_MigrationParameters(params);
 }
 
@@ -674,6 +784,94 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
         p->has_direct_io = true;
         visit_type_bool(v, param, &p->direct_io, &err);
         break;
+    case MIGRATION_PARAMETER_XBZRLE:
+        p->has_xbzrle = true;
+        visit_type_bool(v, param, &p->xbzrle, &err);
+        break;
+    case MIGRATION_PARAMETER_RDMA_PIN_ALL:
+        p->has_rdma_pin_all = true;
+        visit_type_bool(v, param, &p->rdma_pin_all, &err);
+        break;
+    case MIGRATION_PARAMETER_AUTO_CONVERGE:
+        p->has_auto_converge = true;
+        visit_type_bool(v, param, &p->auto_converge, &err);
+        break;
+    case MIGRATION_PARAMETER_ZERO_BLOCKS:
+        p->has_zero_blocks = true;
+        visit_type_bool(v, param, &p->zero_blocks, &err);
+        break;
+    case MIGRATION_PARAMETER_EVENTS:
+        p->has_events = true;
+        visit_type_bool(v, param, &p->events, &err);
+        break;
+    case MIGRATION_PARAMETER_POSTCOPY_RAM:
+        p->has_postcopy_ram = true;
+        visit_type_bool(v, param, &p->postcopy_ram, &err);
+        break;
+    case MIGRATION_PARAMETER_X_COLO:
+        p->has_x_colo = true;
+        visit_type_bool(v, param, &p->x_colo, &err);
+        break;
+    case MIGRATION_PARAMETER_RELEASE_RAM:
+        p->has_release_ram = true;
+        visit_type_bool(v, param, &p->release_ram, &err);
+        break;
+    case MIGRATION_PARAMETER_RETURN_PATH:
+        p->has_return_path = true;
+        visit_type_bool(v, param, &p->return_path, &err);
+        break;
+    case MIGRATION_PARAMETER_PAUSE_BEFORE_SWITCHOVER:
+        p->has_pause_before_switchover = true;
+        visit_type_bool(v, param, &p->pause_before_switchover, &err);
+        break;
+    case MIGRATION_PARAMETER_MULTIFD:
+        p->has_multifd = true;
+        visit_type_bool(v, param, &p->multifd, &err);
+        break;
+    case MIGRATION_PARAMETER_DIRTY_BITMAPS:
+        p->has_dirty_bitmaps = true;
+        visit_type_bool(v, param, &p->dirty_bitmaps, &err);
+        break;
+    case MIGRATION_PARAMETER_POSTCOPY_BLOCKTIME:
+        p->has_postcopy_blocktime = true;
+        visit_type_bool(v, param, &p->postcopy_blocktime, &err);
+        break;
+    case MIGRATION_PARAMETER_LATE_BLOCK_ACTIVATE:
+        p->has_late_block_activate = true;
+        visit_type_bool(v, param, &p->late_block_activate, &err);
+        break;
+    case MIGRATION_PARAMETER_X_IGNORE_SHARED:
+        p->has_x_ignore_shared = true;
+        visit_type_bool(v, param, &p->x_ignore_shared, &err);
+        break;
+    case MIGRATION_PARAMETER_VALIDATE_UUID:
+        p->has_validate_uuid = true;
+        visit_type_bool(v, param, &p->validate_uuid, &err);
+        break;
+    case MIGRATION_PARAMETER_BACKGROUND_SNAPSHOT:
+        p->has_background_snapshot = true;
+        visit_type_bool(v, param, &p->background_snapshot, &err);
+        break;
+    case MIGRATION_PARAMETER_ZERO_COPY_SEND:
+        p->has_zero_copy_send = true;
+        visit_type_bool(v, param, &p->zero_copy_send, &err);
+        break;
+    case MIGRATION_PARAMETER_POSTCOPY_PREEMPT:
+        p->has_postcopy_preempt = true;
+        visit_type_bool(v, param, &p->postcopy_preempt, &err);
+        break;
+    case MIGRATION_PARAMETER_SWITCHOVER_ACK:
+        p->has_switchover_ack = true;
+        visit_type_bool(v, param, &p->switchover_ack, &err);
+        break;
+    case MIGRATION_PARAMETER_DIRTY_LIMIT:
+        p->has_dirty_limit = true;
+        visit_type_bool(v, param, &p->dirty_limit, &err);
+        break;
+    case MIGRATION_PARAMETER_MAPPED_RAM:
+        p->has_mapped_ram = true;
+        visit_type_bool(v, param, &p->mapped_ram, &err);
+        break;
     default:
         g_assert_not_reached();
     }
migration/migration.c +8 -0
index 031a5f8ede..efb1dbb0c4 100644
@@ -4098,6 +4098,14 @@ static bool migration_object_check(MigrationState *ms, Error **errp)
         return false;
     }
 
+    /*
+     * FIXME: Temporarily while -global capabilties are still using
+     * s->capabilities. Will be gone by the end of the series.
+     */
+    for (int i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
+        migrate_capability_set_compat(&ms->parameters, i, ms->capabilities[i]);
+    }
+
     return migrate_caps_check(old_caps, ms->capabilities, errp);
 }
 
migration/options.c +130 -0

154 lines not on this page · raw message

migration/options.h +5 -0
index 999eee6f3b..cac9201a5e 100644
@@ -92,4 +92,9 @@ ZeroPageDetection migrate_zero_page_detection(void);
 bool migrate_params_check(MigrationParameters *params, Error **errp);
 void migrate_params_init(MigrationParameters *params);
 void migrate_tls_opts_free(MigrationParameters *params);
+bool migrate_capability_get_compat(MigrationParameters *params, int i);
+void migrate_capability_set_compat(MigrationParameters *params, int i,
+                                   bool val);
+void migrate_capabilities_set_compat(MigrationParameters *params,
+                                     MigrationCapabilityStatusList *caps);
 #endif
qapi/migration.json +131 -4

155 lines not on this page · raw message

Signature · 1 line
2.35.3
Acked-by on v1 15/21
#49 lore raw

Re: [PATCH 15/21] migration: Add capabilities into MigrationParameters

Quoted 11 lines · Fabiano Rosas

Add capabilities to MigrationParameters. This structure will hold all migration options. Capabilities will go away in the next patch.

Also add capabilities to MigrationParameter as the enum needs to be kept in sync with MigrationParameters. This affects the parsing of migration HMP commands so make the necessary additions there too.

From this point on, both QMP and HMP versions of migrate-set-parameters and query-migrate-parameters gain the ability to work with capabilities.

Quoted 7 lines

With MigrationParameters now having members for each capability, the migration capabilities commands (query-migrate-capabilities, migrate-set-capabilities) will soon be deprecated. Add a set of helpers to convert between the old MigrationCapability representation and the new representation as members of MigrationParameters.

Signature · 1 line
Peter Xu
#50 lore raw

PATCH 16/21 qapi/migration: Mark that query/set-migrate-parameters support capabilities

In reply to Fabiano Rosas

Add a QAPI command feature "capabilities" that can be queried by the client to check that the parameters commands now also support capabilities.

---
 qapi/migration.json | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
qapi/migration.json +18 -2
index 5942622ba7..557a9c523e 100644
@@ -776,6 +776,13 @@
 #
 # Set various migration parameters.
 #
+# Features:
+#
+# @capabilities: Indicates this command supports setting the set of
+# parameters previously known as capabilities.  This means this
+# command can (and should) be used instead of the depreacated
+# @migrate-set-capabilities.
+#
 # Since: 2.4
 #
 # .. qmp-example::
@@ -785,7 +792,8 @@
 #     <- { "return": {} }
 ##
 { 'command': 'migrate-set-parameters', 'boxed': true,
-  'data': 'MigrationParameters' }
+  'data': 'MigrationParameters',
+  'features': [ 'capabilities' ] }
 
 ##
 # @MigrationParameters:
@@ -1110,6 +1118,13 @@
 #
 # Returns: @MigrationParameters
 #
+# Features:
+#
+# @capabilities: Indicates this command supports setting the set of
+# parameters previously known as capabilities.  This means this
+# command can (and should) be used instead of the depreacated
+# @migrate-set-capabilities.
+#
 # Since: 2.4
 #
 # .. qmp-example::
@@ -1125,7 +1140,8 @@
 #        }
 ##
 { 'command': 'query-migrate-parameters',
-  'returns': 'MigrationParameters' }
+  'returns': 'MigrationParameters',
+  'features': [ 'capabilities' ] }
 
 ##
 # @migrate-start-postcopy:
Signature · 1 line
2.35.3
#51 lore raw

Re: [PATCH 16/21] qapi/migration: Mark that query/set-migrate-parameters support capabilities

Quoted 52 lines · Fabiano Rosas

Add a QAPI command feature "capabilities" that can be queried by the client to check that the parameters commands now also support capabilities.

---
 qapi/migration.json | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
qapi/migration.json +16 -1
index 5942622ba7..557a9c523e 100644
@@ -776,6 +776,13 @@
 #
 # Set various migration parameters.
 #
+# Features:
+#
+# @capabilities: Indicates this command supports setting the set of
+# parameters previously known as capabilities.  This means this
+# command can (and should) be used instead of the depreacated
+# @migrate-set-capabilities.
+#
 # Since: 2.4
 #
 # .. qmp-example::
@@ -785,7 +792,8 @@
 #     <- { "return": {} }
 ##
 { 'command': 'migrate-set-parameters', 'boxed': true,
-  'data': 'MigrationParameters' }
+  'data': 'MigrationParameters',
+  'features': [ 'capabilities' ] }
 
 ##
 # @MigrationParameters:
@@ -1110,6 +1118,13 @@
 #
 # Returns: @MigrationParameters
 #
+# Features:
+#
+# @capabilities: Indicates this command supports setting the set of
+# parameters previously known as capabilities.  This means this
+# command can (and should) be used instead of the depreacated
+# @migrate-set-capabilities.
+#
 # Since: 2.4
 #
 # .. qmp-example::

qapi/migration.json line 1145

Quoted 7 lines
qapi/migration.json +2 -1
@@ -1125,7 +1140,8 @@
 #        }
 ##
 { 'command': 'query-migrate-parameters',
-  'returns': 'MigrationParameters' }
+  'returns': 'MigrationParameters',
+  'features': [ 'capabilities' ] }
 

Adding QAPI "features" is only needed if there is no other viable way to detect existence of the feature. In this case, apps can trivially detect the feature by querying the QAPI schema and identifying that the MigrationParameters struct has gained a load of new fields. So IMHO this patch can be dropped.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#52 lore raw

Re: [PATCH 16/21] qapi/migration: Mark that query/set-migrate-parameters support capabilities

Quoted 58 lines · Daniel P. Berrangé
Quoted 57 lines · Fabiano Rosas

Add a QAPI command feature "capabilities" that can be queried by the client to check that the parameters commands now also support capabilities.

---
 qapi/migration.json | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)
qapi/migration.json +17 -2
index 5942622ba7..557a9c523e 100644
@@ -776,6 +776,13 @@
 #
 # Set various migration parameters.
 #
+# Features:
+#
+# @capabilities: Indicates this command supports setting the set of
+# parameters previously known as capabilities.  This means this
+# command can (and should) be used instead of the depreacated
+# @migrate-set-capabilities.
+#
 # Since: 2.4
 #
 # .. qmp-example::
@@ -785,7 +792,8 @@
 #     <- { "return": {} }
 ##
 { 'command': 'migrate-set-parameters', 'boxed': true,
-  'data': 'MigrationParameters' }
+  'data': 'MigrationParameters',
+  'features': [ 'capabilities' ] }
 
 ##
 # @MigrationParameters:
@@ -1110,6 +1118,13 @@
 #
 # Returns: @MigrationParameters
 #
+# Features:
+#
+# @capabilities: Indicates this command supports setting the set of
+# parameters previously known as capabilities.  This means this
+# command can (and should) be used instead of the depreacated
+# @migrate-set-capabilities.
+#
 # Since: 2.4
 #
 # .. qmp-example::
@@ -1125,7 +1140,8 @@
 #        }
 ##
 { 'command': 'query-migrate-parameters',
-  'returns': 'MigrationParameters' }
+  'returns': 'MigrationParameters',
Quoted 9 lines

qapi/migration.json line 1145

Quoted 2 lines
qapi/migration.json +1 -0
+  'features': [ 'capabilities' ] }
 

Adding QAPI "features" is only needed if there is no other viable way to detect existence of the feature. In this case, apps can trivially detect the feature by querying the QAPI schema and identifying that the MigrationParameters struct has gained a load of new fields. So IMHO this patch can be dropped.

Oh, ok. I was thinking this would be friendlier to the management layer, but if it's all the same I'll drop it. Same for the other one in patch 19.

Thanks

#53 lore raw

PATCH 17/21 migration: Remove s->capabilities

In reply to Fabiano Rosas

Last patch added capabilities to s->parameters. Now we can replace all instances of s->capabilities with s->parameters:

- The -global properties now get set directly in s->parameters.

- Accessors from options.c now read from s->parameters.

- migrate_caps_check() now takes a MigrationParameters object. The function is still kept around because migrate-set-capabilities will still use it.

- The machinery for background-snapshot compatibility check goes away. We can check each capability by name (if s->parameters.cap ...)

- savevm uses the helper functions introduced in the last patch to do validation of capabilities found on the migration stream.

---
 migration/migration.c |  22 +---
 migration/migration.h |   1 -
 migration/options.c   | 285 ++++++++++++++++++------------------------
 migration/options.h   |  20 +--
 migration/savevm.c    |   8 +-
 5 files changed, 133 insertions(+), 203 deletions(-)
migration/migration.c +4 -18
index efb1dbb0c4..75c4ec9a95 100644
@@ -266,9 +266,10 @@ static bool
 migration_capabilities_and_transport_compatible(MigrationAddress *addr,
                                                 Error **errp)
 {
+    MigrationState *s = migrate_get_current();
+
     if (addr->transport == MIGRATION_ADDRESS_TYPE_RDMA) {
-        return migrate_rdma_caps_check(migrate_get_current()->capabilities,
-                                       errp);
+        return migrate_rdma_caps_check(&s->parameters, errp);
     }
 
     return true;
@@ -4091,22 +4092,7 @@ static void migration_instance_init(Object *obj)
  */
 static bool migration_object_check(MigrationState *ms, Error **errp)
 {
-    /* Assuming all off */
-    bool old_caps[MIGRATION_CAPABILITY__MAX] = { 0 };
-
-    if (!migrate_params_check(&ms->parameters, errp)) {
-        return false;
-    }
-
-    /*
-     * FIXME: Temporarily while -global capabilties are still using
-     * s->capabilities. Will be gone by the end of the series.
-     */
-    for (int i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
-        migrate_capability_set_compat(&ms->parameters, i, ms->capabilities[i]);
-    }
-
-    return migrate_caps_check(old_caps, ms->capabilities, errp);
+    return migrate_params_check(&ms->parameters, errp);
 }
 
 static const TypeInfo migration_type = {
migration/migration.h +0 -1
index ab797540b0..993d51aedd 100644
@@ -358,7 +358,6 @@ struct MigrationState {
     int64_t downtime_start;
     int64_t downtime;
     int64_t expected_downtime;
-    bool capabilities[MIGRATION_CAPABILITY__MAX];
     int64_t setup_time;
 
     /*
migration/options.c +121 -164

583 lines not on this page · raw message

migration/options.h +3 -17
index cac9201a5e..fcfd120cd7 100644
@@ -1,5 +1,5 @@
 /*
- * QEMU migration capabilities
+ * QEMU migration options
  *
  * Copyright (c) 2012-2023 Red Hat Inc
  *
@@ -23,8 +23,6 @@
 extern const Property migration_properties[];
 extern const size_t migration_properties_count;
 
-/* capabilities */
-
 bool migrate_auto_converge(void);
 bool migrate_colo(void);
 bool migrate_dirty_bitmaps(void);
@@ -43,22 +41,12 @@ bool migrate_validate_uuid(void);
 bool migrate_xbzrle(void);
 bool migrate_zero_copy_send(void);
 
-/*
- * pseudo capabilities
- *
- * These are functions that are used in a similar way to capabilities
- * check, but they are not a capability.
- */
-
 bool migrate_multifd_flush_after_each_section(void);
 bool migrate_postcopy(void);
 bool migrate_rdma(void);
 bool migrate_tls(void);
 
-/* capabilities helpers */
-
-bool migrate_rdma_caps_check(bool *caps, Error **errp);
-bool migrate_caps_check(bool *old_caps, bool *new_caps, Error **errp);
+bool migrate_rdma_caps_check(MigrationParameters *config, Error **errp);
 
 /* parameters */
 
@@ -87,14 +75,12 @@ const char *migrate_tls_hostname(void);
 uint64_t migrate_xbzrle_cache_size(void);
 ZeroPageDetection migrate_zero_page_detection(void);
 
-/* parameters helpers */
-
 bool migrate_params_check(MigrationParameters *params, Error **errp);
-void migrate_params_init(MigrationParameters *params);
 void migrate_tls_opts_free(MigrationParameters *params);
 bool migrate_capability_get_compat(MigrationParameters *params, int i);
 void migrate_capability_set_compat(MigrationParameters *params, int i,
                                    bool val);
 void migrate_capabilities_set_compat(MigrationParameters *params,
                                      MigrationCapabilityStatusList *caps);
+bool migrate_caps_check(MigrationParameters *new, Error **errp);
 #endif
migration/savevm.c +5 -3
index 006514c3e3..e052a4ff97 100644
@@ -291,7 +291,8 @@ static uint32_t get_validatable_capabilities_count(void)
     uint32_t result = 0;
     int i;
     for (i = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
-        if (should_validate_capability(i) && s->capabilities[i]) {
+        if (should_validate_capability(i) &&
+            migrate_capability_get_compat(&s->parameters, i)) {
             result++;
         }
     }
@@ -313,7 +314,8 @@ static int configuration_pre_save(void *opaque)
     state->capabilities = g_renew(MigrationCapability, state->capabilities,
                                   state->caps_count);
     for (i = j = 0; i < MIGRATION_CAPABILITY__MAX; i++) {
-        if (should_validate_capability(i) && s->capabilities[i]) {
+        if (should_validate_capability(i) &&
+            migrate_capability_get_compat(&s->parameters, i)) {
             state->capabilities[j++] = i;
         }
     }
@@ -363,7 +365,7 @@ static bool configuration_validate_capabilities(SaveState *state)
             continue;
         }
         source_state = test_bit(i, source_caps_bm);
-        target_state = s->capabilities[i];
+        target_state = migrate_capability_get_compat(&s->parameters, i);
         if (source_state != target_state) {
             error_report("Capability %s is %s, but received capability is %s",
                          MigrationCapability_str(i),
Signature · 1 line
2.35.3
Reviewed-by on v1 17/21
#54 lore raw

Re: [PATCH 17/21] migration: Remove s->capabilities

Quoted 11 lines · Fabiano Rosas

Last patch added capabilities to s->parameters. Now we can replace all instances of s->capabilities with s->parameters:

- The -global properties now get set directly in s->parameters.

- Accessors from options.c now read from s->parameters.

- migrate_caps_check() now takes a MigrationParameters object. The function is still kept around because migrate-set-capabilities will still use it.

Quoted 7 lines

- The machinery for background-snapshot compatibility check goes away. We can check each capability by name (if s->parameters.cap ...)

- savevm uses the helper functions introduced in the last patch to do validation of capabilities found on the migration stream.

Signature · 1 line
Peter Xu
#55 lore raw

PATCH 18/21 qapi/migration: Deprecate capabilities commands

In reply to Fabiano Rosas

The concept of capabilities is being merged into the concept of parameters. From now on, the commands that handle capabilities are deprecated in favor of the commands that handle parameters.

Affected commands:

- migrate-set-capabilities
- query-migrate-capabilities

---
 docs/about/deprecated.rst      | 12 ++++++++++++
 migration/migration-hmp-cmds.c |  6 ++++++
 qapi/migration.json            | 16 ++++++++++++++--
 3 files changed, 32 insertions(+), 2 deletions(-)
docs/about/deprecated.rst +12 -0
index 42037131de..15474833ea 100644
@@ -605,3 +605,15 @@ command documentation for details on the ``fdset`` usage.
 
 The ``zero-blocks`` capability was part of the block migration which
 doesn't exist anymore since it was removed in QEMU v9.1.
+
+``migrate-set-capabilities`` command (since 10.1)
+'''''''''''''''''''''''''''''''''''''''''''''''''
+
+This command was deprecated. Use ``migrate-set-parameters`` instead
+which now supports setting capabilities.
+
+``query-migrate-capabilities`` command (since 10.1)
+'''''''''''''''''''''''''''''''''''''''''''''''''''
+
+This command was deprecated. Use ``query-migrate-parameters`` instead
+which now supports querying capabilities.
migration/migration-hmp-cmds.c +6 -0
index 6d8d189b81..a8c3515e9d 100644
@@ -229,6 +229,9 @@ void hmp_info_migrate_capabilities(Monitor *mon, const QDict *qdict)
 {
     MigrationCapabilityStatusList *caps, *cap;
 
+    warn_report("info migrate_capabilities is deprecated;"
+                " use info migrate_parameters instead");
+
     caps = qmp_query_migrate_capabilities(NULL);
 
     if (caps) {
@@ -608,6 +611,9 @@ void hmp_migrate_set_capability(Monitor *mon, const QDict *qdict)
     MigrationCapabilityStatus *value;
     int val;
 
+    warn_report("migrate_set_capability is deprecated;"
+                " use migrate_set_parameter instead");
+
     val = qapi_enum_parse(&MigrationCapability_lookup, cap, -1, &err);
     if (val < 0) {
         goto end;
qapi/migration.json +14 -2
index 557a9c523e..7282e4b9eb 100644
@@ -521,6 +521,11 @@
 #
 # @capabilities: json array of capability modifications to make
 #
+# Features:
+#
+# @deprecated: This command is deprecated in favor of
+# migrate-set-parameters.
+#
 # Since: 1.2
 #
 # .. qmp-example::
@@ -530,7 +535,8 @@
 #     <- { "return": {} }
 ##
 { 'command': 'migrate-set-capabilities',
-  'data': { 'capabilities': ['MigrationCapabilityStatus'] } }
+  'data': { 'capabilities': ['MigrationCapabilityStatus'] },
+  'features': ['deprecated'] }
 
 ##
 # @query-migrate-capabilities:
@@ -539,6 +545,11 @@
 #
 # Returns: @MigrationCapabilityStatus
 #
+# Features:
+#
+# @deprecated: This command is deprecated in favor of
+# query-migrate-parameters.
+#
 # Since: 1.2
 #
 # .. qmp-example::
@@ -554,7 +565,8 @@
 #           {"state": false, "capability": "x-colo"}
 #        ]}
 ##
-{ 'command': 'query-migrate-capabilities', 'returns':   ['MigrationCapabilityStatus']}
+{ 'command': 'query-migrate-capabilities', 'returns':   ['MigrationCapabilityStatus'],
+  'features': ['deprecated'] }
 
 ##
 # @MultiFDCompression:
Signature · 1 line
2.35.3
Reviewed-by on v1 18/21
#56 lore raw

Re: [PATCH 18/21] qapi/migration: Deprecate capabilities commands

Quoted 10 lines · Fabiano Rosas

The concept of capabilities is being merged into the concept of parameters. From now on, the commands that handle capabilities are deprecated in favor of the commands that handle parameters.

Affected commands:

- migrate-set-capabilities
- query-migrate-capabilities

Signature · 1 line
Peter Xu
#57 lore raw

PATCH 19/21 migration: Allow migrate commands to provide the migration config

In reply to Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

The options that are changed during the migration can still be set with the existing commands.

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

I.e. the config takes precedence over all, values not present in the config assume the default values. The (debug) -global command line option allows the defaults to be overridden.

---
 migration/migration-hmp-cmds.c |  5 +++--
 migration/migration.c          | 29 ++++++++++++++++++++++++++---
 migration/migration.h          |  1 +
 migration/options.c            | 30 ++++++++++++++++++++++++++++++
 migration/options.h            |  3 +++
 qapi/migration.json            | 25 +++++++++++++++++++++++--
 system/vl.c                    |  3 ++-
 7 files changed, 88 insertions(+), 8 deletions(-)
migration/migration-hmp-cmds.c +3 -2
index a8c3515e9d..38b289e8d8 100644
@@ -575,7 +575,7 @@ void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
     }
     QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel));
 
-    qmp_migrate_incoming(NULL, true, caps, true, false, &err);
+    qmp_migrate_incoming(NULL, true, caps, NULL, true, false, &err);
     qapi_free_MigrationChannelList(caps);
 
 end:
@@ -952,7 +952,8 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     }
     QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel));
 
-    qmp_migrate(NULL, true, caps, false, false, true, resume, &err);
+    qmp_migrate(NULL, true, caps, NULL, false, false, true, resume,
+                &err);
     if (hmp_handle_error(mon, err)) {
         return;
     }
migration/migration.c +26 -3
index 75c4ec9a95..7b450b8836 100644
@@ -335,6 +335,7 @@ void migration_object_init(void)
     current_incoming->exit_on_error = INMIGRATE_DEFAULT_EXIT_ON_ERROR;
 
     migration_object_check(current_migration, &error_fatal);
+    migrate_params_store_defaults(current_migration);
 
     ram_mig_init();
     dirty_bitmap_mig_init();
@@ -1916,13 +1917,24 @@ void migrate_del_blocker(Error **reasonp)
 
 void qmp_migrate_incoming(const char *uri, bool has_channels,
                           MigrationChannelList *channels,
-                          bool has_exit_on_error, bool exit_on_error,
-                          Error **errp)
+                          MigrationParameters *config, bool has_exit_on_error,
+                          bool exit_on_error, Error **errp)
 {
     Error *local_err = NULL;
     static bool once = true;
+    MigrationState *s = migrate_get_current();
     MigrationIncomingState *mis = migration_incoming_get_current();
 
+    if (config) {
+        /*
+         * If a config was provided, all options set previously get
+         * ignored.
+         */
+        if (!migrate_params_override(s, config, errp)) {
+            return;
+        }
+    }
+
     if (!once) {
         error_setg(errp, "The incoming migration has already been started");
         return;
@@ -2182,7 +2194,8 @@ static gboolean qmp_migrate_finish_cb(QIOChannel *channel,
 }
 
 void qmp_migrate(const char *uri, bool has_channels,
-                 MigrationChannelList *channels, bool has_detach, bool detach,
+                 MigrationChannelList *channels,
+                 bool has_detach, bool detach, MigrationParameters *config,
                  bool has_resume, bool resume, Error **errp)
 {
     bool resume_requested;
@@ -2193,6 +2206,16 @@ void qmp_migrate(const char *uri, bool has_channels,
     MigrationChannel *channelv[MIGRATION_CHANNEL_TYPE__MAX] = { NULL };
     MigrationChannel *cpr_channel = NULL;
 
+    if (config) {
+        /*
+         * If a config was provided, all options set previously get
+         * ignored.
+         */
+        if (!migrate_params_override(s, config, errp)) {
+            return;
+        }
+    }
+
     /*
      * Having preliminary checks for uri and channel
      */
migration/migration.h +1 -0
index 993d51aedd..49761f4699 100644
@@ -319,6 +319,7 @@ struct MigrationState {
 
     /* params from 'migrate-set-parameters' */
     MigrationParameters parameters;
+    MigrationParameters defaults;
 
     MigrationStatus state;
 
migration/options.c +30 -0
index fa3f7035c8..dd2288187d 100644
@@ -1333,6 +1333,36 @@ static void migrate_params_apply(MigrationParameters *params)
                                            params->block_bitmap_mapping);
 }
 
+void migrate_params_store_defaults(MigrationState *s)
+{
+    /*
+     * The defaults set for each qdev property in migration_properties
+     * will be stored as the default values for each migration
+     * parameter. For debugging, using -global can override the
+     * defaults.
+     */
+    QAPI_CLONE_MEMBERS(MigrationParameters, &s->defaults, &s->parameters);
+}
+
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp)
+{
+    ERRP_GUARD();
+
+    assert(bql_locked());
+
+    /* reset to default parameters */
+    migrate_params_apply(&s->defaults);
+
+    /* overwrite with the new ones */
+    qmp_migrate_set_parameters(new, errp);
+    if (*errp) {
+        return false;
+    }
+
+    return true;
+}
+
 void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
 {
     MigrationParameters *tmp = g_new0(MigrationParameters, 1);
migration/options.h +3 -0
index fcfd120cd7..3630c2a0dd 100644
@@ -83,4 +83,7 @@ void migrate_capability_set_compat(MigrationParameters *params, int i,
 void migrate_capabilities_set_compat(MigrationParameters *params,
                                      MigrationCapabilityStatusList *caps);
 bool migrate_caps_check(MigrationParameters *new, Error **errp);
+void migrate_params_store_defaults(MigrationState *s);
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp);
 #endif
qapi/migration.json +23 -2
index 7282e4b9eb..64a92d8d28 100644
@@ -1474,9 +1474,16 @@
 #
 # @resume: resume one paused migration, default "off".  (since 3.0)
 #
+# @config: migration configuration options, previously set via
+#     @migrate-set-parameters and @migrate-set-capabilities.  (since
+#     10.1)
+#
 # Features:
 #
 # @deprecated: Argument @detach is deprecated.
+# @config: Indicates this command can receive the entire migration
+# configuration via the @config field, dispensing the use of
+# @migrate-set-parameters.
 #
 # Since: 0.14
 #
@@ -1538,7 +1545,9 @@
   'data': {'*uri': 'str',
            '*channels': [ 'MigrationChannel' ],
            '*detach': { 'type': 'bool', 'features': [ 'deprecated' ] },
-           '*resume': 'bool' } }
+           '*config': 'MigrationParameters',
+           '*resume': 'bool' },
+  'features': [ 'config' ] }
 
 ##
 # @migrate-incoming:
@@ -1557,6 +1566,16 @@
 #     error details could be retrieved with query-migrate.
 #     (since 9.1)
 #
+# @config: migration configuration options, previously set via
+#     @migrate-set-parameters and @migrate-set-capabilities.  (since
+#     10.1)
+#
+# Features:
+#
+# @config: Indicates this command can receive the entire migration
+# configuration via the @config field, dispensing the use of
+# @migrate-set-parameters.
+#
 # Since: 2.3
 #
 # .. admonition:: Notes
@@ -1610,7 +1629,9 @@
 { 'command': 'migrate-incoming',
              'data': {'*uri': 'str',
                       '*channels': [ 'MigrationChannel' ],
-                      '*exit-on-error': 'bool' } }
+                      '*config': 'MigrationParameters',
+                      '*exit-on-error': 'bool' },
+             'features': [ 'config' ] }
 
 ##
 # @xen-save-devices-state:
system/vl.c +2 -1
index 3b7057e6c6..b29fd24d08 100644
@@ -2823,7 +2823,8 @@ void qmp_x_exit_preconfig(Error **errp)
                 g_new0(MigrationChannelList, 1);
 
             channels->value = incoming_channels[MIGRATION_CHANNEL_TYPE_MAIN];
-            qmp_migrate_incoming(NULL, true, channels, true, true, &local_err);
+            qmp_migrate_incoming(NULL, true, channels, NULL, true, true,
+                                 &local_err);
             if (local_err) {
                 error_reportf_err(local_err, "-incoming %s: ", incoming);
                 exit(1);
Signature · 1 line
2.35.3
#58 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 39 lines · Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

The options that are changed during the migration can still be set with the existing commands.

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

I.e. the config takes precedence over all, values not present in the config assume the default values. The (debug) -global command line option allows the defaults to be overridden.

---
 migration/migration-hmp-cmds.c |  5 +++--
 migration/migration.c          | 29 ++++++++++++++++++++++++++---
 migration/migration.h          |  1 +
 migration/options.c            | 30 ++++++++++++++++++++++++++++++
 migration/options.h            |  3 +++
 qapi/migration.json            | 25 +++++++++++++++++++++++--
 system/vl.c                    |  3 ++-
 7 files changed, 88 insertions(+), 8 deletions(-)
qapi/migration.json +0 -0
index 7282e4b9eb..64a92d8d28 100644
@@ -1474,9 +1474,16 @@
 #
 # @resume: resume one paused migration, default "off".  (since 3.0)
 #

qapi/migration.json line 1486

Quoted 10 lines
qapi/migration.json +7 -0
+# @config: migration configuration options, previously set via
+#     @migrate-set-parameters and @migrate-set-capabilities.  (since
+#     10.1)
+#
 # Features:
 #
 # @deprecated: Argument @detach is deprecated.
+# @config: Indicates this command can receive the entire migration
+# configuration via the @config field, dispensing the use of
+# @migrate-set-parameters.

There is no need to add this feature - mgmt apps can identify this simply by the fact that the 'config' parameter now exists in the QAPI schema.

Quoted 17 lines
qapi/migration.json +3 -1
 #
 # Since: 0.14
 #
@@ -1538,7 +1545,9 @@
   'data': {'*uri': 'str',
            '*channels': [ 'MigrationChannel' ],
            '*detach': { 'type': 'bool', 'features': [ 'deprecated' ] },
-           '*resume': 'bool' } }
+           '*config': 'MigrationParameters',
+           '*resume': 'bool' },
+  'features': [ 'config' ] }
 
 ##
 # @migrate-incoming:
@@ -1557,6 +1566,16 @@
 #     error details could be retrieved with query-migrate.
 #     (since 9.1)

qapi/migration.json line 1577

Quoted 10 lines
qapi/migration.json +9 -0
 #
+# @config: migration configuration options, previously set via
+#     @migrate-set-parameters and @migrate-set-capabilities.  (since
+#     10.1)
+#
+# Features:
+#
+# @config: Indicates this command can receive the entire migration
+# configuration via the @config field, dispensing the use of
+# @migrate-set-parameters.

Likewise redundant.

Quoted 5 lines
qapi/migration.json +1 -0
+#
 # Since: 2.3
 #
 # .. admonition:: Notes

qapi/migration.json line 1637

Quoted 10 lines
qapi/migration.json +3 -1
@@ -1610,7 +1629,9 @@
 { 'command': 'migrate-incoming',
              'data': {'*uri': 'str',
                       '*channels': [ 'MigrationChannel' ],
-                      '*exit-on-error': 'bool' } }
+                      '*config': 'MigrationParameters',
+                      '*exit-on-error': 'bool' },
+             'features': [ 'config' ] }
 
 ##
 # @xen-save-devices-state:

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#59 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

In reply to Fabiano Rosas
Quoted 9 lines · Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

Quoted 6 lines

The options that are changed during the migration can still be set with the existing commands.

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

Could we still keep the QMP migrate-set-parameters values?

'config' argument > QMP setups using migrate-set-parameters >
-global cmdline > defaults (migration_properties)

I asked this before, maybe I forgot the answer..

Quoted 110 lines

I.e. the config takes precedence over all, values not present in the config assume the default values. The (debug) -global command line option allows the defaults to be overridden.

---
 migration/migration-hmp-cmds.c |  5 +++--
 migration/migration.c          | 29 ++++++++++++++++++++++++++---
 migration/migration.h          |  1 +
 migration/options.c            | 30 ++++++++++++++++++++++++++++++
 migration/options.h            |  3 +++
 qapi/migration.json            | 25 +++++++++++++++++++++++--
 system/vl.c                    |  3 ++-
 7 files changed, 88 insertions(+), 8 deletions(-)
migration/migration-hmp-cmds.c +3 -2
index a8c3515e9d..38b289e8d8 100644
@@ -575,7 +575,7 @@ void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
     }
     QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel));
 
-    qmp_migrate_incoming(NULL, true, caps, true, false, &err);
+    qmp_migrate_incoming(NULL, true, caps, NULL, true, false, &err);
     qapi_free_MigrationChannelList(caps);
 
 end:
@@ -952,7 +952,8 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     }
     QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel));
 
-    qmp_migrate(NULL, true, caps, false, false, true, resume, &err);
+    qmp_migrate(NULL, true, caps, NULL, false, false, true, resume,
+                &err);
     if (hmp_handle_error(mon, err)) {
         return;
     }
migration/migration.c +26 -3
index 75c4ec9a95..7b450b8836 100644
@@ -335,6 +335,7 @@ void migration_object_init(void)
     current_incoming->exit_on_error = INMIGRATE_DEFAULT_EXIT_ON_ERROR;
 
     migration_object_check(current_migration, &error_fatal);
+    migrate_params_store_defaults(current_migration);
 
     ram_mig_init();
     dirty_bitmap_mig_init();
@@ -1916,13 +1917,24 @@ void migrate_del_blocker(Error **reasonp)
 
 void qmp_migrate_incoming(const char *uri, bool has_channels,
                           MigrationChannelList *channels,
-                          bool has_exit_on_error, bool exit_on_error,
-                          Error **errp)
+                          MigrationParameters *config, bool has_exit_on_error,
+                          bool exit_on_error, Error **errp)
 {
     Error *local_err = NULL;
     static bool once = true;
+    MigrationState *s = migrate_get_current();
     MigrationIncomingState *mis = migration_incoming_get_current();
 
+    if (config) {
+        /*
+         * If a config was provided, all options set previously get
+         * ignored.
+         */
+        if (!migrate_params_override(s, config, errp)) {
+            return;
+        }
+    }
+
     if (!once) {
         error_setg(errp, "The incoming migration has already been started");
         return;
@@ -2182,7 +2194,8 @@ static gboolean qmp_migrate_finish_cb(QIOChannel *channel,
 }
 
 void qmp_migrate(const char *uri, bool has_channels,
-                 MigrationChannelList *channels, bool has_detach, bool detach,
+                 MigrationChannelList *channels,
+                 bool has_detach, bool detach, MigrationParameters *config,
                  bool has_resume, bool resume, Error **errp)
 {
     bool resume_requested;
@@ -2193,6 +2206,16 @@ void qmp_migrate(const char *uri, bool has_channels,
     MigrationChannel *channelv[MIGRATION_CHANNEL_TYPE__MAX] = { NULL };
     MigrationChannel *cpr_channel = NULL;
 
+    if (config) {
+        /*
+         * If a config was provided, all options set previously get
+         * ignored.
+         */
+        if (!migrate_params_override(s, config, errp)) {
+            return;
+        }
+    }
+
     /*
      * Having preliminary checks for uri and channel
      */
migration/migration.h +0 -0
index 993d51aedd..49761f4699 100644

migration/migration.h struct MigrationState { · line 322

Quoted 4 lines
migration/migration.h +1 -0
@@ -319,6 +319,7 @@ struct MigrationState {
 
     /* params from 'migrate-set-parameters' */
     MigrationParameters parameters;
+    MigrationParameters defaults;

This is also prone to be a pointer; I still think embeded qapi objects are too error prone. Since it's new, make it a pointer from start?

Quoted 133 lines
migration/migration.h +0 -0
     MigrationStatus state;
 
migration/options.c +30 -0
index fa3f7035c8..dd2288187d 100644
@@ -1333,6 +1333,36 @@ static void migrate_params_apply(MigrationParameters *params)
                                            params->block_bitmap_mapping);
 }
 
+void migrate_params_store_defaults(MigrationState *s)
+{
+    /*
+     * The defaults set for each qdev property in migration_properties
+     * will be stored as the default values for each migration
+     * parameter. For debugging, using -global can override the
+     * defaults.
+     */
+    QAPI_CLONE_MEMBERS(MigrationParameters, &s->defaults, &s->parameters);
+}
+
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp)
+{
+    ERRP_GUARD();
+
+    assert(bql_locked());
+
+    /* reset to default parameters */
+    migrate_params_apply(&s->defaults);
+
+    /* overwrite with the new ones */
+    qmp_migrate_set_parameters(new, errp);
+    if (*errp) {
+        return false;
+    }
+
+    return true;
+}
+
 void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
 {
     MigrationParameters *tmp = g_new0(MigrationParameters, 1);
migration/options.h +3 -0
index fcfd120cd7..3630c2a0dd 100644
@@ -83,4 +83,7 @@ void migrate_capability_set_compat(MigrationParameters *params, int i,
 void migrate_capabilities_set_compat(MigrationParameters *params,
                                      MigrationCapabilityStatusList *caps);
 bool migrate_caps_check(MigrationParameters *new, Error **errp);
+void migrate_params_store_defaults(MigrationState *s);
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp);
 #endif
qapi/migration.json +23 -2
index 7282e4b9eb..64a92d8d28 100644
@@ -1474,9 +1474,16 @@
 #
 # @resume: resume one paused migration, default "off".  (since 3.0)
 #
+# @config: migration configuration options, previously set via
+#     @migrate-set-parameters and @migrate-set-capabilities.  (since
+#     10.1)
+#
 # Features:
 #
 # @deprecated: Argument @detach is deprecated.
+# @config: Indicates this command can receive the entire migration
+# configuration via the @config field, dispensing the use of
+# @migrate-set-parameters.
 #
 # Since: 0.14
 #
@@ -1538,7 +1545,9 @@
   'data': {'*uri': 'str',
            '*channels': [ 'MigrationChannel' ],
            '*detach': { 'type': 'bool', 'features': [ 'deprecated' ] },
-           '*resume': 'bool' } }
+           '*config': 'MigrationParameters',
+           '*resume': 'bool' },
+  'features': [ 'config' ] }
 
 ##
 # @migrate-incoming:
@@ -1557,6 +1566,16 @@
 #     error details could be retrieved with query-migrate.
 #     (since 9.1)
 #
+# @config: migration configuration options, previously set via
+#     @migrate-set-parameters and @migrate-set-capabilities.  (since
+#     10.1)
+#
+# Features:
+#
+# @config: Indicates this command can receive the entire migration
+# configuration via the @config field, dispensing the use of
+# @migrate-set-parameters.
+#
 # Since: 2.3
 #
 # .. admonition:: Notes
@@ -1610,7 +1629,9 @@
 { 'command': 'migrate-incoming',
              'data': {'*uri': 'str',
                       '*channels': [ 'MigrationChannel' ],
-                      '*exit-on-error': 'bool' } }
+                      '*config': 'MigrationParameters',
+                      '*exit-on-error': 'bool' },
+             'features': [ 'config' ] }
 
 ##
 # @xen-save-devices-state:
system/vl.c +2 -1
index 3b7057e6c6..b29fd24d08 100644
@@ -2823,7 +2823,8 @@ void qmp_x_exit_preconfig(Error **errp)
                 g_new0(MigrationChannelList, 1);
 
             channels->value = incoming_channels[MIGRATION_CHANNEL_TYPE_MAIN];
-            qmp_migrate_incoming(NULL, true, channels, true, true, &local_err);
+            qmp_migrate_incoming(NULL, true, channels, NULL, true, true,
+                                 &local_err);
             if (local_err) {
                 error_reportf_err(local_err, "-incoming %s: ", incoming);
                 exit(1);
Signature · 1 line
2.35.3
Signature · 1 line
Peter Xu
#60 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 13 lines · Peter Xu
Quoted 12 lines · Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

The options that are changed during the migration can still be set with the existing commands.

Quoted 9 lines
Quoted 3 lines

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

Could we still keep the QMP migrate-set-parameters values?

'config' argument > QMP setups using migrate-set-parameters >
-global cmdline > defaults (migration_properties)

That's the case. I failed to mention it in the commit message. IOW it behaves just like today, but the new 'config' way takes precedence over all.

Quoted 113 lines

I asked this before, maybe I forgot the answer..

Quoted 111 lines

I.e. the config takes precedence over all, values not present in the config assume the default values. The (debug) -global command line option allows the defaults to be overridden.

---
 migration/migration-hmp-cmds.c |  5 +++--
 migration/migration.c          | 29 ++++++++++++++++++++++++++---
 migration/migration.h          |  1 +
 migration/options.c            | 30 ++++++++++++++++++++++++++++++
 migration/options.h            |  3 +++
 qapi/migration.json            | 25 +++++++++++++++++++++++--
 system/vl.c                    |  3 ++-
 7 files changed, 88 insertions(+), 8 deletions(-)
migration/migration-hmp-cmds.c +3 -2
index a8c3515e9d..38b289e8d8 100644
@@ -575,7 +575,7 @@ void hmp_migrate_incoming(Monitor *mon, const QDict *qdict)
     }
     QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel));
 
-    qmp_migrate_incoming(NULL, true, caps, true, false, &err);
+    qmp_migrate_incoming(NULL, true, caps, NULL, true, false, &err);
     qapi_free_MigrationChannelList(caps);
 
 end:
@@ -952,7 +952,8 @@ void hmp_migrate(Monitor *mon, const QDict *qdict)
     }
     QAPI_LIST_PREPEND(caps, g_steal_pointer(&channel));
 
-    qmp_migrate(NULL, true, caps, false, false, true, resume, &err);
+    qmp_migrate(NULL, true, caps, NULL, false, false, true, resume,
+                &err);
     if (hmp_handle_error(mon, err)) {
         return;
     }
migration/migration.c +26 -3
index 75c4ec9a95..7b450b8836 100644
@@ -335,6 +335,7 @@ void migration_object_init(void)
     current_incoming->exit_on_error = INMIGRATE_DEFAULT_EXIT_ON_ERROR;
 
     migration_object_check(current_migration, &error_fatal);
+    migrate_params_store_defaults(current_migration);
 
     ram_mig_init();
     dirty_bitmap_mig_init();
@@ -1916,13 +1917,24 @@ void migrate_del_blocker(Error **reasonp)
 
 void qmp_migrate_incoming(const char *uri, bool has_channels,
                           MigrationChannelList *channels,
-                          bool has_exit_on_error, bool exit_on_error,
-                          Error **errp)
+                          MigrationParameters *config, bool has_exit_on_error,
+                          bool exit_on_error, Error **errp)
 {
     Error *local_err = NULL;
     static bool once = true;
+    MigrationState *s = migrate_get_current();
     MigrationIncomingState *mis = migration_incoming_get_current();
 
+    if (config) {
+        /*
+         * If a config was provided, all options set previously get
+         * ignored.
+         */
+        if (!migrate_params_override(s, config, errp)) {
+            return;
+        }
+    }
+
     if (!once) {
         error_setg(errp, "The incoming migration has already been started");
         return;
@@ -2182,7 +2194,8 @@ static gboolean qmp_migrate_finish_cb(QIOChannel *channel,
 }
 
 void qmp_migrate(const char *uri, bool has_channels,
-                 MigrationChannelList *channels, bool has_detach, bool detach,
+                 MigrationChannelList *channels,
+                 bool has_detach, bool detach, MigrationParameters *config,
                  bool has_resume, bool resume, Error **errp)
 {
     bool resume_requested;
@@ -2193,6 +2206,16 @@ void qmp_migrate(const char *uri, bool has_channels,
     MigrationChannel *channelv[MIGRATION_CHANNEL_TYPE__MAX] = { NULL };
     MigrationChannel *cpr_channel = NULL;
 
+    if (config) {
+        /*
+         * If a config was provided, all options set previously get
+         * ignored.
+         */
+        if (!migrate_params_override(s, config, errp)) {
+            return;
+        }
+    }
+
     /*
      * Having preliminary checks for uri and channel
      */
migration/migration.h +0 -0
index 993d51aedd..49761f4699 100644
@@ -319,6 +319,7 @@ struct MigrationState {
 
Quoted 7 lines

migration/migration.h struct MigrationState { · line 322

Quoted 3 lines
migration/migration.h +1 -0
     /* params from 'migrate-set-parameters' */
     MigrationParameters parameters;
+    MigrationParameters defaults;

This is also prone to be a pointer; I still think embeded qapi objects are too error prone. Since it's new, make it a pointer from start?

Ok.

Quoted 133 lines
Quoted 133 lines
migration/migration.h +0 -0
     MigrationStatus state;
 
migration/options.c +30 -0
index fa3f7035c8..dd2288187d 100644
@@ -1333,6 +1333,36 @@ static void migrate_params_apply(MigrationParameters *params)
                                            params->block_bitmap_mapping);
 }
 
+void migrate_params_store_defaults(MigrationState *s)
+{
+    /*
+     * The defaults set for each qdev property in migration_properties
+     * will be stored as the default values for each migration
+     * parameter. For debugging, using -global can override the
+     * defaults.
+     */
+    QAPI_CLONE_MEMBERS(MigrationParameters, &s->defaults, &s->parameters);
+}
+
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp)
+{
+    ERRP_GUARD();
+
+    assert(bql_locked());
+
+    /* reset to default parameters */
+    migrate_params_apply(&s->defaults);
+
+    /* overwrite with the new ones */
+    qmp_migrate_set_parameters(new, errp);
+    if (*errp) {
+        return false;
+    }
+
+    return true;
+}
+
 void qmp_migrate_set_parameters(MigrationParameters *params, Error **errp)
 {
     MigrationParameters *tmp = g_new0(MigrationParameters, 1);
migration/options.h +3 -0
index fcfd120cd7..3630c2a0dd 100644
@@ -83,4 +83,7 @@ void migrate_capability_set_compat(MigrationParameters *params, int i,
 void migrate_capabilities_set_compat(MigrationParameters *params,
                                      MigrationCapabilityStatusList *caps);
 bool migrate_caps_check(MigrationParameters *new, Error **errp);
+void migrate_params_store_defaults(MigrationState *s);
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp);
 #endif
qapi/migration.json +23 -2
index 7282e4b9eb..64a92d8d28 100644
@@ -1474,9 +1474,16 @@
 #
 # @resume: resume one paused migration, default "off".  (since 3.0)
 #
+# @config: migration configuration options, previously set via
+#     @migrate-set-parameters and @migrate-set-capabilities.  (since
+#     10.1)
+#
 # Features:
 #
 # @deprecated: Argument @detach is deprecated.
+# @config: Indicates this command can receive the entire migration
+# configuration via the @config field, dispensing the use of
+# @migrate-set-parameters.
 #
 # Since: 0.14
 #
@@ -1538,7 +1545,9 @@
   'data': {'*uri': 'str',
            '*channels': [ 'MigrationChannel' ],
            '*detach': { 'type': 'bool', 'features': [ 'deprecated' ] },
-           '*resume': 'bool' } }
+           '*config': 'MigrationParameters',
+           '*resume': 'bool' },
+  'features': [ 'config' ] }
 
 ##
 # @migrate-incoming:
@@ -1557,6 +1566,16 @@
 #     error details could be retrieved with query-migrate.
 #     (since 9.1)
 #
+# @config: migration configuration options, previously set via
+#     @migrate-set-parameters and @migrate-set-capabilities.  (since
+#     10.1)
+#
+# Features:
+#
+# @config: Indicates this command can receive the entire migration
+# configuration via the @config field, dispensing the use of
+# @migrate-set-parameters.
+#
 # Since: 2.3
 #
 # .. admonition:: Notes
@@ -1610,7 +1629,9 @@
 { 'command': 'migrate-incoming',
              'data': {'*uri': 'str',
                       '*channels': [ 'MigrationChannel' ],
-                      '*exit-on-error': 'bool' } }
+                      '*config': 'MigrationParameters',
+                      '*exit-on-error': 'bool' },
+             'features': [ 'config' ] }
 
 ##
 # @xen-save-devices-state:
system/vl.c +2 -1
index 3b7057e6c6..b29fd24d08 100644
@@ -2823,7 +2823,8 @@ void qmp_x_exit_preconfig(Error **errp)
                 g_new0(MigrationChannelList, 1);
 
             channels->value = incoming_channels[MIGRATION_CHANNEL_TYPE_MAIN];
-            qmp_migrate_incoming(NULL, true, channels, true, true, &local_err);
+            qmp_migrate_incoming(NULL, true, channels, NULL, true, true,
+                                 &local_err);
             if (local_err) {
                 error_reportf_err(local_err, "-incoming %s: ", incoming);
                 exit(1);
Signature · 1 line
2.35.3
#61 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 21 lines · Fabiano Rosas
Quoted 19 lines · Peter Xu
Quoted 9 lines · Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

Quoted 6 lines

The options that are changed during the migration can still be set with the existing commands.

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

Could we still keep the QMP migrate-set-parameters values?

Quoted 7 lines
Quoted 3 lines

'config' argument > QMP setups using migrate-set-parameters >
-global cmdline > defaults (migration_properties)

That's the case. I failed to mention it in the commit message. IOW it behaves just like today, but the new 'config' way takes precedence over all.

Referring to below chunk of code:

[...]

Quoted 9 lines
Quoted 9 lines

migration/options.c static void migrate_params_apply(MigrationParameters *params) · line 1355

Quoted 9 lines
migration/options.c +9 -0
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp)
+{
+    ERRP_GUARD();
+
+    assert(bql_locked());
+
+    /* reset to default parameters */
+    migrate_params_apply(&s->defaults);

IIUC here it'll reset all global parameters using the initial defaults first, then apply the "config" specified in "migrate" QMP command?

I think there're actually two separate questions to be asked, to make it clearer, they are:

(1) Whether we should allow QMP "migrate" 'config' parameter to overwrite global setup?

(2) Whether we should allow previous QMP global setup to be used even if QMP "migrate" provided 'config' parameter?

So IIUC the patch does (1) YES (2) NO, while what I think might be more intuitive is (1) NO (2) YES.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
migration/options.c +9 -0
+
+    /* overwrite with the new ones */
+    qmp_migrate_set_parameters(new, errp);
+    if (*errp) {
+        return false;
+    }
+
+    return true;
+}
Signature · 1 line
Peter Xu
#62 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 34 lines · Peter Xu
Quoted 21 lines · Fabiano Rosas
Quoted 19 lines · Peter Xu
Quoted 9 lines · Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

Quoted 6 lines

The options that are changed during the migration can still be set with the existing commands.

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

Could we still keep the QMP migrate-set-parameters values?

Quoted 7 lines
Quoted 3 lines

'config' argument > QMP setups using migrate-set-parameters >
-global cmdline > defaults (migration_properties)

That's the case. I failed to mention it in the commit message. IOW it behaves just like today, but the new 'config' way takes precedence over all.

Referring to below chunk of code:

[...]

Quoted 13 lines
Quoted 9 lines
Quoted 9 lines

migration/options.c static void migrate_params_apply(MigrationParameters *params) · line 1355

Quoted 9 lines
migration/options.c +9 -0
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp)
+{
+    ERRP_GUARD();
+
+    assert(bql_locked());
+
+    /* reset to default parameters */
+    migrate_params_apply(&s->defaults);

IIUC here it'll reset all global parameters using the initial defaults first, then apply the "config" specified in "migrate" QMP command?

Yes, this is so any previously set parameter via migrate-set-parameter gets erased. I think what we want (but feel free to disagree) is to have the migrate-set-parameter _eventually_ only handle parameters that need to be modifed during migration runtime. Anything else can be done via passing config to qmp_migrate.

For -global, I don't have a preference. Having -global take precedence over all would require a way to know which options were present in the command-line and which are just the defaults seet in migration_properties. I currently don't know how to do that. If it is at all possible (within reason) we could make the change, no worries.

Quoted 2 lines

I think there're actually two separate questions to be asked, to make it clearer, they are:

Here it got ambiguous when you say "global", I've been using -global to refer to the cmdline -global migration.foo, but others have used global to mean s->parameters (which has an extended lifetime). Could you clarify?

Quoted 19 lines

(1) Whether we should allow QMP "migrate" 'config' parameter to overwrite global setup?

(2) Whether we should allow previous QMP global setup to be used even if QMP "migrate" provided 'config' parameter?

So IIUC the patch does (1) YES (2) NO, while what I think might be more intuitive is (1) NO (2) YES.

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
migration/options.c +9 -0
+
+    /* overwrite with the new ones */
+    qmp_migrate_set_parameters(new, errp);
+    if (*errp) {
+        return false;
+    }
+
+    return true;
+}
#63 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 62 lines · Fabiano Rosas
Quoted 34 lines · Peter Xu
Quoted 21 lines · Fabiano Rosas
Quoted 19 lines · Peter Xu
Quoted 9 lines · Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

Quoted 6 lines

The options that are changed during the migration can still be set with the existing commands.

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

Could we still keep the QMP migrate-set-parameters values?

Quoted 7 lines
Quoted 3 lines

'config' argument > QMP setups using migrate-set-parameters >
-global cmdline > defaults (migration_properties)

That's the case. I failed to mention it in the commit message. IOW it behaves just like today, but the new 'config' way takes precedence over all.

Referring to below chunk of code:

[...]

Quoted 13 lines
Quoted 9 lines
Quoted 9 lines

migration/options.c static void migrate_params_apply(MigrationParameters *params) · line 1355

Quoted 9 lines
migration/options.c +9 -0
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp)
+{
+    ERRP_GUARD();
+
+    assert(bql_locked());
+
+    /* reset to default parameters */
+    migrate_params_apply(&s->defaults);

IIUC here it'll reset all global parameters using the initial defaults first, then apply the "config" specified in "migrate" QMP command?

Yes, this is so any previously set parameter via migrate-set-parameter gets erased. I think what we want (but feel free to disagree) is to have the migrate-set-parameter _eventually_ only handle parameters that need to be modifed during migration runtime. Anything else can be done via passing config to qmp_migrate.

For -global, I don't have a preference. Having -global take precedence over all would require a way to know which options were present in the command-line and which are just the defaults seet in migration_properties. I currently don't know how to do that. If it is at all possible (within reason) we could make the change, no worries.

Quoted 7 lines
Quoted 2 lines

I think there're actually two separate questions to be asked, to make it clearer, they are:

Here it got ambiguous when you say "global", I've been using -global to refer to the cmdline -global migration.foo, but others have used global to mean s->parameters (which has an extended lifetime). Could you clarify?

I meant the -global, and the global setups via migrate-set-parameters.

As replied to Dan in the other email, I changed my mind on question (1); I think it makes sense to have it YES. I left my pure question on (2) there too.

Do we really want to disable migrate-set-parameters setting most of the parameters, and only allow it to be set during migration on a few things like bandwidth or so?

I just don't really see the major benefit of that yet. I would think it make more sense if we don't need to change any parameters in migration, then provide that in one shot in QMP migrate "config". Maybe making more sense if migration is not heavily thread-based but having its aiocontext so we could even move to Jobs.

Now after all we'll need to allow setting something like bandwidth even during migration alive, and we have all the things ready allowing to set before migration starts, I'm not 100% sure whether we need to bother even if it does look cleaner, because we'll still break mgmt used to be working for years.. I could be over-cautious on breaking things, but I still want to understand better on the benefits.

One step back, on this "allow migrate to specify 'config'" request: I think we can definitely do that as it still provides some kind of atomicity. But frankly speaking I never see it a "real problem" - do we really have report or use case showing that Libvirt can trigger "migrate" with some global settings touched by other apps at all?

To me, it was yet an illutionary problem, I never know the answer of that. If Libvirt is still the owner of QEMU instance via the QMP channel, I actually don't really see why the atomicity would even help, even though we can still provide that as it's pretty easy as something optional; like what this patch does without too much hassle.

Then if to move one step further to remove all global settings, we face breaking debugging scripts, and breaking of any old libvirt and non-libvirt mgmt apps. Frankly I really don't yet know whether it's a good idea. I could miss some important reasoning of why we want to do it - it needs to be something not relevant to "making the code cleaner", IMHO..

Signature · 1 line
Peter Xu
#64 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 73 lines · Peter Xu
Quoted 62 lines · Fabiano Rosas
Quoted 34 lines · Peter Xu
Quoted 21 lines · Fabiano Rosas
Quoted 19 lines · Peter Xu
Quoted 9 lines · Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

Quoted 6 lines

The options that are changed during the migration can still be set with the existing commands.

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

Could we still keep the QMP migrate-set-parameters values?

Quoted 7 lines
Quoted 3 lines

'config' argument > QMP setups using migrate-set-parameters >
-global cmdline > defaults (migration_properties)

That's the case. I failed to mention it in the commit message. IOW it behaves just like today, but the new 'config' way takes precedence over all.

Referring to below chunk of code:

[...]

Quoted 13 lines
Quoted 9 lines
Quoted 9 lines

migration/options.c static void migrate_params_apply(MigrationParameters *params) · line 1355

Quoted 9 lines
migration/options.c +9 -0
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp)
+{
+    ERRP_GUARD();
+
+    assert(bql_locked());
+
+    /* reset to default parameters */
+    migrate_params_apply(&s->defaults);

IIUC here it'll reset all global parameters using the initial defaults first, then apply the "config" specified in "migrate" QMP command?

Yes, this is so any previously set parameter via migrate-set-parameter gets erased. I think what we want (but feel free to disagree) is to have the migrate-set-parameter _eventually_ only handle parameters that need to be modifed during migration runtime. Anything else can be done via passing config to qmp_migrate.

For -global, I don't have a preference. Having -global take precedence over all would require a way to know which options were present in the command-line and which are just the defaults seet in migration_properties. I currently don't know how to do that. If it is at all possible (within reason) we could make the change, no worries.

Quoted 7 lines
Quoted 2 lines

I think there're actually two separate questions to be asked, to make it clearer, they are:

Here it got ambiguous when you say "global", I've been using -global to refer to the cmdline -global migration.foo, but others have used global to mean s->parameters (which has an extended lifetime). Could you clarify?

I meant the -global, and the global setups via migrate-set-parameters.

Quoted 7 lines

As replied to Dan in the other email, I changed my mind on question (1); I think it makes sense to have it YES. I left my pure question on (2) there too.

Do we really want to disable migrate-set-parameters setting most of the parameters, and only allow it to be set during migration on a few things like bandwidth or so?

Yes, that's the whole point of the exercise IMHO.

Quoted 5 lines

I just don't really see the major benefit of that yet. I would think it make more sense if we don't need to change any parameters in migration, then provide that in one shot in QMP migrate "config". Maybe making more sense if migration is not heavily thread-based but having its aiocontext so we could even move to Jobs.

The benefit is that it brings 'migrate' into line with all other QMP commands, such that the data provided with the command is precisely what controls behaviour, giving predictable behaviour.

Quoted 5 lines

One step back, on this "allow migrate to specify 'config'" request: I think we can definitely do that as it still provides some kind of atomicity. But frankly speaking I never see it a "real problem" - do we really have report or use case showing that Libvirt can trigger "migrate" with some global settings touched by other apps at all?

atomicity is only one of the goals - being free from side effects of externally set global state is the more important aspect.

Quoted 5 lines

To me, it was yet an illutionary problem, I never know the answer of that. If Libvirt is still the owner of QEMU instance via the QMP channel, I actually don't really see why the atomicity would even help, even though we can still provide that as it's pretty easy as something optional; like what this patch does without too much hassle.

Even if only a single mgmt app is involved this is still beneficial because the migration infrastructure is used for distinct use cases inside QEMU - live migration, CPR, save/restore, and savevm/loadvm. Any time code any one of those uses cases starts using a new parameter, apps have to make sure they don't inadvertantly have its effects apply to the other use cases.

Quoted 5 lines

Then if to move one step further to remove all global settings, we face breaking debugging scripts, and breaking of any old libvirt and non-libvirt mgmt apps. Frankly I really don't yet know whether it's a good idea. I could miss some important reasoning of why we want to do it - it needs to be something not relevant to "making the code cleaner", IMHO..

Again, it makes the behaviour predictable as the QMP command fully expresses what action is going to be peformed, free with side effets of any previously set state.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#65 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

(I had a reply in the other thread, that might have covered most of the
points but maybe not this one..)

Quoted 3 lines · Daniel P. Berrangé

Even if only a single mgmt app is involved this is still beneficial because the migration infrastructure is used for distinct use cases inside QEMU - live migration, CPR, save/restore, and savevm/loadvm.

I assume CPR is save/restore, so indeed we have 3 ways to use migration core.

Quoted 3 lines

Any time code any one of those uses cases starts using a new parameter, apps have to make sure they don't inadvertantly have its effects apply to the other use cases.

AFAICT, that's not affected by "whether we allow global settings", that is still a concern internally as long as they use migration core.

One thing to mention is CPR is really a fine citizen here, AFAICT it is exactly live migration using all the proper caps/params. We _could_ split it as many things do not apply like postcopy, but we could still just reuse everything and ignoring the rest. It'll be again a cleaness issue to me, and even if CPR reuses everything it looks still clean enough, especially comparing to savevm/loadvm.

savevm/loadvm is another story.. however afaiu if we want to decouple it, it should be done not from the interface level, but internally first. E.g., we should allow taking parameters as a temp pointer passing to migration core, so that will be passed over by savevm setting all caps off, for example, ignoring the global config. The interface alone should, IMHO, be done only later.

Meanwhile, even if that, IMO we can't avoid the need to think any new param affecting savevm, as long as it's still using migration core. I don't know whether we need to do that one step even further to decouple savevm: I would think the other way round to obsolete savevm completely if necessary when we have fine "file:" migrations now, especially with mapped-ram.

Thanks,

Signature · 1 line
Peter Xu
#66 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 25 lines · Peter Xu

(I had a reply in the other thread, that might have covered most of the
points but maybe not this one..)

Quoted 3 lines · Daniel P. Berrangé

Even if only a single mgmt app is involved this is still beneficial because the migration infrastructure is used for distinct use cases inside QEMU - live migration, CPR, save/restore, and savevm/loadvm.

I assume CPR is save/restore, so indeed we have 3 ways to use migration core.

Quoted 3 lines

Any time code any one of those uses cases starts using a new parameter, apps have to make sure they don't inadvertantly have its effects apply to the other use cases.

AFAICT, that's not affected by "whether we allow global settings", that is still a concern internally as long as they use migration core.

One thing to mention is CPR is really a fine citizen here, AFAICT it is exactly live migration using all the proper caps/params. We _could_ split it as many things do not apply like postcopy, but we could still just reuse everything and ignoring the rest. It'll be again a cleaness issue to me, and even if CPR reuses everything it looks still clean enough, especially comparing to savevm/loadvm.

Quoted 7 lines

savevm/loadvm is another story.. however afaiu if we want to decouple it, it should be done not from the interface level, but internally first. E.g., we should allow taking parameters as a temp pointer passing to migration core, so that will be passed over by savevm setting all caps off, for example, ignoring the global config. The interface alone should, IMHO, be done only later.

This is simple to do, just reset all of s->parameters to (the new) s->defaults. We never decided if any migration parameters do make sense to use with savevm. If some of them does or is added later, then snapshot_save would gain a "config" argument.

Quoted 5 lines

Meanwhile, even if that, IMO we can't avoid the need to think any new param affecting savevm, as long as it's still using migration core. I don't know whether we need to do that one step even further to decouple savevm: I would think the other way round to obsolete savevm completely if necessary when we have fine "file:" migrations now, especially with mapped-ram.

savevm is a weird case. It supports a wider range of setups than regular migration. I don't know what to make of this. I would also like to make it "just migration" but it will need a bunch of special-casing. Anyway, we can discuss, but that's definitely for another day.

Quoted 2 lines

Thanks,

#67 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

In reply to Peter Xu
Quoted 73 lines · Peter Xu
Quoted 62 lines · Fabiano Rosas
Quoted 34 lines · Peter Xu
Quoted 21 lines · Fabiano Rosas
Quoted 19 lines · Peter Xu
Quoted 9 lines · Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

Quoted 6 lines

The options that are changed during the migration can still be set with the existing commands.

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

Could we still keep the QMP migrate-set-parameters values?

Quoted 7 lines
Quoted 3 lines

'config' argument > QMP setups using migrate-set-parameters >
-global cmdline > defaults (migration_properties)

That's the case. I failed to mention it in the commit message. IOW it behaves just like today, but the new 'config' way takes precedence over all.

Referring to below chunk of code:

[...]

Quoted 13 lines
Quoted 9 lines
Quoted 9 lines

migration/options.c static void migrate_params_apply(MigrationParameters *params) · line 1355

Quoted 9 lines
migration/options.c +9 -0
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp)
+{
+    ERRP_GUARD();
+
+    assert(bql_locked());
+
+    /* reset to default parameters */
+    migrate_params_apply(&s->defaults);

IIUC here it'll reset all global parameters using the initial defaults first, then apply the "config" specified in "migrate" QMP command?

Yes, this is so any previously set parameter via migrate-set-parameter gets erased. I think what we want (but feel free to disagree) is to have the migrate-set-parameter _eventually_ only handle parameters that need to be modifed during migration runtime. Anything else can be done via passing config to qmp_migrate.

For -global, I don't have a preference. Having -global take precedence over all would require a way to know which options were present in the command-line and which are just the defaults seet in migration_properties. I currently don't know how to do that. If it is at all possible (within reason) we could make the change, no worries.

Quoted 7 lines
Quoted 2 lines

I think there're actually two separate questions to be asked, to make it clearer, they are:

Here it got ambiguous when you say "global", I've been using -global to refer to the cmdline -global migration.foo, but others have used global to mean s->parameters (which has an extended lifetime). Could you clarify?

I meant the -global, and the global setups via migrate-set-parameters.

Quoted 8 lines

As replied to Dan in the other email, I changed my mind on question (1); I think it makes sense to have it YES. I left my pure question on (2) there too.

Do we really want to disable migrate-set-parameters setting most of the parameters, and only allow it to be set during migration on a few things like bandwidth or so?

Well, if we decide we have reasons to introduce the "config" concept, then I think we should not present two ways of doing the same thing. User calls qmp_migrate with its arguments and that's the migration. No other ways of setting parameters.

Since we do have parameters that are set in "runtime" I though of keeping migrate-set-parameters around to minimize the interface change. Maybe those should have been separate knobs on their own after all... But in any case, we can't reject migrate-set-parameters because it might happen way earlier than the actual migration command. So I don't think anything changes regarding the API.

Quoted 6 lines

I just don't really see the major benefit of that yet. I would think it make more sense if we don't need to change any parameters in migration, then provide that in one shot in QMP migrate "config". Maybe making more sense if migration is not heavily thread-based but having its aiocontext so we could even move to Jobs.

Quoted 7 lines

Now after all we'll need to allow setting something like bandwidth even during migration alive, and we have all the things ready allowing to set before migration starts, I'm not 100% sure whether we need to bother even if it does look cleaner, because we'll still break mgmt used to be working for years.. I could be over-cautious on breaking things, but I still want to understand better on the benefits.

Makes sense. We'd say either use the old way or the new way. If both are mixed, then the new way takes precedence. That keeps older apps working and allows new code to transition into the new way.

Quoted 6 lines

One step back, on this "allow migrate to specify 'config'" request: I think we can definitely do that as it still provides some kind of atomicity. But frankly speaking I never see it a "real problem" - do we really have report or use case showing that Libvirt can trigger "migrate" with some global settings touched by other apps at all?

I don't think other apps is the problem, but libvirt itself maybe attempting two migrations in sequence after one of them fails.

There always the possibility that the user is poking around, which of course is not advisable, but if a weird migration bug shows up it's difficult to confirm that other app/user hasn't changed the parameters.

Quoted 6 lines

To me, it was yet an illutionary problem, I never know the answer of that. If Libvirt is still the owner of QEMU instance via the QMP channel, I actually don't really see why the atomicity would even help, even though we can still provide that as it's pretty easy as something optional; like what this patch does without too much hassle.

We can provide it, but I'd rather not unless we agree that is the way forward. We don't need another way of doing the same as existing commands.

Quoted 5 lines

Then if to move one step further to remove all global settings, we face breaking debugging scripts, and breaking of any old libvirt and non-libvirt mgmt apps. Frankly I really don't yet know whether it's a good idea. I could miss some important reasoning of why we want to do it - it needs to be something not relevant to "making the code cleaner", IMHO..

I don't see it as breaking the old stuff. Because any old users would still be using migrate-set-parameters as usual. So I think your concern is about calling migrate the new way and also keeping -global working. As I said, personally I don't mind if put some ifs around to keep -global working.

Could we add another parameter that says allow-globals (or w/e) and make everyone happy?

#68 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 110 lines · Fabiano Rosas
Quoted 73 lines · Peter Xu
Quoted 62 lines · Fabiano Rosas
Quoted 34 lines · Peter Xu
Quoted 21 lines · Fabiano Rosas
Quoted 19 lines · Peter Xu
Quoted 9 lines · Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

Quoted 6 lines

The options that are changed during the migration can still be set with the existing commands.

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

Could we still keep the QMP migrate-set-parameters values?

Quoted 7 lines
Quoted 3 lines

'config' argument > QMP setups using migrate-set-parameters >
-global cmdline > defaults (migration_properties)

That's the case. I failed to mention it in the commit message. IOW it behaves just like today, but the new 'config' way takes precedence over all.

Referring to below chunk of code:

[...]

Quoted 13 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp)
+{
+    ERRP_GUARD();
+
+    assert(bql_locked());
+
+    /* reset to default parameters */
+    migrate_params_apply(&s->defaults);

IIUC here it'll reset all global parameters using the initial defaults first, then apply the "config" specified in "migrate" QMP command?

Yes, this is so any previously set parameter via migrate-set-parameter gets erased. I think what we want (but feel free to disagree) is to have the migrate-set-parameter _eventually_ only handle parameters that need to be modifed during migration runtime. Anything else can be done via passing config to qmp_migrate.

For -global, I don't have a preference. Having -global take precedence over all would require a way to know which options were present in the command-line and which are just the defaults seet in migration_properties. I currently don't know how to do that. If it is at all possible (within reason) we could make the change, no worries.

Quoted 7 lines
Quoted 2 lines

I think there're actually two separate questions to be asked, to make it clearer, they are:

Here it got ambiguous when you say "global", I've been using -global to refer to the cmdline -global migration.foo, but others have used global to mean s->parameters (which has an extended lifetime). Could you clarify?

I meant the -global, and the global setups via migrate-set-parameters.

Quoted 8 lines

As replied to Dan in the other email, I changed my mind on question (1); I think it makes sense to have it YES. I left my pure question on (2) there too.

Do we really want to disable migrate-set-parameters setting most of the parameters, and only allow it to be set during migration on a few things like bandwidth or so?

Well, if we decide we have reasons to introduce the "config" concept, then I think we should not present two ways of doing the same thing. User calls qmp_migrate with its arguments and that's the migration. No other ways of setting parameters.

Since we do have parameters that are set in "runtime" I though of keeping migrate-set-parameters around to minimize the interface change. Maybe those should have been separate knobs on their own after all... But in any case, we can't reject migrate-set-parameters because it might happen way earlier than the actual migration command. So I don't think anything changes regarding the API.

Quoted 6 lines

I just don't really see the major benefit of that yet. I would think it make more sense if we don't need to change any parameters in migration, then provide that in one shot in QMP migrate "config". Maybe making more sense if migration is not heavily thread-based but having its aiocontext so we could even move to Jobs.

Quoted 7 lines

Now after all we'll need to allow setting something like bandwidth even during migration alive, and we have all the things ready allowing to set before migration starts, I'm not 100% sure whether we need to bother even if it does look cleaner, because we'll still break mgmt used to be working for years.. I could be over-cautious on breaking things, but I still want to understand better on the benefits.

Quoted 3 lines

Makes sense. We'd say either use the old way or the new way. If both are mixed, then the new way takes precedence. That keeps older apps working and allows new code to transition into the new way.

Fair enough. Yes whenever the new way is chosen it can work in anyway we define it.

It's just that if the global list of parameters will still be around then it seems to have no good reason to not build the migration parameters on top of the global list of parameters. After all, anything can be overwritten in the QMP migrate if needed.

Quoted 8 lines
Quoted 7 lines

One step back, on this "allow migrate to specify 'config'" request: I think we can definitely do that as it still provides some kind of atomicity. But frankly speaking I never see it a "real problem" - do we really have report or use case showing that Libvirt can trigger "migrate" with some global settings touched by other apps at all?

Quoted 6 lines

I don't think other apps is the problem, but libvirt itself maybe attempting two migrations in sequence after one of them fails.

There always the possibility that the user is poking around, which of course is not advisable, but if a weird migration bug shows up it's difficult to confirm that other app/user hasn't changed the parameters.

That's almost what I think the current patch is useful on providing some kind of atomicity.

If we want to make debugging easy, we could also consider returning the finalized migration setup in the response of QMP "migrate" with all parameters, by defining "returns" for QMP "migrate".

Quoted 11 lines
Quoted 7 lines

To me, it was yet an illutionary problem, I never know the answer of that. If Libvirt is still the owner of QEMU instance via the QMP channel, I actually don't really see why the atomicity would even help, even though we can still provide that as it's pretty easy as something optional; like what this patch does without too much hassle.

We can provide it, but I'd rather not unless we agree that is the way forward. We don't need another way of doing the same as existing commands.

OK, it might be me that misunderstood the request initially.

Quoted 7 lines
Quoted 6 lines

Then if to move one step further to remove all global settings, we face breaking debugging scripts, and breaking of any old libvirt and non-libvirt mgmt apps. Frankly I really don't yet know whether it's a good idea. I could miss some important reasoning of why we want to do it - it needs to be something not relevant to "making the code cleaner", IMHO..

Quoted 8 lines

I don't see it as breaking the old stuff. Because any old users would still be using migrate-set-parameters as usual. So I think your concern is about calling migrate the new way and also keeping -global working. As I said, personally I don't mind if put some ifs around to keep -global working.

Could we add another parameter that says allow-globals (or w/e) and make everyone happy?

That's not needed if it's about making me happy. :) My happiness alone isn't that important, I can change any of my script, and I'm OK whatever ABI changes, but as long as the downstream won't be a mess..

If we want to either do nothing or making it a bundle, then we can decide what's the bundle now.

For example, do we plan to have this, then drop migrate-set-parameters & capabilities finally (or at least failing non-runtime-modifi-able ones)?

How fast do we want to do this, and how do we manage downstream to not be affected by having new QEMU's migrate-set-* commands completely gone, would be the follow up questions..

Maybe I worked much enough on Linux so I pay a lot of attention trying to think such trade-off, then if I see not much benefit normally I'll try to not break any ABI. But if that's everyone's wish (except myself.. even if it only makes the interface better..) then we can discuss before moving on.

Signature · 1 line
Peter Xu
#69 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 115 lines · Peter Xu
Quoted 110 lines · Fabiano Rosas
Quoted 73 lines · Peter Xu
Quoted 62 lines · Fabiano Rosas
Quoted 34 lines · Peter Xu
Quoted 21 lines · Fabiano Rosas
Quoted 19 lines · Peter Xu
Quoted 9 lines · Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

Quoted 6 lines

The options that are changed during the migration can still be set with the existing commands.

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

Could we still keep the QMP migrate-set-parameters values?

Quoted 7 lines
Quoted 3 lines

'config' argument > QMP setups using migrate-set-parameters >
-global cmdline > defaults (migration_properties)

That's the case. I failed to mention it in the commit message. IOW it behaves just like today, but the new 'config' way takes precedence over all.

Referring to below chunk of code:

[...]

Quoted 13 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp)
+{
+    ERRP_GUARD();
+
+    assert(bql_locked());
+
+    /* reset to default parameters */
+    migrate_params_apply(&s->defaults);

IIUC here it'll reset all global parameters using the initial defaults first, then apply the "config" specified in "migrate" QMP command?

Yes, this is so any previously set parameter via migrate-set-parameter gets erased. I think what we want (but feel free to disagree) is to have the migrate-set-parameter _eventually_ only handle parameters that need to be modifed during migration runtime. Anything else can be done via passing config to qmp_migrate.

For -global, I don't have a preference. Having -global take precedence over all would require a way to know which options were present in the command-line and which are just the defaults seet in migration_properties. I currently don't know how to do that. If it is at all possible (within reason) we could make the change, no worries.

Quoted 7 lines
Quoted 2 lines

I think there're actually two separate questions to be asked, to make it clearer, they are:

Here it got ambiguous when you say "global", I've been using -global to refer to the cmdline -global migration.foo, but others have used global to mean s->parameters (which has an extended lifetime). Could you clarify?

I meant the -global, and the global setups via migrate-set-parameters.

Quoted 8 lines

As replied to Dan in the other email, I changed my mind on question (1); I think it makes sense to have it YES. I left my pure question on (2) there too.

Do we really want to disable migrate-set-parameters setting most of the parameters, and only allow it to be set during migration on a few things like bandwidth or so?

Well, if we decide we have reasons to introduce the "config" concept, then I think we should not present two ways of doing the same thing. User calls qmp_migrate with its arguments and that's the migration. No other ways of setting parameters.

Since we do have parameters that are set in "runtime" I though of keeping migrate-set-parameters around to minimize the interface change. Maybe those should have been separate knobs on their own after all... But in any case, we can't reject migrate-set-parameters because it might happen way earlier than the actual migration command. So I don't think anything changes regarding the API.

Quoted 6 lines

I just don't really see the major benefit of that yet. I would think it make more sense if we don't need to change any parameters in migration, then provide that in one shot in QMP migrate "config". Maybe making more sense if migration is not heavily thread-based but having its aiocontext so we could even move to Jobs.

Quoted 7 lines

Now after all we'll need to allow setting something like bandwidth even during migration alive, and we have all the things ready allowing to set before migration starts, I'm not 100% sure whether we need to bother even if it does look cleaner, because we'll still break mgmt used to be working for years.. I could be over-cautious on breaking things, but I still want to understand better on the benefits.

Quoted 3 lines

Makes sense. We'd say either use the old way or the new way. If both are mixed, then the new way takes precedence. That keeps older apps working and allows new code to transition into the new way.

Quoted 8 lines

Fair enough. Yes whenever the new way is chosen it can work in anyway we define it.

It's just that if the global list of parameters will still be around then it seems to have no good reason to not build the migration parameters on top of the global list of parameters. After all, anything can be overwritten in the QMP migrate if needed.

If we had a way to detect that the user has modified some parameters via the cmdline, then we could merge that with the s->defaults and restore it before applying config, that would achieve what you want. I'm in favor, -global should only be used for debugging, I think it's fine if we let it go through. But anything set by migrate-set-parameters definitely needs to be reset. I just need a way to differentiate between "default parameter" vs. "default parameter that got overwritten by -global". I'll try to figure something out.

Quoted 15 lines
Quoted 8 lines
Quoted 7 lines

One step back, on this "allow migrate to specify 'config'" request: I think we can definitely do that as it still provides some kind of atomicity. But frankly speaking I never see it a "real problem" - do we really have report or use case showing that Libvirt can trigger "migrate" with some global settings touched by other apps at all?

Quoted 6 lines

I don't think other apps is the problem, but libvirt itself maybe attempting two migrations in sequence after one of them fails.

There always the possibility that the user is poking around, which of course is not advisable, but if a weird migration bug shows up it's difficult to confirm that other app/user hasn't changed the parameters.

Quoted 7 lines

That's almost what I think the current patch is useful on providing some kind of atomicity.

If we want to make debugging easy, we could also consider returning the finalized migration setup in the response of QMP "migrate" with all parameters, by defining "returns" for QMP "migrate".

Isn't query-migrate-parameters that already?

Quoted 27 lines
Quoted 11 lines
Quoted 7 lines

To me, it was yet an illutionary problem, I never know the answer of that. If Libvirt is still the owner of QEMU instance via the QMP channel, I actually don't really see why the atomicity would even help, even though we can still provide that as it's pretty easy as something optional; like what this patch does without too much hassle.

We can provide it, but I'd rather not unless we agree that is the way forward. We don't need another way of doing the same as existing commands.

OK, it might be me that misunderstood the request initially.

Quoted 13 lines
Quoted 6 lines

Then if to move one step further to remove all global settings, we face breaking debugging scripts, and breaking of any old libvirt and non-libvirt mgmt apps. Frankly I really don't yet know whether it's a good idea. I could miss some important reasoning of why we want to do it - it needs to be something not relevant to "making the code cleaner", IMHO..

I don't see it as breaking the old stuff. Because any old users would still be using migrate-set-parameters as usual. So I think your concern is about calling migrate the new way and also keeping -global working. As I said, personally I don't mind if put some ifs around to keep -global working.

Quoted 7 lines
Quoted 2 lines

Could we add another parameter that says allow-globals (or w/e) and make everyone happy?

That's not needed if it's about making me happy. :) My happiness alone isn't that important, I can change any of my script, and I'm OK whatever ABI changes, but as long as the downstream won't be a mess..

At this point you've probably done more migrations than any single person. So of course your use-case is important. I don't think an extra knob is too much to ask. Could even be -global only.

However, if we're going to keep both requirements working: 1) overwrite migrate-set-params; 2) do not overwrite -global; as I said we need a way to detect a parameter changed via -global... and then we don't need a new knob because that would already tell us.

Quoted 6 lines

If we want to either do nothing or making it a bundle, then we can decide what's the bundle now.

For example, do we plan to have this, then drop migrate-set-parameters & capabilities finally (or at least failing non-runtime-modifi-able ones)?

Good question, I don't think we've decided. Those last few patches could have kept the RFC tag. I say we:

- Merge params+caps and deprecate migrate-set-capabilities now.

One is an internal change and the other is a normal command deprecation, AFAIK.

- Make sure we agree on how config is going to work and introduce it then (possibly this release).

We also need to make sure this is the right thing for savevm, cpr, etc. It would be good to have all of them uniformly prepared to take (or not) the config parameter.

- Leave migrate-set-parameters as is.
(this wasn't my original intention, but this discussion changed my mind)

As I said, we can't predict whether the user will call migrate-set-parameters before calling migrate. So I don't think we can say:

"Only use this if you're not using the new 'config' option OR if
you're using the new 'config' option plus setting runtime parameters"

It also gives us the ability to say that nothing changes with migrate-set-parameter except that it now takes caps as well.

Quoted 4 lines

How fast do we want to do this, and how do we manage downstream to not be affected by having new QEMU's migrate-set-* commands completely gone, would be the follow up questions..

- The migrate-set-parameters change is just an addition of options. We do this anytime a new feature is added and I don't think there are issues downstream. Are there?

- Dropping migrate-set-capabilities would be covered by the deprecation period. We shouldn't have to think about it. But let's say we _are_ going to think about it: a libvirt from before the removal of the command would have trouble with a QEMU from after the removal. Converting between the two may not be trivial because caps today take a MigrationCapabilityList which is a more complex data structure than just key=value as MigrationParameters.

- The 'config' change is supported by keeping migrate-set-parameters around, so it wouldn't affect anything. Just don't use the new API.

I think that's it? Am I being too simplistic?

Quoted 5 lines

Maybe I worked much enough on Linux so I pay a lot of attention trying to think such trade-off, then if I see not much benefit normally I'll try to not break any ABI. But if that's everyone's wish (except myself.. even if it only makes the interface better..) then we can discuss before moving on.

I think we can do this without breaking anything. We could bring more people into the discussion to double-check. Let's just agree between ourselves on some of these other details.

I don't discard the possibility of simply dropping it. But I see Daniel (and Markus on the previous version) making compelling points.

#70 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 126 lines · Fabiano Rosas
Quoted 115 lines · Peter Xu
Quoted 110 lines · Fabiano Rosas
Quoted 73 lines · Peter Xu
Quoted 62 lines · Fabiano Rosas
Quoted 34 lines · Peter Xu
Quoted 21 lines · Fabiano Rosas
Quoted 19 lines · Peter Xu
Quoted 9 lines · Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

Quoted 6 lines

The options that are changed during the migration can still be set with the existing commands.

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

Could we still keep the QMP migrate-set-parameters values?

Quoted 7 lines
Quoted 3 lines

'config' argument > QMP setups using migrate-set-parameters >
-global cmdline > defaults (migration_properties)

That's the case. I failed to mention it in the commit message. IOW it behaves just like today, but the new 'config' way takes precedence over all.

Referring to below chunk of code:

[...]

Quoted 13 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp)
+{
+    ERRP_GUARD();
+
+    assert(bql_locked());
+
+    /* reset to default parameters */
+    migrate_params_apply(&s->defaults);

IIUC here it'll reset all global parameters using the initial defaults first, then apply the "config" specified in "migrate" QMP command?

Yes, this is so any previously set parameter via migrate-set-parameter gets erased. I think what we want (but feel free to disagree) is to have the migrate-set-parameter _eventually_ only handle parameters that need to be modifed during migration runtime. Anything else can be done via passing config to qmp_migrate.

For -global, I don't have a preference. Having -global take precedence over all would require a way to know which options were present in the command-line and which are just the defaults seet in migration_properties. I currently don't know how to do that. If it is at all possible (within reason) we could make the change, no worries.

Quoted 7 lines
Quoted 2 lines

I think there're actually two separate questions to be asked, to make it clearer, they are:

Here it got ambiguous when you say "global", I've been using -global to refer to the cmdline -global migration.foo, but others have used global to mean s->parameters (which has an extended lifetime). Could you clarify?

I meant the -global, and the global setups via migrate-set-parameters.

Quoted 8 lines

As replied to Dan in the other email, I changed my mind on question (1); I think it makes sense to have it YES. I left my pure question on (2) there too.

Do we really want to disable migrate-set-parameters setting most of the parameters, and only allow it to be set during migration on a few things like bandwidth or so?

Well, if we decide we have reasons to introduce the "config" concept, then I think we should not present two ways of doing the same thing. User calls qmp_migrate with its arguments and that's the migration. No other ways of setting parameters.

Since we do have parameters that are set in "runtime" I though of keeping migrate-set-parameters around to minimize the interface change. Maybe those should have been separate knobs on their own after all... But in any case, we can't reject migrate-set-parameters because it might happen way earlier than the actual migration command. So I don't think anything changes regarding the API.

Quoted 6 lines

I just don't really see the major benefit of that yet. I would think it make more sense if we don't need to change any parameters in migration, then provide that in one shot in QMP migrate "config". Maybe making more sense if migration is not heavily thread-based but having its aiocontext so we could even move to Jobs.

Quoted 7 lines

Now after all we'll need to allow setting something like bandwidth even during migration alive, and we have all the things ready allowing to set before migration starts, I'm not 100% sure whether we need to bother even if it does look cleaner, because we'll still break mgmt used to be working for years.. I could be over-cautious on breaking things, but I still want to understand better on the benefits.

Quoted 3 lines

Makes sense. We'd say either use the old way or the new way. If both are mixed, then the new way takes precedence. That keeps older apps working and allows new code to transition into the new way.

Quoted 8 lines

Fair enough. Yes whenever the new way is chosen it can work in anyway we define it.

It's just that if the global list of parameters will still be around then it seems to have no good reason to not build the migration parameters on top of the global list of parameters. After all, anything can be overwritten in the QMP migrate if needed.

Quoted 8 lines

If we had a way to detect that the user has modified some parameters via the cmdline, then we could merge that with the s->defaults and restore it before applying config, that would achieve what you want. I'm in favor, -global should only be used for debugging, I think it's fine if we let it go through. But anything set by migrate-set-parameters definitely needs to be reset. I just need a way to differentiate between "default parameter" vs. "default parameter that got overwritten by -global". I'll try to figure something out.

I think I see what you meant. Ignoring -global is ok. I agree with you that should be pure debugging, and feel free to keep it like that if you can't find anything to persist it - it may not justify your time spent if it grows too much.

Quoted 19 lines
Quoted 19 lines
Quoted 9 lines
Quoted 8 lines

One step back, on this "allow migrate to specify 'config'" request: I think we can definitely do that as it still provides some kind of atomicity. But frankly speaking I never see it a "real problem" - do we really have report or use case showing that Libvirt can trigger "migrate" with some global settings touched by other apps at all?

Quoted 6 lines

I don't think other apps is the problem, but libvirt itself maybe attempting two migrations in sequence after one of them fails.

There always the possibility that the user is poking around, which of course is not advisable, but if a weird migration bug shows up it's difficult to confirm that other app/user hasn't changed the parameters.

That's almost what I think the current patch is useful on providing some kind of atomicity.

Quoted 6 lines
Quoted 4 lines

If we want to make debugging easy, we could also consider returning the finalized migration setup in the response of QMP "migrate" with all parameters, by defining "returns" for QMP "migrate".

Isn't query-migrate-parameters that already?

The important part is still "atomicity". Consider right after Libvirt sends a "migrate" command someone quickly cancelled it and invoked another one using another "config". Yes there will still be events generated to Libvirt but I think that'll be asynchronous anyway so its arrival might have been after the other one migrating VM again.

Attach to that to "returns" provides atomicity making sure if Libvirt invoking a "migrate" command and get the returns, if that succeeded Libvirt knows the returned setup is 100% the one that is running now. It might be cancelled too but the finalized setup will match what Libvirt triggers.

Said that, not that I think any of such would ever happen.. but that idea does match with atomicity provided by QMP "migrate" with "config".

Quoted 36 lines
Quoted 28 lines
Quoted 9 lines
Quoted 8 lines

To me, it was yet an illutionary problem, I never know the answer of that. If Libvirt is still the owner of QEMU instance via the QMP channel, I actually don't really see why the atomicity would even help, even though we can still provide that as it's pretty easy as something optional; like what this patch does without too much hassle.

Quoted 3 lines

We can provide it, but I'd rather not unless we agree that is the way forward. We don't need another way of doing the same as existing commands.

OK, it might be me that misunderstood the request initially.

Quoted 13 lines
Quoted 6 lines

Then if to move one step further to remove all global settings, we face breaking debugging scripts, and breaking of any old libvirt and non-libvirt mgmt apps. Frankly I really don't yet know whether it's a good idea. I could miss some important reasoning of why we want to do it - it needs to be something not relevant to "making the code cleaner", IMHO..

I don't see it as breaking the old stuff. Because any old users would still be using migrate-set-parameters as usual. So I think your concern is about calling migrate the new way and also keeping -global working. As I said, personally I don't mind if put some ifs around to keep -global working.

Quoted 7 lines
Quoted 2 lines

Could we add another parameter that says allow-globals (or w/e) and make everyone happy?

That's not needed if it's about making me happy. :) My happiness alone isn't that important, I can change any of my script, and I'm OK whatever ABI changes, but as long as the downstream won't be a mess..

Quoted 8 lines

At this point you've probably done more migrations than any single person. So of course your use-case is important. I don't think an extra knob is too much to ask. Could even be -global only.

However, if we're going to keep both requirements working: 1) overwrite migrate-set-params; 2) do not overwrite -global; as I said we need a way to detect a parameter changed via -global... and then we don't need a new knob because that would already tell us.

Let's not bother; I'm totally OK ignoring -global. When one's testing manually, one won't be using "config" in "migrate" normally so it's fine.

Quoted 8 lines
Quoted 7 lines

If we want to either do nothing or making it a bundle, then we can decide what's the bundle now.

For example, do we plan to have this, then drop migrate-set-parameters & capabilities finally (or at least failing non-runtime-modifi-able ones)?

Quoted 7 lines

Good question, I don't think we've decided. Those last few patches could have kept the RFC tag. I say we:

- Merge params+caps and deprecate migrate-set-capabilities now.

One is an internal change and the other is a normal command deprecation, AFAIK.

Agree. Maybe we could still keep the interface for more than two releases. Maybe we don't need to rush removing the support, and keep it deprecate for long enough, until we figure out when it's safe.

Quoted 7 lines

- Make sure we agree on how config is going to work and introduce it then (possibly this release).

We also need to make sure this is the right thing for savevm, cpr, etc. It would be good to have all of them uniformly prepared to take (or not) the config parameter.

CPR is still live migration, I hope we can reach consensus. It uses exactly the caps/params it needs, but it's migrating the same as live migration would do, except it migrates some more fds.

It could be more special if it was based on fork(), there're tons of uncertainties over fork() with a multi-threaded app, but now we're going scm rights, much better I'd say. Same reason, it is still live migration when it's using generic unix sockets.

savevm - we don't plan to yet support any migration cap/param on it, right?

I remember the other use case for enabling mapped-ram, but per my memory there is much better way to go for that use case rather than building it on top of savevm, so I'd still think savevm doesn't need any extension, and it should take zero parameters even in the near future.

What it can do is reset all parameters right before start, then "recover" the parameters right after, taking BQL for the whole process. Logically if we know it's a new libvirt we don't even need to bother on the "recover" part, but we may still want to consider the old libvirts too as long as there's compat concerns.

Quoted 9 lines

- Leave migrate-set-parameters as is.
(this wasn't my original intention, but this discussion changed my mind)

As I said, we can't predict whether the user will call migrate-set-parameters before calling migrate. So I don't think we can say:

Quoted 5 lines

"Only use this if you're not using the new 'config' option OR if
you're using the new 'config' option plus setting runtime parameters"

It also gives us the ability to say that nothing changes with migrate-set-parameter except that it now takes caps as well.

Yep. For this one keeping it as-is is simpler. We can wait for Dan/Markus and others to chime in when there's other opinions.

Quoted 9 lines
Quoted 5 lines

How fast do we want to do this, and how do we manage downstream to not be affected by having new QEMU's migrate-set-* commands completely gone, would be the follow up questions..

- The migrate-set-parameters change is just an addition of options. We do this anytime a new feature is added and I don't think there are issues downstream. Are there?

Adding caps into it is all fine; I don't see anything would break.

Quoted 8 lines

- Dropping migrate-set-capabilities would be covered by the deprecation period. We shouldn't have to think about it. But let's say we _are_ going to think about it: a libvirt from before the removal of the command would have trouble with a QEMU from after the removal. Converting between the two may not be trivial because caps today take a MigrationCapabilityList which is a more complex data structure than just key=value as MigrationParameters.

Yes, this is discussed above as well. The worst case is we can keep the deprecation for as long as how we deprecate machine types. Logically that was defined partly as "max major release cycle on guaranteed ABI", then we may assume whatever to be rebased on the current release in any downstream would have new libvirt ready. Again, we can discuss this later, marking deprecation can be done first.

Quoted 5 lines

- The 'config' change is supported by keeping migrate-set-parameters around, so it wouldn't affect anything. Just don't use the new API.

I think that's it? Am I being too simplistic?

Nop; so far so good to me.

Quoted 7 lines
Quoted 6 lines

Maybe I worked much enough on Linux so I pay a lot of attention trying to think such trade-off, then if I see not much benefit normally I'll try to not break any ABI. But if that's everyone's wish (except myself.. even if it only makes the interface better..) then we can discuss before moving on.

Quoted 6 lines

I think we can do this without breaking anything. We could bring more people into the discussion to double-check. Let's just agree between ourselves on some of these other details.

I don't discard the possibility of simply dropping it. But I see Daniel (and Markus on the previous version) making compelling points.

Yeah I was absent for quite a while, and I may have missed some points. We can wait for some more inputs.

Signature · 1 line
Peter Xu
#71 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 136 lines · Peter Xu
Quoted 126 lines · Fabiano Rosas
Quoted 115 lines · Peter Xu
Quoted 110 lines · Fabiano Rosas
Quoted 73 lines · Peter Xu
Quoted 62 lines · Fabiano Rosas
Quoted 34 lines · Peter Xu
Quoted 21 lines · Fabiano Rosas
Quoted 19 lines · Peter Xu
Quoted 9 lines · Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

Quoted 6 lines

The options that are changed during the migration can still be set with the existing commands.

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

Could we still keep the QMP migrate-set-parameters values?

Quoted 7 lines
Quoted 3 lines

'config' argument > QMP setups using migrate-set-parameters >
-global cmdline > defaults (migration_properties)

That's the case. I failed to mention it in the commit message. IOW it behaves just like today, but the new 'config' way takes precedence over all.

Referring to below chunk of code:

[...]

Quoted 13 lines
Quoted 9 lines
Quoted 9 lines

Review

Quoted 9 lines
(quoted diff) +9 -0
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp)
+{
+    ERRP_GUARD();
+
+    assert(bql_locked());
+
+    /* reset to default parameters */
+    migrate_params_apply(&s->defaults);

IIUC here it'll reset all global parameters using the initial defaults first, then apply the "config" specified in "migrate" QMP command?

Yes, this is so any previously set parameter via migrate-set-parameter gets erased. I think what we want (but feel free to disagree) is to have the migrate-set-parameter _eventually_ only handle parameters that need to be modifed during migration runtime. Anything else can be done via passing config to qmp_migrate.

For -global, I don't have a preference. Having -global take precedence over all would require a way to know which options were present in the command-line and which are just the defaults seet in migration_properties. I currently don't know how to do that. If it is at all possible (within reason) we could make the change, no worries.

Quoted 7 lines
Quoted 2 lines

I think there're actually two separate questions to be asked, to make it clearer, they are:

Here it got ambiguous when you say "global", I've been using -global to refer to the cmdline -global migration.foo, but others have used global to mean s->parameters (which has an extended lifetime). Could you clarify?

I meant the -global, and the global setups via migrate-set-parameters.

Quoted 8 lines

As replied to Dan in the other email, I changed my mind on question (1); I think it makes sense to have it YES. I left my pure question on (2) there too.

Do we really want to disable migrate-set-parameters setting most of the parameters, and only allow it to be set during migration on a few things like bandwidth or so?

Well, if we decide we have reasons to introduce the "config" concept, then I think we should not present two ways of doing the same thing. User calls qmp_migrate with its arguments and that's the migration. No other ways of setting parameters.

Since we do have parameters that are set in "runtime" I though of keeping migrate-set-parameters around to minimize the interface change. Maybe those should have been separate knobs on their own after all... But in any case, we can't reject migrate-set-parameters because it might happen way earlier than the actual migration command. So I don't think anything changes regarding the API.

Quoted 6 lines

I just don't really see the major benefit of that yet. I would think it make more sense if we don't need to change any parameters in migration, then provide that in one shot in QMP migrate "config". Maybe making more sense if migration is not heavily thread-based but having its aiocontext so we could even move to Jobs.

Quoted 7 lines

Now after all we'll need to allow setting something like bandwidth even during migration alive, and we have all the things ready allowing to set before migration starts, I'm not 100% sure whether we need to bother even if it does look cleaner, because we'll still break mgmt used to be working for years.. I could be over-cautious on breaking things, but I still want to understand better on the benefits.

Quoted 3 lines

Makes sense. We'd say either use the old way or the new way. If both are mixed, then the new way takes precedence. That keeps older apps working and allows new code to transition into the new way.

Quoted 8 lines

Fair enough. Yes whenever the new way is chosen it can work in anyway we define it.

It's just that if the global list of parameters will still be around then it seems to have no good reason to not build the migration parameters on top of the global list of parameters. After all, anything can be overwritten in the QMP migrate if needed.

Quoted 8 lines

If we had a way to detect that the user has modified some parameters via the cmdline, then we could merge that with the s->defaults and restore it before applying config, that would achieve what you want. I'm in favor, -global should only be used for debugging, I think it's fine if we let it go through. But anything set by migrate-set-parameters definitely needs to be reset. I just need a way to differentiate between "default parameter" vs. "default parameter that got overwritten by -global". I'll try to figure something out.

Quoted 5 lines

I think I see what you meant. Ignoring -global is ok. I agree with you that should be pure debugging, and feel free to keep it like that if you can't find anything to persist it - it may not justify your time spent if it grows too much.

I think I caused some confusion here. I wrote migrate_params_override() last thing on a friday and forgot it did the right thing from the beginning:

    migrate_params_apply(&s->defaults);
    qmp_migrate_set_parameters(new, errp);

This s->defaults is poorly named and is actualy already the merge of defaults + globals, because qdev does it for us. migrate_params_apply() will then copy that to s->parameters and qmp_migrate_set_parameters() will apply the 'new' params from 'config' on top s->parameters. An example:

Setting multifd-channels (default 2) using various methods and querying both QMP and HMP:

a) global overrides default:

 $ ./qemu-system-x86_64 -global migration.multifd-channels=4 ...
 => QMP: "multifd-channels": 4, HMP: multifd-channels: 4

b) migrate-set-parameter overrides global:

{ 'execute': 'migrate-set-parameters', 'arguments': { 'multifd-channels': 8 } } => QMP: "multifd-channels": 8, HMP: multifd-channels: 8

c) config not touching the parameter, value is reset to global:

{ 'execute': 'migrate', 'arguments': { ..., 'config': { 'multifd': true } } } => QMP: "multifd-channels": 4, HMP: multifd-channels: 4

d) config overrides all:

{ 'execute': 'migrate', 'arguments': { ..., 'config': {'multifd-channels': 16 } } } => QMP: "multifd-channels": 16, HMP: multifd-channels: 16

Without global:

e) default is set initially

 $ ./qemu-system-x86_64 ...
 => QMP: "multifd-channels": 2, HMP: multifd-channels: 2

f) migrate-set-parameter overrides default:

{ 'execute': 'migrate-set-parameters', 'arguments': { 'multifd-channels': 8 } } => QMP: "multifd-channels": 8, HMP: multifd-channels: 8

g) config not touching the parameter, value is reset to default:

{ 'execute': 'migrate', 'arguments': { ..., 'config': { 'multifd': true } } } => "multifd-channels": 2, HMP: multifd-channels: 2

h) config overrides all:

{ 'execute': 'migrate', 'arguments': { ..., 'config': {'multifd-channels': 16 } } } => QMP: "multifd-channels": 16, HMP: multifd-channels: 16

I'll update the variable names and code comments to be more precise. Sorry for the noise.

#72 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 9 lines · Fabiano Rosas

I think I caused some confusion here. I wrote migrate_params_override() last thing on a friday and forgot it did the right thing from the beginning:

    migrate_params_apply(&s->defaults);
    qmp_migrate_set_parameters(new, errp);

This s->defaults is poorly named and is actualy already the merge of defaults + globals, because qdev does it for us. migrate_params_apply()

Ha! I didn't remember this part of details when reading, but then I followed with that idea it won't apply to &defaults.

Quoted 44 lines

will then copy that to s->parameters and qmp_migrate_set_parameters() will apply the 'new' params from 'config' on top s->parameters. An example:

Setting multifd-channels (default 2) using various methods and querying both QMP and HMP:

a) global overrides default:

 $ ./qemu-system-x86_64 -global migration.multifd-channels=4 ...
 => QMP: "multifd-channels": 4, HMP: multifd-channels: 4

b) migrate-set-parameter overrides global:

{ 'execute': 'migrate-set-parameters', 'arguments': { 'multifd-channels': 8 } } => QMP: "multifd-channels": 8, HMP: multifd-channels: 8

c) config not touching the parameter, value is reset to global:

{ 'execute': 'migrate', 'arguments': { ..., 'config': { 'multifd': true } } } => QMP: "multifd-channels": 4, HMP: multifd-channels: 4

d) config overrides all:

{ 'execute': 'migrate', 'arguments': { ..., 'config': {'multifd-channels': 16 } } } => QMP: "multifd-channels": 16, HMP: multifd-channels: 16

Without global:

e) default is set initially

 $ ./qemu-system-x86_64 ...
 => QMP: "multifd-channels": 2, HMP: multifd-channels: 2

f) migrate-set-parameter overrides default:

{ 'execute': 'migrate-set-parameters', 'arguments': { 'multifd-channels': 8 } } => QMP: "multifd-channels": 8, HMP: multifd-channels: 8

g) config not touching the parameter, value is reset to default:

{ 'execute': 'migrate', 'arguments': { ..., 'config': { 'multifd': true } } } => "multifd-channels": 2, HMP: multifd-channels: 2

Quoted 7 lines

h) config overrides all:

{ 'execute': 'migrate', 'arguments': { ..., 'config': {'multifd-channels': 16 } } } => QMP: "multifd-channels": 16, HMP: multifd-channels: 16

I'll update the variable names and code comments to be more precise. Sorry for the noise.

Good to know it's even working. Thanks for digging it.

Signature · 1 line
Peter Xu
#73 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

In reply to Peter Xu
Quoted 50 lines · Peter Xu
Quoted 21 lines · Fabiano Rosas
Quoted 19 lines · Peter Xu
Quoted 9 lines · Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

Quoted 6 lines

The options that are changed during the migration can still be set with the existing commands.

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

Could we still keep the QMP migrate-set-parameters values?

Quoted 7 lines
Quoted 3 lines

'config' argument > QMP setups using migrate-set-parameters >
-global cmdline > defaults (migration_properties)

That's the case. I failed to mention it in the commit message. IOW it behaves just like today, but the new 'config' way takes precedence over all.

Referring to below chunk of code:

[...]

Quoted 9 lines
Quoted 9 lines

migration/options.c static void migrate_params_apply(MigrationParameters *params) · line 1355

Quoted 9 lines
migration/options.c +9 -0
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp)
+{
+    ERRP_GUARD();
+
+    assert(bql_locked());
+
+    /* reset to default parameters */
+    migrate_params_apply(&s->defaults);

IIUC here it'll reset all global parameters using the initial defaults first, then apply the "config" specified in "migrate" QMP command?

I think there're actually two separate questions to be asked, to make it clearer, they are:

Quoted 8 lines

(1) Whether we should allow QMP "migrate" 'config' parameter to overwrite global setup?

(2) Whether we should allow previous QMP global setup to be used even if QMP "migrate" provided 'config' parameter?

So IIUC the patch does (1) YES (2) NO, while what I think might be more intuitive is (1) NO (2) YES.

The point of the 'config' parameter to the 'migrate' command is to enable the mgmt app to fully specify what it wants the configuration to be, such that there is no previously set state will will cause it surprises. Allowing -global to have an effect undermines the predictibility in the same way that migrate-set-parameter undermines the predictibility.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#74 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 60 lines · Daniel P. Berrangé
Quoted 50 lines · Peter Xu
Quoted 21 lines · Fabiano Rosas
Quoted 19 lines · Peter Xu
Quoted 9 lines · Fabiano Rosas

Allow the migrate and migrate_incoming commands to pass the migration configuration options all at once, dispensing the use of migrate-set-parameters and migrate-set-capabilities.

The motivation of this is to simplify the interface with the management layer and avoid the usage of several command invocations to configure a migration. It also avoids stale parameters from a previous migration to influence the current migration.

Quoted 6 lines

The options that are changed during the migration can still be set with the existing commands.

The order of precedence is:

'config' argument > -global cmdline > defaults (migration_properties)

Could we still keep the QMP migrate-set-parameters values?

Quoted 7 lines
Quoted 3 lines

'config' argument > QMP setups using migrate-set-parameters >
-global cmdline > defaults (migration_properties)

That's the case. I failed to mention it in the commit message. IOW it behaves just like today, but the new 'config' way takes precedence over all.

Referring to below chunk of code:

[...]

Quoted 9 lines
Quoted 9 lines

migration/options.c static void migrate_params_apply(MigrationParameters *params) · line 1355

Quoted 9 lines
migration/options.c +9 -0
+bool migrate_params_override(MigrationState *s, MigrationParameters *new,
+                             Error **errp)
+{
+    ERRP_GUARD();
+
+    assert(bql_locked());
+
+    /* reset to default parameters */
+    migrate_params_apply(&s->defaults);

IIUC here it'll reset all global parameters using the initial defaults first, then apply the "config" specified in "migrate" QMP command?

I think there're actually two separate questions to be asked, to make it clearer, they are:

Quoted 8 lines

(1) Whether we should allow QMP "migrate" 'config' parameter to overwrite global setup?

(2) Whether we should allow previous QMP global setup to be used even if QMP "migrate" provided 'config' parameter?

So IIUC the patch does (1) YES (2) NO, while what I think might be more intuitive is (1) NO (2) YES.

Quoted 6 lines

The point of the 'config' parameter to the 'migrate' command is to enable the mgmt app to fully specify what it wants the configuration to be, such that there is no previously set state will will cause it surprises. Allowing -global to have an effect undermines the predictibility in the same way that migrate-set-parameter undermines the predictibility.

Now I think I know part of what I've missed: I used to think the "config" of per-QMP-migrate-command can be totally temporary for a specific migration request, but then we need another MigrationState.parameters_2 to cache the old or vice versa; that's probably not necessary. Now I think it makes sense to overwrite any settings directly, hence I think I changed my mind on question (1), YES is fine here.

For (2), why it would introduce any uncertainty for mgmt?

If the mgmt app can both: (1) query from qapi schema knowing all the parameters supported, then (2) specify all the parameters in QMP migrate's "option" parameter. Then it's literally overwritting all the parameters, so it's predictable with or without completely removing global settings as an idea? To me, the "option" is the key to make QMP migrate command and parameter/cap setup in one "atomic-like" operation, and that provides the predictability if the command succeeded and if all the parameters are specified (otherwise it'll fail saying migration in progress, internally protected by BQL or whatever lock QMP monitor holds).

Thanks,

Signature · 1 line
Peter Xu
#75 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 8 lines · Peter Xu

Now I think I know part of what I've missed: I used to think the "config" of per-QMP-migrate-command can be totally temporary for a specific migration request, but then we need another MigrationState.parameters_2 to cache the old or vice versa; that's probably not necessary. Now I think it makes sense to overwrite any settings directly, hence I think I changed my mind on question (1), YES is fine here.

Quoted 7 lines

For (2), why it would introduce any uncertainty for mgmt?

If the mgmt app can both: (1) query from qapi schema knowing all the parameters supported, then (2) specify all the parameters in QMP migrate's "option" parameter. Then it's literally overwritting all the parameters, so it's predictable with or without completely removing global settings as an idea?

That is relying on the mgmt app specifiying absolutely every config parameter that exists. If they miss anything, then the behaviour is not well defined, as external global state still affects things.

This is the same situation we already have with migrate-set-parameter, where mgmt apps have to know to call migrate-set-parameter over & over with every possible parameter to get back to a well known starting point.

The command needs to run with the parameters provided in 'config' and no external global state, whether from -global or any prior call of migrate-set-parameter

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#76 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 21 lines · Daniel P. Berrangé
Quoted 8 lines · Peter Xu

Now I think I know part of what I've missed: I used to think the "config" of per-QMP-migrate-command can be totally temporary for a specific migration request, but then we need another MigrationState.parameters_2 to cache the old or vice versa; that's probably not necessary. Now I think it makes sense to overwrite any settings directly, hence I think I changed my mind on question (1), YES is fine here.

Quoted 7 lines

For (2), why it would introduce any uncertainty for mgmt?

If the mgmt app can both: (1) query from qapi schema knowing all the parameters supported, then (2) specify all the parameters in QMP migrate's "option" parameter. Then it's literally overwritting all the parameters, so it's predictable with or without completely removing global settings as an idea?

That is relying on the mgmt app specifiying absolutely every config parameter that exists. If they miss anything, then the behaviour is not well defined, as external global state still affects things.

Quoted 7 lines

This is the same situation we already have with migrate-set-parameter, where mgmt apps have to know to call migrate-set-parameter over & over with every possible parameter to get back to a well known starting point.

The command needs to run with the parameters provided in 'config' and no external global state, whether from -global or any prior call of migrate-set-parameter

So libvirt does not probe the qapi schema for all possible parameters? Why not do that once on QEMU boot up, then when migration is needed use a sequence of commands to make sure everything will be setup before "migrate"? It'll definitely take a few rounds of QMP commands, but the core issue is whether there can be any real atomic issues of that.

Just to say, I still think having "option" is a fine idea at least, but I'm really curious on whether there's any real issue even without it.

Thanks,

Signature · 1 line
Peter Xu
#77 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 30 lines · Peter Xu
Quoted 21 lines · Daniel P. Berrangé
Quoted 8 lines · Peter Xu

Now I think I know part of what I've missed: I used to think the "config" of per-QMP-migrate-command can be totally temporary for a specific migration request, but then we need another MigrationState.parameters_2 to cache the old or vice versa; that's probably not necessary. Now I think it makes sense to overwrite any settings directly, hence I think I changed my mind on question (1), YES is fine here.

Quoted 7 lines

For (2), why it would introduce any uncertainty for mgmt?

If the mgmt app can both: (1) query from qapi schema knowing all the parameters supported, then (2) specify all the parameters in QMP migrate's "option" parameter. Then it's literally overwritting all the parameters, so it's predictable with or without completely removing global settings as an idea?

That is relying on the mgmt app specifiying absolutely every config parameter that exists. If they miss anything, then the behaviour is not well defined, as external global state still affects things.

Quoted 7 lines

This is the same situation we already have with migrate-set-parameter, where mgmt apps have to know to call migrate-set-parameter over & over with every possible parameter to get back to a well known starting point.

The command needs to run with the parameters provided in 'config' and no external global state, whether from -global or any prior call of migrate-set-parameter

Quoted 8 lines

So libvirt does not probe the qapi schema for all possible parameters? Why not do that once on QEMU boot up, then when migration is needed use a sequence of commands to make sure everything will be setup before "migrate"? It'll definitely take a few rounds of QMP commands, but the core issue is whether there can be any real atomic issues of that.

Just to say, I still think having "option" is a fine idea at least, but I'm really curious on whether there's any real issue even without it.

Btw, one more thing to mention: IIUC libvirt shouldn't need to specify all parameters either. We have default parameters provided, now with Fabiano's work we can even have default caps being enabled now, used to controversial when being a cap. Hence, I would expect Libvirt doesn't need to specify all parameters (with/without "config") but whatever parameters it doesn't want to use the default (e.g. being specified by the user).

When we can have more sane default parameters (I do plan to turn on preempt and blocktime caps on by default for postcopy at some point, for example), I think it's better libvirt uses the default, or e.g. blocktime may have been disabled there.

Thanks,

Signature · 1 line
Peter Xu
#78 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

In reply to Peter Xu
Quoted 30 lines · Peter Xu
Quoted 21 lines · Daniel P. Berrangé
Quoted 8 lines · Peter Xu

Now I think I know part of what I've missed: I used to think the "config" of per-QMP-migrate-command can be totally temporary for a specific migration request, but then we need another MigrationState.parameters_2 to cache the old or vice versa; that's probably not necessary. Now I think it makes sense to overwrite any settings directly, hence I think I changed my mind on question (1), YES is fine here.

Quoted 7 lines

For (2), why it would introduce any uncertainty for mgmt?

If the mgmt app can both: (1) query from qapi schema knowing all the parameters supported, then (2) specify all the parameters in QMP migrate's "option" parameter. Then it's literally overwritting all the parameters, so it's predictable with or without completely removing global settings as an idea?

That is relying on the mgmt app specifiying absolutely every config parameter that exists. If they miss anything, then the behaviour is not well defined, as external global state still affects things.

Quoted 7 lines

This is the same situation we already have with migrate-set-parameter, where mgmt apps have to know to call migrate-set-parameter over & over with every possible parameter to get back to a well known starting point.

The command needs to run with the parameters provided in 'config' and no external global state, whether from -global or any prior call of migrate-set-parameter

Quoted 5 lines

So libvirt does not probe the qapi schema for all possible parameters? Why not do that once on QEMU boot up, then when migration is needed use a sequence of commands to make sure everything will be setup before "migrate"? It'll definitely take a few rounds of QMP commands, but the core issue is whether there can be any real atomic issues of that.

Probing the QAPI schema tells you what parameters exist. It does not tell you what values you should set for parameters, if you don't already know what the semantics of that parameter are. Such a requirement to probe all parameters & set them all manually is again making migration into a special case that is not following the normal QMP design, and there's no justification for that other than the historical design mistakes in migration QMP which were copied from HMP.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#79 lore raw

Re: [PATCH 19/21] migration: Allow migrate commands to provide the migration config

Quoted 31 lines · Daniel P. Berrangé
Quoted 30 lines · Peter Xu
Quoted 28 lines · Daniel P. Berrangé
Quoted 8 lines · Peter Xu

Now I think I know part of what I've missed: I used to think the "config" of per-QMP-migrate-command can be totally temporary for a specific migration request, but then we need another MigrationState.parameters_2 to cache the old or vice versa; that's probably not necessary. Now I think it makes sense to overwrite any settings directly, hence I think I changed my mind on question (1), YES is fine here.

Quoted 7 lines

For (2), why it would introduce any uncertainty for mgmt?

If the mgmt app can both: (1) query from qapi schema knowing all the parameters supported, then (2) specify all the parameters in QMP migrate's "option" parameter. Then it's literally overwritting all the parameters, so it's predictable with or without completely removing global settings as an idea?

That is relying on the mgmt app specifiying absolutely every config parameter that exists. If they miss anything, then the behaviour is not well defined, as external global state still affects things.

This is the same situation we already have with migrate-set-parameter, where mgmt apps have to know to call migrate-set-parameter over & over with every possible parameter to get back to a well known starting point.

The command needs to run with the parameters provided in 'config' and no external global state, whether from -global or any prior call of migrate-set-parameter

Quoted 8 lines
Quoted 5 lines

So libvirt does not probe the qapi schema for all possible parameters? Why not do that once on QEMU boot up, then when migration is needed use a sequence of commands to make sure everything will be setup before "migrate"? It'll definitely take a few rounds of QMP commands, but the core issue is whether there can be any real atomic issues of that.

Probing the QAPI schema tells you what parameters exist. It does not tell you what values you should set for parameters, if you don't already know

If Libvirt is looking for some suggested value to set a parameter, it should just leave it empty, using the default provided by QEMU? I was expecting Libvirt to only specify anything it explicitly knows the answer.

Quoted 5 lines

what the semantics of that parameter are. Such a requirement to probe all parameters & set them all manually is again making migration into a special case that is not following the normal QMP design, and there's no justification for that other than the historical design mistakes in migration QMP which were copied from HMP.

I agree migration is special cased.. I also agree if we design the interface today it may not be like that. I suppose it means it's only the "API cleaness" issue. That matches my understanding, even if I wished I missed something else..

That'll be a hassle for all mgmt for sure whenever an old libvirt might still have a chance to run on a newer QEMU.

That'll also be a hassle for any downstream if some Y+1 branch starts to drop the global-set way completely then downstream might need to take care of keeping that instead for the major release until the last Y, otherwise if someone installs some X.Y+1 package on X.Y it might break similarly. All that for "let's make the interface look better".

I sincerely could be wrong, but I keep my skeptical view of this whole effort; it's only about after this series (while this series still makes sense to me to have caps being able to set as params, and the "config" in general). I would say we could at least prioritize and invest other more important things, for example on handshakes, which could provide functional differences (removing src/dst param dependency, removing hackish channel establishments all over the places, early failure of device state mismatch rather than late failure on converge, etc.).

Thanks,

Signature · 1 line
Peter Xu
#80 lore raw

PATCH 20/21 libqtest: Add a function to check whether a QMP command supports a feature

In reply to Fabiano Rosas
---
 tests/qtest/libqtest.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 tests/qtest/libqtest.h | 12 ++++++++++++
 2 files changed, 54 insertions(+)
tests/qtest/libqtest.c +42 -0
index 94526b7f9c..7ee4831841 100644
@@ -34,6 +34,9 @@
 #include "qemu/ctype.h"
 #include "qemu/cutils.h"
 #include "qemu/sockets.h"
+#include "qapi/error.h"
+#include "qapi/qapi-visit-introspect.h"
+#include "qapi/qobject-input-visitor.h"
 #include "qobject/qdict.h"
 #include "qobject/qjson.h"
 #include "qobject/qlist.h"
@@ -2091,3 +2094,42 @@ bool mkimg(const char *file, const char *fmt, unsigned size_mb)
 
     return ret && !err;
 }
+
+bool qtest_qmp_cmd_has_feature(QTestState *qts, const char *cmd,
+                               const char *feature)
+{
+    QDict *resp;
+    Visitor *qiv;
+    SchemaInfoList *tail;
+    SchemaInfo *si;
+    strList *str;
+
+    resp = qtest_qmp(qts, "{ 'execute': 'query-qmp-schema' }");
+
+    qiv = qobject_input_visitor_new(qdict_get(resp, "return"));
+    visit_type_SchemaInfoList(qiv, NULL, &tail, &error_abort);
+    visit_free(qiv);
+    qobject_unref(resp);
+
+    for (; tail; tail = tail->next) {
+        si = tail->value;
+
+        if (si->meta_type != SCHEMA_META_TYPE_COMMAND) {
+            continue;
+        }
+
+        if (g_str_equal(si->name, cmd)) {
+            break;
+        }
+    }
+
+    if (tail && si->has_features) {
+        for (str = si->features; str; str = str->next) {
+            if (g_str_equal(str->value, feature)) {
+                return true;
+            }
+        }
+    }
+
+    return false;
+}
tests/qtest/libqtest.h +12 -0
index b3f2e7fbef..c609316223 100644
@@ -1153,4 +1153,16 @@ bool have_qemu_img(void);
  */
 bool mkimg(const char *file, const char *fmt, unsigned size_mb);
 
+/**
+ * qtest_qmp_cmd_has_feature:
+ * @qts: QTestState instance
+ * @cmd: The QMP command being introspected
+ * @feature: Name of the feature to be checked
+ *
+ * Returns: true if the QMP command @cmd supports @feature, false otherwise.
+ */
+bool qtest_qmp_cmd_has_feature(QTestState *qts, const char *cmd,
+                               const char *feature);
+
+
 #endif
Signature · 1 line
2.35.3
#81 lore raw

PATCH 21/21 tests/qtest/migration: Add a test for config passing

In reply to Fabiano Rosas

Pass the config directly via the migrate/incoming command.

---
 tests/qtest/migration/framework.h  |  2 ++
 tests/qtest/migration/misc-tests.c | 39 ++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+)
tests/qtest/migration/framework.h +2 -0
index 01e425e64e..e55cd33fa8 100644
@@ -145,6 +145,8 @@ typedef struct {
     /* Optional: fine tune start parameters */
     MigrateStart start;
 
+    const char *config;
+
     /* Required: the URI for the dst QEMU to listen on */
     const char *listen_uri;
 
tests/qtest/migration/misc-tests.c +39 -0
index 54995256d8..e835865aee 100644
@@ -256,6 +256,42 @@ static void test_validate_uri_channels_none_set(void)
     do_test_validate_uri_channel(&args);
 }
 
+static void test_config_migrate(void)
+{
+    QTestState *from, *to;
+    MigrateStart args = {
+        .hide_stderr = false,
+    };
+    const char *config = "{"
+        "'events':true, "
+        "'multifd':true, "
+        "'multifd-channels': 4"
+        "}";
+
+    if (migrate_start(&from, &to, "defer", &args)) {
+        return;
+    }
+
+    assert(qtest_qmp_cmd_has_feature(from, "migrate", "config"));
+
+    wait_for_serial("src_serial");
+    qtest_qmp_assert_success(from, "{ 'execute' : 'stop'}");
+    migrate_ensure_converge(from);
+
+    migrate_incoming_qmp(to, "tcp:127.0.0.1:0", NULL,
+                         "{ 'exit-on-error': false, 'config': %p }",
+                         qobject_from_json(config, &error_abort));
+
+    migrate_qmp(from, to, migrate_get_connect_uri(to), NULL,
+                "{ 'config': %p }",
+                qobject_from_json(config, &error_abort));
+
+    wait_for_migration_complete(from);
+    wait_for_migration_complete(to);
+
+    migrate_end(from, to, false);
+}
+
 static void migration_test_add_misc_smoke(MigrationTestEnv *env)
 {
 #ifndef _WIN32
@@ -294,4 +330,7 @@ void migration_test_add_misc(MigrationTestEnv *env)
                        test_validate_uri_channels_both_set);
     migration_test_add("/migration/validate_uri/channels/none_set",
                        test_validate_uri_channels_none_set);
+
+    migration_test_add("/migration/config/migrate",
+                       test_config_migrate);
 }
Signature · 1 line
2.35.3
Tested-by on the v1 series
#82 lore raw
In reply to Fabiano Rosas

This series has been successfully tested. Boot up two VMs, one in source and the other in destination with -incoming defer. Using the migrate_set_parameter, enable the postcopy-ram, after that check with info migrate_parameters this is correct.

(qemu) migrate_set_parameter postcopy-ram on
(qemu) info migrate_parameters
...
events: off
postcopy-ram: on
x-colo: off
...

Do migration plus the postcopy and check with info migrate there's a real postcopy process while migrating

(qemu) migrate -d tcp:${DST_IP}:8888
(qemu) info migrate
Status: postcopy-active
Time (ms): total=3410, setup=34, down=53
RAM info:
Throughput (Mbps): 1000.82
Sizes (KiB): pagesize=4, total=16798280,

    transferred=357703, remain=6293884,
    precopy=128792, multifd=0, postcopy=228566

Pages: normal=88199, zero=440747, rate_per_sec=34875
Others: dirty_syncs=2, postcopy_req=644

(qemu) info migrate -a
Status: postcopy-active
Sockets: [
tcp::::8888
]
Globals:
store-global-state: on
only-migratable: off
send-configuration: on
send-section-footer: on
send-switchover-start: on
clear-bitmap-shift: 18

Finally migration ends seamlessly.
(qemu) info migrate
Status: completed

Quoted 84 lines · Fabiano Rosas

Hi,

Thanks for the reviews in the last round. Your feedback has allowed me to reduce the complexity of the series and the code considerably.

Changes in this v2:

- Followed the suggestion to unify the TLS strings as StrOrNull. This allows the complete removal of the MigrateSetParameters type. Therefore, no need for playing tricks with base types.

- I figured out that block_bitmap_mapping was set as optional in qmp_query_migrate_parameters in error. Fixing that allows to simplify that function somewhat.

- The suggestion of not checking the has_* fields when setting the parameters also led to great simplification. Now there's no need to open-code the setting of every single parameter.

- Deprecated the capabilities commands.

- Removed some redundant documentation from migration.json. Now there's only 1 (one) place where migration parameters need to be documented.

The series:
- passes CI: https://gitlab.com/farosas/qemu/-/pipelines/1849885920
- passes the migration tests in the ASAN build.
- passes the migration compat tests against each of the 3 last QEMU versions.
- passes the iotest 300 (related to block_bitmap_mapping).

v1:
https://lore.kernel.org/r/[email protected]

Fabiano Rosas (21):
migration: Normalize tls arguments
migration: Remove MigrateSetParameters
qapi/migration: Don't document MigrationParameter
migration: Run a post update routine after setting parameters
migration: Add a flag to track block-bitmap-mapping input
migration: Remove checks for s->parameters has_* fields
migration: Set block_bitmap_mapping unconditionally in
query-migrate-parameters
migration: Do away with usage of QERR_INVALID_PARAMETER_VALUE
migration: Extract code to mark all parameters as present
migration: Use QAPI_CLONE_MEMBERS in query_migrate_parameters
migration: Use QAPI_CLONE_MEMBERS in migrate_params_test_apply
migration: Use QAPI_CLONE_MEMBERS in migrate_params_apply
migration: Use visitors in migrate_params_test_apply
migration: Cleanup hmp_info_migrate_parameters
migration: Add capabilities into MigrationParameters qapi/migration: Mark that query/set-migrate-parameters support
capabilities
migration: Remove s->capabilities
qapi/migration: Deprecate capabilities commands
migration: Allow migrate commands to provide the migration config
libqtest: Add a function to check whether a QMP command supports a
feature
tests/qtest/migration: Add a test for config passing

 docs/about/deprecated.rst          |   12 +
 migration/migration-hmp-cmds.c     |  484 ++++++++----
 migration/migration.c              |   50 +-
 migration/migration.h              |    9 +-
 migration/options.c                | 1090 +++++++++++++---------------
 migration/options.h                |   29 +-
 migration/page_cache.c             |    6 +-
 migration/ram.c                    |    5 +-
 migration/savevm.c                 |    8 +-
 migration/tls.c                    |    2 +-
 qapi/migration.json                |  573 ++++++---------
 qapi/pragma.json                   |    3 +-
 system/vl.c                        |    3 +-
 tests/qtest/libqtest.c             |   42 ++
 tests/qtest/libqtest.h             |   12 +
 tests/qtest/migration/framework.h  |    2 +
 tests/qtest/migration/misc-tests.c |   39 +
 17 files changed, 1243 insertions(+), 1126 deletions(-)

--
2.35.3