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: Thu, 14 May 2020 16:19:20 -0500 [thread overview]
Message-ID: <facc883f-08b7-1b7e-bf9b-0b582b734eaf@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.");
Consecutive error_report() calls each output a newline, which means your
new output includes a trailing space.
> @@ -572,16 +584,8 @@ static int img_create(int argc, char **argv)
> if (optind < argc) {
> int64_t sval;
>
> - sval = cvtnum(argv[optind++]);
> + sval = cvtnum("image size", argv[optind++]);
> if (sval < 0) {
> - if (sval == -ERANGE) {
> - error_report("Image size must be less than 8 EiB!");
> - } else {
> - error_report("Invalid image size specified! You may use k, M, "
> - "G, T, P or E suffixes for ");
> - error_report("kilobytes, megabytes, gigabytes, terabytes, "
> - "petabytes and exabytes.");
> - }
True, that's what some of the old code was doing, but...
> +++ b/tests/qemu-iotests/049.out
>
> qemu-img create -f qcow2 TEST_DIR/t.qcow2 -- 1kilobyte
> -qemu-img: Invalid image size specified! You may use k, M, G, T, P or E suffixes for
> +qemu-img: Invalid image size specified. You may use k, M, G, T, P or E suffixes for
where it gets hairy is that our iotests _intentionally_ strip trailing
space before comparing to expected output, because it is such a pain to
commit files with trailing spaces into the repository. We're better off
making the expected output precisely match what qemu-img actually
outputs, which means using this as an opportunity to fix qemu-img to not
output trailing space in the first place.
--
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-14 21:20 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
2020-05-14 21:19 ` Eric Blake [this message]
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=facc883f-08b7-1b7e-bf9b-0b582b734eaf@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).