From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428525; cv=none; d=zohomail.com; s=zohoarc; b=CKEdr9TuWv/ZMzxTKFs26RgTTRzTlbfOfACI704zgIjF0CZ4FTXCdN6qzUdCJ3/SuFJ00FLM4TlkVQlVFgHgwF8cwF6Dd/AZTc2XFYKNxOz/E28xpqlfVNVPJ++BfAfDOq6AC6DDYpNbh7CWjB4DxMK+PprQKOizQLQiuNDlPLk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428525; h=Content-Type: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; bh=Fdb+zGGiOB4lQ4ROZ95omYLZPOSQoHCyg1PVyv+9TK4=; b=LO26gQp9r1lRcIkQrEKJEE1p3n74zijUGyAyLfb0iBprFs1Q9LR/UKvBdD0MMXtn5959sOkPxngvUgTLnKcWrrI7K+LQqRFcu5Njz2lLyfjiBQsxFClrbOcb7r2lHgJEIghYDM/6h+znvYxBXw3eR/G5YkHpjhL1uqzdalrQVmE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428525184454.03364217665387; Tue, 25 Apr 2023 06:15:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIUp-0006GH-O1; Tue, 25 Apr 2023 09:14:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUm-0006EC-Bk for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUj-0006WQ-PW for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:11 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-583-B0LD_EMgNXmIydyRHYGIuA-1; Tue, 25 Apr 2023 09:14:05 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7F42128135AA; Tue, 25 Apr 2023 13:14:05 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9D3F40C2064; Tue, 25 Apr 2023 13:14:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428449; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fdb+zGGiOB4lQ4ROZ95omYLZPOSQoHCyg1PVyv+9TK4=; b=Kv8NbDqDVc28IX0paQxxWODIx5pjcX+zeka7CSS7nE2lip6wk1rNcSSv73kBOGsvIM13iP Zy95wxOczPiQqborPUXiYWyvU04BcD2Db3O2HGDX+KO2RUvGyI08So5AgQYcNMH0vN1K1W Sb37Xu/YNNLKpXBRq37RzntCD17ukLw= X-MC-Unique: B0LD_EMgNXmIydyRHYGIuA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 01/25] block: make BlockBackend->quiesce_counter atomic Date: Tue, 25 Apr 2023 15:13:35 +0200 Message-Id: <20230425131359.259007-2-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428527156100007 From: Stefan Hajnoczi The main loop thread increments/decrements BlockBackend->quiesce_counter when drained sections begin/end. The counter is read in the I/O code path. Therefore this field is used to communicate between threads without a lock. Acquire/release are not necessary because the BlockBackend->in_flight counter already uses sequentially consistent accesses and running I/O requests hold that counter when blk_wait_while_drained() is called. qatomic_read() can be used. Use qatomic_fetch_inc()/qatomic_fetch_dec() for modifications even though sequentially consistent atomic accesses are not strictly required here. They are, however, nicer to read than multiple calls to qatomic_read() and qatomic_set(). Since beginning and ending drain is not a hot path the extra cost doesn't matter. Signed-off-by: Stefan Hajnoczi Message-Id: <20230307210427.269214-2-stefanha@redhat.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/block-backend.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 5566ea059d..2ae768f24d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -80,7 +80,7 @@ struct BlockBackend { NotifierList remove_bs_notifiers, insert_bs_notifiers; QLIST_HEAD(, BlockBackendAioNotifier) aio_notifiers; =20 - int quiesce_counter; + int quiesce_counter; /* atomic: written under BQL, read by other threa= ds */ CoQueue queued_requests; bool disable_request_queuing; =20 @@ -1057,7 +1057,7 @@ void blk_set_dev_ops(BlockBackend *blk, const BlockDe= vOps *ops, blk->dev_opaque =3D opaque; =20 /* Are we currently quiesced? Should we enforce this right now? */ - if (blk->quiesce_counter && ops && ops->drained_begin) { + if (qatomic_read(&blk->quiesce_counter) && ops && ops->drained_begin) { ops->drained_begin(opaque); } } @@ -1271,7 +1271,7 @@ static void coroutine_fn blk_wait_while_drained(Block= Backend *blk) { assert(blk->in_flight > 0); =20 - if (blk->quiesce_counter && !blk->disable_request_queuing) { + if (qatomic_read(&blk->quiesce_counter) && !blk->disable_request_queui= ng) { blk_dec_in_flight(blk); qemu_co_queue_wait(&blk->queued_requests, NULL); blk_inc_in_flight(blk); @@ -2595,7 +2595,7 @@ static void blk_root_drained_begin(BdrvChild *child) BlockBackend *blk =3D child->opaque; ThrottleGroupMember *tgm =3D &blk->public.throttle_group_member; =20 - if (++blk->quiesce_counter =3D=3D 1) { + if (qatomic_fetch_inc(&blk->quiesce_counter) =3D=3D 0) { if (blk->dev_ops && blk->dev_ops->drained_begin) { blk->dev_ops->drained_begin(blk->dev_opaque); } @@ -2613,7 +2613,7 @@ static bool blk_root_drained_poll(BdrvChild *child) { BlockBackend *blk =3D child->opaque; bool busy =3D false; - assert(blk->quiesce_counter); + assert(qatomic_read(&blk->quiesce_counter)); =20 if (blk->dev_ops && blk->dev_ops->drained_poll) { busy =3D blk->dev_ops->drained_poll(blk->dev_opaque); @@ -2624,12 +2624,12 @@ static bool blk_root_drained_poll(BdrvChild *child) static void blk_root_drained_end(BdrvChild *child) { BlockBackend *blk =3D child->opaque; - assert(blk->quiesce_counter); + assert(qatomic_read(&blk->quiesce_counter)); =20 assert(blk->public.throttle_group_member.io_limits_disabled); qatomic_dec(&blk->public.throttle_group_member.io_limits_disabled); =20 - if (--blk->quiesce_counter =3D=3D 0) { + if (qatomic_fetch_dec(&blk->quiesce_counter) =3D=3D 1) { if (blk->dev_ops && blk->dev_ops->drained_end) { blk->dev_ops->drained_end(blk->dev_opaque); } --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428770; cv=none; d=zohomail.com; s=zohoarc; b=OlesGRXB9OyTr/+YhJTSgxA9UTVCrVxtGRAA/On8SNWXAA0RlindpX/OiQezxtpae0/9KIAxefwg1gYWRgz33nunMC72AclOlc87xe1USDGZom2sTgliIoGGvOyCRjy2x+d2xP4+m/qaJKLyVwRKLHY19fxBV7wqMhBX1UDmELg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428770; h=Content-Type: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; bh=phTlyt1Zifgy1Lq/4J4gJlUYJ7MjcBmXuKb6aHZq4kM=; b=gPxvNNFfal31n0XuO53OqKZD/YUTUs/e43nvvE9/8xmkzvxNVp1d36EAqI8NS6oTsK5Ofwx2aqGfZh/ZkIG1b6XGnklcdQalzeiIimzEBtc/Eo+ynIP09JY1hBgX29jcYrDSIhUYueboNMXxL7IutI4Mrz/OduIHCetc+bVTIK0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428770404780.381147503578; Tue, 25 Apr 2023 06:19:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIUt-0006Jb-7m; Tue, 25 Apr 2023 09:14:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUn-0006F5-Ip for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUl-0006Ws-M4 for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:13 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-593-tG3p4wBUO424H20seJ4CLg-1; Tue, 25 Apr 2023 09:14:08 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6FFC438221DD; Tue, 25 Apr 2023 13:14:06 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id B592D40C2064; Tue, 25 Apr 2023 13:14:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428450; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=phTlyt1Zifgy1Lq/4J4gJlUYJ7MjcBmXuKb6aHZq4kM=; b=d1g/USAJ3n/xnCPCreWNCmzDs3Q+UmdWyXCN5wcN0zoXKxJK7giEkd+pDcNyhILHke4Y8h c8ITw7f2HTaJToZCrcULd8F042/HfsEn40vwM1+eUzY4AjWmACIbVDDfgvFHavUKMmhVFV 7WVOnlSaWMf9Gkg+ZJgwDBPZjGUfToQ= X-MC-Unique: tG3p4wBUO424H20seJ4CLg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 02/25] block: make BlockBackend->disable_request_queuing atomic Date: Tue, 25 Apr 2023 15:13:36 +0200 Message-Id: <20230425131359.259007-3-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428770719100001 From: Stefan Hajnoczi This field is accessed by multiple threads without a lock. Use explicit qatomic_read()/qatomic_set() calls. There is no need for acquire/release because blk_set_disable_request_queuing() doesn't provide any guarantees (it helps that it's used at BlockBackend creation time and not when there is I/O in flight). Signed-off-by: Stefan Hajnoczi Reviewed-by: Hanna Czenczek Message-Id: <20230307210427.269214-3-stefanha@redhat.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/block-backend.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 2ae768f24d..8552b6dfd0 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -82,7 +82,7 @@ struct BlockBackend { =20 int quiesce_counter; /* atomic: written under BQL, read by other threa= ds */ CoQueue queued_requests; - bool disable_request_queuing; + bool disable_request_queuing; /* atomic */ =20 VMChangeStateEntry *vmsh; bool force_allow_inactivate; @@ -1232,7 +1232,7 @@ void blk_set_allow_aio_context_change(BlockBackend *b= lk, bool allow) void blk_set_disable_request_queuing(BlockBackend *blk, bool disable) { IO_CODE(); - blk->disable_request_queuing =3D disable; + qatomic_set(&blk->disable_request_queuing, disable); } =20 static int coroutine_fn GRAPH_RDLOCK @@ -1271,7 +1271,8 @@ static void coroutine_fn blk_wait_while_drained(Block= Backend *blk) { assert(blk->in_flight > 0); =20 - if (qatomic_read(&blk->quiesce_counter) && !blk->disable_request_queui= ng) { + if (qatomic_read(&blk->quiesce_counter) && + !qatomic_read(&blk->disable_request_queuing)) { blk_dec_in_flight(blk); qemu_co_queue_wait(&blk->queued_requests, NULL); blk_inc_in_flight(blk); --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428535; cv=none; d=zohomail.com; s=zohoarc; b=SrIBx9ls7tasY5gWgqB5fAR5k59NgpCm3ztm5V/swp2oacnbN55WIHwQ7Xar6kxijCq2i+dOLbYYZdCfjMy4BZyVx0toxtqjDKYOSkTXB3hpqLbt/xKa+qtSXTEWPQvjTKSogkMWUaqO6LoRmXPG9QT4YLl4fa0Lq5nqozl/f1A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428535; 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; bh=nShfLOl8CclmcnUxnQ0bFrxy8Xke8kt4MSTLZqnK6MA=; b=GeLZLq34eaAUoxDf06k+6O/kExS0shaQAQnsMBq3B/n+x62bRftUnPww43Sq805ds3UEgIaSZirH4tOQY9RAi1MnGxYKrIQ6/AssPxccWrTh6Vn7mDIqlob9ehZMtA8SJ0NQ0uBE8ZfVRiz4Gx197s1mbqmXgxUR7HOm/AsXaQc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428535754227.3216987715398; Tue, 25 Apr 2023 06:15:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIV6-0006Mq-FU; Tue, 25 Apr 2023 09:14:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUo-0006FD-0D for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUm-0006XD-Eh for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:13 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-463-1m8eqFn2MbSvT4Dc_9SpKg-1; Tue, 25 Apr 2023 09:14:07 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 65A7C38221C4; Tue, 25 Apr 2023 13:14:07 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB98540C2064; Tue, 25 Apr 2023 13:14:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428451; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nShfLOl8CclmcnUxnQ0bFrxy8Xke8kt4MSTLZqnK6MA=; b=hmmaYpmRtWFaoaqqF+Ao4qBOs/+KFuGEV8nesphLJFgkLvO6x4iwutKYatqKrk3iMLGHgZ 38zFByYl2LBUhCp3pPnD4wIUU5Kt7Uq/j2bHJrgAICQ4OSx1DY8bX/VD4Y7x8dvdxcSQJH 2upP9itCCj8bMZ37sEHPbyEKKBnGRf4= X-MC-Unique: 1m8eqFn2MbSvT4Dc_9SpKg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 03/25] block: protect BlockBackend->queued_requests with a lock Date: Tue, 25 Apr 2023 15:13:37 +0200 Message-Id: <20230425131359.259007-4-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428537199100001 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi The CoQueue API offers thread-safety via the lock argument that qemu_co_queue_wait() and qemu_co_enter_next() take. BlockBackend currently does not make use of the lock argument. This means that multiple threads submitting I/O requests can corrupt the CoQueue's QSIMPLEQ. Add a QemuMutex and pass it to CoQueue APIs so that the queue is protected. While we're at it, also assert that the queue is empty when the BlockBackend is deleted. Signed-off-by: Stefan Hajnoczi Reviewed-by: Hanna Czenczek Message-Id: <20230307210427.269214-4-stefanha@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/block-backend.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 8552b6dfd0..47e006c645 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -81,6 +81,7 @@ struct BlockBackend { QLIST_HEAD(, BlockBackendAioNotifier) aio_notifiers; =20 int quiesce_counter; /* atomic: written under BQL, read by other threa= ds */ + QemuMutex queued_requests_lock; /* protects queued_requests */ CoQueue queued_requests; bool disable_request_queuing; /* atomic */ =20 @@ -368,6 +369,7 @@ BlockBackend *blk_new(AioContext *ctx, uint64_t perm, u= int64_t shared_perm) =20 block_acct_init(&blk->stats); =20 + qemu_mutex_init(&blk->queued_requests_lock); qemu_co_queue_init(&blk->queued_requests); notifier_list_init(&blk->remove_bs_notifiers); notifier_list_init(&blk->insert_bs_notifiers); @@ -485,6 +487,8 @@ static void blk_delete(BlockBackend *blk) assert(QLIST_EMPTY(&blk->remove_bs_notifiers.notifiers)); assert(QLIST_EMPTY(&blk->insert_bs_notifiers.notifiers)); assert(QLIST_EMPTY(&blk->aio_notifiers)); + assert(qemu_co_queue_empty(&blk->queued_requests)); + qemu_mutex_destroy(&blk->queued_requests_lock); QTAILQ_REMOVE(&block_backends, blk, link); drive_info_del(blk->legacy_dinfo); block_acct_cleanup(&blk->stats); @@ -1273,9 +1277,16 @@ static void coroutine_fn blk_wait_while_drained(Bloc= kBackend *blk) =20 if (qatomic_read(&blk->quiesce_counter) && !qatomic_read(&blk->disable_request_queuing)) { + /* + * Take lock before decrementing in flight counter so main loop th= read + * waits for us to enqueue ourselves before it can leave the drain= ed + * section. + */ + qemu_mutex_lock(&blk->queued_requests_lock); blk_dec_in_flight(blk); - qemu_co_queue_wait(&blk->queued_requests, NULL); + qemu_co_queue_wait(&blk->queued_requests, &blk->queued_requests_lo= ck); blk_inc_in_flight(blk); + qemu_mutex_unlock(&blk->queued_requests_lock); } } =20 @@ -2634,9 +2645,12 @@ static void blk_root_drained_end(BdrvChild *child) if (blk->dev_ops && blk->dev_ops->drained_end) { blk->dev_ops->drained_end(blk->dev_opaque); } - while (qemu_co_enter_next(&blk->queued_requests, NULL)) { + qemu_mutex_lock(&blk->queued_requests_lock); + while (qemu_co_enter_next(&blk->queued_requests, + &blk->queued_requests_lock)) { /* Resume all queued requests */ } + qemu_mutex_unlock(&blk->queued_requests_lock); } } =20 --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428505; cv=none; d=zohomail.com; s=zohoarc; b=jwpDNteoaFl5MuS5GWYisFxmT+Junj9ys7dycaXyuS2p9cQPaHo8ai69IptG/LuQKt5BBrXHOywYWW84v6QzLUn5dzANMElRwa98leYbMaCI8MbF7sRNOoO3AuxJKIZrLehfX8PFEP5D4QV2pHFx1btfC/nctAtJe6ojIVhWg/Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428505; 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; bh=wD7WjN5MqtLw+Ywbd0kEmPtkDFlNLgkgcildmGprRrM=; b=aVv4tTz6pm/0zlnwHuXlWiPnM1CWVpi2kQnwgKcWa4fLoTO0jw/bqHbw0eV4BqpoPDHGifMRtyAUTiUZHyvzgKDGRq8Sr/XnA5y7Dg1+HvtnzBZmdS2pi9KK181BusjhT1fFf/P3jI12TWiMs0o2jaPPi8IJ2fJ+zHKvcRKw6No= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428505252580.596918190847; Tue, 25 Apr 2023 06:15:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIVH-0006Vi-ED; Tue, 25 Apr 2023 09:14:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUo-0006FM-Kc for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:15 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUm-0006XM-LM for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:14 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-235-iDzd8UDMNcq7A1Bvtxbzdg-1; Tue, 25 Apr 2023 09:14:08 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 57F128828D2; Tue, 25 Apr 2023 13:14:08 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9CF9640C2064; Tue, 25 Apr 2023 13:14:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428452; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wD7WjN5MqtLw+Ywbd0kEmPtkDFlNLgkgcildmGprRrM=; b=DXCf8jUPWwQWTRuko+HoH3VQJo5whbvahOgtCdpz4A5pMewJDeTTu5B9PL+LNj0b8YUfXg t3s74Syq53gu7mMxnLz8l49j2m/sfmG9gmJAYg9KVJlvQmsV9wjlPJkwlHvdfvXGalFfJn tZdkVWnSlka0u693qOHDt/0gwckPgv8= X-MC-Unique: iDzd8UDMNcq7A1Bvtxbzdg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 04/25] block: don't acquire AioContext lock in bdrv_drain_all() Date: Tue, 25 Apr 2023 15:13:38 +0200 Message-Id: <20230425131359.259007-5-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428505977100001 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi There is no need for the AioContext lock in bdrv_drain_all() because nothing in AIO_WAIT_WHILE() needs the lock and the condition is atomic. AIO_WAIT_WHILE_UNLOCKED() has no use for the AioContext parameter other than performing a check that is nowadays already done by the GLOBAL_STATE_CODE()/IO_CODE() macros. Set the ctx argument to NULL here to help us keep track of all converted callers. Eventually all callers will have been converted and then the argument can be dropped entirely. Reviewed-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi Message-Id: <20230309190855.414275-2-stefanha@redhat.com> Reviewed-by: Kevin Wolf Reviewed-by: Wilfred Mallawa Signed-off-by: Kevin Wolf --- block/block-backend.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 47e006c645..fc530ded6a 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1874,14 +1874,8 @@ void blk_drain_all(void) bdrv_drain_all_begin(); =20 while ((blk =3D blk_all_next(blk)) !=3D NULL) { - AioContext *ctx =3D blk_get_aio_context(blk); - - aio_context_acquire(ctx); - /* We may have -ENOMEDIUM completions in flight */ - AIO_WAIT_WHILE(ctx, qatomic_read(&blk->in_flight) > 0); - - aio_context_release(ctx); + AIO_WAIT_WHILE_UNLOCKED(NULL, qatomic_read(&blk->in_flight) > 0); } =20 bdrv_drain_all_end(); --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428783; cv=none; d=zohomail.com; s=zohoarc; b=M4C8otb3dzXkSTyDgI0OqZYOS4HbrXQJX8th4DiUpgZxER2//J87Z+yaFLWNew/d7ifJSyyJKWwk5SljJeTbbwRTJvK2xwejlc3VSFrT+lhTw/GIdWKbndNDqHyWzY2OSsjI3KZUtt4T5MpT4KhFqSi/wJi/7agwT6717DpQx/Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428783; h=Content-Type: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; bh=Tq4fo0VI2Z5THQOCCzgyYxvKowZlVbLpV7a1Dt60HJM=; b=Ls6wLbiVgJ1S0qLG7IgW/I16REKO3VmTXtKyCCx/bV8gpuu/uD9rE8vGjOF8Or/liXjwH5Uz6s7bO8MCWE88ImkhXdm6C743z48FpLbTWwbp0lqVfDa+3LoOJ5DCrhPYfiEd57h2A08pcrnT1uZGTvo461Yej1YuAJw5UpHWAiE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428783365423.89561741055434; Tue, 25 Apr 2023 06:19:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIWh-0008Mw-BF; Tue, 25 Apr 2023 09:16:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVJ-0006c7-3Y for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006bW-0J for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:44 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-645-3-06oF1cNEi5uxjPpMflxA-1; Tue, 25 Apr 2023 09:14:09 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4780E857FB9; Tue, 25 Apr 2023 13:14:09 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E16240C2064; Tue, 25 Apr 2023 13:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428464; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Tq4fo0VI2Z5THQOCCzgyYxvKowZlVbLpV7a1Dt60HJM=; b=ZkktZZMaNxfVvB5A8HGpV+fJV+tiohCmAdmBN7Q35KK4676+Mz9uPUlSHMNiKrCw5M4phi uxgn9RBvM5Otgn8RU5UEYm4q11YoF8hbMc5k7QZ0gN1p+zO/yEXte89J8nhRxVZP0kgpqe JxaBtQFcyMtAsF8v9pHUaddiPtQ5vCI= X-MC-Unique: 3-06oF1cNEi5uxjPpMflxA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 05/25] block: convert blk_exp_close_all_type() to AIO_WAIT_WHILE_UNLOCKED() Date: Tue, 25 Apr 2023 15:13:39 +0200 Message-Id: <20230425131359.259007-6-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428784996100001 From: Stefan Hajnoczi There is no change in behavior. Switch to AIO_WAIT_WHILE_UNLOCKED() instead of AIO_WAIT_WHILE() to document that this code has already been audited and converted. The AioContext argument is already NULL so aio_context_release() is never called anyway. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi Message-Id: <20230309190855.414275-3-stefanha@redhat.com> Reviewed-by: Wilfred Mallawa Signed-off-by: Kevin Wolf --- block/export/export.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/export/export.c b/block/export/export.c index 28a91c9c42..e3fee60611 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -306,7 +306,7 @@ void blk_exp_close_all_type(BlockExportType type) blk_exp_request_shutdown(exp); } =20 - AIO_WAIT_WHILE(NULL, blk_exp_has_type(type)); + AIO_WAIT_WHILE_UNLOCKED(NULL, blk_exp_has_type(type)); } =20 void blk_exp_close_all(void) --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428538; cv=none; d=zohomail.com; s=zohoarc; b=h9DYxeMGjJzsBlqLnlVc2YVuzo9YEDu/mvjbbXllZ556DZgU6vttoKshZpil5CUgxL8nRtA9dHpFMGxxjPQTjfM4tj5LOeemcPJcdKrvpXBwM62sPqxeWqRGTDA0CIAWjGcW4HwQbhQGRUbV3cJ3j/cFTfSLJNqZyaYM3yhRdrM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428538; h=Content-Type: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; bh=bKQLVWSHThtVZrDboUZcqCzd2/g4SHW9pEqs0RAjMd8=; b=cP2vT5iIIPpE03DCPE5z1DroOX6Vf8lf5tMIriBec6rSMlSldlr0QTJHa3EgOEatTmzI+KR4cStV9jSvIaZryg/i2NhRXlAMtSNH2L2AdUupUdAwkkh+aueqZYyaxKF7JK8daQaiiNUNnZUdhx6ZiNnpAcb/t1D+leyPPlgN3qo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168242853836240.90374802469353; Tue, 25 Apr 2023 06:15:38 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIVJ-0006dE-UR; Tue, 25 Apr 2023 09:14:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUq-0006H6-Mi for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUp-0006YW-1w for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:16 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-167-II83OfLyOXiYxAuJBcxnwQ-1; Tue, 25 Apr 2023 09:14:10 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 372CB38221CF; Tue, 25 Apr 2023 13:14:10 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DA7F40C2064; Tue, 25 Apr 2023 13:14:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428454; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bKQLVWSHThtVZrDboUZcqCzd2/g4SHW9pEqs0RAjMd8=; b=hnjr6lRLRmPaM8KrbR3xHxdiz8AHxUUUFuBGZhtIbsXLk22ZBkhoZgOpl0CIAl5dVp0Dl1 QSGz5/Wh025vUFLz3MlL/y+YO0Z8fkpPr/nQTSEHrlhU+6tsN7oHXaNJjIVQRi/ubhQkdp zS+7+tEaj5N+qveJbI+PD/6/dw7TnVo= X-MC-Unique: II83OfLyOXiYxAuJBcxnwQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 06/25] block: convert bdrv_graph_wrlock() to AIO_WAIT_WHILE_UNLOCKED() Date: Tue, 25 Apr 2023 15:13:40 +0200 Message-Id: <20230425131359.259007-7-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428539242100005 From: Stefan Hajnoczi The following conversion is safe and does not change behavior: GLOBAL_STATE_CODE(); ... - AIO_WAIT_WHILE(qemu_get_aio_context(), ...); + AIO_WAIT_WHILE_UNLOCKED(NULL, ...); Since we're in GLOBAL_STATE_CODE(), qemu_get_aio_context() is our home thread's AioContext. Thus AIO_WAIT_WHILE() does not unlock the AioContext: if (ctx_ && in_aio_context_home_thread(ctx_)) { \ while ((cond)) { \ aio_poll(ctx_, true); \ waited_ =3D true; \ } \ And that means AIO_WAIT_WHILE_UNLOCKED(NULL, ...) can be substituted. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi Message-Id: <20230309190855.414275-4-stefanha@redhat.com> Reviewed-by: Wilfred Mallawa Signed-off-by: Kevin Wolf --- block/graph-lock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/graph-lock.c b/block/graph-lock.c index 454c31e691..639526608f 100644 --- a/block/graph-lock.c +++ b/block/graph-lock.c @@ -127,7 +127,7 @@ void bdrv_graph_wrlock(void) * reader lock. */ qatomic_set(&has_writer, 0); - AIO_WAIT_WHILE(qemu_get_aio_context(), reader_count() >=3D 1); + AIO_WAIT_WHILE_UNLOCKED(NULL, reader_count() >=3D 1); qatomic_set(&has_writer, 1); =20 /* --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428492; cv=none; d=zohomail.com; s=zohoarc; b=HeQBOoQ9Lp/mzUjw7URRV90/wFIOxHh0Rb21jIs/UTSPFYztg/jqNYPSOQ+oNY9+hexlIKIfx7a4wV4r7v+muh163M423tJZTRpTCm/uVuFVQclcwabTrHilJo64R4cfeH4B2CFIyxXOiFj+9byS1PtyvdXUDxYhLogT/IjLTPM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428492; h=Content-Type: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; bh=ZRjiibhAsX+fubqXrgWhtGlA/1vTIs+dT1Acdr852Hk=; b=dYni5svcD4cecvA7Ct12lCMjXWhIY15FFmsOyADEyOJP69FRNMKX0rYqB2qd9MvQZIiX/FLy4j39BFkokjrDGQ2lmhezYtRQ3OVqsMtXMRzYRBkfSV96ZW3SyydpPtbtn6YfW5dgwxlb9g9Hqb/wH+uSdIvNpzIPaR9atWR35Dw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16824284920798.78283741858138; Tue, 25 Apr 2023 06:14:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIV6-0006Mj-FR; Tue, 25 Apr 2023 09:14:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUr-0006HP-Cf for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUp-0006Yh-LQ for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:17 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-18-Xu8EeL0QNYywdtvNIjthsw-1; Tue, 25 Apr 2023 09:14:11 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 27C96857F81; Tue, 25 Apr 2023 13:14:11 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DE3940C2064; Tue, 25 Apr 2023 13:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428454; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZRjiibhAsX+fubqXrgWhtGlA/1vTIs+dT1Acdr852Hk=; b=Ut4V/VrBDL/rX5+kgr7hlOtE6n3eSJySMFbH7DbNb+de513bsce/CZ/MULphm0tlN4eyni eoRzhhej2DqLSOZ+7doeOhvbf5y7qvBQGKT9+mY6NxEZpc+g906vYOw8PTxOadJ2+dOJlV O3ciyrCRZ6oHwH/nsvoDMHEcDRVSUnQ= X-MC-Unique: Xu8EeL0QNYywdtvNIjthsw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 07/25] block: convert bdrv_drain_all_begin() to AIO_WAIT_WHILE_UNLOCKED() Date: Tue, 25 Apr 2023 15:13:41 +0200 Message-Id: <20230425131359.259007-8-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428493118100001 From: Stefan Hajnoczi Since the AioContext argument was already NULL, AIO_WAIT_WHILE() was never going to unlock the AioContext. Therefore it is possible to replace AIO_WAIT_WHILE() with AIO_WAIT_WHILE_UNLOCKED(). Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi Message-Id: <20230309190855.414275-5-stefanha@redhat.com> Reviewed-by: Wilfred Mallawa Signed-off-by: Kevin Wolf --- block/io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/io.c b/block/io.c index 2e267a85ab..6fa1993374 100644 --- a/block/io.c +++ b/block/io.c @@ -524,7 +524,7 @@ void bdrv_drain_all_begin(void) bdrv_drain_all_begin_nopoll(); =20 /* Now poll the in-flight requests */ - AIO_WAIT_WHILE(NULL, bdrv_drain_all_poll()); + AIO_WAIT_WHILE_UNLOCKED(NULL, bdrv_drain_all_poll()); =20 while ((bs =3D bdrv_next_all_states(bs))) { bdrv_drain_assert_idle(bs); --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428720; cv=none; d=zohomail.com; s=zohoarc; b=HmITIJGIyHzhtQvQHMy0S0E+zDB9JM0kmpSjzjmWS5ZqdlZ4vvQxOZ7CYKATHKesrO56lD2HPzRBUytC3yKSHEwN5LnpmVBYa9SQJNiQPrKrqvaC9B7Am4MV/XR12angp7P/X1c5nfpwyU2yRFTaJtvARccssQ2txnT6fX6fxQQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428720; h=Content-Type: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; bh=WZzjOQjr4EGJGYSIGh5NZ6SmuS59Q02T1jtutgDaXvU=; b=SLH43NnBjGZc+2mhWm0UGz7w2BHkjyt1IJyBl1K91U0h2UG4IkvXGqLORpo18b3l80XXdy7+hcy4G6k6pmculqXHbZibHRhfiZiXMCGVXjg/vOdN00AYCOVdmBr6fedQyhwzLGa/bw4SHmmhV2jFDDX4Xn28Bm3HGVqxguVr2cM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428720704651.7119724114641; Tue, 25 Apr 2023 06:18:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIVE-0006Oi-RF; Tue, 25 Apr 2023 09:14:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUq-0006H5-CZ for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:17 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUo-0006YL-LY for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:15 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-646-I3w3NSFjO-Ou95LxWV529Q-1; Tue, 25 Apr 2023 09:14:12 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 17875858F09; Tue, 25 Apr 2023 13:14:12 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5EA9840C2064; Tue, 25 Apr 2023 13:14:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428453; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WZzjOQjr4EGJGYSIGh5NZ6SmuS59Q02T1jtutgDaXvU=; b=Z1dqRRcaKVWFVqE1mxTiW0+/ssBisqiE/2837ptkWa2y1mvG5NE+M4E+OVVnyCV0nw+5ce n0sRUu8yimhdFkeLox40aJjillh/6G+7Ds3uyMPLcat5FWTqCQ/jotaMpz6co2ZC3j07YD MYRtfv+h2er4SF0QNgGQQcgstGHpdVw= X-MC-Unique: I3w3NSFjO-Ou95LxWV529Q-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 08/25] hmp: convert handle_hmp_command() to AIO_WAIT_WHILE_UNLOCKED() Date: Tue, 25 Apr 2023 15:13:42 +0200 Message-Id: <20230425131359.259007-9-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428722737100003 From: Stefan Hajnoczi The HMP monitor runs in the main loop thread. Calling AIO_WAIT_WHILE(qemu_get_aio_context(), ...) from the main loop thread is equivalent to AIO_WAIT_WHILE_UNLOCKED(NULL, ...) because neither unlocks the AioContext and the latter's assertion that we're in the main loop succeeds. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Markus Armbruster Reviewed-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi Message-Id: <20230309190855.414275-6-stefanha@redhat.com> Reviewed-by: Wilfred Mallawa Signed-off-by: Kevin Wolf --- monitor/hmp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monitor/hmp.c b/monitor/hmp.c index fee410362f..5cab56d355 100644 --- a/monitor/hmp.c +++ b/monitor/hmp.c @@ -1167,7 +1167,7 @@ void handle_hmp_command(MonitorHMP *mon, const char *= cmdline) Coroutine *co =3D qemu_coroutine_create(handle_hmp_command_co, &da= ta); monitor_set_cur(co, &mon->common); aio_co_enter(qemu_get_aio_context(), co); - AIO_WAIT_WHILE(qemu_get_aio_context(), !data.done); + AIO_WAIT_WHILE_UNLOCKED(NULL, !data.done); } =20 qobject_unref(qdict); --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428524; cv=none; d=zohomail.com; s=zohoarc; b=g46q7Efxx9qYmmVnT61H8gWuppchXkhlXxg/bFNxg1RzabQ7plYDBidOC2A0rSBjEUy7OptH7E2b2F9gXeKdlTplVsZPOFHWmrQXtF5M9tyqWZEe8sytubSOLmFbIn73ller8z9A/b4HPwpJGbNNBzgerl4j8BMPWjRXSrZradE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428524; h=Content-Type: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; bh=+a0Om1pyX5kchh5KIhHakz5JJTDaGPGmUIzribKhxkw=; b=jJna0vOGKYrpgMIj5unW+Q3p6H4q2RchdX0B+xQeDAOz+o0A9ssQ+fCLKyIaEQAtOMnIJKg32qGiacCqpYfrs/gjX9/NoS37TUC6xWmugPUhRgdCB36d4Jp1TPhTX5lKYV+chFnXlUQe3KMHTLwyFb57cFateiZrju5CnQYPKR0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428524517550.8974967807015; Tue, 25 Apr 2023 06:15:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIVd-0006r4-6q; Tue, 25 Apr 2023 09:15:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUt-0006Ko-HA for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUr-0006ZX-Ri for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:19 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-624-KrE7a0f7Naut9KFcFf7Rog-1; Tue, 25 Apr 2023 09:14:13 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 08E13101A49E; Tue, 25 Apr 2023 13:14:13 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DBD540C2064; Tue, 25 Apr 2023 13:14:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428457; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+a0Om1pyX5kchh5KIhHakz5JJTDaGPGmUIzribKhxkw=; b=CCF2gE/FvNFPZF4c1fb6YKKpMLKJETi0rEV6uMEpTXPCm/YbYqSOjk9APmOCBvwre3SS4o +6q+E2FLBf4Yii/11FXO/0rrW/FXueEeHfzj6eZHitbol2Z2o4lI7y4xb4YF3crENl9c/A qLQVz6LqDV+LpVtmXj1hfqvQQVYBjQg= X-MC-Unique: KrE7a0f7Naut9KFcFf7Rog-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 09/25] monitor: convert monitor_cleanup() to AIO_WAIT_WHILE_UNLOCKED() Date: Tue, 25 Apr 2023 15:13:43 +0200 Message-Id: <20230425131359.259007-10-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428525651100001 From: Stefan Hajnoczi monitor_cleanup() is called from the main loop thread. Calling AIO_WAIT_WHILE(qemu_get_aio_context(), ...) from the main loop thread is equivalent to AIO_WAIT_WHILE_UNLOCKED(NULL, ...) because neither unlocks the AioContext and the latter's assertion that we're in the main loop succeeds. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Tested-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Markus Armbruster Reviewed-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi Message-Id: <20230309190855.414275-7-stefanha@redhat.com> Reviewed-by: Wilfred Mallawa Signed-off-by: Kevin Wolf --- monitor/monitor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monitor/monitor.c b/monitor/monitor.c index 8dc96f6af9..602535696c 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -666,7 +666,7 @@ void monitor_cleanup(void) * We need to poll both qemu_aio_context and iohandler_ctx to make * sure that the dispatcher coroutine keeps making progress and * eventually terminates. qemu_aio_context is automatically - * polled by calling AIO_WAIT_WHILE on it, but we must poll + * polled by calling AIO_WAIT_WHILE_UNLOCKED on it, but we must poll * iohandler_ctx manually. * * Letting the iothread continue while shutting down the dispatcher @@ -679,7 +679,7 @@ void monitor_cleanup(void) aio_co_wake(qmp_dispatcher_co); } =20 - AIO_WAIT_WHILE(qemu_get_aio_context(), + AIO_WAIT_WHILE_UNLOCKED(NULL, (aio_poll(iohandler_get_aio_context(), false), qatomic_mb_read(&qmp_dispatcher_co_busy))); =20 --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428843; cv=none; d=zohomail.com; s=zohoarc; b=XurfeuoXHrlAn9FzwtmMaRt3b/9CT4IbLrDxpTFFW52EBNtv+fCgDeLL2pQgR7/rZ+aRf2uqnWsWRhZWVbpfp62Cmkh7s0BtEKiFRLi45hEXNUg7RmgUR5aI9dx1JU7ZnOtASnb1liJBE4cEGDsArqN+RHLQpWCpOw3OS54IKJU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428843; h=Content-Type: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; bh=c8FGnLv9hOieBHK1nF0Jh6FzEm+T4TuP6lDC0AACalE=; b=G/SLPxiYJqqyAEdW+SjW0XV/lwUd55QV0xZjmfbh7OAmK8vAhZco+1zeCwP0/BnyAgdfAVYuHTPPfAtwMRnqun9qHOlRau2O9oNvRVEhnxI7Dp2A5SWtahCfuoiD9YaTZ1CeHm3bJ1sQnnAjKHcWerJy4l7S1kAbgE2sS9F41u0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428843752653.2928099181499; Tue, 25 Apr 2023 06:20:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIVK-0006dh-0f; Tue, 25 Apr 2023 09:14:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUt-0006Kv-Kl for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:19 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUs-0006Zk-6H for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:19 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-267-qBwxS0IrNziQ0FyuBzCfgQ-1; Tue, 25 Apr 2023 09:14:14 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EBC2A185A78B; Tue, 25 Apr 2023 13:14:13 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3EBDE40C201F; Tue, 25 Apr 2023 13:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428457; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c8FGnLv9hOieBHK1nF0Jh6FzEm+T4TuP6lDC0AACalE=; b=AVUpIRmJES4wixQgU6cfHmX8sAd33d3BZ2mwwrvDKY3GgOjAwT1ZhjU9zXFxcDHyV/u/o/ 8t5egeQLepQnqipj57BmzQ1CWnhKh5fGPDg7qotWBPxwblHCQO1sxY+0rOChydeN0FVgbX eAqn70GkrADctOY4Z1yFvHpb760Zsbw= X-MC-Unique: qBwxS0IrNziQ0FyuBzCfgQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 10/25] include/block: fixup typos Date: Tue, 25 Apr 2023 15:13:44 +0200 Message-Id: <20230425131359.259007-11-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428845568100009 From: Wilfred Mallawa Fixup a few minor typos Signed-off-by: Wilfred Mallawa Message-Id: <20230313003744.55476-1-wilfred.mallawa@opensource.wdc.com> Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- include/block/aio-wait.h | 2 +- include/block/block_int-common.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/block/aio-wait.h b/include/block/aio-wait.h index da13357bb8..6e43e3b7bb 100644 --- a/include/block/aio-wait.h +++ b/include/block/aio-wait.h @@ -63,7 +63,7 @@ extern AioWait global_aio_wait; * @ctx: the aio context, or NULL if multiple aio contexts (for which the * caller does not hold a lock) are involved in the polling conditio= n. * @cond: wait while this conditional expression is true - * @unlock: whether to unlock and then lock again @ctx. This apples + * @unlock: whether to unlock and then lock again @ctx. This applies * only when waiting for another AioContext from the main loop. * Otherwise it's ignored. * diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index f01bb8b617..013d419444 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -1260,7 +1260,7 @@ extern QemuOptsList bdrv_create_opts_simple; /* * Common functions that are neither I/O nor Global State. * - * See include/block/block-commmon.h for more information about + * See include/block/block-common.h for more information about * the Common API. */ =20 --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428583; cv=none; d=zohomail.com; s=zohoarc; b=C81yi2A5Rsie9VRY9dd5m/wI5gY+S43rZ9GSVtLvu0kwJ9Mf6M3JEwA6IjAF6wVgTx6QDGco8NAoKhQDgc1gCf2UKL9o2WMJqxpR6ovHVyQCOmbMFtWfDBXXJ+MZK9U+YH8SR6GuE339vZQmmbVnINqOqZs0JzW29sfV31t6lP4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428583; 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; bh=pHk8N0f96tL2rJPj52DQrzGBU6ROjgou1ZioErz5vyc=; b=Lu5MKUXOXpljV+C/mr1nXQ5+d/Xz7RctDTE7bmq3f7eDaRAp4WMjb4g6k5xWdTKlMX1OfYqdGDSmASonAKNYj78QFIMlzZ0Wm15W10U4OH4rdddtl6RNIxLKsrPSIhIvlPlFrlCEbaZWCOOWyGKgIzxUnTj2d7uuY5fQsE9tauM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428583079221.55700103228548; Tue, 25 Apr 2023 06:16:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIVd-0006r2-HP; Tue, 25 Apr 2023 09:15:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006QK-Ah for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUt-0006aB-4D for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:20 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-655-qDzI0NqCNpC9btpex2oOvw-1; Tue, 25 Apr 2023 09:14:15 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DAA363C1022A; Tue, 25 Apr 2023 13:14:14 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E1AE40C2064; Tue, 25 Apr 2023 13:14:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pHk8N0f96tL2rJPj52DQrzGBU6ROjgou1ZioErz5vyc=; b=NWZH4z2WKmUJu5E20yQKkS673HmAcwLLKypwilsaS6j8qJW9xdlkaRql+pj2W7PilR2zd4 jHF9YWDU67AhBiodNwHfL9pFcDme328UwuyXndrWn6pj1tBP4R5zIx++AgTstVs9dpeqUn UizB0i3fFsFaQEZpQvzAYlqfvAHcA+4= X-MC-Unique: qDzI0NqCNpC9btpex2oOvw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 11/25] block: add missing coroutine_fn to bdrv_sum_allocated_file_size() Date: Tue, 25 Apr 2023 15:13:45 +0200 Message-Id: <20230425131359.259007-12-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428584551100003 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi Not a coroutine_fn, you say? static int64_t bdrv_sum_allocated_file_size(BlockDriverState *bs) { BdrvChild *child; int64_t child_size, sum =3D 0; QLIST_FOREACH(child, &bs->children, next) { if (child->role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA | BDRV_CHILD_FILTERED)) { child_size =3D bdrv_co_get_allocated_file_size(child->bs); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Well what do we have here?! I rest my case, your honor. Signed-off-by: Stefan Hajnoczi Message-Id: <20230308211435.346375-1-stefanha@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block.c b/block.c index d79a52ca74..5ec1a3897e 100644 --- a/block.c +++ b/block.c @@ -5750,7 +5750,7 @@ exit: * sums the size of all data-bearing children. (This excludes backing * children.) */ -static int64_t bdrv_sum_allocated_file_size(BlockDriverState *bs) +static int64_t coroutine_fn bdrv_sum_allocated_file_size(BlockDriverState = *bs) { BdrvChild *child; int64_t child_size, sum =3D 0; --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682429034; cv=none; d=zohomail.com; s=zohoarc; b=TzOE1V0uhBF/rU1JZLv2jISxJxzvsdBDB4bLUPTr3ALPyEMCrT7ApZaRsKm5r9213z6z0HA3wlw0hjuBBbqqFZqeiPFXuFEqGVT9+h6g9ynFXWg2K+xdkotMChgz73BRO6F8LYbFdgmBtspHQwdzEeU9SMnqUI9BRS7GPkvJGts= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682429034; 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; bh=dGMhJc4Z+y3jNPXYlhCA33o3xlODKuTB/fJNiO26q/s=; b=Iap0xNv1FwPufQuhZix4zItvx4yPHa02LMe8+1S//iYdS7T+YEOgp6sdtloDcgir0iTTu11l40ZSZHrJNkuiSQva4YwEY0WTkX56WzdwlQ1IEjNEE1LXLMCDrAyt/+FCFxPzbwWQioKP8e6/E04d/Ks2z2PyYqwKQ76ariqdlLs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682429034698841.3678068662027; Tue, 25 Apr 2023 06:23:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIVi-0007LJ-NQ; Tue, 25 Apr 2023 09:15:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006QF-HV for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUt-0006aI-6V for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:21 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-393-E9HyaMcyPMuWHQEdwK6Xvg-1; Tue, 25 Apr 2023 09:14:16 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CA5F3185A7A9; Tue, 25 Apr 2023 13:14:15 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D56040C2064; Tue, 25 Apr 2023 13:14:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428457; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dGMhJc4Z+y3jNPXYlhCA33o3xlODKuTB/fJNiO26q/s=; b=I+VNNQJg7bbpZnGkKtfxU0TpQCgg+P1NH0/MYo7UbVTFwKoEtNjZeirPWNUiBmNSW+lEaj BOwBWbP6Io+3X9pIcH73IMbCvoj899YHtpa4Oqd5A2LxaL2zIUuRB2eoLXZGsgDFLndTT5 6ncwV0+7iGoz6Q4yMkvI8vXhVzzxN9c= X-MC-Unique: E9HyaMcyPMuWHQEdwK6Xvg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 12/25] linux-aio: use LinuxAioState from the running thread Date: Tue, 25 Apr 2023 15:13:46 +0200 Message-Id: <20230425131359.259007-13-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682429036285100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito Remove usage of aio_context_acquire by always submitting asynchronous AIO to the current thread's LinuxAioState. In order to prevent mistakes from the caller side, avoid passing LinuxAioSt= ate in laio_io_{plug/unplug} and laio_co_submit, and document the functions to make clear that they work in the current thread's AioContext. Signed-off-by: Emanuele Giuseppe Esposito Message-Id: <20230203131731.851116-2-eesposit@redhat.com> Reviewed-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- include/block/aio.h | 4 ---- include/block/raw-aio.h | 18 ++++++++++++------ include/sysemu/block-backend-io.h | 5 +++++ block/file-posix.c | 10 +++------- block/linux-aio.c | 29 +++++++++++++++++------------ 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/include/block/aio.h b/include/block/aio.h index 543717f294..9e53aabba6 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -208,10 +208,6 @@ struct AioContext { struct ThreadPool *thread_pool; =20 #ifdef CONFIG_LINUX_AIO - /* - * State for native Linux AIO. Uses aio_context_acquire/release for - * locking. - */ struct LinuxAioState *linux_aio; #endif #ifdef CONFIG_LINUX_IO_URING diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h index f8cda9df91..db614472e6 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -49,14 +49,20 @@ typedef struct LinuxAioState LinuxAioState; LinuxAioState *laio_init(Error **errp); void laio_cleanup(LinuxAioState *s); -int coroutine_fn laio_co_submit(BlockDriverState *bs, LinuxAioState *s, in= t fd, - uint64_t offset, QEMUIOVector *qiov, int t= ype, - uint64_t dev_max_batch); + +/* laio_co_submit: submit I/O requests in the thread's current AioContext.= */ +int coroutine_fn laio_co_submit(int fd, uint64_t offset, QEMUIOVector *qio= v, + int type, uint64_t dev_max_batch); + void laio_detach_aio_context(LinuxAioState *s, AioContext *old_context); void laio_attach_aio_context(LinuxAioState *s, AioContext *new_context); -void laio_io_plug(BlockDriverState *bs, LinuxAioState *s); -void laio_io_unplug(BlockDriverState *bs, LinuxAioState *s, - uint64_t dev_max_batch); + +/* + * laio_io_plug/unplug work in the thread's current AioContext, therefore = the + * caller must ensure that they are paired in the same IOThread. + */ +void laio_io_plug(void); +void laio_io_unplug(uint64_t dev_max_batch); #endif /* io_uring.c - Linux io_uring implementation */ #ifdef CONFIG_LINUX_IO_URING diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index bb25493ba1..851a44de96 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -90,6 +90,11 @@ void blk_iostatus_set_err(BlockBackend *blk, int error); int blk_get_max_iov(BlockBackend *blk); int blk_get_max_hw_iov(BlockBackend *blk); =20 +/* + * blk_io_plug/unplug are thread-local operations. This means that multiple + * IOThreads can simultaneously call plug/unplug, but the caller must ensu= re + * that each unplug() is called in the same IOThread of the matching plug(= ). + */ void coroutine_fn blk_co_io_plug(BlockBackend *blk); void co_wrapper blk_io_plug(BlockBackend *blk); =20 diff --git a/block/file-posix.c b/block/file-posix.c index c2dee3f056..1b4342822b 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2095,10 +2095,8 @@ static int coroutine_fn raw_co_prw(BlockDriverState = *bs, uint64_t offset, #endif #ifdef CONFIG_LINUX_AIO } else if (s->use_linux_aio) { - LinuxAioState *aio =3D aio_get_linux_aio(bdrv_get_aio_context(bs)); assert(qiov->size =3D=3D bytes); - return laio_co_submit(bs, aio, s->fd, offset, qiov, type, - s->aio_max_batch); + return laio_co_submit(s->fd, offset, qiov, type, s->aio_max_batch); #endif } =20 @@ -2137,8 +2135,7 @@ static void coroutine_fn raw_co_io_plug(BlockDriverSt= ate *bs) BDRVRawState __attribute__((unused)) *s =3D bs->opaque; #ifdef CONFIG_LINUX_AIO if (s->use_linux_aio) { - LinuxAioState *aio =3D aio_get_linux_aio(bdrv_get_aio_context(bs)); - laio_io_plug(bs, aio); + laio_io_plug(); } #endif #ifdef CONFIG_LINUX_IO_URING @@ -2154,8 +2151,7 @@ static void coroutine_fn raw_co_io_unplug(BlockDriver= State *bs) BDRVRawState __attribute__((unused)) *s =3D bs->opaque; #ifdef CONFIG_LINUX_AIO if (s->use_linux_aio) { - LinuxAioState *aio =3D aio_get_linux_aio(bdrv_get_aio_context(bs)); - laio_io_unplug(bs, aio, s->aio_max_batch); + laio_io_unplug(s->aio_max_batch); } #endif #ifdef CONFIG_LINUX_IO_URING diff --git a/block/linux-aio.c b/block/linux-aio.c index d2cfb7f523..fc50cdd1bf 100644 --- a/block/linux-aio.c +++ b/block/linux-aio.c @@ -16,6 +16,9 @@ #include "qemu/coroutine.h" #include "qapi/error.h" =20 +/* Only used for assertions. */ +#include "qemu/coroutine_int.h" + #include =20 /* @@ -56,10 +59,8 @@ struct LinuxAioState { io_context_t ctx; EventNotifier e; =20 - /* io queue for submit at batch. Protected by AioContext lock. */ + /* No locking required, only accessed from AioContext home thread */ LaioQueue io_q; - - /* I/O completion processing. Only runs in I/O thread. */ QEMUBH *completion_bh; int event_idx; int event_max; @@ -102,6 +103,7 @@ static void qemu_laio_process_completion(struct qemu_la= iocb *laiocb) * later. Coroutines cannot be entered recursively so avoid doing * that! */ + assert(laiocb->co->ctx =3D=3D laiocb->ctx->aio_context); if (!qemu_coroutine_entered(laiocb->co)) { aio_co_wake(laiocb->co); } @@ -232,13 +234,11 @@ static void qemu_laio_process_completions(LinuxAioSta= te *s) =20 static void qemu_laio_process_completions_and_submit(LinuxAioState *s) { - aio_context_acquire(s->aio_context); qemu_laio_process_completions(s); =20 if (!s->io_q.plugged && !QSIMPLEQ_EMPTY(&s->io_q.pending)) { ioq_submit(s); } - aio_context_release(s->aio_context); } =20 static void qemu_laio_completion_bh(void *opaque) @@ -354,14 +354,19 @@ static uint64_t laio_max_batch(LinuxAioState *s, uint= 64_t dev_max_batch) return max_batch; } =20 -void laio_io_plug(BlockDriverState *bs, LinuxAioState *s) +void laio_io_plug(void) { + AioContext *ctx =3D qemu_get_current_aio_context(); + LinuxAioState *s =3D aio_get_linux_aio(ctx); + s->io_q.plugged++; } =20 -void laio_io_unplug(BlockDriverState *bs, LinuxAioState *s, - uint64_t dev_max_batch) +void laio_io_unplug(uint64_t dev_max_batch) { + AioContext *ctx =3D qemu_get_current_aio_context(); + LinuxAioState *s =3D aio_get_linux_aio(ctx); + assert(s->io_q.plugged); s->io_q.plugged--; =20 @@ -411,15 +416,15 @@ static int laio_do_submit(int fd, struct qemu_laiocb = *laiocb, off_t offset, return 0; } =20 -int coroutine_fn laio_co_submit(BlockDriverState *bs, LinuxAioState *s, in= t fd, - uint64_t offset, QEMUIOVector *qiov, int t= ype, - uint64_t dev_max_batch) +int coroutine_fn laio_co_submit(int fd, uint64_t offset, QEMUIOVector *qio= v, + int type, uint64_t dev_max_batch) { int ret; + AioContext *ctx =3D qemu_get_current_aio_context(); struct qemu_laiocb laiocb =3D { .co =3D qemu_coroutine_self(), .nbytes =3D qiov->size, - .ctx =3D s, + .ctx =3D aio_get_linux_aio(ctx), .ret =3D -EINPROGRESS, .is_read =3D (type =3D=3D QEMU_AIO_READ), .qiov =3D qiov, --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428516; cv=none; d=zohomail.com; s=zohoarc; b=OdxA8K1P4Zh0eAU8Y1EjiQOBu8lTrwKgYgjGc8VuhPWPAsCS3Cp8NsRLcJPDmJkZxlaCIX8piH54dtpP7RuQoYyucEsOYElU1PKkSQZM2reGnoDxKK7s2DRh9yNKRmLRAqsXU4TdmGwmf+LtTNr6oX6S5ML9GP+ZdNi6VQBoXOQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428516; 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; bh=YijfYPH6A8UH2Sl6+fxNlhx4m+vMGk3MZm7EECWpDzo=; b=NmfopHf54q8be0JZuN9vP8Jf8ohrIZ/7bIOslzLKmELIWVCkmOuMo3/oX45Zx1HtuOh+e17hinUCndFYLKOjfHVySBzmBryeUzrIizcEgLrD55H5t42HeXDAhWdY5j4kmv8YP1fG4kZiMV8sAXjodBVFdwYycVBT8V/E9d4W8e4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428516491209.68243465402463; Tue, 25 Apr 2023 06:15:16 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIVY-0006lT-0h; Tue, 25 Apr 2023 09:15:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006Sg-De for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:42 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIUt-0006aE-0x for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:21 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-616-is4YeGWGP9248eX5tSWj2g-1; Tue, 25 Apr 2023 09:14:17 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BC8B21C01B25; Tue, 25 Apr 2023 13:14:16 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0CC5E40C201F; Tue, 25 Apr 2023 13:14:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YijfYPH6A8UH2Sl6+fxNlhx4m+vMGk3MZm7EECWpDzo=; b=dEutORoPBgSSZnqKcPIMGHPODXReAY1VgsSw+yXVs+VdUxcnNIg3FQvpDfm9MfhzVACeUj JuGVhPtkT4Qjnh49O+A4zRh3dTrP72ympMloLARAw0XNu46jLWPyrnxy/rp/uk5qItbo28 h3LmpCh0Gagp8G1AgJY2zMy8v8JH5qY= X-MC-Unique: is4YeGWGP9248eX5tSWj2g-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 13/25] io_uring: use LuringState from the running thread Date: Tue, 25 Apr 2023 15:13:47 +0200 Message-Id: <20230425131359.259007-14-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428517313100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito Remove usage of aio_context_acquire by always submitting asynchronous AIO to the current thread's LuringState. In order to prevent mistakes from the caller side, avoid passing LuringState in luring_io_{plug/unplug} and luring_co_submit, and document the functions to make clear that they work in the current thread's AioContext. Signed-off-by: Emanuele Giuseppe Esposito Message-Id: <20230203131731.851116-3-eesposit@redhat.com> Reviewed-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- include/block/aio.h | 4 ---- include/block/raw-aio.h | 15 +++++++++++---- block/file-posix.c | 12 ++++-------- block/io_uring.c | 23 +++++++++++++++-------- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/include/block/aio.h b/include/block/aio.h index 9e53aabba6..e267d918fd 100644 --- a/include/block/aio.h +++ b/include/block/aio.h @@ -211,10 +211,6 @@ struct AioContext { struct LinuxAioState *linux_aio; #endif #ifdef CONFIG_LINUX_IO_URING - /* - * State for Linux io_uring. Uses aio_context_acquire/release for - * locking. - */ struct LuringState *linux_io_uring; =20 /* State for file descriptor monitoring using Linux io_uring */ diff --git a/include/block/raw-aio.h b/include/block/raw-aio.h index db614472e6..e46a29c3f0 100644 --- a/include/block/raw-aio.h +++ b/include/block/raw-aio.h @@ -69,12 +69,19 @@ void laio_io_unplug(uint64_t dev_max_batch); typedef struct LuringState LuringState; LuringState *luring_init(Error **errp); void luring_cleanup(LuringState *s); -int coroutine_fn luring_co_submit(BlockDriverState *bs, LuringState *s, in= t fd, - uint64_t offset, QEMUIOVector *qiov, int t= ype); + +/* luring_co_submit: submit I/O requests in the thread's current AioContex= t. */ +int coroutine_fn luring_co_submit(BlockDriverState *bs, int fd, uint64_t o= ffset, + QEMUIOVector *qiov, int type); void luring_detach_aio_context(LuringState *s, AioContext *old_context); void luring_attach_aio_context(LuringState *s, AioContext *new_context); -void luring_io_plug(BlockDriverState *bs, LuringState *s); -void luring_io_unplug(BlockDriverState *bs, LuringState *s); + +/* + * luring_io_plug/unplug work in the thread's current AioContext, therefor= e the + * caller must ensure that they are paired in the same IOThread. + */ +void luring_io_plug(void); +void luring_io_unplug(void); #endif =20 #ifdef _WIN32 diff --git a/block/file-posix.c b/block/file-posix.c index 1b4342822b..30cb4ae421 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2089,9 +2089,8 @@ static int coroutine_fn raw_co_prw(BlockDriverState *= bs, uint64_t offset, type |=3D QEMU_AIO_MISALIGNED; #ifdef CONFIG_LINUX_IO_URING } else if (s->use_linux_io_uring) { - LuringState *aio =3D aio_get_linux_io_uring(bdrv_get_aio_context(b= s)); assert(qiov->size =3D=3D bytes); - return luring_co_submit(bs, aio, s->fd, offset, qiov, type); + return luring_co_submit(bs, s->fd, offset, qiov, type); #endif #ifdef CONFIG_LINUX_AIO } else if (s->use_linux_aio) { @@ -2140,8 +2139,7 @@ static void coroutine_fn raw_co_io_plug(BlockDriverSt= ate *bs) #endif #ifdef CONFIG_LINUX_IO_URING if (s->use_linux_io_uring) { - LuringState *aio =3D aio_get_linux_io_uring(bdrv_get_aio_context(b= s)); - luring_io_plug(bs, aio); + luring_io_plug(); } #endif } @@ -2156,8 +2154,7 @@ static void coroutine_fn raw_co_io_unplug(BlockDriver= State *bs) #endif #ifdef CONFIG_LINUX_IO_URING if (s->use_linux_io_uring) { - LuringState *aio =3D aio_get_linux_io_uring(bdrv_get_aio_context(b= s)); - luring_io_unplug(bs, aio); + luring_io_unplug(); } #endif } @@ -2181,8 +2178,7 @@ static int coroutine_fn raw_co_flush_to_disk(BlockDri= verState *bs) =20 #ifdef CONFIG_LINUX_IO_URING if (s->use_linux_io_uring) { - LuringState *aio =3D aio_get_linux_io_uring(bdrv_get_aio_context(b= s)); - return luring_co_submit(bs, aio, s->fd, 0, NULL, QEMU_AIO_FLUSH); + return luring_co_submit(bs, s->fd, 0, NULL, QEMU_AIO_FLUSH); } #endif return raw_thread_pool_submit(bs, handle_aiocb_flush, &acb); diff --git a/block/io_uring.c b/block/io_uring.c index 973e15d876..989f9a99ed 100644 --- a/block/io_uring.c +++ b/block/io_uring.c @@ -18,6 +18,9 @@ #include "qapi/error.h" #include "trace.h" =20 +/* Only used for assertions. */ +#include "qemu/coroutine_int.h" + /* io_uring ring size */ #define MAX_ENTRIES 128 =20 @@ -50,10 +53,9 @@ typedef struct LuringState { =20 struct io_uring ring; =20 - /* io queue for submit at batch. Protected by AioContext lock. */ + /* No locking required, only accessed from AioContext home thread */ LuringQueue io_q; =20 - /* I/O completion processing. Only runs in I/O thread. */ QEMUBH *completion_bh; } LuringState; =20 @@ -209,6 +211,7 @@ end: * eventually runs later. Coroutines cannot be entered recursively * so avoid doing that! */ + assert(luringcb->co->ctx =3D=3D s->aio_context); if (!qemu_coroutine_entered(luringcb->co)) { aio_co_wake(luringcb->co); } @@ -262,13 +265,11 @@ static int ioq_submit(LuringState *s) =20 static void luring_process_completions_and_submit(LuringState *s) { - aio_context_acquire(s->aio_context); luring_process_completions(s); =20 if (!s->io_q.plugged && s->io_q.in_queue > 0) { ioq_submit(s); } - aio_context_release(s->aio_context); } =20 static void qemu_luring_completion_bh(void *opaque) @@ -306,14 +307,18 @@ static void ioq_init(LuringQueue *io_q) io_q->blocked =3D false; } =20 -void luring_io_plug(BlockDriverState *bs, LuringState *s) +void luring_io_plug(void) { + AioContext *ctx =3D qemu_get_current_aio_context(); + LuringState *s =3D aio_get_linux_io_uring(ctx); trace_luring_io_plug(s); s->io_q.plugged++; } =20 -void luring_io_unplug(BlockDriverState *bs, LuringState *s) +void luring_io_unplug(void) { + AioContext *ctx =3D qemu_get_current_aio_context(); + LuringState *s =3D aio_get_linux_io_uring(ctx); assert(s->io_q.plugged); trace_luring_io_unplug(s, s->io_q.blocked, s->io_q.plugged, s->io_q.in_queue, s->io_q.in_flight); @@ -373,10 +378,12 @@ static int luring_do_submit(int fd, LuringAIOCB *luri= ngcb, LuringState *s, return 0; } =20 -int coroutine_fn luring_co_submit(BlockDriverState *bs, LuringState *s, in= t fd, - uint64_t offset, QEMUIOVector *qiov, int= type) +int coroutine_fn luring_co_submit(BlockDriverState *bs, int fd, uint64_t o= ffset, + QEMUIOVector *qiov, int type) { int ret; + AioContext *ctx =3D qemu_get_current_aio_context(); + LuringState *s =3D aio_get_linux_io_uring(ctx); LuringAIOCB luringcb =3D { .co =3D qemu_coroutine_self(), .ret =3D -EINPROGRESS, --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428971; cv=none; d=zohomail.com; s=zohoarc; b=KPvImtQozZl/kj6AwflMk0tl9NIE9b3vPpmqA52LayqOca2atPPe/eqOUWAQWxkDbAQmQ3zbfd9vXUFk+wjFM9tZp8UvTz9XzqThcNGdZzRDiIEmjIqXkNSrDYgcnj+VO561+eJMBABhPg/IgNBpd1TtXvgy2pi+LD+p//vYsP8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428971; 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; bh=eOxD0B6t6Kjmv88wWP5XaU39InLoXf99vLZGPp2IDzA=; b=TNP6JOME/kRJyjMG6MSkEqt7A9GHdN/xAmslpBIVBihXeaje8TMYVYJ6RKWf13ffMwhVB0WxG8ZG8YPYjpwmYx43vQc1eMqtZVdLLZSimTRCkeK3jjF/6RjW3x/0PitakSRzrAC90nlPqwdqRZm86nhYtGxzdvWPHOQARwqFJOU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428971874253.70015123477367; Tue, 25 Apr 2023 06:22:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIYy-00029Y-CT; Tue, 25 Apr 2023 09:18:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVT-0006rN-Uc for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:15:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006an-KU for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:50 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-27-5Es_dXVCM669woBBZbrTcw-1; Tue, 25 Apr 2023 09:14:18 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AF0C3185A794; Tue, 25 Apr 2023 13:14:17 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 004E240C2064; Tue, 25 Apr 2023 13:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428459; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eOxD0B6t6Kjmv88wWP5XaU39InLoXf99vLZGPp2IDzA=; b=hVqbmSSRSXnQH1yto34bR1st7uEDi1tKOixRyM8Z3NsUsUHmE1ug+3ul9cnXwr+ArgSp7E XvuA0kwKaLRcAdycF0UTFpFkAOeC0xcLIYx1NyLg/INqPGdagvptryoywkJRaPjMz55+Q+ 6EsqJSMgG6yzs8txA9JYL/cn4sFlKNQ= X-MC-Unique: 5Es_dXVCM669woBBZbrTcw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 14/25] thread-pool: use ThreadPool from the running thread Date: Tue, 25 Apr 2023 15:13:48 +0200 Message-Id: <20230425131359.259007-15-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428974062100006 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito Use qemu_get_current_aio_context() where possible, since we always submit work to the current thread anyways. We want to also be sure that the thread submitting the work is the same as the one processing the pool, to avoid adding synchronization to the pool list. Signed-off-by: Emanuele Giuseppe Esposito Message-Id: <20230203131731.851116-4-eesposit@redhat.com> Reviewed-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- include/block/thread-pool.h | 5 +++++ block/file-posix.c | 21 ++++++++++----------- block/file-win32.c | 2 +- block/qcow2-threads.c | 2 +- util/thread-pool.c | 9 ++++----- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/include/block/thread-pool.h b/include/block/thread-pool.h index 95ff2b0bdb..c408bde74c 100644 --- a/include/block/thread-pool.h +++ b/include/block/thread-pool.h @@ -29,12 +29,17 @@ typedef struct ThreadPool ThreadPool; ThreadPool *thread_pool_new(struct AioContext *ctx); void thread_pool_free(ThreadPool *pool); =20 +/* + * thread_pool_submit* API: submit I/O requests in the thread's + * current AioContext. + */ BlockAIOCB *thread_pool_submit_aio(ThreadPool *pool, ThreadPoolFunc *func, void *arg, BlockCompletionFunc *cb, void *opaque); int coroutine_fn thread_pool_submit_co(ThreadPool *pool, ThreadPoolFunc *func, void *arg); void thread_pool_submit(ThreadPool *pool, ThreadPoolFunc *func, void *arg); + void thread_pool_update_params(ThreadPool *pool, struct AioContext *ctx); =20 #endif diff --git a/block/file-posix.c b/block/file-posix.c index 30cb4ae421..173b3b1653 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2040,11 +2040,10 @@ out: return result; } =20 -static int coroutine_fn raw_thread_pool_submit(BlockDriverState *bs, - ThreadPoolFunc func, void *= arg) +static int coroutine_fn raw_thread_pool_submit(ThreadPoolFunc func, void *= arg) { /* @bs can be NULL, bdrv_get_aio_context() returns the main context th= en */ - ThreadPool *pool =3D aio_get_thread_pool(bdrv_get_aio_context(bs)); + ThreadPool *pool =3D aio_get_thread_pool(qemu_get_current_aio_context(= )); return thread_pool_submit_co(pool, func, arg); } =20 @@ -2112,7 +2111,7 @@ static int coroutine_fn raw_co_prw(BlockDriverState *= bs, uint64_t offset, }; =20 assert(qiov->size =3D=3D bytes); - return raw_thread_pool_submit(bs, handle_aiocb_rw, &acb); + return raw_thread_pool_submit(handle_aiocb_rw, &acb); } =20 static int coroutine_fn raw_co_preadv(BlockDriverState *bs, int64_t offset, @@ -2181,7 +2180,7 @@ static int coroutine_fn raw_co_flush_to_disk(BlockDri= verState *bs) return luring_co_submit(bs, s->fd, 0, NULL, QEMU_AIO_FLUSH); } #endif - return raw_thread_pool_submit(bs, handle_aiocb_flush, &acb); + return raw_thread_pool_submit(handle_aiocb_flush, &acb); } =20 static void raw_aio_attach_aio_context(BlockDriverState *bs, @@ -2243,7 +2242,7 @@ raw_regular_truncate(BlockDriverState *bs, int fd, in= t64_t offset, }, }; =20 - return raw_thread_pool_submit(bs, handle_aiocb_truncate, &acb); + return raw_thread_pool_submit(handle_aiocb_truncate, &acb); } =20 static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offs= et, @@ -2992,7 +2991,7 @@ raw_do_pdiscard(BlockDriverState *bs, int64_t offset,= int64_t bytes, acb.aio_type |=3D QEMU_AIO_BLKDEV; } =20 - ret =3D raw_thread_pool_submit(bs, handle_aiocb_discard, &acb); + ret =3D raw_thread_pool_submit(handle_aiocb_discard, &acb); raw_account_discard(s, bytes, ret); return ret; } @@ -3067,7 +3066,7 @@ raw_do_pwrite_zeroes(BlockDriverState *bs, int64_t of= fset, int64_t bytes, handler =3D handle_aiocb_write_zeroes; } =20 - return raw_thread_pool_submit(bs, handler, &acb); + return raw_thread_pool_submit(handler, &acb); } =20 static int coroutine_fn raw_co_pwrite_zeroes( @@ -3305,7 +3304,7 @@ raw_co_copy_range_to(BlockDriverState *bs, }, }; =20 - return raw_thread_pool_submit(bs, handle_aiocb_copy_range, &acb); + return raw_thread_pool_submit(handle_aiocb_copy_range, &acb); } =20 BlockDriver bdrv_file =3D { @@ -3635,7 +3634,7 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int= req, void *buf) struct sg_io_hdr *io_hdr =3D buf; if (io_hdr->cmdp[0] =3D=3D PERSISTENT_RESERVE_OUT || io_hdr->cmdp[0] =3D=3D PERSISTENT_RESERVE_IN) { - return pr_manager_execute(s->pr_mgr, bdrv_get_aio_context(bs), + return pr_manager_execute(s->pr_mgr, qemu_get_current_aio_cont= ext(), s->fd, io_hdr); } } @@ -3651,7 +3650,7 @@ hdev_co_ioctl(BlockDriverState *bs, unsigned long int= req, void *buf) }, }; =20 - return raw_thread_pool_submit(bs, handle_aiocb_ioctl, &acb); + return raw_thread_pool_submit(handle_aiocb_ioctl, &acb); } #endif /* linux */ =20 diff --git a/block/file-win32.c b/block/file-win32.c index 1763b8662e..0aedb0875c 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -168,7 +168,7 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, HA= NDLE hfile, acb->aio_offset =3D offset; =20 trace_file_paio_submit(acb, opaque, offset, count, type); - pool =3D aio_get_thread_pool(bdrv_get_aio_context(bs)); + pool =3D aio_get_thread_pool(qemu_get_current_aio_context()); return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); } =20 diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c index 953bbe6df8..6d2e6b7bf4 100644 --- a/block/qcow2-threads.c +++ b/block/qcow2-threads.c @@ -43,7 +43,7 @@ qcow2_co_process(BlockDriverState *bs, ThreadPoolFunc *fu= nc, void *arg) { int ret; BDRVQcow2State *s =3D bs->opaque; - ThreadPool *pool =3D aio_get_thread_pool(bdrv_get_aio_context(bs)); + ThreadPool *pool =3D aio_get_thread_pool(qemu_get_current_aio_context(= )); =20 qemu_co_mutex_lock(&s->lock); while (s->nb_threads >=3D QCOW2_MAX_THREADS) { diff --git a/util/thread-pool.c b/util/thread-pool.c index 31113b5860..a70abb8a59 100644 --- a/util/thread-pool.c +++ b/util/thread-pool.c @@ -48,7 +48,7 @@ struct ThreadPoolElement { /* Access to this list is protected by lock. */ QTAILQ_ENTRY(ThreadPoolElement) reqs; =20 - /* Access to this list is protected by the global mutex. */ + /* This list is only written by the thread pool's mother thread. */ QLIST_ENTRY(ThreadPoolElement) all; }; =20 @@ -175,7 +175,6 @@ static void thread_pool_completion_bh(void *opaque) ThreadPool *pool =3D opaque; ThreadPoolElement *elem, *next; =20 - aio_context_acquire(pool->ctx); restart: QLIST_FOREACH_SAFE(elem, &pool->head, all, next) { if (elem->state !=3D THREAD_DONE) { @@ -195,9 +194,7 @@ restart: */ qemu_bh_schedule(pool->completion_bh); =20 - aio_context_release(pool->ctx); elem->common.cb(elem->common.opaque, elem->ret); - aio_context_acquire(pool->ctx); =20 /* We can safely cancel the completion_bh here regardless of s= omeone * else having scheduled it meanwhile because we reenter the @@ -211,7 +208,6 @@ restart: qemu_aio_unref(elem); } } - aio_context_release(pool->ctx); } =20 static void thread_pool_cancel(BlockAIOCB *acb) @@ -251,6 +247,9 @@ BlockAIOCB *thread_pool_submit_aio(ThreadPool *pool, { ThreadPoolElement *req; =20 + /* Assert that the thread submitting work is the same running the pool= */ + assert(pool->ctx =3D=3D qemu_get_current_aio_context()); + req =3D qemu_aio_get(&thread_pool_aiocb_info, NULL, cb, opaque); req->func =3D func; req->arg =3D arg; --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428965; cv=none; d=zohomail.com; s=zohoarc; b=f3FXXLJvlVxNqOB2SyQ1Hio3Cw1Nh7/ZIk5qrlEbsU7TkOF6L2nSerVAfd75chgPZ9uCE1frX6XxOzXnZ4+OjzUdobk9a93ZOmbTttPspQx8jN/1ELm8cksXpZ4XM7n8IDjk5YtqH99SLMH14JLrRVCDOKp/NWGRlP5U3onAqYk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428965; 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; bh=R7SB5UwcI+Y0Zd37MCHQXQT7/n9ZX98WKUYtdvDD/ms=; b=MKgqQiiR0XC5RnEiV3kz5TgnhIiCJiZm0d0olkawleW22iQkmNmWjB8YpPYI+HvMaN3HW1GPBdFnb0JfXr/bCxnIXjAAkvw+soMk+wug2teQYJO6C8GNgjh8tVJzWy578yQIr4TO24IvXmLYbN87tc0xI+D3vMGm7woV54unNSI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168242896584421.501741529045262; Tue, 25 Apr 2023 06:22:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIWX-0007yg-Sf; Tue, 25 Apr 2023 09:16:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVN-0006l4-Fu for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006bj-7X for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:48 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-416-egl9LIvdMaKGcqeojm7AgA-1; Tue, 25 Apr 2023 09:14:19 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9EF6A1C01B3C; Tue, 25 Apr 2023 13:14:18 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id E445E40C201F; Tue, 25 Apr 2023 13:14:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428464; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R7SB5UwcI+Y0Zd37MCHQXQT7/n9ZX98WKUYtdvDD/ms=; b=eyw0AIAMLxGEsNmQ4soNWtbSIMpALJTilwiaUSVSEpScLvNsma3I7kLjcPXsUy7BBXao5c THcHlfHORzwTNTrn5ji60JZw7n2rBptMizihHEu+bUo9HRdkZHmcv6KN+702yqnAVv+cIh 7oGxhrsHZJAsOBwDjmJMCmfdrmIhRkA= X-MC-Unique: egl9LIvdMaKGcqeojm7AgA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 15/25] thread-pool: avoid passing the pool parameter every time Date: Tue, 25 Apr 2023 15:13:49 +0200 Message-Id: <20230425131359.259007-16-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428966508100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito thread_pool_submit_aio() is always called on a pool taken from qemu_get_current_aio_context(), and that is the only intended use: each pool runs only in the same thread that is submitting work to it, it can't run anywhere else. Therefore simplify the thread_pool_submit* API and remove the ThreadPool function parameter. Signed-off-by: Emanuele Giuseppe Esposito Message-Id: <20230203131731.851116-5-eesposit@redhat.com> Reviewed-by: Kevin Wolf Reviewed-by: Stefan Hajnoczi Signed-off-by: Kevin Wolf --- include/block/thread-pool.h | 10 ++++------ backends/tpm/tpm_backend.c | 4 +--- block/file-posix.c | 4 +--- block/file-win32.c | 4 +--- block/qcow2-threads.c | 3 +-- hw/9pfs/coth.c | 3 +-- hw/ppc/spapr_nvdimm.c | 6 ++---- hw/virtio/virtio-pmem.c | 3 +-- scsi/pr-manager.c | 3 +-- scsi/qemu-pr-helper.c | 3 +-- tests/unit/test-thread-pool.c | 12 +++++------- util/thread-pool.c | 16 ++++++++-------- 12 files changed, 27 insertions(+), 44 deletions(-) diff --git a/include/block/thread-pool.h b/include/block/thread-pool.h index c408bde74c..948ff5f30c 100644 --- a/include/block/thread-pool.h +++ b/include/block/thread-pool.h @@ -33,12 +33,10 @@ void thread_pool_free(ThreadPool *pool); * thread_pool_submit* API: submit I/O requests in the thread's * current AioContext. */ -BlockAIOCB *thread_pool_submit_aio(ThreadPool *pool, - ThreadPoolFunc *func, void *arg, - BlockCompletionFunc *cb, void *opaque); -int coroutine_fn thread_pool_submit_co(ThreadPool *pool, - ThreadPoolFunc *func, void *arg); -void thread_pool_submit(ThreadPool *pool, ThreadPoolFunc *func, void *arg); +BlockAIOCB *thread_pool_submit_aio(ThreadPoolFunc *func, void *arg, + BlockCompletionFunc *cb, void *opaque); +int coroutine_fn thread_pool_submit_co(ThreadPoolFunc *func, void *arg); +void thread_pool_submit(ThreadPoolFunc *func, void *arg); =20 void thread_pool_update_params(ThreadPool *pool, struct AioContext *ctx); =20 diff --git a/backends/tpm/tpm_backend.c b/backends/tpm/tpm_backend.c index 375587e743..485a20b9e0 100644 --- a/backends/tpm/tpm_backend.c +++ b/backends/tpm/tpm_backend.c @@ -100,8 +100,6 @@ bool tpm_backend_had_startup_error(TPMBackend *s) =20 void tpm_backend_deliver_request(TPMBackend *s, TPMBackendCmd *cmd) { - ThreadPool *pool =3D aio_get_thread_pool(qemu_get_aio_context()); - if (s->cmd !=3D NULL) { error_report("There is a TPM request pending"); return; @@ -109,7 +107,7 @@ void tpm_backend_deliver_request(TPMBackend *s, TPMBack= endCmd *cmd) =20 s->cmd =3D cmd; object_ref(OBJECT(s)); - thread_pool_submit_aio(pool, tpm_backend_worker_thread, s, + thread_pool_submit_aio(tpm_backend_worker_thread, s, tpm_backend_request_completed, s); } =20 diff --git a/block/file-posix.c b/block/file-posix.c index 173b3b1653..c7b723368e 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2042,9 +2042,7 @@ out: =20 static int coroutine_fn raw_thread_pool_submit(ThreadPoolFunc func, void *= arg) { - /* @bs can be NULL, bdrv_get_aio_context() returns the main context th= en */ - ThreadPool *pool =3D aio_get_thread_pool(qemu_get_current_aio_context(= )); - return thread_pool_submit_co(pool, func, arg); + return thread_pool_submit_co(func, arg); } =20 /* diff --git a/block/file-win32.c b/block/file-win32.c index 0aedb0875c..48b790d917 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -153,7 +153,6 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, HA= NDLE hfile, BlockCompletionFunc *cb, void *opaque, int type) { RawWin32AIOData *acb =3D g_new(RawWin32AIOData, 1); - ThreadPool *pool; =20 acb->bs =3D bs; acb->hfile =3D hfile; @@ -168,8 +167,7 @@ static BlockAIOCB *paio_submit(BlockDriverState *bs, HA= NDLE hfile, acb->aio_offset =3D offset; =20 trace_file_paio_submit(acb, opaque, offset, count, type); - pool =3D aio_get_thread_pool(qemu_get_current_aio_context()); - return thread_pool_submit_aio(pool, aio_worker, acb, cb, opaque); + return thread_pool_submit_aio(aio_worker, acb, cb, opaque); } =20 int qemu_ftruncate64(int fd, int64_t length) diff --git a/block/qcow2-threads.c b/block/qcow2-threads.c index 6d2e6b7bf4..d6071a1eae 100644 --- a/block/qcow2-threads.c +++ b/block/qcow2-threads.c @@ -43,7 +43,6 @@ qcow2_co_process(BlockDriverState *bs, ThreadPoolFunc *fu= nc, void *arg) { int ret; BDRVQcow2State *s =3D bs->opaque; - ThreadPool *pool =3D aio_get_thread_pool(qemu_get_current_aio_context(= )); =20 qemu_co_mutex_lock(&s->lock); while (s->nb_threads >=3D QCOW2_MAX_THREADS) { @@ -52,7 +51,7 @@ qcow2_co_process(BlockDriverState *bs, ThreadPoolFunc *fu= nc, void *arg) s->nb_threads++; qemu_co_mutex_unlock(&s->lock); =20 - ret =3D thread_pool_submit_co(pool, func, arg); + ret =3D thread_pool_submit_co(func, arg); =20 qemu_co_mutex_lock(&s->lock); s->nb_threads--; diff --git a/hw/9pfs/coth.c b/hw/9pfs/coth.c index 2802d41cce..598f46add9 100644 --- a/hw/9pfs/coth.c +++ b/hw/9pfs/coth.c @@ -41,6 +41,5 @@ static int coroutine_enter_func(void *arg) void co_run_in_worker_bh(void *opaque) { Coroutine *co =3D opaque; - thread_pool_submit_aio(aio_get_thread_pool(qemu_get_aio_context()), - coroutine_enter_func, co, coroutine_enter_cb, c= o); + thread_pool_submit_aio(coroutine_enter_func, co, coroutine_enter_cb, c= o); } diff --git a/hw/ppc/spapr_nvdimm.c b/hw/ppc/spapr_nvdimm.c index 04a64cada3..a8688243a6 100644 --- a/hw/ppc/spapr_nvdimm.c +++ b/hw/ppc/spapr_nvdimm.c @@ -496,7 +496,6 @@ static int spapr_nvdimm_flush_post_load(void *opaque, i= nt version_id) { SpaprNVDIMMDevice *s_nvdimm =3D (SpaprNVDIMMDevice *)opaque; SpaprNVDIMMDeviceFlushState *state; - ThreadPool *pool =3D aio_get_thread_pool(qemu_get_aio_context()); HostMemoryBackend *backend =3D MEMORY_BACKEND(PC_DIMM(s_nvdimm)->hostm= em); bool is_pmem =3D object_property_get_bool(OBJECT(backend), "pmem", NUL= L); bool pmem_override =3D object_property_get_bool(OBJECT(s_nvdimm), @@ -517,7 +516,7 @@ static int spapr_nvdimm_flush_post_load(void *opaque, i= nt version_id) } =20 QLIST_FOREACH(state, &s_nvdimm->pending_nvdimm_flush_states, node) { - thread_pool_submit_aio(pool, flush_worker_cb, state, + thread_pool_submit_aio(flush_worker_cb, state, spapr_nvdimm_flush_completion_cb, state); } =20 @@ -664,7 +663,6 @@ static target_ulong h_scm_flush(PowerPCCPU *cpu, SpaprM= achineState *spapr, PCDIMMDevice *dimm; HostMemoryBackend *backend =3D NULL; SpaprNVDIMMDeviceFlushState *state; - ThreadPool *pool =3D aio_get_thread_pool(qemu_get_aio_context()); int fd; =20 if (!drc || !drc->dev || @@ -699,7 +697,7 @@ static target_ulong h_scm_flush(PowerPCCPU *cpu, SpaprM= achineState *spapr, =20 state->drcidx =3D drc_index; =20 - thread_pool_submit_aio(pool, flush_worker_cb, state, + thread_pool_submit_aio(flush_worker_cb, state, spapr_nvdimm_flush_completion_cb, state); =20 continue_token =3D state->continue_token; diff --git a/hw/virtio/virtio-pmem.c b/hw/virtio/virtio-pmem.c index dff402f08f..c3512c2dae 100644 --- a/hw/virtio/virtio-pmem.c +++ b/hw/virtio/virtio-pmem.c @@ -70,7 +70,6 @@ static void virtio_pmem_flush(VirtIODevice *vdev, VirtQue= ue *vq) VirtIODeviceRequest *req_data; VirtIOPMEM *pmem =3D VIRTIO_PMEM(vdev); HostMemoryBackend *backend =3D MEMORY_BACKEND(pmem->memdev); - ThreadPool *pool =3D aio_get_thread_pool(qemu_get_aio_context()); =20 trace_virtio_pmem_flush_request(); req_data =3D virtqueue_pop(vq, sizeof(VirtIODeviceRequest)); @@ -88,7 +87,7 @@ static void virtio_pmem_flush(VirtIODevice *vdev, VirtQue= ue *vq) req_data->fd =3D memory_region_get_fd(&backend->mr); req_data->pmem =3D pmem; req_data->vdev =3D vdev; - thread_pool_submit_aio(pool, worker_cb, req_data, done_cb, req_data); + thread_pool_submit_aio(worker_cb, req_data, done_cb, req_data); } =20 static void virtio_pmem_get_config(VirtIODevice *vdev, uint8_t *config) diff --git a/scsi/pr-manager.c b/scsi/pr-manager.c index 2098d7e759..fb5fc29730 100644 --- a/scsi/pr-manager.c +++ b/scsi/pr-manager.c @@ -51,7 +51,6 @@ static int pr_manager_worker(void *opaque) int coroutine_fn pr_manager_execute(PRManager *pr_mgr, AioContext *ctx, in= t fd, struct sg_io_hdr *hdr) { - ThreadPool *pool =3D aio_get_thread_pool(ctx); PRManagerData data =3D { .pr_mgr =3D pr_mgr, .fd =3D fd, @@ -62,7 +61,7 @@ int coroutine_fn pr_manager_execute(PRManager *pr_mgr, Ai= oContext *ctx, int fd, =20 /* The matching object_unref is in pr_manager_worker. */ object_ref(OBJECT(pr_mgr)); - return thread_pool_submit_co(pool, pr_manager_worker, &data); + return thread_pool_submit_co(pr_manager_worker, &data); } =20 bool pr_manager_is_connected(PRManager *pr_mgr) diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index 199227a556..e9b3ad259a 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -180,7 +180,6 @@ static int do_sgio_worker(void *opaque) static int do_sgio(int fd, const uint8_t *cdb, uint8_t *sense, uint8_t *buf, int *sz, int dir) { - ThreadPool *pool =3D aio_get_thread_pool(qemu_get_aio_context()); int r; =20 PRHelperSGIOData data =3D { @@ -192,7 +191,7 @@ static int do_sgio(int fd, const uint8_t *cdb, uint8_t = *sense, .dir =3D dir, }; =20 - r =3D thread_pool_submit_co(pool, do_sgio_worker, &data); + r =3D thread_pool_submit_co(do_sgio_worker, &data); *sz =3D data.sz; return r; } diff --git a/tests/unit/test-thread-pool.c b/tests/unit/test-thread-pool.c index 6020e65d69..448fbf7e5f 100644 --- a/tests/unit/test-thread-pool.c +++ b/tests/unit/test-thread-pool.c @@ -8,7 +8,6 @@ #include "qemu/main-loop.h" =20 static AioContext *ctx; -static ThreadPool *pool; static int active; =20 typedef struct { @@ -47,7 +46,7 @@ static void done_cb(void *opaque, int ret) static void test_submit(void) { WorkerTestData data =3D { .n =3D 0 }; - thread_pool_submit(pool, worker_cb, &data); + thread_pool_submit(worker_cb, &data); while (data.n =3D=3D 0) { aio_poll(ctx, true); } @@ -57,7 +56,7 @@ static void test_submit(void) static void test_submit_aio(void) { WorkerTestData data =3D { .n =3D 0, .ret =3D -EINPROGRESS }; - data.aiocb =3D thread_pool_submit_aio(pool, worker_cb, &data, + data.aiocb =3D thread_pool_submit_aio(worker_cb, &data, done_cb, &data); =20 /* The callbacks are not called until after the first wait. */ @@ -78,7 +77,7 @@ static void co_test_cb(void *opaque) active =3D 1; data->n =3D 0; data->ret =3D -EINPROGRESS; - thread_pool_submit_co(pool, worker_cb, data); + thread_pool_submit_co(worker_cb, data); =20 /* The test continues in test_submit_co, after qemu_coroutine_enter...= */ =20 @@ -122,7 +121,7 @@ static void test_submit_many(void) for (i =3D 0; i < 100; i++) { data[i].n =3D 0; data[i].ret =3D -EINPROGRESS; - thread_pool_submit_aio(pool, worker_cb, &data[i], done_cb, &data[i= ]); + thread_pool_submit_aio(worker_cb, &data[i], done_cb, &data[i]); } =20 active =3D 100; @@ -150,7 +149,7 @@ static void do_test_cancel(bool sync) for (i =3D 0; i < 100; i++) { data[i].n =3D 0; data[i].ret =3D -EINPROGRESS; - data[i].aiocb =3D thread_pool_submit_aio(pool, long_cb, &data[i], + data[i].aiocb =3D thread_pool_submit_aio(long_cb, &data[i], done_cb, &data[i]); } =20 @@ -235,7 +234,6 @@ int main(int argc, char **argv) { qemu_init_main_loop(&error_abort); ctx =3D qemu_get_current_aio_context(); - pool =3D aio_get_thread_pool(ctx); =20 g_test_init(&argc, &argv, NULL); g_test_add_func("/thread-pool/submit", test_submit); diff --git a/util/thread-pool.c b/util/thread-pool.c index a70abb8a59..0d97888df0 100644 --- a/util/thread-pool.c +++ b/util/thread-pool.c @@ -241,11 +241,12 @@ static const AIOCBInfo thread_pool_aiocb_info =3D { .get_aio_context =3D thread_pool_get_aio_context, }; =20 -BlockAIOCB *thread_pool_submit_aio(ThreadPool *pool, - ThreadPoolFunc *func, void *arg, - BlockCompletionFunc *cb, void *opaque) +BlockAIOCB *thread_pool_submit_aio(ThreadPoolFunc *func, void *arg, + BlockCompletionFunc *cb, void *opaque) { ThreadPoolElement *req; + AioContext *ctx =3D qemu_get_current_aio_context(); + ThreadPool *pool =3D aio_get_thread_pool(ctx); =20 /* Assert that the thread submitting work is the same running the pool= */ assert(pool->ctx =3D=3D qemu_get_current_aio_context()); @@ -283,19 +284,18 @@ static void thread_pool_co_cb(void *opaque, int ret) aio_co_wake(co->co); } =20 -int coroutine_fn thread_pool_submit_co(ThreadPool *pool, ThreadPoolFunc *f= unc, - void *arg) +int coroutine_fn thread_pool_submit_co(ThreadPoolFunc *func, void *arg) { ThreadPoolCo tpc =3D { .co =3D qemu_coroutine_self(), .ret =3D -EINPRO= GRESS }; assert(qemu_in_coroutine()); - thread_pool_submit_aio(pool, func, arg, thread_pool_co_cb, &tpc); + thread_pool_submit_aio(func, arg, thread_pool_co_cb, &tpc); qemu_coroutine_yield(); return tpc.ret; } =20 -void thread_pool_submit(ThreadPool *pool, ThreadPoolFunc *func, void *arg) +void thread_pool_submit(ThreadPoolFunc *func, void *arg) { - thread_pool_submit_aio(pool, func, arg, NULL, NULL); + thread_pool_submit_aio(func, arg, NULL, NULL); } =20 void thread_pool_update_params(ThreadPool *pool, AioContext *ctx) --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428892; cv=none; d=zohomail.com; s=zohoarc; b=ZZKk1bId2mmjGfcGmhBjHIOgBZUXeJzq6td7mMtWsExOcSssTtDH6vK4eqCO9PXt1ufE01TyQF5CugVvTpJbCWOXlZFcVntvLFeuOngqQG24uUP9/GAIqor7ViDsfg/+2im4tFRbfY4z3mX9oIp1qsJYYk8dKW1fN8OlxAyEaXw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428892; 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; bh=MsujTFtByCb4h5ljvGu1y+tBM3+dYvvxd0Vakulip5g=; b=mY/W+Q7k1Ecgr2v9smnrqsy3WxVvPAbJ2t8nXnNARXtoohtU0QZXKw61mBKG0wv5RqZ3XwAnlkFazWZ+GK7rGd2mqPXx2h7P6SM1VXwUwcwa3UlKeEKKWWoPR24ntileyFmz37ZJKKvrT9i/unO4BorA9OxHoCmNRAn1BJbRe+A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428892166390.9492957813976; Tue, 25 Apr 2023 06:21:32 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIW1-0007YU-O2; Tue, 25 Apr 2023 09:15:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVK-0006fW-Ao for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006bK-23 for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:46 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-354-Mxs9j0jrNCWu2RblsJFcLQ-1; Tue, 25 Apr 2023 09:14:20 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 91B0C185A794; Tue, 25 Apr 2023 13:14:19 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id D760740C2064; Tue, 25 Apr 2023 13:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428463; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MsujTFtByCb4h5ljvGu1y+tBM3+dYvvxd0Vakulip5g=; b=hDrRjOCFRavA+PoZOYiwigemJwA2OurO6V69DHQYV+CV6RYQWrqZXCVJ7DY2wQxVi6xjG7 OaYVj/CGsztGPKO4+62dEd/sfOBeOD3zSZ6K5apsscFK6xzBmKr994AdJU1IwaXAmuEhBN +C7empnX4sEn82/4Gewr8Cd+PajLHJw= X-MC-Unique: Mxs9j0jrNCWu2RblsJFcLQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 16/25] vvfat: mark various functions as coroutine_fn Date: Tue, 25 Apr 2023 15:13:50 +0200 Message-Id: <20230425131359.259007-17-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428893527100001 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Functions that can do I/O are prime candidates for being coroutine_fns. Ma= ke the change for those that are themselves called only from coroutine_fns. In addition, coroutine_fns should do I/O using bdrv_co_*() functions, for which it is required to hold the BlockDriverState graph lock. So also nnot= ate functions on the I/O path with TSA attributes, making it possible to switch them to use bdrv_co_*() functions. Signed-off-by: Paolo Bonzini Message-Id: <20230309084456.304669-2-pbonzini@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/vvfat.c | 58 ++++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/block/vvfat.c b/block/vvfat.c index fd45e86416..0ddc91fc09 100644 --- a/block/vvfat.c +++ b/block/vvfat.c @@ -1053,7 +1053,7 @@ static BDRVVVFATState *vvv =3D NULL; #endif =20 static int enable_write_target(BlockDriverState *bs, Error **errp); -static int is_consistent(BDRVVVFATState *s); +static int coroutine_fn is_consistent(BDRVVVFATState *s); =20 static QemuOptsList runtime_opts =3D { .name =3D "vvfat", @@ -1469,8 +1469,8 @@ static void print_mapping(const mapping_t* mapping) } #endif =20 -static int vvfat_read(BlockDriverState *bs, int64_t sector_num, - uint8_t *buf, int nb_sectors) +static int coroutine_fn GRAPH_RDLOCK +vvfat_read(BlockDriverState *bs, int64_t sector_num, uint8_t *buf, int nb_= sectors) { BDRVVVFATState *s =3D bs->opaque; int i; @@ -1490,8 +1490,8 @@ static int vvfat_read(BlockDriverState *bs, int64_t s= ector_num, DLOG(fprintf(stderr, "sectors %" PRId64 "+%" PRId64 " allocated\n", sector_num, n >> BDRV_SECTOR_BITS)); - if (bdrv_pread(s->qcow, sector_num * BDRV_SECTOR_SIZE, n, - buf + i * 0x200, 0) < 0) { + if (bdrv_co_pread(s->qcow, sector_num * BDRV_SECTOR_SIZE, = n, + buf + i * 0x200, 0) < 0) { return -1; } i +=3D (n >> BDRV_SECTOR_BITS) - 1; @@ -1532,7 +1532,7 @@ static int vvfat_read(BlockDriverState *bs, int64_t s= ector_num, return 0; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vvfat_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -1796,8 +1796,8 @@ static inline uint32_t modified_fat_get(BDRVVVFATStat= e* s, } } =20 -static inline bool cluster_was_modified(BDRVVVFATState *s, - uint32_t cluster_num) +static inline bool coroutine_fn GRAPH_RDLOCK +cluster_was_modified(BDRVVVFATState *s, uint32_t cluster_num) { int was_modified =3D 0; int i; @@ -1852,8 +1852,8 @@ typedef enum { * Further, the files/directories handled by this function are * assumed to be *not* deleted (and *only* those). */ -static uint32_t get_cluster_count_for_direntry(BDRVVVFATState* s, - direntry_t* direntry, const char* path) +static uint32_t coroutine_fn GRAPH_RDLOCK +get_cluster_count_for_direntry(BDRVVVFATState* s, direntry_t* direntry, co= nst char* path) { /* * This is a little bit tricky: @@ -1979,9 +1979,9 @@ static uint32_t get_cluster_count_for_direntry(BDRVVV= FATState* s, if (res) { return -1; } - res =3D bdrv_pwrite(s->qcow, offset * BDRV_SECTOR_= SIZE, - BDRV_SECTOR_SIZE, s->cluster_buf= fer, - 0); + res =3D bdrv_co_pwrite(s->qcow, offset * BDRV_SECT= OR_SIZE, + BDRV_SECTOR_SIZE, s->cluster_= buffer, + 0); if (res < 0) { return -2; } @@ -2011,8 +2011,8 @@ static uint32_t get_cluster_count_for_direntry(BDRVVV= FATState* s, * It returns 0 upon inconsistency or error, and the number of clusters * used by the directory, its subdirectories and their files. */ -static int check_directory_consistency(BDRVVVFATState *s, - int cluster_num, const char* path) +static int coroutine_fn GRAPH_RDLOCK +check_directory_consistency(BDRVVVFATState *s, int cluster_num, const char= * path) { int ret =3D 0; unsigned char* cluster =3D g_malloc(s->cluster_size); @@ -2138,7 +2138,8 @@ DLOG(fprintf(stderr, "check direntry %d:\n", i); prin= t_direntry(direntries + i)) } =20 /* returns 1 on success */ -static int is_consistent(BDRVVVFATState* s) +static int coroutine_fn GRAPH_RDLOCK +is_consistent(BDRVVVFATState* s) { int i, check; int used_clusters_count =3D 0; @@ -2414,8 +2415,8 @@ static int commit_mappings(BDRVVVFATState* s, return 0; } =20 -static int commit_direntries(BDRVVVFATState* s, - int dir_index, int parent_mapping_index) +static int coroutine_fn GRAPH_RDLOCK +commit_direntries(BDRVVVFATState* s, int dir_index, int parent_mapping_ind= ex) { direntry_t* direntry =3D array_get(&(s->directory), dir_index); uint32_t first_cluster =3D dir_index =3D=3D 0 ? 0 : begin_of_direntry(= direntry); @@ -2504,8 +2505,8 @@ static int commit_direntries(BDRVVVFATState* s, =20 /* commit one file (adjust contents, adjust mapping), return first_mapping_index */ -static int commit_one_file(BDRVVVFATState* s, - int dir_index, uint32_t offset) +static int coroutine_fn GRAPH_RDLOCK +commit_one_file(BDRVVVFATState* s, int dir_index, uint32_t offset) { direntry_t* direntry =3D array_get(&(s->directory), dir_index); uint32_t c =3D begin_of_direntry(direntry); @@ -2770,7 +2771,7 @@ static int handle_renames_and_mkdirs(BDRVVVFATState* = s) /* * TODO: make sure that the short name is not matching *another* file */ -static int handle_commits(BDRVVVFATState* s) +static int coroutine_fn GRAPH_RDLOCK handle_commits(BDRVVVFATState* s) { int i, fail =3D 0; =20 @@ -2913,7 +2914,7 @@ static int handle_deletes(BDRVVVFATState* s) * - recurse direntries from root (using bs->bdrv_pread) * - delete files corresponding to mappings marked as deleted */ -static int do_commit(BDRVVVFATState* s) +static int coroutine_fn GRAPH_RDLOCK do_commit(BDRVVVFATState* s) { int ret =3D 0; =20 @@ -2963,7 +2964,7 @@ DLOG(checkpoint()); return 0; } =20 -static int try_commit(BDRVVVFATState* s) +static int coroutine_fn GRAPH_RDLOCK try_commit(BDRVVVFATState* s) { vvfat_close_current_file(s); DLOG(checkpoint()); @@ -2972,8 +2973,9 @@ DLOG(checkpoint()); return do_commit(s); } =20 -static int vvfat_write(BlockDriverState *bs, int64_t sector_num, - const uint8_t *buf, int nb_sectors) +static int coroutine_fn GRAPH_RDLOCK +vvfat_write(BlockDriverState *bs, int64_t sector_num, + const uint8_t *buf, int nb_sectors) { BDRVVVFATState *s =3D bs->opaque; int i, ret; @@ -3082,8 +3084,8 @@ DLOG(checkpoint()); * Use qcow backend. Commit later. */ DLOG(fprintf(stderr, "Write to qcow backend: %d + %d\n", (int)sector_num, = nb_sectors)); - ret =3D bdrv_pwrite(s->qcow, sector_num * BDRV_SECTOR_SIZE, - nb_sectors * BDRV_SECTOR_SIZE, buf, 0); + ret =3D bdrv_co_pwrite(s->qcow, sector_num * BDRV_SECTOR_SIZE, + nb_sectors * BDRV_SECTOR_SIZE, buf, 0); if (ret < 0) { fprintf(stderr, "Error writing to qcow backend\n"); return ret; @@ -3103,7 +3105,7 @@ DLOG(checkpoint()); return 0; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vvfat_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428844; cv=none; d=zohomail.com; s=zohoarc; b=UrJGaGP4jN6iwE3Spl3hcUQ1sIh0tlR1dSLc+WNLGU5ovOph10R0KzHzzaHlOCh4cO0nDoquO5lCcMrVzau70g6YfchHOQLwB6l4W4VOE8AwbkrsvJdlQ+n3XyXg1moVJL+7RQXw5VrgLP+IULKsiKa/fpsHZ1TS9cWBCmcTLJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428844; 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; bh=dbC6UIG8BprQRxNjldWbWhSO93+p1ebzHuX9AjtwDlg=; b=Tit+Yj1Q/BHP/x7oIfM74IsJmp8SoZDd6nD0hspfra43UNNXEE/KUJps9LqbsPQc5dYFuahaE4AatiXW7rxPy786W6XaXsye6rMIysszHRNMM2/TzklZEQKSvSwxIKPt4roQPLi3q/LeYBmNdE9TtRAhXsUuA9x+mRhgKCW68YY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16824288444241007.2399887139503; Tue, 25 Apr 2023 06:20:44 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIYS-0000lh-5f; Tue, 25 Apr 2023 09:18:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVU-0006rV-5D for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:15:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006bb-Vb for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:52 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-363-UhRQ09lrNEq-W3zbVefhLg-1; Tue, 25 Apr 2023 09:14:20 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 81D79101A531; Tue, 25 Apr 2023 13:14:20 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7B2140C2064; Tue, 25 Apr 2023 13:14:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428464; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dbC6UIG8BprQRxNjldWbWhSO93+p1ebzHuX9AjtwDlg=; b=iKQKeSqTKxF5BPVfRIym03RQmIDXjbHgCEQS7RkuWf5vKdf8x7f5lZzeE6dXK6eXFMYYNd KNe9DLrUtEcjC0za7cpBF+ukTXYsyOUF2ojda2IGimfAZm7MVJ0GLiA6wiccvGWe1sMM7s 50c3c5XfewdL1l0YnrNn893Y1a94snw= X-MC-Unique: UhRQ09lrNEq-W3zbVefhLg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 17/25] blkdebug: add missing coroutine_fn annotation Date: Tue, 25 Apr 2023 15:13:51 +0200 Message-Id: <20230425131359.259007-18-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428845564100008 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Signed-off-by: Paolo Bonzini Message-Id: <20230309084456.304669-3-pbonzini@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/blkdebug.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/blkdebug.c b/block/blkdebug.c index 978c8cff9e..addad914b3 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -583,8 +583,8 @@ out: return ret; } =20 -static int rule_check(BlockDriverState *bs, uint64_t offset, uint64_t byte= s, - BlkdebugIOType iotype) +static int coroutine_fn rule_check(BlockDriverState *bs, uint64_t offset, + uint64_t bytes, BlkdebugIOType iotype) { BDRVBlkdebugState *s =3D bs->opaque; BlkdebugRule *rule =3D NULL; --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428886; cv=none; d=zohomail.com; s=zohoarc; b=H25ym2YrsquWfh4DXWYVVVFsTJPh8Uf9llXGxD4pf378Aib5jokx/BNyCzaHOW3xY68dm2+Etbv/pwrvp6HpgIu4ugfrZBr7VDUKBmtB3qn0CAZDv07BrPXnaW0FzZLdpBn2n7vFCAMLW+fBOfoHRDAVC7BM0QhVs96lHB1F2XU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428886; 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; bh=5saFqpyHhnk4jLXIg5Xk9qB/2nICv9QvVbxh3P0Vy3E=; b=llcbP1QJBdVzOZ8Q/izCv4iqUM8kOMck/ljNUmKqUupOsHAEgB5bTy/MkayPDy0LYOOTKJWjxd2rTIDiSifdl25S6/C3cqiUgK4XrLJd5CKqif9U+nC/z/2aPjUnCHeu/hG4Ajf+PP+s4xXi9peuirbRZUH7N8tr1alCPjLaEI0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428885735677.0782964661353; Tue, 25 Apr 2023 06:21:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIXe-0000XK-U0; Tue, 25 Apr 2023 09:17:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVN-0006l3-Fv for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006bn-7n for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:47 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-299-s5uXk66ZMjmuVfQUauv2IA-1; Tue, 25 Apr 2023 09:14:22 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 72FDC3C10221; Tue, 25 Apr 2023 13:14:21 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id B852F40C2064; Tue, 25 Apr 2023 13:14:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428465; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5saFqpyHhnk4jLXIg5Xk9qB/2nICv9QvVbxh3P0Vy3E=; b=bxPy3ZXVlSmryuwmXKJ2izqS40YbIx6DDI1ty8Ttjre4tEH3Mi9K8dlh3FTbcre29lj21I nfGkR+Qpq8FEY6QZrQxWXOq8x3W2nrai9geg/gHES3fJDQjugNi9WUX0WXpj2B8KzfCEZ5 9zvG60Eoitcz4TIuyrvYcikcwZcIZNI= X-MC-Unique: s5uXk66ZMjmuVfQUauv2IA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 18/25] mirror: make mirror_flush a coroutine_fn, do not use co_wrappers Date: Tue, 25 Apr 2023 15:13:52 +0200 Message-Id: <20230425131359.259007-19-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428887742100001 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini mirror_flush calls a mixed function blk_flush but it is only called from mirror_run; so call the coroutine version and make mirror_flush a coroutine_fn too. Signed-off-by: Paolo Bonzini Message-Id: <20230309084456.304669-4-pbonzini@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/mirror.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block/mirror.c b/block/mirror.c index 663e2b7002..af9bbd23d4 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -886,9 +886,9 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJo= b *s) /* Called when going out of the streaming phase to flush the bulk of the * data to the medium, or just before completing. */ -static int mirror_flush(MirrorBlockJob *s) +static int coroutine_fn mirror_flush(MirrorBlockJob *s) { - int ret =3D blk_flush(s->target); + int ret =3D blk_co_flush(s->target); if (ret < 0) { if (mirror_error_action(s, false, -ret) =3D=3D BLOCK_ERROR_ACTION_= REPORT) { s->ret =3D ret; --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428843; cv=none; d=zohomail.com; s=zohoarc; b=Ux3NN/mfi59RVlToOP537rWQ7WesbWWTNNKENKUFTryP5xZ1u+r3cSuLRaJXk+AWErdRJDj+x1paIAlpyDwhI9VG7/r/PiERTVwLpvDKIY67rqUrz2otmOLtBOWtiBWxl6hcH111z74ePgh/6pOW9HVY6vXswc82mKx9YyeuMQc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428843; 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; bh=Fhyni0yQP+q7GmZm9HRoi5upQSbmFq+MED/2LTroyrk=; b=Gt8uwOrWoP+U94sV1LKAY8xMw0hTfw1IZNmGrT+21r1xBbDumcKUyMzr3fEs8zL4MdjY4Qrn8zvi86EhrivxyU2BpF1r18wrTQlN+w+nCZbFdfMJxv7Z8ETUqlRmjaqd9xKEGG7zzmId7lltgGvvpEZUkP1VgryOpk0TKN3yx8c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428843839643.9627163273458; Tue, 25 Apr 2023 06:20:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIX3-0000Ks-1O; Tue, 25 Apr 2023 09:16:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVN-0006l5-Ga for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006bv-HK for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:48 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-164-PZvUZbWOMvSixG_ojSK13A-1; Tue, 25 Apr 2023 09:14:22 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 667B028135A3; Tue, 25 Apr 2023 13:14:22 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA68840C201F; Tue, 25 Apr 2023 13:14:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428465; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Fhyni0yQP+q7GmZm9HRoi5upQSbmFq+MED/2LTroyrk=; b=FhhyDLfYufEjJMuvQSeuHyyVYdwoNF/Pp7Hf0s9BbDYw4Gi9h4wor4G23KuiE6x7GE8kWz JhOxVB1DMlVkmCtKDe0tMx0SvVjkJwiHKJLM6Q1t5tEi74/nxBJTUgzPg/SvoUY/pjRobn bRrJERo4kX5k+sHi8/3m6gtoCgLVX3E= X-MC-Unique: PZvUZbWOMvSixG_ojSK13A-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 19/25] nbd: mark more coroutine_fns, do not use co_wrappers Date: Tue, 25 Apr 2023 15:13:53 +0200 Message-Id: <20230425131359.259007-20-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428845529100007 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Signed-off-by: Paolo Bonzini Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- nbd/server.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 4f5c42f84d..e239c2890f 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1409,8 +1409,8 @@ nbd_read_eof(NBDClient *client, void *buffer, size_t = size, Error **errp) return 1; } =20 -static int nbd_receive_request(NBDClient *client, NBDRequest *request, - Error **errp) +static int coroutine_fn nbd_receive_request(NBDClient *client, NBDRequest = *request, + Error **errp) { uint8_t buf[NBD_REQUEST_SIZE]; uint32_t magic; @@ -1893,12 +1893,12 @@ static inline void set_be_simple_reply(NBDSimpleRep= ly *reply, uint64_t error, stq_be_p(&reply->handle, handle); } =20 -static int nbd_co_send_simple_reply(NBDClient *client, - uint64_t handle, - uint32_t error, - void *data, - size_t len, - Error **errp) +static int coroutine_fn nbd_co_send_simple_reply(NBDClient *client, + uint64_t handle, + uint32_t error, + void *data, + size_t len, + Error **errp) { NBDSimpleReply reply; int nbd_err =3D system_errno_to_nbd_errno(error); @@ -2036,8 +2036,8 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDCl= ient *client, stl_be_p(&chunk.length, pnum); ret =3D nbd_co_send_iov(client, iov, 1, errp); } else { - ret =3D blk_pread(exp->common.blk, offset + progress, pnum, - data + progress, 0); + ret =3D blk_co_pread(exp->common.blk, offset + progress, pnum, + data + progress, 0); if (ret < 0) { error_setg_errno(errp, -ret, "reading from file failed"); break; @@ -2196,9 +2196,9 @@ static int coroutine_fn blockalloc_to_extents(BlockBa= ckend *blk, * @ea is converted to BE by the function * @last controls whether NBD_REPLY_FLAG_DONE is sent. */ -static int nbd_co_send_extents(NBDClient *client, uint64_t handle, - NBDExtentArray *ea, - bool last, uint32_t context_id, Error **err= p) +static int coroutine_fn +nbd_co_send_extents(NBDClient *client, uint64_t handle, NBDExtentArray *ea, + bool last, uint32_t context_id, Error **errp) { NBDStructuredMeta chunk; struct iovec iov[] =3D { @@ -2275,10 +2275,10 @@ static void bitmap_to_extents(BdrvDirtyBitmap *bitm= ap, bdrv_dirty_bitmap_unlock(bitmap); } =20 -static int nbd_co_send_bitmap(NBDClient *client, uint64_t handle, - BdrvDirtyBitmap *bitmap, uint64_t offset, - uint32_t length, bool dont_fragment, bool la= st, - uint32_t context_id, Error **errp) +static int coroutine_fn nbd_co_send_bitmap(NBDClient *client, uint64_t han= dle, + BdrvDirtyBitmap *bitmap, uint64= _t offset, + uint32_t length, bool dont_frag= ment, bool last, + uint32_t context_id, Error **er= rp) { unsigned int nb_extents =3D dont_fragment ? 1 : NBD_MAX_BLOCK_STATUS_E= XTENTS; g_autoptr(NBDExtentArray) ea =3D nbd_extent_array_new(nb_extents); @@ -2295,8 +2295,8 @@ static int nbd_co_send_bitmap(NBDClient *client, uint= 64_t handle, * to the client (although the caller may still need to disconnect after * reporting the error). */ -static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request, - Error **errp) +static int coroutine_fn nbd_co_receive_request(NBDRequestData *req, NBDReq= uest *request, + Error **errp) { NBDClient *client =3D req->client; int valid_flags; @@ -2444,7 +2444,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *cl= ient, NBDRequest *request, data, request->len, errp); } =20 - ret =3D blk_pread(exp->common.blk, request->from, request->len, data, = 0); + ret =3D blk_co_pread(exp->common.blk, request->from, request->len, dat= a, 0); if (ret < 0) { return nbd_send_generic_reply(client, request->handle, ret, "reading from file failed", errp); @@ -2511,8 +2511,8 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, if (request->flags & NBD_CMD_FLAG_FUA) { flags |=3D BDRV_REQ_FUA; } - ret =3D blk_pwrite(exp->common.blk, request->from, request->len, d= ata, - flags); + ret =3D blk_co_pwrite(exp->common.blk, request->from, request->len= , data, + flags); return nbd_send_generic_reply(client, request->handle, ret, "writing to file failed", errp); =20 @@ -2527,8 +2527,8 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, if (request->flags & NBD_CMD_FLAG_FAST_ZERO) { flags |=3D BDRV_REQ_NO_FALLBACK; } - ret =3D blk_pwrite_zeroes(exp->common.blk, request->from, request-= >len, - flags); + ret =3D blk_co_pwrite_zeroes(exp->common.blk, request->from, reque= st->len, + flags); return nbd_send_generic_reply(client, request->handle, ret, "writing to file failed", errp); =20 --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428884; cv=none; d=zohomail.com; s=zohoarc; b=SkyZmqcokrYdi+LeHFSjEeJUuC6Gj8ltr7NBlmgPwW21po/na2/lLTSLvBWZCFlTTV8nJ1fdJIbaCbnC/2yzfXsJNx9/mtihYmm4chvjgSph+sZ48rmUr7st3BQbWIW0C62PW8pT7E98V4yKVHx/zk6drLrDmXekxXS6M7cUk0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428884; 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; bh=ZuQuf0oyAdKgbihbApNW080nlqs2h3IQDaIqmyz0AF8=; b=Nr8RbzCVJwW9OsXycg6MVXSp3uVO5zhmlN7utU6J/TujEXM3qGHMnf2y/uneyu3nf0wikVsI6/0sGujsaQB1MNaTbP487JAjnEVq1pSzEU8zeRsOB7h5NzjQIOd58qK1Ugr/J2wCzZ1XJCbnoQtCWhW6rNNzNjZwQoFIrLwkrWE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682428884097349.6712031506074; Tue, 25 Apr 2023 06:21:24 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIX6-0000RG-Q5; Tue, 25 Apr 2023 09:16:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVK-0006fu-FA for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006cP-6G for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:46 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-138-T0szTnGIO2qRga-yS0R_qQ-1; Tue, 25 Apr 2023 09:14:23 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 56B57101A553; Tue, 25 Apr 2023 13:14:23 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E20D40C2064; Tue, 25 Apr 2023 13:14:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428469; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZuQuf0oyAdKgbihbApNW080nlqs2h3IQDaIqmyz0AF8=; b=TukFV7MZ6ObycZxL//J2+K6Wixe8CvspX2Qu2VJhic+1z2ZowAN4/wSVHEJ3xeqvKslK6n y1zvPCqc880SDTHj4EMNtPIO9xLSJ0os80ptuZziYOHCjbdLYIXNZtsuQWREIxDNttggyx xSTRknYh1i8vRrkiYuZJKnTd6eu2qVU= X-MC-Unique: T0szTnGIO2qRga-yS0R_qQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 20/25] 9pfs: mark more coroutine_fns Date: Tue, 25 Apr 2023 15:13:54 +0200 Message-Id: <20230425131359.259007-21-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428885325100002 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Signed-off-by: Paolo Bonzini Message-Id: <20230309084456.304669-6-pbonzini@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- hw/9pfs/9p.h | 4 ++-- hw/9pfs/codir.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/hw/9pfs/9p.h b/hw/9pfs/9p.h index 2fce4140d1..1b0d805b9c 100644 --- a/hw/9pfs/9p.h +++ b/hw/9pfs/9p.h @@ -203,7 +203,7 @@ typedef struct V9fsDir { QemuMutex readdir_mutex_L; } V9fsDir; =20 -static inline void v9fs_readdir_lock(V9fsDir *dir) +static inline void coroutine_fn v9fs_readdir_lock(V9fsDir *dir) { if (dir->proto_version =3D=3D V9FS_PROTO_2000U) { qemu_co_mutex_lock(&dir->readdir_mutex_u); @@ -212,7 +212,7 @@ static inline void v9fs_readdir_lock(V9fsDir *dir) } } =20 -static inline void v9fs_readdir_unlock(V9fsDir *dir) +static inline void coroutine_fn v9fs_readdir_unlock(V9fsDir *dir) { if (dir->proto_version =3D=3D V9FS_PROTO_2000U) { qemu_co_mutex_unlock(&dir->readdir_mutex_u); diff --git a/hw/9pfs/codir.c b/hw/9pfs/codir.c index 7ba63be489..2068a4779d 100644 --- a/hw/9pfs/codir.c +++ b/hw/9pfs/codir.c @@ -68,9 +68,9 @@ int coroutine_fn v9fs_co_readdir(V9fsPDU *pdu, V9fsFidSta= te *fidp, * * See v9fs_co_readdir_many() (as its only user) below for details. */ -static int do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, - struct V9fsDirEnt **entries, off_t offset, - int32_t maxsize, bool dostat) +static int coroutine_fn +do_readdir_many(V9fsPDU *pdu, V9fsFidState *fidp, struct V9fsDirEnt **entr= ies, + off_t offset, int32_t maxsize, bool dostat) { V9fsState *s =3D pdu->s; V9fsString name; --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682429035; cv=none; d=zohomail.com; s=zohoarc; b=LS9kvPCTLR3DW6f3Q0EyFskLhBM2nI+QTPZg1PA+mKGsP27ovYlq5J5ywpwaLEJdXCxEhqmqB6Oes4+qxgGF8zez+RQk9Ig/4z8276DF/YoDW8iK9DiA0GwsPUdaJfjn4hnB7HWlOKqlwETb82sQq1rv2+RRIzDkTFQ8C+9QMGQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682429035; 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; bh=JDK2bWRoL1fPnb9JRW8yfhaM5CIPpA07SEoVN8s0gKI=; b=LJSVub2MZsacqFb/wBfMSFx9mO1QWNQnei7resycLV7G0AI9h4+XKszRXmRtb0FCqi+3MZJwhgDavetxQKPkY6qd4TjsAaiUop0049pY5LpFaOHPiaRH6JyM5fmXHIiFuE5mGEx5HUVrcxvzBtLymzagVXBMrUt3ELhfSG0EB5M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168242903529557.267049417339194; Tue, 25 Apr 2023 06:23:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIZ4-0002Qk-L5; Tue, 25 Apr 2023 09:18:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVU-0006rU-4z for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:15:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006bx-Ph for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:52 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-344-NddgkydNPPSRGeGsK_Ap5A-1; Tue, 25 Apr 2023 09:14:24 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 47DF98828C1; Tue, 25 Apr 2023 13:14:24 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8E41D40C2064; Tue, 25 Apr 2023 13:14:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428466; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JDK2bWRoL1fPnb9JRW8yfhaM5CIPpA07SEoVN8s0gKI=; b=dQu1t2tiXv2Rs4IqlOs9SKxqIbRyvs+V+/rS4NYzfp8+nXquOIob8A5NbCdP8URsO6YAsQ k/d7kdTOQzthtZ3cPd7yBOTBasghQNh5glSW0XDldxrp9XjDeAFkSLBQDOHDmlLMeAMdup vzXZc/SUsm3QMkZEVyB/pVoc/AfCqvo= X-MC-Unique: NddgkydNPPSRGeGsK_Ap5A-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 21/25] qemu-pr-helper: mark more coroutine_fns Date: Tue, 25 Apr 2023 15:13:55 +0200 Message-Id: <20230425131359.259007-22-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682429036291100002 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini do_sgio can suspend via the coroutine function thread_pool_submit_co, so it has to be coroutine_fn as well---and the same is true of all its direct and indirect callers. Signed-off-by: Paolo Bonzini Message-Id: <20230309084456.304669-7-pbonzini@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- scsi/qemu-pr-helper.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/scsi/qemu-pr-helper.c b/scsi/qemu-pr-helper.c index e9b3ad259a..a857e80c03 100644 --- a/scsi/qemu-pr-helper.c +++ b/scsi/qemu-pr-helper.c @@ -177,8 +177,8 @@ static int do_sgio_worker(void *opaque) return status; } =20 -static int do_sgio(int fd, const uint8_t *cdb, uint8_t *sense, - uint8_t *buf, int *sz, int dir) +static int coroutine_fn do_sgio(int fd, const uint8_t *cdb, uint8_t *sense, + uint8_t *buf, int *sz, int dir) { int r; =20 @@ -319,7 +319,7 @@ static SCSISense mpath_generic_sense(int r) } } =20 -static int mpath_reconstruct_sense(int fd, int r, uint8_t *sense) +static int coroutine_fn mpath_reconstruct_sense(int fd, int r, uint8_t *se= nse) { switch (r) { case MPATH_PR_SUCCESS: @@ -371,8 +371,8 @@ static int mpath_reconstruct_sense(int fd, int r, uint8= _t *sense) } } =20 -static int multipath_pr_in(int fd, const uint8_t *cdb, uint8_t *sense, - uint8_t *data, int sz) +static int coroutine_fn multipath_pr_in(int fd, const uint8_t *cdb, uint8_= t *sense, + uint8_t *data, int sz) { int rq_servact =3D cdb[1]; struct prin_resp resp; @@ -426,8 +426,8 @@ static int multipath_pr_in(int fd, const uint8_t *cdb, = uint8_t *sense, return mpath_reconstruct_sense(fd, r, sense); } =20 -static int multipath_pr_out(int fd, const uint8_t *cdb, uint8_t *sense, - const uint8_t *param, int sz) +static int coroutine_fn multipath_pr_out(int fd, const uint8_t *cdb, uint8= _t *sense, + const uint8_t *param, int sz) { int rq_servact =3D cdb[1]; int rq_scope =3D cdb[2] >> 4; @@ -544,8 +544,8 @@ static int multipath_pr_out(int fd, const uint8_t *cdb,= uint8_t *sense, } #endif =20 -static int do_pr_in(int fd, const uint8_t *cdb, uint8_t *sense, - uint8_t *data, int *resp_sz) +static int coroutine_fn do_pr_in(int fd, const uint8_t *cdb, uint8_t *sens= e, + uint8_t *data, int *resp_sz) { #ifdef CONFIG_MPATH if (is_mpath(fd)) { @@ -562,8 +562,8 @@ static int do_pr_in(int fd, const uint8_t *cdb, uint8_t= *sense, SG_DXFER_FROM_DEV); } =20 -static int do_pr_out(int fd, const uint8_t *cdb, uint8_t *sense, - const uint8_t *param, int sz) +static int coroutine_fn do_pr_out(int fd, const uint8_t *cdb, uint8_t *sen= se, + const uint8_t *param, int sz) { int resp_sz; =20 --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428909; cv=none; d=zohomail.com; s=zohoarc; b=lpR4BDzAeg/snkf5lUm807nega/Wdsyk3CYv8DIWeurTSm3lW28QnjpiIqGu9L4OixUwLSbLM3Jxu6beTpVvmjGDJyARdDbrBGyeaujVLLVKNkKGpOr8pOOBSIHzDTahtfGvWogp8CZlhVWFLh59+dxht35rert/+3Mjohw0zHI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428909; 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; bh=xvmCO97HQyFtVcu1X/n44IvRTXOGcYA5BRP/Sy3DSU8=; b=KabjFQTFdhV/u12/anRRu+4+S1Eat6RBPHxr/TilxPVUAWkZc6GAfTrvOr5X89p3f4UQ6xr7zTIGN7jDdJA6kAYnZ20SECz79tmDAKNwnpSQ+Uq/0QxA3UdAvaQA2qEkW89iGDqEneITgqsSYXNNkRco/UxzbiesTGPsE4V+Pew= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16824289091781022.1792574366137; Tue, 25 Apr 2023 06:21:49 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIYz-0002Dh-FK; Tue, 25 Apr 2023 09:18:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVU-0006rT-4l for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:15:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVH-0006cJ-Mg for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:53 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-210-lbVGSwetMJKXHerGpR1Riw-1; Tue, 25 Apr 2023 09:14:25 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 372D93C10228; Tue, 25 Apr 2023 13:14:25 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EC8240C201F; Tue, 25 Apr 2023 13:14:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428469; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xvmCO97HQyFtVcu1X/n44IvRTXOGcYA5BRP/Sy3DSU8=; b=IixQwMbx92yDnAnEMDFcShWwdybiCNKUVDKtnE9vKWmyDfUeaTRZnKomyuXvBJz1CF9THc 9EJLDc8zpIJEfLmFA35XzTe2FclML1SEgrOUEbUQGCdWHxwsmBiobd7RBEMTO1ZV3DaMUA nkdsqtRRbMNFWKe0A/TqlEG+LYj/hik= X-MC-Unique: lbVGSwetMJKXHerGpR1Riw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 22/25] tests: mark more coroutine_fns Date: Tue, 25 Apr 2023 15:13:56 +0200 Message-Id: <20230425131359.259007-23-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428909910100001 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Signed-off-by: Paolo Bonzini Message-Id: <20230309084456.304669-8-pbonzini@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- tests/unit/test-thread-pool.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test-thread-pool.c b/tests/unit/test-thread-pool.c index 448fbf7e5f..1483e53473 100644 --- a/tests/unit/test-thread-pool.c +++ b/tests/unit/test-thread-pool.c @@ -70,7 +70,7 @@ static void test_submit_aio(void) g_assert_cmpint(data.ret, =3D=3D, 0); } =20 -static void co_test_cb(void *opaque) +static void coroutine_fn co_test_cb(void *opaque) { WorkerTestData *data =3D opaque; =20 --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682429032; cv=none; d=zohomail.com; s=zohoarc; b=D3YsFvpTX9vkT6/KY7sJBozsztwNY+peY8vI8s1vkhawebqtfe3Dp3YMgui5PmKDGjZpb1RRW4w4VSY4FXhgiluEmRhE0zxI0WotTGR7NXnNm9bXSVb+CvXBsnfn/qITaYHBz03zGqjHbgwZxxi4wP1l+jIqv54GGcyLitJze7Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682429032; 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; bh=G5LaIixywHQ5ouRaZs16frq4M+d3Q1atIcWQp1CnFh0=; b=LdaWP4GHNsf/1yLMSB+js1ne8tbpnlDpjbD4o5V2b5Capr7oz9bdAgRZa6y9TJDOe7d48dqPlYcnvKLxj8qAuB83AU6hmQCC956dQoUibguJOHzEwGjeo2VLDrqUFpAXyK3bbYR8LwgLRuHES2KtJkt4jVLFM93wu8iqrwnDpVQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682429032541362.867914716982; Tue, 25 Apr 2023 06:23:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIVi-0007La-Og; Tue, 25 Apr 2023 09:15:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVK-0006eJ-4F for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:46 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006cX-10 for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:45 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-605-X4hvrHuSP76-auECGXGEaw-1; Tue, 25 Apr 2023 09:14:26 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 42AE9185A79C; Tue, 25 Apr 2023 13:14:26 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6DD8C40C2064; Tue, 25 Apr 2023 13:14:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428469; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=G5LaIixywHQ5ouRaZs16frq4M+d3Q1atIcWQp1CnFh0=; b=bg9CmmN4PS9bN5e3qhQzFIKCuraFqyGbvCCaSYymbKBvxU1EH+nJ8KH8RQ33xc7ShU46Cp IZwdhbj/THmCm5B2fheyro3C0sw+ityChIQQAW5iOyoNiKlpH2wd062xOW8BUl5yIzFUyh Ki/g1ErAlmDSS/7Pio39aprT7kCDdzE= X-MC-Unique: X4hvrHuSP76-auECGXGEaw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 23/25] qcow2: mark various functions as coroutine_fn and GRAPH_RDLOCK Date: Tue, 25 Apr 2023 15:13:57 +0200 Message-Id: <20230425131359.259007-24-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682429033039100001 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Functions that can do I/O (including calling bdrv_is_allocated and bdrv_block_status functions) are prime candidates for being coroutine_fns. Make the change for those that are themselves called only from coroutine_fns. Also annotate that they are called with the graph rdlock taken, thus allowing them to call bdrv_co_*() functions for I/O. Signed-off-by: Paolo Bonzini Message-Id: <20230309084456.304669-9-pbonzini@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/qcow2.h | 15 ++++++++------- block/qcow2-bitmap.c | 2 +- block/qcow2-cluster.c | 21 +++++++++++++-------- block/qcow2-refcount.c | 8 ++++---- block/qcow2-snapshot.c | 25 +++++++++++++------------ block/qcow2.c | 27 ++++++++++++++------------- 6 files changed, 53 insertions(+), 45 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index c59e33c01c..c75decc38a 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -862,9 +862,9 @@ int64_t qcow2_refcount_area(BlockDriverState *bs, uint6= 4_t offset, uint64_t new_refblock_offset); =20 int64_t qcow2_alloc_clusters(BlockDriverState *bs, uint64_t size); -int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset, - int64_t nb_clusters); -int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size); +int64_t coroutine_fn qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_= t offset, + int64_t nb_clusters); +int64_t coroutine_fn qcow2_alloc_bytes(BlockDriverState *bs, int size); void qcow2_free_clusters(BlockDriverState *bs, int64_t offset, int64_t size, enum qcow2_discard_type type); @@ -894,7 +894,7 @@ int qcow2_change_refcount_order(BlockDriverState *bs, i= nt refcount_order, BlockDriverAmendStatusCB *status_cb, void *cb_opaque, Error **errp); int coroutine_fn GRAPH_RDLOCK qcow2_shrink_reftable(BlockDriverState *bs); -int64_t qcow2_get_last_cluster(BlockDriverState *bs, int64_t size); +int64_t coroutine_fn qcow2_get_last_cluster(BlockDriverState *bs, int64_t = size); int coroutine_fn qcow2_detect_metadata_preallocation(BlockDriverState *bs); =20 /* qcow2-cluster.c functions */ @@ -924,7 +924,7 @@ void qcow2_parse_compressed_l2_entry(BlockDriverState *= bs, uint64_t l2_entry, int coroutine_fn GRAPH_RDLOCK qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m); =20 -void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m); +void coroutine_fn qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Me= ta *m); int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset, uint64_t bytes, enum qcow2_discard_type type, bool full_discard); @@ -951,7 +951,8 @@ int qcow2_snapshot_load_tmp(BlockDriverState *bs, Error **errp); =20 void qcow2_free_snapshots(BlockDriverState *bs); -int qcow2_read_snapshots(BlockDriverState *bs, Error **errp); +int coroutine_fn GRAPH_RDLOCK +qcow2_read_snapshots(BlockDriverState *bs, Error **errp); int qcow2_write_snapshots(BlockDriverState *bs); =20 int coroutine_fn GRAPH_RDLOCK @@ -994,7 +995,7 @@ bool coroutine_fn qcow2_load_dirty_bitmaps(BlockDriverS= tate *bs, bool qcow2_get_bitmap_info_list(BlockDriverState *bs, Qcow2BitmapInfoList **info_list, Error **e= rrp); int qcow2_reopen_bitmaps_rw(BlockDriverState *bs, Error **errp); -int qcow2_truncate_bitmaps_check(BlockDriverState *bs, Error **errp); +int coroutine_fn qcow2_truncate_bitmaps_check(BlockDriverState *bs, Error = **errp); bool qcow2_store_persistent_dirty_bitmaps(BlockDriverState *bs, bool release_stored, Error **err= p); int qcow2_reopen_bitmaps_ro(BlockDriverState *bs, Error **errp); diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 5f456a2785..a952fd58d8 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -1221,7 +1221,7 @@ out: } =20 /* Checks to see if it's safe to resize bitmaps */ -int qcow2_truncate_bitmaps_check(BlockDriverState *bs, Error **errp) +int coroutine_fn qcow2_truncate_bitmaps_check(BlockDriverState *bs, Error = **errp) { BDRVQcow2State *s =3D bs->opaque; Qcow2BitmapList *bm_list; diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index a9e6622fe3..39cda7f907 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1126,7 +1126,7 @@ err: * Frees the allocated clusters because the request failed and they won't * actually be linked. */ -void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m) +void coroutine_fn qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Me= ta *m) { BDRVQcow2State *s =3D bs->opaque; if (!has_data_file(bs) && !m->keep_old_clusters) { @@ -1156,9 +1156,11 @@ void qcow2_alloc_cluster_abort(BlockDriverState *bs,= QCowL2Meta *m) * * Returns 0 on success, -errno on failure. */ -static int calculate_l2_meta(BlockDriverState *bs, uint64_t host_cluster_o= ffset, - uint64_t guest_offset, unsigned bytes, - uint64_t *l2_slice, QCowL2Meta **m, bool keep= _old) +static int coroutine_fn calculate_l2_meta(BlockDriverState *bs, + uint64_t host_cluster_offset, + uint64_t guest_offset, unsigned = bytes, + uint64_t *l2_slice, QCowL2Meta *= *m, + bool keep_old) { BDRVQcow2State *s =3D bs->opaque; int sc_index, l2_index =3D offset_to_l2_slice_index(s, guest_offset); @@ -1599,8 +1601,10 @@ out: * function has been waiting for another request and the allocation must be * restarted, but the whole request should not be failed. */ -static int do_alloc_cluster_offset(BlockDriverState *bs, uint64_t guest_of= fset, - uint64_t *host_offset, uint64_t *nb_clu= sters) +static int coroutine_fn do_alloc_cluster_offset(BlockDriverState *bs, + uint64_t guest_offset, + uint64_t *host_offset, + uint64_t *nb_clusters) { BDRVQcow2State *s =3D bs->opaque; =20 @@ -2065,8 +2069,9 @@ static int zero_in_l2_slice(BlockDriverState *bs, uin= t64_t offset, return nb_clusters; } =20 -static int zero_l2_subclusters(BlockDriverState *bs, uint64_t offset, - unsigned nb_subclusters) +static int coroutine_fn +zero_l2_subclusters(BlockDriverState *bs, uint64_t offset, + unsigned nb_subclusters) { BDRVQcow2State *s =3D bs->opaque; uint64_t *l2_slice; diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index b092f89da9..b2a81ff707 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1030,8 +1030,8 @@ int64_t qcow2_alloc_clusters(BlockDriverState *bs, ui= nt64_t size) return offset; } =20 -int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset, - int64_t nb_clusters) +int64_t coroutine_fn qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_= t offset, + int64_t nb_clusters) { BDRVQcow2State *s =3D bs->opaque; uint64_t cluster_index, refcount; @@ -1069,7 +1069,7 @@ int64_t qcow2_alloc_clusters_at(BlockDriverState *bs,= uint64_t offset, =20 /* only used to allocate compressed sectors. We try to allocate contiguous sectors. size must be <=3D cluster_size */ -int64_t qcow2_alloc_bytes(BlockDriverState *bs, int size) +int64_t coroutine_fn qcow2_alloc_bytes(BlockDriverState *bs, int size) { BDRVQcow2State *s =3D bs->opaque; int64_t offset; @@ -3685,7 +3685,7 @@ out: return ret; } =20 -int64_t qcow2_get_last_cluster(BlockDriverState *bs, int64_t size) +int64_t coroutine_fn qcow2_get_last_cluster(BlockDriverState *bs, int64_t = size) { BDRVQcow2State *s =3D bs->opaque; int64_t i; diff --git a/block/qcow2-snapshot.c b/block/qcow2-snapshot.c index 62e8a0335d..92e47978bf 100644 --- a/block/qcow2-snapshot.c +++ b/block/qcow2-snapshot.c @@ -77,10 +77,11 @@ void qcow2_free_snapshots(BlockDriverState *bs) * qcow2_check_refcounts() does not do anything with snapshots' * extra data.) */ -static int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair, - int *nb_clusters_reduced, - int *extra_data_dropped, - Error **errp) +static coroutine_fn GRAPH_RDLOCK +int qcow2_do_read_snapshots(BlockDriverState *bs, bool repair, + int *nb_clusters_reduced, + int *extra_data_dropped, + Error **errp) { BDRVQcow2State *s =3D bs->opaque; QCowSnapshotHeader h; @@ -108,7 +109,7 @@ static int qcow2_do_read_snapshots(BlockDriverState *bs= , bool repair, =20 /* Read statically sized part of the snapshot header */ offset =3D ROUND_UP(offset, 8); - ret =3D bdrv_pread(bs->file, offset, sizeof(h), &h, 0); + ret =3D bdrv_co_pread(bs->file, offset, sizeof(h), &h, 0); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to read snapshot table"); goto fail; @@ -146,8 +147,8 @@ static int qcow2_do_read_snapshots(BlockDriverState *bs= , bool repair, } =20 /* Read known extra data */ - ret =3D bdrv_pread(bs->file, offset, - MIN(sizeof(extra), sn->extra_data_size), &extra, = 0); + ret =3D bdrv_co_pread(bs->file, offset, + MIN(sizeof(extra), sn->extra_data_size), &extr= a, 0); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to read snapshot table"); goto fail; @@ -184,8 +185,8 @@ static int qcow2_do_read_snapshots(BlockDriverState *bs= , bool repair, /* Store unknown extra data */ unknown_extra_data_size =3D sn->extra_data_size - sizeof(extra= ); sn->unknown_extra_data =3D g_malloc(unknown_extra_data_size); - ret =3D bdrv_pread(bs->file, offset, unknown_extra_data_size, - sn->unknown_extra_data, 0); + ret =3D bdrv_co_pread(bs->file, offset, unknown_extra_data_siz= e, + sn->unknown_extra_data, 0); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to read snapshot table"); @@ -196,7 +197,7 @@ static int qcow2_do_read_snapshots(BlockDriverState *bs= , bool repair, =20 /* Read snapshot ID */ sn->id_str =3D g_malloc(id_str_size + 1); - ret =3D bdrv_pread(bs->file, offset, id_str_size, sn->id_str, 0); + ret =3D bdrv_co_pread(bs->file, offset, id_str_size, sn->id_str, 0= ); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to read snapshot table"); goto fail; @@ -206,7 +207,7 @@ static int qcow2_do_read_snapshots(BlockDriverState *bs= , bool repair, =20 /* Read snapshot name */ sn->name =3D g_malloc(name_size + 1); - ret =3D bdrv_pread(bs->file, offset, name_size, sn->name, 0); + ret =3D bdrv_co_pread(bs->file, offset, name_size, sn->name, 0); if (ret < 0) { error_setg_errno(errp, -ret, "Failed to read snapshot table"); goto fail; @@ -261,7 +262,7 @@ fail: return ret; } =20 -int qcow2_read_snapshots(BlockDriverState *bs, Error **errp) +int coroutine_fn qcow2_read_snapshots(BlockDriverState *bs, Error **errp) { return qcow2_do_read_snapshots(bs, false, NULL, NULL, errp); } diff --git a/block/qcow2.c b/block/qcow2.c index 30fd53fa64..fe5def438e 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -199,10 +199,10 @@ qcow2_extract_crypto_opts(QemuOpts *opts, const char = *fmt, Error **errp) * unknown magic is skipped (future extension this version knows nothing a= bout) * return 0 upon success, non-0 otherwise */ -static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offs= et, - uint64_t end_offset, void **p_feature_tab= le, - int flags, bool *need_update_header, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset, + uint64_t end_offset, void **p_feature_table, + int flags, bool *need_update_header, Error **errp) { BDRVQcow2State *s =3D bs->opaque; QCowExtension ext; @@ -228,7 +228,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, = uint64_t start_offset, printf("attempting to read extended header in offset %lu\n", offse= t); #endif =20 - ret =3D bdrv_pread(bs->file, offset, sizeof(ext), &ext, 0); + ret =3D bdrv_co_pread(bs->file, offset, sizeof(ext), &ext, 0); if (ret < 0) { error_setg_errno(errp, -ret, "qcow2_read_extension: ERROR: " "pread fail from offset %" PRIu64, offset); @@ -256,7 +256,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, = uint64_t start_offset, sizeof(bs->backing_format)); return 2; } - ret =3D bdrv_pread(bs->file, offset, ext.len, bs->backing_form= at, 0); + ret =3D bdrv_co_pread(bs->file, offset, ext.len, bs->backing_f= ormat, 0); if (ret < 0) { error_setg_errno(errp, -ret, "ERROR: ext_backing_format: " "Could not read format name"); @@ -272,7 +272,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, = uint64_t start_offset, case QCOW2_EXT_MAGIC_FEATURE_TABLE: if (p_feature_table !=3D NULL) { void *feature_table =3D g_malloc0(ext.len + 2 * sizeof(Qco= w2Feature)); - ret =3D bdrv_pread(bs->file, offset, ext.len, feature_tabl= e, 0); + ret =3D bdrv_co_pread(bs->file, offset, ext.len, feature_t= able, 0); if (ret < 0) { error_setg_errno(errp, -ret, "ERROR: ext_feature_table= : " "Could not read table"); @@ -298,7 +298,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, = uint64_t start_offset, return -EINVAL; } =20 - ret =3D bdrv_pread(bs->file, offset, ext.len, &s->crypto_heade= r, 0); + ret =3D bdrv_co_pread(bs->file, offset, ext.len, &s->crypto_he= ader, 0); if (ret < 0) { error_setg_errno(errp, -ret, "Unable to read CRYPTO header extension"); @@ -354,7 +354,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, = uint64_t start_offset, break; } =20 - ret =3D bdrv_pread(bs->file, offset, ext.len, &bitmaps_ext, 0); + ret =3D bdrv_co_pread(bs->file, offset, ext.len, &bitmaps_ext,= 0); if (ret < 0) { error_setg_errno(errp, -ret, "bitmaps_ext: " "Could not read ext header"); @@ -418,7 +418,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, = uint64_t start_offset, case QCOW2_EXT_MAGIC_DATA_FILE: { s->image_data_file =3D g_malloc0(ext.len + 1); - ret =3D bdrv_pread(bs->file, offset, ext.len, s->image_data_fi= le, 0); + ret =3D bdrv_co_pread(bs->file, offset, ext.len, s->image_data= _file, 0); if (ret < 0) { error_setg_errno(errp, -ret, "ERROR: Could not read data file name"); @@ -442,7 +442,7 @@ static int qcow2_read_extensions(BlockDriverState *bs, = uint64_t start_offset, uext->len =3D ext.len; QLIST_INSERT_HEAD(&s->unknown_header_ext, uext, next); =20 - ret =3D bdrv_pread(bs->file, offset, uext->len, uext->data= , 0); + ret =3D bdrv_co_pread(bs->file, offset, uext->len, uext->d= ata, 0); if (ret < 0) { error_setg_errno(errp, -ret, "ERROR: unknown extension= : " "Could not read data"); @@ -1241,8 +1241,9 @@ static void qcow2_update_options_abort(BlockDriverSta= te *bs, qapi_free_QCryptoBlockOpenOptions(r->crypto_opts); } =20 -static int qcow2_update_options(BlockDriverState *bs, QDict *options, - int flags, Error **errp) +static int coroutine_fn +qcow2_update_options(BlockDriverState *bs, QDict *options, int flags, + Error **errp) { Qcow2ReopenState r =3D {}; int ret; --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682428938; cv=none; d=zohomail.com; s=zohoarc; b=RTLN/gCO3/iwDjWAeQ3xtmSH4Gc4K0AkZmZoxecWdYr1OyBkBm0wdKex1dtEXdjFUv7F+VuUyWH08tzYay1bDbetfyXCW18VDDoRtacOhUgyGqmpKRPNGRfH3zd9AkqVwWnpKUhYNUof29YLWEeIA+S3v7rUHzUOIjiULuK71wo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682428938; 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; bh=goC0+V3ApTSiKsw11bGVSK/Vwd7KgTol7PUe4lqysLo=; b=e5HkYjWDO6j29l1moQnptimWWBzHHdWThTArD1XpMgTMIETqEYKoZYuDJeIXO9hqJta62VytLSPW2yY9AQqfTffeApp9aoxz9HZPWRa4PVlrVkP73BzVpajjiEqjm64gE1xQ6UAO1Si5agwfxFBNO/XD22H0PGF8SntHDw4vyCw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 168242893819576.62976141612398; Tue, 25 Apr 2023 06:22:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIZ6-0002Xp-E4; Tue, 25 Apr 2023 09:18:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVU-0006rW-5S for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:15:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006ce-Vt for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:53 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-394-FTFTurJIPG6sACkM5UO9pQ-1; Tue, 25 Apr 2023 09:14:27 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 343538828C7; Tue, 25 Apr 2023 13:14:27 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7A61340C2064; Tue, 25 Apr 2023 13:14:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=goC0+V3ApTSiKsw11bGVSK/Vwd7KgTol7PUe4lqysLo=; b=Tob8pJqzno/796brV3axFVr0TP5FPdO4YGv/K8eHplGjiKjzTx5Y5BXC6JLAwz5glXp2jA Jjom7PcOFJ9GtndpGXE419++LkboC5/Tmfpls16pgm4WBGAbsYPqMRpf7AcBH5Bt3YLusH DnP33cJ7g9iTFaVmGt9r2EKgMw7vpbY= X-MC-Unique: FTFTurJIPG6sACkM5UO9pQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 24/25] vmdk: make vmdk_is_cid_valid a coroutine_fn Date: Tue, 25 Apr 2023 15:13:58 +0200 Message-Id: <20230425131359.259007-25-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682428940052100003 Content-Type: text/plain; charset="utf-8" From: Paolo Bonzini Functions that can do I/O are prime candidates for being coroutine_fns. Ma= ke the change for the one that is itself called only from coroutine_fns. Unfortun= ately vmdk does not use a coroutine_fn for the bulk of the open (like qcow2 does)= so vmdk_read_cid cannot have the same treatment. Signed-off-by: Paolo Bonzini Message-Id: <20230309084456.304669-10-pbonzini@redhat.com> Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/vmdk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/vmdk.c b/block/vmdk.c index f5f49018fe..3f8c731e32 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -376,7 +376,7 @@ out: return ret; } =20 -static int vmdk_is_cid_valid(BlockDriverState *bs) +static int coroutine_fn vmdk_is_cid_valid(BlockDriverState *bs) { BDRVVmdkState *s =3D bs->opaque; uint32_t cur_pcid; --=20 2.40.0 From nobody Tue Feb 10 12:14:31 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1682429007; cv=none; d=zohomail.com; s=zohoarc; b=ezv6VK6eY4NQJcPA2y9QOqkk9AZuD9e/3WuJ/Km996yoMl3tgLYB13wrlU881CgFk0oxtaRxVTcGy2Fx7jYnKKgE4LDXQhTsfO2PS+pwBx1uspKHrQ5PKWYdA811o+zFIcEh+otrtX8NRbI6OVJ109b2Uuzpwhpp+C3ooR22a34= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1682429007; 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; bh=OChVcuXN9xUdxHfBX7+VcKkQZ81IQ8rfLZ+Ubj4/KWw=; b=HLwwwhF9XSdU3Jg0fE0/0pdSGUMW9uUdWC7s9IaDvtGVSRP51LUodbWD9QteR0934kuCTRPQhbGS26QWxynGxwhqGF8tsnDf9wxUeXPavIXQQb0qnISeX0blhd+DFEwCJ9X+sHxAZKv/6QLwjenDXMAv6Md+c0HZSvAtEhlyx10= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1682429007459691.1348249902621; Tue, 25 Apr 2023 06:23:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prIZ8-0002bm-UA; Tue, 25 Apr 2023 09:18:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVU-0006ra-6J for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:15:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.145.221.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1prIVG-0006cg-OP for qemu-devel@nongnu.org; Tue, 25 Apr 2023 09:14:52 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-2-93VU3-YuOym9tznnBhmXaA-1; Tue, 25 Apr 2023 09:14:28 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 26E28185A7A7; Tue, 25 Apr 2023 13:14:28 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6B76C40C2064; Tue, 25 Apr 2023 13:14:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682428471; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OChVcuXN9xUdxHfBX7+VcKkQZ81IQ8rfLZ+Ubj4/KWw=; b=cl3gkTS+DgMTWpAEN0Zx1PVM3mhYvZqK9hh4GmZfpMXkgxq6DI+Tt7jMi4jDHmS5IG34iO CxA/cLXWpcsXDIz8T117gT7r8gLncvcrYyBGWq5rLrfHE0FarSrKTk+bhMjjE3mi3uM610 g/ujbuTBXhum+vnOtMjBdL1SYNnVQOM= X-MC-Unique: 93VU3-YuOym9tznnBhmXaA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, richard.henderson@linaro.org, qemu-devel@nongnu.org Subject: [PULL 25/25] block/monitor/block-hmp-cmds.c: Fix crash when execute hmp_commit Date: Tue, 25 Apr 2023 15:13:59 +0200 Message-Id: <20230425131359.259007-26-kwolf@redhat.com> In-Reply-To: <20230425131359.259007-1-kwolf@redhat.com> References: <20230425131359.259007-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 Received-SPF: pass (zohomail.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; Received-SPF: permerror client-ip=216.145.221.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -22 X-Spam_score: -2.3 X-Spam_bar: -- X-Spam_report: (-2.3 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.171, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_FAIL=0.001, SPF_HELO_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1682429009054100001 Content-Type: text/plain; charset="utf-8" From: Wang Liang hmp_commit() calls blk_is_available() from a non-coroutine context (and in the main loop). blk_is_available() is a co_wrapper_mixed_bdrv_rdlock function, and in the non-coroutine context it calls AIO_WAIT_WHILE(), which crashes if the aio_context lock is not taken before. Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1615 Signed-off-by: Wang Liang Message-Id: <20230424103902.45265-1-wangliangzz@126.com> Reviewed-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/monitor/block-hmp-cmds.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 2846083546..ca2599de44 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -214,15 +214,17 @@ void hmp_commit(Monitor *mon, const QDict *qdict) error_report("Device '%s' not found", device); return; } - if (!blk_is_available(blk)) { - error_report("Device '%s' has no medium", device); - return; - } =20 bs =3D bdrv_skip_implicit_filters(blk_bs(blk)); aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); =20 + if (!blk_is_available(blk)) { + error_report("Device '%s' has no medium", device); + aio_context_release(aio_context); + return; + } + ret =3D bdrv_commit(bs); =20 aio_context_release(aio_context); --=20 2.40.0