- bool use_int_value = false;
- int i, ret;
-
- for (i = 0; i < MIGRATION_PARAMETER__MAX; i++) {
- if (strcmp(param, MigrationParameter_lookup[i]) == 0) {
- MigrationParameters p = { 0 };
- switch (i) {
- case MIGRATION_PARAMETER_COMPRESS_LEVEL:
- p.has_compress_level = true;
- use_int_value = true;
- break;
- case MIGRATION_PARAMETER_COMPRESS_THREADS:
- p.has_compress_threads = true;
- use_int_value = true;
- break;
- case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
- p.has_decompress_threads = true;
- use_int_value = true;
- break;
- case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
- p.has_cpu_throttle_initial = true;
- use_int_value = true;
- break;
- case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
- p.has_cpu_throttle_increment = true;
- use_int_value = true;
- break;
- case MIGRATION_PARAMETER_TLS_CREDS:
- p.has_tls_creds = true;
- p.tls_creds = (char *) valuestr;
- break;
- case MIGRATION_PARAMETER_TLS_HOSTNAME:
- p.has_tls_hostname = true;
- p.tls_hostname = (char *) valuestr;
- break;
- case MIGRATION_PARAMETER_MAX_BANDWIDTH:
- p.has_max_bandwidth = true;
- ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
- if (ret < 0 || valuebw > INT64_MAX
- || (size_t)valuebw != valuebw) {
- error_setg(&err, "Invalid size %s", valuestr);
- goto cleanup;
- }
- p.max_bandwidth = valuebw;
- break;
- case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
- p.has_downtime_limit = true;
- use_int_value = true;
- break;
- case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
- p.has_x_checkpoint_delay = true;
- use_int_value = true;
- break;
- }
-
- if (use_int_value) {
- if (qemu_strtol(valuestr, NULL, 10, &valueint) < 0) {
- error_setg(&err, "Unable to parse '%s' as an int",
- valuestr);
- goto cleanup;
- }
- /* Set all integers; only one has_FOO will be set, and
- * the code ignores the remaining values */
- p.compress_level = valueint;
- p.compress_threads = valueint;
- p.decompress_threads = valueint;
- p.cpu_throttle_initial = valueint;
- p.cpu_throttle_increment = valueint;
- p.downtime_limit = valueint;
- p.x_checkpoint_delay = valueint;
- }
-
- qmp_migrate_set_parameters(&p, &err);
+ int val, ret;
+
+ val = qapi_enum_parse(&MigrationParameter_lookup, param, -1, &err);
+ if (val < 0) {
+ goto cleanup;
+ }
+
+ switch (val) {
+ case MIGRATION_PARAMETER_COMPRESS_LEVEL:
+ p->has_compress_level = true;
+ visit_type_int(v, param, &p->compress_level, &err);
+ break;
+ case MIGRATION_PARAMETER_COMPRESS_THREADS:
+ p->has_compress_threads = true;
+ visit_type_int(v, param, &p->compress_threads, &err);
+ break;
+ case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
+ p->has_decompress_threads = true;
+ visit_type_int(v, param, &p->decompress_threads, &err);
+ break;
+ case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
+ p->has_cpu_throttle_initial = true;
+ visit_type_int(v, param, &p->cpu_throttle_initial, &err);
+ break;
+ case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
+ p->has_cpu_throttle_increment = true;
+ visit_type_int(v, param, &p->cpu_throttle_increment, &err);
+ break;
+ case MIGRATION_PARAMETER_TLS_CREDS:
+ p->has_tls_creds = true;
+ p->tls_creds = g_new0(StrOrNull, 1);
+ p->tls_creds->type = QTYPE_QSTRING;
+ visit_type_str(v, param, &p->tls_creds->u.s, &err);
+ break;
+ case MIGRATION_PARAMETER_TLS_HOSTNAME:
+ p->has_tls_hostname = true;
+ p->tls_hostname = g_new0(StrOrNull, 1);
+ p->tls_hostname->type = QTYPE_QSTRING;
+ visit_type_str(v, param, &p->tls_hostname->u.s, &err);
+ break;
+ case MIGRATION_PARAMETER_MAX_BANDWIDTH:
+ p->has_max_bandwidth = true;
+ /*
+ * Can't use visit_type_size() here, because it
+ * defaults to Bytes rather than Mebibytes.
+ */
+ ret = qemu_strtosz_MiB(valuestr, NULL, &valuebw);
+ if (ret < 0 || valuebw > INT64_MAX
+ || (size_t)valuebw != valuebw) {
+ error_setg(&err, "Invalid size %s", valuestr);