From: Eric Blake <eblake@redhat.com>
To: John Snow <jsnow@redhat.com>, qemu-block@nongnu.org
Cc: kwolf@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] qemu-img: add check for zero-length job len
Date: Mon, 2 Nov 2015 16:43:33 -0700 [thread overview]
Message-ID: <5637F525.5060109@redhat.com> (raw)
In-Reply-To: <1446506900-27733-1-git-send-email-jsnow@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1667 bytes --]
On 11/02/2015 04:28 PM, John Snow wrote:
> The mirror job doesn't update its total length until
> it has already started running, so we should translate
> a zero-length job-len as meaning 0%.
>
> Otherwise, we may get divide-by-zero faults.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> ---
> qemu-img.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
And indeed, this has tripped up libvirt in the past :)
My only concern is what if you truly have a 0-length job? For example,
when doing two block-stream commands with identical arguments in a row,
the second block-stream has no work to do, but can complete instantly.
Will this result in such a job never reporting 100% complete? If so,
that's bad.
If you can answer my concerns that we don't have a design bug, then the
code changes look correct, and you can add:
Reviewed-by: Eric Blake <eblake@redhat.com>
>
> diff --git a/qemu-img.c b/qemu-img.c
> index 3025776..38b4888 100644
> --- a/qemu-img.c
> +++ b/qemu-img.c
> @@ -656,7 +656,8 @@ static void run_block_job(BlockJob *job, Error **errp)
>
> do {
> aio_poll(aio_context, true);
> - qemu_progress_print((float)job->offset / job->len * 100.f, 0);
> + qemu_progress_print(job->len ?
> + ((float)job->offset / job->len * 100.f) : 0.00, 0);
Also, note that this promotes to double rather than float; maybe you
want to use 0.f instead of 0.00 to keep the ternary as a float? But it
shouldn't make a difference in practice.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2015-11-02 23:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-02 23:28 [Qemu-devel] [PATCH] qemu-img: add check for zero-length job len John Snow
2015-11-02 23:43 ` Eric Blake [this message]
2015-11-02 23:45 ` John Snow
2015-11-04 11:12 ` Kevin Wolf
2015-11-03 0:24 ` Jeff Cody
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=5637F525.5060109@redhat.com \
--to=eblake@redhat.com \
--cc=jcody@redhat.com \
--cc=jsnow@redhat.com \
--cc=kwolf@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.