Skip to contentSkip to conversation

[5716] block: make raw aio signaling non-blocking (Gerd Hoffman)

Qemu-devel Anthony Liguori 1 participant 1 message Nov 13, 2008

lore
Share & tools
lore
#0 lore raw

Revision: 5716

          http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=5716
Author:   aliguori
Date:     2008-11-13 19:23:17 +0000 (Thu, 13 Nov 2008)

Log Message:
-----------
block: make raw aio signaling non-blocking (Gerd Hoffman)

This patch switches the read handle of the signaling pipe into non-blocking mode. This avoids unwanted blocking reads and also allows to read all bytes out of the signaling pipe in case we got signaled more that once before the handler ran.

Modified Paths:
--------------
trunk/block-raw-posix.c

Modified: trunk/block-raw-posix.c
===================================================================

block-raw-posix.c +10 -7
@@ -497,15 +497,17 @@
     int ret;
     ssize_t len;
 
-    do {
-        char byte;
+    /* read all bytes from signal pipe */
+    for (;;) {
+        char bytes[16];
 
-        len = read(s->rfd, &byte, 1);
+        len = read(s->rfd, bytes, sizeof(bytes));
         if (len == -1 && errno == EINTR)
-            continue;
-        if (len == -1 && errno == EAGAIN)
-            break;
-    } while (len == -1);
+            continue; /* try again */
+        if (len == sizeof(bytes))
+            continue; /* more to read */
+        break;
+    }
 
     for(;;) {
         pacb = &s->first_aio;
@@ -591,6 +593,7 @@
     s->rfd = fds[0];
     s->wfd = fds[1];
 
+    fcntl(s->rfd, F_SETFL, O_NONBLOCK);
     fcntl(s->wfd, F_SETFL, O_NONBLOCK);
 
     qemu_aio_set_fd_handler(s->rfd, posix_aio_read, NULL, posix_aio_flush, s);