From: Eric Blake <eblake@redhat.com>
To: Eyal Moscovici <eyal.moscovici@oracle.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 v3 1/1] qemu_img: add cvtnum_full to print error reports
Date: Wed, 13 May 2020 10:57:46 -0500 [thread overview]
Message-ID: <3360d9b8-89cf-04be-3da3-3463d99e4808@redhat.com> (raw)
In-Reply-To: <20200513133629.18508-2-eyal.moscovici@oracle.com>
On 5/13/20 8:36 AM, 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_full to reduce code
> duplication and provide a single error message. Additionally, cvtnum now wraps
> cvtnum_full with the existing default range of 0 to MAX_INT64.
>
> Acked-by: Mark Kanda <mark.kanda@oracle.com>
> Signed-off-by: Eyal Moscovici <eyal.moscovici@oracle.com>
> ---
> -static int64_t cvtnum(const char *s)
> +static int64_t cvtnum_full(const char *name, const char *value, int64_t min,
> + int64_t max)
> {
> int err;
> - uint64_t value;
> -
> - err = qemu_strtosz(s, NULL, &value);
> - if (err < 0) {
> + uint64_t res;
> +
> + err = qemu_strtosz(value, NULL, &res);
> + if (err < 0 && err != -ERANGE) {
> + error_report("Invalid %s specified. You may use "
> + "k, M, G, T, P or E suffixes for ", name);
> + error_report("kilobytes, megabytes, gigabytes, terabytes, "
> + "petabytes and exabytes.");
The new common message is in terms of bytes, even though not all callers
are specifically related to bytes. I don't think it's a show-stopper,
though, merely a quality of error message, and I don't have any ideas
for how to improve it.
> @@ -4506,10 +4508,9 @@ static int img_dd_count(const char *arg,
> struct DdIo *in, struct DdIo *out,
> struct DdInfo *dd)
> {
> - dd->count = cvtnum(arg);
> + dd->count = cvtnum("count", arg);
>
> if (dd->count < 0) {
> - error_report("invalid number: '%s'", arg);
For example, the count argument to dd is not really about bytes, but
repetitions. So the error message is now more informative (what
suffixes you can use) but also less accurate ("invalid number" was vague
but at least correct).
I think the common code is worth the corner case regressions, so:
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
next prev parent reply other threads:[~2020-05-13 15:58 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-13 13:36 [PATCH v3 0/4] Additional parameters for qemu_img map Eyal Moscovici
2020-05-13 13:36 ` [PATCH v3 1/1] qemu_img: add cvtnum_full to print error reports Eyal Moscovici
2020-05-13 15:57 ` Eric Blake [this message]
2020-05-14 21:19 ` Eric Blake
2020-05-13 13:36 ` [PATCH v3 2/4] qemu-img: validate image length in img_map Eyal Moscovici
2020-05-13 17:38 ` Eric Blake
2020-05-13 13:36 ` [PATCH v3 3/4] qemu-img: refactor dump_map_entry JSON format output Eyal Moscovici
2020-05-13 13:36 ` [PATCH v3 4/4] qemu-img: Add --start-offset and --max-length to map Eyal Moscovici
2020-05-13 17:49 ` [PATCH v3 0/4] Additional parameters for qemu_img map Eric Blake
2020-05-13 18:46 ` Eyal Moscovici
2020-05-13 18:14 ` [PATCH v3 5/4] iotests: Enhance 223 to cover qemu-img map improvements Eric Blake
2020-05-13 22:13 ` [PATCH v3 0/4] Additional parameters for qemu_img map no-reply
2020-05-14 13:44 ` 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=3360d9b8-89cf-04be-3da3-3463d99e4808@redhat.com \
--to=eblake@redhat.com \
--cc=eyal.moscovici@oracle.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).