All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] qemu-img: add check for zero-length job len
@ 2015-11-02 23:28 John Snow
  2015-11-02 23:43 ` Eric Blake
  2015-11-03  0:24 ` Jeff Cody
  0 siblings, 2 replies; 5+ messages in thread
From: John Snow @ 2015-11-02 23:28 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, jcody, John Snow, qemu-devel

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(-)

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);
     } while (!job->ready);
 
     block_job_complete_sync(job, errp);
-- 
2.4.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] qemu-img: add check for zero-length job len
  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
  2015-11-03  0:24 ` Jeff Cody
  1 sibling, 1 reply; 5+ messages in thread
From: Eric Blake @ 2015-11-02 23:43 UTC (permalink / raw)
  To: John Snow, qemu-block; +Cc: kwolf, jcody, qemu-devel

[-- 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 --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] qemu-img: add check for zero-length job len
  2015-11-02 23:43 ` Eric Blake
@ 2015-11-02 23:45   ` John Snow
  2015-11-04 11:12     ` Kevin Wolf
  0 siblings, 1 reply; 5+ messages in thread
From: John Snow @ 2015-11-02 23:45 UTC (permalink / raw)
  To: Eric Blake, qemu-block; +Cc: kwolf, jcody, qemu-devel



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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] qemu-img: add check for zero-length job len
  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-03  0:24 ` Jeff Cody
  1 sibling, 0 replies; 5+ messages in thread
From: Jeff Cody @ 2015-11-03  0:24 UTC (permalink / raw)
  To: John Snow; +Cc: kwolf, qemu-devel, qemu-block

On Mon, Nov 02, 2015 at 06:28:20PM -0500, 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(-)
> 
> 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);
>      } while (!job->ready);
>  
>      block_job_complete_sync(job, errp);
> -- 
> 2.4.3
>

Reviewed-by: Jeff Cody <jcody@redhat.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] qemu-img: add check for zero-length job len
  2015-11-02 23:45   ` John Snow
@ 2015-11-04 11:12     ` Kevin Wolf
  0 siblings, 0 replies; 5+ messages in thread
From: Kevin Wolf @ 2015-11-04 11:12 UTC (permalink / raw)
  To: John Snow; +Cc: jcody, qemu-devel, qemu-block

Am 03.11.2015 um 00:45 hat John Snow geschrieben:
> >> 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.

Thanks, fixed that up and applied to the block branch.

Kevin

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-11-04 11:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2015-11-04 11:12     ` Kevin Wolf
2015-11-03  0:24 ` Jeff Cody

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.