Re: [Qemu-devel] [PATCH 15/24] util/cutils: Rename qemu_strtosz() to qemu_strtosz_mebi()

2017-02-17 Thread Eric Blake
On 02/14/2017 04:26 AM, Markus Armbruster wrote:
> With qemu_strtosz(), no suffix means mebibytes.  It's used rarely.
> I'm going to add a similar function where no suffix means bytes.
> Rename qemu_strtosz() to qemu_strtosz_mebi() to make the name
> qemu_strtosz() available for the new function.
> 
> Signed-off-by: Markus Armbruster 
> ---

With the conversion to Paolo's suggested naming (s/mebi/MiB/),

Reviewed-by: Eric Blake 

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature


Re: [Qemu-devel] [PATCH 15/24] util/cutils: Rename qemu_strtosz() to qemu_strtosz_mebi()

2017-02-14 Thread Paolo Bonzini


On 14/02/2017 11:26, Markus Armbruster wrote:
> With qemu_strtosz(), no suffix means mebibytes.  It's used rarely.
> I'm going to add a similar function where no suffix means bytes.
> Rename qemu_strtosz() to qemu_strtosz_mebi() to make the name
> qemu_strtosz() available for the new function.

What about qemu_strtosz_MiB (yes, camelcase intended).

Paolo

> 
> Signed-off-by: Markus Armbruster 
> ---
>  hmp.c |  2 +-
>  hw/misc/ivshmem.c |  2 +-
>  include/qemu/cutils.h |  2 +-
>  monitor.c |  2 +-
>  tests/test-cutils.c   | 38 +++---
>  util/cutils.c |  2 +-
>  6 files changed, 24 insertions(+), 24 deletions(-)
> 
> diff --git a/hmp.c b/hmp.c
> index 2bc4f06..6d0d05b 100644
> --- a/hmp.c
> +++ b/hmp.c
> @@ -1379,7 +1379,7 @@ void hmp_migrate_set_parameter(Monitor *mon, const 
> QDict *qdict)
>  break;
>  case MIGRATION_PARAMETER_MAX_BANDWIDTH:
>  p.has_max_bandwidth = true;
> -valuebw = qemu_strtosz(valuestr, );
> +valuebw = qemu_strtosz_mebi(valuestr, );
>  if (valuebw < 0 || (size_t)valuebw != valuebw
>  || *endp != '\0') {
>  error_setg(, "Invalid size %s", valuestr);
> diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c
> index bf57e63..382dd8b 100644
> --- a/hw/misc/ivshmem.c
> +++ b/hw/misc/ivshmem.c
> @@ -1268,7 +1268,7 @@ static void ivshmem_realize(PCIDevice *dev, Error 
> **errp)
>  s->legacy_size = 4 << 20; /* 4 MB default */
>  } else {
>  char *end;
> -int64_t size = qemu_strtosz(s->sizearg, );
> +int64_t size = qemu_strtosz_mebi(s->sizearg, );
>  if (size < 0 || (size_t)size != size || *end != '\0'
>  || !is_power_of_2(size)) {
>  error_setg(errp, "Invalid size %s", s->sizearg);
> diff --git a/include/qemu/cutils.h b/include/qemu/cutils.h
> index 81613d0..5f4e138 100644
> --- a/include/qemu/cutils.h
> +++ b/include/qemu/cutils.h
> @@ -153,9 +153,9 @@ int parse_uint_full(const char *s, unsigned long long 
> *value, int base);
>  #define QEMU_STRTOSZ_DEFSUFFIX_MB 'M'
>  #define QEMU_STRTOSZ_DEFSUFFIX_KB 'K'
>  #define QEMU_STRTOSZ_DEFSUFFIX_B 'B'
> -int64_t qemu_strtosz(const char *nptr, char **end);
>  int64_t qemu_strtosz_suffix(const char *nptr, char **end,
>  const char default_suffix);
> +int64_t qemu_strtosz_mebi(const char *nptr, char **end);
>  int64_t qemu_strtosz_metric(const char *nptr, char **end);
>  
>  #define K_BYTE (1ULL << 10)
> diff --git a/monitor.c b/monitor.c
> index 3cd72a9..1f8c031 100644
> --- a/monitor.c
> +++ b/monitor.c
> @@ -2785,7 +2785,7 @@ static QDict *monitor_parse_arguments(Monitor *mon,
>  break;
>  }
>  }
> -val = qemu_strtosz(p, );
> +val = qemu_strtosz_mebi(p, );
>  if (val < 0) {
>  monitor_printf(mon, "invalid size\n");
>  goto fail;
> diff --git a/tests/test-cutils.c b/tests/test-cutils.c
> index 383f812..86d36b7 100644
> --- a/tests/test-cutils.c
> +++ b/tests/test-cutils.c
> @@ -1376,16 +1376,16 @@ static void test_qemu_strtosz_simple(void)
>  int64_t res;
>  
>  str = "0";
> -res = qemu_strtosz(str, );
> +res = qemu_strtosz_mebi(str, );
>  g_assert_cmpint(res, ==, 0);
>  g_assert(endptr == str + 1);
>  
>  str = "12345M";
> -res = qemu_strtosz(str, );
> +res = qemu_strtosz_mebi(str, );
>  g_assert_cmpint(res, ==, 12345 * M_BYTE);
>  g_assert(endptr == str + 6);
>  
> -res = qemu_strtosz(str, NULL);
> +res = qemu_strtosz_mebi(str, NULL);
>  g_assert_cmpint(res, ==, 12345 * M_BYTE);
>  
>  /* Note: precision is 53 bits since we're parsing with strtod() */
> @@ -1433,35 +1433,35 @@ static void test_qemu_strtosz_units(void)
>  int64_t res;
>  
>  /* default is M */
> -res = qemu_strtosz(none, );
> +res = qemu_strtosz_mebi(none, );
>  g_assert_cmpint(res, ==, M_BYTE);
>  g_assert(endptr == none + 1);
>  
> -res = qemu_strtosz(b, );
> +res = qemu_strtosz_mebi(b, );
>  g_assert_cmpint(res, ==, 1);
>  g_assert(endptr == b + 2);
>  
> -res = qemu_strtosz(k, );
> +res = qemu_strtosz_mebi(k, );
>  g_assert_cmpint(res, ==, K_BYTE);
>  g_assert(endptr == k + 2);
>  
> -res = qemu_strtosz(m, );
> +res = qemu_strtosz_mebi(m, );
>  g_assert_cmpint(res, ==, M_BYTE);
>  g_assert(endptr == m + 2);
>  
> -res = qemu_strtosz(g, );
> +res = qemu_strtosz_mebi(g, );
>  g_assert_cmpint(res, ==, G_BYTE);
>  g_assert(endptr == g + 2);
>  
> -res = qemu_strtosz(t, );
> +res = qemu_strtosz_mebi(t, );
>  g_assert_cmpint(res, ==, T_BYTE);
>  g_assert(endptr == t + 2);
>  
> -res = qemu_strtosz(p, );
> +res = qemu_strtosz_mebi(p, );
>