gus: Do not manually free the state, qdev does it for us
[qemu] / aio.c
diff --git a/aio.c b/aio.c
index 70d3cdc..efc63fd 100644 (file)
--- a/aio.c
+++ b/aio.c
@@ -44,7 +44,8 @@ static AioHandler *find_aio_handler(int fd)
 
     LIST_FOREACH(node, &aio_handlers, node) {
         if (node->fd == fd)
-            return node;
+            if (!node->deleted)
+                return node;
     }
 
     return NULL;
@@ -79,8 +80,6 @@ int qemu_aio_set_fd_handler(int fd,
         if (node == NULL) {
             /* Alloc and insert if it's not already there */
             node = qemu_mallocz(sizeof(AioHandler));
-            if (node == NULL)
-                return -ENOMEM;
             node->fd = fd;
             LIST_INSERT_HEAD(&aio_handlers, node, node);
         }
@@ -104,12 +103,16 @@ void qemu_aio_flush(void)
     do {
         ret = 0;
 
+       /*
+        * If there are pending emulated aio start them now so flush
+        * will be able to return 1.
+        */
+        qemu_aio_wait();
+
         LIST_FOREACH(node, &aio_handlers, node) {
             ret |= node->io_flush(node->opaque);
         }
-
-        qemu_aio_wait();
-    } while (ret > 0);
+    } while (qemu_bh_poll() || ret > 0);
 }
 
 void qemu_aio_wait(void)