From patchwork Thu Dec 15 00:44:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 705898 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tfGMs1Pglz9t0P for ; Thu, 15 Dec 2016 12:39:53 +1100 (AEDT) Received: from localhost ([::1]:51422 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cHL1T-0001oi-4G for incoming@patchwork.ozlabs.org; Wed, 14 Dec 2016 20:39:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43336) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cHKCK-0004ii-OL for qemu-devel@nongnu.org; Wed, 14 Dec 2016 19:47:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cHKCH-0001dg-N2 for qemu-devel@nongnu.org; Wed, 14 Dec 2016 19:47:00 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:60192) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cHKCH-0001cj-DZ for qemu-devel@nongnu.org; Wed, 14 Dec 2016 19:46:57 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id uBF0hZuK130750 for ; Wed, 14 Dec 2016 19:46:56 -0500 Received: from e19.ny.us.ibm.com (e19.ny.us.ibm.com [129.33.205.209]) by mx0a-001b2d01.pphosted.com with ESMTP id 27bdkvs7cv-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 14 Dec 2016 19:46:56 -0500 Received: from localhost by e19.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 14 Dec 2016 19:46:54 -0500 Received: from d01dlp01.pok.ibm.com (9.56.250.166) by e19.ny.us.ibm.com (146.89.104.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 14 Dec 2016 19:46:51 -0500 Received: from b01cxnp23033.gho.pok.ibm.com (b01cxnp23033.gho.pok.ibm.com [9.57.198.28]) by d01dlp01.pok.ibm.com (Postfix) with ESMTP id 238B838C8039; Wed, 14 Dec 2016 19:46:51 -0500 (EST) Received: from b01ledav03.gho.pok.ibm.com (b01ledav003.gho.pok.ibm.com [9.57.199.108]) by b01cxnp23033.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id uBF0kpp019988902; Thu, 15 Dec 2016 00:46:51 GMT Received: from b01ledav03.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 30B5CB2046; Wed, 14 Dec 2016 19:46:51 -0500 (EST) Received: from localhost (unknown [9.80.108.238]) by b01ledav03.gho.pok.ibm.com (Postfix) with ESMTP id E781EB204D; Wed, 14 Dec 2016 19:46:50 -0500 (EST) From: Michael Roth To: qemu-devel@nongnu.org Date: Wed, 14 Dec 2016 18:44:50 -0600 X-Mailer: git-send-email 1.9.1 In-Reply-To: <1481762701-4587-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1481762701-4587-1-git-send-email-mdroth@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16121500-0056-0000-0000-00000237C233 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006250; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000196; SDB=6.00793944; UDB=6.00384987; IPR=6.00571750; BA=6.00004968; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013630; XFM=3.00000011; UTC=2016-12-15 00:46:53 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 16121500-0057-0000-0000-0000066CC2A8 Message-Id: <1481762701-4587-57-git-send-email-mdroth@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2016-12-14_15:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1612150008 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH 56/67] block/curl: Remember all sockets X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jeff Cody , qemu-stable@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Max Reitz For some connection types (like FTP, generally), more than one socket may be used (in FTP's case: control vs. data stream). As of commit 838ef602498b8d1985a231a06f5e328e2946a81d ("curl: Eliminate unnecessary use of curl_multi_socket_all"), we have to remember all of the sockets used by libcurl, but in fact we only did that for a single one. Since one libcurl connection may use multiple sockets, however, we have to remember them all. Cc: qemu-stable@nongnu.org Signed-off-by: Max Reitz Message-id: 20161025025431.24714-4-mreitz@redhat.com Signed-off-by: Jeff Cody (cherry picked from commit ff5ca1664af85b24a4180d595ea6873fd3deac57) Signed-off-by: Michael Roth --- block/curl.c | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/block/curl.c b/block/curl.c index f47f4e6..600d032 100644 --- a/block/curl.c +++ b/block/curl.c @@ -105,12 +105,17 @@ typedef struct CURLAIOCB { size_t end; } CURLAIOCB; +typedef struct CURLSocket { + int fd; + QLIST_ENTRY(CURLSocket) next; +} CURLSocket; + typedef struct CURLState { struct BDRVCURLState *s; CURLAIOCB *acb[CURL_NUM_ACB]; CURL *curl; - curl_socket_t sock_fd; + QLIST_HEAD(, CURLSocket) sockets; char *orig_buf; size_t buf_start; size_t buf_off; @@ -164,10 +169,27 @@ static int curl_sock_cb(CURL *curl, curl_socket_t fd, int action, { BDRVCURLState *s; CURLState *state = NULL; + CURLSocket *socket; + curl_easy_getinfo(curl, CURLINFO_PRIVATE, (char **)&state); - state->sock_fd = fd; s = state->s; + QLIST_FOREACH(socket, &state->sockets, next) { + if (socket->fd == fd) { + if (action == CURL_POLL_REMOVE) { + QLIST_REMOVE(socket, next); + g_free(socket); + } + break; + } + } + if (!socket) { + socket = g_new0(CURLSocket, 1); + socket->fd = fd; + QLIST_INSERT_HEAD(&state->sockets, socket, next); + } + socket = NULL; + DPRINTF("CURL (AIO): Sock action %d on fd %d\n", action, (int)fd); switch (action) { case CURL_POLL_IN: @@ -355,6 +377,7 @@ static void curl_multi_check_completion(BDRVCURLState *s) static void curl_multi_do(void *arg) { CURLState *s = (CURLState *)arg; + CURLSocket *socket, *next_socket; int running; int r; @@ -362,10 +385,13 @@ static void curl_multi_do(void *arg) return; } - do { - r = curl_multi_socket_action(s->s->multi, s->sock_fd, 0, &running); - } while(r == CURLM_CALL_MULTI_PERFORM); - + /* 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 = curl_multi_socket_action(s->s->multi, socket->fd, 0, &running); + } while (r == CURLM_CALL_MULTI_PERFORM); + } } static void curl_multi_read(void *arg) @@ -469,6 +495,7 @@ static CURLState *curl_init_state(BlockDriverState *bs, BDRVCURLState *s) #endif } + QLIST_INIT(&state->sockets); state->s = s; return state; @@ -478,6 +505,14 @@ static void curl_clean_state(CURLState *s) { if (s->s->multi) curl_multi_remove_handle(s->s->multi, s->curl); + + while (!QLIST_EMPTY(&s->sockets)) { + CURLSocket *socket = QLIST_FIRST(&s->sockets); + + QLIST_REMOVE(socket, next); + g_free(socket); + } + s->in_use = 0; }