thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-curl-Eliminate-unnecessary-use-of-curl_multi_socket_.patch

05bba0
From 2b07b0558685c234fd93214be705a4feb058e27b Mon Sep 17 00:00:00 2001
05bba0
From: Richard Jones <rjones@redhat.com>
05bba0
Date: Thu, 11 Jun 2015 11:40:16 +0200
05bba0
Subject: [PATCH 16/30] curl: Eliminate unnecessary use of
05bba0
 curl_multi_socket_all
05bba0
05bba0
Message-id: <1434022828-13037-10-git-send-email-rjones@redhat.com>
05bba0
Patchwork-id: 65844
05bba0
O-Subject: [RHEL-7.2 qemu-kvm v3 PATCH 09/21] curl: Eliminate unnecessary use of curl_multi_socket_all
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: Matthew Booth <mbooth@redhat.com>
05bba0
05bba0
curl_multi_socket_all is a deprecated catch-all which checks for
05bba0
activities on all open curl sockets. We have enough information from
05bba0
the event loop to check only the sockets with activity. This change
05bba0
removes use of curl_multi_socket_all in favour of
05bba0
curl_multi_socket_action called with the relevant handle.
05bba0
05bba0
At the same time, it also ensures that the driver only checks for
05bba0
completion of read operations after reading from a socket, rather than
05bba0
both reading and writing.
05bba0
05bba0
Signed-off-by: Matthew Booth <mbooth@redhat.com>
05bba0
Tested-by: Richard W.M. Jones <rjones@redhat.com>
05bba0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
05bba0
05bba0
Upstream-status: 838ef602498b8d1985a231a06f5e328e2946a81d
05bba0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
---
05bba0
 block/curl.c | 34 +++++++++++++++++++++++-----------
05bba0
 1 file changed, 23 insertions(+), 11 deletions(-)
05bba0
05bba0
diff --git a/block/curl.c b/block/curl.c
05bba0
index e4332c5..b19e632 100644
05bba0
--- a/block/curl.c
05bba0
+++ b/block/curl.c
05bba0
@@ -71,6 +71,7 @@ typedef struct CURLState
05bba0
     struct BDRVCURLState *s;
05bba0
     CURLAIOCB *acb[CURL_NUM_ACB];
05bba0
     CURL *curl;
05bba0
+    curl_socket_t sock_fd;
05bba0
     char *orig_buf;
05bba0
     size_t buf_start;
05bba0
     size_t buf_off;
05bba0
@@ -92,6 +93,7 @@ typedef struct BDRVCURLState {
05bba0
 static void curl_clean_state(CURLState *s);
05bba0
 static void curl_multi_do(void *arg);
05bba0
 static int curl_aio_flush(void *opaque);
05bba0
+static void curl_multi_read(void *arg);
05bba0
 
05bba0
 #ifdef NEED_CURL_TIMER_CALLBACK
05bba0
 static int curl_timer_cb(CURLM *multi, long timeout_ms, void *opaque)
05bba0
@@ -113,17 +115,21 @@ static int curl_timer_cb(CURLM *multi, long timeout_ms, void *opaque)
05bba0
 static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action,
05bba0
                         void *s, void *sp)
05bba0
 {
05bba0
+    CURLState *state = NULL;
05bba0
+    curl_easy_getinfo(curl, CURLINFO_PRIVATE, (char **)&state);
05bba0
+    state->sock_fd = fd;
05bba0
+
05bba0
     DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, fd);
05bba0
     switch (action) {
05bba0
         case CURL_POLL_IN:
05bba0
-            qemu_aio_set_fd_handler(fd, curl_multi_do, NULL, curl_aio_flush, s);
05bba0
+            qemu_aio_set_fd_handler(fd, curl_multi_read, NULL, curl_aio_flush, state);
05bba0
             break;
05bba0
         case CURL_POLL_OUT:
05bba0
-            qemu_aio_set_fd_handler(fd, NULL, curl_multi_do, curl_aio_flush, s);
05bba0
+            qemu_aio_set_fd_handler(fd, NULL, curl_multi_do, curl_aio_flush, state);
05bba0
             break;
05bba0
         case CURL_POLL_INOUT:
05bba0
-            qemu_aio_set_fd_handler(fd, curl_multi_do, curl_multi_do,
05bba0
-                                    curl_aio_flush, s);
05bba0
+            qemu_aio_set_fd_handler(fd, curl_multi_read, curl_multi_do,
05bba0
+                                    curl_aio_flush, state);
05bba0
             break;
05bba0
         case CURL_POLL_REMOVE:
05bba0
             qemu_aio_set_fd_handler(fd, NULL, NULL, NULL, NULL);
05bba0
@@ -236,7 +242,7 @@ static int curl_find_buf(BDRVCURLState *s, size_t start, size_t len,
05bba0
     return FIND_RET_NONE;
05bba0
 }
05bba0
 
05bba0
-static void curl_multi_read(BDRVCURLState *s)
05bba0
+static void curl_multi_check_completion(BDRVCURLState *s)
05bba0
 {
05bba0
     int msgs_in_queue;
05bba0
 
05bba0
@@ -286,19 +292,26 @@ static void curl_multi_read(BDRVCURLState *s)
05bba0
 
05bba0
 static void curl_multi_do(void *arg)
05bba0
 {
05bba0
-    BDRVCURLState *s = (BDRVCURLState *)arg;
05bba0
+    CURLState *s = (CURLState *)arg;
05bba0
     int running;
05bba0
     int r;
05bba0
 
05bba0
-    if (!s->multi) {
05bba0
+    if (!s->s->multi) {
05bba0
         return;
05bba0
     }
05bba0
 
05bba0
     do {
05bba0
-        r = curl_multi_socket_all(s->multi, &running);
05bba0
+        r = curl_multi_socket_action(s->s->multi, s->sock_fd, 0, &running);
05bba0
     } while(r == CURLM_CALL_MULTI_PERFORM);
05bba0
 
05bba0
-    curl_multi_read(s);
05bba0
+}
05bba0
+
05bba0
+static void curl_multi_read(void *arg)
05bba0
+{
05bba0
+    CURLState *s = (CURLState *)arg;
05bba0
+
05bba0
+    curl_multi_do(arg);
05bba0
+    curl_multi_check_completion(s->s);
05bba0
 }
05bba0
 
05bba0
 static void curl_multi_timeout_do(void *arg)
05bba0
@@ -313,7 +326,7 @@ static void curl_multi_timeout_do(void *arg)
05bba0
 
05bba0
     curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running);
05bba0
 
05bba0
-    curl_multi_read(s);
05bba0
+    curl_multi_check_completion(s);
05bba0
 #else
05bba0
     abort();
05bba0
 #endif
05bba0
@@ -517,7 +530,6 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,
05bba0
     // initialize the multi interface!
05bba0
 
05bba0
     s->multi = curl_multi_init();
05bba0
-    curl_multi_setopt(s->multi, CURLMOPT_SOCKETDATA, s);
05bba0
     curl_multi_setopt(s->multi, CURLMOPT_SOCKETFUNCTION, curl_sock_cb);
05bba0
 #ifdef NEED_CURL_TIMER_CALLBACK
05bba0
     curl_multi_setopt(s->multi, CURLMOPT_TIMERDATA, s);
05bba0
-- 
05bba0
1.8.3.1
05bba0