[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-block] [Qemu-devel] [PATCH for-2.8] nbd: Don't inf-loop on ear
From: |
Eric Blake |
Subject: |
Re: [Qemu-block] [Qemu-devel] [PATCH for-2.8] nbd: Don't inf-loop on early EOF |
Date: |
Mon, 7 Nov 2016 16:10:22 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 |
[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.
>
> 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)
>
> Reported-by: Max Reitz <address@hidden>
> Signed-off-by: Eric Blake <address@hidden>
> ---
> nbd/client.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> 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 =
> QTAILQ_HEAD_INITIALIZER(exports);
> * the amount of bytes consumed. */
> static ssize_t drop_sync(QIOChannel *ioc, size_t size)
> {
> - ssize_t ret, dropped = size;
> + ssize_t ret = 0;
> char small[1024];
> char *buffer;
>
> buffer = sizeof(small) < size ? small : g_malloc(MIN(65536, size));
> while (size > 0) {
> - ret = read_sync(ioc, buffer, MIN(65536, size));
> - if (ret < 0) {
> + ssize_t count = read_sync(ioc, buffer, MIN(65536, size));
> +
> + if (count <= 0) {
> goto cleanup;
> }
> - assert(ret <= size);
> - size -= ret;
> + assert(count <= size);
> + size -= count;
> + ret += count;
> }
> - ret = dropped;
>
> cleanup:
> if (buffer != small) {
>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature