From: John Snow <jsnow@redhat.com>
To: Eric Blake <eblake@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 18:45:50 -0500 [thread overview]
Message-ID: <5637F5AE.5020006@redhat.com> (raw)
In-Reply-To: <5637F525.5060109@redhat.com>
On 11/02/2015 06:43 PM, Eric Blake wrote:
> 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.
>
A few lines below the context:
/* A block job may finish instantaneously without publishing any
progress,
* so just signal completion here */
qemu_progress_print(100.f, 0);
> 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.
>
Yes, oops -- but harmless.
next prev parent reply other threads:[~2015-11-02 23:46 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
2015-11-02 23:45 ` John Snow [this message]
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=5637F5AE.5020006@redhat.com \
--to=jsnow@redhat.com \
--cc=eblake@redhat.com \
--cc=jcody@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 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).