]> xenbits.xensource.com Git - qemu-xen-4.4-testing.git/commitdiff
block: make raw aio signaling non-blocking (Gerd Hoffman)
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>
Thu, 13 Nov 2008 19:23:17 +0000 (19:23 +0000)
committerIan Jackson <Ian.Jackson@eu.citrix.com>
Tue, 9 Dec 2008 16:30:29 +0000 (16:30 +0000)
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.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5716 c046a42c-6fe2-441c-8c8c-71466251a162
(cherry picked from commit e20e830bbdc502986d6fd30c26b06c37a5ee0611)

block-raw-posix.c

index 33258c9fbfcdbe8b11ba2b4b3ff4553375621f3f..0a0a7e993e33af8c6fda309045951c1308884fc5 100644 (file)
@@ -498,15 +498,17 @@ static void posix_aio_read(void *opaque)
     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;
@@ -592,6 +594,7 @@ static int posix_aio_init(void)
     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);