qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrange" <berrange@redhat.com>
To: Juan Quintela <quintela@redhat.com>,
	Markus Armbruster <armbru@redhat.com>
Cc: qemu-devel@nongnu.org, lvivier@redhat.com, dgilbert@redhat.com,
	peterx@redhat.com
Subject: Re: [Qemu-devel] [PATCH 10/10] migration: [RFC] Use proper types in json
Date: Wed, 11 Oct 2017 10:28:15 +0100	[thread overview]
Message-ID: <20171011092815.GE20372@redhat.com> (raw)
In-Reply-To: <20171010181542.24168-11-quintela@redhat.com>

On Tue, Oct 10, 2017 at 08:15:42PM +0200, Juan Quintela wrote:
> We use int for everything (int64_t), and then we check that value is
> between 0 and 255.  Change it to the valid types.
> 
> For qmp, the only real change is that now max_bandwidth allows to use
> the k/M/G suffixes.

So on input apps previous would use:

    "max-bandwidth":  1024

ie json numeric field, and would expect to see the same when reading
data back from QEMU.

With this change they could use a string field

    "max-bandwidth":  "1k"

As long as QEMU's JSON parser accepts both number & string values
for the 'size' type it is still backwards compatible if an app
continues to use 1024 instead of "1k"

On *output* though (ie 'info migrate-parameters') this is not
compatible for applications, unless QEMU *always* uses the
numeric format when generating values. ie it must always
report 1024, and never "1k", as apps won't be expecting a string
with suffix.  I can't 100% tell whether this is the case or not,
so CC'ing Markus to confirm if changing "int" to "size" is
guaranteed back-compat in both directions

