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