[Qemu-devel] [PULL 08/15] migrate: Use boxed qapi for migrate-set-parameters

2016-10-14 Thread Juan Quintela
From: Eric Blake 

Now that QAPI makes it easy to pass a struct around, we don't
have to declare as many parameters or local variables.

Signed-off-by: Eric Blake 
Reviewed-by: Marc-André Lureau 
Reviewed-by: Juan Quintela 
Signed-off-by: Juan Quintela 
---
 hmp.c | 40 ++-
 migration/migration.c | 65 +--
 qapi-schema.json  |  2 +-
 3 files changed, 46 insertions(+), 61 deletions(-)

diff --git a/hmp.c b/hmp.c
index c405d3e..4c0f600 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1325,44 +1325,40 @@ void hmp_migrate_set_parameter(Monitor *mon, const 
QDict *qdict)
 const char *valuestr = qdict_get_str(qdict, "value");
 long valueint = 0;
 Error *err = NULL;
-bool has_compress_level = false;
-bool has_compress_threads = false;
-bool has_decompress_threads = false;
-bool has_cpu_throttle_initial = false;
-bool has_cpu_throttle_increment = false;
-bool has_tls_creds = false;
-bool has_tls_hostname = false;
 bool use_int_value = false;
 int i;

 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:
-has_compress_level = true;
+p.has_compress_level = true;
 use_int_value = true;
 break;
 case MIGRATION_PARAMETER_COMPRESS_THREADS:
-has_compress_threads = true;
+p.has_compress_threads = true;
 use_int_value = true;
 break;
 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
-has_decompress_threads = true;
+p.has_decompress_threads = true;
 use_int_value = true;
 break;
 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
-has_cpu_throttle_initial = true;
+p.has_cpu_throttle_initial = true;
 use_int_value = true;
 break;
 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
-has_cpu_throttle_increment = true;
+p.has_cpu_throttle_increment = true;
 use_int_value = true;
 break;
 case MIGRATION_PARAMETER_TLS_CREDS:
-has_tls_creds = true;
+p.has_tls_creds = true;
+p.tls_creds = (char *) valuestr;
 break;
 case MIGRATION_PARAMETER_TLS_HOSTNAME:
-has_tls_hostname = true;
+p.has_tls_hostname = true;
+p.tls_hostname = (char *) valuestr;
 break;
 }

@@ -1372,16 +1368,16 @@ void hmp_migrate_set_parameter(Monitor *mon, const 
QDict *qdict)
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;
 }

-qmp_migrate_set_parameters(has_compress_level, valueint,
-   has_compress_threads, valueint,
-   has_decompress_threads, valueint,
-   has_cpu_throttle_initial, valueint,
-   has_cpu_throttle_increment, valueint,
-   has_tls_creds, valuestr,
-   has_tls_hostname, valuestr,
-   &err);
+qmp_migrate_set_parameters(&p, &err);
 break;
 }
 }
diff --git a/migration/migration.c b/migration/migration.c
index 1a8f26b..42336e3 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -766,78 +766,67 @@ void 
qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
 }
 }

-void qmp_migrate_set_parameters(bool has_compress_level,
-int64_t compress_level,
-bool has_compress_threads,
-int64_t compress_threads,
-bool has_decompress_threads,
-int64_t decompress_threads,
-bool has_cpu_throttle_initial,
-int64_t cpu_throttle_initial,
-bool has_cpu_throttle_increment,
-int64_t cpu_throttle_increment,
-bool has_tls_creds,
-const char *tls_cr

[Qemu-devel] [PULL 08/15] migrate: Use boxed qapi for migrate-set-parameters

2016-10-05 Thread Juan Quintela
From: Eric Blake 

Now that QAPI makes it easy to pass a struct around, we don't
have to declare as many parameters or local variables.

Signed-off-by: Eric Blake 
Reviewed-by: Marc-André Lureau 
Reviewed-by: Juan Quintela 
Signed-off-by: Juan Quintela 
---
 hmp.c | 40 ++-
 migration/migration.c | 65 +--
 qapi-schema.json  |  2 +-
 3 files changed, 46 insertions(+), 61 deletions(-)

diff --git a/hmp.c b/hmp.c
index ce741a5..5f52ee2 100644
--- a/hmp.c
+++ b/hmp.c
@@ -1260,44 +1260,40 @@ void hmp_migrate_set_parameter(Monitor *mon, const 
QDict *qdict)
 const char *valuestr = qdict_get_str(qdict, "value");
 long valueint = 0;
 Error *err = NULL;
-bool has_compress_level = false;
-bool has_compress_threads = false;
-bool has_decompress_threads = false;
-bool has_cpu_throttle_initial = false;
-bool has_cpu_throttle_increment = false;
-bool has_tls_creds = false;
-bool has_tls_hostname = false;
 bool use_int_value = false;
 int i;

 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:
-has_compress_level = true;
+p.has_compress_level = true;
 use_int_value = true;
 break;
 case MIGRATION_PARAMETER_COMPRESS_THREADS:
-has_compress_threads = true;
+p.has_compress_threads = true;
 use_int_value = true;
 break;
 case MIGRATION_PARAMETER_DECOMPRESS_THREADS:
-has_decompress_threads = true;
+p.has_decompress_threads = true;
 use_int_value = true;
 break;
 case MIGRATION_PARAMETER_CPU_THROTTLE_INITIAL:
-has_cpu_throttle_initial = true;
+p.has_cpu_throttle_initial = true;
 use_int_value = true;
 break;
 case MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT:
-has_cpu_throttle_increment = true;
+p.has_cpu_throttle_increment = true;
 use_int_value = true;
 break;
 case MIGRATION_PARAMETER_TLS_CREDS:
-has_tls_creds = true;
+p.has_tls_creds = true;
+p.tls_creds = (char *) valuestr;
 break;
 case MIGRATION_PARAMETER_TLS_HOSTNAME:
-has_tls_hostname = true;
+p.has_tls_hostname = true;
+p.tls_hostname = (char *) valuestr;
 break;
 }

@@ -1307,16 +1303,16 @@ void hmp_migrate_set_parameter(Monitor *mon, const 
QDict *qdict)
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;
 }

-qmp_migrate_set_parameters(has_compress_level, valueint,
-   has_compress_threads, valueint,
-   has_decompress_threads, valueint,
-   has_cpu_throttle_initial, valueint,
-   has_cpu_throttle_increment, valueint,
-   has_tls_creds, valuestr,
-   has_tls_hostname, valuestr,
-   &err);
+qmp_migrate_set_parameters(&p, &err);
 break;
 }
 }
diff --git a/migration/migration.c b/migration/migration.c
index 1a8f26b..42336e3 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -766,78 +766,67 @@ void 
qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
 }
 }

-void qmp_migrate_set_parameters(bool has_compress_level,
-int64_t compress_level,
-bool has_compress_threads,
-int64_t compress_threads,
-bool has_decompress_threads,
-int64_t decompress_threads,
-bool has_cpu_throttle_initial,
-int64_t cpu_throttle_initial,
-bool has_cpu_throttle_increment,
-int64_t cpu_throttle_increment,
-bool has_tls_creds,
-const char *tls_cr