cryptospore / rpms / qemu-kvm

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