qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH v3] qemu-img: correct size parsers and help mess


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH v3] qemu-img: correct size parsers and help message
Date: Wed, 18 Jul 2012 07:34:37 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

On 07/18/2012 07:23 AM, Dong Xu Wang wrote:
> qemu-img not only suports k/K/M/G/T/b, but also supports m/g/t/B. So correct
> it in help message.
> 

> +++ b/qemu-img.c
> @@ -69,8 +69,9 @@ static void help(void)
>             "    options are: 'none', 'writeback' (default, except for 
> convert), 'writethrough',\n"
>             "    'directsync' and 'unsafe' (default for convert)\n"
>             "  'size' is the disk image size in bytes. Optional suffixes\n"
> -           "    'k' or 'K' (kilobyte, 1024), 'M' (megabyte, 1024k), 'G' 
> (gigabyte, 1024M)\n"
> -           "    and T (terabyte, 1024G) are supported. 'b' is ignored.\n"
> +           "    'k' or 'K' (kilobyte, 1024), 'm' or 'M' (megabyte, 1024k),\n"
> +           "    'g' or 'G' (gigabyte, 1024M) and 't' or 'T' (terabyte, 
> 1024G) are supported.\n"
> +           "    'b' or 'B' is ignored.\n"

Technically, 'kilobyte' is only 1000 bytes; the correct term for 1024
bytes is 'kibibyte'.  Likewise for 'megabyte' (1000000) vs. 'mebibyte'
(1024k, or 1,048,576 bytes); and so on for gibibytes and tebibytes.
Since disk manufacturers have already forced the rest of the world to
ask whether the number of bytes they are looking at is a power of 10 or
a power of 2 suffix, we might as well be precise in our naming to
document that we really are using powers of 2.

Furthermore, I think you can compress this by mentioning that the parse
is case-insensitive, instead of spelling out all the options:

'size' is the disk image size in bytes, scaled by an optional
case-insensitive suffix: 'k' (kibibyte, 1024), 'M' (mebibyte, 1024k),
'G' (gibibyte, 1024M), 'T' (tebibyte, 1024G), or 'b' (no scaling).

> @@ -341,8 +342,8 @@ static int img_create(int argc, char **argv)
>          char *end;
>          sval = strtosz_suffix(argv[optind++], &end, STRTOSZ_DEFSUFFIX_B);
>          if (sval < 0 || *end) {
> -            error_report("Invalid image size specified! You may use k, M, G 
> or "
> -                  "T suffixes for ");
> +            error_report("Invalid image size specified! You may use k/K, 
> m/M, "
> +                  "g/G or t/T suffixes for ");

I personally dislike this change.  Just because we're lenient in what we
accept does not mean we have to document all of the possibilities that
we parse when correcting a user error; rather, we need only document the
preferred possibilities.

>          default:
>              error_set(errp, QERR_INVALID_PARAMETER_VALUE, name, "a size");
> -            error_printf_unless_qmp("You may use k, M, G or T suffixes for "
> +            error_printf_unless_qmp("You may use K/k, M/m, G/g or T/t 
> suffixes for "

Again, in an error message, I'd only document the preferred capitalization.

-- 
Eric Blake   address@hidden    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]