cd9d16
From 84be2986f687b998f583b27d8b3e068e87032418 Mon Sep 17 00:00:00 2001
cd9d16
From: Nick Thomas <nick@bytemark.co.uk>
cd9d16
Date: Wed, 21 Sep 2011 11:55:49 +0100
cd9d16
Subject: [PATCH] block/curl: Implement a flush function on the fd handlers
cd9d16
MIME-Version: 1.0
cd9d16
Content-Type: text/plain; charset=UTF-8
cd9d16
Content-Transfer-Encoding: 8bit
cd9d16
cd9d16
Signed-off-by: Nick Thomas <nick@bytemark.co.uk>
cd9d16
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
cd9d16
(cherry picked from commit c84dcdc1d6583ebe5841907c99d95deb8c40a6e0)
cd9d16
cd9d16
Signed-off-by: Bruce Rogers <brogers@suse.com>
cd9d16
Signed-off-by: Andreas Färber <afaerber@suse.de>
cd9d16
---
cd9d16
 block/curl.c | 26 ++++++++++++++++++++++----
cd9d16
 1 file changed, 22 insertions(+), 4 deletions(-)
cd9d16
cd9d16
diff --git a/block/curl.c b/block/curl.c
cd9d16
index 407f095..6cf6a70 100644
cd9d16
--- a/block/curl.c
cd9d16
+++ b/block/curl.c
cd9d16
@@ -76,6 +76,7 @@ typedef struct BDRVCURLState {
cd9d16
 
cd9d16
 static void curl_clean_state(CURLState *s);
cd9d16
 static void curl_multi_do(void *arg);
cd9d16
+static int curl_aio_flush(void *opaque);
cd9d16
 
cd9d16
 static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action,
cd9d16
                         void *s, void *sp)
cd9d16
@@ -83,14 +84,16 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action,
cd9d16
     DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, fd);
cd9d16
     switch (action) {
cd9d16
         case CURL_POLL_IN:
cd9d16
-            qemu_aio_set_fd_handler(fd, curl_multi_do, NULL, NULL, NULL, s);
cd9d16
+            qemu_aio_set_fd_handler(fd, curl_multi_do, NULL, curl_aio_flush,
cd9d16
+                                    NULL, s);
cd9d16
             break;
cd9d16
         case CURL_POLL_OUT:
cd9d16
-            qemu_aio_set_fd_handler(fd, NULL, curl_multi_do, NULL, NULL, s);
cd9d16
+            qemu_aio_set_fd_handler(fd, NULL, curl_multi_do, curl_aio_flush,
cd9d16
+                                    NULL, s);
cd9d16
             break;
cd9d16
         case CURL_POLL_INOUT:
cd9d16
-            qemu_aio_set_fd_handler(fd, curl_multi_do,
cd9d16
-                                    curl_multi_do, NULL, NULL, s);
cd9d16
+            qemu_aio_set_fd_handler(fd, curl_multi_do, curl_multi_do,
cd9d16
+                                    curl_aio_flush, NULL, s);
cd9d16
             break;
cd9d16
         case CURL_POLL_REMOVE:
cd9d16
             qemu_aio_set_fd_handler(fd, NULL, NULL, NULL, NULL, NULL);
cd9d16
@@ -394,6 +397,21 @@ out_noclean:
cd9d16
     return -EINVAL;
cd9d16
 }
cd9d16
 
cd9d16
+static int curl_aio_flush(void *opaque)
cd9d16
+{
cd9d16
+    BDRVCURLState *s = opaque;
cd9d16
+    int i, j;
cd9d16
+
cd9d16
+    for (i=0; i < CURL_NUM_STATES; i++) {
cd9d16
+        for(j=0; j < CURL_NUM_ACB; j++) {
cd9d16
+            if (s->states[i].acb[j]) {
cd9d16
+                return 1;
cd9d16
+            }
cd9d16
+        }
cd9d16
+    }
cd9d16
+    return 0;
cd9d16
+}
cd9d16
+
cd9d16
 static void curl_aio_cancel(BlockDriverAIOCB *blockacb)
cd9d16
 {
cd9d16
     // Do we have to implement canceling? Seems to work without...
cd9d16
-- 
cd9d16
1.7.11.2
cd9d16