From: Eyal Moscovici <eyal.moscovici@oracle.com>
To: Eric Blake <eblake@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
liran.alon@oracle.com, qemu-devel@nongnu.org,
qemu-block@nongnu.org, Max Reitz <mreitz@redhat.com>
Subject: Re: [PATCH v2 2/5] qemu_img: add error report to cvtnum
Date: Tue, 12 May 2020 12:44:18 +0300 [thread overview]
Message-ID: <a8ce4904-3c57-e5b0-25a6-857ac8753bed@oracle.com> (raw)
In-Reply-To: <b9274eb3-1e89-e9f7-d9fd-2f1c8b2e3387@redhat.com>
On 07/05/2020 0:59, Eric Blake wrote:
> On 5/6/20 4:34 PM, Eyal Moscovici wrote:
>> All calls to cvtnum check the return value and print the same error
>> message more
>> or less. And so error reporting moved to cvtnum to reduce duplicate
>> code and
>> provide a single error message.
>>
>> Acked-by: Mark Kanda <mark.kanda@oracle.com>
>> Signed-off-by: Eyal Moscovici <eyal.moscovici@oracle.com>
>> ---
>> qemu-img.c | 63 ++++++++++++++++----------------------
>> tests/qemu-iotests/049.out | 4 +--
>> 2 files changed, 28 insertions(+), 39 deletions(-)
>>
>
>>
>> - err = qemu_strtosz(s, NULL, &value);
>> - if (err < 0) {
>> + err = qemu_strtosz(arg_value, NULL, &value);
>> + if (err < 0 && err != -ERANGE) {
>> + error_report("Invalid %s specified! You may use "
>> + "k, M, G, T, P or E suffixes for ", arg_name);
>> + error_report("kilobytes, megabytes, gigabytes, terabytes, "
>> + "petabytes and exabytes.");
>> return err;
>> }
>> - if (value > INT64_MAX) {
>> + if (err == -ERANGE || value > INT64_MAX) {
>> + error_report("Invalid %s specified! Must be less than 8 EiB!",
>
> Copied from our pre-existing errors, but why are we shouting at our
> user? This would be a good time to s/!/./ to tone it down a bit.
Sure, will fix.
>
>> @@ -4491,10 +4488,12 @@ static int img_dd_bs(const char *arg,
>> {
>> int64_t res;
>> - res = cvtnum(arg);
>> + res = cvtnum("bs", arg);
>> - if (res <= 0) {
>> - error_report("invalid number: '%s'", arg);
>> + if (res < 0) {
>> + return 1;
>> + } else if (res == 0) {
>> + error_report("Invalid bs specified! It cannot be 0.");
>
> Maybe it's worth two functions:
>
> int64_t cvtnum_full(const char *name, const char *value, int64_t min,
> int64_t max)
>
> and then a common helper:
>
> int64_t cvtnum(const char *name, const char *value) {
> return cvtnum_full(name, value, 0, INT64_MAX);
> }
>
> many existing callers remain with cvtnum(), but callers like this
> could be cvtnum("bs", arg, 1, INT64_MAX). You'd still have to
> special-case other restrictions, such as whether a number must a
> power-of-2, but that's fewer places.
>
Great idea, I will create two functions.
>> +++ b/tests/qemu-iotests/049.out
>> @@ -92,13 +92,13 @@ Formatting 'TEST_DIR/t.qcow2', fmt=qcow2
>> size=1649267441664 cluster_size=65536 l
>> == 3. Invalid sizes ==
>> qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- -1024
>> -qemu-img: Image size must be less than 8 EiB!
>> +qemu-img: Invalid image size specified! Must be less than 8 EiB!
>
> Nice that you checked for iotest fallout. Is this really the only
> impacted test?
>
Thanks, yes.
next prev parent reply other threads:[~2020-05-12 9:45 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-22 9:11 [PATCH 0/2] Additional parameters for qemu_img map Eyal Moscovici
2020-03-22 9:11 ` [PATCH 1/2] qemu-img: refactor dump_map_entry JSON format output Eyal Moscovici
2020-04-29 14:58 ` Eric Blake
2020-05-06 9:55 ` Eyal Moscovici
2020-03-22 9:11 ` [PATCH 2/2] qemu-img: Add --start-offset and --max-length to map Eyal Moscovici
2020-04-29 15:04 ` Eric Blake
2020-05-06 9:52 ` Eyal Moscovici
2020-04-29 13:39 ` [PATCH 0/2] Additional parameters for qemu_img map John Snow
2020-05-06 21:34 ` [PATCH v2 0/5] " Eyal Moscovici
2020-05-06 21:34 ` [PATCH v2 1/5] qemu-img: remove check that cvtnum value > MAX_INT Eyal Moscovici
2020-05-06 21:49 ` Eric Blake
2020-05-12 9:39 ` Eyal Moscovici
2020-05-12 14:14 ` Eric Blake
2020-05-06 21:34 ` [PATCH v2 2/5] qemu_img: add error report to cvtnum Eyal Moscovici
2020-05-06 21:59 ` Eric Blake
2020-05-12 9:44 ` Eyal Moscovici [this message]
2020-05-06 21:34 ` [PATCH v2 3/5] qemu-img: validate image length in img_map Eyal Moscovici
2020-05-06 22:01 ` Eric Blake
2020-05-06 21:34 ` [PATCH v2 4/5] qemu-img: refactor dump_map_entry JSON format output Eyal Moscovici
2020-05-06 21:34 ` [PATCH v2 5/5] qemu-img: Add --start-offset and --max-length to map Eyal Moscovici
2020-05-06 22:04 ` Eric Blake
2020-05-12 9:48 ` Eyal Moscovici
2020-05-06 21:45 ` [PATCH v2 0/5] Additional parameters for qemu_img map Eric Blake
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=a8ce4904-3c57-e5b0-25a6-857ac8753bed@oracle.com \
--to=eyal.moscovici@oracle.com \
--cc=eblake@redhat.com \
--cc=kwolf@redhat.com \
--cc=liran.alon@oracle.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/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).