[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 6/6] nbd: Don't inf-loop on early EOF
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 6/6] nbd: Don't inf-loop on early EOF |
Date: |
Thu, 10 Nov 2016 18:52:42 +0100 |
From: Eric Blake <address@hidden>
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.
Reported-by: Max Reitz <address@hidden>
Signed-off-by: Eric Blake <address@hidden>
Message-Id: <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
nbd/client.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/nbd/client.c b/nbd/client.c
index 7db4301..ffb0743 100644
--- a/nbd/client.c
+++ b/nbd/client.c
@@ -90,20 +90,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) {
--
1.8.3.1
- [Qemu-devel] [PULL 0/6] QEMU patches for 2.8.0-rc0, Paolo Bonzini, 2016/11/10
- [Qemu-devel] [PULL 2/6] vl.c: move pidfile creation up the line, Paolo Bonzini, 2016/11/10
- [Qemu-devel] [PULL 3/6] target-i386/machine: fix migrate faile because of Hyper-V HV_X64_MSR_VP_RUNTIME, Paolo Bonzini, 2016/11/10
- [Qemu-devel] [PULL 1/6] target-i386: fix typo, Paolo Bonzini, 2016/11/10
- [Qemu-devel] [PULL 4/6] qdev: fix use-after-free regression from becdfa00cfa, Paolo Bonzini, 2016/11/10
- [Qemu-devel] [PULL 6/6] nbd: Don't inf-loop on early EOF,
Paolo Bonzini <=
- [Qemu-devel] [PULL 5/6] target-i386: document how x86 gdb_num_core_regs is computed., Paolo Bonzini, 2016/11/10
- Re: [Qemu-devel] [PULL 0/6] QEMU patches for 2.8.0-rc0, Stefan Hajnoczi, 2016/11/11