From nobody Wed Nov 12 00:08:34 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566923811; cv=none; d=zoho.com; s=zohoarc; b=BnbLT2KO4Fu0a/GZdt7BCqqb9J+LhN0oHNeAwqVEcG5gVTfuYJegJSZ+AgXkO4dpNHhVdD/cJAdKZAgrdV/lSi7pMzwgyyfbJmS10H6WC/XOqjFc8pMOqG57c2IS7X96eOvPkBGnvfMqLt803pctV4NtZpoGjmIkMezkCytUtJY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566923811; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=9eTNJIc+0t/uaLhecvaG2GBBaPwbE+CKQJ8YV3qOQhA=; b=nsyTnyM1ZB5V7zbqwa92p8+5vbKtPdaDgmrMxbSUfdOPU6bW4dM8f6rFXq7xoSOiAUiUKFkdqH7fz0ouoqPYleQR8awZXDC82qb/e3eJ6sVpxoQg0xamuk5pJNjgd7imgXFUAHz7lfhCLXQDs+Gh05080BJfVU6dIM5ow9dOgKo= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566923811462408.4829641221713; Tue, 27 Aug 2019 09:36:51 -0700 (PDT) Received: from localhost ([::1]:53986 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2eSY-0004pX-9U for importer@patchew.org; Tue, 27 Aug 2019 12:36:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34931) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2eQj-0003Ni-2o for qemu-devel@nongnu.org; Tue, 27 Aug 2019 12:34:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i2eQh-0000E1-Q5 for qemu-devel@nongnu.org; Tue, 27 Aug 2019 12:34:48 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43328) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i2eQf-0000BM-IE; Tue, 27 Aug 2019 12:34:45 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E70F4C053FDC; Tue, 27 Aug 2019 16:34:44 +0000 (UTC) Received: from localhost (unknown [10.40.205.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7CB2760CD0; Tue, 27 Aug 2019 16:34:44 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 27 Aug 2019 18:34:34 +0200 Message-Id: <20190827163439.16686-2-mreitz@redhat.com> In-Reply-To: <20190827163439.16686-1-mreitz@redhat.com> References: <20190827163439.16686-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 27 Aug 2019 16:34:44 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/6] curl: Keep pointer to the CURLState in CURLSocket X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" A follow-up patch will make curl_multi_do() and curl_multi_read() take a CURLSocket instead of the CURLState. They still need the latter, though, so add a pointer to it to the former. Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz Reviewed-by: John Snow --- block/curl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/block/curl.c b/block/curl.c index d4c8e94f3e..92dc2f630e 100644 --- a/block/curl.c +++ b/block/curl.c @@ -80,6 +80,7 @@ static CURLMcode __curl_multi_socket_action(CURLM *multi_= handle, #define CURL_BLOCK_OPT_TIMEOUT_DEFAULT 5 =20 struct BDRVCURLState; +struct CURLState; =20 static bool libcurl_initialized; =20 @@ -97,6 +98,7 @@ typedef struct CURLAIOCB { =20 typedef struct CURLSocket { int fd; + struct CURLState *state; QLIST_ENTRY(CURLSocket) next; } CURLSocket; =20 @@ -180,6 +182,7 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, i= nt action, if (!socket) { socket =3D g_new0(CURLSocket, 1); socket->fd =3D fd; + socket->state =3D state; QLIST_INSERT_HEAD(&state->sockets, socket, next); } socket =3D NULL; --=20 2.21.0 From nobody Wed Nov 12 00:08:34 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566923811; cv=none; d=zoho.com; s=zohoarc; b=FI+f458QD0zCFQ3EMxfItozKaOA1wEzvn8cdL4GLJ5uzT/U51J/Pae4pAFF5rDDBVIajns8FOsRa5f6VIsur1J0lvrudLxI51N43ihJqdst5FQDGflAk5edTD4JAWoh4OwPaAEFkqy4izr3cgHnd1thHLh0MSp9amwtpSASHd0g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566923811; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=+OYxSjZ8Tv5w3Lpgs093Vl8UqOPFZ3Y6ATAdN7LBCQs=; b=K4VzchhpMsjPf3NtHCqa+JBd+tTSSymjXfZexhd447MLdTDRFFT+n9uGhqc0k1O9bvJrwUYscZUUMxU+s36+hXoDbnMWAbV2r5rCTljicvcZKehKkVkXsDNhIzzXjzuEL/DNS/4mCkpp6ZkCZAWppJsY0apZ6gi5XnALhkqkDX4= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566923811864569.7601611948954; Tue, 27 Aug 2019 09:36:51 -0700 (PDT) Received: from localhost ([::1]:53990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2eSe-0004yS-Hp for importer@patchew.org; Tue, 27 Aug 2019 12:36:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34964) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2eQl-0003RE-EK for qemu-devel@nongnu.org; Tue, 27 Aug 2019 12:34:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i2eQk-0000Fc-DJ for qemu-devel@nongnu.org; Tue, 27 Aug 2019 12:34:51 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40860) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i2eQi-0000Dt-1A; Tue, 27 Aug 2019 12:34:48 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 44CEA18AF95E; Tue, 27 Aug 2019 16:34:47 +0000 (UTC) Received: from localhost (unknown [10.40.205.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CE5985DAAF; Tue, 27 Aug 2019 16:34:46 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 27 Aug 2019 18:34:35 +0200 Message-Id: <20190827163439.16686-3-mreitz@redhat.com> In-Reply-To: <20190827163439.16686-1-mreitz@redhat.com> References: <20190827163439.16686-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Tue, 27 Aug 2019 16:34:47 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/6] curl: Keep *socket until the end of curl_sock_cb() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" This does not really change anything, but it makes the code a bit easier to follow once we use @socket as the opaque pointer for aio_set_fd_handler(). (Also, this change stops us from creating new CURLSocket objects when the cURL library just wants to stop listening on an existing socket that we do not recognize. With a well-behaving cURL, that should never happen anyway.) Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz --- block/curl.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/block/curl.c b/block/curl.c index 92dc2f630e..8a45b371cc 100644 --- a/block/curl.c +++ b/block/curl.c @@ -174,18 +174,16 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd,= int action, if (socket->fd =3D=3D fd) { if (action =3D=3D CURL_POLL_REMOVE) { QLIST_REMOVE(socket, next); - g_free(socket); } break; } } - if (!socket) { + if (action !=3D CURL_POLL_REMOVE && !socket) { socket =3D g_new0(CURLSocket, 1); socket->fd =3D fd; socket->state =3D state; QLIST_INSERT_HEAD(&state->sockets, socket, next); } - socket =3D NULL; =20 trace_curl_sock_cb(action, (int)fd); switch (action) { @@ -207,6 +205,9 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, i= nt action, break; } =20 + if (action =3D=3D CURL_POLL_REMOVE) { + g_free(socket); + } return 0; } =20 --=20 2.21.0 From nobody Wed Nov 12 00:08:34 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566923976; cv=none; d=zoho.com; s=zohoarc; b=Eks/yBM1sWmqiAF+v174TYXPl8DcncCTQJIdw29Wusdq5ebiVLA80Y6KA8Ptens5+Htxfq3ka5YrWKfbbC96k+Vg3sqqFnpwokrFX3wth5x/Q1fZe9McFGf0EqSh7vxhUmqDZZx74SjhDVH43XONNxakTfAEPniB6csFI37GxNs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566923976; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=6RLeId19Cn4MY7GLBZ4oIp2gmbv0RQBgyI9d78x+Gj4=; b=LjvjAbwqUzaWqUGP7opk1AJLmxFdFa+O9BxgcAwq5UD1IWBgrMlBN8XIL9Wj7A57hX08IXPGln/2J+ZUmOzl+eLcmaB4CIMJSZfQ+nUJI+qG37TvkWR31mzywalPVHfTCJs3NzjU0DXzHDRmoyxj4Ick2njAIvN6SV8GSmw8Rrg= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566923976878347.6521987432659; Tue, 27 Aug 2019 09:39:36 -0700 (PDT) Received: from localhost ([::1]:54018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2eVL-0007w2-LB for importer@patchew.org; Tue, 27 Aug 2019 12:39:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35005) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2eQp-0003Wy-Av for qemu-devel@nongnu.org; Tue, 27 Aug 2019 12:34:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i2eQm-0000Gt-QI for qemu-devel@nongnu.org; Tue, 27 Aug 2019 12:34:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:28706) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i2eQk-0000FH-BN; Tue, 27 Aug 2019 12:34:50 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8F15F66C46; Tue, 27 Aug 2019 16:34:49 +0000 (UTC) Received: from localhost (unknown [10.40.205.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2821D196AE; Tue, 27 Aug 2019 16:34:48 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 27 Aug 2019 18:34:36 +0200 Message-Id: <20190827163439.16686-4-mreitz@redhat.com> In-Reply-To: <20190827163439.16686-1-mreitz@redhat.com> References: <20190827163439.16686-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 27 Aug 2019 16:34:49 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/6] curl: Pass CURLSocket to curl_multi_{do, read}() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" curl_multi_do_locked() currently marks all sockets as ready. That is not only inefficient, but in fact unsafe (the loop is). A follow-up patch will change that, but to do so, curl_multi_do_locked() needs to know exactly which socket is ready; and that is accomplished by this patch here. Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz --- block/curl.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/block/curl.c b/block/curl.c index 8a45b371cc..05f77a38c2 100644 --- a/block/curl.c +++ b/block/curl.c @@ -189,15 +189,15 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd,= int action, switch (action) { case CURL_POLL_IN: aio_set_fd_handler(s->aio_context, fd, false, - curl_multi_read, NULL, NULL, state); + curl_multi_read, NULL, NULL, socket); break; case CURL_POLL_OUT: aio_set_fd_handler(s->aio_context, fd, false, - NULL, curl_multi_do, NULL, state); + NULL, curl_multi_do, NULL, socket); break; case CURL_POLL_INOUT: aio_set_fd_handler(s->aio_context, fd, false, - curl_multi_read, curl_multi_do, NULL, state= ); + curl_multi_read, curl_multi_do, NULL, socke= t); break; case CURL_POLL_REMOVE: aio_set_fd_handler(s->aio_context, fd, false, @@ -394,9 +394,10 @@ static void curl_multi_check_completion(BDRVCURLState = *s) } =20 /* Called with s->mutex held. */ -static void curl_multi_do_locked(CURLState *s) +static void curl_multi_do_locked(CURLSocket *ready_socket) { CURLSocket *socket, *next_socket; + CURLState *s =3D socket->state; int running; int r; =20 @@ -415,21 +416,23 @@ static void curl_multi_do_locked(CURLState *s) =20 static void curl_multi_do(void *arg) { - CURLState *s =3D (CURLState *)arg; + CURLSocket *socket =3D arg; + BDRVCURLState *s =3D socket->state->s; =20 - qemu_mutex_lock(&s->s->mutex); - curl_multi_do_locked(s); - qemu_mutex_unlock(&s->s->mutex); + qemu_mutex_lock(&s->mutex); + curl_multi_do_locked(socket); + qemu_mutex_unlock(&s->mutex); } =20 static void curl_multi_read(void *arg) { - CURLState *s =3D (CURLState *)arg; + CURLSocket *socket =3D arg; + BDRVCURLState *s =3D socket->state->s; =20 - qemu_mutex_lock(&s->s->mutex); - curl_multi_do_locked(s); - curl_multi_check_completion(s->s); - qemu_mutex_unlock(&s->s->mutex); + qemu_mutex_lock(&s->mutex); + curl_multi_do_locked(socket); + curl_multi_check_completion(s); + qemu_mutex_unlock(&s->mutex); } =20 static void curl_multi_timeout_do(void *arg) --=20 2.21.0 From nobody Wed Nov 12 00:08:34 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566923981; cv=none; d=zoho.com; s=zohoarc; b=Bm2mCYE5QK80okqiQhQvQR4k05ZEWfqHAkVVjDxUKuizVgumKnBNURELtQLx/OaEeOA63qT3eSb6T/dzfmgmczqYi0s2hSbiZ/UdVDQfsXdhtkWrVkOsTUcZUf9T2sxR4KoRkn+2VStpEWBxRGs9mzvkIIw9RnN7rzI/et+nlrY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566923981; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=ir7gu1Ve8XkGgyjRAa+O8U5DEFU+kNYPuZyw/Tji/xU=; b=TDTyshJp88Hf4lsQp34KkN8mqG+F8Bxv0IEs2ShymgBEHdFasSDrHLusmT8n1R0LCpdEnZwq49LZnhQ4jHqFOAPfYL5EWEJxd2oZihfuyb23es1fX4I/66zjfBUqCpuQZHrwPYkOeIcSn5GZIozzA9fxhAcOKaUxrxCC4dNRWZE= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566923981816810.7305231595232; Tue, 27 Aug 2019 09:39:41 -0700 (PDT) Received: from localhost ([::1]:54021 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2eVP-00082w-J2 for importer@patchew.org; Tue, 27 Aug 2019 12:39:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35015) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2eQq-0003YP-8r for qemu-devel@nongnu.org; Tue, 27 Aug 2019 12:34:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i2eQp-0000Hm-3f for qemu-devel@nongnu.org; Tue, 27 Aug 2019 12:34:56 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38498) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i2eQm-0000GX-L0; Tue, 27 Aug 2019 12:34:52 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E0CE0807062; Tue, 27 Aug 2019 16:34:51 +0000 (UTC) Received: from localhost (unknown [10.40.205.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 74ADC19D7A; Tue, 27 Aug 2019 16:34:51 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 27 Aug 2019 18:34:37 +0200 Message-Id: <20190827163439.16686-5-mreitz@redhat.com> In-Reply-To: <20190827163439.16686-1-mreitz@redhat.com> References: <20190827163439.16686-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.67]); Tue, 27 Aug 2019 16:34:52 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/6] curl: Report only ready sockets X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Instead of reporting all sockets to cURL, only report the one that has caused curl_multi_do_locked() to be called. This lets us get rid of the QLIST_FOREACH_SAFE() list, which was actually wrong: SAFE foreaches are only safe when the current element is removed in each iteration. If it possible for the list to be concurrently modified, we cannot guarantee that only the current element will be removed. Therefore, we must not use QLIST_FOREACH_SAFE() here. Fixes: ff5ca1664af85b24a4180d595ea6873fd3deac57 Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz --- block/curl.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/block/curl.c b/block/curl.c index 05f77a38c2..bc70f39fcb 100644 --- a/block/curl.c +++ b/block/curl.c @@ -394,24 +394,19 @@ static void curl_multi_check_completion(BDRVCURLState= *s) } =20 /* Called with s->mutex held. */ -static void curl_multi_do_locked(CURLSocket *ready_socket) +static void curl_multi_do_locked(CURLSocket *socket) { - CURLSocket *socket, *next_socket; - CURLState *s =3D socket->state; + BDRVCURLState *s =3D socket->state->s; int running; int r; =20 - if (!s->s->multi) { + if (!s->multi) { return; } =20 - /* Need to use _SAFE because curl_multi_socket_action() may trigger - * curl_sock_cb() which might modify this list */ - QLIST_FOREACH_SAFE(socket, &s->sockets, next, next_socket) { - do { - r =3D curl_multi_socket_action(s->s->multi, socket->fd, 0, &ru= nning); - } while (r =3D=3D CURLM_CALL_MULTI_PERFORM); - } + do { + r =3D curl_multi_socket_action(s->multi, socket->fd, 0, &running); + } while (r =3D=3D CURLM_CALL_MULTI_PERFORM); } =20 static void curl_multi_do(void *arg) --=20 2.21.0 From nobody Wed Nov 12 00:08:34 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566923971; cv=none; d=zoho.com; s=zohoarc; b=aCG9Sg3UpUPC9hSjnWjBCNfK5xfoPFHEglVI4PtGZ+glK4FwL/idQNddtqV0AXZUZdeoqlxXh4M2XmnhSCJ4UOqsTQCFAtFkERVuiS1ZPUkECua+RitSFatoR0wUvzLlTwQ7AwPp9V/4o01Mm+HaiC+SkmyloyUn/0Cvbp4Tx3I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566923971; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=iKw686KG7X4ks+xW6qwyPysA1DWFNfBj6UVlM8/z+70=; b=ILK7FS1uDSMwz1xWz5dKD0K17+EuWKehU+ZTwJIwaWg/XkZWIYkwec/eB21gRufY7QEgfl+azd3ON5+slURWrdam8TDmS1VaaDPR2o5Oj5n2V5euoa6a5eowWYCbKJ8VceXNHZ59kmsqCz1esjCMxPXcxCzISc06VxvwRu8g28w= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1566923971122946.6796210869754; Tue, 27 Aug 2019 09:39:31 -0700 (PDT) Received: from localhost ([::1]:54016 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2eVF-0007sU-IF for importer@patchew.org; Tue, 27 Aug 2019 12:39:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35042) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2eQv-0003ed-1a for qemu-devel@nongnu.org; Tue, 27 Aug 2019 12:35:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i2eQt-0000KM-Nc for qemu-devel@nongnu.org; Tue, 27 Aug 2019 12:35:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64120) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i2eQq-0000IC-Gh; Tue, 27 Aug 2019 12:34:56 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D2733106E299; Tue, 27 Aug 2019 16:34:55 +0000 (UTC) Received: from localhost (unknown [10.40.205.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C6A295D772; Tue, 27 Aug 2019 16:34:53 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 27 Aug 2019 18:34:38 +0200 Message-Id: <20190827163439.16686-6-mreitz@redhat.com> In-Reply-To: <20190827163439.16686-1-mreitz@redhat.com> References: <20190827163439.16686-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Tue, 27 Aug 2019 16:34:55 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 5/6] curl: Handle success in multi_check_completion X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Background: As of cURL 7.59.0, it verifies that several functions are not called from within a callback. Among these functions is curl_multi_add_handle(). curl_read_cb() is a callback from cURL and not a coroutine. Waking up acb->co will lead to entering it then and there, which means the current request will settle and the caller (if it runs in the same coroutine) may then issue the next request. In such a case, we will enter curl_setup_preadv() effectively from within curl_read_cb(). Calling curl_multi_add_handle() will then fail and the new request will not be processed. Fix this by not letting curl_read_cb() wake up acb->co. Instead, leave the whole business of settling the AIOCB objects to curl_multi_check_completion() (which is called from our timer callback and our FD read handler, so not from any cURL callbacks). Reported-by: Natalie Gavrielov Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=3D1740193 Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz --- block/curl.c | 69 ++++++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 40 deletions(-) diff --git a/block/curl.c b/block/curl.c index bc70f39fcb..5e0cca601d 100644 --- a/block/curl.c +++ b/block/curl.c @@ -231,7 +231,6 @@ static size_t curl_read_cb(void *ptr, size_t size, size= _t nmemb, void *opaque) { CURLState *s =3D ((CURLState*)opaque); size_t realsize =3D size * nmemb; - int i; =20 trace_curl_read_cb(realsize); =20 @@ -247,32 +246,6 @@ static size_t curl_read_cb(void *ptr, size_t size, siz= e_t nmemb, void *opaque) memcpy(s->orig_buf + s->buf_off, ptr, realsize); s->buf_off +=3D realsize; =20 - for(i=3D0; iacb[i]; - - if (!acb) - continue; - - if ((s->buf_off >=3D acb->end)) { - size_t request_length =3D acb->bytes; - - qemu_iovec_from_buf(acb->qiov, 0, s->orig_buf + acb->start, - acb->end - acb->start); - - if (acb->end - acb->start < request_length) { - size_t offset =3D acb->end - acb->start; - qemu_iovec_memset(acb->qiov, offset, 0, - request_length - offset); - } - - acb->ret =3D 0; - s->acb[i] =3D NULL; - qemu_mutex_unlock(&s->s->mutex); - aio_co_wake(acb->co); - qemu_mutex_lock(&s->s->mutex); - } - } - read_end: /* curl will error out if we do not return this value */ return size * nmemb; @@ -353,13 +326,14 @@ static void curl_multi_check_completion(BDRVCURLState= *s) break; =20 if (msg->msg =3D=3D CURLMSG_DONE) { + int i; CURLState *state =3D NULL; + bool error =3D msg->data.result !=3D CURLE_OK; + curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, (char **)&state); =20 - /* ACBs for successful messages get completed in curl_read_cb = */ - if (msg->data.result !=3D CURLE_OK) { - int i; + if (error) { static int errcount =3D 100; =20 /* Don't lose the original error message from curl, since @@ -371,20 +345,35 @@ static void curl_multi_check_completion(BDRVCURLState= *s) error_report("curl: further errors suppressed"); } } + } =20 - for (i =3D 0; i < CURL_NUM_ACB; i++) { - CURLAIOCB *acb =3D state->acb[i]; + for (i =3D 0; i < CURL_NUM_ACB; i++) { + CURLAIOCB *acb =3D state->acb[i]; =20 - if (acb =3D=3D NULL) { - continue; - } + if (acb =3D=3D NULL) { + continue; + } + + if (!error) { + /* Assert that we have read all data */ + assert(state->buf_off >=3D acb->end); + + qemu_iovec_from_buf(acb->qiov, 0, + state->orig_buf + acb->start, + acb->end - acb->start); =20 - acb->ret =3D -EIO; - state->acb[i] =3D NULL; - qemu_mutex_unlock(&s->mutex); - aio_co_wake(acb->co); - qemu_mutex_lock(&s->mutex); + if (acb->end - acb->start < acb->bytes) { + size_t offset =3D acb->end - acb->start; + qemu_iovec_memset(acb->qiov, offset, 0, + acb->bytes - offset); + } } + + acb->ret =3D error ? -EIO : 0; + state->acb[i] =3D NULL; + qemu_mutex_unlock(&s->mutex); + aio_co_wake(acb->co); + qemu_mutex_lock(&s->mutex); } =20 curl_clean_state(state); --=20 2.21.0 From nobody Wed Nov 12 00:08:34 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1566924125; cv=none; d=zoho.com; s=zohoarc; b=nUiZgyPY9y05zQYoZibHCSrXGqhiwkTJvyqRiIW3tBJdHQIeqY9E31sYVvgI8hjkyXCC9GO5d7JfbvyqDN0I+ELUevr5rZDRy9XZlX9F6uU4vGOng+ggVDaVyPayMvMHV3LayxcnTLFDNXxOPJjEJ9SsAccvLccAoaNTMe2JKWw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566924125; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=j52oYeoM1cqW/aUx/sM11ZhihSdMjrVNyPbJv9LQ4D0=; b=lHHwFVC1mBy3ImCDc51Vv/TEadTKIaxa8DrVNvIdsJ+1f9vLJw1SkWXAxSLqIFoAgAGjdJ4/1y6RrObUGGop1wc1aIpIkeaAnXDfI+YSSJLDrXfAxNx6Q34GEDlRy8hArQCgaRhYZli/mN9gPjEXqjJ5qdck8KMsNn0tU8nri6c= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156692412531133.02691205361464; Tue, 27 Aug 2019 09:42:05 -0700 (PDT) Received: from localhost ([::1]:54040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2eXg-00020t-Cp for importer@patchew.org; Tue, 27 Aug 2019 12:42:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35133) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i2eR1-0003n9-Ml for qemu-devel@nongnu.org; Tue, 27 Aug 2019 12:35:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i2eR0-0000RA-Jn for qemu-devel@nongnu.org; Tue, 27 Aug 2019 12:35:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5238) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1i2eQw-0000Mk-Nm; Tue, 27 Aug 2019 12:35:02 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1237C107DD04; Tue, 27 Aug 2019 16:35:02 +0000 (UTC) Received: from localhost (unknown [10.40.205.2]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B10AA5D6B0; Tue, 27 Aug 2019 16:34:57 +0000 (UTC) From: Max Reitz To: qemu-block@nongnu.org Date: Tue, 27 Aug 2019 18:34:39 +0200 Message-Id: <20190827163439.16686-7-mreitz@redhat.com> In-Reply-To: <20190827163439.16686-1-mreitz@redhat.com> References: <20190827163439.16686-1-mreitz@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Tue, 27 Aug 2019 16:35:02 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 6/6] curl: Check curl_multi_add_handle()'s return code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-devel@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If we had done that all along, debugging would have been much simpler. (Also, I/O errors are better than hangs.) Signed-off-by: Max Reitz --- block/curl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block/curl.c b/block/curl.c index 5e0cca601d..4a7aff02a6 100644 --- a/block/curl.c +++ b/block/curl.c @@ -894,7 +894,13 @@ static void curl_setup_preadv(BlockDriverState *bs, CU= RLAIOCB *acb) trace_curl_setup_preadv(acb->bytes, start, state->range); curl_easy_setopt(state->curl, CURLOPT_RANGE, state->range); =20 - curl_multi_add_handle(s->multi, state->curl); + if (curl_multi_add_handle(s->multi, state->curl) !=3D CURLM_OK) { + state->acb[0] =3D NULL; + acb->ret =3D -EIO; + + curl_clean_state(state); + goto out; + } =20 /* Tell curl it needs to kick things off */ curl_multi_socket_action(s->multi, CURL_SOCKET_TIMEOUT, 0, &running); --=20 2.21.0