|
|
f2a088 |
From 212aefaa53d142baa9a22f5aadd2e72eb916c0c0 Mon Sep 17 00:00:00 2001
|
|
|
f2a088 |
From: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
|
|
|
f2a088 |
Date: Wed, 13 Aug 2014 12:44:27 -0300
|
|
|
f2a088 |
Subject: [PATCH] block.curl: adding 'timeout' option
|
|
|
f2a088 |
|
|
|
f2a088 |
The curl hardcoded timeout (5 seconds) sometimes is not long
|
|
|
f2a088 |
enough depending on the remote server configuration and network
|
|
|
f2a088 |
traffic. The user should be able to set how much long he is
|
|
|
f2a088 |
willing to wait for the connection.
|
|
|
f2a088 |
|
|
|
f2a088 |
Adding a new option to set this timeout gives the user this
|
|
|
f2a088 |
flexibility. The previous default timeout of 5 seconds will be
|
|
|
f2a088 |
used if this option is not present.
|
|
|
f2a088 |
|
|
|
f2a088 |
Reviewed-by: Fam Zheng <famz@redhat.com>
|
|
|
f2a088 |
Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
|
|
|
f2a088 |
Reviewed-by: Benoit Canet <benoit.canet@nodalink.com>
|
|
|
f2a088 |
Tested-by: Richard W.M. Jones <rjones@redhat.com>
|
|
|
f2a088 |
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
|
|
|
f2a088 |
---
|
|
|
f2a088 |
block/curl.c | 13 ++++++++++++-
|
|
|
f2a088 |
qemu-options.hx | 10 ++++++++--
|
|
|
f2a088 |
2 files changed, 20 insertions(+), 3 deletions(-)
|
|
|
f2a088 |
|
|
|
f2a088 |
diff --git a/block/curl.c b/block/curl.c
|
|
|
f2a088 |
index d4b85d2..2698ae3 100644
|
|
|
f2a088 |
--- a/block/curl.c
|
|
|
f2a088 |
+++ b/block/curl.c
|
|
|
f2a088 |
@@ -63,6 +63,7 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_handle,
|
|
|
f2a088 |
#define CURL_NUM_ACB 8
|
|
|
f2a088 |
#define SECTOR_SIZE 512
|
|
|
f2a088 |
#define READ_AHEAD_DEFAULT (256 * 1024)
|
|
|
f2a088 |
+#define CURL_TIMEOUT_DEFAULT 5
|
|
|
f2a088 |
|
|
|
f2a088 |
#define FIND_RET_NONE 0
|
|
|
f2a088 |
#define FIND_RET_OK 1
|
|
|
f2a088 |
@@ -71,6 +72,7 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_handle,
|
|
|
f2a088 |
#define CURL_BLOCK_OPT_URL "url"
|
|
|
f2a088 |
#define CURL_BLOCK_OPT_READAHEAD "readahead"
|
|
|
f2a088 |
#define CURL_BLOCK_OPT_SSLVERIFY "sslverify"
|
|
|
f2a088 |
+#define CURL_BLOCK_OPT_TIMEOUT "timeout"
|
|
|
f2a088 |
|
|
|
f2a088 |
struct BDRVCURLState;
|
|
|
f2a088 |
|
|
|
f2a088 |
@@ -109,6 +111,7 @@ typedef struct BDRVCURLState {
|
|
|
f2a088 |
char *url;
|
|
|
f2a088 |
size_t readahead_size;
|
|
|
f2a088 |
bool sslverify;
|
|
|
f2a088 |
+ int timeout;
|
|
|
f2a088 |
bool accept_range;
|
|
|
f2a088 |
AioContext *aio_context;
|
|
|
f2a088 |
} BDRVCURLState;
|
|
|
f2a088 |
@@ -382,7 +385,7 @@ static CURLState *curl_init_state(BDRVCURLState *s)
|
|
|
f2a088 |
curl_easy_setopt(state->curl, CURLOPT_URL, s->url);
|
|
|
f2a088 |
curl_easy_setopt(state->curl, CURLOPT_SSL_VERIFYPEER,
|
|
|
f2a088 |
(long) s->sslverify);
|
|
|
f2a088 |
- curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, 5);
|
|
|
f2a088 |
+ curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, s->timeout);
|
|
|
f2a088 |
curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION,
|
|
|
f2a088 |
(void *)curl_read_cb);
|
|
|
f2a088 |
curl_easy_setopt(state->curl, CURLOPT_WRITEDATA, (void *)state);
|
|
|
f2a088 |
@@ -489,6 +492,11 @@ static QemuOptsList runtime_opts = {
|
|
|
f2a088 |
.type = QEMU_OPT_BOOL,
|
|
|
f2a088 |
.help = "Verify SSL certificate"
|
|
|
f2a088 |
},
|
|
|
f2a088 |
+ {
|
|
|
f2a088 |
+ .name = CURL_BLOCK_OPT_TIMEOUT,
|
|
|
f2a088 |
+ .type = QEMU_OPT_NUMBER,
|
|
|
f2a088 |
+ .help = "Curl timeout"
|
|
|
f2a088 |
+ },
|
|
|
f2a088 |
{ /* end of list */ }
|
|
|
f2a088 |
},
|
|
|
f2a088 |
};
|
|
|
f2a088 |
@@ -525,6 +533,9 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
f2a088 |
goto out_noclean;
|
|
|
f2a088 |
}
|
|
|
f2a088 |
|
|
|
f2a088 |
+ s->timeout = qemu_opt_get_number(opts, CURL_BLOCK_OPT_TIMEOUT,
|
|
|
f2a088 |
+ CURL_TIMEOUT_DEFAULT);
|
|
|
f2a088 |
+
|
|
|
f2a088 |
s->sslverify = qemu_opt_get_bool(opts, CURL_BLOCK_OPT_SSLVERIFY, true);
|
|
|
f2a088 |
|
|
|
f2a088 |
file = qemu_opt_get(opts, CURL_BLOCK_OPT_URL);
|
|
|
f2a088 |
diff --git a/qemu-options.hx b/qemu-options.hx
|
|
|
f2a088 |
index c573dd8..52d56f4 100644
|
|
|
f2a088 |
--- a/qemu-options.hx
|
|
|
f2a088 |
+++ b/qemu-options.hx
|
|
|
f2a088 |
@@ -2351,6 +2351,11 @@ multiple of 512 bytes. It defaults to 256k.
|
|
|
f2a088 |
@item sslverify
|
|
|
f2a088 |
Whether to verify the remote server's certificate when connecting over SSL. It
|
|
|
f2a088 |
can have the value 'on' or 'off'. It defaults to 'on'.
|
|
|
f2a088 |
+
|
|
|
f2a088 |
+@item timeout
|
|
|
f2a088 |
+Set the timeout in seconds of the CURL connection. This timeout is the time
|
|
|
f2a088 |
+that CURL waits for a response from the remote server to get the size of the
|
|
|
f2a088 |
+image to be downloaded. If not set, the default timeout of 5 seconds is used.
|
|
|
f2a088 |
@end table
|
|
|
f2a088 |
|
|
|
f2a088 |
Note that when passing options to qemu explicitly, @option{driver} is the value
|
|
|
f2a088 |
@@ -2372,9 +2377,10 @@ qemu-system-x86_64 -drive file=/tmp/Fedora-x86_64-20-20131211.1-sda.qcow2,copy-o
|
|
|
f2a088 |
@end example
|
|
|
f2a088 |
|
|
|
f2a088 |
Example: boot from an image stored on a VMware vSphere server with a self-signed
|
|
|
f2a088 |
-certificate using a local overlay for writes and a readahead of 64k
|
|
|
f2a088 |
+certificate using a local overlay for writes, a readahead of 64k and a timeout
|
|
|
f2a088 |
+of 10 seconds.
|
|
|
f2a088 |
@example
|
|
|
f2a088 |
-qemu-img create -f qcow2 -o backing_file='json:@{"file.driver":"https",, "file.url":"https://user:password@@vsphere.example.com/folder/test/test-flat.vmdk?dcPath=Datacenter&dsName=datastore1",, "file.sslverify":"off",, "file.readahead":"64k"@}' /tmp/test.qcow2
|
|
|
f2a088 |
+qemu-img create -f qcow2 -o backing_file='json:@{"file.driver":"https",, "file.url":"https://user:password@@vsphere.example.com/folder/test/test-flat.vmdk?dcPath=Datacenter&dsName=datastore1",, "file.sslverify":"off",, "file.readahead":"64k",, "file.timeout":10@}' /tmp/test.qcow2
|
|
|
f2a088 |
|
|
|
f2a088 |
qemu-system-x86_64 -drive file=/tmp/test.qcow2
|
|
|
f2a088 |
@end example
|
|
|
f2a088 |
--
|
|
|
f2a088 |
2.0.4
|
|
|
f2a088 |
|