05bba0
From 06b79081237eff3ebd8719af55265855d446f3e6 Mon Sep 17 00:00:00 2001
05bba0
From: Richard Jones <rjones@redhat.com>
05bba0
Date: Thu, 11 Jun 2015 11:40:25 +0200
05bba0
Subject: [PATCH 25/30] block.curl: adding 'timeout' option
05bba0
05bba0
Message-id: <1434022828-13037-19-git-send-email-rjones@redhat.com>
05bba0
Patchwork-id: 65851
05bba0
O-Subject: [RHEL-7.2 qemu-kvm v3 PATCH 18/21] block.curl: adding 'timeout' option
05bba0
Bugzilla: 1226684
05bba0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
05bba0
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
05bba0
05bba0
From: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
05bba0
05bba0
The curl hardcoded timeout (5 seconds) sometimes is not long
05bba0
enough depending on the remote server configuration and network
05bba0
traffic. The user should be able to set how much long he is
05bba0
willing to wait for the connection.
05bba0
05bba0
Adding a new option to set this timeout gives the user this
05bba0
flexibility. The previous default timeout of 5 seconds will be
05bba0
used if this option is not present.
05bba0
05bba0
Reviewed-by: Fam Zheng <famz@redhat.com>
05bba0
Signed-off-by: Daniel Henrique Barboza <danielhb@linux.vnet.ibm.com>
05bba0
Reviewed-by: Benoit Canet <benoit.canet@nodalink.com>
05bba0
Tested-by: Richard W.M. Jones <rjones@redhat.com>
05bba0
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
05bba0
05bba0
Upstream-status: 212aefaa53d142baa9a22f5aadd2e72eb916c0c0
05bba0
05bba0
Note this intentionally omits the documentation changes in
05bba0
'qemu-options.hx' from the upstream patch.
05bba0
05bba0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
---
05bba0
 block/curl.c | 13 ++++++++++++-
05bba0
 1 file changed, 12 insertions(+), 1 deletion(-)
05bba0
05bba0
diff --git a/block/curl.c b/block/curl.c
05bba0
index 2486449..1f1df4f 100644
05bba0
--- a/block/curl.c
05bba0
+++ b/block/curl.c
05bba0
@@ -63,6 +63,7 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_handle,
05bba0
 #define CURL_NUM_ACB    8
05bba0
 #define SECTOR_SIZE     512
05bba0
 #define READ_AHEAD_DEFAULT (256 * 1024)
05bba0
+#define CURL_TIMEOUT_DEFAULT 5
05bba0
 
05bba0
 #define FIND_RET_NONE   0
05bba0
 #define FIND_RET_OK     1
05bba0
@@ -71,6 +72,7 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_handle,
05bba0
 #define CURL_BLOCK_OPT_URL       "url"
05bba0
 #define CURL_BLOCK_OPT_READAHEAD "readahead"
05bba0
 #define CURL_BLOCK_OPT_SSLVERIFY "sslverify"
05bba0
+#define CURL_BLOCK_OPT_TIMEOUT "timeout"
05bba0
 
05bba0
 struct BDRVCURLState;
05bba0
 
05bba0
@@ -109,6 +111,7 @@ typedef struct BDRVCURLState {
05bba0
     char *url;
05bba0
     size_t readahead_size;
05bba0
     bool sslverify;
05bba0
+    int timeout;
05bba0
     bool accept_range;
05bba0
 } BDRVCURLState;
05bba0
 
05bba0
@@ -379,7 +382,7 @@ static CURLState *curl_init_state(BDRVCURLState *s)
05bba0
         curl_easy_setopt(state->curl, CURLOPT_URL, s->url);
05bba0
         curl_easy_setopt(state->curl, CURLOPT_SSL_VERIFYPEER,
05bba0
                          (long) s->sslverify);
05bba0
-        curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, 5);
05bba0
+        curl_easy_setopt(state->curl, CURLOPT_TIMEOUT, s->timeout);
05bba0
         curl_easy_setopt(state->curl, CURLOPT_WRITEFUNCTION,
05bba0
                          (void *)curl_read_cb);
05bba0
         curl_easy_setopt(state->curl, CURLOPT_WRITEDATA, (void *)state);
05bba0
@@ -443,6 +446,11 @@ static QemuOptsList runtime_opts = {
05bba0
             .type = QEMU_OPT_BOOL,
05bba0
             .help = "Verify SSL certificate"
05bba0
         },
05bba0
+        {
05bba0
+            .name = CURL_BLOCK_OPT_TIMEOUT,
05bba0
+            .type = QEMU_OPT_NUMBER,
05bba0
+            .help = "Curl timeout"
05bba0
+        },
05bba0
         { /* end of list */ }
05bba0
     },
05bba0
 };
05bba0
@@ -475,6 +483,9 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
05bba0
         goto out_noclean;
05bba0
     }
05bba0
 
05bba0
+    s->timeout = qemu_opt_get_number(opts, CURL_BLOCK_OPT_TIMEOUT,
05bba0
+                                     CURL_TIMEOUT_DEFAULT);
05bba0
+
05bba0
     s->sslverify = qemu_opt_get_bool(opts, CURL_BLOCK_OPT_SSLVERIFY, true);
05bba0
 
05bba0
     file = qemu_opt_get(opts, CURL_BLOCK_OPT_URL);
05bba0
-- 
05bba0
1.8.3.1
05bba0