From nobody Tue May 7 21:17:12 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=1667911145; cv=none; d=zohomail.com; s=zohoarc; b=XKlswu3d2tzS4HuKd+u8rJANP+6ukxXkQUAdz4G/SJ9/JDvMyABoa7obFwaVtWXKO9JPHg6TXZitpxMSwZB5jDFovcrexqnsW5kjt83q7yqqfW0VnskSZaq4BLtnMbWZLXD+dQJMIr7Y/aWEPGjVmP0kuoDAPkfGC6Nm78zxxDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667911145; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=M41wqeY7k1iT6AvPvsFo70lZxD5TyMTs2NziNtkBCrU=; b=hhahmfjco1cZ7XsAlZ/anaoTnrb0S9P18rELqPVFFWs+0aKJEVGzbcENQe2qeaLp3VuDYpItrIRzTEM498jBHr+iqjAryz+6xr37/EF4EggeVgfI+FIS+ZQwD8H7fg7sjw5tZBdNu3D6kIu3B0FqMKOFVaIarpFYIIYXt/85GrE= 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 1667911145569601.3597288198592; Tue, 8 Nov 2022 04:39:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osNrh-0007hv-Kk; Tue, 08 Nov 2022 07:38:05 -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 1osNrb-0007fs-PF for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:00 -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 1osNrZ-0000PN-ML for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:37:59 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-142-q7av53KVPWOjUw_i7bDMxg-1; Tue, 08 Nov 2022 07:37:54 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 434AC3C0CD48; Tue, 8 Nov 2022 12:37:54 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28EA29E70; Tue, 8 Nov 2022 12:37:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667911076; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M41wqeY7k1iT6AvPvsFo70lZxD5TyMTs2NziNtkBCrU=; b=gFNtb/7ylC8k5qYSJwQlx/sY0Rl43ydSxMLShpg0Ot/o61ISvrUI1MECgE7F3qSoPULFZ7 AVPvbbfEje/OwzBLvtTqidPT4Vx/s+UuAT1K7Z/RVearovzEh2314LMCNGzDmTyWJg9mZx 73xbkEIj+9P2GZHxIS5QmXHvtPuyUfc= X-MC-Unique: q7av53KVPWOjUw_i7bDMxg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eesposit@redhat.com, stefanha@redhat.com, hreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 01/13] qed: Don't yield in bdrv_qed_co_drain_begin() Date: Tue, 8 Nov 2022 13:37:26 +0100 Message-Id: <20221108123738.530873-2-kwolf@redhat.com> In-Reply-To: <20221108123738.530873-1-kwolf@redhat.com> References: <20221108123738.530873-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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: 1667911147940100015 Content-Type: text/plain; charset="utf-8" We want to change .bdrv_co_drained_begin() back to be a non-coroutine callback, so in preparation, avoid yielding in its implementation. Because we increase bs->in_flight and bdrv_drained_begin() polls, the behaviour is unchanged. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito Reviewed-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/qed.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/block/qed.c b/block/qed.c index 2f36ad342c..013f826c44 100644 --- a/block/qed.c +++ b/block/qed.c @@ -282,9 +282,8 @@ static void coroutine_fn qed_unplug_allocating_write_re= qs(BDRVQEDState *s) qemu_co_mutex_unlock(&s->table_lock); } =20 -static void coroutine_fn qed_need_check_timer_entry(void *opaque) +static void coroutine_fn qed_need_check_timer(BDRVQEDState *s) { - BDRVQEDState *s =3D opaque; int ret; =20 trace_qed_need_check_timer_cb(s); @@ -310,9 +309,20 @@ static void coroutine_fn qed_need_check_timer_entry(vo= id *opaque) (void) ret; } =20 +static void coroutine_fn qed_need_check_timer_entry(void *opaque) +{ + BDRVQEDState *s =3D opaque; + + qed_need_check_timer(opaque); + bdrv_dec_in_flight(s->bs); +} + static void qed_need_check_timer_cb(void *opaque) { + BDRVQEDState *s =3D opaque; Coroutine *co =3D qemu_coroutine_create(qed_need_check_timer_entry, op= aque); + + bdrv_inc_in_flight(s->bs); qemu_coroutine_enter(co); } =20 @@ -363,8 +373,12 @@ static void coroutine_fn bdrv_qed_co_drain_begin(Block= DriverState *bs) * header is flushed. */ if (s->need_check_timer && timer_pending(s->need_check_timer)) { + Coroutine *co; + qed_cancel_need_check_timer(s); - qed_need_check_timer_entry(s); + co =3D qemu_coroutine_create(qed_need_check_timer_entry, s); + bdrv_inc_in_flight(bs); + aio_co_enter(bdrv_get_aio_context(bs), co); } } =20 --=20 2.38.1 From nobody Tue May 7 21:17:12 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=1667911145; cv=none; d=zohomail.com; s=zohoarc; b=A6zl2QsJVFQlkEBdmTFzXQCUwwu/n1hgjOPT5H9fxFPTH/Ab4pToK2SXGpmefO9EUFnDZx0PGL3sXwp/CZXIu/+FmdGAqjuJrMdHAVc7UToMgBmpeENA1U6t+vbr5ndkvT2J5xKvLgTRDsRYHM0TCvO77Wlb8Se4U/aS3B29+Qc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667911145; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=iKXtTnIMUFfHr88uUjrabFNYuleTXMetkDHhk5sQefc=; b=OMC7rCOrmW0d7UMA5zJDlIUSbbpVCpDOSIfmhFy9meOrnVZTTaD+X3sZmJUgXI6Hz4EXzWaMrbBlVRky1J+xZIArmN0Dmk0nE4xufU3w8x4IXAzF9RNzY8sW/ZomY4ymD/R8FZlYz/YMpIFIXo+ToT4HkaqH+6AgP0qJVhQVmOg= 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 1667911145531425.22825030052866; Tue, 8 Nov 2022 04:39:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osNrl-0007kp-Ur; Tue, 08 Nov 2022 07:38:10 -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 1osNre-0007gs-Vu for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:03 -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 1osNrb-0000SY-Gu for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:01 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-204-WcY4mJAANQOUqTC0MmcyvQ-1; Tue, 08 Nov 2022 07:37:55 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 986CB3C0CD48; Tue, 8 Nov 2022 12:37:55 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EF329E70; Tue, 8 Nov 2022 12:37:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667911079; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iKXtTnIMUFfHr88uUjrabFNYuleTXMetkDHhk5sQefc=; b=a13uvs5870Yp3JrOIIByHijsTabqowbgYbB2MJOGSIZcNeHL/P6SdC7mwW6i73NkX0Zy8r rvrKWHRidG3v2yqD6XbfT9RWfgzKHhXK0UWRQPa2PR1z3FO8hOpYGiBpBMv6Y715rEwgnR I9nYcRdmo6onvU1hUrdhdJFPUoOKChA= X-MC-Unique: WcY4mJAANQOUqTC0MmcyvQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eesposit@redhat.com, stefanha@redhat.com, hreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 02/13] test-bdrv-drain: Don't yield in .bdrv_co_drained_begin/end() Date: Tue, 8 Nov 2022 13:37:27 +0100 Message-Id: <20221108123738.530873-3-kwolf@redhat.com> In-Reply-To: <20221108123738.530873-1-kwolf@redhat.com> References: <20221108123738.530873-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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: 1667911147986100016 Content-Type: text/plain; charset="utf-8" We want to change .bdrv_co_drained_begin/end() back to be non-coroutine callbacks, so in preparation, avoid yielding in their implementation. This does almost the same as the existing logic in bdrv_drain_invoke(), by creating and entering coroutines internally. However, since the test case is by far the heaviest user of coroutine code in drain callbacks, it is preferable to have the complexity in the test case rather than the drain core, which is already complicated enough without this. The behaviour for bdrv_drain_begin() is unchanged because we increase bs->in_flight and this is still polled. However, bdrv_drain_end() doesn't wait for the spawned coroutine to complete any more. This is fine, we don't rely on bdrv_drain_end() restarting all operations immediately before the next aio_poll(). Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito Reviewed-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- tests/unit/test-bdrv-drain.c | 64 ++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 18 deletions(-) diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 09dc4a4891..24f34e24ad 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -38,12 +38,22 @@ typedef struct BDRVTestState { bool sleep_in_drain_begin; } BDRVTestState; =20 +static void coroutine_fn sleep_in_drain_begin(void *opaque) +{ + BlockDriverState *bs =3D opaque; + + qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 100000); + bdrv_dec_in_flight(bs); +} + static void coroutine_fn bdrv_test_co_drain_begin(BlockDriverState *bs) { BDRVTestState *s =3D bs->opaque; s->drain_count++; if (s->sleep_in_drain_begin) { - qemu_co_sleep_ns(QEMU_CLOCK_REALTIME, 100000); + Coroutine *co =3D qemu_coroutine_create(sleep_in_drain_begin, bs); + bdrv_inc_in_flight(bs); + aio_co_enter(bdrv_get_aio_context(bs), co); } } =20 @@ -1916,6 +1926,21 @@ static int coroutine_fn bdrv_replace_test_co_preadv(= BlockDriverState *bs, return 0; } =20 +static void coroutine_fn bdrv_replace_test_drain_co(void *opaque) +{ + BlockDriverState *bs =3D opaque; + BDRVReplaceTestState *s =3D bs->opaque; + + /* Keep waking io_co up until it is done */ + while (s->io_co) { + aio_co_wake(s->io_co); + s->io_co =3D NULL; + qemu_coroutine_yield(); + } + s->drain_co =3D NULL; + bdrv_dec_in_flight(bs); +} + /** * If .drain_count is 0, wake up .io_co if there is one; and set * .was_drained. @@ -1926,20 +1951,27 @@ static void coroutine_fn bdrv_replace_test_co_drain= _begin(BlockDriverState *bs) BDRVReplaceTestState *s =3D bs->opaque; =20 if (!s->drain_count) { - /* Keep waking io_co up until it is done */ - s->drain_co =3D qemu_coroutine_self(); - while (s->io_co) { - aio_co_wake(s->io_co); - s->io_co =3D NULL; - qemu_coroutine_yield(); - } - s->drain_co =3D NULL; - + s->drain_co =3D qemu_coroutine_create(bdrv_replace_test_drain_co, = bs); + bdrv_inc_in_flight(bs); + aio_co_enter(bdrv_get_aio_context(bs), s->drain_co); s->was_drained =3D true; } s->drain_count++; } =20 +static void coroutine_fn bdrv_replace_test_read_entry(void *opaque) +{ + BlockDriverState *bs =3D opaque; + char data; + QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, &data, 1); + int ret; + + /* Queue a read request post-drain */ + ret =3D bdrv_replace_test_co_preadv(bs, 0, 1, &qiov, 0); + g_assert(ret >=3D 0); + bdrv_dec_in_flight(bs); +} + /** * Reduce .drain_count, set .was_undrained once it reaches 0. * If .drain_count reaches 0 and the node has a backing file, issue a @@ -1951,17 +1983,13 @@ static void coroutine_fn bdrv_replace_test_co_drain= _end(BlockDriverState *bs) =20 g_assert(s->drain_count > 0); if (!--s->drain_count) { - int ret; - s->was_undrained =3D true; =20 if (bs->backing) { - char data; - QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, &data, 1); - - /* Queue a read request post-drain */ - ret =3D bdrv_replace_test_co_preadv(bs, 0, 1, &qiov, 0); - g_assert(ret >=3D 0); + Coroutine *co =3D qemu_coroutine_create(bdrv_replace_test_read= _entry, + bs); + bdrv_inc_in_flight(bs); + aio_co_enter(bdrv_get_aio_context(bs), co); } } } --=20 2.38.1 From nobody Tue May 7 21:17:12 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=1667911145; cv=none; d=zohomail.com; s=zohoarc; b=cxH7XoD+8/DQASPhnnhyy7K7q5OZkJMFYlP8o3JmQwPrxeirLqOol9/Yoo4AufvgF3283KbV8e5lt0Kkz7K51Zn5rHkPWCsqG6Fp60aWMR1ybEXb7y75FvTqQWKdnLcpXvGcRuomPQaid5oDBae/kD0BRdhTzJcafQhxfdJKCks= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667911145; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Y7TVexk9JyZUilantQhtKDPwYRPqjLPVktPAQ9hbpYw=; b=ETJn/EsnpURW81QVmTLMOI5sakSo77C29AbCesU5Bj4/3eB1zusdqooWgX53yevhuX5k9i7AnZsjEvM71W530T2u5q6HGFWMtbc8C+/CsAh73EjHH10dng/6we0hASSZSsH1ntDWFYDMUOei7EfQ5cM416bE2thkWStVyiTH6Cs= 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 16679111459877.049879417235729; Tue, 8 Nov 2022 04:39:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osNrp-0007mO-ER; Tue, 08 Nov 2022 07:38:13 -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 1osNri-0007iM-SM for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:07 -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 1osNre-0000ZT-Qr for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:06 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-516-ZHtBJI3mOIWmBOIEHj_MOQ-1; Tue, 08 Nov 2022 07:37:57 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EAC20833AEE; Tue, 8 Nov 2022 12:37:56 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id D16BD9E70; Tue, 8 Nov 2022 12:37:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667911080; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Y7TVexk9JyZUilantQhtKDPwYRPqjLPVktPAQ9hbpYw=; b=ZP6k6BCWsaT3cERUSJtpUQK1dGIsmv+moIUj0cBY5YO5dYmA+9K7m0Kej/CiPnoqrHZXea oDhqNnqo+vYSpbV4NW6C8Y01EHWJYnZLm8paxZJ/xh+wB5QPFMQA82pezZcaOeHGmc9ndh 7lvw603HDzBR6QWdv9nkygx/ScFfVqs= X-MC-Unique: ZHtBJI3mOIWmBOIEHj_MOQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eesposit@redhat.com, stefanha@redhat.com, hreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 03/13] block: Revert .bdrv_drained_begin/end to non-coroutine_fn Date: Tue, 8 Nov 2022 13:37:28 +0100 Message-Id: <20221108123738.530873-4-kwolf@redhat.com> In-Reply-To: <20221108123738.530873-1-kwolf@redhat.com> References: <20221108123738.530873-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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: 1667911148003100017 Content-Type: text/plain; charset="utf-8" Polling during bdrv_drained_end() can be problematic (and in the future, we may get cases for bdrv_drained_begin() where polling is forbidden, and we don't care about already in-flight requests, but just want to prevent new requests from arriving). The .bdrv_drained_begin/end callbacks running in a coroutine is the only reason why we have to do this polling, so make them non-coroutine callbacks again. None of the callers actually yield any more. This means that bdrv_drained_end() effectively doesn't poll any more, even if AIO_WAIT_WHILE() loops are still there (their condition is false from the beginning). This is generally not a problem, but in test-bdrv-drain, some additional explicit aio_poll() calls need to be added because the test case wants to verify the final state after BHs have executed. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito Reviewed-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/block_int-common.h | 10 ++++--- block.c | 4 +-- block/io.c | 49 +++++--------------------------- block/qed.c | 4 +-- block/throttle.c | 6 ++-- tests/unit/test-bdrv-drain.c | 18 ++++++------ 6 files changed, 30 insertions(+), 61 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 5a2cc077a0..0956acbb60 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -735,17 +735,19 @@ struct BlockDriver { void (*bdrv_io_unplug)(BlockDriverState *bs); =20 /** - * bdrv_co_drain_begin is called if implemented in the beginning of a + * bdrv_drain_begin is called if implemented in the beginning of a * drain operation to drain and stop any internal sources of requests = in * the driver. - * bdrv_co_drain_end is called if implemented at the end of the drain. + * bdrv_drain_end is called if implemented at the end of the drain. * * They should be used by the driver to e.g. manage scheduled I/O * requests, or toggle an internal state. After the end of the drain n= ew * requests will continue normally. + * + * Implementations of both functions must not call aio_poll(). */ - void coroutine_fn (*bdrv_co_drain_begin)(BlockDriverState *bs); - void coroutine_fn (*bdrv_co_drain_end)(BlockDriverState *bs); + void (*bdrv_drain_begin)(BlockDriverState *bs); + void (*bdrv_drain_end)(BlockDriverState *bs); =20 bool (*bdrv_supports_persistent_dirty_bitmap)(BlockDriverState *bs); bool coroutine_fn (*bdrv_co_can_store_new_dirty_bitmap)( diff --git a/block.c b/block.c index 3bd594eb2a..fed8077993 100644 --- a/block.c +++ b/block.c @@ -1705,8 +1705,8 @@ static int bdrv_open_driver(BlockDriverState *bs, Blo= ckDriver *drv, assert(is_power_of_2(bs->bl.request_alignment)); =20 for (i =3D 0; i < bs->quiesce_counter; i++) { - if (drv->bdrv_co_drain_begin) { - drv->bdrv_co_drain_begin(bs); + if (drv->bdrv_drain_begin) { + drv->bdrv_drain_begin(bs); } } =20 diff --git a/block/io.c b/block/io.c index 34b30e304e..183b407f5b 100644 --- a/block/io.c +++ b/block/io.c @@ -250,55 +250,20 @@ typedef struct { int *drained_end_counter; } BdrvCoDrainData; =20 -static void coroutine_fn bdrv_drain_invoke_entry(void *opaque) -{ - BdrvCoDrainData *data =3D opaque; - BlockDriverState *bs =3D data->bs; - - if (data->begin) { - bs->drv->bdrv_co_drain_begin(bs); - } else { - bs->drv->bdrv_co_drain_end(bs); - } - - /* Set data->done and decrement drained_end_counter before bdrv_wakeup= () */ - qatomic_mb_set(&data->done, true); - if (!data->begin) { - qatomic_dec(data->drained_end_counter); - } - bdrv_dec_in_flight(bs); - - g_free(data); -} - -/* Recursively call BlockDriver.bdrv_co_drain_begin/end callbacks */ +/* Recursively call BlockDriver.bdrv_drain_begin/end callbacks */ static void bdrv_drain_invoke(BlockDriverState *bs, bool begin, int *drained_end_counter) { - BdrvCoDrainData *data; - - if (!bs->drv || (begin && !bs->drv->bdrv_co_drain_begin) || - (!begin && !bs->drv->bdrv_co_drain_end)) { + if (!bs->drv || (begin && !bs->drv->bdrv_drain_begin) || + (!begin && !bs->drv->bdrv_drain_end)) { return; } =20 - data =3D g_new(BdrvCoDrainData, 1); - *data =3D (BdrvCoDrainData) { - .bs =3D bs, - .done =3D false, - .begin =3D begin, - .drained_end_counter =3D drained_end_counter, - }; - - if (!begin) { - qatomic_inc(drained_end_counter); + if (begin) { + bs->drv->bdrv_drain_begin(bs); + } else { + bs->drv->bdrv_drain_end(bs); } - - /* Make sure the driver callback completes during the polling phase for - * drain_begin. */ - bdrv_inc_in_flight(bs); - data->co =3D qemu_coroutine_create(bdrv_drain_invoke_entry, data); - aio_co_schedule(bdrv_get_aio_context(bs), data->co); } =20 /* Returns true if BDRV_POLL_WHILE() should go into a blocking aio_poll() = */ diff --git a/block/qed.c b/block/qed.c index 013f826c44..301ff8fd86 100644 --- a/block/qed.c +++ b/block/qed.c @@ -365,7 +365,7 @@ static void bdrv_qed_attach_aio_context(BlockDriverStat= e *bs, } } =20 -static void coroutine_fn bdrv_qed_co_drain_begin(BlockDriverState *bs) +static void bdrv_qed_co_drain_begin(BlockDriverState *bs) { BDRVQEDState *s =3D bs->opaque; =20 @@ -1661,7 +1661,7 @@ static BlockDriver bdrv_qed =3D { .bdrv_co_check =3D bdrv_qed_co_check, .bdrv_detach_aio_context =3D bdrv_qed_detach_aio_context, .bdrv_attach_aio_context =3D bdrv_qed_attach_aio_context, - .bdrv_co_drain_begin =3D bdrv_qed_co_drain_begin, + .bdrv_drain_begin =3D bdrv_qed_co_drain_begin, }; =20 static void bdrv_qed_init(void) diff --git a/block/throttle.c b/block/throttle.c index 131eba3ab4..6e3ae1b355 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -214,7 +214,7 @@ static void throttle_reopen_abort(BDRVReopenState *reop= en_state) reopen_state->opaque =3D NULL; } =20 -static void coroutine_fn throttle_co_drain_begin(BlockDriverState *bs) +static void throttle_co_drain_begin(BlockDriverState *bs) { ThrottleGroupMember *tgm =3D bs->opaque; if (qatomic_fetch_inc(&tgm->io_limits_disabled) =3D=3D 0) { @@ -261,8 +261,8 @@ static BlockDriver bdrv_throttle =3D { .bdrv_reopen_commit =3D throttle_reopen_commit, .bdrv_reopen_abort =3D throttle_reopen_abort, =20 - .bdrv_co_drain_begin =3D throttle_co_drain_begin, - .bdrv_co_drain_end =3D throttle_co_drain_end, + .bdrv_drain_begin =3D throttle_co_drain_begin, + .bdrv_drain_end =3D throttle_co_drain_end, =20 .is_filter =3D true, .strong_runtime_opts =3D throttle_strong_runtime_opts, diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 24f34e24ad..695519ee02 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -46,7 +46,7 @@ static void coroutine_fn sleep_in_drain_begin(void *opaqu= e) bdrv_dec_in_flight(bs); } =20 -static void coroutine_fn bdrv_test_co_drain_begin(BlockDriverState *bs) +static void bdrv_test_drain_begin(BlockDriverState *bs) { BDRVTestState *s =3D bs->opaque; s->drain_count++; @@ -57,7 +57,7 @@ static void coroutine_fn bdrv_test_co_drain_begin(BlockDr= iverState *bs) } } =20 -static void coroutine_fn bdrv_test_co_drain_end(BlockDriverState *bs) +static void bdrv_test_drain_end(BlockDriverState *bs) { BDRVTestState *s =3D bs->opaque; s->drain_count--; @@ -111,8 +111,8 @@ static BlockDriver bdrv_test =3D { .bdrv_close =3D bdrv_test_close, .bdrv_co_preadv =3D bdrv_test_co_preadv, =20 - .bdrv_co_drain_begin =3D bdrv_test_co_drain_begin, - .bdrv_co_drain_end =3D bdrv_test_co_drain_end, + .bdrv_drain_begin =3D bdrv_test_drain_begin, + .bdrv_drain_end =3D bdrv_test_drain_end, =20 .bdrv_child_perm =3D bdrv_default_perms, =20 @@ -1703,6 +1703,7 @@ static void test_blockjob_commit_by_drained_end(void) bdrv_drained_begin(bs_child); g_assert(!job_has_completed); bdrv_drained_end(bs_child); + aio_poll(qemu_get_aio_context(), false); g_assert(job_has_completed); =20 bdrv_unref(bs_parents[0]); @@ -1858,6 +1859,7 @@ static void test_drop_intermediate_poll(void) =20 g_assert(!job_has_completed); ret =3D bdrv_drop_intermediate(chain[1], chain[0], NULL); + aio_poll(qemu_get_aio_context(), false); g_assert(ret =3D=3D 0); g_assert(job_has_completed); =20 @@ -1946,7 +1948,7 @@ static void coroutine_fn bdrv_replace_test_drain_co(v= oid *opaque) * .was_drained. * Increment .drain_count. */ -static void coroutine_fn bdrv_replace_test_co_drain_begin(BlockDriverState= *bs) +static void bdrv_replace_test_drain_begin(BlockDriverState *bs) { BDRVReplaceTestState *s =3D bs->opaque; =20 @@ -1977,7 +1979,7 @@ static void coroutine_fn bdrv_replace_test_read_entry= (void *opaque) * If .drain_count reaches 0 and the node has a backing file, issue a * read request. */ -static void coroutine_fn bdrv_replace_test_co_drain_end(BlockDriverState *= bs) +static void bdrv_replace_test_drain_end(BlockDriverState *bs) { BDRVReplaceTestState *s =3D bs->opaque; =20 @@ -2002,8 +2004,8 @@ static BlockDriver bdrv_replace_test =3D { .bdrv_close =3D bdrv_replace_test_close, .bdrv_co_preadv =3D bdrv_replace_test_co_preadv, =20 - .bdrv_co_drain_begin =3D bdrv_replace_test_co_drain_begin, - .bdrv_co_drain_end =3D bdrv_replace_test_co_drain_end, + .bdrv_drain_begin =3D bdrv_replace_test_drain_begin, + .bdrv_drain_end =3D bdrv_replace_test_drain_end, =20 .bdrv_child_perm =3D bdrv_default_perms, }; --=20 2.38.1 From nobody Tue May 7 21:17:12 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=1667911531; cv=none; d=zohomail.com; s=zohoarc; b=AgN6W/O+4vXTsrNSxOlUrvawZflD+g5nnDh0EsEQGLpmocEdLIkBijLuqMfD2Bcxip8wS54Ng4cTWMFwmEO3BDCFnQVV2ajTm3seAq73BiJhEFAFdwRBpd1RtCD+QygQQAmWPI+8AARJ4G4OaV8b5QAKC6C/QEZTXU5AgeKjMw0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667911531; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Vheh6oYRhEllMER/a/juSrdPMY9WMiojYAA0IfegZCE=; b=XuD2mOTtJwAPXAXMqq9erxOE9DUC258lFI27nkbC6fOgra1kfkkdDse5QPgT0lVKlpAi99/lWXgzGaTr42BjeY4h73+DA0nF47YX7IPjE2dVMcfU0Gj3cfiAGjAxVm8JQJMmwjJLzbaBs1haT6I/W1VXEL0nXDmeXvQBs4wDHjs= 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 1667911531736320.19323869584935; Tue, 8 Nov 2022 04:45:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osNrn-0007lf-3Q; Tue, 08 Nov 2022 07:38:11 -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 1osNrh-0007hZ-9k for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:05 -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 1osNre-0000il-KD for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:05 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-146-Te1R2edAP0KbyAmIIbSmig-1; Tue, 08 Nov 2022 07:37:58 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 658848001B8; Tue, 8 Nov 2022 12:37:58 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2FCC09E70; Tue, 8 Nov 2022 12:37:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667911081; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Vheh6oYRhEllMER/a/juSrdPMY9WMiojYAA0IfegZCE=; b=OAx0RYh5YZO3ETCKzn/Kep8S8vT37UBthHgICEZZZyg0b1P/fRgf2rEqdwicl5VJtk6yoU Q5f7+fcAqn8mOHqitZVhThe6k0IzB8bVA0nepphwkHwlmB3WnwtX6uAy9Pe+kfCnTJZZU9 XnN2j7f/xGgoeNCzLnXjcUDYvhfqyTY= X-MC-Unique: Te1R2edAP0KbyAmIIbSmig-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eesposit@redhat.com, stefanha@redhat.com, hreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 04/13] block: Remove drained_end_counter Date: Tue, 8 Nov 2022 13:37:29 +0100 Message-Id: <20221108123738.530873-5-kwolf@redhat.com> In-Reply-To: <20221108123738.530873-1-kwolf@redhat.com> References: <20221108123738.530873-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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: 1667911532275100003 Content-Type: text/plain; charset="utf-8" drained_end_counter is unused now, nobody changes its value any more. It can be removed. In cases where we had two almost identical functions that only differed in whether the caller passes drained_end_counter, or whether they would poll for a local drained_end_counter to reach 0, these become a single function. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/block-io.h | 15 ----- include/block/block_int-common.h | 6 +- block.c | 5 +- block/block-backend.c | 4 +- block/io.c | 97 ++++++++------------------------ blockjob.c | 2 +- 6 files changed, 30 insertions(+), 99 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 770ddeb7c8..97e9ae8bee 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -235,21 +235,6 @@ int coroutine_fn bdrv_co_copy_range(BdrvChild *src, in= t64_t src_offset, int64_t bytes, BdrvRequestFlags read_f= lags, BdrvRequestFlags write_flags); =20 -/** - * bdrv_drained_end_no_poll: - * - * Same as bdrv_drained_end(), but do not poll for the subgraph to - * actually become unquiesced. Therefore, no graph changes will occur - * with this function. - * - * *drained_end_counter is incremented for every background operation - * that is scheduled, and will be decremented for every operation once - * it settles. The caller must poll until it reaches 0. The counter - * should be accessed using atomic operations only. - */ -void bdrv_drained_end_no_poll(BlockDriverState *bs, int *drained_end_count= er); - - /* * "I/O or GS" API functions. These functions can run without * the BQL, but only in one specific iothread/main loop. diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 0956acbb60..6504db4fd9 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -939,15 +939,11 @@ struct BdrvChildClass { * These functions must not change the graph (and therefore also must = not * call aio_poll(), which could change the graph indirectly). * - * If drained_end() schedules background operations, it must atomically - * increment *drained_end_counter for each such operation and atomical= ly - * decrement it once the operation has settled. - * * Note that this can be nested. If drained_begin() was called twice, = new * I/O is allowed only after drained_end() was called twice, too. */ void (*drained_begin)(BdrvChild *child); - void (*drained_end)(BdrvChild *child, int *drained_end_counter); + void (*drained_end)(BdrvChild *child); =20 /* * Returns whether the parent has pending requests for the child. This diff --git a/block.c b/block.c index fed8077993..7a24bd4c36 100644 --- a/block.c +++ b/block.c @@ -1227,11 +1227,10 @@ static bool bdrv_child_cb_drained_poll(BdrvChild *c= hild) return bdrv_drain_poll(bs, false, NULL, false); } =20 -static void bdrv_child_cb_drained_end(BdrvChild *child, - int *drained_end_counter) +static void bdrv_child_cb_drained_end(BdrvChild *child) { BlockDriverState *bs =3D child->opaque; - bdrv_drained_end_no_poll(bs, drained_end_counter); + bdrv_drained_end(bs); } =20 static int bdrv_child_cb_inactivate(BdrvChild *child) diff --git a/block/block-backend.c b/block/block-backend.c index c0c7d56c8d..ecdfeb49bb 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -129,7 +129,7 @@ static void blk_root_inherit_options(BdrvChildRole role= , bool parent_is_format, } static void blk_root_drained_begin(BdrvChild *child); static bool blk_root_drained_poll(BdrvChild *child); -static void blk_root_drained_end(BdrvChild *child, int *drained_end_counte= r); +static void blk_root_drained_end(BdrvChild *child); =20 static void blk_root_change_media(BdrvChild *child, bool load); static void blk_root_resize(BdrvChild *child); @@ -2549,7 +2549,7 @@ static bool blk_root_drained_poll(BdrvChild *child) return busy || !!blk->in_flight; } =20 -static void blk_root_drained_end(BdrvChild *child, int *drained_end_counte= r) +static void blk_root_drained_end(BdrvChild *child) { BlockBackend *blk =3D child->opaque; assert(blk->quiesce_counter); diff --git a/block/io.c b/block/io.c index 183b407f5b..41e6121c31 100644 --- a/block/io.c +++ b/block/io.c @@ -58,27 +58,19 @@ static void bdrv_parent_drained_begin(BlockDriverState = *bs, BdrvChild *ignore, } } =20 -static void bdrv_parent_drained_end_single_no_poll(BdrvChild *c, - int *drained_end_counte= r) +void bdrv_parent_drained_end_single(BdrvChild *c) { + IO_OR_GS_CODE(); + assert(c->parent_quiesce_counter > 0); c->parent_quiesce_counter--; if (c->klass->drained_end) { - c->klass->drained_end(c, drained_end_counter); + c->klass->drained_end(c); } } =20 -void bdrv_parent_drained_end_single(BdrvChild *c) -{ - int drained_end_counter =3D 0; - IO_OR_GS_CODE(); - bdrv_parent_drained_end_single_no_poll(c, &drained_end_counter); - BDRV_POLL_WHILE(c->bs, qatomic_read(&drained_end_counter) > 0); -} - static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignor= e, - bool ignore_bds_parents, - int *drained_end_counter) + bool ignore_bds_parents) { BdrvChild *c; =20 @@ -86,7 +78,7 @@ static void bdrv_parent_drained_end(BlockDriverState *bs,= BdrvChild *ignore, if (c =3D=3D ignore || (ignore_bds_parents && c->klass->parent_is_= bds)) { continue; } - bdrv_parent_drained_end_single_no_poll(c, drained_end_counter); + bdrv_parent_drained_end_single(c); } } =20 @@ -247,12 +239,10 @@ typedef struct { bool poll; BdrvChild *parent; bool ignore_bds_parents; - int *drained_end_counter; } BdrvCoDrainData; =20 /* Recursively call BlockDriver.bdrv_drain_begin/end callbacks */ -static void bdrv_drain_invoke(BlockDriverState *bs, bool begin, - int *drained_end_counter) +static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) { if (!bs->drv || (begin && !bs->drv->bdrv_drain_begin) || (!begin && !bs->drv->bdrv_drain_end)) { @@ -303,8 +293,7 @@ static void bdrv_do_drained_begin(BlockDriverState *bs,= bool recursive, BdrvChild *parent, bool ignore_bds_paren= ts, bool poll); static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, - BdrvChild *parent, bool ignore_bds_parents, - int *drained_end_counter); + BdrvChild *parent, bool ignore_bds_parents= ); =20 static void bdrv_co_drain_bh_cb(void *opaque) { @@ -317,14 +306,12 @@ static void bdrv_co_drain_bh_cb(void *opaque) aio_context_acquire(ctx); bdrv_dec_in_flight(bs); if (data->begin) { - assert(!data->drained_end_counter); bdrv_do_drained_begin(bs, data->recursive, data->parent, data->ignore_bds_parents, data->poll); } else { assert(!data->poll); bdrv_do_drained_end(bs, data->recursive, data->parent, - data->ignore_bds_parents, - data->drained_end_counter); + data->ignore_bds_parents); } aio_context_release(ctx); } else { @@ -340,8 +327,7 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDr= iverState *bs, bool begin, bool recursive, BdrvChild *parent, bool ignore_bds_parents, - bool poll, - int *drained_end_counter) + bool poll) { BdrvCoDrainData data; Coroutine *self =3D qemu_coroutine_self(); @@ -361,7 +347,6 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDr= iverState *bs, .parent =3D parent, .ignore_bds_parents =3D ignore_bds_parents, .poll =3D poll, - .drained_end_counter =3D drained_end_counter, }; =20 if (bs) { @@ -404,7 +389,7 @@ void bdrv_do_drained_begin_quiesce(BlockDriverState *bs, } =20 bdrv_parent_drained_begin(bs, parent, ignore_bds_parents); - bdrv_drain_invoke(bs, true, NULL); + bdrv_drain_invoke(bs, true); } =20 static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, @@ -415,7 +400,7 @@ static void bdrv_do_drained_begin(BlockDriverState *bs,= bool recursive, =20 if (qemu_in_coroutine()) { bdrv_co_yield_to_drain(bs, true, recursive, parent, ignore_bds_par= ents, - poll, NULL); + poll); return; } =20 @@ -459,38 +444,24 @@ void bdrv_subtree_drained_begin(BlockDriverState *bs) =20 /** * This function does not poll, nor must any of its recursively called - * functions. The *drained_end_counter pointee will be incremented - * once for every background operation scheduled, and decremented once - * the operation settles. Therefore, the pointer must remain valid - * until the pointee reaches 0. That implies that whoever sets up the - * pointee has to poll until it is 0. - * - * We use atomic operations to access *drained_end_counter, because - * (1) when called from bdrv_set_aio_context_ignore(), the subgraph of - * @bs may contain nodes in different AioContexts, - * (2) bdrv_drain_all_end() uses the same counter for all nodes, - * regardless of which AioContext they are in. + * functions. */ static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, - BdrvChild *parent, bool ignore_bds_parents, - int *drained_end_counter) + BdrvChild *parent, bool ignore_bds_parents) { BdrvChild *child; int old_quiesce_counter; =20 - assert(drained_end_counter !=3D NULL); - if (qemu_in_coroutine()) { bdrv_co_yield_to_drain(bs, false, recursive, parent, ignore_bds_pa= rents, - false, drained_end_counter); + false); return; } assert(bs->quiesce_counter > 0); =20 /* Re-enable things in child-to-parent order */ - bdrv_drain_invoke(bs, false, drained_end_counter); - bdrv_parent_drained_end(bs, parent, ignore_bds_parents, - drained_end_counter); + bdrv_drain_invoke(bs, false); + bdrv_parent_drained_end(bs, parent, ignore_bds_parents); =20 old_quiesce_counter =3D qatomic_fetch_dec(&bs->quiesce_counter); if (old_quiesce_counter =3D=3D 1) { @@ -501,32 +472,21 @@ static void bdrv_do_drained_end(BlockDriverState *bs,= bool recursive, assert(!ignore_bds_parents); bs->recursive_quiesce_counter--; QLIST_FOREACH(child, &bs->children, next) { - bdrv_do_drained_end(child->bs, true, child, ignore_bds_parents, - drained_end_counter); + bdrv_do_drained_end(child->bs, true, child, ignore_bds_parents= ); } } } =20 void bdrv_drained_end(BlockDriverState *bs) { - int drained_end_counter =3D 0; IO_OR_GS_CODE(); - bdrv_do_drained_end(bs, false, NULL, false, &drained_end_counter); - BDRV_POLL_WHILE(bs, qatomic_read(&drained_end_counter) > 0); -} - -void bdrv_drained_end_no_poll(BlockDriverState *bs, int *drained_end_count= er) -{ - IO_CODE(); - bdrv_do_drained_end(bs, false, NULL, false, drained_end_counter); + bdrv_do_drained_end(bs, false, NULL, false); } =20 void bdrv_subtree_drained_end(BlockDriverState *bs) { - int drained_end_counter =3D 0; IO_OR_GS_CODE(); - bdrv_do_drained_end(bs, true, NULL, false, &drained_end_counter); - BDRV_POLL_WHILE(bs, qatomic_read(&drained_end_counter) > 0); + bdrv_do_drained_end(bs, true, NULL, false); } =20 void bdrv_apply_subtree_drain(BdrvChild *child, BlockDriverState *new_pare= nt) @@ -541,16 +501,12 @@ void bdrv_apply_subtree_drain(BdrvChild *child, Block= DriverState *new_parent) =20 void bdrv_unapply_subtree_drain(BdrvChild *child, BlockDriverState *old_pa= rent) { - int drained_end_counter =3D 0; int i; IO_OR_GS_CODE(); =20 for (i =3D 0; i < old_parent->recursive_quiesce_counter; i++) { - bdrv_do_drained_end(child->bs, true, child, false, - &drained_end_counter); + bdrv_do_drained_end(child->bs, true, child, false); } - - BDRV_POLL_WHILE(child->bs, qatomic_read(&drained_end_counter) > 0); } =20 void bdrv_drain(BlockDriverState *bs) @@ -608,7 +564,7 @@ void bdrv_drain_all_begin(void) GLOBAL_STATE_CODE(); =20 if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(NULL, true, false, NULL, true, true, NULL); + bdrv_co_yield_to_drain(NULL, true, false, NULL, true, true); return; } =20 @@ -647,22 +603,19 @@ void bdrv_drain_all_begin(void) =20 void bdrv_drain_all_end_quiesce(BlockDriverState *bs) { - int drained_end_counter =3D 0; GLOBAL_STATE_CODE(); =20 g_assert(bs->quiesce_counter > 0); g_assert(!bs->refcnt); =20 while (bs->quiesce_counter) { - bdrv_do_drained_end(bs, false, NULL, true, &drained_end_counter); + bdrv_do_drained_end(bs, false, NULL, true); } - BDRV_POLL_WHILE(bs, qatomic_read(&drained_end_counter) > 0); } =20 void bdrv_drain_all_end(void) { BlockDriverState *bs =3D NULL; - int drained_end_counter =3D 0; GLOBAL_STATE_CODE(); =20 /* @@ -678,13 +631,11 @@ 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, false, NULL, true, &drained_end_counter); + bdrv_do_drained_end(bs, false, NULL, true); aio_context_release(aio_context); } =20 assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context()); - AIO_WAIT_WHILE(NULL, qatomic_read(&drained_end_counter) > 0); - assert(bdrv_drain_all_count > 0); bdrv_drain_all_count--; } diff --git a/blockjob.c b/blockjob.c index 2d86014fa5..43d0db1f94 100644 --- a/blockjob.c +++ b/blockjob.c @@ -120,7 +120,7 @@ static bool child_job_drained_poll(BdrvChild *c) } } =20 -static void child_job_drained_end(BdrvChild *c, int *drained_end_counter) +static void child_job_drained_end(BdrvChild *c) { BlockJob *job =3D c->opaque; job_resume(&job->job); --=20 2.38.1 From nobody Tue May 7 21:17:12 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=1667911633; cv=none; d=zohomail.com; s=zohoarc; b=ONVBvUbx9XEFIrYRCKkCd+X9eWn4EXPaQOsOUL2RY7fSg1IIVABytFA6Hcaki8PG/okuUBUuugvKPLEVkrW4MZkO4wiJK7JzKPKgSlp0le3SgFC/lGgYIiG2xKKuq+asMRF0GJ+SFdDBMv/ZbN2WIvOdjgzwlnP/H3vMIWLeatc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667911633; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=h9O1xxCMnNw2TxPiON7N7f9zP6IQiXiXvJZViYa6z/c=; b=cK7hky5gtHHszyhmdpUdGUi4dhb8d7FVEfqEzqV3kvsK51E2nwJwfnZnQQwHv7hywQA4lfpjehrmzjI9PyK0pxuyxU1X2QDGMoGP/U9ACXzOvcUAdElKLERfEFZzUKjxlqBOJ9aHHo5afUOeIs4QgskaScoEUagyxiwI82+clIA= 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 1667911633347616.2595429685053; Tue, 8 Nov 2022 04:47:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osNs1-0007tP-4A; Tue, 08 Nov 2022 07:38:25 -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 1osNrl-0007jq-3Z for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:09 -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 1osNrf-0000qn-PQ for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:08 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-202-30fk09uBOOSEUZ3h7z2aXw-1; Tue, 08 Nov 2022 07:38:00 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B94833C0CD53; Tue, 8 Nov 2022 12:37:59 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9F64F9E70; Tue, 8 Nov 2022 12:37:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667911083; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=h9O1xxCMnNw2TxPiON7N7f9zP6IQiXiXvJZViYa6z/c=; b=f4D2RAH9R+ancuMIhD+TFUoJ8SIGpk0fgQwPzOorDznmffFOsF2W3EubbJBisuuxn3VEGa pvOQYUZP0kfeIK2pF+6Yf6QI6vPLHaVoTn27aHMNZCR1qBH5aLyNDNrvRQLFJVosrOBNMf NEwTzdQycMGx/UWFQvSthv8o5kVN7Dk= X-MC-Unique: 30fk09uBOOSEUZ3h7z2aXw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eesposit@redhat.com, stefanha@redhat.com, hreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 05/13] block: Inline bdrv_drain_invoke() Date: Tue, 8 Nov 2022 13:37:30 +0100 Message-Id: <20221108123738.530873-6-kwolf@redhat.com> In-Reply-To: <20221108123738.530873-1-kwolf@redhat.com> References: <20221108123738.530873-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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: 1667911634900100003 Content-Type: text/plain; charset="utf-8" bdrv_drain_invoke() has now two entirely separate cases that share no code any more and are selected depending on a bool parameter. Each case has only one caller. Just inline the function. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Emanuele Giuseppe Esposito Reviewed-by: Hanna Reitz Reviewed-by: Stefan Hajnoczi Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/io.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/block/io.c b/block/io.c index 41e6121c31..c520183fb7 100644 --- a/block/io.c +++ b/block/io.c @@ -241,21 +241,6 @@ typedef struct { bool ignore_bds_parents; } BdrvCoDrainData; =20 -/* Recursively call BlockDriver.bdrv_drain_begin/end callbacks */ -static void bdrv_drain_invoke(BlockDriverState *bs, bool begin) -{ - if (!bs->drv || (begin && !bs->drv->bdrv_drain_begin) || - (!begin && !bs->drv->bdrv_drain_end)) { - return; - } - - if (begin) { - bs->drv->bdrv_drain_begin(bs); - } else { - bs->drv->bdrv_drain_end(bs); - } -} - /* Returns true if BDRV_POLL_WHILE() should go into a blocking aio_poll() = */ bool bdrv_drain_poll(BlockDriverState *bs, bool recursive, BdrvChild *ignore_parent, bool ignore_bds_parents) @@ -389,7 +374,9 @@ void bdrv_do_drained_begin_quiesce(BlockDriverState *bs, } =20 bdrv_parent_drained_begin(bs, parent, ignore_bds_parents); - bdrv_drain_invoke(bs, true); + if (bs->drv && bs->drv->bdrv_drain_begin) { + bs->drv->bdrv_drain_begin(bs); + } } =20 static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, @@ -460,7 +447,9 @@ static void bdrv_do_drained_end(BlockDriverState *bs, b= ool recursive, assert(bs->quiesce_counter > 0); =20 /* Re-enable things in child-to-parent order */ - bdrv_drain_invoke(bs, false); + if (bs->drv && bs->drv->bdrv_drain_end) { + bs->drv->bdrv_drain_end(bs); + } bdrv_parent_drained_end(bs, parent, ignore_bds_parents); =20 old_quiesce_counter =3D qatomic_fetch_dec(&bs->quiesce_counter); --=20 2.38.1 From nobody Tue May 7 21:17:12 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=1667911969; cv=none; d=zohomail.com; s=zohoarc; b=V+1JxNNbVLwTJUsM00E7SOUS5UEZbd7aGIiw3uxVrnsoRaaNFlLobiu0UTNyn8Ea/aNePvuvqmT/rXQ6Y/FzjmES+ev4bTg91b17rTXGlMRhxoGSuliMzNoQI1/ucBPLhwzixIgfga4VQ9llzN/YyHgpxWvC5DTR7DniaAISpq8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667911969; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=VHNdZ8ld+frJDiOMMbtIIugEltCcnk/loS+XMbHu3T4=; b=K5gYV+ST7ZktNVvo3LHcWQ6cgCe2gG7I0EAl20mbdsJBT+dUvmk08xSQOMIYaYcQQw9V4jB57mb5antsnXfvlUU602H9MFz9ZMz0nmr4ZRZ8Z/KoousN2ogYeqIDxktvJ84YKf99efr2nzZ/Ci9XkRyvAXOZkjGsP+yXRg1oaNg= 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 1667911969754744.9472797616315; Tue, 8 Nov 2022 04:52:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osNs7-000850-LG; Tue, 08 Nov 2022 07:38:31 -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 1osNrn-0007ly-BQ for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:11 -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 1osNrh-0000yo-FM for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:11 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-631-GLJw91HhMSu3TKxWazN_6g-1; Tue, 08 Nov 2022 07:38:01 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1D358833AED; Tue, 8 Nov 2022 12:38:01 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id F15B29E70; Tue, 8 Nov 2022 12:37:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667911084; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VHNdZ8ld+frJDiOMMbtIIugEltCcnk/loS+XMbHu3T4=; b=TWp506o2JNvVQHcDaoZA699G7U0FQHOmlCBn0Yz42pvuNQUJlGIHZXx9+s/tEkN5jVqdC6 q3l8afojGP7X37Zi1/jRRUdC7PFwigB3IPUGYFBFmqHumO18+g8rmVHq4RsyAFpLE+a3K4 8WWmpu0/0e6MFlrM2c3jbujLwe/I/rU= X-MC-Unique: GLJw91HhMSu3TKxWazN_6g-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eesposit@redhat.com, stefanha@redhat.com, hreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 06/13] block: Drain invidual nodes during reopen Date: Tue, 8 Nov 2022 13:37:31 +0100 Message-Id: <20221108123738.530873-7-kwolf@redhat.com> In-Reply-To: <20221108123738.530873-1-kwolf@redhat.com> References: <20221108123738.530873-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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: 1667911971811100005 Content-Type: text/plain; charset="utf-8" bdrv_reopen() and friends use subtree drains as a lazy way of covering all the nodes they touch. Turns out that this lazy way is a lot more complicated than just draining the nodes individually, even not accounting for the additional complexity in the drain mechanism itself. Simplify the code by switching to draining the individual nodes that are already managed in the BlockReopenQueue anyway. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- block.c | 11 ++++------- block/replication.c | 6 ------ blockdev.c | 13 ------------- 3 files changed, 4 insertions(+), 26 deletions(-) diff --git a/block.c b/block.c index 7a24bd4c36..5828b970e4 100644 --- a/block.c +++ b/block.c @@ -4142,7 +4142,7 @@ static bool bdrv_recurse_has_child(BlockDriverState *= bs, * returns a pointer to bs_queue, which is either the newly allocated * bs_queue, or the existing bs_queue being used. * - * bs must be drained between bdrv_reopen_queue() and bdrv_reopen_multiple= (). + * bs is drained here and undrained by bdrv_reopen_queue_free(). */ static BlockReopenQueue *bdrv_reopen_queue_child(BlockReopenQueue *bs_queu= e, BlockDriverState *bs, @@ -4162,12 +4162,10 @@ static BlockReopenQueue *bdrv_reopen_queue_child(Bl= ockReopenQueue *bs_queue, int flags; QemuOpts *opts; =20 - /* Make sure that the caller remembered to use a drained section. This= is - * important to avoid graph changes between the recursive queuing here= and - * bdrv_reopen_multiple(). */ - assert(bs->quiesce_counter > 0); GLOBAL_STATE_CODE(); =20 + bdrv_drained_begin(bs); + if (bs_queue =3D=3D NULL) { bs_queue =3D g_new0(BlockReopenQueue, 1); QTAILQ_INIT(bs_queue); @@ -4317,6 +4315,7 @@ void bdrv_reopen_queue_free(BlockReopenQueue *bs_queu= e) if (bs_queue) { BlockReopenQueueEntry *bs_entry, *next; QTAILQ_FOREACH_SAFE(bs_entry, bs_queue, entry, next) { + bdrv_drained_end(bs_entry->state.bs); qobject_unref(bs_entry->state.explicit_options); qobject_unref(bs_entry->state.options); g_free(bs_entry); @@ -4464,7 +4463,6 @@ int bdrv_reopen(BlockDriverState *bs, QDict *opts, bo= ol keep_old_opts, =20 GLOBAL_STATE_CODE(); =20 - bdrv_subtree_drained_begin(bs); if (ctx !=3D qemu_get_aio_context()) { aio_context_release(ctx); } @@ -4475,7 +4473,6 @@ int bdrv_reopen(BlockDriverState *bs, QDict *opts, bo= ol keep_old_opts, if (ctx !=3D qemu_get_aio_context()) { aio_context_acquire(ctx); } - bdrv_subtree_drained_end(bs); =20 return ret; } diff --git a/block/replication.c b/block/replication.c index f1eed25e43..c62f48a874 100644 --- a/block/replication.c +++ b/block/replication.c @@ -374,9 +374,6 @@ static void reopen_backing_file(BlockDriverState *bs, b= ool writable, s->orig_secondary_read_only =3D bdrv_is_read_only(secondary_disk->= bs); } =20 - bdrv_subtree_drained_begin(hidden_disk->bs); - bdrv_subtree_drained_begin(secondary_disk->bs); - if (s->orig_hidden_read_only) { QDict *opts =3D qdict_new(); qdict_put_bool(opts, BDRV_OPT_READ_ONLY, !writable); @@ -401,9 +398,6 @@ static void reopen_backing_file(BlockDriverState *bs, b= ool writable, aio_context_acquire(ctx); } } - - bdrv_subtree_drained_end(hidden_disk->bs); - bdrv_subtree_drained_end(secondary_disk->bs); } =20 static void backup_job_cleanup(BlockDriverState *bs) diff --git a/blockdev.c b/blockdev.c index 3f1dec6242..8ffb3d9537 100644 --- a/blockdev.c +++ b/blockdev.c @@ -3547,8 +3547,6 @@ fail: void qmp_blockdev_reopen(BlockdevOptionsList *reopen_list, Error **errp) { BlockReopenQueue *queue =3D NULL; - GSList *drained =3D NULL; - GSList *p; =20 /* Add each one of the BDS that we want to reopen to the queue */ for (; reopen_list !=3D NULL; reopen_list =3D reopen_list->next) { @@ -3585,9 +3583,7 @@ void qmp_blockdev_reopen(BlockdevOptionsList *reopen_= list, Error **errp) ctx =3D bdrv_get_aio_context(bs); aio_context_acquire(ctx); =20 - bdrv_subtree_drained_begin(bs); queue =3D bdrv_reopen_queue(queue, bs, qdict, false); - drained =3D g_slist_prepend(drained, bs); =20 aio_context_release(ctx); } @@ -3598,15 +3594,6 @@ void qmp_blockdev_reopen(BlockdevOptionsList *reopen= _list, Error **errp) =20 fail: bdrv_reopen_queue_free(queue); - for (p =3D drained; p; p =3D p->next) { - BlockDriverState *bs =3D p->data; - AioContext *ctx =3D bdrv_get_aio_context(bs); - - aio_context_acquire(ctx); - bdrv_subtree_drained_end(bs); - aio_context_release(ctx); - } - g_slist_free(drained); } =20 void qmp_blockdev_del(const char *node_name, Error **errp) --=20 2.38.1 From nobody Tue May 7 21:17:12 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=1667911145; cv=none; d=zohomail.com; s=zohoarc; b=CG08sJXEkwtB6wjvJ1pv9wATu0DB1gcBUmyXtKzqpo7Xkz2zSr/dN93532QVJINkioR7QaCosZmnfT704zyWgE2UEfb7pFuqTxyriz8HzcFt/xFf13sF703aGk2oGezRXeiAFCadFeWK1eq+HtRxCdRnM7mF3ZolE0UTJ+wh7uY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667911145; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=aASdHM9LagztoXP2FajDKQImWulyF1tSzWXi9fWzA68=; b=TEzshlds5HP72Q2PY1jJ4Smcz/I235Fk6dmUdUaZLaNlA8I5JWuOMSJLXsSfKKA0g6sEcGezh9MFBVdZoFIsCQ1Q5APmiaHSQC2+hllEyhVUr5poz+cn+YO5pMxeQKcYF2n994OEWYfP9EXS07wD4rIyb7Qd4WsIvcA/f7XuuSo= 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 1667911145536239.08835540635664; Tue, 8 Nov 2022 04:39:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osNs6-00080o-V0; Tue, 08 Nov 2022 07:38:30 -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 1osNrm-0007lJ-Do for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38: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 1osNrg-0000xW-VR for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:10 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-673-LbHrORqhM9Kows41wFC5RQ-1; Tue, 08 Nov 2022 07:38:03 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 70ADA3817A67; Tue, 8 Nov 2022 12:38:02 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 569249E70; Tue, 8 Nov 2022 12:38:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667911084; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aASdHM9LagztoXP2FajDKQImWulyF1tSzWXi9fWzA68=; b=IDEg3XnQzipWP5W3C3OyYj5nagdYzEVs+0xTdWPg8Bbe/7zPHDxzKT9HxfvB7Q0RDa3lMI FekXk3rcP07dg4fnCwQlZ7doEMezrO003VGp2w4M0y63b7Nox75rR2gIKPb7Bh97GiRqk/ 3xiiY4Capu+jHhTfqrfkHF8QAqt9/EM= X-MC-Unique: LbHrORqhM9Kows41wFC5RQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eesposit@redhat.com, stefanha@redhat.com, hreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 07/13] block: Don't use subtree drains in bdrv_drop_intermediate() Date: Tue, 8 Nov 2022 13:37:32 +0100 Message-Id: <20221108123738.530873-8-kwolf@redhat.com> In-Reply-To: <20221108123738.530873-1-kwolf@redhat.com> References: <20221108123738.530873-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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: 1667911146175100001 Content-Type: text/plain; charset="utf-8" Instead of using a subtree drain from the top node (which also drains child nodes of base that we're not even interested in), use a normal drain for base, which automatically drains all of the parents, too. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index 5828b970e4..2f6b25875f 100644 --- a/block.c +++ b/block.c @@ -5581,7 +5581,7 @@ int bdrv_drop_intermediate(BlockDriverState *top, Blo= ckDriverState *base, GLOBAL_STATE_CODE(); =20 bdrv_ref(top); - bdrv_subtree_drained_begin(top); + bdrv_drained_begin(base); =20 if (!top->drv || !base->drv) { goto exit; @@ -5654,7 +5654,7 @@ int bdrv_drop_intermediate(BlockDriverState *top, Blo= ckDriverState *base, =20 ret =3D 0; exit: - bdrv_subtree_drained_end(top); + bdrv_drained_end(base); bdrv_unref(top); return ret; } --=20 2.38.1 From nobody Tue May 7 21:17:12 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=1667911969; cv=none; d=zohomail.com; s=zohoarc; b=ISQZGhNtwbV13TcltVvknY5nypP3QgxwG3dBJny3xdfkrHUjoaqZcxwogOLTaLrLdiXv3V4g7TMF7uKX2rxpVxWk+H1lreLE/92OBZbFiydLbaHoObqErSbif+Gi3aBmknQTbCWHrqoxf2KHTwGYyp2yRTOWY/C+9Jvzw52W8O8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667911969; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TbVD6LB6hd+aULt57ZpK1JUvQf7Q2WY8CUIRT+yvYFM=; b=OzHhMsQGglasJMh4AcY/DFJkuSVfuCvHaP2Nz/3eHe4nOcd1ir9pFAPbddIiZBU8y31UpVPjKUOyNvz/hMINFJg9RDZlsizsIrqL0a0BKo2Qm62Pd6sDYIF9D8asiCR+2t1n9GdVHju9VCuC/sclaHbNNHbi/xfopjfoRZr2VF0= 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 1667911969206727.4450570547075; Tue, 8 Nov 2022 04:52:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osNs8-00086D-Jw; Tue, 08 Nov 2022 07:38:32 -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 1osNrn-0007mF-Ov for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38: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 1osNrh-000126-Rf for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:11 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-158-PTdO1b-DN8-l4OLAZSj0Mg-1; Tue, 08 Nov 2022 07:38:04 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C717C833AEF; Tue, 8 Nov 2022 12:38:03 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9DA69E70; Tue, 8 Nov 2022 12:38:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667911085; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TbVD6LB6hd+aULt57ZpK1JUvQf7Q2WY8CUIRT+yvYFM=; b=dvHZHw1LwWkquPd+uV16L1ZcXa3IvYKpKrnL4CAEVfN8TQpPTsi2MUxMVHz764YH3mOnHf MzRlYY+Ifd9cKm4Eg8koziiabdSyVWpgOAxQvyy/8oV0Ze7ZAQS3iB8/Gc+fVm0v+Ivvez cnynSUyGDTYuGhuLaXHkiQFocoquof0= X-MC-Unique: PTdO1b-DN8-l4OLAZSj0Mg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eesposit@redhat.com, stefanha@redhat.com, hreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 08/13] stream: Replace subtree drain with a single node drain Date: Tue, 8 Nov 2022 13:37:33 +0100 Message-Id: <20221108123738.530873-9-kwolf@redhat.com> In-Reply-To: <20221108123738.530873-1-kwolf@redhat.com> References: <20221108123738.530873-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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: 1667911971843100006 Content-Type: text/plain; charset="utf-8" The subtree drain was introduced in commit b1e1af394d9 as a way to avoid graph changes between finding the base node and changing the block graph as necessary on completion of the image streaming job. The block graph could change between these two points because bdrv_set_backing_hd() first drains the parent node, which involved polling and can do anything. Subtree draining was an imperfect way to make this less likely (because with it, fewer callbacks are called during this window). Everyone agreed that it's not really the right solution, and it was only committed as a stopgap solution. This replaces the subtree drain with a solution that simply drains the parent node before we try to find the base node, and then call a version of bdrv_set_backing_hd() that doesn't drain, but just asserts that the parent node is already drained. This way, any graph changes caused by draining happen before we start looking at the graph and things stay consistent between finding the base node and changing the graph. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/block-global-state.h | 3 +++ block.c | 17 ++++++++++++++--- block/stream.c | 20 ++++++++++---------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index bb42ed9559..7923415d4e 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -82,6 +82,9 @@ int bdrv_open_file_child(const char *filename, BlockDriverState *bdrv_open_blockdev_ref(BlockdevRef *ref, Error **errp); int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, Error **errp); +int bdrv_set_backing_hd_drained(BlockDriverState *bs, + BlockDriverState *backing_hd, + Error **errp); int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options, const char *bdref_key, Error **errp); BlockDriverState *bdrv_open(const char *filename, const char *reference, diff --git a/block.c b/block.c index 2f6b25875f..43b893dd6c 100644 --- a/block.c +++ b/block.c @@ -3395,14 +3395,15 @@ static int bdrv_set_backing_noperm(BlockDriverState= *bs, return bdrv_set_file_or_backing_noperm(bs, backing_hd, true, tran, err= p); } =20 -int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, - Error **errp) +int bdrv_set_backing_hd_drained(BlockDriverState *bs, + BlockDriverState *backing_hd, + Error **errp) { int ret; Transaction *tran =3D tran_new(); =20 GLOBAL_STATE_CODE(); - bdrv_drained_begin(bs); + assert(bs->quiesce_counter > 0); =20 ret =3D bdrv_set_backing_noperm(bs, backing_hd, tran, errp); if (ret < 0) { @@ -3412,7 +3413,17 @@ int bdrv_set_backing_hd(BlockDriverState *bs, BlockD= riverState *backing_hd, ret =3D bdrv_refresh_perms(bs, errp); out: tran_finalize(tran, ret); + return ret; +} =20 +int bdrv_set_backing_hd(BlockDriverState *bs, BlockDriverState *backing_hd, + Error **errp) +{ + int ret; + GLOBAL_STATE_CODE(); + + bdrv_drained_begin(bs); + ret =3D bdrv_set_backing_hd_drained(bs, backing_hd, errp); bdrv_drained_end(bs); =20 return ret; diff --git a/block/stream.c b/block/stream.c index 694709bd25..81dcf5a417 100644 --- a/block/stream.c +++ b/block/stream.c @@ -64,13 +64,16 @@ static int stream_prepare(Job *job) bdrv_cor_filter_drop(s->cor_filter_bs); s->cor_filter_bs =3D NULL; =20 - bdrv_subtree_drained_begin(s->above_base); + /* + * bdrv_set_backing_hd() requires that unfiltered_bs is drained. Drain + * already here and use bdrv_set_backing_hd_drained() instead because + * the polling during drained_begin() might change the graph, and if w= e do + * this only later, we may end up working with the wrong base node (or= it + * might even have gone away by the time we want to use it). + */ + bdrv_drained_begin(unfiltered_bs); =20 base =3D bdrv_filter_or_cow_bs(s->above_base); - if (base) { - bdrv_ref(base); - } - unfiltered_base =3D bdrv_skip_filters(base); =20 if (bdrv_cow_child(unfiltered_bs)) { @@ -82,7 +85,7 @@ static int stream_prepare(Job *job) } } =20 - bdrv_set_backing_hd(unfiltered_bs, base, &local_err); + bdrv_set_backing_hd_drained(unfiltered_bs, base, &local_err); ret =3D bdrv_change_backing_file(unfiltered_bs, base_id, base_fmt,= false); if (local_err) { error_report_err(local_err); @@ -92,10 +95,7 @@ static int stream_prepare(Job *job) } =20 out: - if (base) { - bdrv_unref(base); - } - bdrv_subtree_drained_end(s->above_base); + bdrv_drained_end(unfiltered_bs); return ret; } =20 --=20 2.38.1 From nobody Tue May 7 21:17:12 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=1667911683; cv=none; d=zohomail.com; s=zohoarc; b=aFvLNyQPa0xvaEi/oo1wkTuUMw0V/e7+WesYvwEdlYZK12/bVUrq7MBBmw/ExEXaSdBVacY2KO1lrWUj8j23vAJRZg/kuMad+hubsRMlm84ZNLvuFAJ7xHio1Kd17dJscl6d9ERK9Qcolwj/vunkY13Q/8syvopWLz9vCd3I8sY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667911683; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=rGmw5zrEx1mh/JyNoydhjgVY5S/H434ZqGXJo+H5UtM=; b=jDhbgjamZb+yMK5suxYb253YTIWOQVE4bum0R2V4S9IT6WhJU4/O+ZwJw1HD+h1pc26QZ42hK3JDGcFn8q+6+z9TstI8v0akZnObmYC0L6ccm0U/PLOmxAH/xwr7quNzmi3MhBIaNMAdOzgTbKsidp42hSzeZ49+Q7kQjrO/z9I= 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 1667911683414903.3223311208105; Tue, 8 Nov 2022 04:48:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osNsG-0008Fm-64; Tue, 08 Nov 2022 07:38:40 -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 1osNrs-0007nH-Lq for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:17 -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 1osNrj-00014Y-8H for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:15 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-274-GzOm_B5VOEuXvvNq34mtWw-1; Tue, 08 Nov 2022 07:38:05 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 44AF1858F17; Tue, 8 Nov 2022 12:38:05 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E4479E70; Tue, 8 Nov 2022 12:38:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667911086; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rGmw5zrEx1mh/JyNoydhjgVY5S/H434ZqGXJo+H5UtM=; b=cH9DSXvkEzT1e+n797TL4YX8RoTxzF06L/okxB2YR+cJaQxVeR4993h6VLZER9Z8e6rFd1 NNA+Re0c80x9tOfTH/2Gq2jQ2el8nlsHkPpxISPA3gH8pfMAkErUWoB1r7GFXfqSyVN0Z2 nbU4qLy/H/+eIAdlqW+Uc66qX5tdZtU= X-MC-Unique: GzOm_B5VOEuXvvNq34mtWw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eesposit@redhat.com, stefanha@redhat.com, hreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 09/13] block: Remove subtree drains Date: Tue, 8 Nov 2022 13:37:34 +0100 Message-Id: <20221108123738.530873-10-kwolf@redhat.com> In-Reply-To: <20221108123738.530873-1-kwolf@redhat.com> References: <20221108123738.530873-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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: 1667911685344100003 Content-Type: text/plain; charset="utf-8" Subtree drains are not used any more. Remove them. After this, BdrvChildClass.attach/detach() don't poll any more. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/block-io.h | 18 +-- include/block/block_int-common.h | 1 - include/block/block_int-io.h | 12 -- block.c | 20 +-- block/io.c | 121 +++----------- tests/unit/test-bdrv-drain.c | 261 ++----------------------------- 6 files changed, 44 insertions(+), 389 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 97e9ae8bee..c35cb1e53f 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -303,8 +303,7 @@ void bdrv_parent_drained_end_single(BdrvChild *c); /** * bdrv_drain_poll: * - * Poll for pending requests in @bs, its parents (except for @ignore_paren= t), - * and if @recursive is true its children as well (used for subtree drain). + * Poll for pending requests in @bs and its parents (except for @ignore_pa= rent). * * If @ignore_bds_parents is true, parents that are BlockDriverStates must * ignore the drain request because they will be drained separately (used = for @@ -312,8 +311,8 @@ void bdrv_parent_drained_end_single(BdrvChild *c); * * This is part of bdrv_drained_begin. */ -bool bdrv_drain_poll(BlockDriverState *bs, bool recursive, - BdrvChild *ignore_parent, bool ignore_bds_parents); +bool bdrv_drain_poll(BlockDriverState *bs, BdrvChild *ignore_parent, + bool ignore_bds_parents); =20 /** * bdrv_drained_begin: @@ -334,12 +333,6 @@ void bdrv_drained_begin(BlockDriverState *bs); void bdrv_do_drained_begin_quiesce(BlockDriverState *bs, BdrvChild *parent, bool ignore_bds_pare= nts); =20 -/** - * Like bdrv_drained_begin, but recursively begins a quiesced section for - * exclusive access to all child nodes as well. - */ -void bdrv_subtree_drained_begin(BlockDriverState *bs); - /** * bdrv_drained_end: * @@ -353,9 +346,4 @@ void bdrv_subtree_drained_begin(BlockDriverState *bs); */ void bdrv_drained_end(BlockDriverState *bs); =20 -/** - * End a quiescent section started by bdrv_subtree_drained_begin(). - */ -void bdrv_subtree_drained_end(BlockDriverState *bs); - #endif /* BLOCK_IO_H */ diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 6504db4fd9..65ee5fcbec 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -1184,7 +1184,6 @@ struct BlockDriverState { =20 /* Accessed with atomic ops. */ int quiesce_counter; - int recursive_quiesce_counter; =20 unsigned int write_gen; /* Current data generation */ =20 diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 4b0b3e17ef..8bc061ebb8 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -179,16 +179,4 @@ void bdrv_bsc_invalidate_range(BlockDriverState *bs, */ void bdrv_bsc_fill(BlockDriverState *bs, int64_t offset, int64_t bytes); =20 - -/* - * "I/O or GS" API functions. These functions can run without - * the BQL, but only in one specific iothread/main loop. - * - * See include/block/block-io.h for more information about - * the "I/O or GS" API. - */ - -void bdrv_apply_subtree_drain(BdrvChild *child, BlockDriverState *new_pare= nt); -void bdrv_unapply_subtree_drain(BdrvChild *child, BlockDriverState *old_pa= rent); - #endif /* BLOCK_INT_IO_H */ diff --git a/block.c b/block.c index 43b893dd6c..9d082631d9 100644 --- a/block.c +++ b/block.c @@ -1224,7 +1224,7 @@ static void bdrv_child_cb_drained_begin(BdrvChild *ch= ild) static bool bdrv_child_cb_drained_poll(BdrvChild *child) { BlockDriverState *bs =3D child->opaque; - return bdrv_drain_poll(bs, false, NULL, false); + return bdrv_drain_poll(bs, NULL, false); } =20 static void bdrv_child_cb_drained_end(BdrvChild *child) @@ -1474,8 +1474,6 @@ static void bdrv_child_cb_attach(BdrvChild *child) assert(!bs->file); bs->file =3D child; } - - bdrv_apply_subtree_drain(child, bs); } =20 static void bdrv_child_cb_detach(BdrvChild *child) @@ -1486,8 +1484,6 @@ static void bdrv_child_cb_detach(BdrvChild *child) bdrv_backing_detach(child); } =20 - bdrv_unapply_subtree_drain(child, bs); - assert_bdrv_graph_writable(bs); QLIST_REMOVE(child, next); if (child =3D=3D bs->backing) { @@ -2843,9 +2839,6 @@ static void bdrv_replace_child_noperm(BdrvChild *chil= d, } =20 if (old_bs) { - /* Detach first so that the recursive drain sections coming from @= child - * are already gone and we only end the drain sections that came f= rom - * elsewhere. */ if (child->klass->detach) { child->klass->detach(child); } @@ -2860,17 +2853,14 @@ static void bdrv_replace_child_noperm(BdrvChild *ch= ild, QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); =20 /* - * Detaching the old node may have led to the new node's - * quiesce_counter having been decreased. Not a problem, we - * just need to recognize this here and then invoke - * drained_end appropriately more often. + * Polling in bdrv_parent_drained_begin_single() may have led to t= he new + * node's quiesce_counter having been decreased. Not a problem, w= e just + * need to recognize this here and then invoke drained_end appropr= iately + * more often. */ assert(new_bs->quiesce_counter <=3D new_bs_quiesce_counter); drain_saldo +=3D new_bs->quiesce_counter - new_bs_quiesce_counter; =20 - /* Attach only after starting new drained sections, so that recurs= ive - * drain sections coming from @child don't get an extra .drained_b= egin - * callback. */ if (child->klass->attach) { child->klass->attach(child); } diff --git a/block/io.c b/block/io.c index c520183fb7..870a25d7a5 100644 --- a/block/io.c +++ b/block/io.c @@ -235,17 +235,15 @@ typedef struct { BlockDriverState *bs; bool done; bool begin; - bool recursive; bool poll; BdrvChild *parent; bool ignore_bds_parents; } BdrvCoDrainData; =20 /* Returns true if BDRV_POLL_WHILE() should go into a blocking aio_poll() = */ -bool bdrv_drain_poll(BlockDriverState *bs, bool recursive, - BdrvChild *ignore_parent, bool ignore_bds_parents) +bool bdrv_drain_poll(BlockDriverState *bs, BdrvChild *ignore_parent, + bool ignore_bds_parents) { - BdrvChild *child, *next; IO_OR_GS_CODE(); =20 if (bdrv_parent_drained_poll(bs, ignore_parent, ignore_bds_parents)) { @@ -256,29 +254,19 @@ bool bdrv_drain_poll(BlockDriverState *bs, bool recur= sive, return true; } =20 - if (recursive) { - assert(!ignore_bds_parents); - QLIST_FOREACH_SAFE(child, &bs->children, next, next) { - if (bdrv_drain_poll(child->bs, recursive, child, false)) { - return true; - } - } - } - return false; } =20 -static bool bdrv_drain_poll_top_level(BlockDriverState *bs, bool recursive, +static bool bdrv_drain_poll_top_level(BlockDriverState *bs, BdrvChild *ignore_parent) { - return bdrv_drain_poll(bs, recursive, ignore_parent, false); + return bdrv_drain_poll(bs, ignore_parent, false); } =20 -static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, - BdrvChild *parent, bool ignore_bds_paren= ts, - bool poll); -static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, - BdrvChild *parent, bool ignore_bds_parents= ); +static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent, + bool ignore_bds_parents, bool poll); +static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent, + bool ignore_bds_parents); =20 static void bdrv_co_drain_bh_cb(void *opaque) { @@ -291,12 +279,11 @@ static void bdrv_co_drain_bh_cb(void *opaque) aio_context_acquire(ctx); bdrv_dec_in_flight(bs); if (data->begin) { - bdrv_do_drained_begin(bs, data->recursive, data->parent, - data->ignore_bds_parents, data->poll); + bdrv_do_drained_begin(bs, data->parent, data->ignore_bds_paren= ts, + data->poll); } else { assert(!data->poll); - bdrv_do_drained_end(bs, data->recursive, data->parent, - data->ignore_bds_parents); + bdrv_do_drained_end(bs, data->parent, data->ignore_bds_parents= ); } aio_context_release(ctx); } else { @@ -309,7 +296,7 @@ static void bdrv_co_drain_bh_cb(void *opaque) } =20 static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, - bool begin, bool recursive, + bool begin, BdrvChild *parent, bool ignore_bds_parents, bool poll) @@ -328,7 +315,6 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDr= iverState *bs, .bs =3D bs, .done =3D false, .begin =3D begin, - .recursive =3D recursive, .parent =3D parent, .ignore_bds_parents =3D ignore_bds_parents, .poll =3D poll, @@ -379,29 +365,16 @@ void bdrv_do_drained_begin_quiesce(BlockDriverState *= bs, } } =20 -static void bdrv_do_drained_begin(BlockDriverState *bs, bool recursive, - BdrvChild *parent, bool ignore_bds_paren= ts, - bool poll) +static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent, + bool ignore_bds_parents, bool poll) { - BdrvChild *child, *next; - if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(bs, true, recursive, parent, ignore_bds_par= ents, - poll); + bdrv_co_yield_to_drain(bs, true, parent, ignore_bds_parents, poll); return; } =20 bdrv_do_drained_begin_quiesce(bs, parent, ignore_bds_parents); =20 - if (recursive) { - assert(!ignore_bds_parents); - bs->recursive_quiesce_counter++; - QLIST_FOREACH_SAFE(child, &bs->children, next, next) { - bdrv_do_drained_begin(child->bs, true, child, ignore_bds_paren= ts, - false); - } - } - /* * Wait for drained requests to finish. * @@ -413,35 +386,27 @@ static void bdrv_do_drained_begin(BlockDriverState *b= s, bool recursive, */ if (poll) { assert(!ignore_bds_parents); - BDRV_POLL_WHILE(bs, bdrv_drain_poll_top_level(bs, recursive, paren= t)); + BDRV_POLL_WHILE(bs, bdrv_drain_poll_top_level(bs, parent)); } } =20 void bdrv_drained_begin(BlockDriverState *bs) { IO_OR_GS_CODE(); - bdrv_do_drained_begin(bs, false, NULL, false, true); -} - -void bdrv_subtree_drained_begin(BlockDriverState *bs) -{ - IO_OR_GS_CODE(); - bdrv_do_drained_begin(bs, true, NULL, false, true); + bdrv_do_drained_begin(bs, NULL, false, true); } =20 /** * This function does not poll, nor must any of its recursively called * functions. */ -static void bdrv_do_drained_end(BlockDriverState *bs, bool recursive, - BdrvChild *parent, bool ignore_bds_parents) +static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent, + bool ignore_bds_parents) { - BdrvChild *child; int old_quiesce_counter; =20 if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(bs, false, recursive, parent, ignore_bds_pa= rents, - false); + bdrv_co_yield_to_drain(bs, false, parent, ignore_bds_parents, fals= e); return; } assert(bs->quiesce_counter > 0); @@ -456,46 +421,12 @@ static void bdrv_do_drained_end(BlockDriverState *bs,= bool recursive, if (old_quiesce_counter =3D=3D 1) { aio_enable_external(bdrv_get_aio_context(bs)); } - - if (recursive) { - assert(!ignore_bds_parents); - bs->recursive_quiesce_counter--; - QLIST_FOREACH(child, &bs->children, next) { - bdrv_do_drained_end(child->bs, true, child, ignore_bds_parents= ); - } - } } =20 void bdrv_drained_end(BlockDriverState *bs) { IO_OR_GS_CODE(); - bdrv_do_drained_end(bs, false, NULL, false); -} - -void bdrv_subtree_drained_end(BlockDriverState *bs) -{ - IO_OR_GS_CODE(); - bdrv_do_drained_end(bs, true, NULL, false); -} - -void bdrv_apply_subtree_drain(BdrvChild *child, BlockDriverState *new_pare= nt) -{ - int i; - IO_OR_GS_CODE(); - - for (i =3D 0; i < new_parent->recursive_quiesce_counter; i++) { - bdrv_do_drained_begin(child->bs, true, child, false, true); - } -} - -void bdrv_unapply_subtree_drain(BdrvChild *child, BlockDriverState *old_pa= rent) -{ - int i; - IO_OR_GS_CODE(); - - for (i =3D 0; i < old_parent->recursive_quiesce_counter; i++) { - bdrv_do_drained_end(child->bs, true, child, false); - } + bdrv_do_drained_end(bs, NULL, false); } =20 void bdrv_drain(BlockDriverState *bs) @@ -528,7 +459,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, false, NULL, true); + result |=3D bdrv_drain_poll(bs, NULL, true); aio_context_release(aio_context); } =20 @@ -553,7 +484,7 @@ void bdrv_drain_all_begin(void) GLOBAL_STATE_CODE(); =20 if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(NULL, true, false, NULL, true, true); + bdrv_co_yield_to_drain(NULL, true, NULL, true, true); return; } =20 @@ -578,7 +509,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, false, NULL, true, false); + bdrv_do_drained_begin(bs, NULL, true, false); aio_context_release(aio_context); } =20 @@ -598,7 +529,7 @@ void bdrv_drain_all_end_quiesce(BlockDriverState *bs) g_assert(!bs->refcnt); =20 while (bs->quiesce_counter) { - bdrv_do_drained_end(bs, false, NULL, true); + bdrv_do_drained_end(bs, NULL, true); } } =20 @@ -620,7 +551,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, false, NULL, true); + bdrv_do_drained_end(bs, NULL, true); aio_context_release(aio_context); } =20 diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 695519ee02..dda08de8db 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -156,7 +156,6 @@ static void call_in_coroutine(void (*entry)(void)) enum drain_type { BDRV_DRAIN_ALL, BDRV_DRAIN, - BDRV_SUBTREE_DRAIN, DRAIN_TYPE_MAX, }; =20 @@ -165,7 +164,6 @@ static void do_drain_begin(enum drain_type drain_type, = BlockDriverState *bs) switch (drain_type) { case BDRV_DRAIN_ALL: bdrv_drain_all_begin(); break; case BDRV_DRAIN: bdrv_drained_begin(bs); break; - case BDRV_SUBTREE_DRAIN: bdrv_subtree_drained_begin(bs); break; default: g_assert_not_reached(); } } @@ -175,7 +173,6 @@ static void do_drain_end(enum drain_type drain_type, Bl= ockDriverState *bs) switch (drain_type) { case BDRV_DRAIN_ALL: bdrv_drain_all_end(); break; case BDRV_DRAIN: bdrv_drained_end(bs); break; - case BDRV_SUBTREE_DRAIN: bdrv_subtree_drained_end(bs); break; default: g_assert_not_reached(); } } @@ -271,11 +268,6 @@ static void test_drv_cb_drain(void) test_drv_cb_common(BDRV_DRAIN, false); } =20 -static void test_drv_cb_drain_subtree(void) -{ - test_drv_cb_common(BDRV_SUBTREE_DRAIN, true); -} - static void test_drv_cb_co_drain_all(void) { call_in_coroutine(test_drv_cb_drain_all); @@ -286,11 +278,6 @@ static void test_drv_cb_co_drain(void) call_in_coroutine(test_drv_cb_drain); } =20 -static void test_drv_cb_co_drain_subtree(void) -{ - call_in_coroutine(test_drv_cb_drain_subtree); -} - static void test_quiesce_common(enum drain_type drain_type, bool recursive) { BlockBackend *blk; @@ -332,11 +319,6 @@ static void test_quiesce_drain(void) test_quiesce_common(BDRV_DRAIN, false); } =20 -static void test_quiesce_drain_subtree(void) -{ - test_quiesce_common(BDRV_SUBTREE_DRAIN, true); -} - static void test_quiesce_co_drain_all(void) { call_in_coroutine(test_quiesce_drain_all); @@ -347,11 +329,6 @@ static void test_quiesce_co_drain(void) call_in_coroutine(test_quiesce_drain); } =20 -static void test_quiesce_co_drain_subtree(void) -{ - call_in_coroutine(test_quiesce_drain_subtree); -} - static void test_nested(void) { BlockBackend *blk; @@ -402,158 +379,6 @@ static void test_nested(void) blk_unref(blk); } =20 -static void test_multiparent(void) -{ - BlockBackend *blk_a, *blk_b; - BlockDriverState *bs_a, *bs_b, *backing; - BDRVTestState *a_s, *b_s, *backing_s; - - blk_a =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); - bs_a =3D bdrv_new_open_driver(&bdrv_test, "test-node-a", BDRV_O_RDWR, - &error_abort); - a_s =3D bs_a->opaque; - blk_insert_bs(blk_a, bs_a, &error_abort); - - blk_b =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); - bs_b =3D bdrv_new_open_driver(&bdrv_test, "test-node-b", BDRV_O_RDWR, - &error_abort); - b_s =3D bs_b->opaque; - blk_insert_bs(blk_b, bs_b, &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_a, backing, &error_abort); - bdrv_set_backing_hd(bs_b, backing, &error_abort); - - g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 0); - g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 0); - g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); - g_assert_cmpint(a_s->drain_count, =3D=3D, 0); - g_assert_cmpint(b_s->drain_count, =3D=3D, 0); - g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); - - do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a); - - g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 1); - g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 1); - g_assert_cmpint(backing->quiesce_counter, =3D=3D, 1); - g_assert_cmpint(a_s->drain_count, =3D=3D, 1); - g_assert_cmpint(b_s->drain_count, =3D=3D, 1); - g_assert_cmpint(backing_s->drain_count, =3D=3D, 1); - - do_drain_begin(BDRV_SUBTREE_DRAIN, bs_b); - - g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 2); - g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 2); - g_assert_cmpint(backing->quiesce_counter, =3D=3D, 2); - g_assert_cmpint(a_s->drain_count, =3D=3D, 2); - g_assert_cmpint(b_s->drain_count, =3D=3D, 2); - g_assert_cmpint(backing_s->drain_count, =3D=3D, 2); - - do_drain_end(BDRV_SUBTREE_DRAIN, bs_b); - - g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 1); - g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 1); - g_assert_cmpint(backing->quiesce_counter, =3D=3D, 1); - g_assert_cmpint(a_s->drain_count, =3D=3D, 1); - g_assert_cmpint(b_s->drain_count, =3D=3D, 1); - g_assert_cmpint(backing_s->drain_count, =3D=3D, 1); - - do_drain_end(BDRV_SUBTREE_DRAIN, bs_a); - - g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 0); - g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 0); - g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); - g_assert_cmpint(a_s->drain_count, =3D=3D, 0); - g_assert_cmpint(b_s->drain_count, =3D=3D, 0); - g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); - - bdrv_unref(backing); - bdrv_unref(bs_a); - bdrv_unref(bs_b); - blk_unref(blk_a); - blk_unref(blk_b); -} - -static void test_graph_change_drain_subtree(void) -{ - BlockBackend *blk_a, *blk_b; - BlockDriverState *bs_a, *bs_b, *backing; - BDRVTestState *a_s, *b_s, *backing_s; - - blk_a =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); - bs_a =3D bdrv_new_open_driver(&bdrv_test, "test-node-a", BDRV_O_RDWR, - &error_abort); - a_s =3D bs_a->opaque; - blk_insert_bs(blk_a, bs_a, &error_abort); - - blk_b =3D blk_new(qemu_get_aio_context(), BLK_PERM_ALL, BLK_PERM_ALL); - bs_b =3D bdrv_new_open_driver(&bdrv_test, "test-node-b", BDRV_O_RDWR, - &error_abort); - b_s =3D bs_b->opaque; - blk_insert_bs(blk_b, bs_b, &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_a, backing, &error_abort); - - g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 0); - g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 0); - g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); - g_assert_cmpint(a_s->drain_count, =3D=3D, 0); - g_assert_cmpint(b_s->drain_count, =3D=3D, 0); - g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); - - do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a); - do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a); - do_drain_begin(BDRV_SUBTREE_DRAIN, bs_a); - do_drain_begin(BDRV_SUBTREE_DRAIN, bs_b); - do_drain_begin(BDRV_SUBTREE_DRAIN, bs_b); - - bdrv_set_backing_hd(bs_b, backing, &error_abort); - g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 5); - g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 5); - g_assert_cmpint(backing->quiesce_counter, =3D=3D, 5); - g_assert_cmpint(a_s->drain_count, =3D=3D, 5); - g_assert_cmpint(b_s->drain_count, =3D=3D, 5); - g_assert_cmpint(backing_s->drain_count, =3D=3D, 5); - - bdrv_set_backing_hd(bs_b, NULL, &error_abort); - g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 3); - g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 2); - g_assert_cmpint(backing->quiesce_counter, =3D=3D, 3); - g_assert_cmpint(a_s->drain_count, =3D=3D, 3); - g_assert_cmpint(b_s->drain_count, =3D=3D, 2); - g_assert_cmpint(backing_s->drain_count, =3D=3D, 3); - - bdrv_set_backing_hd(bs_b, backing, &error_abort); - g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 5); - g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 5); - g_assert_cmpint(backing->quiesce_counter, =3D=3D, 5); - g_assert_cmpint(a_s->drain_count, =3D=3D, 5); - g_assert_cmpint(b_s->drain_count, =3D=3D, 5); - g_assert_cmpint(backing_s->drain_count, =3D=3D, 5); - - do_drain_end(BDRV_SUBTREE_DRAIN, bs_b); - do_drain_end(BDRV_SUBTREE_DRAIN, bs_b); - do_drain_end(BDRV_SUBTREE_DRAIN, bs_a); - do_drain_end(BDRV_SUBTREE_DRAIN, bs_a); - do_drain_end(BDRV_SUBTREE_DRAIN, bs_a); - - g_assert_cmpint(bs_a->quiesce_counter, =3D=3D, 0); - g_assert_cmpint(bs_b->quiesce_counter, =3D=3D, 0); - g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); - g_assert_cmpint(a_s->drain_count, =3D=3D, 0); - g_assert_cmpint(b_s->drain_count, =3D=3D, 0); - g_assert_cmpint(backing_s->drain_count, =3D=3D, 0); - - bdrv_unref(backing); - bdrv_unref(bs_a); - bdrv_unref(bs_b); - blk_unref(blk_a); - blk_unref(blk_b); -} - static void test_graph_change_drain_all(void) { BlockBackend *blk_a, *blk_b; @@ -773,12 +598,6 @@ static void test_iothread_drain(void) test_iothread_common(BDRV_DRAIN, 1); } =20 -static void test_iothread_drain_subtree(void) -{ - test_iothread_common(BDRV_SUBTREE_DRAIN, 0); - test_iothread_common(BDRV_SUBTREE_DRAIN, 1); -} - =20 typedef struct TestBlockJob { BlockJob common; @@ -863,7 +682,6 @@ enum test_job_result { enum test_job_drain_node { TEST_JOB_DRAIN_SRC, TEST_JOB_DRAIN_SRC_CHILD, - TEST_JOB_DRAIN_SRC_PARENT, }; =20 static void test_blockjob_common_drain_node(enum drain_type drain_type, @@ -901,9 +719,6 @@ static void test_blockjob_common_drain_node(enum drain_= type drain_type, case TEST_JOB_DRAIN_SRC_CHILD: drain_bs =3D src_backing; break; - case TEST_JOB_DRAIN_SRC_PARENT: - drain_bs =3D src_overlay; - break; default: g_assert_not_reached(); } @@ -1055,10 +870,6 @@ static void test_blockjob_common(enum drain_type drai= n_type, bool use_iothread, TEST_JOB_DRAIN_SRC); test_blockjob_common_drain_node(drain_type, use_iothread, result, TEST_JOB_DRAIN_SRC_CHILD); - if (drain_type =3D=3D BDRV_SUBTREE_DRAIN) { - test_blockjob_common_drain_node(drain_type, use_iothread, result, - TEST_JOB_DRAIN_SRC_PARENT); - } } =20 static void test_blockjob_drain_all(void) @@ -1071,11 +882,6 @@ static void test_blockjob_drain(void) test_blockjob_common(BDRV_DRAIN, false, TEST_JOB_SUCCESS); } =20 -static void test_blockjob_drain_subtree(void) -{ - test_blockjob_common(BDRV_SUBTREE_DRAIN, false, TEST_JOB_SUCCESS); -} - static void test_blockjob_error_drain_all(void) { test_blockjob_common(BDRV_DRAIN_ALL, false, TEST_JOB_FAIL_RUN); @@ -1088,12 +894,6 @@ static void test_blockjob_error_drain(void) test_blockjob_common(BDRV_DRAIN, false, TEST_JOB_FAIL_PREPARE); } =20 -static void test_blockjob_error_drain_subtree(void) -{ - test_blockjob_common(BDRV_SUBTREE_DRAIN, false, TEST_JOB_FAIL_RUN); - test_blockjob_common(BDRV_SUBTREE_DRAIN, false, TEST_JOB_FAIL_PREPARE); -} - static void test_blockjob_iothread_drain_all(void) { test_blockjob_common(BDRV_DRAIN_ALL, true, TEST_JOB_SUCCESS); @@ -1104,11 +904,6 @@ static void test_blockjob_iothread_drain(void) test_blockjob_common(BDRV_DRAIN, true, TEST_JOB_SUCCESS); } =20 -static void test_blockjob_iothread_drain_subtree(void) -{ - test_blockjob_common(BDRV_SUBTREE_DRAIN, true, TEST_JOB_SUCCESS); -} - static void test_blockjob_iothread_error_drain_all(void) { test_blockjob_common(BDRV_DRAIN_ALL, true, TEST_JOB_FAIL_RUN); @@ -1121,12 +916,6 @@ static void test_blockjob_iothread_error_drain(void) test_blockjob_common(BDRV_DRAIN, true, TEST_JOB_FAIL_PREPARE); } =20 -static void test_blockjob_iothread_error_drain_subtree(void) -{ - test_blockjob_common(BDRV_SUBTREE_DRAIN, true, TEST_JOB_FAIL_RUN); - test_blockjob_common(BDRV_SUBTREE_DRAIN, true, TEST_JOB_FAIL_PREPARE); -} - =20 typedef struct BDRVTestTopState { BdrvChild *wait_child; @@ -1273,14 +1062,6 @@ static void do_test_delete_by_drain(bool detach_inst= ead_of_delete, bdrv_drain(child_bs); bdrv_unref(child_bs); break; - case BDRV_SUBTREE_DRAIN: - /* Would have to ref/unref bs here for !detach_instead_of_delete, = but - * then the whole test becomes pointless because the graph changes - * don't occur during the drain any more. */ - assert(detach_instead_of_delete); - bdrv_subtree_drained_begin(bs); - bdrv_subtree_drained_end(bs); - break; case BDRV_DRAIN_ALL: bdrv_drain_all_begin(); bdrv_drain_all_end(); @@ -1315,11 +1096,6 @@ static void test_detach_by_drain(void) do_test_delete_by_drain(true, BDRV_DRAIN); } =20 -static void test_detach_by_drain_subtree(void) -{ - do_test_delete_by_drain(true, BDRV_SUBTREE_DRAIN); -} - =20 struct detach_by_parent_data { BlockDriverState *parent_b; @@ -1452,7 +1228,10 @@ static void test_detach_indirect(bool by_parent_cb) g_assert(acb !=3D NULL); =20 /* Drain and check the expected result */ - bdrv_subtree_drained_begin(parent_b); + bdrv_drained_begin(parent_b); + bdrv_drained_begin(a); + bdrv_drained_begin(b); + bdrv_drained_begin(c); =20 g_assert(detach_by_parent_data.child_c !=3D NULL); =20 @@ -1467,12 +1246,15 @@ static void test_detach_indirect(bool by_parent_cb) g_assert(QLIST_NEXT(child_a, next) =3D=3D NULL); =20 g_assert_cmpint(parent_a->quiesce_counter, =3D=3D, 1); - g_assert_cmpint(parent_b->quiesce_counter, =3D=3D, 1); + g_assert_cmpint(parent_b->quiesce_counter, =3D=3D, 3); g_assert_cmpint(a->quiesce_counter, =3D=3D, 1); - g_assert_cmpint(b->quiesce_counter, =3D=3D, 0); + g_assert_cmpint(b->quiesce_counter, =3D=3D, 1); g_assert_cmpint(c->quiesce_counter, =3D=3D, 1); =20 - bdrv_subtree_drained_end(parent_b); + bdrv_drained_end(parent_b); + bdrv_drained_end(a); + bdrv_drained_end(b); + bdrv_drained_end(c); =20 bdrv_unref(parent_b); blk_unref(blk); @@ -2202,70 +1984,47 @@ int main(int argc, char **argv) =20 g_test_add_func("/bdrv-drain/driver-cb/drain_all", test_drv_cb_drain_a= ll); g_test_add_func("/bdrv-drain/driver-cb/drain", test_drv_cb_drain); - g_test_add_func("/bdrv-drain/driver-cb/drain_subtree", - test_drv_cb_drain_subtree); =20 g_test_add_func("/bdrv-drain/driver-cb/co/drain_all", test_drv_cb_co_drain_all); g_test_add_func("/bdrv-drain/driver-cb/co/drain", test_drv_cb_co_drain= ); - g_test_add_func("/bdrv-drain/driver-cb/co/drain_subtree", - test_drv_cb_co_drain_subtree); - =20 g_test_add_func("/bdrv-drain/quiesce/drain_all", test_quiesce_drain_al= l); g_test_add_func("/bdrv-drain/quiesce/drain", test_quiesce_drain); - g_test_add_func("/bdrv-drain/quiesce/drain_subtree", - test_quiesce_drain_subtree); =20 g_test_add_func("/bdrv-drain/quiesce/co/drain_all", test_quiesce_co_drain_all); g_test_add_func("/bdrv-drain/quiesce/co/drain", test_quiesce_co_drain); - g_test_add_func("/bdrv-drain/quiesce/co/drain_subtree", - test_quiesce_co_drain_subtree); =20 g_test_add_func("/bdrv-drain/nested", test_nested); - g_test_add_func("/bdrv-drain/multiparent", test_multiparent); =20 - g_test_add_func("/bdrv-drain/graph-change/drain_subtree", - test_graph_change_drain_subtree); g_test_add_func("/bdrv-drain/graph-change/drain_all", test_graph_change_drain_all); =20 g_test_add_func("/bdrv-drain/iothread/drain_all", test_iothread_drain_= all); g_test_add_func("/bdrv-drain/iothread/drain", test_iothread_drain); - g_test_add_func("/bdrv-drain/iothread/drain_subtree", - test_iothread_drain_subtree); =20 g_test_add_func("/bdrv-drain/blockjob/drain_all", test_blockjob_drain_= all); g_test_add_func("/bdrv-drain/blockjob/drain", test_blockjob_drain); - g_test_add_func("/bdrv-drain/blockjob/drain_subtree", - test_blockjob_drain_subtree); =20 g_test_add_func("/bdrv-drain/blockjob/error/drain_all", test_blockjob_error_drain_all); g_test_add_func("/bdrv-drain/blockjob/error/drain", test_blockjob_error_drain); - g_test_add_func("/bdrv-drain/blockjob/error/drain_subtree", - test_blockjob_error_drain_subtree); =20 g_test_add_func("/bdrv-drain/blockjob/iothread/drain_all", test_blockjob_iothread_drain_all); g_test_add_func("/bdrv-drain/blockjob/iothread/drain", test_blockjob_iothread_drain); - g_test_add_func("/bdrv-drain/blockjob/iothread/drain_subtree", - test_blockjob_iothread_drain_subtree); =20 g_test_add_func("/bdrv-drain/blockjob/iothread/error/drain_all", test_blockjob_iothread_error_drain_all); g_test_add_func("/bdrv-drain/blockjob/iothread/error/drain", test_blockjob_iothread_error_drain); - g_test_add_func("/bdrv-drain/blockjob/iothread/error/drain_subtree", - test_blockjob_iothread_error_drain_subtree); =20 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/drain_subtree", test_detach_by_dra= in_subtree); 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 --=20 2.38.1 From nobody Tue May 7 21:17:12 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=1667911591; cv=none; d=zohomail.com; s=zohoarc; b=WSA/i9qpTrQqKRE0B+Lr1/gXR/ky+B8sH09s0UxQFA6JKi0pQ5rr4yZ4Tvl4B5+uxmjwkr56y8+MY24qX+ccKYg1FtOiozTggX/NFalwtuAE8dGf5jHw28yALlO7NMdEUSSfDa6zaXkkvLrYhwdAnhHK0ALmoJuni2KeOR0lN7k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667911591; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Oz/xkuuB1OMbrNhzRzbKbFgmf9Y1AK7qsxUYnCzpcf0=; b=QcZ8IluvWs+fRBqG5FGi8XgmbfzpqeKKNoHPjbdnwHBYsk4y077chrNkDmZALBbziyI6okK3qCXcVWYGVuFDYTPN8wfh1+dopuYAqdNL0HPUXKKEG/a7KWt5OtzmLyMXRq2PZMaI9L00Kl30kZvOitv78ewiBRzLxMa7gZ3hvBM= 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 1667911591093105.43443983662655; Tue, 8 Nov 2022 04:46:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osNsH-0008Je-TS; Tue, 08 Nov 2022 07:38:41 -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 1osNrx-0007rq-CO for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:23 -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 1osNrm-0001Iv-DJ for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:21 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-314-9IiCP7NkNY6xKLzStEveyw-1; Tue, 08 Nov 2022 07:38:06 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 994B0101A52A; Tue, 8 Nov 2022 12:38:06 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F0589E70; Tue, 8 Nov 2022 12:38:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667911089; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Oz/xkuuB1OMbrNhzRzbKbFgmf9Y1AK7qsxUYnCzpcf0=; b=IXsCf2ndyMTWV4Pla/1cy5FOlM9aHCUvEXfjYNDcHDGaZ1muH6vL8ds3HEpGd0sr7bRG1f xAyTKoLXb8Gry02OFACOhx6t6jKNb1nh6vJNByhsRaqSgGlip3eUax9cQx7CVo/Zs7Ls0a LaXhREGWe8M6YkJMQiLrrhO9PNtz3iE= X-MC-Unique: 9IiCP7NkNY6xKLzStEveyw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eesposit@redhat.com, stefanha@redhat.com, hreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 10/13] block: Call drain callbacks only once Date: Tue, 8 Nov 2022 13:37:35 +0100 Message-Id: <20221108123738.530873-11-kwolf@redhat.com> In-Reply-To: <20221108123738.530873-1-kwolf@redhat.com> References: <20221108123738.530873-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, 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, T_SPF_HELO_TEMPERROR=0.01, T_SPF_TEMPERROR=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1667911592946100003 Content-Type: text/plain; charset="utf-8" We only need to call both the BlockDriver's callback and the parent callbacks when going from undrained to drained or vice versa. A second drain section doesn't make a difference for the driver or the parent, they weren't supposed to send new requests before and after the second drain. One thing that gets in the way is the 'ignore_bds_parents' parameter in bdrv_do_drained_begin_quiesce() and bdrv_do_drained_end(): If it is true for the first drain, bs->quiesce_counter will be non-zero, but the parent callbacks still haven't been called, so a second drain where it is false would still have to call them. Instead of keeping track of this, let's just get rid of the parameter. It was introduced in commit 6cd5c9d7b2d as an optimisation so that during bdrv_drain_all(), we wouldn't recursively drain all parents up to the root for each node, resulting in quadratic complexity. As it happens, calling the callbacks only once solves the same problem, so as of this patch, we'll still have O(n) complexity and ignore_bds_parents is not needed any more. This patch only ignores the 'ignore_bds_parents' parameter. It will be removed in a separate patch. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Hanna Reitz --- block.c | 13 ++++++------- block/io.c | 24 +++++++++++++----------- tests/unit/test-bdrv-drain.c | 16 ++++++++++------ 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/block.c b/block.c index 9d082631d9..8878586f6e 100644 --- a/block.c +++ b/block.c @@ -2816,7 +2816,6 @@ static void bdrv_replace_child_noperm(BdrvChild *chil= d, { BlockDriverState *old_bs =3D child->bs; int new_bs_quiesce_counter; - int drain_saldo; =20 assert(!child->frozen); assert(old_bs !=3D new_bs); @@ -2827,15 +2826,13 @@ static void bdrv_replace_child_noperm(BdrvChild *ch= ild, } =20 new_bs_quiesce_counter =3D (new_bs ? new_bs->quiesce_counter : 0); - drain_saldo =3D new_bs_quiesce_counter - child->parent_quiesce_counter; =20 /* * If the new child node is drained but the old one was not, flush * all outstanding requests to the old child node. */ - while (drain_saldo > 0 && child->klass->drained_begin) { + if (new_bs_quiesce_counter && !child->parent_quiesce_counter) { bdrv_parent_drained_begin_single(child, true); - drain_saldo--; } =20 if (old_bs) { @@ -2859,7 +2856,6 @@ static void bdrv_replace_child_noperm(BdrvChild *chil= d, * more often. */ assert(new_bs->quiesce_counter <=3D new_bs_quiesce_counter); - drain_saldo +=3D new_bs->quiesce_counter - new_bs_quiesce_counter; =20 if (child->klass->attach) { child->klass->attach(child); @@ -2869,10 +2865,13 @@ static void bdrv_replace_child_noperm(BdrvChild *ch= ild, /* * 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. */ - while (drain_saldo < 0 && child->klass->drained_end) { + new_bs_quiesce_counter =3D (new_bs ? new_bs->quiesce_counter : 0); + if (!new_bs_quiesce_counter && child->parent_quiesce_counter) { bdrv_parent_drained_end_single(child); - drain_saldo++; } } =20 diff --git a/block/io.c b/block/io.c index 870a25d7a5..87c7a92f15 100644 --- a/block/io.c +++ b/block/io.c @@ -62,7 +62,7 @@ void bdrv_parent_drained_end_single(BdrvChild *c) { IO_OR_GS_CODE(); =20 - assert(c->parent_quiesce_counter > 0); + assert(c->parent_quiesce_counter =3D=3D 1); c->parent_quiesce_counter--; if (c->klass->drained_end) { c->klass->drained_end(c); @@ -109,6 +109,7 @@ static bool bdrv_parent_drained_poll(BlockDriverState *= bs, BdrvChild *ignore, void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll) { IO_OR_GS_CODE(); + assert(c->parent_quiesce_counter =3D=3D 0); c->parent_quiesce_counter++; if (c->klass->drained_begin) { c->klass->drained_begin(c); @@ -352,16 +353,16 @@ void bdrv_do_drained_begin_quiesce(BlockDriverState *= bs, BdrvChild *parent, bool ignore_bds_pare= nts) { IO_OR_GS_CODE(); - assert(!qemu_in_coroutine()); =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)); - } =20 - bdrv_parent_drained_begin(bs, parent, ignore_bds_parents); - if (bs->drv && bs->drv->bdrv_drain_begin) { - bs->drv->bdrv_drain_begin(bs); + /* TODO Remove ignore_bds_parents, we don't consider it any more */ + bdrv_parent_drained_begin(bs, parent, false); + if (bs->drv && bs->drv->bdrv_drain_begin) { + bs->drv->bdrv_drain_begin(bs); + } } } =20 @@ -412,13 +413,14 @@ static void bdrv_do_drained_end(BlockDriverState *bs,= BdrvChild *parent, assert(bs->quiesce_counter > 0); =20 /* Re-enable things in child-to-parent order */ - if (bs->drv && bs->drv->bdrv_drain_end) { - bs->drv->bdrv_drain_end(bs); - } - bdrv_parent_drained_end(bs, parent, ignore_bds_parents); - old_quiesce_counter =3D qatomic_fetch_dec(&bs->quiesce_counter); if (old_quiesce_counter =3D=3D 1) { + if (bs->drv && bs->drv->bdrv_drain_end) { + bs->drv->bdrv_drain_end(bs); + } + /* TODO Remove ignore_bds_parents, we don't consider it any more */ + bdrv_parent_drained_end(bs, parent, false); + aio_enable_external(bdrv_get_aio_context(bs)); } } diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index dda08de8db..172bc6debc 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -296,7 +296,11 @@ static void test_quiesce_common(enum drain_type drain_= type, bool recursive) =20 do_drain_begin(drain_type, bs); =20 - g_assert_cmpint(bs->quiesce_counter, =3D=3D, 1); + if (drain_type =3D=3D BDRV_DRAIN_ALL) { + g_assert_cmpint(bs->quiesce_counter, =3D=3D, 2); + } else { + g_assert_cmpint(bs->quiesce_counter, =3D=3D, 1); + } g_assert_cmpint(backing->quiesce_counter, =3D=3D, !!recursive); =20 do_drain_end(drain_type, bs); @@ -348,8 +352,8 @@ static void test_nested(void) =20 for (outer =3D 0; outer < DRAIN_TYPE_MAX; outer++) { for (inner =3D 0; inner < DRAIN_TYPE_MAX; inner++) { - int backing_quiesce =3D (outer !=3D BDRV_DRAIN) + - (inner !=3D BDRV_DRAIN); + int backing_quiesce =3D (outer =3D=3D BDRV_DRAIN_ALL) + + (inner =3D=3D BDRV_DRAIN_ALL); =20 g_assert_cmpint(bs->quiesce_counter, =3D=3D, 0); g_assert_cmpint(backing->quiesce_counter, =3D=3D, 0); @@ -359,10 +363,10 @@ static void test_nested(void) do_drain_begin(outer, bs); do_drain_begin(inner, bs); =20 - g_assert_cmpint(bs->quiesce_counter, =3D=3D, 2); + g_assert_cmpint(bs->quiesce_counter, =3D=3D, 2 + !!backing_qui= esce); g_assert_cmpint(backing->quiesce_counter, =3D=3D, backing_quie= sce); - g_assert_cmpint(s->drain_count, =3D=3D, 2); - g_assert_cmpint(backing_s->drain_count, =3D=3D, backing_quiesc= e); + g_assert_cmpint(s->drain_count, =3D=3D, 1); + g_assert_cmpint(backing_s->drain_count, =3D=3D, !!backing_quie= sce); =20 do_drain_end(inner, bs); do_drain_end(outer, bs); --=20 2.38.1 From nobody Tue May 7 21:17:12 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=1667911453; cv=none; d=zohomail.com; s=zohoarc; b=SkbN5CXR+hMIxjpUFBklFs9fmZYIdqWo+Hc1Z5zqab6WATuuawdanR4XHlWbxwc4NOaCHBARZIMqtEpxz0qh5eejFAKE+NX+fJdqdfv8+BY3tUv0EeXY6R8qBXwwOdBtQaJmHRCyOcNkhY9DwAXhiXefJYQnzDuvweY+5jmIIFk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667911453; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=/8GslLIM4BJMRtRjOc5AxZ4GQ2egucex8xB74Tv8heA=; b=D3IOEANbMw44pDu8T6DDtocavmBrTx2c9gm1pO5jForFE+LbTFMliFWymyhqaPrQDj05yiK8qj7Zw49+SFZgQR1myimJiQxgeX5YWn66EFF16xBxn9pdf7y89RZS5QhZDT0NdKMxO7v/M3kTzbBRDBVMY9Sw63FVuQuatLypWKo= 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 1667911453566697.9377377470189; Tue, 8 Nov 2022 04:44:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osNse-0000G2-Qr; Tue, 08 Nov 2022 07:39:04 -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 1osNs3-0007xM-Tn for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:29 -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 1osNrv-0001tA-M0 for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:26 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-670-0ZixrecPM7S6b56CMmMMKQ-1; Tue, 08 Nov 2022 07:38:08 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F3205185A79C; Tue, 8 Nov 2022 12:38:07 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3BF29E70; Tue, 8 Nov 2022 12:38:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667911099; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/8GslLIM4BJMRtRjOc5AxZ4GQ2egucex8xB74Tv8heA=; b=JjDp5KUt67C9D23vnNs0hJc4tlSCymVSClfnMvU8UBVr2ein0Kkm03zyvXpSRssAlH3Xur jt/yS15F9yvOn8v/Ji+jyFPjANtCbjv7QL0jYpdliMigCOijnr44HwYA1m0BRZDQTPZQAm 4jbtwyQi5V1zi0bENZyL3OzPKen37r4= X-MC-Unique: 0ZixrecPM7S6b56CMmMMKQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eesposit@redhat.com, stefanha@redhat.com, hreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 11/13] block: Remove ignore_bds_parents parameter from drain functions Date: Tue, 8 Nov 2022 13:37:36 +0100 Message-Id: <20221108123738.530873-12-kwolf@redhat.com> In-Reply-To: <20221108123738.530873-1-kwolf@redhat.com> References: <20221108123738.530873-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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: 1667911454079100002 Content-Type: text/plain; charset="utf-8" ignore_bds_parents is now ignored, so we can just remove it. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Hanna Reitz Reviewed-by: Vladimir Sementsov-Ogievskiy --- include/block/block-io.h | 10 ++---- block.c | 4 +-- block/io.c | 78 +++++++++++++++------------------------- 3 files changed, 32 insertions(+), 60 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index c35cb1e53f..5b54ed4672 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -305,14 +305,9 @@ void bdrv_parent_drained_end_single(BdrvChild *c); * * Poll for pending requests in @bs and its parents (except for @ignore_pa= rent). * - * If @ignore_bds_parents is true, parents that are BlockDriverStates must - * ignore the drain request because they will be drained separately (used = for - * drain_all). - * * 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, BdrvChild *ignore_parent); =20 /** * bdrv_drained_begin: @@ -330,8 +325,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, bool ignore_bds_pare= nts); +void bdrv_do_drained_begin_quiesce(BlockDriverState *bs, BdrvChild *parent= ); =20 /** * bdrv_drained_end: diff --git a/block.c b/block.c index 8878586f6e..5f5f79cd16 100644 --- a/block.c +++ b/block.c @@ -1218,13 +1218,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, false); + bdrv_do_drained_begin_quiesce(bs, NULL); } =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, NULL); } =20 static void bdrv_child_cb_drained_end(BdrvChild *child) diff --git a/block/io.c b/block/io.c index 87c7a92f15..4a83359a8f 100644 --- a/block/io.c +++ b/block/io.c @@ -45,13 +45,12 @@ 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, - bool ignore_bds_parents) +static void bdrv_parent_drained_begin(BlockDriverState *bs, BdrvChild *ign= ore) { BdrvChild *c, *next; =20 QLIST_FOREACH_SAFE(c, &bs->parents, next_parent, next) { - if (c =3D=3D ignore || (ignore_bds_parents && c->klass->parent_is_= bds)) { + if (c =3D=3D ignore) { continue; } bdrv_parent_drained_begin_single(c, false); @@ -69,13 +68,12 @@ void bdrv_parent_drained_end_single(BdrvChild *c) } } =20 -static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignor= e, - bool ignore_bds_parents) +static void bdrv_parent_drained_end(BlockDriverState *bs, BdrvChild *ignor= e) { BdrvChild *c; =20 QLIST_FOREACH(c, &bs->parents, next_parent) { - if (c =3D=3D ignore || (ignore_bds_parents && c->klass->parent_is_= bds)) { + if (c =3D=3D ignore) { continue; } bdrv_parent_drained_end_single(c); @@ -90,14 +88,13 @@ static 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, BdrvChild *igno= re) { 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 (c =3D=3D ignore) { continue; } busy |=3D bdrv_parent_drained_poll_single(c); @@ -238,16 +235,14 @@ typedef struct { bool begin; bool poll; BdrvChild *parent; - bool ignore_bds_parents; } 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, BdrvChild *ignore_parent) { IO_OR_GS_CODE(); =20 - if (bdrv_parent_drained_poll(bs, ignore_parent, ignore_bds_parents)) { + if (bdrv_parent_drained_poll(bs, ignore_parent)) { return true; } =20 @@ -258,16 +253,9 @@ bool bdrv_drain_poll(BlockDriverState *bs, BdrvChild *= ignore_parent, return false; } =20 -static bool bdrv_drain_poll_top_level(BlockDriverState *bs, - BdrvChild *ignore_parent) -{ - return bdrv_drain_poll(bs, ignore_parent, false); -} - static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent, - bool ignore_bds_parents, bool poll); -static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent, - bool ignore_bds_parents); + bool poll); +static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent); =20 static void bdrv_co_drain_bh_cb(void *opaque) { @@ -280,11 +268,10 @@ static void bdrv_co_drain_bh_cb(void *opaque) aio_context_acquire(ctx); bdrv_dec_in_flight(bs); if (data->begin) { - bdrv_do_drained_begin(bs, data->parent, data->ignore_bds_paren= ts, - data->poll); + bdrv_do_drained_begin(bs, data->parent, data->poll); } else { assert(!data->poll); - bdrv_do_drained_end(bs, data->parent, data->ignore_bds_parents= ); + bdrv_do_drained_end(bs, data->parent); } aio_context_release(ctx); } else { @@ -299,7 +286,6 @@ static void bdrv_co_drain_bh_cb(void *opaque) static void coroutine_fn bdrv_co_yield_to_drain(BlockDriverState *bs, bool begin, BdrvChild *parent, - bool ignore_bds_parents, bool poll) { BdrvCoDrainData data; @@ -317,7 +303,6 @@ static void coroutine_fn bdrv_co_yield_to_drain(BlockDr= iverState *bs, .done =3D false, .begin =3D begin, .parent =3D parent, - .ignore_bds_parents =3D ignore_bds_parents, .poll =3D poll, }; =20 @@ -349,17 +334,14 @@ static void coroutine_fn bdrv_co_yield_to_drain(Block= DriverState *bs, } } =20 -void bdrv_do_drained_begin_quiesce(BlockDriverState *bs, - BdrvChild *parent, bool ignore_bds_pare= nts) +void bdrv_do_drained_begin_quiesce(BlockDriverState *bs, BdrvChild *parent) { IO_OR_GS_CODE(); =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)); - - /* TODO Remove ignore_bds_parents, we don't consider it any more */ - bdrv_parent_drained_begin(bs, parent, false); + bdrv_parent_drained_begin(bs, parent); if (bs->drv && bs->drv->bdrv_drain_begin) { bs->drv->bdrv_drain_begin(bs); } @@ -367,14 +349,14 @@ void bdrv_do_drained_begin_quiesce(BlockDriverState *= bs, } =20 static void bdrv_do_drained_begin(BlockDriverState *bs, BdrvChild *parent, - bool ignore_bds_parents, bool poll) + bool poll) { if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(bs, true, parent, ignore_bds_parents, poll); + bdrv_co_yield_to_drain(bs, true, parent, poll); return; } =20 - bdrv_do_drained_begin_quiesce(bs, parent, ignore_bds_parents); + bdrv_do_drained_begin_quiesce(bs, parent); =20 /* * Wait for drained requests to finish. @@ -386,28 +368,26 @@ static void bdrv_do_drained_begin(BlockDriverState *b= s, BdrvChild *parent, * nodes. */ if (poll) { - assert(!ignore_bds_parents); - BDRV_POLL_WHILE(bs, bdrv_drain_poll_top_level(bs, parent)); + BDRV_POLL_WHILE(bs, bdrv_drain_poll(bs, parent)); } } =20 void bdrv_drained_begin(BlockDriverState *bs) { IO_OR_GS_CODE(); - bdrv_do_drained_begin(bs, NULL, false, true); + bdrv_do_drained_begin(bs, NULL, true); } =20 /** * This function does not poll, nor must any of its recursively called * functions. */ -static void bdrv_do_drained_end(BlockDriverState *bs, BdrvChild *parent, - bool ignore_bds_parents) +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, ignore_bds_parents, fals= e); + bdrv_co_yield_to_drain(bs, false, parent, false); return; } assert(bs->quiesce_counter > 0); @@ -418,9 +398,7 @@ static void bdrv_do_drained_end(BlockDriverState *bs, B= drvChild *parent, if (bs->drv && bs->drv->bdrv_drain_end) { bs->drv->bdrv_drain_end(bs); } - /* TODO Remove ignore_bds_parents, we don't consider it any more */ - bdrv_parent_drained_end(bs, parent, false); - + bdrv_parent_drained_end(bs, parent); aio_enable_external(bdrv_get_aio_context(bs)); } } @@ -428,7 +406,7 @@ static void bdrv_do_drained_end(BlockDriverState *bs, B= drvChild *parent, void bdrv_drained_end(BlockDriverState *bs) { IO_OR_GS_CODE(); - bdrv_do_drained_end(bs, NULL, false); + bdrv_do_drained_end(bs, NULL); } =20 void bdrv_drain(BlockDriverState *bs) @@ -461,7 +439,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, NULL); aio_context_release(aio_context); } =20 @@ -486,7 +464,7 @@ void bdrv_drain_all_begin(void) GLOBAL_STATE_CODE(); =20 if (qemu_in_coroutine()) { - bdrv_co_yield_to_drain(NULL, true, NULL, true, true); + bdrv_co_yield_to_drain(NULL, true, NULL, true); return; } =20 @@ -511,7 +489,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, true, false); + bdrv_do_drained_begin(bs, NULL, false); aio_context_release(aio_context); } =20 @@ -531,7 +509,7 @@ void bdrv_drain_all_end_quiesce(BlockDriverState *bs) g_assert(!bs->refcnt); =20 while (bs->quiesce_counter) { - bdrv_do_drained_end(bs, NULL, true); + bdrv_do_drained_end(bs, NULL); } } =20 @@ -553,7 +531,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, true); + bdrv_do_drained_end(bs, NULL); aio_context_release(aio_context); } =20 --=20 2.38.1 From nobody Tue May 7 21:17:12 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=1667911452; cv=none; d=zohomail.com; s=zohoarc; b=nLOAmZvGffrgnSKPr92nwUl2TyNFH+RPSLW9Dr31sYDsP3ycD+QkbhO1QT5YhOQTG0yM/GqI/jhWOND9Nx2b7+pQwvovf95SrwaO9B17M8wiSCnPgg+o+greYmkNY/kj6aFPUWPOnDrfG+goQK/aRVVm7ZmaH6Zk37ZGbohIzq4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667911452; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=yjuET9HJG9ScGKWOrNVDYGN8n+xDQgxMJi2xcyZvQqU=; b=DJa5UHzzAHLks7zKsL8ZDGnG/KhSou2d/4HcehI26vfHmmqf9bQxucBqQof4gtCmLa4J75u5N1+GVNi3KvnZY8/QzNe2L1KcGKXhvpI0Mw5I7M6zdq9qTfXAeYNEXfNd2+wFqSCKcQC8PrvdqAGdV1Mb75BxATrel3N5sllvNR4= 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 1667911452792219.59611827271146; Tue, 8 Nov 2022 04:44:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osNsT-0008UK-2G; Tue, 08 Nov 2022 07:38: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 1osNrz-0007tI-6W for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:24 -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 1osNrp-0001Rp-Ih for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:22 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-357-6Z2pHzPDMHWLuNxe2LljJA-1; Tue, 08 Nov 2022 07:38:09 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 58922811E81; Tue, 8 Nov 2022 12:38:09 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 39A299E70; Tue, 8 Nov 2022 12:38:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667911092; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yjuET9HJG9ScGKWOrNVDYGN8n+xDQgxMJi2xcyZvQqU=; b=Np4NwvCR9zmbm6lZRKHu3F5eblLmz/fcCzA9eYCbZ4Jhxvx0QftT1ysz9IMeJAu1uoVku1 OYVXD5yEkwIdMla5Wr5JO0l5OOzOfyNzfIaSroH/fgOYn1tZ8+wK82tfV7nwO0FUy8gx4l reRiU8tbzvmJyXmDugcMmhkhCpTR5sY= X-MC-Unique: 6Z2pHzPDMHWLuNxe2LljJA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eesposit@redhat.com, stefanha@redhat.com, hreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 12/13] block: Don't poll in bdrv_replace_child_noperm() Date: Tue, 8 Nov 2022 13:37:37 +0100 Message-Id: <20221108123738.530873-13-kwolf@redhat.com> In-Reply-To: <20221108123738.530873-1-kwolf@redhat.com> References: <20221108123738.530873-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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: 1667911454072100001 Content-Type: text/plain; charset="utf-8" In order to make sure that bdrv_replace_child_noperm() doesn't have to poll any more, get rid of the bdrv_parent_drained_begin_single() call. This is possible now because we can require that the child is already drained when the function is called (it better be, having in-flight requests while modifying the graph isn't going to end well!) and we don't call the parent drain callbacks more than once. The additional drain calls needed in callers cause the test case to run its code in the drain handler too early (bdrv_attach_child() drains now), so modify it to only enable the code after the test setup has completed. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi --- include/block/block-io.h | 8 ++++ block.c | 72 +++++++++++++++++++++++++----------- block/io.c | 2 +- tests/unit/test-bdrv-drain.c | 10 +++++ 4 files changed, 70 insertions(+), 22 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 5b54ed4672..ddce8550a9 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -290,6 +290,14 @@ 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/block.c b/block.c index 5f5f79cd16..12039e9b8a 100644 --- a/block.c +++ b/block.c @@ -2399,6 +2399,20 @@ 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->parent_quiesce_counter); bdrv_replace_child_noperm(s->child, s->old_bs); bdrv_unref(new_bs); } @@ -2414,12 +2428,20 @@ static TransactionActionDrv bdrv_replace_child_drv = =3D { * * Note: real unref of old_bs is done only on commit. * + * Both child and new_bs (if non-NULL) must be drained. new_bs must be kept + * drained until the transaction is completed (this automatically implies = that + * child remains drained, too). + * * 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->parent_quiesce_counter); + assert(!new_bs || new_bs->quiesce_counter); + *s =3D (BdrvReplaceChildState) { .child =3D child, .old_bs =3D child->bs, @@ -2818,6 +2840,12 @@ static void bdrv_replace_child_noperm(BdrvChild *chi= ld, int new_bs_quiesce_counter; =20 assert(!child->frozen); + /* + * When removing the child, it's the callers responsibility to make su= re + * that no requests are in flight any more. Usually the parent is drai= ned, + * but not through child->parent_quiesce_counter. + */ + assert(!new_bs || child->parent_quiesce_counter); assert(old_bs !=3D new_bs); GLOBAL_STATE_CODE(); =20 @@ -2825,16 +2853,6 @@ 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 - new_bs_quiesce_counter =3D (new_bs ? new_bs->quiesce_counter : 0); - - /* - * If the new child node is drained but the old one was not, flush - * all outstanding requests to the old child node. - */ - if (new_bs_quiesce_counter && !child->parent_quiesce_counter) { - bdrv_parent_drained_begin_single(child, true); - } - if (old_bs) { if (child->klass->detach) { child->klass->detach(child); @@ -2849,14 +2867,6 @@ static void bdrv_replace_child_noperm(BdrvChild *chi= ld, assert_bdrv_graph_writable(new_bs); QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); =20 - /* - * Polling in bdrv_parent_drained_begin_single() may have led to t= he new - * node's quiesce_counter having been decreased. Not a problem, w= e just - * need to recognize this here and then invoke drained_end appropr= iately - * more often. - */ - assert(new_bs->quiesce_counter <=3D new_bs_quiesce_counter); - if (child->klass->attach) { child->klass->attach(child); } @@ -2865,9 +2875,6 @@ static void bdrv_replace_child_noperm(BdrvChild *chil= d, /* * 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->parent_quiesce_counter) { @@ -3004,6 +3011,12 @@ static BdrvChild *bdrv_attach_child_common(BlockDriv= erState *child_bs, } =20 bdrv_ref(child_bs); + /* + * Let every new BdrvChild start drained, inserting it in the graph wi= th + * bdrv_replace_child_noperm() will undrain it if the child node is not + * drained. The child was only just created, so polling is not necessa= ry. + */ + bdrv_parent_drained_begin_single(new_child, false); bdrv_replace_child_noperm(new_child, child_bs); =20 BdrvAttachChildCommonState *s =3D g_new(BdrvAttachChildCommonState, 1); @@ -5053,7 +5066,10 @@ static void bdrv_remove_child(BdrvChild *child, Tran= saction *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); @@ -5070,6 +5086,15 @@ static void bdrv_remove_filter_or_cow_child(BlockDri= verState *bs, bdrv_remove_child(bdrv_filter_or_cow_child(bs), tran); } =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, @@ -5079,6 +5104,11 @@ 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 4a83359a8f..d0f641926f 100644 --- a/block/io.c +++ b/block/io.c @@ -80,7 +80,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); diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 172bc6debc..2686a8acee 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -1654,6 +1654,7 @@ static void test_drop_intermediate_poll(void) =20 =20 typedef struct BDRVReplaceTestState { + bool setup_completed; bool was_drained; bool was_undrained; bool has_read; @@ -1738,6 +1739,10 @@ 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); @@ -1769,6 +1774,10 @@ 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; @@ -1867,6 +1876,7 @@ 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 Tue May 7 21:17:12 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=1667912014; cv=none; d=zohomail.com; s=zohoarc; b=SEc/mSbL5aP9qc+pUMX6pXYTVYsWkKIEGTGxuvSj+BKcy/P9YTwFBZCGV5jyNvBWDbKtF9yFoWJ0x1AA0QvVdGXFxC0qAGYsS+zFj45bdGcR2v5stMXv8wDJ6AyiH4KiRQ8XEElmHSKAE5GNMQcZJ8xlEu9IQeQ4+PWzU5rvUTM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1667912014; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=J5AvUSk33icUn6VLINECmBDRqlVEXNjmiajH7cm7YfA=; b=Z/KKN+CO1pe2GvPRJDWeSTOkimfv/vuqIN2mE5uAH67J9Vw5D/xSP/tcIAZ32cHF4I/mpzV7pscwesGV12ulWY1lDOS8sWcg2Xds0NPCto6rtF62xpyicsNJ7snYbU5RdtTsRVYOrKsyshLys3TeqhKWxEHREusQfGAUpNxeLnE= 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 1667912014886833.0168475185807; Tue, 8 Nov 2022 04:53:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1osNsO-0008Or-FA; Tue, 08 Nov 2022 07:38: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 1osNs0-0007uu-JP for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:25 -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 1osNrr-0001XX-Th for qemu-devel@nongnu.org; Tue, 08 Nov 2022 07:38:24 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-515-zneTLLdwPRql8HqzNSq3dA-1; Tue, 08 Nov 2022 07:38:11 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C3D7A1C07557; Tue, 8 Nov 2022 12:38:10 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.118]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9155210197; Tue, 8 Nov 2022 12:38:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667911094; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J5AvUSk33icUn6VLINECmBDRqlVEXNjmiajH7cm7YfA=; b=HdxESQ743KJrJECj8MwtFnfn9sqKKbKiWgqxKYvQHiLmmTPRYUpFY/8uzTBXClcktG0sqs yprQNrluuOhBsSHdZpotWpGmjWsmlO/10bP5l0j4ovia3SXeYFqaUH5kC5Ej7/HowbxXZ0 gwcBSVQSvwcY/88xjNjGY6du6JasOLc= X-MC-Unique: zneTLLdwPRql8HqzNSq3dA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, eesposit@redhat.com, stefanha@redhat.com, hreitz@redhat.com, pbonzini@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 13/13] block: Remove poll parameter from bdrv_parent_drained_begin_single() Date: Tue, 8 Nov 2022 13:37:38 +0100 Message-Id: <20221108123738.530873-14-kwolf@redhat.com> In-Reply-To: <20221108123738.530873-1-kwolf@redhat.com> References: <20221108123738.530873-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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: 1667912015684100001 Content-Type: text/plain; charset="utf-8" All callers of bdrv_parent_drained_begin_single() pass poll=3Dfalse now, so we don't need the parameter any more. Signed-off-by: Kevin Wolf Acked-by: Stefan Hajnoczi Reviewed-by: Hanna Reitz --- include/block/block-io.h | 5 ++--- block.c | 4 ++-- block/io.c | 7 ++----- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index ddce8550a9..35669f0e62 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -285,10 +285,9 @@ bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector= *qiov, int64_t pos); /** * 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. + * Begin a quiesced section for the parent of @c. */ -void bdrv_parent_drained_begin_single(BdrvChild *c, bool poll); +void bdrv_parent_drained_begin_single(BdrvChild *c); =20 /** * bdrv_parent_drained_poll_single: diff --git a/block.c b/block.c index 12039e9b8a..c200f7afa0 100644 --- a/block.c +++ b/block.c @@ -2409,7 +2409,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, false); + bdrv_parent_drained_begin_single(s->child); assert(!bdrv_parent_drained_poll_single(s->child)); } assert(s->child->parent_quiesce_counter); @@ -3016,7 +3016,7 @@ static BdrvChild *bdrv_attach_child_common(BlockDrive= rState *child_bs, * bdrv_replace_child_noperm() will undrain it if the child node is not * drained. The child was only just created, so polling is not necessa= ry. */ - bdrv_parent_drained_begin_single(new_child, false); + bdrv_parent_drained_begin_single(new_child); 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 d0f641926f..9bcb19e5ee 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 @@ -103,7 +103,7 @@ 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) { IO_OR_GS_CODE(); assert(c->parent_quiesce_counter =3D=3D 0); @@ -111,9 +111,6 @@ void bdrv_parent_drained_begin_single(BdrvChild *c, boo= l poll) if (c->klass->drained_begin) { c->klass->drained_begin(c); } - if (poll) { - BDRV_POLL_WHILE(c->bs, bdrv_parent_drained_poll_single(c)); - } } =20 static void bdrv_merge_limits(BlockLimits *dst, const BlockLimits *src) --=20 2.38.1