From nobody Sat May 18 18:02:00 2024 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=1670849985; cv=none; d=zohomail.com; s=zohoarc; b=QzmE7EMGAzUCsj2oY/r8h8OCZOT6J32swCU3nx5aSVM6phYeyJRg3YoepNngRl5dnHmnnn012mRIXrIirC8p6SHp0yB4sVPoJUzycLl9pG8e2rQlzLBlITbXJMW/2hYOgi/kuOOx6+qvjS51z3NA1pzGrlXUgNHfX8owS8LUQcY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670849985; 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=93Vb2O90S1QkJg8CKuiinms78f3vrRZAmob0IGqZ83Y=; b=OfEApLGRH5Oq4R0Ob4S9Pk6829wGXq9vd35HitXPuLO16Vp+cnHn/LeJl5/guzlBwITKserXuKE6EvMGLNtjdIT66wO16vlIKze/kjL+wT8Qxv9tUgW3l143wWkhBokp5ykvzxm3+4ROCsLTUoJEYgBsROQtVKsNe8RNY10Aklo= 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 1670849985416554.0952977290386; Mon, 12 Dec 2022 04:59:45 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iP6-0000Vg-Vh; Mon, 12 Dec 2022 07:59:33 -0500 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 1p4iP5-0000TK-Tk for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:32 -0500 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 1p4iP4-0000Xh-BZ for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:31 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-61-AMRUJpDbP_CKuUn09SKAOw-1; Mon, 12 Dec 2022 07:59:28 -0500 Received: by mail-wm1-f70.google.com with SMTP id ay19-20020a05600c1e1300b003cf758f1617so4134869wmb.5 for ; Mon, 12 Dec 2022 04:59:28 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id c66-20020a1c3545000000b003d09150b339sm9392544wma.20.2022.12.12.04.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 04:59:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670849969; 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=93Vb2O90S1QkJg8CKuiinms78f3vrRZAmob0IGqZ83Y=; b=d9H7wgFdWUKwyGj7Dw3ybdP22j0mbi/JW+B53XoL1MHiA9WgWH3QTxtREUU3395AG8TlpC z6qcvyUbqs0h3xxOKAKOgSnHjgAACfQ2T3xrc4L+YTQR12SqoUSRCjURbAu7le0T0heps8 ZqBqL2nSI+R560KfVLB9rAY5Lo/ysok= X-MC-Unique: AMRUJpDbP_CKuUn09SKAOw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=93Vb2O90S1QkJg8CKuiinms78f3vrRZAmob0IGqZ83Y=; b=3LthB/9VhSJVhpNyFL3a+EUEMr3XMaS+x62FDcZPR20QtMc5zswRRgbJ5YwIAX576w s81sG9oe/GjicN7yznV2rkGDL9EGziLcdBOFLiOw2XrBRGhozKZUJnLwmyaZyr34Sqfp jrH9zTuKKRgaYtquqWt8A0ymRP9WMze4qHpTd3RXx7ua+2Xi+HFzI5bI2Wb0b0lvOrC6 OHXkmJhjG/uEsFUscRFWjzYyHYaoxpILRdCbwq1QRK6xwsrq6gfuV40RhHGOLdnVsqw7 pCnYMBAuOTtpriPv0NLu5K2NbduWkJvBxDLZvnj5neNTDhzuNy5HQW477ffB1uRGSjnA QS3Q== X-Gm-Message-State: ANoB5plmUIbMRNCxe70uvLWgbrGabBKxoIE15obRcZxAHpXUKmuXTSa9 HFoodUdfJ7Sm7xb32aHxJYzqyChh5QMYLhl0gIeMGFRyfNOyLvIL4kvTxXLKePGogohYu/ks9wJ 6B7Flx8AD8qrrgFjIl6jU7NB2gtutEaMs2ODneIUsGDM+J7EM8C2yQnoEWvTkTHzW+OI= X-Received: by 2002:a05:600c:1e88:b0:3d1:efa1:3689 with SMTP id be8-20020a05600c1e8800b003d1efa13689mr11967736wmb.24.1670849966522; Mon, 12 Dec 2022 04:59:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf4DUVH2KtukyGjZbouJxlRkpu5qOKN97ixm6Xjw5WQ/tpXeJ6xjs0TaAbO96Iz+8KEZzEaMIA== X-Received: by 2002:a05:600c:1e88:b0:3d1:efa1:3689 with SMTP id be8-20020a05600c1e8800b003d1efa13689mr11967720wmb.24.1670849966213; Mon, 12 Dec 2022 04:59:26 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com Subject: [PATCH 01/15] Revert "block: Remove poll parameter from bdrv_parent_drained_begin_single()" Date: Mon, 12 Dec 2022 13:59:06 +0100 Message-Id: <20221212125920.248567-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: 1670849986876100003 Content-Type: text/plain; charset="utf-8" This reverts commit dcc5d4bc2abed4268bf31908193c4369e4c9d005. Signed-off-by: Paolo Bonzini --- block.c | 4 ++-- block/io.c | 8 ++++++-- include/block/block-io.h | 5 +++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index 6191ac1f440c..87022f4cd971 100644 --- a/block.c +++ b/block.c @@ -2377,7 +2377,7 @@ static void bdrv_replace_child_abort(void *opaque) * new_bs drained when calling bdrv_replace_child_tran() is not a * requirement any more. */ - bdrv_parent_drained_begin_single(s->child); + bdrv_parent_drained_begin_single(s->child, false); assert(!bdrv_parent_drained_poll_single(s->child)); } assert(s->child->quiesced_parent); @@ -3050,7 +3050,7 @@ static BdrvChild *bdrv_attach_child_common(BlockDrive= rState *child_bs, * a problem, we already did this), but it will still poll until the p= arent * is fully quiesced, so it will not be negatively affected either. */ - bdrv_parent_drained_begin_single(new_child); + bdrv_parent_drained_begin_single(new_child, false); bdrv_replace_child_noperm(new_child, child_bs); =20 BdrvAttachChildCommonState *s =3D g_new(BdrvAttachChildCommonState, 1); diff --git a/block/io.c b/block/io.c index f4444b7777d9..aee6e70c1496 100644 --- a/block/io.c +++ b/block/io.c @@ -53,7 +53,7 @@ static void bdrv_parent_drained_begin(BlockDriverState *b= s, BdrvChild *ignore) if (c =3D=3D ignore) { continue; } - bdrv_parent_drained_begin_single(c); + bdrv_parent_drained_begin_single(c, false); } } =20 @@ -105,8 +105,9 @@ static bool bdrv_parent_drained_poll(BlockDriverState *= bs, BdrvChild *ignore, return busy; } =20 -void bdrv_parent_drained_begin_single(BdrvChild *c) +void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll) { + AioContext *ctx =3D bdrv_child_get_parent_aio_context(c); IO_OR_GS_CODE(); =20 assert(!c->quiesced_parent); @@ -115,6 +116,9 @@ void bdrv_parent_drained_begin_single(BdrvChild *c) if (c->klass->drained_begin) { c->klass->drained_begin(c); } + if (poll) { + AIO_WAIT_WHILE(ctx, bdrv_parent_drained_poll_single(c)); + } } =20 static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src) diff --git a/include/block/block-io.h b/include/block/block-io.h index 52869ea08eb5..75d043204355 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -308,9 +308,10 @@ bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector= *qiov, int64_t pos); /** * bdrv_parent_drained_begin_single: * - * Begin a quiesced section for the parent of @c. + * Begin a quiesced section for the parent of @c. If @poll is true, wait f= or + * any pending activity to cease. */ -void bdrv_parent_drained_begin_single(BdrvChild *c); +void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll); =20 /** * bdrv_parent_drained_poll_single: --=20 2.38.1 From nobody Sat May 18 18:02:00 2024 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=1670850047; cv=none; d=zohomail.com; s=zohoarc; b=U/buT5LgDpBdBrQS3O2y+H3J+avOnIFR0jgL83PlzlATRCIB6gMgeWQCTnRNvCm74y0N3HSuj0sMpMVBCpBQjzUF1mb1oXfJwv5nTVZQppZRIwj2CRvDc8HL99Bpwhnc4ADWGcjcZwY5RspQFi4q+6hwxZdFOJEo85zG+Z8B3vU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670850047; 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=rSV1TeijoZsmxAvrhyYs0t9/sSLc9dqrPATrVhnl4kI=; b=CKWRJN+e28MSt70GOGCPAv3HDj4FtuLLZw1sg1Bhx+FeoAjJig8bwGWW+VvH1m/9Fd4FVrwZSLa88UmGzoMXycrt0998ZZf5YINjaXMmCOa4n18fHnr2QWMP+72gjosTwftRrss4l7VUbVbzg0ti1qK0peRkvvkvGwBHlWRyfr8= 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 1670850047894639.5751303823093; Mon, 12 Dec 2022 05:00:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iPA-0000eH-FK; Mon, 12 Dec 2022 07:59:36 -0500 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 1p4iP8-0000ab-T3 for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:34 -0500 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 1p4iP7-0000YK-0L for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:34 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-616-JjHThkunPl6MY_O5ADbXqA-1; Mon, 12 Dec 2022 07:59:31 -0500 Received: by mail-wm1-f69.google.com with SMTP id t24-20020a1c7718000000b003d1fd0b866fso1972351wmi.3 for ; Mon, 12 Dec 2022 04:59:31 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id iw3-20020a05600c54c300b003d220ef3232sm5885669wmb.34.2022.12.12.04.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 04:59:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670849972; 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=rSV1TeijoZsmxAvrhyYs0t9/sSLc9dqrPATrVhnl4kI=; b=Mt2UNvefytq8mcfBt6dAQV9qrxArqa+v/ai9LWqXiK52Nff3wKRdcqwaiJjXagxhXnBw1U JJIMyYeIQCZddCga7/cOjkR5PhxNR3KmNQ4XAFQbV3sIYfdOeDpb0vFv/7sTYL7qoPRyQh 4Kfrys9nJ7va8bDWtI2HRfXjv8YquOk= X-MC-Unique: JjHThkunPl6MY_O5ADbXqA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rSV1TeijoZsmxAvrhyYs0t9/sSLc9dqrPATrVhnl4kI=; b=DgWCDNPQeQxz4sgthkMw30BdM8lcKaAiS1wo62a90E2nDKjTFmW1CVfWgKEG3huTW7 ZYVvk3YnpJxNqJr+fD8oquIpBcr0yjJF7C2dNBj9/MVY8lcrQ8dQARgNEvShLn7ToqmM 54Ijl76QSYixCC/3sJOye+7XFQOFhFyxPLM4hadKlC++akgKlJ4TpGIvjXrmvlBHvyDx 4ECFlTVetKnq1Q/pp4vQ5sR4piSFkyEnmjymJvO3C+lDFET9g5aBJdqzwBg0msICRoa4 U287Om+ZX1o/8erA3TweLfo1c4ITRGgPPUKkpisxkwYEpPiy/ZGQKfIIvP/yFt1byWoO ddwA== X-Gm-Message-State: ANoB5pmb1BwQilZjcpffnpgexuxkiY6x+vuwhjDeoKBhVITMLfcKU8AT ALe+V/BW7H0VmpPWp7iExKu0X3RAi+m2wPlraR9TVyaPeBY+e96kYX/OiP5mElQWTZy/36Yq+3N 5J0jH1nUOH4Gh+Fzd6g97iQ6UoCpIvFPBvSt7nTByFWIF9jOzrI5dzqFOfGYCdQ06hjY= X-Received: by 2002:a05:600c:3d19:b0:3d0:bd9:edd4 with SMTP id bh25-20020a05600c3d1900b003d00bd9edd4mr12339469wmb.0.1670849969852; Mon, 12 Dec 2022 04:59:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf5/UqhHoj7+mwT9ZDOmXABBepgcA1dgGsGzskUgJghdLD7clnC2xMzw7j5RvUH3O2unyxZZUw== X-Received: by 2002:a05:600c:3d19:b0:3d0:bd9:edd4 with SMTP id bh25-20020a05600c3d1900b003d00bd9edd4mr12339441wmb.0.1670849969216; Mon, 12 Dec 2022 04:59:29 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com Subject: [PATCH 02/15] Revert "block: Don't poll in bdrv_replace_child_noperm()" Date: Mon, 12 Dec 2022 13:59:07 +0100 Message-Id: <20221212125920.248567-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1670850049401100001 Content-Type: text/plain; charset="utf-8" This reverts commit a4e5c80a45b22359cf9c187f0df4f8544812c55c. Signed-off-by: Paolo Bonzini --- block.c | 103 +++++------------------------------ block/io.c | 2 +- include/block/block-io.h | 8 --- tests/unit/test-bdrv-drain.c | 10 ---- 4 files changed, 15 insertions(+), 108 deletions(-) diff --git a/block.c b/block.c index 87022f4cd971..2f2123f4a4e5 100644 --- a/block.c +++ b/block.c @@ -2367,20 +2367,6 @@ static void bdrv_replace_child_abort(void *opaque) =20 GLOBAL_STATE_CODE(); /* old_bs reference is transparently moved from @s to @s->child */ - if (!s->child->bs) { - /* - * The parents were undrained when removing old_bs from the child.= New - * requests can't have been made, though, because the child was em= pty. - * - * TODO Make bdrv_replace_child_noperm() transactionable to avoid - * undraining the parent in the first place. Once this is done, ha= ving - * new_bs drained when calling bdrv_replace_child_tran() is not a - * requirement any more. - */ - bdrv_parent_drained_begin_single(s->child, false); - assert(!bdrv_parent_drained_poll_single(s->child)); - } - assert(s->child->quiesced_parent); bdrv_replace_child_noperm(s->child, s->old_bs); bdrv_unref(new_bs); } @@ -2396,19 +2382,12 @@ static TransactionActionDrv bdrv_replace_child_drv = =3D { * * Note: real unref of old_bs is done only on commit. * - * Both @child->bs and @new_bs (if non-NULL) must be drained. @new_bs must= be - * kept drained until the transaction is completed. - * * The function doesn't update permissions, caller is responsible for this. */ static void bdrv_replace_child_tran(BdrvChild *child, BlockDriverState *ne= w_bs, Transaction *tran) { BdrvReplaceChildState *s =3D g_new(BdrvReplaceChildState, 1); - - assert(child->quiesced_parent); - assert(!new_bs || new_bs->quiesce_counter); - *s =3D (BdrvReplaceChildState) { .child =3D child, .old_bs =3D child->bs, @@ -2831,14 +2810,6 @@ uint64_t bdrv_qapi_perm_to_blk_perm(BlockPermission = qapi_perm) return permissions[qapi_perm]; } =20 -/* - * Replaces the node that a BdrvChild points to without updating permissio= ns. - * - * If @new_bs is non-NULL, the parent of @child must already be drained th= rough - * @child. - * - * This function does not poll. - */ static void bdrv_replace_child_noperm(BdrvChild *child, BlockDriverState *new_bs) { @@ -2846,28 +2817,6 @@ static void bdrv_replace_child_noperm(BdrvChild *chi= ld, int new_bs_quiesce_counter; =20 assert(!child->frozen); - - /* - * If we want to change the BdrvChild to point to a drained node as it= s new - * child->bs, we need to make sure that its new parent is drained, too= . In - * other words, either child->quiesce_parent must already be true or w= e must - * be able to set it and keep the parent's quiesce_counter consistent = with - * that, but without polling or starting new requests (this function - * guarantees that it doesn't poll, and starting new requests would be - * against the invariants of drain sections). - * - * To keep things simple, we pick the first option (child->quiesce_par= ent - * must already be true). We also generalise the rule a bit to make it - * easier to verify in callers and more likely to be covered in test c= ases: - * The parent must be quiesced through this child even if new_bs isn't - * currently drained. - * - * The only exception is for callers that always pass new_bs =3D=3D NU= LL. In - * this case, we obviously never need to consider the case of a drained - * new_bs, so we can keep the callers simpler by allowing them not to = drain - * the parent. - */ - assert(!new_bs || child->quiesced_parent); assert(old_bs !=3D new_bs); GLOBAL_STATE_CODE(); =20 @@ -2875,6 +2824,15 @@ static void bdrv_replace_child_noperm(BdrvChild *chi= ld, assert(bdrv_get_aio_context(old_bs) =3D=3D bdrv_get_aio_context(ne= w_bs)); } =20 + /* + * If the new child node is drained but the old one was not, flush + * all outstanding requests to the old child node. + */ + new_bs_quiesce_counter =3D (new_bs ? new_bs->quiesce_counter : 0); + if (new_bs_quiesce_counter && !child->quiesced_parent) { + bdrv_parent_drained_begin_single(child, true); + } + if (old_bs) { if (child->klass->detach) { child->klass->detach(child); @@ -2894,9 +2852,11 @@ static void bdrv_replace_child_noperm(BdrvChild *chi= ld, } =20 /* - * If the parent was drained through this BdrvChild previously, but ne= w_bs - * is not drained, allow requests to come in only after the new node h= as - * been attached. + * If the old child node was drained but the new one is not, allow + * requests to come in only after the new node has been attached. + * + * Update new_bs_quiesce_counter because bdrv_parent_drained_begin_sin= gle() + * polls, which could have changed the value. */ new_bs_quiesce_counter =3D (new_bs ? new_bs->quiesce_counter : 0); if (!new_bs_quiesce_counter && child->quiesced_parent) { @@ -3033,24 +2993,6 @@ static BdrvChild *bdrv_attach_child_common(BlockDriv= erState *child_bs, } =20 bdrv_ref(child_bs); - /* - * Let every new BdrvChild start with a drained parent. Inserting the = child - * in the graph with bdrv_replace_child_noperm() will undrain it if - * @child_bs is not drained. - * - * The child was only just created and is not yet visible in global st= ate - * until bdrv_replace_child_noperm() inserts it into the graph, so nob= ody - * could have sent requests and polling is not necessary. - * - * Note that this means that the parent isn't fully drained yet, we on= ly - * stop new requests from coming in. This is fine, we don't care about= the - * old requests here, they are not for this child. If another place en= ters a - * drain section for the same parent, but wants it to be fully quiesce= d, it - * will not run most of the the code in .drained_begin() again (which = is not - * a problem, we already did this), but it will still poll until the p= arent - * is fully quiesced, so it will not be negatively affected either. - */ - bdrv_parent_drained_begin_single(new_child, false); bdrv_replace_child_noperm(new_child, child_bs); =20 BdrvAttachChildCommonState *s =3D g_new(BdrvAttachChildCommonState, 1); @@ -5096,24 +5038,12 @@ static void bdrv_remove_child(BdrvChild *child, Tra= nsaction *tran) } =20 if (child->bs) { - BlockDriverState *bs =3D child->bs; - bdrv_drained_begin(bs); bdrv_replace_child_tran(child, NULL, tran); - bdrv_drained_end(bs); } =20 tran_add(tran, &bdrv_remove_child_drv, child); } =20 -static void undrain_on_clean_cb(void *opaque) -{ - bdrv_drained_end(opaque); -} - -static TransactionActionDrv undrain_on_clean =3D { - .clean =3D undrain_on_clean_cb, -}; - static int bdrv_replace_node_noperm(BlockDriverState *from, BlockDriverState *to, bool auto_skip, Transaction *tran, @@ -5123,11 +5053,6 @@ static int bdrv_replace_node_noperm(BlockDriverState= *from, =20 GLOBAL_STATE_CODE(); =20 - bdrv_drained_begin(from); - bdrv_drained_begin(to); - tran_add(tran, &undrain_on_clean, from); - tran_add(tran, &undrain_on_clean, to); - QLIST_FOREACH_SAFE(c, &from->parents, next_parent, next) { assert(c->bs =3D=3D from); if (!should_update_child(c, to)) { diff --git a/block/io.c b/block/io.c index aee6e70c1496..571ff8c6493a 100644 --- a/block/io.c +++ b/block/io.c @@ -81,7 +81,7 @@ static void bdrv_parent_drained_end(BlockDriverState *bs,= BdrvChild *ignore) } } =20 -bool bdrv_parent_drained_poll_single(BdrvChild *c) +static bool bdrv_parent_drained_poll_single(BdrvChild *c) { if (c->klass->drained_poll) { return c->klass->drained_poll(c); diff --git a/include/block/block-io.h b/include/block/block-io.h index 75d043204355..0e0cd1249705 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -313,14 +313,6 @@ bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector= *qiov, int64_t pos); */ void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll); =20 -/** - * bdrv_parent_drained_poll_single: - * - * Returns true if there is any pending activity to cease before @c can be - * called quiesced, false otherwise. - */ -bool bdrv_parent_drained_poll_single(BdrvChild *c); - /** * bdrv_parent_drained_end_single: * diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 2686a8aceee1..172bc6debc23 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -1654,7 +1654,6 @@ static void test_drop_intermediate_poll(void) =20 =20 typedef struct BDRVReplaceTestState { - bool setup_completed; bool was_drained; bool was_undrained; bool has_read; @@ -1739,10 +1738,6 @@ static void bdrv_replace_test_drain_begin(BlockDrive= rState *bs) { BDRVReplaceTestState *s =3D bs->opaque; =20 - if (!s->setup_completed) { - return; - } - if (!s->drain_count) { s->drain_co =3D qemu_coroutine_create(bdrv_replace_test_drain_co, = bs); bdrv_inc_in_flight(bs); @@ -1774,10 +1769,6 @@ static void bdrv_replace_test_drain_end(BlockDriverS= tate *bs) { BDRVReplaceTestState *s =3D bs->opaque; =20 - if (!s->setup_completed) { - return; - } - g_assert(s->drain_count > 0); if (!--s->drain_count) { s->was_undrained =3D true; @@ -1876,7 +1867,6 @@ static void do_test_replace_child_mid_drain(int old_d= rain_count, bdrv_ref(old_child_bs); bdrv_attach_child(parent_bs, old_child_bs, "child", &child_of_bds, BDRV_CHILD_COW, &error_abort); - parent_s->setup_completed =3D true; =20 for (i =3D 0; i < old_drain_count; i++) { bdrv_drained_begin(old_child_bs); --=20 2.38.1 From nobody Sat May 18 18:02:00 2024 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=1670850017; cv=none; d=zohomail.com; s=zohoarc; b=e9cWgzIcg4Y/xvp02Oh1qR1misD8sK0UnNf8PQG5B/UN5LYMzaW+JPUsw9TGhDcGwERZqkiXojK/WZdNOgcW2880pXABIW6PaLyDBYWH4xp9/xsft2GyPxtBrX0qRX9e1/JciSumCeP0sKM1Uua7w5NUtEdNqVAIu9D5c1wOisM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670850017; 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=7AHE4B+LCR9BTgpv+4FWDIQZFuMe4/pVoEPr5P/DUCA=; b=XFe9sk7VR44yCA/ReHYvyTCnJVpnycMNBaFA0DjG/v0X9YXfaHsiv1nWMOQtqWOG8udhn1VaIzo5CawX3VOBLaAre9rgb9rP6ZfpXEd1Z3MRW42tOSUhiH8HbW70gHPVUv3jI4XAQhhyHfJSkqqa/qXoWjaAUwCahWcf7NuVHcQ= 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 167085001798056.12735057819282; Mon, 12 Dec 2022 05:00:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iPC-0000hJ-EV; Mon, 12 Dec 2022 07:59:38 -0500 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 1p4iPB-0000g1-FK for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:37 -0500 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 1p4iP9-0000Yg-Ob for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:37 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-632-guFTiXTiNHK3Sw3qPaqO8Q-1; Mon, 12 Dec 2022 07:59:33 -0500 Received: by mail-wm1-f69.google.com with SMTP id h81-20020a1c2154000000b003d1c8e519fbso4139170wmh.2 for ; Mon, 12 Dec 2022 04:59:33 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id l5-20020a5d6685000000b0024194bba380sm8860338wru.22.2022.12.12.04.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 04:59:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670849975; 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=7AHE4B+LCR9BTgpv+4FWDIQZFuMe4/pVoEPr5P/DUCA=; b=i+fYLJahZv2Qv1wWYrhM0P968GAdCxWaUGlvP/V+NWS5VjIBqDT66VDcof6HbSHTe6XjHW SxHRNrQuagtUXZ0lqU4RsNJorZHCT88k0YH/KtRq6jivOA5unY/7J/wUOKdpJ4TE6sgkEh 66DpaavWE/lYXnOfzHODCArhNaKLRDI= X-MC-Unique: guFTiXTiNHK3Sw3qPaqO8Q-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7AHE4B+LCR9BTgpv+4FWDIQZFuMe4/pVoEPr5P/DUCA=; b=zVdhpXeRbuDDtLpcyFlkHltfRjC+cjUuN4lSKw5gwUjUhxSPvsnX4tirhWOUn2Ehrl fU0GDNoDw78JZL8QLNO1HLuRShDSz3kYPfNuiJsWUdUQce14YAGeW9XMZYZQX6gn2UEO yklisdIrxhyYrYoXz5SnYv1ytfTLox8tHISokFAvgvTpLgORvjnKUqGvIqpXJhZLPjKh h2/ESTtPQEIHMGWRI0bav24jvHN+TuMGXNTwfxTzBk1jIDjEsacMm5a+8Flh7NurtjZj gnK3G/tMQEppLBtKXbmW+UOF1W31nB3E39QH4wshUNzSNuciP8O9FygGm//I+YvJQgtD hwEA== X-Gm-Message-State: ANoB5pkCeWH2uviiWefm83wNQpDTtqQp5JF3F7M9syZMCbHRIL/mBYUB 2icHE1+akjmU2Pb4IkpyKKJt3rz0cKn7Dyzlc7P8kT9BRSyUZH3cTrXN/SNsu8lz/yaF9eHmpp5 kYI3FqfQ74r9KxExMnufohz+9P3pUi4p3ujNok+2X/dAgtWNEEZnCpX37SghNlntikwg= X-Received: by 2002:a5d:574f:0:b0:242:5b60:e23c with SMTP id q15-20020a5d574f000000b002425b60e23cmr8965785wrw.19.1670849972208; Mon, 12 Dec 2022 04:59:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf5ioof3TY8/eu2ajKYSR8Fe7Vq6qYhIncjragpAKhaeOmbYFTkwkGlD1inzuBdd2Fgp88EGtA== X-Received: by 2002:a5d:574f:0:b0:242:5b60:e23c with SMTP id q15-20020a5d574f000000b002425b60e23cmr8965766wrw.19.1670849971875; Mon, 12 Dec 2022 04:59:31 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com Subject: [PATCH 03/15] block: Pull polling out of bdrv_parent_drained_begin_single() Date: Mon, 12 Dec 2022 13:59:08 +0100 Message-Id: <20221212125920.248567-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1670850019159100001 Content-Type: text/plain; charset="utf-8" Only one caller of bdrv_parent_drained_begin_single() passes poll=3Dtrue; move the polling to that one caller. While this requires exposing bdrv_parent_drained_poll_single to outside block/io.c, this is not a big deal because the bdrv_parent_drained_*_single functions are really internal between block.c and block/io.c. So make that clear while we're at it, by moving them to block_int-io.h. Based on a patch by Kevin Wolf . Signed-off-by: Paolo Bonzini --- block.c | 4 +++- block/io.c | 10 +++------- include/block/block-io.h | 15 --------------- include/block/block_int-io.h | 21 +++++++++++++++++++++ 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/block.c b/block.c index 2f2123f4a4e5..c542a0a33358 100644 --- a/block.c +++ b/block.c @@ -2830,7 +2830,9 @@ static void bdrv_replace_child_noperm(BdrvChild *chil= d, */ new_bs_quiesce_counter =3D (new_bs ? new_bs->quiesce_counter : 0); if (new_bs_quiesce_counter && !child->quiesced_parent) { - bdrv_parent_drained_begin_single(child, true); + bdrv_parent_drained_begin_single(child); + AIO_WAIT_WHILE(bdrv_child_get_parent_aio_context(child), + bdrv_parent_drained_poll_single(child)); } =20 if (old_bs) { diff --git a/block/io.c b/block/io.c index 571ff8c6493a..f4444b7777d9 100644 --- a/block/io.c +++ b/block/io.c @@ -53,7 +53,7 @@ static void bdrv_parent_drained_begin(BlockDriverState *b= s, BdrvChild *ignore) if (c =3D=3D ignore) { continue; } - bdrv_parent_drained_begin_single(c, false); + bdrv_parent_drained_begin_single(c); } } =20 @@ -81,7 +81,7 @@ static void bdrv_parent_drained_end(BlockDriverState *bs,= BdrvChild *ignore) } } =20 -static bool bdrv_parent_drained_poll_single(BdrvChild *c) +bool bdrv_parent_drained_poll_single(BdrvChild *c) { if (c->klass->drained_poll) { return c->klass->drained_poll(c); @@ -105,9 +105,8 @@ static bool bdrv_parent_drained_poll(BlockDriverState *= bs, BdrvChild *ignore, return busy; } =20 -void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll) +void bdrv_parent_drained_begin_single(BdrvChild *c) { - AioContext *ctx =3D bdrv_child_get_parent_aio_context(c); IO_OR_GS_CODE(); =20 assert(!c->quiesced_parent); @@ -116,9 +115,6 @@ void bdrv_parent_drained_begin_single(BdrvChild *c, boo= l poll) if (c->klass->drained_begin) { c->klass->drained_begin(c); } - if (poll) { - AIO_WAIT_WHILE(ctx, bdrv_parent_drained_poll_single(c)); - } } =20 static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src) diff --git a/include/block/block-io.h b/include/block/block-io.h index 0e0cd1249705..10659a3f246c 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -305,21 +305,6 @@ bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector = *qiov, int64_t pos); int co_wrapper_mixed bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); =20 -/** - * bdrv_parent_drained_begin_single: - * - * Begin a quiesced section for the parent of @c. If @poll is true, wait f= or - * any pending activity to cease. - */ -void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll); - -/** - * bdrv_parent_drained_end_single: - * - * End a quiesced section for the parent of @c. - */ -void bdrv_parent_drained_end_single(BdrvChild *c); - /** * bdrv_drain_poll: * diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 8bc061ebb895..0ced9c025acb 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -179,4 +179,25 @@ void bdrv_bsc_invalidate_range(BlockDriverState *bs, */ void bdrv_bsc_fill(BlockDriverState *bs, int64_t offset, int64_t bytes); =20 +/** + * bdrv_parent_drained_begin_single: + * + * Begin a quiesced section for the parent of @c. + */ +void bdrv_parent_drained_begin_single(BdrvChild *c); + +/** + * bdrv_parent_drained_begin_single: + * + * Check whether the parent of @c has quiesced. + */ +bool bdrv_parent_drained_poll_single(BdrvChild *c); + +/** + * bdrv_parent_drained_end_single: + * + * End a quiesced section for the parent of @c. + */ +void bdrv_parent_drained_end_single(BdrvChild *c); + #endif /* BLOCK_INT_IO_H */ --=20 2.38.1 From nobody Sat May 18 18:02:00 2024 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=1670850307; cv=none; d=zohomail.com; s=zohoarc; b=lOKohl7nUnnHMlx1TnuHCHkyfGDSzeH/Q6ROZZJ8fdI8PWFzk03NxfMMWj5X8bQIxX0pEoYMpo+C2Dgipy0uqihMHPAMzvb7LdzHCHy/ewIY/wKbXMZmO8cD2mqUw16YTNLAtqxDK21EwtXUUsdkpMWwRWjXvYJFu4Aq94OzJSY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670850307; 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=snOC6N8Qmx4rnpNsWU285qEKJ/QBpo3HYAbrLWVrVJU=; b=YBNOAP+YuO5JR8s9WMBHQZ5e+4cH5O91Ew4KhelcgTJ2FxQ2CqaphZXHWak7lB6r7LOZ99H6zVRdjmrmGyst6VCwNwwfQQvCaLv/HqVSKJHIv2UNXP0BvzrqqdBmDeWMeRjDXWYe67p5zvQiY5QNAvKu3hcqJKpztT1QE/SitpI= 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 167085030757672.65865098188124; Mon, 12 Dec 2022 05:05:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iPM-0000v8-2O; Mon, 12 Dec 2022 07:59:48 -0500 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 1p4iPE-0000k1-76 for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:40 -0500 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 1p4iPC-0000ZF-9q for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:39 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-333-qARjSM4FMgicnTO8R-ijRQ-1; Mon, 12 Dec 2022 07:59:36 -0500 Received: by mail-wm1-f71.google.com with SMTP id r129-20020a1c4487000000b003d153a83d27so3347048wma.0 for ; Mon, 12 Dec 2022 04:59:36 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id t123-20020a1c4681000000b003cf87623c16sm9306776wma.4.2022.12.12.04.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 04:59:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670849977; 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=snOC6N8Qmx4rnpNsWU285qEKJ/QBpo3HYAbrLWVrVJU=; b=bVRnjJbpmPzVYVv6GXJhzuwX8jnLziVc2YAsOLfJ4CTETB+2dj9LHQqhrESuBFsOEkPMmW YgdRWFk76yeHLzeFMLlk7xbqAD4l7IvBq1Kby1vnEAXlyHYjSFHMgf3BQsR6vQlKMNB9WK MW15YN6tq8gqqwdx39qfc812H2f3bQ4= X-MC-Unique: qARjSM4FMgicnTO8R-ijRQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=snOC6N8Qmx4rnpNsWU285qEKJ/QBpo3HYAbrLWVrVJU=; b=q4ALUvj36MbZPzfdOph6smAVKmy3n+uUx7UcSGpU74Gv7Zi7AE9J6or3iQRUM55jx9 WjSawO+Kjyo+Kf4V6VOV2fT+4nvaUUu9KX+xzJHAFMGmSoaFjC7Ldd5DkMmuWYQ3XBuD SHmDZ6Tdv3NseClCReg47A7stKKnS6kelwJhwE1Yj/1wxJyJPbfERkON/G6soRvbxBfE LFNmrjxNKtxRayfr/lPkkNvCN3S9IW+U2AJJ0oFQxiCKVr/ZwD1JnsiCMrUieps/f2x3 7NEfDn2Ol2Y5GYF7MqX44CQPBXUmQ5C/CbZObn333z1SIGvoRHHcyJ/WkYQ0wcfrO2F1 zXdA== X-Gm-Message-State: ANoB5pkay4sgtsekvuGkEnFI/DFB+kvQ0v6DQycamVK++qmCu7lzmOaa UTaX1+PXx3hrG6CjpOiFEDegdz/UimSmFwr78I3JyOy0GL+EjqK/uzzLaiSMWmpkyJwsu0gKldb TlqKxrMPLF2dMCwoy/vcJHmJsB7860MqFf7NJttMmiIdxmM2CkYd3FNOdZ4WyBtSk984= X-Received: by 2002:a7b:c417:0:b0:3cc:cc18:b490 with SMTP id k23-20020a7bc417000000b003cccc18b490mr12190164wmi.28.1670849975138; Mon, 12 Dec 2022 04:59:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf6w0f0SloPkHU2nM+WiKkkSMfxO5w3snPsFi1MKUDh0iiGwLazAgDH8p3hf7VFnHo2La3pjvQ== X-Received: by 2002:a7b:c417:0:b0:3cc:cc18:b490 with SMTP id k23-20020a7bc417000000b003cccc18b490mr12190143wmi.28.1670849974738; Mon, 12 Dec 2022 04:59:34 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com, Stefan Hajnoczi Subject: [PATCH 04/15] test-bdrv-drain.c: remove test_detach_by_parent_cb() Date: Mon, 12 Dec 2022 13:59:09 +0100 Message-Id: <20221212125920.248567-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: 1670850307947100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This test uses a callback of an I/O function (blk_aio_preadv) to modify the graph, using bdrv_attach_child. This is simply not allowed anymore. I/O cannot change the graph. Before "block/io.c: make bdrv_do_drained_begin_quiesce static and introduce bdrv_drained_begin_no_poll", the test would simply be at risk of failure, because if bdrv_replace_child_noperm() (called to modify the graph) would call a drain, then one callback of .drained_begin() is bdrv_do_drained_begin_quiesce, that specifically asserts that we are not in a coroutine. Now that we fixed the behavior, the drain will invoke a bh in the main loop, so we don't have such problem. However, this test is still illegal and fails because we forbid graph changes from I/O paths. Once we add the required subtree_drains to protect bdrv_replace_child_noperm(), the key problem in this test is in: acb =3D blk_aio_preadv(blk, 0, &qiov, 0, detach_by_parent_aio_cb, NULL); /* Drain and check the expected result */ bdrv_subtree_drained_begin(parent_b); because the detach_by_parent_aio_cb calls detach_indirect_bh(), that modifies the graph and is invoked during bdrv_subtree_drained_begin(). The call stack is the following: 1. blk_aio_preadv() creates a coroutine, increments in_flight counter and enters the coroutine running blk_aio_read_entry() 2. blk_aio_read_entry() performs the read and then schedules a bh to complete (blk_aio_complete) 3. at this point, subtree_drained_begin() kicks in and waits for all in_flight requests, polling 4. polling allows the bh to be scheduled, so blk_aio_complete runs 5. blk_aio_complete *first* invokes the callback (detach_by_parent_aio_cb) and then decrements the in_flight counter 6. Here we have the problem: detach_by_parent_aio_cb modifies the graph, so both bdrv_unref_child() and bdrv_attach_child() will have subtree_drains inside. And this causes a deadlock, because the nested drain will wait for in_flight counter to go to zero, which is only happening once the drain itself finishes. Different story is test_detach_by_driver_cb(): in this case, detach_by_parent_aio_cb() does not call detach_indirect_bh(), but it is instead called as a bh running in the main loop by detach_by_driver_cb_drained_begin(), the callback for .drained_begin(). This test was added in 231281ab42 and part of the series "Drain fixes and cleanups, part 3" https://lists.nongnu.org/archive/html/qemu-block/2018-05/msg01132.html but as explained above I believe that it is not valid anymore, and can be discarded. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Stefan Hajnoczi Message-Id: <20220314131854.2202651-8-eesposit@redhat.com> Signed-off-by: Paolo Bonzini --- tests/unit/test-bdrv-drain.c | 42 +++++++++--------------------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 172bc6debc23..3be214f30186 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -1106,7 +1106,6 @@ struct detach_by_parent_data { BdrvChild *child_b; BlockDriverState *c; BdrvChild *child_c; - bool by_parent_cb; }; static struct detach_by_parent_data detach_by_parent_data; =20 @@ -1124,12 +1123,7 @@ static void detach_indirect_bh(void *opaque) =20 static void detach_by_parent_aio_cb(void *opaque, int ret) { - struct detach_by_parent_data *data =3D &detach_by_parent_data; - g_assert_cmpint(ret, =3D=3D, 0); - if (data->by_parent_cb) { - detach_indirect_bh(data); - } } =20 static void detach_by_driver_cb_drained_begin(BdrvChild *child) @@ -1148,33 +1142,26 @@ static BdrvChildClass detach_by_driver_cb_class; * \ / \ * A B C * - * by_parent_cb =3D=3D true: Test that parent callbacks don't poll - * - * PA has a pending write request whose callback changes the child nod= es of - * PB: It removes B and adds C instead. The subtree of PB is drained, = which - * will indirectly drain the write request, too. - * - * by_parent_cb =3D=3D false: Test that bdrv_drain_invoke() doesn't poll + * Test that bdrv_drain_invoke() doesn't poll * * PA's BdrvChildClass has a .drained_begin callback that schedules a = BH * that does the same graph change. If bdrv_drain_invoke() calls it, t= he * state is messed up, but if it is only polled in the single * BDRV_POLL_WHILE() at the end of the drain, this should work fine. */ -static void test_detach_indirect(bool by_parent_cb) +static void test_detach_indirect(void) { BlockBackend *blk; BlockDriverState *parent_a, *parent_b, *a, *b, *c; BdrvChild *child_a, *child_b; BlockAIOCB *acb; + BDRVTestState *s; =20 QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); =20 - if (!by_parent_cb) { - detach_by_driver_cb_class =3D child_of_bds; - detach_by_driver_cb_class.drained_begin =3D - detach_by_driver_cb_drained_begin; - } + detach_by_driver_cb_class =3D child_of_bds; + detach_by_driver_cb_class.drained_begin =3D + detach_by_driver_cb_drained_begin; =20 /* Create all involved nodes */ parent_a =3D bdrv_new_open_driver(&bdrv_test, "parent-a", BDRV_O_RDWR, @@ -1193,10 +1180,8 @@ static void test_detach_indirect(bool by_parent_cb) =20 /* If we want to get bdrv_drain_invoke() to call aio_poll(), the driver * callback must not return immediately. */ - if (!by_parent_cb) { - BDRVTestState *s =3D parent_a->opaque; - s->sleep_in_drain_begin =3D true; - } + s =3D parent_a->opaque; + s->sleep_in_drain_begin =3D true; =20 /* Set child relationships */ bdrv_ref(b); @@ -1208,7 +1193,7 @@ static void test_detach_indirect(bool by_parent_cb) =20 bdrv_ref(a); bdrv_attach_child(parent_a, a, "PA-A", - by_parent_cb ? &child_of_bds : &detach_by_driver_cb_= class, + &detach_by_driver_cb_class, BDRV_CHILD_DATA, &error_abort); =20 g_assert_cmpint(parent_a->refcnt, =3D=3D, 1); @@ -1226,7 +1211,6 @@ static void test_detach_indirect(bool by_parent_cb) .parent_b =3D parent_b, .child_b =3D child_b, .c =3D c, - .by_parent_cb =3D by_parent_cb, }; acb =3D blk_aio_preadv(blk, 0, &qiov, 0, detach_by_parent_aio_cb, NULL= ); g_assert(acb !=3D NULL); @@ -1271,14 +1255,9 @@ static void test_detach_indirect(bool by_parent_cb) bdrv_unref(c); } =20 -static void test_detach_by_parent_cb(void) -{ - test_detach_indirect(true); -} - static void test_detach_by_driver_cb(void) { - test_detach_indirect(false); + test_detach_indirect(); } =20 static void test_append_to_drained(void) @@ -2029,7 +2008,6 @@ int main(int argc, char **argv) g_test_add_func("/bdrv-drain/deletion/drain", test_delete_by_drain); g_test_add_func("/bdrv-drain/detach/drain_all", test_detach_by_drain_a= ll); g_test_add_func("/bdrv-drain/detach/drain", test_detach_by_drain); - g_test_add_func("/bdrv-drain/detach/parent_cb", test_detach_by_parent_= cb); g_test_add_func("/bdrv-drain/detach/driver_cb", test_detach_by_driver_= cb); =20 g_test_add_func("/bdrv-drain/attach/drain", test_append_to_drained); --=20 2.38.1 From nobody Sat May 18 18:02:00 2024 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=1670850510; cv=none; d=zohomail.com; s=zohoarc; b=M8oNpjhJw/0yb+hBq9CB5eNs7b7ANGpgB73+2w9MVLl1Coq2SFoxfRTImTZJ/vEHzKNB7Mud5mVsbCHaTHs6wRGxwxK0GNePE2DXsb+rh0FwO/kMNXWI4ZVYBcAEbrM3FaLVRzcoPBqKaWBTAEQE2ZivI23eInj7hhSKA+0JfEk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670850510; 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=VbsEJKW9F3PhNnVVdbZPvZl4EDjDR53UnrFcZTkNxbk=; b=lkWcN+UROH6y7MLqisQKfqtdXb3/r9tN3azNUg1S5WXgzrFrOsLD1tHLlXZ/vTL7AcYH9QgArEvOSVG9H3Rb0a/jgAWNv1cMlez+Kl4YUEpr0BJFNelkIp1uP2tplvRaH42dV2nvpKOdYr3v7aCXT2ltKIRqj9t/zsobygYD/mM= 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 1670850510130207.25262303334011; Mon, 12 Dec 2022 05:08:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iPM-0000vT-A4; Mon, 12 Dec 2022 07:59:48 -0500 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 1p4iPH-0000qi-6q for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:45 -0500 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 1p4iPF-0000Zc-BN for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:42 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-209-13RiYR62PN2Utp7arV06aw-1; Mon, 12 Dec 2022 07:59:39 -0500 Received: by mail-wm1-f71.google.com with SMTP id c187-20020a1c35c4000000b003cfee3c91cdso3323784wma.6 for ; Mon, 12 Dec 2022 04:59:39 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id w8-20020a5d5448000000b0022584c82c80sm8758395wrv.19.2022.12.12.04.59.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 04:59:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670849980; 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=VbsEJKW9F3PhNnVVdbZPvZl4EDjDR53UnrFcZTkNxbk=; b=aj7CoYR6A41oDQ55UyiNfuwGXNLKHXozxNZYi8HewuKX7BsgZtEZ2J33fhvZEvNdUjIyGz Uy4CtB01KMN9jZq89udQk6HG5bx0pwXCOoMCH3ZyANE/xCI5ZlYlcgkZ/88+Wwir6+r4KW lHQXhrEXDWpwX9MH+5EMxcwCXR5Kuvo= X-MC-Unique: 13RiYR62PN2Utp7arV06aw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VbsEJKW9F3PhNnVVdbZPvZl4EDjDR53UnrFcZTkNxbk=; b=wGYsFWZQju3sFQhSGDiN8szGY9pOzZaQITNKLyTSQQpDfIM0pyGDLz/h1xrAmyS7id qpmeo+g+7bRapyUj3ip0J6rgBRsVVGEHy1m7VR2PnxkY+MkDZJlBez3Rm4RtDFvKYezb NdXcfXqVE8j5Y15gqkIoHnMXAcs4eCrMLeJSUVKN2D/caTyaMhx71rcEzZWD2IHwfSXQ YFk+NjjYkh/9pkJYh4yor020pObNskQZjwWfQE0JssVj+ehbAJDhUl4bT87EHqfh5pea h587Hr1/Isp31GP0aR56bP5AwkVhLNKCDY+PXK5j7xm7Hs4XGtGbjD2F+X3g/pNtavAP wq5g== X-Gm-Message-State: ANoB5pnPKJkq/6IlTC8bs+MOX2hxNjKpMjI3Nb94M3Y4UcL4lTQhk9RU HdRoOgO8L7Tgw0JwFW55snxbGP3Tzy8pNjN1q+FanihBcMhkn6rHPXm6cOrhtJb4KDY3tPGhn4r Akub24JgO1WlZGQj/u+b4ZBJ/mcW93yJPvo0Ox0f8M1/5N2iwC9s7uSRkbm9gtU5+6Dg= X-Received: by 2002:a05:600c:1c9e:b0:3d2:7a7:5cc6 with SMTP id k30-20020a05600c1c9e00b003d207a75cc6mr10288532wms.18.1670849978084; Mon, 12 Dec 2022 04:59:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf4E8DqwvsoJwSrBffwYTWyWfGVeX6dSyCB0WT4qrV1Zb6sxPqpOuig3C55p8/dGdg+YY0+koQ== X-Received: by 2002:a05:600c:1c9e:b0:3d2:7a7:5cc6 with SMTP id k30-20020a05600c1c9e00b003d207a75cc6mr10288513wms.18.1670849977760; Mon, 12 Dec 2022 04:59:37 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com Subject: [PATCH 05/15] tests/unit/test-bdrv-drain.c: graph setup functions can't run in coroutines Date: Mon, 12 Dec 2022 13:59:10 +0100 Message-Id: <20221212125920.248567-6-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: 1670850511684100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito Graph initialization functions like blk_new(), bdrv_new() and so on should not run in a coroutine. In fact, they might invoke a drain (for example blk_insert_bs eventually calls bdrv_replace_child_noperm) that in turn can invoke callbacks like bdrv_do_drained_begin_quiesce(), that asserts exactly that we are not in a coroutine. Move the initialization phase of test_drv_cb and test_quiesce_common outside the coroutine logic. Signed-off-by: Emanuele Giuseppe Esposito Message-Id: <20220314131854.2202651-9-eesposit@redhat.com> Signed-off-by: Paolo Bonzini --- tests/unit/test-bdrv-drain.c | 110 ++++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 41 deletions(-) diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 3be214f30186..f677f1d9fc25 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -126,7 +126,8 @@ static void aio_ret_cb(void *opaque, int ret) } =20 typedef struct CallInCoroutineData { - void (*entry)(void); + void (*entry)(void *); + void *arg; bool done; } CallInCoroutineData; =20 @@ -134,15 +135,16 @@ static coroutine_fn void call_in_coroutine_entry(void= *opaque) { CallInCoroutineData *data =3D opaque; =20 - data->entry(); + data->entry(data->arg); data->done =3D true; } =20 -static void call_in_coroutine(void (*entry)(void)) +static void call_in_coroutine(void (*entry)(void *), void *arg) { Coroutine *co; CallInCoroutineData data =3D { .entry =3D entry, + .arg =3D arg, .done =3D false, }; =20 @@ -199,26 +201,28 @@ static void do_drain_end_unlocked(enum drain_type dra= in_type, BlockDriverState * } } =20 -static void test_drv_cb_common(enum drain_type drain_type, bool recursive) -{ +typedef struct TestDriverCBData { + enum drain_type drain_type; + bool recursive; BlockBackend *blk; BlockDriverState *bs, *backing; - BDRVTestState *s, *backing_s; +} TestDriverCBData; + +static void test_drv_cb_common(void *arg) +{ + TestDriverCBData *data =3D arg; + BlockBackend *blk =3D data->blk; + BlockDriverState *bs =3D data->bs; + BlockDriverState *backing =3D data->backing; + enum drain_type drain_type =3D data->drain_type; + bool recursive =3D data->recursive; + BDRVTestState *s =3D bs->opaque; + BDRVTestState *backing_s =3D backing->opaque; BlockAIOCB *acb; int aio_ret; =20 QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, 0); =20 - blk =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); - bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, - &error_abort); - s =3D bs->opaque; - blk_insert_bs(blk, bs, &error_abort); - - backing =3D bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abor= t); - backing_s =3D backing->opaque; - bdrv_set_backing_hd(bs, backing, &error_abort); - /* Simple bdrv_drain_all_begin/end pair, check that CBs are called */ g_assert_cmpint(s->drain_count, =3D=3D, 0); g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); @@ -252,44 +256,67 @@ static void test_drv_cb_common(enum drain_type drain_= type, bool recursive) =20 g_assert_cmpint(s->drain_count, =3D=3D, 0); g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); +} =20 - bdrv_unref(backing); - bdrv_unref(bs); - blk_unref(blk); +static void test_common_cb(enum drain_type drain_type, bool in_coroutine, + void (*cb)(void *)) +{ + TestDriverCBData data; + + data.drain_type =3D drain_type; + data.recursive =3D (drain_type !=3D BDRV_DRAIN); + + data.blk =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_AL= L); + data.bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, + &error_abort); + blk_insert_bs(data.blk, data.bs, &error_abort); + + data.backing =3D bdrv_new_open_driver(&bdrv_test, "backing", 0, &error= _abort); + bdrv_set_backing_hd(data.bs, data.backing, &error_abort); + + if (in_coroutine) { + call_in_coroutine(cb, &data); + } else { + cb(&data); + } + + bdrv_unref(data.backing); + bdrv_unref(data.bs); + blk_unref(data.blk); +} + +static void test_drv_cb(enum drain_type drain_type, bool in_coroutine) +{ + test_common_cb(drain_type, in_coroutine, test_drv_cb_common); } =20 static void test_drv_cb_drain_all(void) { - test_drv_cb_common(BDRV_DRAIN_ALL, true); + test_drv_cb(BDRV_DRAIN_ALL, false); } =20 static void test_drv_cb_drain(void) { - test_drv_cb_common(BDRV_DRAIN, false); + test_drv_cb(BDRV_DRAIN, false); } =20 static void test_drv_cb_co_drain_all(void) { - call_in_coroutine(test_drv_cb_drain_all); + test_drv_cb(BDRV_DRAIN_ALL, true); } =20 static void test_drv_cb_co_drain(void) { - call_in_coroutine(test_drv_cb_drain); + test_drv_cb(BDRV_DRAIN, true); } =20 -static void test_quiesce_common(enum drain_type drain_type, bool recursive) +static void test_quiesce_common(void *arg) { - BlockBackend *blk; - BlockDriverState *bs, *backing; - - blk =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); - bs =3D bdrv_new_open_driver(&bdrv_test, "test-node", BDRV_O_RDWR, - &error_abort); - blk_insert_bs(blk, bs, &error_abort); - - backing =3D bdrv_new_open_driver(&bdrv_test, "backing", 0, &error_abor= t); - bdrv_set_backing_hd(bs, backing, &error_abort); + TestDriverCBData *data =3D arg; + BlockDriverState *bs =3D data->bs; + BlockDriverState *backing =3D data->backing; + enum drain_type drain_type =3D data->drain_type; + bool recursive =3D data->recursive; =20 g_assert_cmpint(bs->quiesce_counter, =3D=3D, 0); g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); @@ -307,30 +334,31 @@ static void test_quiesce_common(enum drain_type drain= _type, bool recursive) =20 g_assert_cmpint(bs->quiesce_counter, =3D=3D, 0); g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); +} =20 - bdrv_unref(backing); - bdrv_unref(bs); - blk_unref(blk); +static void test_quiesce(enum drain_type drain_type, bool in_coroutine) +{ + test_common_cb(drain_type, in_coroutine, test_quiesce_common); } =20 static void test_quiesce_drain_all(void) { - test_quiesce_common(BDRV_DRAIN_ALL, true); + test_quiesce(BDRV_DRAIN_ALL, false); } =20 static void test_quiesce_drain(void) { - test_quiesce_common(BDRV_DRAIN, false); + test_quiesce(BDRV_DRAIN, false); } =20 static void test_quiesce_co_drain_all(void) { - call_in_coroutine(test_quiesce_drain_all); + test_quiesce(BDRV_DRAIN_ALL, true); } =20 static void test_quiesce_co_drain(void) { - call_in_coroutine(test_quiesce_drain); + test_quiesce(BDRV_DRAIN, true); } =20 static void test_nested(void) --=20 2.38.1 From nobody Sat May 18 18:02:00 2024 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=1670850357; cv=none; d=zohomail.com; s=zohoarc; b=kHcWuzkl4mJYlG07tLyKY8c09ueTKwIlPgrDnpnVi735d5FzVsyT78iZqbsc+Xwjy3ESm4Q0fOlbDua80EPm8/I5xGIRiXPxnKKQb7x0tE0Vw97juAqxLEhCKAzfPPthB31hF0eX0W9G6spqLduqR5/y8/xTel4i+d4FNdh2C2E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670850357; 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=rsVfL5XDIu6LZaIdcZU4pJWqYmJqYM1K2rNCMTcYK2w=; b=ItnFas40mpkBGAtf+Hl4iD1ShcimezuBYKHhXFnprJ9jiSEvcKgK1HTwmoAleXaRh9nMNCYRQIIxPrnFNtVpq2OHQvpgJBe6bjDEW1nig8Dt5tQgdLpHY7iNKfrN8vsxLMAItddPB8pF5ZgmYqQuASw8Wo3nSKbUG9JtaDwGimw= 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 1670850357370946.2246247930905; Mon, 12 Dec 2022 05:05:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iPO-0000yz-Fl; Mon, 12 Dec 2022 07:59:50 -0500 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 1p4iPK-0000so-Ch for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:46 -0500 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 1p4iPI-0000aA-US for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:46 -0500 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-590-eUsRFmDdOYKWq56Io7A5sA-1; Mon, 12 Dec 2022 07:59:42 -0500 Received: by mail-wm1-f69.google.com with SMTP id g9-20020a7bc4c9000000b003d214cffa4eso1966947wmk.5 for ; Mon, 12 Dec 2022 04:59:42 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id d6-20020a5d6446000000b002425504ae7dsm8804822wrw.80.2022.12.12.04.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 04:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670849984; 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=rsVfL5XDIu6LZaIdcZU4pJWqYmJqYM1K2rNCMTcYK2w=; b=GE/VHnTQGd+ZePN/1BkpdcdH7OGYOey2C6zq5H+jn6g0GywV3ieizuIgNVEic2Kb98+DLE EVXHhJUQDSlFGtIHfPYpcihnQBFR/veqwA4+Og0PkhPGzgira0jkHaEsc0CdajBmV2jV5f H4LGCblfbUe8nHA+64iSXPIHyEERQkY= X-MC-Unique: eUsRFmDdOYKWq56Io7A5sA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rsVfL5XDIu6LZaIdcZU4pJWqYmJqYM1K2rNCMTcYK2w=; b=OlafGTHmaQb0JUsFP7KdGtVaa/VY+V59o568MmaTBIqQibkQA7Rzluweggm/WvBlwR 1qsvq2JIQ13ByptEZfCRAU5D6mIuY7APGC2Lt/8uovb8M0iRq3Es7MWx0PBV476dyEK1 6jWAzLZqdhmD0A+hvt3bY2J/k3/uxXEWLVOAdsmGERROjR3ZQF0Wo0UjTwCpqFxoeOVQ +sXDc7YVleWn/4pFsXRGblqewU08e3nw6zGXbHVZe/5pXZOrqx5LwzkMKPcRHCNej8gn E0bZqtDOGLDap4kMfqF0U5rYq5AfUe17FLQa+FcCqdK7GZgc4q5IGKCPbq7UnM1Ly9Pr EA/g== X-Gm-Message-State: ANoB5pm4BGJy2sgGDttxXLjG2T8R9io67vexpdsBlEO52fh20SY7oHLm TU+RG+zo32M4pYgG4iVMiG8sXmbU6oRembSX9PkRSZmuIaDUGnfNuOgyoZc11onBELV9l5kkKgD wlLgi4rdq521DPJgXMZu6ularVOKEjvmtDNk5tyJT1D+BZhrENnVh5LFpJhcScGsPFHo= X-Received: by 2002:a5d:5a90:0:b0:242:6af:8a26 with SMTP id bp16-20020a5d5a90000000b0024206af8a26mr9976942wrb.70.1670849980961; Mon, 12 Dec 2022 04:59:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf4TrapX/VdjyUPZXOxDU3lsrrEtQkqzDYzFhO1tQYbK2kli88ZRtlYEgHaWgvtDsfpLSkDXQg== X-Received: by 2002:a5d:5a90:0:b0:242:6af:8a26 with SMTP id bp16-20020a5d5a90000000b0024206af8a26mr9976925wrb.70.1670849980694; Mon, 12 Dec 2022 04:59:40 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com Subject: [PATCH 06/15] tests/qemu-iotests/030: test_stream_parallel should use auto_finalize=False Date: Mon, 12 Dec 2022 13:59:11 +0100 Message-Id: <20221212125920.248567-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1670850358249100005 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito First, use run_job() instead of the current logic to run the stream job. Then, use auto_finalize=3DFalse to be sure that the job is not automatically deleted once it is done. In this way, if the job finishes before we want, it is not finalized yet so the other commands can still execute without failing. run_job() will then take care of calling job-finalize. Signed-off-by: Emanuele Giuseppe Esposito Suggested-by: Kevin Wolf Message-Id: <20220314131854.2202651-11-eesposit@redhat.com> Signed-off-by: Paolo Bonzini --- tests/qemu-iotests/030 | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/qemu-iotests/030 b/tests/qemu-iotests/030 index 98595d47fec3..e5c13cb5fe4c 100755 --- a/tests/qemu-iotests/030 +++ b/tests/qemu-iotests/030 @@ -256,7 +256,7 @@ class TestParallelOps(iotests.QMPTestCase): pending_jobs.append(job_id) result =3D self.vm.qmp('block-stream', device=3Dnode_name, job_id=3Djob_id, bottom=3Df'node{i-1}', - speed=3D1024) + speed=3D1024, auto_finalize=3DFalse) self.assert_qmp(result, 'return', {}) =20 # Do this in reverse: After unthrottling them, some jobs may finish @@ -272,14 +272,8 @@ class TestParallelOps(iotests.QMPTestCase): result =3D self.vm.qmp('block-job-set-speed', device=3Djob, sp= eed=3D0) self.assert_qmp(result, 'return', {}) =20 - # Wait for all jobs to be finished. - while len(pending_jobs) > 0: - for event in self.vm.get_qmp_events(wait=3DTrue): - if event['event'] =3D=3D 'BLOCK_JOB_COMPLETED': - job_id =3D self.dictpath(event, 'data/device') - self.assertTrue(job_id in pending_jobs) - self.assert_qmp_absent(event, 'data/error') - pending_jobs.remove(job_id) + for job in pending_jobs: + self.vm.run_job(job=3Djob, auto_finalize=3DFalse) =20 self.assert_no_active_block_jobs() self.vm.shutdown() --=20 2.38.1 From nobody Sat May 18 18:02:00 2024 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=1670850518; cv=none; d=zohomail.com; s=zohoarc; b=RPOklt9peC2aTvs7Ly6BEasDQxLZF8bXzB+LWHFFTGS+FfJjmjrm+oSjFztriT1RysrkRq+RWYBWYNT6HP1YMkRmazoytbAJI2E02xzb0gVXsK8HvC4O96aAFFwhJCQJTXZxlQDQvRLXAIq1Q6Gfcmw8kprvtXbAtn+xBvNGDMQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670850518; 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=uLV1gQudJd+2ESbdrMy1FxHMXOTy4Nn2ipJ8lzvzrV0=; b=da/UrDKpH9mpkBOz3T2zETQwNQt9+LZzfkcaiUtYxUPNPvXbZDXiGtKR99jJA742bBP8AAXwNpvUbMvtx1Hl8YpmXOZhrOZcxC2fW1Ug2kiBUBD5x7i1Ml8kiMkQuU8MKwoiPEvIBdWgWxSOWr2zyN2SD9iPzEj0ThjRsyCvr6Y= 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 1670850518773285.45548960649046; Mon, 12 Dec 2022 05:08:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iPP-000111-7v; Mon, 12 Dec 2022 07:59:51 -0500 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 1p4iPM-0000w7-RA for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:48 -0500 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 1p4iPL-0000c5-7o for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:48 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-73-d-2VbveMMKGVS7gXAZY7QQ-1; Mon, 12 Dec 2022 07:59:45 -0500 Received: by mail-wm1-f72.google.com with SMTP id r67-20020a1c4446000000b003d09b0fbf54so4143481wma.3 for ; Mon, 12 Dec 2022 04:59:45 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id u17-20020a05600c19d100b003b4fe03c881sm9970929wmq.48.2022.12.12.04.59.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 04:59:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670849986; 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=uLV1gQudJd+2ESbdrMy1FxHMXOTy4Nn2ipJ8lzvzrV0=; b=TSCvr3NGG1I+4iFxEFxrn3oe+FvuY/RnNICD2eUHxWCicA9mJTn5DduiOCzQ8Xoo5J6caK 18nCP8QBETTuAMsytX2+scYoBcLSMs+/cLQMsIEp19ELMI1E0I7Aqw2v9puLjsjYtNUhhP RiTlpQ7v9PyA1KXxvdujidSLvFxpxUE= X-MC-Unique: d-2VbveMMKGVS7gXAZY7QQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uLV1gQudJd+2ESbdrMy1FxHMXOTy4Nn2ipJ8lzvzrV0=; b=olcipee14mVEy7rDt0jOMsR9SWZsyOoFzHpFX0hktC3eaExwHDlrumKgWfiObf/mTf 4SBTRh6P6EO4zaT3DxduZZec9B/i/IQcaDlFkMpjXOUD7izD49oZGrB/sUduugk6papo xO1EuFVWn7DoqyJRistFOU15jejMzRfIq6xt7z1ECvKIxf3vGAVSIUBMF89xdsjX3wGw 9GitfCwpEhovQENtOze6ZFgIz9WwQeagGW4X/2/tIGyQoeaL+kMqQxx85DgAfEyEQuqC OXA61yItocLxg18Tew1QcZrOnfyIapUENayOsGMDpblyRZtPISSe1ocRUQV7pWLD2SBJ dAaQ== X-Gm-Message-State: ANoB5pk3QSsjyaHh8jfYlhyfOOvx5vWolhqx/xveIO6vgpxwGfidZAPc Mzrk87y9uoI6PiFitpO+53to7+KoAiW/G9qPdnbkiNmeho9zYmhjscXqQdyFgbdDsVavcaZyWWA dfox9I/LPig6XgMzuxHoIB+tH8RlWaSMwHZnoVBeIC4rNTQyKvlJ+2838UNl+bCGh5Pg= X-Received: by 2002:a05:600c:348a:b0:3cf:69f4:bfd4 with SMTP id a10-20020a05600c348a00b003cf69f4bfd4mr12547445wmq.7.1670849984063; Mon, 12 Dec 2022 04:59:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf4UKkREgl74Wde8Kle2VYN31cjdWZN1cwSzBnrOfSCqPwNuXN0gv7MBlCzKO3pH/MGQYiutyw== X-Received: by 2002:a05:600c:348a:b0:3cf:69f4:bfd4 with SMTP id a10-20020a05600c348a00b003cf69f4bfd4mr12547427wmq.7.1670849983764; Mon, 12 Dec 2022 04:59:43 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com Subject: [PATCH 07/15] block-backend: enter aio coroutine only after drain Date: Mon, 12 Dec 2022 13:59:12 +0100 Message-Id: <20221212125920.248567-8-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: 1670850519718100002 Content-Type: text/plain; charset="utf-8" When called from within (another) coroutine, aio_co_enter will not enter a coroutine immediately; instead the new coroutine is scheduled to run after qemu_coroutine_yield(). This however might cause the currently-running coroutine to yield without having raised blk->in_flight. If it was a ->drained_begin() callback who scheduled the coroutine, bdrv_drained_begin() might exit without waiting for the I/O operation to finish. Right now, this is masked by unnecessary polling done by bdrv_drained_begin() after the callbacks return, but it is wrong and a latent bug. So, ensure that blk_inc_in_flight() and blk_wait_while_drained() are called before aio_co_enter(). To do so, pull the call to blk_wait_while_drained() out of the blk_co_do_* functions, which are called from the AIO coroutines, and place them separately in the public blk_co_* functions and in blk_aio_prwv. Signed-off-by: Paolo Bonzini --- block/block-backend.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 2852a892de6c..c4a884b86c2b 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1288,8 +1288,6 @@ blk_co_do_preadv_part(BlockBackend *blk, int64_t offs= et, int64_t bytes, BlockDriverState *bs; IO_CODE(); =20 - blk_wait_while_drained(blk); - /* Call blk_bs() only after waiting, the graph may have changed */ bs =3D blk_bs(blk); trace_blk_co_preadv(blk, bs, offset, bytes, flags); @@ -1332,6 +1330,7 @@ int coroutine_fn blk_co_preadv(BlockBackend *blk, int= 64_t offset, IO_OR_GS_CODE(); =20 blk_inc_in_flight(blk); + blk_wait_while_drained(blk); ret =3D blk_co_do_preadv_part(blk, offset, bytes, qiov, 0, flags); blk_dec_in_flight(blk); =20 @@ -1346,6 +1345,7 @@ int coroutine_fn blk_co_preadv_part(BlockBackend *blk= , int64_t offset, IO_OR_GS_CODE(); =20 blk_inc_in_flight(blk); + blk_wait_while_drained(blk); ret =3D blk_co_do_preadv_part(blk, offset, bytes, qiov, qiov_offset, f= lags); blk_dec_in_flight(blk); =20 @@ -1362,8 +1362,6 @@ blk_co_do_pwritev_part(BlockBackend *blk, int64_t off= set, int64_t bytes, BlockDriverState *bs; IO_CODE(); =20 - blk_wait_while_drained(blk); - /* Call blk_bs() only after waiting, the graph may have changed */ bs =3D blk_bs(blk); trace_blk_co_pwritev(blk, bs, offset, bytes, flags); @@ -1399,6 +1397,7 @@ int coroutine_fn blk_co_pwritev_part(BlockBackend *bl= k, int64_t offset, IO_OR_GS_CODE(); =20 blk_inc_in_flight(blk); + blk_wait_while_drained(blk); ret =3D blk_co_do_pwritev_part(blk, offset, bytes, qiov, qiov_offset, = flags); blk_dec_in_flight(blk); =20 @@ -1543,6 +1542,7 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, in= t64_t offset, Coroutine *co; =20 blk_inc_in_flight(blk); + blk_wait_while_drained(blk); acb =3D blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); acb->rwco =3D (BlkRwCo) { .blk =3D blk, @@ -1667,8 +1667,6 @@ blk_co_do_ioctl(BlockBackend *blk, unsigned long int = req, void *buf) { IO_CODE(); =20 - blk_wait_while_drained(blk); - if (!blk_is_available(blk)) { return -ENOMEDIUM; } @@ -1683,6 +1681,7 @@ int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsi= gned long int req, IO_OR_GS_CODE(); =20 blk_inc_in_flight(blk); + blk_wait_while_drained(blk); ret =3D blk_co_do_ioctl(blk, req, buf); blk_dec_in_flight(blk); =20 @@ -1713,8 +1712,6 @@ blk_co_do_pdiscard(BlockBackend *blk, int64_t offset,= int64_t bytes) int ret; IO_CODE(); =20 - blk_wait_while_drained(blk); - ret =3D blk_check_byte_request(blk, offset, bytes); if (ret < 0) { return ret; @@ -1748,6 +1745,7 @@ int coroutine_fn blk_co_pdiscard(BlockBackend *blk, i= nt64_t offset, IO_OR_GS_CODE(); =20 blk_inc_in_flight(blk); + blk_wait_while_drained(blk); ret =3D blk_co_do_pdiscard(blk, offset, bytes); blk_dec_in_flight(blk); =20 @@ -1757,7 +1755,6 @@ int coroutine_fn blk_co_pdiscard(BlockBackend *blk, i= nt64_t offset, /* To be called between exactly one pair of blk_inc/dec_in_flight() */ static int coroutine_fn blk_co_do_flush(BlockBackend *blk) { - blk_wait_while_drained(blk); IO_CODE(); =20 if (!blk_is_available(blk)) { @@ -1789,6 +1786,7 @@ int coroutine_fn blk_co_flush(BlockBackend *blk) IO_OR_GS_CODE(); =20 blk_inc_in_flight(blk); + blk_wait_while_drained(blk); ret =3D blk_co_do_flush(blk); blk_dec_in_flight(blk); =20 --=20 2.38.1 From nobody Sat May 18 18:02:00 2024 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=1670850626; cv=none; d=zohomail.com; s=zohoarc; b=kkuuS4YZTTmcHRxeNqa1a4ePR2vkswLjYl9v3xN/pKY8NAXjumYy7OJIlEWm5shFFU8Ogjv6t2CIWzDmIX9/qx5oI1lIApluucbfSofDGt7nCUbEu7lZ/9dW7Vz4+a2e5QkFsXA+BniJQVGW8SygFNG9V4rpKSYbmosULWsax4s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670850626; 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=llzwygXVBbniiEaNBjy/u1gez32vAXcC9dHquqw9tLk=; b=I2lqLDhI/1xR+CUd6jq1T1xd5BKt30R+vxoa674JrQ7iy2wctI77E6Hll2mHfqC5Nbuqubxcrv3aeAT3LQ4hPNtEOY55cQ08p0e5AkPrT6jMtySMOVtVpkThjZaO0HRcCZ2BkfyQBlSN9EQUPYgxD3Ik3/NX1kt5VlPpfVN93mw= 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 1670850626471507.4023136112372; Mon, 12 Dec 2022 05:10:26 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iPR-000152-8U; Mon, 12 Dec 2022 07:59:53 -0500 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 1p4iPP-00011w-NY for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:51 -0500 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 1p4iPO-0000cr-7e for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:51 -0500 Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-531-LnUEca8GNja5Mu7oxb4iPg-1; Mon, 12 Dec 2022 07:59:48 -0500 Received: by mail-wr1-f72.google.com with SMTP id h10-20020adfaa8a000000b0024208cf285eso2243219wrc.22 for ; Mon, 12 Dec 2022 04:59:48 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id bu4-20020a056000078400b00236576c8eddsm8892663wrb.12.2022.12.12.04.59.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 04:59:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670849989; 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=llzwygXVBbniiEaNBjy/u1gez32vAXcC9dHquqw9tLk=; b=Teyb2irZCbY4Oe8LRwuxxi2FrpTfNTfJUApZF2TlEqKce5wL8BR03EtCBhQtOlYyrjaxzZ sq89uf8Y5nOoCf/bQLTrKc9IoSqUbrN5Tl0AbZDyC8SqfZUEYSWo3paT/xQJ8fsHO66qlG EnW/lBSTcata1Kf3Cg6fl+xgh/NrVEE= X-MC-Unique: LnUEca8GNja5Mu7oxb4iPg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=llzwygXVBbniiEaNBjy/u1gez32vAXcC9dHquqw9tLk=; b=EtJ7tFxEkJBX4JsnHFXI2dA5J48yTsDe7ySqjKDL6AwWSGreGrVSNZfI23GeTS8E4a LX9ewE6Kv+2+08jUULD1LoxCfibhUfxHesFGBBRRLORx2uHSicvKzRYn/YQYMriPw6r9 Y7qQZXIw6OfXxxLVx4V4arT79xc7Gag0vHaE8h9i8ghAyJ6rCzPxexhecvsmtcX2L7xX MOSqb8uZfiA21IApXkOFDdJOmTWKfA7Vx1uhe8dCDr8nFVNwLNl95UIXkrv1W8Sqzn4+ M+xYapkBR+yigr5fmyrLMe0JHICGq9gL/NkHaQLugHixuX0YSRrxSDVF26thIShrJ9Yk gM2w== X-Gm-Message-State: ANoB5pnE4ZgfVA12XYOYjlQgNjvnK0JLeUjZ7O5TQp5fX5XjhRvGy2ev CYQ1T1VBNlUPhXbhyBBxd28++x1h5SCEjiAqspaJ5lMPCEtQZn6aGpkH9QPGfAkO+KnYEcBvLWk jWj0CXXdn6OUY9AQjp5WG3b143YvVxehY71TQGA3oeIb22umxXEJyYwDHyc2Fz+9+PPQ= X-Received: by 2002:a5d:4c43:0:b0:242:290c:34e8 with SMTP id n3-20020a5d4c43000000b00242290c34e8mr10801409wrt.31.1670849986749; Mon, 12 Dec 2022 04:59:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf6jycmQObNB8QUmj/WIQMGf5ThfU60Z7zejjRpz6kM52n9tqWtAzxgUAWXCpfyElSYi+Kn6kg== X-Received: by 2002:a5d:4c43:0:b0:242:290c:34e8 with SMTP id n3-20020a5d4c43000000b00242290c34e8mr10801392wrt.31.1670849986459; Mon, 12 Dec 2022 04:59:46 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com Subject: [PATCH 08/15] nbd: a BlockExport always has a BlockBackend Date: Mon, 12 Dec 2022 13:59:13 +0100 Message-Id: <20221212125920.248567-9-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: 1670850645859100002 Content-Type: text/plain; charset="utf-8" exp->common.blk cannot be NULL, nbd_export_delete() is only called from blk_exp_unref() and in turn that can only happen after blk_exp_add() has asserted exp->blk !=3D NULL. Signed-off-by: Paolo Bonzini --- nbd/server.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index c53c39560e50..462ddb0e4adb 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1848,15 +1848,13 @@ static void nbd_export_delete(BlockExport *blk_exp) g_free(exp->description); exp->description =3D NULL; =20 - if (exp->common.blk) { - if (exp->eject_notifier_blk) { - notifier_remove(&exp->eject_notifier); - blk_unref(exp->eject_notifier_blk); - } - blk_remove_aio_context_notifier(exp->common.blk, blk_aio_attached, - blk_aio_detach, exp); - blk_set_disable_request_queuing(exp->common.blk, false); + if (exp->eject_notifier_blk) { + notifier_remove(&exp->eject_notifier); + blk_unref(exp->eject_notifier_blk); } + blk_remove_aio_context_notifier(exp->common.blk, blk_aio_attached, + blk_aio_detach, exp); + blk_set_disable_request_queuing(exp->common.blk, false); =20 for (i =3D 0; i < exp->nr_export_bitmaps; i++) { bdrv_dirty_bitmap_set_busy(exp->export_bitmaps[i], false); --=20 2.38.1 From nobody Sat May 18 18:02:00 2024 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=1670850055; cv=none; d=zohomail.com; s=zohoarc; b=Vtr1E52zupMQP8ksdlJ2wpQYxN00aa/rKtVcqB2Vv/yeHXPV2lerzAzfedAe8gmwPTF7J1bUthNXfqikCPrltYLkCdWDvXmKMHoKb8+RFJUP47sEqVvQXuD/xCVDpn+PRqZ7PshV0BMf4+cGveT/WaxMqG6IPvKpjmIgDBagOys= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670850055; 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=372OTOBxI2AXWgTlqDZU+4Uyk2bfD1HPIFuxCc+rwBM=; b=DJE5XjhcPg+nmNkBvJfdJgNbhZy5+1TIlGNEpFAk6Rk+vd2625Cxz7JuzAFxSeG+NovbyCPtLDjlk+XeXvzZ2f/V1OqtunDs0X02F0X80de7PYfbAzJu1g89rkd53CfkLNK3Rkkb3gC8XUuKoJLLvn1L05vGLAdc2a2430wAyCM= 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 1670850055975890.5916611977211; Mon, 12 Dec 2022 05:00:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iPu-0001N5-CJ; Mon, 12 Dec 2022 08:00:29 -0500 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 1p4iPT-0001CH-Lt for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:55 -0500 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 1p4iPR-0000dL-FE for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:55 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-574-evXOj14WPJWrTR_tCQ_O5A-1; Mon, 12 Dec 2022 07:59:52 -0500 Received: by mail-wm1-f71.google.com with SMTP id r129-20020a1c4487000000b003d153a83d27so3347352wma.0 for ; Mon, 12 Dec 2022 04:59:51 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id bt4-20020a056000080400b002365cd93d05sm8893696wrb.102.2022.12.12.04.59.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 04:59:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670849992; 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=372OTOBxI2AXWgTlqDZU+4Uyk2bfD1HPIFuxCc+rwBM=; b=ZcpnUjbIKdJTeRaQOX2knRBvLEbZCGq0G6jX9bq3CD9TXfQi9sI5nCxZqbQ95epZyWwyja wg/8/kgJVEnrNDnbw4WbBb0HPt214BdCfC5tlmiA1WgqGuR2UR7D3raQ9fhObrRykzzpgX CPOmnqkcutPfE0vbHUnjlPE1A9OzeMk= X-MC-Unique: evXOj14WPJWrTR_tCQ_O5A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=372OTOBxI2AXWgTlqDZU+4Uyk2bfD1HPIFuxCc+rwBM=; b=KjFZSkKzwa5UTojfInhn6Y6Necj2DxmMa+VxyS4KhAEHC70sPD33f2LQgZMKcyELGE 53MH305TuPX5P3oKwAIUtn0KyXPJcMSFaHQHc9+wZuI8uJclTWlTJoT0wZ1kojuPfDKe 728VNv4LEmToQcbaATwbIK8Yic0QjUZ8Jui2DCCnTH4b5cRassvZHgaQzM8lzBbBbWY4 4feeqzX0GFNM03bln6sV3ozcZ6DKh7DvHEzSaAVAy5wmLHf0zElmV0ieIYD4GQlTMIev YraTCUIQZxaKy8hH9SUu3FunMpd3dGCGRrxbnoBzkfLCES0WdeAkXkXpTKnJYCVj5gxs NXMg== X-Gm-Message-State: ANoB5pmtkSNsB1mS/HeuVRFva3ANt2OlBHQGkHmaI8kOmP68jIciAE5k QWoyTGnLYbiyN2k99q9n/8mXyNSvBPUtJMpgyjQcH3Tumxe9mQ7YlWGjKxfRtOtsRxsop2tK//5 3RMLIcjjqzsbXccVlQn1dfqTlIMc/dIJPvi5iidDcihoKENzIwUFGs9vXxBeu7V6iCzI= X-Received: by 2002:a05:600c:3b0e:b0:3cf:b067:4161 with SMTP id m14-20020a05600c3b0e00b003cfb0674161mr12355447wms.15.1670849989880; Mon, 12 Dec 2022 04:59:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf4qcHHfGXH8L3OQ3ttO9HnljgxNDW/WWoTyQ70hHUPYe+8Vp7uyG1ksgjKd1ZOYry3PpTWLhw== X-Received: by 2002:a05:600c:3b0e:b0:3cf:b067:4161 with SMTP id m14-20020a05600c3b0e00b003cfb0674161mr12355425wms.15.1670849989508; Mon, 12 Dec 2022 04:59:49 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com Subject: [PATCH 09/15] block-backend: make global properties write-once Date: Mon, 12 Dec 2022 13:59:14 +0100 Message-Id: <20221212125920.248567-10-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1670850057494100003 Content-Type: text/plain; charset="utf-8" The three global properties allow_aio_context_change, disable_request_queuing and allow_write_before_eof are always set for the whole life of a BlockBackend. Make this clear by removing the possibility of clearing them, and by marking the corresponding function GLOBAL_STATE_CODE(). Signed-off-by: Paolo Bonzini --- block/block-backend.c | 24 ++++++++++++++---------- block/commit.c | 4 ++-- block/export/export.c | 2 +- block/mirror.c | 4 ++-- block/parallels.c | 2 +- block/qcow.c | 2 +- block/qcow2.c | 2 +- block/qed.c | 2 +- block/stream.c | 4 ++-- block/vdi.c | 2 +- block/vhdx.c | 2 +- block/vmdk.c | 4 ++-- block/vpc.c | 2 +- include/sysemu/block-backend-io.h | 6 +++--- nbd/server.c | 3 +-- tests/unit/test-bdrv-drain.c | 4 ++-- tests/unit/test-block-iothread.c | 2 +- 17 files changed, 37 insertions(+), 34 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index c4a884b86c2b..fe42d53d655d 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -73,8 +73,13 @@ struct BlockBackend { uint64_t shared_perm; bool disable_perm; =20 + /* + * Can only become true; should be written before any requests is + * submitted to the BlockBackend. + */ bool allow_aio_context_change; bool allow_write_beyond_eof; + bool disable_request_queuing; =20 /* Protected by BQL */ NotifierList remove_bs_notifiers, insert_bs_notifiers; @@ -82,7 +87,6 @@ struct BlockBackend { =20 int quiesce_counter; CoQueue queued_requests; - bool disable_request_queuing; =20 VMChangeStateEntry *vmsh; bool force_allow_inactivate; @@ -1217,22 +1221,22 @@ void blk_iostatus_set_err(BlockBackend *blk, int er= ror) } } =20 -void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow) +void blk_allow_write_beyond_eof(BlockBackend *blk) { - IO_CODE(); - blk->allow_write_beyond_eof =3D allow; + GLOBAL_STATE_CODE(); + blk->allow_write_beyond_eof =3D true; } =20 -void blk_set_allow_aio_context_change(BlockBackend *blk, bool allow) +void blk_allow_aio_context_change(BlockBackend *blk) { - IO_CODE(); - blk->allow_aio_context_change =3D allow; + GLOBAL_STATE_CODE(); + blk->allow_aio_context_change =3D true; } =20 -void blk_set_disable_request_queuing(BlockBackend *blk, bool disable) +void blk_disable_request_queuing(BlockBackend *blk) { - IO_CODE(); - blk->disable_request_queuing =3D disable; + GLOBAL_STATE_CODE(); + blk->disable_request_queuing =3D true; } =20 static int blk_check_byte_request(BlockBackend *blk, int64_t offset, diff --git a/block/commit.c b/block/commit.c index b34634176797..7a448838301b 100644 --- a/block/commit.c +++ b/block/commit.c @@ -379,7 +379,7 @@ void commit_start(const char *job_id, BlockDriverState = *bs, if (ret < 0) { goto fail; } - blk_set_disable_request_queuing(s->base, true); + blk_disable_request_queuing(s->base); s->base_bs =3D base; =20 /* Required permissions are already taken with block_job_add_bdrv() */ @@ -388,7 +388,7 @@ void commit_start(const char *job_id, BlockDriverState = *bs, if (ret < 0) { goto fail; } - blk_set_disable_request_queuing(s->top, true); + blk_disable_request_queuing(s->top); =20 s->backing_file_str =3D g_strdup(backing_file_str); s->on_error =3D on_error; diff --git a/block/export/export.c b/block/export/export.c index 7cc0c25c1c9f..6abfe5becb88 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -155,7 +155,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) blk =3D blk_new(ctx, perm, BLK_PERM_ALL); =20 if (!fixed_iothread) { - blk_set_allow_aio_context_change(blk, true); + blk_allow_aio_context_change(blk); } =20 ret =3D blk_insert_bs(blk, bs, errp); diff --git a/block/mirror.c b/block/mirror.c index 251adc5ae02a..28e76e9dbf55 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1768,8 +1768,8 @@ static BlockJob *mirror_start_job( * ensure that. */ blk_set_force_allow_inactivate(s->target); } - blk_set_allow_aio_context_change(s->target, true); - blk_set_disable_request_queuing(s->target, true); + blk_allow_aio_context_change(s->target); + blk_disable_request_queuing(s->target); =20 s->replaces =3D g_strdup(replaces); s->on_source_error =3D on_source_error; diff --git a/block/parallels.c b/block/parallels.c index bbea2f2221ff..44e18a8cc75d 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -576,7 +576,7 @@ static int coroutine_fn parallels_co_create(BlockdevCre= ateOptions* opts, ret =3D -EPERM; goto out; } - blk_set_allow_write_beyond_eof(blk, true); + blk_allow_write_beyond_eof(blk); =20 /* Create image format */ bat_entries =3D DIV_ROUND_UP(total_size, cl_size); diff --git a/block/qcow.c b/block/qcow.c index 18e17a5b1235..6165885882dd 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -844,7 +844,7 @@ static int coroutine_fn qcow_co_create(BlockdevCreateOp= tions *opts, ret =3D -EPERM; goto exit; } - blk_set_allow_write_beyond_eof(qcow_blk, true); + blk_allow_write_beyond_eof(qcow_blk); =20 /* Create image format */ memset(&header, 0, sizeof(header)); diff --git a/block/qcow2.c b/block/qcow2.c index 7cc49a3a6ce3..133dcef16760 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3634,7 +3634,7 @@ qcow2_co_create(BlockdevCreateOptions *create_options= , Error **errp) ret =3D -EPERM; goto out; } - blk_set_allow_write_beyond_eof(blk, true); + blk_allow_write_beyond_eof(blk); =20 /* Write the header */ QEMU_BUILD_BUG_ON((1 << MIN_CLUSTER_BITS) < sizeof(*header)); diff --git a/block/qed.c b/block/qed.c index 9d54c8eec5b0..6bcbace6f24a 100644 --- a/block/qed.c +++ b/block/qed.c @@ -687,7 +687,7 @@ static int coroutine_fn bdrv_qed_co_create(BlockdevCrea= teOptions *opts, ret =3D -EPERM; goto out; } - blk_set_allow_write_beyond_eof(blk, true); + blk_allow_write_beyond_eof(blk); =20 /* Prepare image format */ header =3D (QEDHeader) { diff --git a/block/stream.c b/block/stream.c index 8744ad103f71..660d9dd4fa22 100644 --- a/block/stream.c +++ b/block/stream.c @@ -331,8 +331,8 @@ void stream_start(const char *job_id, BlockDriverState = *bs, * Disable request queuing in the BlockBackend to avoid deadlocks on d= rain: * The job reports that it's busy until it reaches a pause point. */ - blk_set_disable_request_queuing(s->blk, true); - blk_set_allow_aio_context_change(s->blk, true); + blk_disable_request_queuing(s->blk); + blk_allow_aio_context_change(s->blk); =20 /* * Prevent concurrent jobs trying to modify the graph structure here, = we diff --git a/block/vdi.c b/block/vdi.c index 479bcfe820ed..b5f43f42021a 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -812,7 +812,7 @@ static int coroutine_fn vdi_co_do_create(BlockdevCreate= Options *create_options, goto exit; } =20 - blk_set_allow_write_beyond_eof(blk, true); + blk_allow_write_beyond_eof(blk); =20 /* We need enough blocks to store the given disk size, so always round up. */ diff --git a/block/vhdx.c b/block/vhdx.c index 4c929800feeb..30904dc73978 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -2001,7 +2001,7 @@ static int coroutine_fn vhdx_co_create(BlockdevCreate= Options *opts, ret =3D -EPERM; goto delete_and_exit; } - blk_set_allow_write_beyond_eof(blk, true); + blk_allow_write_beyond_eof(blk); =20 /* Create (A) */ =20 diff --git a/block/vmdk.c b/block/vmdk.c index afd347191527..ed9011648ec5 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2307,7 +2307,7 @@ static int coroutine_fn vmdk_create_extent(const char= *filename, goto exit; } =20 - blk_set_allow_write_beyond_eof(blk, true); + blk_allow_write_beyond_eof(blk); =20 ret =3D vmdk_init_extent(blk, filesize, flat, compress, zeroed_grain, = errp); exit: @@ -2807,7 +2807,7 @@ static BlockBackend * coroutine_fn vmdk_co_create_cb(= int64_t size, int idx, if (!blk) { return NULL; } - blk_set_allow_write_beyond_eof(blk, true); + blk_allow_write_beyond_eof(blk); bdrv_unref(bs); =20 if (size !=3D -1) { diff --git a/block/vpc.c b/block/vpc.c index 6ee95dcb9600..e5c420a8cb76 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -1015,7 +1015,7 @@ static int coroutine_fn vpc_co_create(BlockdevCreateO= ptions *opts, ret =3D -EPERM; goto out; } - blk_set_allow_write_beyond_eof(blk, true); + blk_allow_write_beyond_eof(blk); =20 /* Get geometry and check that it matches the image size*/ ret =3D calculate_rounded_image_size(vpc_opts, &cyls, &heads, &secs_pe= r_cyl, diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index 7ec6d978d408..f77adb1fe294 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -26,9 +26,9 @@ const char *blk_name(const BlockBackend *blk); =20 BlockDriverState *blk_bs(BlockBackend *blk); =20 -void blk_set_allow_write_beyond_eof(BlockBackend *blk, bool allow); -void blk_set_allow_aio_context_change(BlockBackend *blk, bool allow); -void blk_set_disable_request_queuing(BlockBackend *blk, bool disable); +void blk_allow_write_beyond_eof(BlockBackend *blk); +void blk_allow_aio_context_change(BlockBackend *blk); +void blk_disable_request_queuing(BlockBackend *blk); bool blk_iostatus_is_enabled(const BlockBackend *blk); =20 char *blk_get_attached_dev_id(BlockBackend *blk); diff --git a/nbd/server.c b/nbd/server.c index 462ddb0e4adb..5c92bec6d005 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1778,7 +1778,7 @@ static int nbd_export_create(BlockExport *blk_exp, Bl= ockExportOptions *exp_args, * be properly quiesced when entering a drained section, as our corout= ines * servicing pending requests might enter blk_pread(). */ - blk_set_disable_request_queuing(blk, true); + blk_disable_request_queuing(blk); =20 blk_add_aio_context_notifier(blk, blk_aio_attached, blk_aio_detach, ex= p); =20 @@ -1854,7 +1854,6 @@ static void nbd_export_delete(BlockExport *blk_exp) } blk_remove_aio_context_notifier(exp->common.blk, blk_aio_attached, blk_aio_detach, exp); - blk_set_disable_request_queuing(exp->common.blk, false); =20 for (i =3D 0; i < exp->nr_export_bitmaps; i++) { bdrv_dirty_bitmap_set_busy(exp->export_bitmaps[i], false); diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index f677f1d9fc25..d44fa1728589 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -541,7 +541,7 @@ static void test_iothread_common(enum drain_type drain_= type, int drain_thread) &error_abort); s =3D bs->opaque; blk_insert_bs(blk, bs, &error_abort); - blk_set_disable_request_queuing(blk, true); + blk_disable_request_queuing(blk); =20 blk_set_aio_context(blk, ctx_a, &error_abort); aio_context_acquire(ctx_a); @@ -767,7 +767,7 @@ static void test_blockjob_common_drain_node(enum drain_= type drain_type, &error_abort); blk_target =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_= ALL); blk_insert_bs(blk_target, target, &error_abort); - blk_set_allow_aio_context_change(blk_target, true); + blk_allow_aio_context_change(blk_target); =20 aio_context_acquire(ctx); tjob =3D block_job_create("job0", &test_job_driver, NULL, src, diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 8ca5adec5e82..68df827cddd8 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -793,7 +793,7 @@ static void test_propagate_mirror(void) =20 /* ...unless we explicitly allow it */ aio_context_acquire(ctx); - blk_set_allow_aio_context_change(blk, true); + blk_allow_aio_context_change(blk); bdrv_try_change_aio_context(target, ctx, NULL, &error_abort); aio_context_release(ctx); =20 --=20 2.38.1 From nobody Sat May 18 18:02:00 2024 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=1670850071; cv=none; d=zohomail.com; s=zohoarc; b=E0mowsaqBQg8qxHyVCHyLhK6Ano19cMT3CIKLZ1lsEOCUyrhYpIOll4X4Oh6RXDzjGYR+bpD5zr94Xy/LrlvTq+bJPurBFgkf0JffI5RZffKo84kqjjWudDsaHJzR+/TCMZ6Ah2Togrjdppxx4pD8K51nQrhRVkMuP8rSc4SqL0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670850071; 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=SNf+Amfu4RgOHfZAxglCNQQHsEjLkMDXAIJYh2GuBxA=; b=Ze9edp1NrAPsclCP+DnkLBoBdwlLg35wcI3O6W/y/OdQJyrEUfV8MPJiZkssX1c16luIoj22HZTdC5Q0+OCQ7f6R/wh2UIWoKy114z+fMIpf3VOIlUGL5b+29uQg3ITaIlEDxHYb64SKdOOFUKBc4GuRwmXAjqNw6Z/z0xFURLQ= 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 1670850071856111.93333882047011; Mon, 12 Dec 2022 05:01:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iQJ-0001dT-Jq; Mon, 12 Dec 2022 08:00:49 -0500 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 1p4iPV-0001Ci-IR for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:59 -0500 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 1p4iPT-0000dx-VE for qemu-devel@nongnu.org; Mon, 12 Dec 2022 07:59:57 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-346-DDs7snKdMtWUElUF8MrNHA-1; Mon, 12 Dec 2022 07:59:54 -0500 Received: by mail-wm1-f71.google.com with SMTP id h9-20020a1c2109000000b003cfd37aec58so3333841wmh.1 for ; Mon, 12 Dec 2022 04:59:54 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id e11-20020a5d500b000000b00241fde8fe04sm8850859wrt.7.2022.12.12.04.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 04:59:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670849995; 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=SNf+Amfu4RgOHfZAxglCNQQHsEjLkMDXAIJYh2GuBxA=; b=LvI4gMvN96Fvkq6gp4yiYctAo46EwWANhNSCvnx5as6/thiePXoRweKuC3M40Kjc4Dk1Mt GaC/xWG2vneohGsAh6LemPFjLkc/oLjHqwghlNc61UCPvDJGI/i7XNehper89Tlvvmi7mH ykeSBzSlxWOpX6YT3vSBwqnqV/GuBXU= X-MC-Unique: DDs7snKdMtWUElUF8MrNHA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SNf+Amfu4RgOHfZAxglCNQQHsEjLkMDXAIJYh2GuBxA=; b=ZPLqUZt9vPsq1BFU9KrhEMwvkBZC2RRwXbrq2Ug4UzjC8KEQ4YV+neIxb8ik5IxZya iM8AYdEbuI5z1YmezoyAa/H3LdzJuWp+fBr+2VSnlSMhsqXMZfZtD0+ab5k7smn5WINo DgBHz5KBsSsvlGY9bnOkYT/OO0nbLGXCUFUfMyLm9pYM5SniIqcytHB2TH8FIw4uwRB0 ZnyqRJp7xZO7+b8I4oNKnkM41eQCRkSLexn4WwBy7QtGCERVhy8Z+29qlbWwb5Bkcfb+ bUJ8YLtqKbisP0HEzauEC01/5ohrQepLAjCrtP4AIaqiHI9sa3VAy+7M1tuuEkn77sd8 jfvA== X-Gm-Message-State: ANoB5pnykcZzG8FXu8hqa23oRojhIC4xNQIPQEwHrKH7gHV4SKdkCJvn f3UN/9uKxBrEusRiwWa5V3d/AvbXsZRr1hG5/Ghz90iW0JslCr/yjTkEqMOQcpSrl/lMFQH+7Np MSczyB/vBoBvEfiez8/fTm1eGq3G6uV4HrFzuxL0fAPstPgs5Kpo0134/wF0/D6sVNmo= X-Received: by 2002:a05:600c:4e54:b0:3cf:51cf:91c with SMTP id e20-20020a05600c4e5400b003cf51cf091cmr12492237wmq.11.1670849992586; Mon, 12 Dec 2022 04:59:52 -0800 (PST) X-Google-Smtp-Source: AA0mqf6r2mohU+wm93TcPgW4TPz8HAa2okeHkZVb+hA9Zj4DosoZGy8NBDgjOnEFryeBAcrKjaU90Q== X-Received: by 2002:a05:600c:4e54:b0:3cf:51cf:91c with SMTP id e20-20020a05600c4e5400b003cf51cf091cmr12492218wmq.11.1670849992275; Mon, 12 Dec 2022 04:59:52 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com Subject: [PATCH 10/15] block-backend: always wait for drain before starting operation Date: Mon, 12 Dec 2022 13:59:15 +0100 Message-Id: <20221212125920.248567-11-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1670850073635100003 Content-Type: text/plain; charset="utf-8" All I/O operations call blk_wait_while_drained() immediately after blk_inc_in_flight(), except for blk_abort_aio_request() where it does not hurt to add such a call. Merge the two functions into one, and add a note about a disturbing lack of thread-safety that will be fixed shortly. While at it, make the quiesce_counter check a loop. While the check does not have to be "perfect", i.e. it only matters that an endless stream of I/Os is stopped sooner or later, it is more logical to check the counter repeatedly until it is zero. Signed-off-by: Paolo Bonzini --- block/block-backend.c | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index fe42d53d655d..627d491d4155 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1270,18 +1270,6 @@ static int blk_check_byte_request(BlockBackend *blk,= int64_t offset, return 0; } =20 -/* To be called between exactly one pair of blk_inc/dec_in_flight() */ -static void coroutine_fn blk_wait_while_drained(BlockBackend *blk) -{ - assert(blk->in_flight > 0); - - if (blk->quiesce_counter && !blk->disable_request_queuing) { - blk_dec_in_flight(blk); - qemu_co_queue_wait(&blk->queued_requests, NULL); - blk_inc_in_flight(blk); - } -} - /* To be called between exactly one pair of blk_inc/dec_in_flight() */ static int coroutine_fn blk_co_do_preadv_part(BlockBackend *blk, int64_t offset, int64_t bytes, @@ -1334,7 +1322,6 @@ int coroutine_fn blk_co_preadv(BlockBackend *blk, int= 64_t offset, IO_OR_GS_CODE(); =20 blk_inc_in_flight(blk); - blk_wait_while_drained(blk); ret =3D blk_co_do_preadv_part(blk, offset, bytes, qiov, 0, flags); blk_dec_in_flight(blk); =20 @@ -1349,7 +1336,6 @@ int coroutine_fn blk_co_preadv_part(BlockBackend *blk= , int64_t offset, IO_OR_GS_CODE(); =20 blk_inc_in_flight(blk); - blk_wait_while_drained(blk); ret =3D blk_co_do_preadv_part(blk, offset, bytes, qiov, qiov_offset, f= lags); blk_dec_in_flight(blk); =20 @@ -1401,7 +1387,6 @@ int coroutine_fn blk_co_pwritev_part(BlockBackend *bl= k, int64_t offset, IO_OR_GS_CODE(); =20 blk_inc_in_flight(blk); - blk_wait_while_drained(blk); ret =3D blk_co_do_pwritev_part(blk, offset, bytes, qiov, qiov_offset, = flags); blk_dec_in_flight(blk); =20 @@ -1466,6 +1451,14 @@ void blk_inc_in_flight(BlockBackend *blk) { IO_CODE(); qatomic_inc(&blk->in_flight); + if (!blk->disable_request_queuing) { + /* TODO: this is not thread-safe! */ + while (blk->quiesce_counter) { + qatomic_dec(&blk->in_flight); + qemu_co_queue_wait(&blk->queued_requests, NULL); + qatomic_inc(&blk->in_flight); + } + } } =20 void blk_dec_in_flight(BlockBackend *blk) @@ -1546,7 +1539,6 @@ static BlockAIOCB *blk_aio_prwv(BlockBackend *blk, in= t64_t offset, Coroutine *co; =20 blk_inc_in_flight(blk); - blk_wait_while_drained(blk); acb =3D blk_aio_get(&blk_aio_em_aiocb_info, blk, cb, opaque); acb->rwco =3D (BlkRwCo) { .blk =3D blk, @@ -1685,7 +1677,6 @@ int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsi= gned long int req, IO_OR_GS_CODE(); =20 blk_inc_in_flight(blk); - blk_wait_while_drained(blk); ret =3D blk_co_do_ioctl(blk, req, buf); blk_dec_in_flight(blk); =20 @@ -1749,7 +1740,6 @@ int coroutine_fn blk_co_pdiscard(BlockBackend *blk, i= nt64_t offset, IO_OR_GS_CODE(); =20 blk_inc_in_flight(blk); - blk_wait_while_drained(blk); ret =3D blk_co_do_pdiscard(blk, offset, bytes); blk_dec_in_flight(blk); =20 @@ -1790,7 +1780,6 @@ int coroutine_fn blk_co_flush(BlockBackend *blk) IO_OR_GS_CODE(); =20 blk_inc_in_flight(blk); - blk_wait_while_drained(blk); ret =3D blk_co_do_flush(blk); blk_dec_in_flight(blk); =20 --=20 2.38.1 From nobody Sat May 18 18:02:00 2024 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=1670850742; cv=none; d=zohomail.com; s=zohoarc; b=Q8TXA2pMrIyWGzTIiB+JH6eXMLQRguX6mKIhwrxggywPeUM8SNPqkuj9h3BnaQz/TYG2YCLgMDdYcUMVA+EWIDYfU27cUH/o6DVIHLBXJIVWlgFrTs2E+C7IDVRSzbm1wW9L6pSIJHIpVIX2F4eVMCv6nDf2zuTHpYqfhUvRil0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670850742; 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=htkU7SVOcGM/+ZnC/Z5yotiRrBUBCT+Uwz5tvqkgeq4=; b=fOuJxHBk7DfsMzUF/QjiM8juP5J8/rat/2vwLrEDAE8leYaE6mdoqRtNI+tvXmZq9fBDGR2vkFfTtwT3KhIm5rdpqMAhfrQ+rCHJuodA4o4+/aWzjZ7G7RwDqZl6CXVe+tItYHxePKYBQ2AEgo0m3Zn4k3cEAt7KmWA/XF08orw= 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 1670850742297470.4860111481968; Mon, 12 Dec 2022 05:12:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iQN-0001jc-BI; Mon, 12 Dec 2022 08:00:51 -0500 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 1p4iPY-0001Cz-HI for qemu-devel@nongnu.org; Mon, 12 Dec 2022 08:00:10 -0500 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 1p4iPW-0000ei-SL for qemu-devel@nongnu.org; Mon, 12 Dec 2022 08:00:00 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-617-KFmbeHVtPIC8br4POBD07A-1; Mon, 12 Dec 2022 07:59:57 -0500 Received: by mail-wm1-f72.google.com with SMTP id c126-20020a1c3584000000b003cfffcf7c1aso4156033wma.0 for ; Mon, 12 Dec 2022 04:59:56 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id l8-20020a05600c4f0800b003cf54b77bfesm9566039wmq.28.2022.12.12.04.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 04:59:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670849998; 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=htkU7SVOcGM/+ZnC/Z5yotiRrBUBCT+Uwz5tvqkgeq4=; b=KYbCwkNdATRf+rtp1sMwr94gcL2BvwWivgWSWjijEG4MpVhfulZorr1e471HzWpOFKroV5 ZVvseJcpfeOrDkeroYd7MQ6/X8lFUAzLasvZydCnmrMASpQjmprvC5zHLNumaHtElYwIVb G3KIAh7SYntMYi7UrsMCw3L8pn4L76w= X-MC-Unique: KFmbeHVtPIC8br4POBD07A-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=htkU7SVOcGM/+ZnC/Z5yotiRrBUBCT+Uwz5tvqkgeq4=; b=Tt6f3kzqNhvNEhRly3BXPXRirBeS7GwUQxNNCfsohTMoQ2EW0XJN6Ydts3N/gPe6vG mxBFeGePp0Iqss3flOLwhDX4Q79j6A+4aCvVAR8iee5MC7GZGKD9doiJisLlI4Q7yqY3 +ACt2DzQ7xVyauNrz2O3Jsi3ys1S7i5kDQp0vESI4M0cx4kz90cKTOa2sSgxWhVWtd77 1LWf65iSj1MsBqBW3yK8vWG5IWm+9EPlS7Y+lc2Srk67Vuf9acS69JnQRcIm+AefKmYW UpyQwqhdP1tKjU6fa2kBSBp5Qm3lXcfT4Euu1G+MgSlKLSn9NQJ/ymadAMxRAqOsWkiK g/aQ== X-Gm-Message-State: ANoB5pnUhNMJpNEJmWqx498X/wdWakYWMp/e4JrRWrq2rO8oGwojUnz8 oX+L9NhsXeuwUOt33rx2yHXezewCdGVR8xfExJAWzxHMi+DqMV/9YOzxd9r72reWOpwVWcdhXhD fKTcw7xGFYXUNiku3VBdlPzuakNLKzctrcch8TZUjomyDDlBPJDPvV+IXyGBWtuKskWY= X-Received: by 2002:a05:600c:310e:b0:3cf:a39f:eb2a with SMTP id g14-20020a05600c310e00b003cfa39feb2amr12545058wmo.11.1670849995307; Mon, 12 Dec 2022 04:59:55 -0800 (PST) X-Google-Smtp-Source: AA0mqf4vR4yuOZcoZutIbG7hq+wY0zkU9iiPima3l1djnTdoOahbFbAL4AFfV2AhHFSEsEJIwcF7Ug== X-Received: by 2002:a05:600c:310e:b0:3cf:a39f:eb2a with SMTP id g14-20020a05600c310e00b003cfa39feb2amr12545039wmo.11.1670849994942; Mon, 12 Dec 2022 04:59:54 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com Subject: [PATCH 11/15] block-backend: make queued_requests thread-safe Date: Mon, 12 Dec 2022 13:59:16 +0100 Message-Id: <20221212125920.248567-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 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: 1670850743685100001 Content-Type: text/plain; charset="utf-8" Protect quiesce_counter and queued_requests with a QemuMutex, so that they are protected from concurrent access in the main thread (for example blk_root_drained_end() reached from bdrv_drain_all()) and in the iothread (where any I/O operation will call blk_inc_in_flight()). Signed-off-by: Paolo Bonzini --- block/block-backend.c | 44 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 627d491d4155..fdf82f1f1599 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -23,6 +23,7 @@ #include "qapi/error.h" #include "qapi/qapi-events-block.h" #include "qemu/id.h" +#include "qemu/thread.h" #include "qemu/main-loop.h" #include "qemu/option.h" #include "trace.h" @@ -85,6 +86,8 @@ struct BlockBackend { NotifierList remove_bs_notifiers, insert_bs_notifiers; QLIST_HEAD(, BlockBackendAioNotifier) aio_notifiers; =20 + /* Protected by quiesce_lock. */ + QemuMutex quiesce_lock; int quiesce_counter; CoQueue queued_requests; =20 @@ -372,6 +375,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->quiesce_lock); qemu_co_queue_init(&blk->queued_requests); notifier_list_init(&blk->remove_bs_notifiers); notifier_list_init(&blk->insert_bs_notifiers); @@ -490,6 +494,7 @@ static void blk_delete(BlockBackend *blk) assert(QLIST_EMPTY(&blk->insert_bs_notifiers.notifiers)); assert(QLIST_EMPTY(&blk->aio_notifiers)); QTAILQ_REMOVE(&block_backends, blk, link); + qemu_mutex_destroy(&blk->quiesce_lock); drive_info_del(blk->legacy_dinfo); block_acct_cleanup(&blk->stats); g_free(blk); @@ -1451,11 +1456,25 @@ void blk_inc_in_flight(BlockBackend *blk) { IO_CODE(); qatomic_inc(&blk->in_flight); - if (!blk->disable_request_queuing) { - /* TODO: this is not thread-safe! */ + + /* + * Avoid a continuous stream of requests from AIO callbacks, which + * call a user-provided callback while blk->in_flight is elevated, + * if the BlockBackend is being quiesced. + * + * This initial test does not have to be perfect: a race might + * cause an extra I/O to be queued, but sooner or later a nonzero + * quiesce_counter will be observed. + */ + if (!blk->disable_request_queuing && qatomic_read(&blk->quiesce_counte= r)) { + /* + * ... on the other hand, it is important that the final check and + * the wait are done under the lock, so that no wakeups are missed. + */ + QEMU_LOCK_GUARD(&blk->quiesce_lock); while (blk->quiesce_counter) { qatomic_dec(&blk->in_flight); - qemu_co_queue_wait(&blk->queued_requests, NULL); + qemu_co_queue_wait(&blk->queued_requests, &blk->quiesce_lock); qatomic_inc(&blk->in_flight); } } @@ -2542,7 +2561,8 @@ 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) { + qatomic_set(&blk->quiesce_counter, blk->quiesce_counter + 1); + if (blk->quiesce_counter =3D=3D 1) { if (blk->dev_ops && blk->dev_ops->drained_begin) { blk->dev_ops->drained_begin(blk->dev_opaque); } @@ -2560,6 +2580,7 @@ static bool blk_root_drained_poll(BdrvChild *child) { BlockBackend *blk =3D child->opaque; bool busy =3D false; + assert(blk->quiesce_counter); =20 if (blk->dev_ops && blk->dev_ops->drained_poll) { @@ -2576,14 +2597,21 @@ static void blk_root_drained_end(BdrvChild *child) 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) { + qemu_mutex_lock(&blk->quiesce_lock); + qatomic_set(&blk->quiesce_counter, blk->quiesce_counter - 1); + if (blk->quiesce_counter =3D=3D 0) { + /* After this point, new I/O will not sleep on queued_requests. */ + qemu_mutex_unlock(&blk->quiesce_lock); + 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)) { - /* Resume all queued requests */ - } + + /* Now resume all queued requests */ + qemu_mutex_lock(&blk->quiesce_lock); + qemu_co_enter_all(&blk->queued_requests, &blk->quiesce_lock); } + qemu_mutex_unlock(&blk->quiesce_lock); } =20 bool blk_register_buf(BlockBackend *blk, void *host, size_t size, Error **= errp) --=20 2.38.1 From nobody Sat May 18 18:02:00 2024 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=1670850128; cv=none; d=zohomail.com; s=zohoarc; b=BpGfAP5bEaceqIy7TZ0mj3AlEv2eO6hPFdO0xnkJl/PsKAFWeVAyxCSWfK8/ua4zB663ZxNSKRJE/XaKzc2sge5s2IytwlnbAqQ6zxoPiYmTYB3MX14K9azBhQkA/gg6OA5GjYkfps58xda1JAx9uYu+4A+wwxfS4IEIJrLQ5b4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670850128; 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=RGQrLDmE0jIV0YVet0Ys7nedRpXWcsJekGch0hOBTMg=; b=HVHPrPYlWtYbWuhyO66ol7nyzX7MPDTFhiL3J2yWa0AQc3AjsdSMGnf2PjZbeOjP79ZNbEGVMVeNBfxNoVJlh7DCR5Wsp5lyStuWTBxYIXCjPfvKvnjrMIH004ctJNs8QH8v2szbq/oL3XJOk9WhPk9EOFPtQOMEA6IRKjsqF1I= 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 1670850128224816.365686673707; Mon, 12 Dec 2022 05:02:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iQO-0001lC-Ie; Mon, 12 Dec 2022 08:00:52 -0500 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 1p4iPg-0001L5-Ri for qemu-devel@nongnu.org; Mon, 12 Dec 2022 08:00:10 -0500 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 1p4iPa-0000fk-1I for qemu-devel@nongnu.org; Mon, 12 Dec 2022 08:00:04 -0500 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-620-XXzWzbX9PsyUGx3yPgObEQ-1; Mon, 12 Dec 2022 07:59:59 -0500 Received: by mail-wr1-f70.google.com with SMTP id c21-20020adfa315000000b002425bf67a87so2203921wrb.19 for ; Mon, 12 Dec 2022 04:59:59 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id bi27-20020a05600c3d9b00b003d225cdb68esm5054917wmb.0.2022.12.12.04.59.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 04:59:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670850001; 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=RGQrLDmE0jIV0YVet0Ys7nedRpXWcsJekGch0hOBTMg=; b=hfCEd3YZcnUkK6A0/WzQ4/VsmTQCIBxyIc0tY+E/Gh9mToLBSPv/lvp4aA0tE4/9MJfqhM 9VNGUK7uEHHdCBNtRoHQXudJasrhuAIaYdfHCKh+qF7G2DZLNQJTGpPm34tz7sgsjCvNP4 8lQi4eZzRlN0x3Ce6WZhxAaPFlnncrU= X-MC-Unique: XXzWzbX9PsyUGx3yPgObEQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RGQrLDmE0jIV0YVet0Ys7nedRpXWcsJekGch0hOBTMg=; b=KtcsUW9LkpyWnjc/Je225JuDsfy8y/VUVxcbeRAWBgPoU/GFVnddTsxUHPzKNI4bZa +zmYqbbl5pjcGY25QlN47LpgSEOj5gt8vLtPyJ+NkDkB0jR75eshUtGAa27WvZZXex7f ywL1s8AXwLFHrzRKQggSDlt2skUa5LG1nGBZRqN9AhzklcgdnOHAWHPQ9Le8xYV+Hdoh 441Y3YU8+B2LW3eoaQgs7wAlzCiAdSeOtz+r+QNdmA1kedr6FmpX3Vx87PBwVkH88moB i4vT9bSEM3Ch+bI8fc3JY05A3mZcug0ZX0BG91jPkbJSUQs9J+flGO5AWxtj6ZUhIpti I46Q== X-Gm-Message-State: ANoB5pnMU9sAon4nWBgW3i88PjiZwprEfwZ3Kd9dHNpWWrQT7XS4bRPM Kv+5NLmZ68OY3y51atU99CvhPknAc1jgND3TTz1m13lQJMQkWTHExGMZvjmEolcDFN3xx/NUcdt N0gcL2L6Ut0ZZMhfIXhsYy6Uwd8rW7zwLWRUeqwe2fe0FzFYnXxAm4Wm6v/AH+z7NiOk= X-Received: by 2002:a05:600c:4f89:b0:3d1:caf1:3f56 with SMTP id n9-20020a05600c4f8900b003d1caf13f56mr12088776wmq.9.1670849998072; Mon, 12 Dec 2022 04:59:58 -0800 (PST) X-Google-Smtp-Source: AA0mqf6LUDfwHpwPE1dLQS1ajGvsVKxa4DRC9ZO5o93XBe16wW6kNzV2+4Kqfb25/l6Rju3gEaDaFQ== X-Received: by 2002:a05:600c:4f89:b0:3d1:caf1:3f56 with SMTP id n9-20020a05600c4f8900b003d1caf13f56mr12088759wmq.9.1670849997785; Mon, 12 Dec 2022 04:59:57 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com Subject: [PATCH 12/15] block: limit bdrv_co_yield_to_drain to drain_begin Date: Mon, 12 Dec 2022 13:59:17 +0100 Message-Id: <20221212125920.248567-13-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1670850128764100001 Content-Type: text/plain; charset="utf-8" Since bdrv_drained_end does not poll anymore, it need not jump out of coroutine context. This in turn enables the removal of the "begin" field in BdrvCoDrainData. Signed-off-by: Paolo Bonzini --- block/io.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/block/io.c b/block/io.c index f4444b7777d9..695c8f3f5faa 100644 --- a/block/io.c +++ b/block/io.c @@ -233,7 +233,6 @@ typedef struct { Coroutine *co; BlockDriverState *bs; bool done; - bool begin; bool poll; BdrvChild *parent; } BdrvCoDrainData; @@ -275,15 +274,9 @@ static void bdrv_co_drain_bh_cb(void *opaque) AioContext *ctx =3D bdrv_get_aio_context(bs); aio_context_acquire(ctx); bdrv_dec_in_flight(bs); - if (data->begin) { - bdrv_do_drained_begin(bs, data->parent, data->poll); - } else { - assert(!data->poll); - bdrv_do_drained_end(bs, data->parent); - } + bdrv_do_drained_begin(bs, data->parent, data->poll); aio_context_release(ctx); } else { - assert(data->begin); bdrv_drain_all_begin(); } =20 @@ -292,7 +285,6 @@ static void bdrv_co_drain_bh_cb(void *opaque) } =20 static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, - bool begin, BdrvChild *parent, bool poll) { @@ -309,7 +301,6 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDr= iverState *bs, .co =3D self, .bs =3D bs, .done =3D false, - .begin =3D begin, .parent =3D parent, .poll =3D poll, }; @@ -348,7 +339,7 @@ static void bdrv_do_drained_begin(BlockDriverState *bs,= BdrvChild *parent, IO_OR_GS_CODE(); =20 if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(bs, true, parent, poll); + bdrv_co_yield_to_drain(bs, parent, poll); return; } =20 @@ -394,10 +385,6 @@ static void bdrv_do_drained_end(BlockDriverState *bs, = BdrvChild *parent) { int old_quiesce_counter; =20 - if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(bs, false, parent, false); - return; - } assert(bs->quiesce_counter > 0); =20 /* Re-enable things in child-to-parent order */ @@ -472,7 +459,7 @@ void bdrv_drain_all_begin(void) GLOBAL_STATE_CODE(); =20 if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(NULL, true, NULL, true); + bdrv_co_yield_to_drain(NULL, NULL, true); return; } =20 --=20 2.38.1 From nobody Sat May 18 18:02:00 2024 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=1670850356; cv=none; d=zohomail.com; s=zohoarc; b=Z2kxbwmn0tG5xPB4VK9XenyU4MO6l44XSCXZHzUg18tmloSyKpkw1hGSnX1yjzqCnvnAIEpLEy3KEJTHqxm2vy6GzjU4WC13Lf5bDBphtWUDoqXvJWV4tfdXEzF6ITclZsolWaZA2CMJ7SShcl+Iq+NVPnpf1wtF/lUmuvpiL+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670850356; 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=xGdm71Q4TtbUpgrQrxbMQTKlqvkd/QknlShWaWKaKHQ=; b=g5+0dtrmvXxrGCd5fEqWNYtKXiCtlFMxW2KyyqRD6J3ENIOXEIEHap82IbC5jwIOQZrOmmfcUlJkh/O9+ZJw/yUpzqUh4MrUkJOvjPoJbQbZnMsgxbfFKugkfgs9a8QgYKvHzZb5ciSd2S9QLJ9cO8ciZN9LPgzvkplTEeO3cy8= 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 1670850356389368.41814101200134; Mon, 12 Dec 2022 05:05:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iQQ-0001np-HV; Mon, 12 Dec 2022 08:00:54 -0500 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 1p4iPi-0001MT-VP for qemu-devel@nongnu.org; Mon, 12 Dec 2022 08:00:12 -0500 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 1p4iPe-0000ic-03 for qemu-devel@nongnu.org; Mon, 12 Dec 2022 08:00:10 -0500 Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-302-acBC1HDePUSHVyl73bW5Qw-1; Mon, 12 Dec 2022 08:00:03 -0500 Received: by mail-wm1-f71.google.com with SMTP id v188-20020a1cacc5000000b003cf76c4ae66so4132629wme.7 for ; Mon, 12 Dec 2022 05:00:02 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id l2-20020a056000022200b002420dba6447sm8777865wrz.59.2022.12.12.05.00.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 05:00:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670850004; 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=xGdm71Q4TtbUpgrQrxbMQTKlqvkd/QknlShWaWKaKHQ=; b=Kov00nUT3PoRibqxfLJ/fhrf6/qEvzNJSzALbQTVXYKEajqgDQ/WZ1uPEsXEYhI4Gj+wFR YbX5bc6poLv0Dx9H2rT7aKp4NM55Rr+Uq9wdjiAK0/6TgrJyl5XeQDzeTbjeeo3gz+7XuP qsZX7psT+AfLrQ1WOfBzNPnmgTLm3ZQ= X-MC-Unique: acBC1HDePUSHVyl73bW5Qw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xGdm71Q4TtbUpgrQrxbMQTKlqvkd/QknlShWaWKaKHQ=; b=ZWCQkWD3l09ngsn39CUDpHt99WQiyYXBX/QB6fq3H547R8v4GKmlbY9NBUIKFwaahq JlCQ6Rihk+xo+2eABYLTC9h5YAK0voLaxPJBJ7Hjut+LjgdJVLB0r9YocY5U4WREnlSY XXxqVjHpxzniQl7oGe2PK3mzq7+gS4sXhAFnybbuNMQ4LQQ4Sxft0CWnN6gAfr6XqbXg 2F9DuSdkKVL8SD9JHIyrtFm3ufzWDdrs7fXyGoaGpbSiYt/ayMlfrf/8SvIrXqwQ3D6i f4juRAQPtrxGWcCPoM4BAEJlZBoE01RAt/f0SYTtDHlAhifvHUoAjzQO6vwXs7LzRh5c 6tkg== X-Gm-Message-State: ANoB5pndBfnRjmIC6RxpczPCT8dNVsqVZVYAmY3+v8rppZDuJw3Uj0GH vutn9XKr3zsOEak8s/3Y6r2Zx26knHbsnVTCnyliS+hwvKoY+JwgfLrjHjURYHHfPBjzKYap456 SAho7UkUiQ3g02lVFvgdDW+XDUmfwij741ZG8LFwbSise7TG36CVKoG962eiWKFpuwxg= X-Received: by 2002:a5d:6806:0:b0:242:7a19:b535 with SMTP id w6-20020a5d6806000000b002427a19b535mr10979309wru.64.1670850001518; Mon, 12 Dec 2022 05:00:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf7X8HZ4VAvf53tX1tToMiImFB90Qr7+1ODLGvPlf1B+0pfcmCNtsVZLHysymFZWIp20qDfkyw== X-Received: by 2002:a5d:6806:0:b0:242:7a19:b535 with SMTP id w6-20020a5d6806000000b002427a19b535mr10979291wru.64.1670850001217; Mon, 12 Dec 2022 05:00:01 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com Subject: [PATCH 13/15] block: second argument of bdrv_do_drained_end is always NULL Date: Mon, 12 Dec 2022 13:59:18 +0100 Message-Id: <20221212125920.248567-14-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1670850358250100006 Content-Type: text/plain; charset="utf-8" Remove it and unify the function with bdrv_drained_end. Signed-off-by: Paolo Bonzini --- block/io.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/block/io.c b/block/io.c index 695c8f3f5faa..c2962adf8d2d 100644 --- a/block/io.c +++ b/block/io.c @@ -69,14 +69,11 @@ void bdrv_parent_drained_end_single(BdrvChild *c) } } =20 -static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignor= e) +static void bdrv_parent_drained_end(BlockDriverState *bs) { BdrvChild *c; =20 QLIST_FOREACH(c, &bs->parents, next_parent) { - if (c =3D=3D ignore) { - continue; - } bdrv_parent_drained_end_single(c); } } @@ -262,7 +259,6 @@ static bool bdrv_drain_poll_top_level(BlockDriverState = *bs, =20 static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent, bool poll); -static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent); =20 static void bdrv_co_drain_bh_cb(void *opaque) { @@ -381,10 +377,11 @@ void bdrv_drained_begin(BlockDriverState *bs) * This function does not poll, nor must any of its recursively called * functions. */ -static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent) +void bdrv_drained_end(BlockDriverState *bs) { int old_quiesce_counter; =20 + IO_OR_GS_CODE(); assert(bs->quiesce_counter > 0); =20 /* Re-enable things in child-to-parent order */ @@ -393,17 +390,11 @@ static void bdrv_do_drained_end(BlockDriverState *bs,= BdrvChild *parent) if (bs->drv && bs->drv->bdrv_drain_end) { bs->drv->bdrv_drain_end(bs); } - bdrv_parent_drained_end(bs, parent); + bdrv_parent_drained_end(bs); aio_enable_external(bdrv_get_aio_context(bs)); } } =20 -void bdrv_drained_end(BlockDriverState *bs) -{ - IO_OR_GS_CODE(); - bdrv_do_drained_end(bs, NULL); -} - void bdrv_drain(BlockDriverState *bs) { IO_OR_GS_CODE(); @@ -504,7 +495,7 @@ void bdrv_drain_all_end_quiesce(BlockDriverState *bs) g_assert(!bs->refcnt); =20 while (bs->quiesce_counter) { - bdrv_do_drained_end(bs, NULL); + bdrv_drained_end(bs); } } =20 @@ -526,7 +517,7 @@ void bdrv_drain_all_end(void) AioContext *aio_context =3D bdrv_get_aio_context(bs); =20 aio_context_acquire(aio_context); - bdrv_do_drained_end(bs, NULL); + bdrv_drained_end(bs); aio_context_release(aio_context); } =20 --=20 2.38.1 From nobody Sat May 18 18:02:00 2024 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=1670850541; cv=none; d=zohomail.com; s=zohoarc; b=f1/GBpMrM4BJTUctKxShpwa43hxbGOAZi8xFWi7vIgGTl8YJBBjSstG7K8jz0KqNVwzpPlq2VLqcO8lGhC+8eVxo/m60CXqYjlGX4Pex4ppGnrHBZmHEdrVJtDtJ1ygXwNw4tupUyHPNVb0lx7+3elMs1cUuJycgIce3d2AwEt4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670850541; 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=QcIXilAWoE8KTc2TcLHja/aK6r+Hwo53E5xRR0bpKH0=; b=CGfYjaNV0N8RYX1ppNeJQ7R3tpm/HfXuVkC2jaZyfCUCr7plHbYHMpL1hBQhPfQrdb56w6FkgbyHduwHes/mecMjWKpTKccJ+ygR9QWaN0kd40EkAGShKYjj7NDovwgZfjYbu1HolaLo/AlUMY5HQ/6angcYm5+FtxoZBhD+nE4= 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 1670850541609876.0496560704897; Mon, 12 Dec 2022 05:09:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iQQ-0001nd-8O; Mon, 12 Dec 2022 08:00:54 -0500 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 1p4iPk-0001Mf-MQ for qemu-devel@nongnu.org; Mon, 12 Dec 2022 08:00:14 -0500 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 1p4iPh-0000sB-HR for qemu-devel@nongnu.org; Mon, 12 Dec 2022 08:00:12 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-158-E8lZCdFYPgmx8Q1YFJbYgw-1; Mon, 12 Dec 2022 08:00:06 -0500 Received: by mail-wm1-f70.google.com with SMTP id a6-20020a05600c224600b003d1f3ed49adso1970922wmm.4 for ; Mon, 12 Dec 2022 05:00:06 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id b17-20020adfde11000000b00236545edc91sm8758968wrm.76.2022.12.12.05.00.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 05:00:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670850008; 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=QcIXilAWoE8KTc2TcLHja/aK6r+Hwo53E5xRR0bpKH0=; b=B7iQdJ7mJ30zl03WMLc7dznB+ix013/7k7DmZUBuVIW2sH279ZHlK+YsCQrlfHR3zsWMoK RQNib7cVto/6ZbAPC5VGfG0VxfywS6z91mVtDOSRQ0DOyIOE5ty0quW85mADVDqLyXfOqY b5TeKvQbf1KZnXHp58cg1yq5/SrpOYw= X-MC-Unique: E8lZCdFYPgmx8Q1YFJbYgw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QcIXilAWoE8KTc2TcLHja/aK6r+Hwo53E5xRR0bpKH0=; b=dnrSxRDCOQfdFI3Hse3RnkuV8Kf0S7qDyI5KaAH9i37hjqfhhiboe9Bnbk3vDNkt4W fQbkQSKqohmSskTM5OkHC5a6U5iX/3v3c4fx0lrvIG9Kx0F3gpIvCOE7eVHr6RBiyrQn NbGxbPvhEwGHxx7K+ZaTt3G2M4sVmUmblR3uwNAzQggGTsFK6SSt9ghxfrJNdpF+iLdf dteG9A9ZaJjKmWsjEDgrGk+1N/PpUDUDHMSnXL2Ljwyw9xshiv08FYXlXINzJO28HhNw BwQMBjZFy76rcRGGT/xlU7Y30/1n276TU14zPl+0MMZ4qHb9tsL8U/VymhxjLUFHqgFM Q2+A== X-Gm-Message-State: ANoB5pm0kxarDT4Y4dW1EC6Td4PpwBdzEkFor6A6gvGxoe1XjHiNh+BT abv49cwj/k15nhC+OdV6zCBw8Vey0+95pYpLAU9gm1wtEtWBjQl+DAatSUzvjZ4yBIKHZSDoIJu fK3VQx6EjOyFEoOMYJTRJpZv6Py0To9UQJPAsEjM1ncN1mfpSR4TzoYDYI8QhluPMEuE= X-Received: by 2002:adf:ebc3:0:b0:237:45f1:7f12 with SMTP id v3-20020adfebc3000000b0023745f17f12mr13051761wrn.39.1670850004580; Mon, 12 Dec 2022 05:00:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf4eCNi+tmDuMw0FfO/riKnUae2Yif7HBL+CNw1JfW2q026hX1nPQF98WsAY9jFWZqs1u03p1Q== X-Received: by 2002:adf:ebc3:0:b0:237:45f1:7f12 with SMTP id v3-20020adfebc3000000b0023745f17f12mr13051720wrn.39.1670850003976; Mon, 12 Dec 2022 05:00:03 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com Subject: [PATCH 14/15] block: second argument of bdrv_do_drained_begin and bdrv_drain_poll is always NULL Date: Mon, 12 Dec 2022 13:59:19 +0100 Message-Id: <20221212125920.248567-15-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1670850544453100001 Content-Type: text/plain; charset="utf-8" Remove it from the functions, from callers/callees such as bdrv_do_drained_begin_quiesce() and bdrv_drain_poll(), and from bdrv_co_yield_to_drain() and BdrvCoDrainData. Signed-off-by: Paolo Bonzini --- block.c | 4 ++-- block/io.c | 49 ++++++++++++++++------------------------ include/block/block-io.h | 7 +++--- 3 files changed, 24 insertions(+), 36 deletions(-) diff --git a/block.c b/block.c index c542a0a33358..676bbe0529b0 100644 --- a/block.c +++ b/block.c @@ -1186,13 +1186,13 @@ static char *bdrv_child_get_parent_desc(BdrvChild *= c) static void bdrv_child_cb_drained_begin(BdrvChild *child) { BlockDriverState *bs =3D child->opaque; - bdrv_do_drained_begin_quiesce(bs, NULL); + bdrv_do_drained_begin_quiesce(bs); } =20 static bool bdrv_child_cb_drained_poll(BdrvChild *child) { BlockDriverState *bs =3D child->opaque; - return bdrv_drain_poll(bs, NULL, false); + return bdrv_drain_poll(bs, false); } =20 static void bdrv_child_cb_drained_end(BdrvChild *child) diff --git a/block/io.c b/block/io.c index c2962adf8d2d..a75f42ee13cb 100644 --- a/block/io.c +++ b/block/io.c @@ -45,14 +45,11 @@ static void bdrv_parent_cb_resize(BlockDriverState *bs); static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, BdrvRequestFlags flags); =20 -static void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ign= ore) +static void bdrv_parent_drained_begin(BlockDriverState *bs) { BdrvChild *c, *next; =20 QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { - if (c =3D=3D ignore) { - continue; - } bdrv_parent_drained_begin_single(c); } } @@ -86,14 +83,13 @@ bool bdrv_parent_drained_poll_single(BdrvChild *c) return false; } =20 -static bool bdrv_parent_drained_poll(BlockDriverState *bs, BdrvChild *igno= re, - bool ignore_bds_parents) +static bool bdrv_parent_drained_poll(BlockDriverState *bs, bool ignore_bds= _parents) { BdrvChild *c, *next; bool busy =3D false; =20 QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { - if (c =3D=3D ignore || (ignore_bds_parents && c->klass->parent_is_= bds)) { + if (ignore_bds_parents && c->klass->parent_is_bds) { continue; } busy |=3D bdrv_parent_drained_poll_single(c); @@ -231,16 +227,14 @@ typedef struct { BlockDriverState *bs; bool done; bool poll; - BdrvChild *parent; } BdrvCoDrainData; =20 /* Returns true if BDRV_POLL_WHILE() should go into a blocking aio_poll() = */ -bool bdrv_drain_poll(BlockDriverState *bs, BdrvChild *ignore_parent, - bool ignore_bds_parents) +bool bdrv_drain_poll(BlockDriverState *bs, bool ignore_bds_parents) { IO_OR_GS_CODE(); =20 - if (bdrv_parent_drained_poll(bs, ignore_parent, ignore_bds_parents)) { + if (bdrv_parent_drained_poll(bs, ignore_bds_parents)) { return true; } =20 @@ -251,14 +245,12 @@ bool bdrv_drain_poll(BlockDriverState *bs, BdrvChild = *ignore_parent, return false; } =20 -static bool bdrv_drain_poll_top_level(BlockDriverState *bs, - BdrvChild *ignore_parent) +static bool bdrv_drain_poll_top_level(BlockDriverState *bs) { - return bdrv_drain_poll(bs, ignore_parent, false); + return bdrv_drain_poll(bs, false); } =20 -static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent, - bool poll); +static void bdrv_do_drained_begin(BlockDriverState *bs, bool poll); =20 static void bdrv_co_drain_bh_cb(void *opaque) { @@ -270,7 +262,7 @@ static void bdrv_co_drain_bh_cb(void *opaque) AioContext *ctx =3D bdrv_get_aio_context(bs); aio_context_acquire(ctx); bdrv_dec_in_flight(bs); - bdrv_do_drained_begin(bs, data->parent, data->poll); + bdrv_do_drained_begin(bs, data->poll); aio_context_release(ctx); } else { bdrv_drain_all_begin(); @@ -281,7 +273,6 @@ static void bdrv_co_drain_bh_cb(void *opaque) } =20 static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, - BdrvChild *parent, bool poll) { BdrvCoDrainData data; @@ -297,7 +288,6 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDr= iverState *bs, .co =3D self, .bs =3D bs, .done =3D false, - .parent =3D parent, .poll =3D poll, }; =20 @@ -329,20 +319,19 @@ static void coroutine_fn bdrv_co_yield_to_drain(Block= DriverState *bs, } } =20 -static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent, - bool poll) +static void bdrv_do_drained_begin(BlockDriverState *bs, bool poll) { IO_OR_GS_CODE(); =20 if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(bs, parent, poll); + bdrv_co_yield_to_drain(bs, poll); return; } =20 /* Stop things in parent-to-child order */ if (qatomic_fetch_inc(&bs->quiesce_counter) =3D=3D 0) { aio_disable_external(bdrv_get_aio_context(bs)); - bdrv_parent_drained_begin(bs, parent); + bdrv_parent_drained_begin(bs); if (bs->drv && bs->drv->bdrv_drain_begin) { bs->drv->bdrv_drain_begin(bs); } @@ -358,19 +347,19 @@ static void bdrv_do_drained_begin(BlockDriverState *b= s, BdrvChild *parent, * nodes. */ if (poll) { - BDRV_POLL_WHILE(bs, bdrv_drain_poll_top_level(bs, parent)); + BDRV_POLL_WHILE(bs, bdrv_drain_poll_top_level(bs)); } } =20 -void bdrv_do_drained_begin_quiesce(BlockDriverState *bs, BdrvChild *parent) +void bdrv_do_drained_begin_quiesce(BlockDriverState *bs) { - bdrv_do_drained_begin(bs, parent, false); + bdrv_do_drained_begin(bs, false); } =20 void bdrv_drained_begin(BlockDriverState *bs) { IO_OR_GS_CODE(); - bdrv_do_drained_begin(bs, NULL, true); + bdrv_do_drained_begin(bs, true); } =20 /** @@ -425,7 +414,7 @@ static bool bdrv_drain_all_poll(void) while ((bs =3D bdrv_next_all_states(bs))) { AioContext *aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(aio_context); - result |=3D bdrv_drain_poll(bs, NULL, true); + result |=3D bdrv_drain_poll(bs, true); aio_context_release(aio_context); } =20 @@ -450,7 +439,7 @@ void bdrv_drain_all_begin(void) GLOBAL_STATE_CODE(); =20 if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(NULL, NULL, true); + bdrv_co_yield_to_drain(NULL, true); return; } =20 @@ -475,7 +464,7 @@ void bdrv_drain_all_begin(void) AioContext *aio_context =3D bdrv_get_aio_context(bs); =20 aio_context_acquire(aio_context); - bdrv_do_drained_begin(bs, NULL, false); + bdrv_do_drained_begin(bs, false); aio_context_release(aio_context); } =20 diff --git a/include/block/block-io.h b/include/block/block-io.h index 10659a3f246c..2f596a56fe0f 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -308,7 +308,7 @@ bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector = *qiov, int64_t pos); /** * bdrv_drain_poll: * - * Poll for pending requests in @bs and its parents (except for @ignore_pa= rent). + * Poll for pending requests in @bs and its parents. * * If @ignore_bds_parents is true, parents that are BlockDriverStates must * ignore the drain request because they will be drained separately (used = for @@ -316,8 +316,7 @@ bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector = *qiov, int64_t pos); * * This is part of bdrv_drained_begin. */ -bool bdrv_drain_poll(BlockDriverState *bs, BdrvChild *ignore_parent, - bool ignore_bds_parents); +bool bdrv_drain_poll(BlockDriverState *bs, bool ignore_bds_parents); =20 /** * bdrv_drained_begin: @@ -335,7 +334,7 @@ void bdrv_drained_begin(BlockDriverState *bs); * Quiesces a BDS like bdrv_drained_begin(), but does not wait for already * running requests to complete. */ -void bdrv_do_drained_begin_quiesce(BlockDriverState *bs, BdrvChild *parent= ); +void bdrv_do_drained_begin_quiesce(BlockDriverState *bs); =20 /** * bdrv_drained_end: --=20 2.38.1 From nobody Sat May 18 18:02:00 2024 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=1670850479; cv=none; d=zohomail.com; s=zohoarc; b=WQsz1WWUIfTDP6F+paqI2gqzGohzfW14azaRpoaBngGhQ3rILhtdEQ0iHLYDSBehqPW0BmtpwF5HefP+qdcCK2XxJVeOL9BxGq71SDRkIqg5jmujU8f3YaDL598K5zwgpM8YeF7u5hjgiLLFndxC27eoSbVhWix4vq53R/fUAxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1670850479; 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=Gd/g5oZBc2il3aJRL+xDn5boPt0eOLClpJBG9Q7t/O0=; b=GgnxOgS8OMbbPwptp2m0Ic+4YfIXfr2CrQA97MwxBgRWMPZxca4B+py9OvCxh+dTumW0S5QQ4+WTel2nB5OBH8oBEcd4C667g0LY5ngfpWCOcxW5T3pU0YDxICtuV75qh0E9gRRrxeNZwBX8I7zdQPVhstBZLLo5HM9iHhZhcIs= 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 1670850479918263.2410691292291; Mon, 12 Dec 2022 05:07:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p4iQM-0001iJ-No; Mon, 12 Dec 2022 08:00:50 -0500 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 1p4iPm-0001NS-CY for qemu-devel@nongnu.org; Mon, 12 Dec 2022 08:00:16 -0500 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 1p4iPk-0000sy-3y for qemu-devel@nongnu.org; Mon, 12 Dec 2022 08:00:13 -0500 Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-126-nFGcYlG0P2C6539lyW5FEg-1; Mon, 12 Dec 2022 08:00:10 -0500 Received: by mail-wm1-f72.google.com with SMTP id c187-20020a1c35c4000000b003cfee3c91cdso3324495wma.6 for ; Mon, 12 Dec 2022 05:00:10 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:9af8:e5f5:7516:fa89]) by smtp.gmail.com with ESMTPSA id l4-20020a5d5604000000b00241ce5d605dsm8837072wrv.110.2022.12.12.05.00.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Dec 2022 05:00:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670850011; 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=Gd/g5oZBc2il3aJRL+xDn5boPt0eOLClpJBG9Q7t/O0=; b=GognHn6eeUwd1lt24P8ngE6FdOrMBk3qU/IKFWaWQ7HgApghkpP7KfXRqSHt2qvBoBZSg3 t1i/W8yaAiIdwwN96NJzWrmDg+ASMg+rD6LPYowBqsAvm4UwER7XpZv3hqpQgrZTCHBz2G YbztR7GPpq/v0IZgIXs4syiuwUat898= X-MC-Unique: nFGcYlG0P2C6539lyW5FEg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gd/g5oZBc2il3aJRL+xDn5boPt0eOLClpJBG9Q7t/O0=; b=aWbcyk5iYXrsszsCpWOdKjscnSlrm1s90FtY5ZwRkX3G3JGrKBxEpn7GIJK5nISVQn v4pRzUPRYgLoLB43++iuI9GXnExBo0pywzWqbWT1K1dmQSNfYiNaCmpDbGrGRUmtqvdV 9DxgEqlXG/93PGfrDBVBHNVlw2vRTvL4v6WKfiVDndiQH+Jxau+pwQOhVZP+UCZqREgC S6x/IZraYX0d6uS/4qTvQLO8uLT3uWCPb8nnmalQl9h6e1IJytLpmU++6W34Re51nGNp SGwhVPz6CrZrXiBGOumrnGNCf3wbLuN8u5z/mOP0cTi5krQ5NDfO7R2lgHczK+k8F8Fv B1DQ== X-Gm-Message-State: ANoB5pmZe0HAy8w9Yh37beiK0fUld39/ClmFn9R7z28mXPkqBS3HNUzT xHOYzeP0nNsgqSybMVJAGgAiOlHAVMVVwE2hasGLyZY70Vsxn7I1TuUoS58eCM1Ed9+yR1nCpf5 n+DmKABI7HdaS/WxCbUHMucmTslIP7uAzcdYwm4AGkadVmfscLh8yi7iv3z52z520EpU= X-Received: by 2002:adf:db01:0:b0:241:c600:39a2 with SMTP id s1-20020adfdb01000000b00241c60039a2mr9274210wri.22.1670850008535; Mon, 12 Dec 2022 05:00:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf7SiG9LHrN5b+W/CeYIQZafBUXBoCS8xXfGOxMhVOCmhkhs87cnElEUqRxMFlKZYU6HNf5hVg== X-Received: by 2002:adf:db01:0:b0:241:c600:39a2 with SMTP id s1-20020adfdb01000000b00241c60039a2mr9274188wri.22.1670850008147; Mon, 12 Dec 2022 05:00:08 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, eesposit@redhat.com, kwolf@redhat.com Subject: [PATCH 15/15] block: only get out of coroutine context for polling Date: Mon, 12 Dec 2022 13:59:20 +0100 Message-Id: <20221212125920.248567-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221212125920.248567-1-pbonzini@redhat.com> References: <20221212125920.248567-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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 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: 1670850492719100001 Content-Type: text/plain; charset="utf-8" The drained_begin callbacks are not polling, all they do is schedule any operations that must complete before bdrv_drained_end(). As such, they can be called before bdrv_co_yield_to_drain(). Thus, the only remaining task left for bdrv_co_drain_bh_cb() is the BDRV_POLL_WHILE() loop. This patch extracts it into two new functions bdrv_drain_wait() and bdrv_drain_all_wait(), so that it is easily accessible from bdrv_co_drain_bh_cb(). Signed-off-by: Paolo Bonzini --- block/io.c | 77 +++++++++++++++++++++++++++--------------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/block/io.c b/block/io.c index a75f42ee13cb..fc4bc38ee9d5 100644 --- a/block/io.c +++ b/block/io.c @@ -245,13 +245,8 @@ bool bdrv_drain_poll(BlockDriverState *bs, bool ignore= _bds_parents) return false; } =20 -static bool bdrv_drain_poll_top_level(BlockDriverState *bs) -{ - return bdrv_drain_poll(bs, false); -} - -static void bdrv_do_drained_begin(BlockDriverState *bs, bool poll); - +static void bdrv_drain_wait(BlockDriverState *bs); +static void bdrv_drain_all_wait(void); static void bdrv_co_drain_bh_cb(void *opaque) { BdrvCoDrainData *data =3D opaque; @@ -262,18 +257,17 @@ static void bdrv_co_drain_bh_cb(void *opaque) AioContext *ctx =3D bdrv_get_aio_context(bs); aio_context_acquire(ctx); bdrv_dec_in_flight(bs); - bdrv_do_drained_begin(bs, data->poll); + bdrv_drain_wait(bs); aio_context_release(ctx); } else { - bdrv_drain_all_begin(); + bdrv_drain_all_wait(); } =20 data->done =3D true; aio_co_wake(co); } =20 -static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, - bool poll) +static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs) { BdrvCoDrainData data; Coroutine *self =3D qemu_coroutine_self(); @@ -288,7 +282,6 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDr= iverState *bs, .co =3D self, .bs =3D bs, .done =3D false, - .poll =3D poll, }; =20 if (bs) { @@ -319,15 +312,10 @@ static void coroutine_fn bdrv_co_yield_to_drain(Block= DriverState *bs, } } =20 -static void bdrv_do_drained_begin(BlockDriverState *bs, bool poll) +void bdrv_do_drained_begin_quiesce(BlockDriverState *bs) { IO_OR_GS_CODE(); =20 - if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(bs, poll); - return; - } - /* Stop things in parent-to-child order */ if (qatomic_fetch_inc(&bs->quiesce_counter) =3D=3D 0) { aio_disable_external(bdrv_get_aio_context(bs)); @@ -336,6 +324,23 @@ static void bdrv_do_drained_begin(BlockDriverState *bs= , bool poll) bs->drv->bdrv_drain_begin(bs); } } +} + +void bdrv_drained_begin(BlockDriverState *bs) +{ + IO_OR_GS_CODE(); + bdrv_do_drained_begin_quiesce(bs); + bdrv_drain_wait(bs); +} + +static void bdrv_drain_wait(BlockDriverState *bs) +{ + IO_OR_GS_CODE(); + + if (qemu_in_coroutine()) { + bdrv_co_yield_to_drain(bs); + return; + } =20 /* * Wait for drained requests to finish. @@ -346,20 +351,7 @@ static void bdrv_do_drained_begin(BlockDriverState *bs= , bool poll) * includes other nodes in the same AioContext and therefore all child * nodes. */ - if (poll) { - BDRV_POLL_WHILE(bs, bdrv_drain_poll_top_level(bs)); - } -} - -void bdrv_do_drained_begin_quiesce(BlockDriverState *bs) -{ - bdrv_do_drained_begin(bs, false); -} - -void bdrv_drained_begin(BlockDriverState *bs) -{ - IO_OR_GS_CODE(); - bdrv_do_drained_begin(bs, true); + BDRV_POLL_WHILE(bs, bdrv_drain_poll(bs, false)); } =20 /** @@ -438,11 +430,6 @@ void bdrv_drain_all_begin(void) BlockDriverState *bs =3D NULL; GLOBAL_STATE_CODE(); =20 - if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(NULL, true); - return; - } - /* * bdrv queue is managed by record/replay, * waiting for finishing the I/O requests may @@ -464,18 +451,30 @@ void bdrv_drain_all_begin(void) AioContext *aio_context =3D bdrv_get_aio_context(bs); =20 aio_context_acquire(aio_context); - bdrv_do_drained_begin(bs, false); + bdrv_do_drained_begin_quiesce(bs); aio_context_release(aio_context); } =20 /* Now poll the in-flight requests */ - AIO_WAIT_WHILE(NULL, bdrv_drain_all_poll()); + bdrv_drain_all_wait(); =20 while ((bs =3D bdrv_next_all_states(bs))) { bdrv_drain_assert_idle(bs); } } =20 +static void bdrv_drain_all_wait(void) +{ + GLOBAL_STATE_CODE(); + + if (qemu_in_coroutine()) { + bdrv_co_yield_to_drain(NULL); + return; + } + + AIO_WAIT_WHILE(NULL, bdrv_drain_all_poll()); +} + void bdrv_drain_all_end_quiesce(BlockDriverState *bs) { GLOBAL_STATE_CODE(); --=20 2.38.1