All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, eblake@redhat.com, berrange@redhat.com,
	kwolf@redhat.com, mreitz@redhat.com, qemu-block@nongnu.org,
	quintela@redhat.com
Subject: Re: [Qemu-devel] [PATCH for-2.10 06/10] hmp: Clean up and simplify hmp_migrate_set_parameter()
Date: Tue, 18 Jul 2017 18:09:53 +0100	[thread overview]
Message-ID: <20170718170953.GD2106@work-vm> (raw)
In-Reply-To: <1500385286-21142-7-git-send-email-armbru@redhat.com>

* Markus Armbruster (armbru@redhat.com) wrote:
> The bulk of hmp_migrate_set_parameter()'s code sets one member of
> MigrationParameters according to the command's arguments.  It uses a
> string visitor for integer and boolean members, but not for string and
> size members.  It calls visit_type_bool() right away, but delays
> visit_type_int() some.  The delaying requires a flag variable and a
> bit of trickery: we set all integer members instead of just the one we
> want, and rely on the has_FOOs to mask the unwanted ones.
> 
> Clean this up as follows.  Don't delay calling visit_type_int().  Use
> the string visitor for strings, too.  This involves extra allocations
> and cleanup, but doing them is simpler and cleaner than avoiding them.
> 
> Sadly, using the string visitor for sizes isn't possible, because it
> defaults to Bytes rather than Mebibytes.  Add a comment explaining
> that.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

