4ec855
From 37acfe84ccbc4cc050e7be0ba9c8c4134a7b004e Mon Sep 17 00:00:00 2001
4ec855
From: Max Reitz <mreitz@redhat.com>
4ec855
Date: Tue, 19 Nov 2019 15:29:57 +0000
4ec855
Subject: [PATCH 5/8] curl: Pass CURLSocket to curl_multi_do()
4ec855
MIME-Version: 1.0
4ec855
Content-Type: text/plain; charset=UTF-8
4ec855
Content-Transfer-Encoding: 8bit
4ec855
4ec855
RH-Author: Max Reitz <mreitz@redhat.com>
4ec855
Message-id: <20191119153000.101646-5-mreitz@redhat.com>
4ec855
Patchwork-id: 92518
4ec855
O-Subject: [RHEL-8.2.0 qemu-kvm PATCH 4/7] curl: Pass CURLSocket to curl_multi_do()
4ec855
Bugzilla: 1744602
4ec855
RH-Acked-by: Maxim Levitsky <mlevitsk@redhat.com>
4ec855
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
4ec855
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
4ec855
4ec855
curl_multi_do_locked() currently marks all sockets as ready.  That is
4ec855
not only inefficient, but in fact unsafe (the loop is).  A follow-up
4ec855
patch will change that, but to do so, curl_multi_do_locked() needs to
4ec855
know exactly which socket is ready; and that is accomplished by this
4ec855
patch here.
4ec855
4ec855
Cc: qemu-stable@nongnu.org
4ec855
Signed-off-by: Max Reitz <mreitz@redhat.com>
4ec855
Message-id: 20190910124136.10565-5-mreitz@redhat.com
4ec855
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
4ec855
Reviewed-by: John Snow <jsnow@redhat.com>
4ec855
Signed-off-by: Max Reitz <mreitz@redhat.com>
4ec855
(cherry picked from commit 9dbad87d25587ff640ef878f7b6159fc368ff541)
4ec855
Signed-off-by: Max Reitz <mreitz@redhat.com>
4ec855
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
4ec855
---
4ec855
 block/curl.c | 20 +++++++++++---------
4ec855
 1 file changed, 11 insertions(+), 9 deletions(-)
4ec855
4ec855
diff --git a/block/curl.c b/block/curl.c
4ec855
index 8f31594..de00ec8 100644
4ec855
--- a/block/curl.c
4ec855
+++ b/block/curl.c
4ec855
@@ -194,15 +194,15 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action,
4ec855
     switch (action) {
4ec855
         case CURL_POLL_IN:
4ec855
             aio_set_fd_handler(s->aio_context, fd, false,
4ec855
-                               curl_multi_do, NULL, NULL, state);
4ec855
+                               curl_multi_do, NULL, NULL, socket);
4ec855
             break;
4ec855
         case CURL_POLL_OUT:
4ec855
             aio_set_fd_handler(s->aio_context, fd, false,
4ec855
-                               NULL, curl_multi_do, NULL, state);
4ec855
+                               NULL, curl_multi_do, NULL, socket);
4ec855
             break;
4ec855
         case CURL_POLL_INOUT:
4ec855
             aio_set_fd_handler(s->aio_context, fd, false,
4ec855
-                               curl_multi_do, curl_multi_do, NULL, state);
4ec855
+                               curl_multi_do, curl_multi_do, NULL, socket);
4ec855
             break;
4ec855
         case CURL_POLL_REMOVE:
4ec855
             aio_set_fd_handler(s->aio_context, fd, false,
4ec855
@@ -401,9 +401,10 @@ static void curl_multi_check_completion(BDRVCURLState *s)
4ec855
 }
4ec855
 
4ec855
 /* Called with s->mutex held.  */
4ec855
-static void curl_multi_do_locked(CURLState *s)
4ec855
+static void curl_multi_do_locked(CURLSocket *ready_socket)
4ec855
 {
4ec855
     CURLSocket *socket, *next_socket;
4ec855
+    CURLState *s = ready_socket->state;
4ec855
     int running;
4ec855
     int r;
4ec855
 
4ec855
@@ -422,12 +423,13 @@ static void curl_multi_do_locked(CURLState *s)
4ec855
 
4ec855
 static void curl_multi_do(void *arg)
4ec855
 {
4ec855
-    CURLState *s = (CURLState *)arg;
4ec855
+    CURLSocket *socket = arg;
4ec855
+    BDRVCURLState *s = socket->state->s;
4ec855
 
4ec855
-    qemu_mutex_lock(&s->s->mutex);
4ec855
-    curl_multi_do_locked(s);
4ec855
-    curl_multi_check_completion(s->s);
4ec855
-    qemu_mutex_unlock(&s->s->mutex);
4ec855
+    qemu_mutex_lock(&s->mutex);
4ec855
+    curl_multi_do_locked(socket);
4ec855
+    curl_multi_check_completion(s);
4ec855
+    qemu_mutex_unlock(&s->mutex);
4ec855
 }
4ec855
 
4ec855
 static void curl_multi_timeout_do(void *arg)
4ec855
-- 
4ec855
1.8.3.1
4ec855