From patchwork Sat Feb 3 15:39:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 868911 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KFIPTymh"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zYdNt73xnz9t0m for ; Sun, 4 Feb 2018 02:41:02 +1100 (AEDT) Received: from localhost ([::1]:43639 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ehzw4-0001wK-U9 for incoming@patchwork.ozlabs.org; Sat, 03 Feb 2018 10:41:00 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ehzur-0001hX-CI for qemu-devel@nongnu.org; Sat, 03 Feb 2018 10:39:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ehzuq-00047g-Dw for qemu-devel@nongnu.org; Sat, 03 Feb 2018 10:39:45 -0500 Received: from mail-qk0-x241.google.com ([2607:f8b0:400d:c09::241]:44464) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ehzuq-00046l-9N; Sat, 03 Feb 2018 10:39:44 -0500 Received: by mail-qk0-x241.google.com with SMTP id n188so16290637qkn.11; Sat, 03 Feb 2018 07:39:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=2YvlCWabKdL+I8FjttoOo1yKaWZ0H0Kvr+485G3eEP8=; b=KFIPTymhMhUekB+JACmWsKUjXsmepYm+507Iwsi5ePqWjJHGB6VxSn2IYbs3VAOFU8 QUixL7CYH5wpNlX4XgVpE1PGbSnHcLnBfhEK7YaPB0+Wp5ujMgMOUg2CmI+J5IO4Ej15 oMDtmU8mgkBsmvwJkbgH5kJx5Y5ao0pm/C2upFa1u4zO/4winlcXnwFMDevWLlffZs6I NH2mHfuragb/vjqYLYuAVafASPmDg+BqYDpIR6nCYM0BHIL2IwdHoIke2NoUFa754nUa Zhv3I0bb15f3r1vJb4B6wVKc1P4VWgaiQrrN7npCk0pRfNankhlx8je7sHVpU1Zf9YY+ 4XpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=2YvlCWabKdL+I8FjttoOo1yKaWZ0H0Kvr+485G3eEP8=; b=esu16z/qb5T9k1JnxEcjCp053Qi/GYZ81uwrKFzkK+dy4t2UeQ2mkPA1QX22e5LCEb cA/8Wfk0liBbaJoIR7pBB5KWSPQTHnkGwBOYExI0X05KwMpvuLMrXM5AMHU7WPTwscMV bNPmAe5VTqvCUrPquvodV9AeVvtU9A9HiP1HKo7dxzRhv7qUg7nvgqNsqFQFLbTJrYYJ mTEcUA49HF7DPsGimmuN6EZRB07u27+wrjuQydcXMkMiJpbcj8Zb/1hFdyrwgWgRaW1Z 1iu5bXtgZDIdk3Am5cdQy7guzuU9x2osLb+6g+GLRFuir9zt3rYRoyT/nJZqOTZ4WdeW 4dPQ== X-Gm-Message-State: APf1xPAZsWIberbLfXHyp78MRRIdS9kGiC7xauhEQsWReZwYJpS/yohU rZ/l2NAEoxGRAJFZH1ZdK7axsxRC X-Google-Smtp-Source: AH8x227RRUChTAullDwX0Gf/NUvUiBhWzUKmO10AAcj1Jwg8WKDVpSoz75kZjtGmzsZeSK2bffhrew== X-Received: by 10.55.139.132 with SMTP id n126mr8512628qkd.299.1517672383492; Sat, 03 Feb 2018 07:39:43 -0800 (PST) Received: from localhost.localdomain (50-205-150-222-static.hfc.comcastbusiness.net. [50.205.150.222]) by smtp.gmail.com with ESMTPSA id z35sm3193790qtz.31.2018.02.03.07.39.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 03 Feb 2018 07:39:42 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Sat, 3 Feb 2018 10:39:35 -0500 Message-Id: <20180203153935.8056-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180203153935.8056-1-pbonzini@redhat.com> References: <20180203153935.8056-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::241 Subject: [Qemu-devel] [PATCH 5/5] curl: convert to CoQueue 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: famz@redhat.com, qemu-block@nongnu.org, stefanha@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Now that CoQueues can use a QemuMutex for thread-safety, there is no need for curl to roll its own coroutine queue. Coroutines can be placed directly on the queue instead of using a list of CURLAIOCBs. Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Reviewed-by: Richard Henderson --- block/curl.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/block/curl.c b/block/curl.c index 35cf417f59..cd578d3d14 100644 --- a/block/curl.c +++ b/block/curl.c @@ -101,8 +101,6 @@ typedef struct CURLAIOCB { size_t start; size_t end; - - QSIMPLEQ_ENTRY(CURLAIOCB) next; } CURLAIOCB; typedef struct CURLSocket { @@ -138,7 +136,7 @@ typedef struct BDRVCURLState { bool accept_range; AioContext *aio_context; QemuMutex mutex; - QSIMPLEQ_HEAD(, CURLAIOCB) free_state_waitq; + CoQueue free_state_waitq; char *username; char *password; char *proxyusername; @@ -538,7 +536,6 @@ static int curl_init_state(BDRVCURLState *s, CURLState *state) /* Called with s->mutex held. */ static void curl_clean_state(CURLState *s) { - CURLAIOCB *next; int j; for (j = 0; j < CURL_NUM_ACB; j++) { assert(!s->acb[j]); @@ -556,13 +553,7 @@ static void curl_clean_state(CURLState *s) s->in_use = 0; - next = QSIMPLEQ_FIRST(&s->s->free_state_waitq); - if (next) { - QSIMPLEQ_REMOVE_HEAD(&s->s->free_state_waitq, next); - qemu_mutex_unlock(&s->s->mutex); - aio_co_wake(next->co); - qemu_mutex_lock(&s->s->mutex); - } + qemu_co_enter_next(&s->s->free_state_waitq, &s->s->mutex); } static void curl_parse_filename(const char *filename, QDict *options, @@ -784,7 +775,7 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags, } DPRINTF("CURL: Opening %s\n", file); - QSIMPLEQ_INIT(&s->free_state_waitq); + qemu_co_queue_init(&s->free_state_waitq); s->aio_context = bdrv_get_aio_context(bs); s->url = g_strdup(file); qemu_mutex_lock(&s->mutex); @@ -888,10 +879,7 @@ static void curl_setup_preadv(BlockDriverState *bs, CURLAIOCB *acb) if (state) { break; } - QSIMPLEQ_INSERT_TAIL(&s->free_state_waitq, acb, next); - qemu_mutex_unlock(&s->mutex); - qemu_coroutine_yield(); - qemu_mutex_lock(&s->mutex); + qemu_co_queue_wait(&s->free_state_waitq, &s->mutex); } if (curl_init_state(s, state) < 0) {