From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c3s7a-0005Ul-Ki for qemu-devel@nongnu.org; Mon, 07 Nov 2016 17:10:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c3s7Z-0002mC-JP for qemu-devel@nongnu.org; Mon, 07 Nov 2016 17:10:30 -0500 References: <1478551093-32757-1-git-send-email-eblake@redhat.com> From: Eric Blake Message-ID: Date: Mon, 7 Nov 2016 16:10:22 -0600 MIME-Version: 1.0 In-Reply-To: <1478551093-32757-1-git-send-email-eblake@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="om8arcusQWLFfVGUfjJ1D5juRnG0dif7K" Subject: Re: [Qemu-devel] [PATCH for-2.8] nbd: Don't inf-loop on early EOF List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --om8arcusQWLFfVGUfjJ1D5juRnG0dif7K From: Eric Blake To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Message-ID: Subject: Re: [Qemu-devel] [PATCH for-2.8] nbd: Don't inf-loop on early EOF References: <1478551093-32757-1-git-send-email-eblake@redhat.com> In-Reply-To: <1478551093-32757-1-git-send-email-eblake@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable [updating subject line, to make sure this regression is fixed] On 11/07/2016 02:38 PM, Eric Blake wrote: > Commit 7d3123e converted a single read_sync() into a while loop > that assumed that read_sync() would either make progress or give > an error. But when the server hangs up early, the client sees > EOF (a read_sync() of 0) and never makes progress, which in turn > caused qemu-iotest './check -nbd 83' to go into an infinite loop. >=20 > Rework the loop to accomodate reads cut short by EOF. and s/accomodate/accommodate/ if the maintainer would be so nice (not every day I get to correct my own typos) >=20 > Reported-by: Max Reitz > Signed-off-by: Eric Blake > --- > nbd/client.c | 13 +++++++------ > 1 file changed, 7 insertions(+), 6 deletions(-) >=20 > diff --git a/nbd/client.c b/nbd/client.c > index 5d94e34..29b6edf 100644 > --- a/nbd/client.c > +++ b/nbd/client.c > @@ -79,20 +79,21 @@ static QTAILQ_HEAD(, NBDExport) exports =3D QTAILQ_= HEAD_INITIALIZER(exports); > * the amount of bytes consumed. */ > static ssize_t drop_sync(QIOChannel *ioc, size_t size) > { > - ssize_t ret, dropped =3D size; > + ssize_t ret =3D 0; > char small[1024]; > char *buffer; >=20 > buffer =3D sizeof(small) < size ? small : g_malloc(MIN(65536, size= )); > while (size > 0) { > - ret =3D read_sync(ioc, buffer, MIN(65536, size)); > - if (ret < 0) { > + ssize_t count =3D read_sync(ioc, buffer, MIN(65536, size)); > + > + if (count <=3D 0) { > goto cleanup; > } > - assert(ret <=3D size); > - size -=3D ret; > + assert(count <=3D size); > + size -=3D count; > + ret +=3D count; > } > - ret =3D dropped; >=20 > cleanup: > if (buffer !=3D small) { >=20 --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --om8arcusQWLFfVGUfjJ1D5juRnG0dif7K 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/ iQEcBAEBCAAGBQJYIPvOAAoJEKeha0olJ0NqCbUIAKYCFddJGPbwZXSNm5H1iYLP 9i99VxgLUpnkUsj9sQNsMygweUsPgHT1i3salGj2VAG7QaTmQmn0oEaMds9R5RoW 3EtN89kg7bF6yvMsvbPJaPKayFTVVUigUdaPAZ6BZeukoZIS+8V1lM2LpRIHJXOj 0imWoOCQNf2m1OuutBP6bE2L5VHx1u+TScDYZqG/7z4sElu3SzEIDiw4L4Ylttd2 yPPrihPmwFMBqZVCRnfXI/rbgby3BXYI2U/3hYoOePIVZHXGUJn9ryK/bgTchq1w makEEBvhXl7kKpB2ejerHFDHYH7jCTSlEuvyRL/O7oIQUStM5jZRegd3WOc8dt4= =aEEi -----END PGP SIGNATURE----- --om8arcusQWLFfVGUfjJ1D5juRnG0dif7K--