qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [patch] block: make raw aio signaling non-blocking.


From: Gerd Hoffmann
Subject: [Qemu-devel] [patch] block: make raw aio signaling non-blocking.
Date: Thu, 13 Nov 2008 17:18:34 +0100
User-agent: Thunderbird 2.0.0.16 (X11/20080723)

  Hi,

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.

cheers,
  Gerd

>From 2b75aad0848fb231a0b942bd768f1e84462d1525 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <address@hidden>
Date: Thu, 13 Nov 2008 14:21:19 +0100
Subject: [PATCH] block: make raw aio signaling non-blocking.

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 <address@hidden>
---
 block-raw-posix.c |   17 ++++++++++-------
 1 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/block-raw-posix.c b/block-raw-posix.c
index c06e38d..0a06a12 100644
--- a/block-raw-posix.c
+++ b/block-raw-posix.c
@@ -497,15 +497,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;
@@ -591,6 +593,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);
-- 
1.5.6.5


reply via email to

[Prev in Thread] Current Thread [Next in Thread]