[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] block/curl: Implement the libcurl timer callbac
From: |
Paolo Bonzini |
Subject: |
Re: [Qemu-devel] [PATCH] block/curl: Implement the libcurl timer callback interface |
Date: |
Wed, 15 Jan 2014 23:06:23 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130923 Thunderbird/17.0.9 |
Il 15/01/2014 18:23, Peter Maydell ha scritto:
> libcurl versions 7.16.0 and later have a timer callback interface which
> must be implemented in order for libcurl to make forward progress (it
> will sometimes rely on being called back on the timeout if there are
> no file descriptors registered). Implement the callback, and use a
> QEMU AIO timer to ensure we prod libcurl again when it asks us to.
>
> Signed-off-by: Peter Maydell <address@hidden>
> ---
> This fixes the problem I was seeing where trying to use the curl block
> backend just hung. I'm not sure whether all libcurl versions that provide
> the timer callback API require its use, but it shouldn't hurt.
It still hangs here, but the adding the following patch on top fixes
curl on Fedora for me!
Signed-off-by: Paolo Bonzini <address@hidden>
diff --git a/block/curl.c b/block/curl.c
index 5238961..e0cf138 100644
--- a/block/curl.c
+++ b/block/curl.c
@@ -232,20 +232,10 @@ static int curl_find_buf(BDRVCURLState *s, size_t start,
size_t len,
return FIND_RET_NONE;
}
-static void curl_multi_do(void *arg)
+static void curl_multi_read(BDRVCURLState *s)
{
- BDRVCURLState *s = (BDRVCURLState *)arg;
- int running;
- int r;
int msgs_in_queue;
- if (!s->multi)
- return;
-
- do {
- r = curl_multi_socket_all(s->multi, &running);
- } while(r == CURLM_CALL_MULTI_PERFORM);
-
/* Try to find done transfers, so we can free the easy
* handle again. */
do {
@@ -289,6 +279,37 @@ static void curl_multi_do(void *arg)
} while(msgs_in_queue);
}
+static void curl_multi_do(void *arg)
+{
+ BDRVCURLState *s = (BDRVCURLState *)arg;
+ int running;
+ int r;
+
+ if (!s->multi) {
+ return;
+ }
+
+ do {
+ r = curl_multi_socket_all(s->multi, &running);
+ } while(r == CURLM_CALL_MULTI_PERFORM);
+
+ curl_multi_read(s);
+}
+
+static void curl_multi_timeout_do(void *arg)
+{
+ BDRVCURLState *s = (BDRVCURLState *)arg;
+ int running;
+
+ if (!s->multi) {
+ return;
+ }
+
+ curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running);
+
+ curl_multi_read(s);
+}
+
static CURLState *curl_init_state(BDRVCURLState *s)
{
CURLState *state = NULL;
@@ -498,7 +519,7 @@ static int curl_open(BlockDriverState *bs, QDict *options,
int flags,
aio_timer_init(bdrv_get_aio_context(bs), &s->timer,
QEMU_CLOCK_REALTIME, SCALE_NS,
- curl_multi_do, s);
+ curl_multi_timeout_do, s);
// Now we know the file exists and its size, so let's
// initialize the multi interface!