From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZtOlN-0001Pk-Ae for qemu-devel@nongnu.org; Mon, 02 Nov 2015 18:43:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZtOlM-0000Pd-4M for qemu-devel@nongnu.org; Mon, 02 Nov 2015 18:43:45 -0500 References: <1446506900-27733-1-git-send-email-jsnow@redhat.com> From: Eric Blake Message-ID: <5637F525.5060109@redhat.com> Date: Mon, 2 Nov 2015 16:43:33 -0700 MIME-Version: 1.0 In-Reply-To: <1446506900-27733-1-git-send-email-jsnow@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="0JOPd00brfgQSBTXsltuMV4EJgoUW6kH5" Subject: Re: [Qemu-devel] [PATCH] qemu-img: add check for zero-length job len List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: John Snow , qemu-block@nongnu.org Cc: kwolf@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --0JOPd00brfgQSBTXsltuMV4EJgoUW6kH5 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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%. >=20 > Otherwise, we may get divide-by-zero faults. >=20 > Signed-off-by: John Snow > --- > 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 >=20 > 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 **er= rp) > =20 > 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. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --0JOPd00brfgQSBTXsltuMV4EJgoUW6kH5 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJWN/UlAAoJEKeha0olJ0NqO7EH/1kXYfb/yduLoyoMLLeG8Xnp mgKXgh6JaN01dU4tGM9XnYwHJrzsbnBMmWwI3/9FMYNskTzIySO4CsZSk/ItuITU 8KB9eqicKib3lETVae0DkmXNC9JLXt9Mi5AryGyXB2xLOfJwq+ev6hnTaNqokCY6 v57UxrARn6yT7Painjv5np/NodvGil7YUMKZqLKkhr5yzA1m0p5nXk0hJONOe9pm i+VSZIcXGEDKBnjBcaQF6aimCQfHIVhoGfsnX1BVxnEMWYRcYK6J4cj9d7SywA0Q rxGvXzdT53wgw5drhZTXMTU0bcfjqAx3+TqymheLzv+tryB3Whj1VymsgrTOSCc= =yuSB -----END PGP SIGNATURE----- --0JOPd00brfgQSBTXsltuMV4EJgoUW6kH5--