]> Git Repo - qemu.git/commitdiff
nbd: Don't inf-loop on early EOF
authorEric Blake <[email protected]>
Mon, 7 Nov 2016 20:38:13 +0000 (14:38 -0600)
committerPaolo Bonzini <[email protected]>
Thu, 10 Nov 2016 15:01:30 +0000 (16:01 +0100)
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 <[email protected]>
Signed-off-by: Eric Blake <[email protected]>
Message-Id: <1478551093[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
nbd/client.c

index 7db4301d292949e9a2cb215cd43a93377efa52df..ffb0743bcecf8dcb0ff6f97c117fbbe3d0545849 100644 (file)
@@ -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) {
This page took 0.027801 seconds and 4 git commands to generate.