From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53027) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xovkz-0006Pp-KN for qemu-devel@nongnu.org; Thu, 13 Nov 2014 09:52:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xovkt-00084i-Pq for qemu-devel@nongnu.org; Thu, 13 Nov 2014 09:52:21 -0500 Received: from mx1.redhat.com ([209.132.183.28]:48696) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xovkt-00084Z-Gf for qemu-devel@nongnu.org; Thu, 13 Nov 2014 09:52:15 -0500 Message-ID: <5464C59A.4000602@redhat.com> Date: Thu, 13 Nov 2014 07:52:10 -0700 From: Eric Blake MIME-Version: 1.0 References: <1415873823-13844-1-git-send-email-armbru@redhat.com> <1415873823-13844-4-git-send-email-armbru@redhat.com> <20141113130327.GD3933@noname.redhat.com> In-Reply-To: <20141113130327.GD3933@noname.redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="JBl6dGw7hmHqFr7wpeexwEj12TBdAjC0V" Subject: Re: [Qemu-devel] [PATCH v2 3/4] raw-posix: Fix try_seek_hole()'s handling of SEEK_DATA failure List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf , Markus Armbruster Cc: famz@redhat.com, tony@bakeyournoodle.com, qemu-devel@nongnu.org, stefanha@redhat.com, pbonzini@redhat.com, mreitz@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --JBl6dGw7hmHqFr7wpeexwEj12TBdAjC0V Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 11/13/2014 06:03 AM, Kevin Wolf wrote: > Am 13.11.2014 um 11:17 hat Markus Armbruster geschrieben: >> When SEEK_HOLE tells us we're in a hole, we try SEEK_DATA to find its >> end. When that fails, we pretend the hole extends to the end of file.= >> Wrong. >=20 > Wrong only in some cases, see below. >=20 >> Except when SEEK_END fails, we screw up and claim it extends >> to offset -1. More wrong. >> +++ b/block/raw-posix.c >> @@ -1494,8 +1494,9 @@ static int try_seek_hole(BlockDriverState *bs, o= ff_t start, off_t *data, >> } else { >> /* On a hole. We need another syscall to find its end. */ >> *data =3D lseek(s->fd, start, SEEK_DATA); >> - if (*data =3D=3D -1) { >> - *data =3D lseek(s->fd, 0, SEEK_END); >> + if (*data < 0) { >> + /* no idea where the hole ends, give up (unlikely to happ= en) */ >=20 > Not quite unlikely. If the file ends with a sparse area, we'll get > -1/ENXIO here. >=20 > lseek() with SEEK_DATA starting in a hole when there is no data until > EOF is actually the part that isn't documented in the man page, but > ENXIO is what I'm seeing here on RHEL 7. Here's the (proposed) POSIX wording: http://austingroupbugs.net/view.php?id=3D415 And ENXIO is indeed the expected error for SEEK_DATA on a trailing hole, so maybe we should special case it. --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --JBl6dGw7hmHqFr7wpeexwEj12TBdAjC0V 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 iQEcBAEBCAAGBQJUZMWaAAoJEKeha0olJ0NqzxoIAIAy2Jr/8UF6iBvOKEx6njuD l9ZhIpGTLLhVhEeuBxM7p6gC7IVO/E28KhsjsMwwRbU9W+0AiVOaMjclxH98QbYf LwQKiN8tc9Zi9gg89X9d5tAJaeGGyix90MKi7ArqK76kLbRjeyezaY3v1DnFfv6R hfVFTe4XAXj6+0BLBDX7wpVIc2s965xxGPJbJUGvvzpqAoNWNMdar0ua0+HIvelX H60gV+/wxBMXvR9ZtfYS1eRKToH29Eb7XcCea62wBhYJ4voxLj6I2veFwAfvHxP9 y9yE2S8RAs4b6dEx99p2Ze3J5Sb+gew0pXD7vD3BCs/5Btq3sLhJuclC1qgXcBI= =2MJr -----END PGP SIGNATURE----- --JBl6dGw7hmHqFr7wpeexwEj12TBdAjC0V--