016a62
From 70c7a568e3c1384704228622990d6aaa2350e44e Mon Sep 17 00:00:00 2001
016a62
From: Max Reitz <mreitz@redhat.com>
016a62
Date: Tue, 19 Nov 2019 15:29:58 +0000
016a62
Subject: [PATCH 6/8] curl: Report only ready sockets
016a62
MIME-Version: 1.0
016a62
Content-Type: text/plain; charset=UTF-8
016a62
Content-Transfer-Encoding: 8bit
016a62
016a62
RH-Author: Max Reitz <mreitz@redhat.com>
016a62
Message-id: <20191119153000.101646-6-mreitz@redhat.com>
016a62
Patchwork-id: 92519
016a62
O-Subject: [RHEL-8.2.0 qemu-kvm PATCH 5/7] curl: Report only ready sockets
016a62
Bugzilla: 1744602
016a62
RH-Acked-by: Maxim Levitsky <mlevitsk@redhat.com>
016a62
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
016a62
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
016a62
016a62
Instead of reporting all sockets to cURL, only report the one that has
016a62
caused curl_multi_do_locked() to be called.  This lets us get rid of the
016a62
QLIST_FOREACH_SAFE() list, which was actually wrong: SAFE foreaches are
016a62
only safe when the current element is removed in each iteration.  If it
016a62
possible for the list to be concurrently modified, we cannot guarantee
016a62
that only the current element will be removed.  Therefore, we must not
016a62
use QLIST_FOREACH_SAFE() here.
016a62
016a62
Fixes: ff5ca1664af85b24a4180d595ea6873fd3deac57
016a62
Cc: qemu-stable@nongnu.org
016a62
Signed-off-by: Max Reitz <mreitz@redhat.com>
016a62
Message-id: 20190910124136.10565-6-mreitz@redhat.com
016a62
Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
016a62
Reviewed-by: John Snow <jsnow@redhat.com>
016a62
Signed-off-by: Max Reitz <mreitz@redhat.com>
016a62
(cherry picked from commit 9abaf9fc474c3dd53e8e119326abc774c977c331)
016a62
Signed-off-by: Max Reitz <mreitz@redhat.com>
016a62
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
016a62
---
016a62
 block/curl.c | 17 ++++++-----------
016a62
 1 file changed, 6 insertions(+), 11 deletions(-)
016a62
016a62
diff --git a/block/curl.c b/block/curl.c
016a62
index de00ec8..f776615 100644
016a62
--- a/block/curl.c
016a62
+++ b/block/curl.c
016a62
@@ -401,24 +401,19 @@ static void curl_multi_check_completion(BDRVCURLState *s)
016a62
 }
016a62
 
016a62
 /* Called with s->mutex held.  */
016a62
-static void curl_multi_do_locked(CURLSocket *ready_socket)
016a62
+static void curl_multi_do_locked(CURLSocket *socket)
016a62
 {
016a62
-    CURLSocket *socket, *next_socket;
016a62
-    CURLState *s = ready_socket->state;
016a62
+    BDRVCURLState *s = socket->state->s;
016a62
     int running;
016a62
     int r;
016a62
 
016a62
-    if (!s->s->multi) {
016a62
+    if (!s->multi) {
016a62
         return;
016a62
     }
016a62
 
016a62
-    /* Need to use _SAFE because curl_multi_socket_action() may trigger
016a62
-     * curl_sock_cb() which might modify this list */
016a62
-    QLIST_FOREACH_SAFE(socket, &s->sockets, next, next_socket) {
016a62
-        do {
016a62
-            r = curl_multi_socket_action(s->s->multi, socket->fd, 0, &running);
016a62
-        } while (r == CURLM_CALL_MULTI_PERFORM);
016a62
-    }
016a62
+    do {
016a62
+        r = curl_multi_socket_action(s->multi, socket->fd, 0, &running);
016a62
+    } while (r == CURLM_CALL_MULTI_PERFORM);
016a62
 }
016a62
 
016a62
 static void curl_multi_do(void *arg)
016a62
-- 
016a62
1.8.3.1
016a62