From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33888) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgzE7-0007wD-HY for qemu-devel@nongnu.org; Wed, 22 Oct 2014 12:57:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XgzE2-0000RI-G3 for qemu-devel@nongnu.org; Wed, 22 Oct 2014 12:57:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11785) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XgzE2-0000R5-8o for qemu-devel@nongnu.org; Wed, 22 Oct 2014 12:57:30 -0400 Message-ID: <5447E1F6.4040302@redhat.com> Date: Wed, 22 Oct 2014 10:57:26 -0600 From: Eric Blake MIME-Version: 1.0 References: <1413993434-11816-1-git-send-email-mreitz@redhat.com> <1413993434-11816-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1413993434-11816-2-git-send-email-mreitz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="1WbC27bpjLoHudEhTUwqwlwT8EISfMe9J" Subject: Re: [Qemu-devel] [PATCH v3 1/3] raw-posix: Fix raw_co_get_block_status() after EOF List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz , qemu-devel@nongnu.org Cc: Kevin Wolf , =?UTF-8?B?QmVub8OudCBDYW5ldA==?= , Stefan Hajnoczi This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --1WbC27bpjLoHudEhTUwqwlwT8EISfMe9J Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 10/22/2014 09:57 AM, Max Reitz wrote: > As its comment states, raw_co_get_block_status() should unconditionally= > return 0 and set *pnum to 0 for after EOF. >=20 > An assertion after lseek(..., SEEK_HOLE) tried to catch this case by > asserting that errno !=3D -ENXIO (which would indicate a position after= > the EOF); but it should be errno !=3D ENXIO instead. Regardless of that= , > there should be no such assertion at all. If bdrv_getlength() returned > an outdated value and the image has been resized outside of qemu, > lseek() will return with errno =3D=3D ENXIO. Just return that value as = an > error then. >=20 > Setting *pnum to 0 and returning 0 should not be done here, as in that > case we should update the device length as well. So, from qemu's > perspective, the file has not been resized; it's just that there was an= > error querying sectors beyond a certain point (the actual file size). >=20 > Additionally, nb_sectors should be clamped against the image end. This > was probably not an issue if FIEMAP or SEEK_HOLE/SEEK_DATA worked, but > the fallback did not take this case into account. >=20 > Reported-by: Kevin Wolf > Signed-off-by: Max Reitz > --- > block/raw-posix.c | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) Reviewed-by: Eric Blake > + if (total_size < 0) { > + return total_size; > + } else if (start >=3D total_size) { > + *pnum =3D 0; > + return 0; > + } else if (start + nb_sectors * BDRV_SECTOR_SIZE > total_size) { > + nb_sectors =3D (total_size - start) / BDRV_SECTOR_SIZE; Should this round up instead of truncate? But it would only matter for a file size that is not a multiple of sectors, where we probably have other issues, and where reporting just the full sectors also seems reasonable. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --1WbC27bpjLoHudEhTUwqwlwT8EISfMe9J Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg iQEcBAEBCAAGBQJUR+H2AAoJEKeha0olJ0NqKYEH/0lSdP4rJZBl8z/I6GdZy7j9 kVhzMUKNLsr4b/7CD8KBZRlsvay+zkOdFvj9pgvIvU65qox9/iQ2EjThjPbTSIgY JsUha6/PgpJzglXR+SLBFSfK0h5CptwsYbohY5QK3pmVAzQz1WVomjJxpJTF/r/H xDhr/RyHmV6r7XU+IQrdBZPKwRFbX2qT9RACVSuQJMUoUTGZJR/eOHz/kA5bGUCL VxozDqk3rA6+Ufz6xmROv4yQ2jUxVB30Ugrt6MGWwdOC7jjIumABSmcJBGjG0anV 9zmFgBljcasQyE6QaCndhhKAnYBeIngaVJyt76rlJEwvzCB+NuA65167bLhbIJI= =vSP1 -----END PGP SIGNATURE----- --1WbC27bpjLoHudEhTUwqwlwT8EISfMe9J--