> ---
>  hmp.c | 78 ++++++++++++++++++++++++++++---------------------------------------
>  1 file changed, 32 insertions(+), 46 deletions(-)
> 
> diff --git a/hmp.c b/hmp.c
> index 6d32c40..2993586 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -1509,90 +1509,75 @@ 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);
> +    MigrationParameters *p = g_new0(MigrationParameters, 1);
>      uint64_t valuebw = 0;
> -    int64_t valueint = 0;
> -    bool valuebool = false;
>      Error *err = NULL;
> -    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;
> +                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;
> -                use_int_value = true;
> +                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;
> -                use_int_value = true;
> +                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;
> -                use_int_value = true;
> +                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;
> -                use_int_value = true;
> +                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 = (char *) valuestr;
> +                p->has_tls_creds = true;
> +                visit_type_str(v, param, &p->tls_creds, &err);
>                  break;
>              case MIGRATION_PARAMETER_TLS_HOSTNAME:
> -                p.has_tls_hostname = true;
> -                p.tls_hostname = (char *) valuestr;
> +                p->has_tls_hostname = true;
> +                visit_type_str(v, param, &p->tls_hostname, &err);
>                  break;
>              case MIGRATION_PARAMETER_MAX_BANDWIDTH:
> -                p.has_max_bandwidth = true;
> +                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);
> -                    goto cleanup;
> +                    break;
>                  }
> -                p.max_bandwidth = valuebw;
> +                p->max_bandwidth = valuebw;
>                  break;
>              case MIGRATION_PARAMETER_DOWNTIME_LIMIT:
> -                p.has_downtime_limit = true;
> -                use_int_value = true;
> +                p->has_downtime_limit = true;
> +                visit_type_int(v, param, &p->downtime_limit, &err);
>                  break;
>              case MIGRATION_PARAMETER_X_CHECKPOINT_DELAY:
> -                p.has_x_checkpoint_delay = true;
> -                use_int_value = true;
> +                p->has_x_checkpoint_delay = true;
> +                visit_type_int(v, param, &p->x_checkpoint_delay, &err);
>                  break;
>              case MIGRATION_PARAMETER_BLOCK_INCREMENTAL:
> -                p.has_block_incremental = true;
> -                visit_type_bool(v, param, &valuebool, &err);
> -                if (err) {
> -                    goto cleanup;
> -                }
> -                p.block_incremental = valuebool;
> +                p->has_block_incremental = true;
> +                visit_type_bool(v, param, &p->block_incremental, &err);
>                  break;
>              }
>  
> -            if (use_int_value) {
> -                visit_type_int(v, param, &valueint, &err);
> -                if (err) {
> -                    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;
> +            if (err) {
> +                goto cleanup;
>              }
>  
> -            qmp_migrate_set_parameters(&p, &err);
> +            qmp_migrate_set_parameters(p, &err);
>              break;
>          }
>      }
> @@ -1602,6 +1587,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const QDict *qdict)
>      }
>  
>   cleanup:
> +    qapi_free_MigrationParameters(p);
>      visit_free(v);
>      if (err) {
>          error_report_err(err);
> -- 
> 2.7.5
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

  parent reply	other threads:[~2017-07-18 17:10 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-18 13:41 [Qemu-devel] [PATCH for-2.10 00/10] Correct two minor QMP interface design flaws Markus Armbruster
2017-07-18 13:41 ` [Qemu-devel] [PATCH for-2.10 01/10] qapi: Separate type QNull from QObject Markus Armbruster
2017-07-18 14:24   ` Eric Blake
2017-07-18 15:44   ` Daniel P. Berrange
2017-07-18 13:41 ` [Qemu-devel] [PATCH for-2.10 02/10] qapi: Use QNull for a more regular visit_type_null() Markus Armbruster
2017-07-18 14:36   ` Eric Blake
2017-07-18 15:05     ` Markus Armbruster
2017-07-18 15:46   ` Daniel P. Berrange
2017-07-18 13:41 ` [Qemu-devel] [PATCH for-2.10 03/10] qapi: Introduce a first class 'null' type Markus Armbruster
2017-07-18 14:53   ` Eric Blake
2017-07-18 14:54     ` Eric Blake
2017-07-18 15:21       ` Markus Armbruster
2017-07-18 19:43         ` Markus Armbruster
2017-07-18 19:47           ` Eric Blake
2017-07-18 20:02             ` Markus Armbruster
2017-07-18 20:08           ` Eric Blake
2017-07-18 20:27             ` Markus Armbruster
2017-07-18 15:20     ` Markus Armbruster
2017-07-18 15:47   ` Daniel P. Berrange
2017-07-18 13:41 ` [Qemu-devel] [PATCH for-2.10 04/10] tests/test-qobject-input-visitor: Drop redundant test Markus Armbruster
2017-07-18 15:13   ` Eric Blake
2017-07-18 15:47   ` Daniel P. Berrange
2017-07-18 13:41 ` [Qemu-devel] [PATCH for-2.10 05/10] block: Use JSON null instead of "" to disable backing file Markus Armbruster
2017-07-18 15:53   ` Daniel P. Berrange
2017-07-18 17:27   ` Eric Blake
2017-07-18 13:41 ` [Qemu-devel] [PATCH for-2.10 06/10] hmp: Clean up and simplify hmp_migrate_set_parameter() Markus Armbruster
2017-07-18 15:54   ` Daniel P. Berrange
2017-07-18 17:09   ` Dr. David Alan Gilbert [this message]
2017-07-18 17:34   ` Eric Blake
2017-07-18 18:28     ` Markus Armbruster
2017-07-18 13:41 ` [Qemu-devel] [PATCH for-2.10 07/10] migration: Clean up around tls_creds, tls_hostname Markus Armbruster
2017-07-18 15:57   ` Daniel P. Berrange
2017-07-18 17:36   ` Eric Blake
2017-07-18 17:37   ` Dr. David Alan Gilbert
2017-07-18 13:41 ` [Qemu-devel] [PATCH for-2.10 08/10] migration: Add TODO comments on duplication of QAPI_CLONE() Markus Armbruster
2017-07-18 15:57   ` Daniel P. Berrange
2017-07-18 17:36   ` Eric Blake
2017-07-18 13:41 ` [Qemu-devel] [PATCH for-2.10 09/10] migration: Unshare MigrationParameters struct for now Markus Armbruster
2017-07-18 16:01   ` Daniel P. Berrange
2017-07-18 17:42   ` Eric Blake
2017-07-18 13:41 ` [Qemu-devel] [PATCH for-2.10 10/10] migration: Use JSON null instead of "" to reset parameter to default Markus Armbruster
2017-07-18 16:03   ` Daniel P. Berrange
2017-07-18 17:46   ` Eric Blake
2017-07-18 18:37     ` Markus Armbruster
2017-07-18 18:39     ` Markus Armbruster
2017-07-18 19:09       ` Eric Blake
2017-07-18 19:32         ` Markus Armbruster
2017-07-18 19:55           ` Eric Blake
2017-07-18 17:52   ` Dr. David Alan Gilbert
2017-07-18 19:24     ` Markus Armbruster
2017-07-19  8:32       ` Daniel P. Berrange
2017-07-18 14:02 ` [Qemu-devel] [PATCH for-2.10 00/10] Correct two minor QMP interface design flaws no-reply
2017-07-18 16:08 ` Daniel P. Berrange
2017-07-19  6:12   ` Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170718170953.GD2106@work-vm \
    --to=dgilbert@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.