> Signed-off-by: Juan Quintela <quintela@redhat.com>
> ---
>  hmp.c                 | 22 +++++++++++-----------
>  migration/migration.c | 49 ++++++++++++++++++++-----------------------------
>  qapi/migration.json   | 20 ++++++++++----------
>  3 files changed, 41 insertions(+), 50 deletions(-)
> 
> diff --git a/hmp.c b/hmp.c
> index f73232399a..905dc93aef 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -293,23 +293,23 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
>  
>      if (params) {
>          assert(params->has_compress_level);
> -        monitor_printf(mon, "%s: %" PRId64 "\n",
> +        monitor_printf(mon, "%s: %u\n",
>              MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_LEVEL),
>              params->compress_level);
>          assert(params->has_compress_threads);
> -        monitor_printf(mon, "%s: %" PRId64 "\n",
> +        monitor_printf(mon, "%s: %u\n",
>              MigrationParameter_str(MIGRATION_PARAMETER_COMPRESS_THREADS),
>              params->compress_threads);
>          assert(params->has_decompress_threads);
> -        monitor_printf(mon, "%s: %" PRId64 "\n",
> +        monitor_printf(mon, "%s: %u\n",
>              MigrationParameter_str(MIGRATION_PARAMETER_DECOMPRESS_THREADS),
>              params->decompress_threads);
>          assert(params->has_cpu_throttle_initial);
> -        monitor_printf(mon, "%s: %" PRId64 "\n",
> +        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: %" PRId64 "\n",
> +        monitor_printf(mon, "%s: %u\n",
>              MigrationParameter_str(MIGRATION_PARAMETER_CPU_THROTTLE_INCREMENT),
>              params->cpu_throttle_increment);
>          assert(params->has_tls_creds);
> @@ -321,28 +321,28 @@ void hmp_info_migrate_parameters(Monitor *mon, const QDict *qdict)
>              MigrationParameter_str(MIGRATION_PARAMETER_TLS_HOSTNAME),
>              params->tls_hostname);
>          assert(params->has_max_bandwidth);
> -        monitor_printf(mon, "%s: %" PRId64 " bytes/second\n",
> +        monitor_printf(mon, "%s: %" PRIu64 " bytes/second\n",
>              MigrationParameter_str(MIGRATION_PARAMETER_MAX_BANDWIDTH),
>              params->max_bandwidth);
>          assert(params->has_downtime_limit);
> -        monitor_printf(mon, "%s: %" PRId64 " milliseconds\n",
> +        monitor_printf(mon, "%s: %" PRIu64 " milliseconds\n",
>              MigrationParameter_str(MIGRATION_PARAMETER_DOWNTIME_LIMIT),
>              params->downtime_limit);
>          assert(params->has_x_checkpoint_delay);
> -        monitor_printf(mon, "%s: %" PRId64 "\n",
> +        monitor_printf(mon, "%s: %u\n",
>              MigrationParameter_str(MIGRATION_PARAMETER_X_CHECKPOINT_DELAY),
>              params->x_checkpoint_delay);
>          assert(params->has_block_incremental);
>          monitor_printf(mon, "%s: %s\n",
>              MigrationParameter_str(MIGRATION_PARAMETER_BLOCK_INCREMENTAL),
>              params->block_incremental ? "on" : "off");
> -        monitor_printf(mon, "%s: %" PRId64 "\n",
> +        monitor_printf(mon, "%s: %u\n",
>              MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_CHANNELS),
>              params->x_multifd_channels);
> -        monitor_printf(mon, "%s: %" PRId64 "\n",
> +        monitor_printf(mon, "%s: %u\n",
>              MigrationParameter_str(MIGRATION_PARAMETER_X_MULTIFD_PAGE_COUNT),
>              params->x_multifd_page_count);
> -        monitor_printf(mon, "%s: %" PRId64 "\n",
> +        monitor_printf(mon, "%s: %" PRIu64 "\n",
>              MigrationParameter_str(MIGRATION_PARAMETER_XBZRLE_CACHE_SIZE),
>              params->xbzrle_cache_size);
>      }
> diff --git a/migration/migration.c b/migration/migration.c
> index fcc0d64625..6d6dcc4e42 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -734,22 +734,20 @@ void qmp_migrate_set_capabilities(MigrationCapabilityStatusList *params,
>  static bool migrate_params_check(MigrationParameters *params, Error **errp)
>  {
>      if (params->has_compress_level &&
> -        (params->compress_level < 0 || params->compress_level > 9)) {
> +        (params->compress_level > 9)) {
>          error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "compress_level",
>                     "is invalid, it should be in the range of 0 to 9");
>          return false;
>      }
>  
> -    if (params->has_compress_threads &&
> -        (params->compress_threads < 1 || params->compress_threads > 255)) {
> +    if (params->has_compress_threads && (params->compress_threads < 1)) {
>          error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
>                     "compress_threads",
>                     "is invalid, it should be in the range of 1 to 255");
>          return false;
>      }
>  
> -    if (params->has_decompress_threads &&
> -        (params->decompress_threads < 1 || params->decompress_threads > 255)) {
> +    if (params->has_decompress_threads && (params->decompress_threads < 1)) {
>          error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
>                     "decompress_threads",
>                     "is invalid, it should be in the range of 1 to 255");
> @@ -774,38 +772,31 @@ static bool migrate_params_check(MigrationParameters *params, Error **errp)
>          return false;
>      }
>  
> -    if (params->has_max_bandwidth &&
> -        (params->max_bandwidth < 0 || params->max_bandwidth > SIZE_MAX)) {
> +    if (params->has_max_bandwidth && (params->max_bandwidth > SIZE_MAX)) {
>          error_setg(errp, "Parameter 'max_bandwidth' expects an integer in the"
>                           " range of 0 to %zu bytes/second", SIZE_MAX);
>          return false;
>      }
>  
>      if (params->has_downtime_limit &&
> -        (params->downtime_limit < 0 ||
> -         params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {
> +        (params->downtime_limit > MAX_MIGRATE_DOWNTIME)) {
>          error_setg(errp, "Parameter 'downtime_limit' expects an integer in "
>                           "the range of 0 to %d milliseconds",
>                           MAX_MIGRATE_DOWNTIME);
>          return false;
>      }
>  
> -    if (params->has_x_checkpoint_delay && (params->x_checkpoint_delay < 0)) {
> -        error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
> -                    "x_checkpoint_delay",
> -                    "is invalid, it should be positive");
> -        return false;
> -    }
> -    if (params->has_x_multifd_channels &&
> -        (params->x_multifd_channels < 1 || params->x_multifd_channels > 255)) {
> +    /* x_checkpoint_delay is now always positive */
> +
> +    if (params->has_x_multifd_channels && (params->x_multifd_channels < 1)) {
>          error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
>                     "multifd_channels",
>                     "is invalid, it should be in the range of 1 to 255");
>          return false;
>      }
>      if (params->has_x_multifd_page_count &&
> -            (params->x_multifd_page_count < 1 ||
> -             params->x_multifd_page_count > 10000)) {
> +        (params->x_multifd_page_count < 1 ||
> +         params->x_multifd_page_count > 10000)) {
>          error_setg(errp, QERR_INVALID_PARAMETER_VALUE,
>                     "multifd_page_count",
>                     "is invalid, it should be in the range of 1 to 10000");
> @@ -2301,33 +2292,33 @@ static Property migration_properties[] = {
>                       send_section_footer, true),
>  
>      /* Migration parameters */
> -    DEFINE_PROP_INT64("x-compress-level", MigrationState,
> +    DEFINE_PROP_UINT8("x-compress-level", MigrationState,
>                        parameters.compress_level,
>                        DEFAULT_MIGRATE_COMPRESS_LEVEL),
> -    DEFINE_PROP_INT64("x-compress-threads", MigrationState,
> +    DEFINE_PROP_UINT8("x-compress-threads", MigrationState,
>                        parameters.compress_threads,
>                        DEFAULT_MIGRATE_COMPRESS_THREAD_COUNT),
> -    DEFINE_PROP_INT64("x-decompress-threads", MigrationState,
> +    DEFINE_PROP_UINT8("x-decompress-threads", MigrationState,
>                        parameters.decompress_threads,
>                        DEFAULT_MIGRATE_DECOMPRESS_THREAD_COUNT),
> -    DEFINE_PROP_INT64("x-cpu-throttle-initial", MigrationState,
> +    DEFINE_PROP_UINT8("x-cpu-throttle-initial", MigrationState,
>                        parameters.cpu_throttle_initial,
>                        DEFAULT_MIGRATE_CPU_THROTTLE_INITIAL),
> -    DEFINE_PROP_INT64("x-cpu-throttle-increment", MigrationState,
> +    DEFINE_PROP_UINT8("x-cpu-throttle-increment", MigrationState,
>                        parameters.cpu_throttle_increment,
>                        DEFAULT_MIGRATE_CPU_THROTTLE_INCREMENT),
> -    DEFINE_PROP_INT64("x-max-bandwidth", MigrationState,
> +    DEFINE_PROP_SIZE("x-max-bandwidth", MigrationState,
>                        parameters.max_bandwidth, MAX_THROTTLE),
> -    DEFINE_PROP_INT64("x-downtime-limit", MigrationState,
> +    DEFINE_PROP_UINT64("x-downtime-limit", MigrationState,
>                        parameters.downtime_limit,
>                        DEFAULT_MIGRATE_SET_DOWNTIME),
> -    DEFINE_PROP_INT64("x-checkpoint-delay", MigrationState,
> +    DEFINE_PROP_UINT32("x-checkpoint-delay", MigrationState,
>                        parameters.x_checkpoint_delay,
>                        DEFAULT_MIGRATE_X_CHECKPOINT_DELAY),
> -    DEFINE_PROP_INT64("x-multifd-channels", MigrationState,
> +    DEFINE_PROP_UINT8("x-multifd-channels", MigrationState,
>                        parameters.x_multifd_channels,
>                        DEFAULT_MIGRATE_MULTIFD_CHANNELS),
> -    DEFINE_PROP_INT64("x-multifd-page-count", MigrationState,
> +    DEFINE_PROP_UINT32("x-multifd-page-count", MigrationState,
>                        parameters.x_multifd_page_count,
>                        DEFAULT_MIGRATE_MULTIFD_PAGE_COUNT),
>      DEFINE_PROP_SIZE("xbzrle-cache-size", MigrationState,
> diff --git a/qapi/migration.json b/qapi/migration.json
> index 830b2e4480..81bd979912 100644
> --- a/qapi/migration.json
> +++ b/qapi/migration.json
> @@ -656,19 +656,19 @@
>  # Since: 2.4
>  ##
>  { 'struct': 'MigrationParameters',
> -  'data': { '*compress-level': 'int',
> -            '*compress-threads': 'int',
> -            '*decompress-threads': 'int',
> -            '*cpu-throttle-initial': 'int',
> -            '*cpu-throttle-increment': 'int',
> +  'data': { '*compress-level': 'uint8',
> +            '*compress-threads': 'uint8',
> +            '*decompress-threads': 'uint8',
> +            '*cpu-throttle-initial': 'uint8',
> +            '*cpu-throttle-increment': 'uint8',
>              '*tls-creds': 'str',
>              '*tls-hostname': 'str',
> -            '*max-bandwidth': 'int',
> -            '*downtime-limit': 'int',
> -            '*x-checkpoint-delay': 'int',
> +            '*max-bandwidth': 'size',
> +            '*downtime-limit': 'uint64',
> +            '*x-checkpoint-delay': 'uint32',
>              '*block-incremental': 'bool' ,
> -            '*x-multifd-channels': 'int',
> -            '*x-multifd-page-count': 'int',
> +            '*x-multifd-channels': 'uint8',
> +            '*x-multifd-page-count': 'uint32',
>              '*xbzrle-cache-size': 'size' } }
>  
>  ##
> -- 
> 2.13.6
> 
> 

Regards,
Daniel
-- 
|: 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 :|

  reply	other threads:[~2017-10-11  9:28 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-10 18:15 [Qemu-devel] [PATCH 00/10] Make xbzrle_cache_size a migration parameter Juan Quintela
2017-10-10 18:15 ` [Qemu-devel] [PATCH 01/10] migration: Fix migrate_test_apply for multifd parameters Juan Quintela
2017-10-12  5:46   ` Peter Xu
2017-10-18  8:37     ` Juan Quintela
2017-10-10 18:15 ` [Qemu-devel] [PATCH 02/10] migratiom: Remove max_item_age parameter Juan Quintela
2017-10-12  5:46   ` Peter Xu
2017-10-10 18:15 ` [Qemu-devel] [PATCH 03/10] migration: Make cache size elements use the right types Juan Quintela
2017-10-12 10:01   ` Dr. David Alan Gilbert
2017-10-10 18:15 ` [Qemu-devel] [PATCH 04/10] migration: Move xbzrle cache resize error handling to xbzrle_cache_resize Juan Quintela
2017-10-12  5:48   ` Peter Xu
2017-10-10 18:15 ` [Qemu-devel] [PATCH 05/10] migration: Make cache_init() take an error parameter Juan Quintela
2017-10-12  5:55   ` Peter Xu
2017-10-10 18:15 ` [Qemu-devel] [PATCH 06/10] migration: Make sure that we pass the right cache size Juan Quintela
2017-10-12  5:57   ` Peter Xu
2017-10-18  8:45     ` Juan Quintela
2017-10-10 18:15 ` [Qemu-devel] [PATCH 07/10] migration: Don't play games with the requested " Juan Quintela
2017-10-10 18:15 ` [Qemu-devel] [PATCH 08/10] migration: No need to return the size of the cache Juan Quintela
2017-10-10 18:15 ` [Qemu-devel] [PATCH 09/10] migration: Make xbzrle_cache_size a migration parameter Juan Quintela
2017-10-12 12:04   ` Dr. David Alan Gilbert
2017-10-18  8:50     ` Juan Quintela
2017-10-10 18:15 ` [Qemu-devel] [PATCH 10/10] migration: [RFC] Use proper types in json Juan Quintela
2017-10-11  9:28   ` Daniel P. Berrange [this message]
2017-10-11  9:41     ` Juan Quintela
2017-11-06 14:26       ` Markus Armbruster
2017-11-08  9:41         ` Juan Quintela
2017-11-08 10:25           ` Markus Armbruster

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=20171011092815.GE20372@redhat.com \
    --to=berrange@redhat.com \
    --cc=armbru@redhat.com \
    --cc=dgilbert@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=peterx@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).