From patchwork Tue Jul 12 21:19:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1655638 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Vsq6jX38; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LjDDb4kdKz9s09 for ; Wed, 13 Jul 2022 07:20:14 +1000 (AEST) Received: from localhost ([::1]:50586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNIg-0001la-DC for incoming@patchwork.ozlabs.org; Tue, 12 Jul 2022 17:20:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHv-0001jJ-EE for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:21606) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHr-0002Gj-RM for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660758; 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=CwFlJAPVPl7sXnM2XXETPNJr8tA5re5ZBNuQxF0Xujg=; b=Vsq6jX38NNjjSk/8OdKnYZICSaYWJtWilD5tiYUw4nYbYd72dDcbwvrY5uva5MnZ9DDDHn m9kuLaj8C6w8feAmDpCXq5gUyI2RihpOcwEcKSrktmi2OSP21gltoVrXOI7V1qh4z74EXR w6a0704Tq/VL/8VwiKwgbIHmq7oR3yk= 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-655-mSsKEi9kO9mPUutM8hbhog-1; Tue, 12 Jul 2022 17:19:17 -0400 X-MC-Unique: mSsKEi9kO9mPUutM8hbhog-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 85E0485A585; Tue, 12 Jul 2022 21:19:16 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 764672166B30; Tue, 12 Jul 2022 21:19:15 +0000 (UTC) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 1/8] block.c: assert bs->aio_context is written under BQL and drains Date: Tue, 12 Jul 2022 17:19:04 -0400 Message-Id: <20220712211911.1302836-2-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Also here ->aio_context is read by I/O threads and written under BQL. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Hanna Reitz --- block.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block.c b/block.c index d0db104d71..267a39c0de 100644 --- a/block.c +++ b/block.c @@ -7285,6 +7285,7 @@ static void bdrv_detach_aio_context(BlockDriverState *bs) if (bs->quiesce_counter) { aio_enable_external(bs->aio_context); } + assert_bdrv_graph_writable(bs); bs->aio_context = NULL; } @@ -7298,6 +7299,7 @@ static void bdrv_attach_aio_context(BlockDriverState *bs, aio_disable_external(new_context); } + assert_bdrv_graph_writable(bs); bs->aio_context = new_context; if (bs->drv && bs->drv->bdrv_attach_aio_context) { From patchwork Tue Jul 12 21:19:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1655640 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DQkr4dwR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LjDDn0cwYz9s09 for ; Wed, 13 Jul 2022 07:20:25 +1000 (AEST) Received: from localhost ([::1]:50590 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNIs-0001m6-Ah for incoming@patchwork.ozlabs.org; Tue, 12 Jul 2022 17:20:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHv-0001kI-MF for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:54546) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHs-0002Gp-Fc for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660759; 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=xamwRQcHxp0nHCghcr5xA3P05s95yhuo/GJ5eC+ybY4=; b=DQkr4dwR5PXKtwTcy7mfNA8k5vcUfTptOpAG2yzIVt8oQDlAGYvBedsJhiATjC9wyuI6D4 iP0lTu8kscI3tt0Xhka+9prUWz+jwU6+38KVj7vZOO2gU+TQ33EcnTBofRUI63cTzwVznP /x8dxsX6mdNeM8KEAZTGZHHUyNHVHG0= 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-91-QUwRMY_6P2-4i11lsLqDgw-1; Tue, 12 Jul 2022 17:19:17 -0400 X-MC-Unique: QUwRMY_6P2-4i11lsLqDgw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DEF67294EDC5; Tue, 12 Jul 2022 21:19:16 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id F29AE2166B2F; Tue, 12 Jul 2022 21:19:15 +0000 (UTC) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 2/8] transactions: add tran_add_back Date: Tue, 12 Jul 2022 17:19:05 -0400 Message-Id: <20220712211911.1302836-3-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" First change the transactions from a QLIST to QSIMPLEQ, then use it to implement tran_add_tail, which allows adding elements to the end of list transactions. This is useful if we have some "preparation" transiction callbacks that we want to run before the others but still only when invoking finalize/commit/abort. For example (A and B are lists transaction callbacks): for (i=0; i < 3; i++) { tran_add(A[i]); tran_add_tail(B[i]); } tran_commit(); Will process transactions in this order: A2 - A1 - A0 - B0 - B1 - B2 Signed-off-by: Emanuele Giuseppe Esposito --- include/qemu/transactions.h | 9 +++++++++ util/transactions.c | 29 +++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/include/qemu/transactions.h b/include/qemu/transactions.h index 2f2060acd9..42783720b9 100644 --- a/include/qemu/transactions.h +++ b/include/qemu/transactions.h @@ -50,7 +50,16 @@ typedef struct TransactionActionDrv { typedef struct Transaction Transaction; Transaction *tran_new(void); +/* + * Add transaction at the beginning of the transaction list. + * @tran will be the first transaction to be processed in finalize/commit/abort. + */ void tran_add(Transaction *tran, TransactionActionDrv *drv, void *opaque); +/* + * Add transaction at the end of the transaction list. + * @tran will be the last transaction to be processed in finalize/commit/abort. + */ +void tran_add_tail(Transaction *tran, TransactionActionDrv *drv, void *opaque); void tran_abort(Transaction *tran); void tran_commit(Transaction *tran); diff --git a/util/transactions.c b/util/transactions.c index 2dbdedce95..89e541c4a4 100644 --- a/util/transactions.c +++ b/util/transactions.c @@ -28,18 +28,18 @@ typedef struct TransactionAction { TransactionActionDrv *drv; void *opaque; - QSLIST_ENTRY(TransactionAction) entry; + QSIMPLEQ_ENTRY(TransactionAction) entry; } TransactionAction; struct Transaction { - QSLIST_HEAD(, TransactionAction) actions; + QSIMPLEQ_HEAD(, TransactionAction) actions; }; Transaction *tran_new(void) { Transaction *tran = g_new(Transaction, 1); - QSLIST_INIT(&tran->actions); + QSIMPLEQ_INIT(&tran->actions); return tran; } @@ -54,20 +54,33 @@ void tran_add(Transaction *tran, TransactionActionDrv *drv, void *opaque) .opaque = opaque }; - QSLIST_INSERT_HEAD(&tran->actions, act, entry); + QSIMPLEQ_INSERT_HEAD(&tran->actions, act, entry); +} + +void tran_add_tail(Transaction *tran, TransactionActionDrv *drv, void *opaque) +{ + TransactionAction *act; + + act = g_new(TransactionAction, 1); + *act = (TransactionAction) { + .drv = drv, + .opaque = opaque + }; + + QSIMPLEQ_INSERT_TAIL(&tran->actions, act, entry); } void tran_abort(Transaction *tran) { TransactionAction *act, *next; - QSLIST_FOREACH(act, &tran->actions, entry) { + QSIMPLEQ_FOREACH(act, &tran->actions, entry) { if (act->drv->abort) { act->drv->abort(act->opaque); } } - QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) { + QSIMPLEQ_FOREACH_SAFE(act, &tran->actions, entry, next) { if (act->drv->clean) { act->drv->clean(act->opaque); } @@ -82,13 +95,13 @@ void tran_commit(Transaction *tran) { TransactionAction *act, *next; - QSLIST_FOREACH(act, &tran->actions, entry) { + QSIMPLEQ_FOREACH(act, &tran->actions, entry) { if (act->drv->commit) { act->drv->commit(act->opaque); } } - QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) { + QSIMPLEQ_FOREACH_SAFE(act, &tran->actions, entry, next) { if (act->drv->clean) { act->drv->clean(act->opaque); } From patchwork Tue Jul 12 21:19:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1655646 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Rl0pX8Ls; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LjDP10S7Bz9s09 for ; Wed, 13 Jul 2022 07:27:33 +1000 (AEST) Received: from localhost ([::1]:39376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNPm-0005V5-Ss for incoming@patchwork.ozlabs.org; Tue, 12 Jul 2022 17:27:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNIL-0002uv-9g for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28452) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNI0-0002Ls-7B for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660767; 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=WWecrIp5grNRw02rHzhY/pOKGKu5Ck6LqGuw+60u3jA=; b=Rl0pX8LsUJvykHXhlbyRh+UfrE2wMh/ZU656NaMnGD1SMz/Ss2kWUXgx2CxzXM8V2V6q0q 5EO0u9G7UOyRcdaIeESv2R+q8ELCY+NObu3jY078khCWjSRsnIeoacjJTlh7Yf+d7Iun5P /fcXXFYuAWWvCUUQ+cPdxCyCAdvK/QI= 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-bpfnTv5-P6ek1aI8kEkeXQ-1; Tue, 12 Jul 2022 17:19:18 -0400 X-MC-Unique: bpfnTv5-P6ek1aI8kEkeXQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AF930101A595; Tue, 12 Jul 2022 21:19:17 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA3582166B2A; Tue, 12 Jul 2022 21:19:16 +0000 (UTC) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 3/8] RFC: block: use transactions as a replacement of ->{can_}set_aio_context() Date: Tue, 12 Jul 2022 17:19:06 -0400 Message-Id: <20220712211911.1302836-4-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" --------- RFC because I am not sure about the AioContext locks. - Do we need to take the new AioContext lock? what does it protect? - Taking the old AioContext lock is required now, because of bdrv_drained_begin calling AIO_WAIT_WHILE that unlocks the aiocontext. If we replace it with AIO_WAIT_WHILE_UNLOCKED, could we get rid of taking every time the old AioContext? drain would be enough to protect the graph modification. ---------- Simplify the way the aiocontext can be changed in a BDS graph. There are currently two problems in bdrv_try_set_aio_context: - There is a confusion of AioContext locks taken and released, because we assume that old aiocontext is always taken and new one is taken inside. - It doesn't look very safe to call bdrv_drained_begin while some nodes have already switched to the new aiocontext and others haven't. This could be especially dangerous because bdrv_drained_begin polls, so something else could be executed while graph is in an inconsistent state. Additional minor nitpick: can_set and set_ callbacks both traverse the graph, both using the ignored list of visited nodes in a different way. Therefore, get rid of all of this and introduce a new callback, change_aio_context, that uses transactions to efficiently, cleanly and most importantly safely change the aiocontext of a graph. This new callback is a "merge" of the two previous ones: - Just like can_set_aio_context, recursively traverses the graph. Marks all nodes that are visited using a GList, and checks if they *could* change the aio_context. - For each node that passes the above check, add a new transaction that implements a callback that effectively changes the aiocontext. - If a node is a BDS, add two transactions: one taking care of draining the node at the beginning of the list (so that will be executed first) and one at the end taking care of changing the AioContext. - Once done, the recursive function returns if *all* nodes can change the AioContext. If so, commit the above transactions. Otherwise don't do anything. - The transaction list contains first all "drain" transactions, so we are sure we are draining all nodes in the same context, and then all the other switch the AioContext. In this way we make sure that bdrv_drained_begin() is always called under the old AioContext, and bdrv_drained_end() under the new one. - Because of the above, we don't need to release and re-acquire the old AioContext every time, as everything is done once (and not per-node drain and aiocontext change). Note that the "change" API is not yet invoked anywhere. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 197 +++++++++++++++++++++++++++++ include/block/block-global-state.h | 9 ++ include/block/block_int-common.h | 3 + 3 files changed, 209 insertions(+) diff --git a/block.c b/block.c index 267a39c0de..bda4e1bcef 100644 --- a/block.c +++ b/block.c @@ -7437,6 +7437,51 @@ static bool bdrv_parent_can_set_aio_context(BdrvChild *c, AioContext *ctx, return true; } +typedef struct BdrvStateSetAioContext { + AioContext *new_ctx; + BlockDriverState *bs; +} BdrvStateSetAioContext; + +/* + * Changes the AioContext used for fd handlers, timers, and BHs by this + * BlockDriverState and all its children and parents. + * + * Must be called from the main AioContext. + * + * The caller must own the AioContext lock for the old AioContext of bs, but it + * must not own the AioContext lock for new_context (unless new_context is the + * same as the current context of bs). + * + * @visited will accumulate all visited BdrvChild object. The caller is + * responsible for freeing the list afterwards. + */ +static bool bdrv_parent_change_aio_context(BdrvChild *c, AioContext *ctx, + GSList **visited, Transaction *tran, + Error **errp) +{ + GLOBAL_STATE_CODE(); + if (g_slist_find(*visited, c)) { + return true; + } + *visited = g_slist_prepend(*visited, c); + + /* + * A BdrvChildClass that doesn't handle AioContext changes cannot + * tolerate any AioContext changes + */ + if (!c->klass->change_aio_ctx) { + char *user = bdrv_child_user_desc(c); + error_setg(errp, "Changing iothreads is not supported by %s", user); + g_free(user); + return false; + } + if (!c->klass->change_aio_ctx(c, ctx, visited, tran, errp)) { + assert(!errp || *errp); + return false; + } + return true; +} + bool bdrv_child_can_set_aio_context(BdrvChild *c, AioContext *ctx, GSList **ignore, Error **errp) { @@ -7448,6 +7493,18 @@ bool bdrv_child_can_set_aio_context(BdrvChild *c, AioContext *ctx, return bdrv_can_set_aio_context(c->bs, ctx, ignore, errp); } +bool bdrv_child_change_aio_context(BdrvChild *c, AioContext *ctx, + GSList **visited, Transaction *tran, + Error **errp) +{ + GLOBAL_STATE_CODE(); + if (g_slist_find(*visited, c)) { + return true; + } + *visited = g_slist_prepend(*visited, c); + return bdrv_change_aio_context(c->bs, ctx, visited, tran, errp); +} + /* @ignore will accumulate all visited BdrvChild object. The caller is * responsible for freeing the list afterwards. */ bool bdrv_can_set_aio_context(BlockDriverState *bs, AioContext *ctx, @@ -7475,6 +7532,99 @@ bool bdrv_can_set_aio_context(BlockDriverState *bs, AioContext *ctx, return true; } +static void bdrv_drained_begin_commit(void *opaque) +{ + BdrvStateSetAioContext *state = (BdrvStateSetAioContext *) opaque; + + /* Paired with bdrv_drained_end in bdrv_drained_end_clean() */ + bdrv_drained_begin(state->bs); +} + +static void bdrv_drained_end_clean(void *opaque) +{ + BdrvStateSetAioContext *state = (BdrvStateSetAioContext *) opaque; + BlockDriverState *bs = (BlockDriverState *) state->bs; + AioContext *new_context = state->new_ctx; + + /* + * drain only if bdrv_drained_begin_commit() and + * bdrv_set_aio_context_commit() executed + */ + if (bdrv_get_aio_context(bs) == new_context) { + /* Paired with bdrv_drained_begin in bdrv_drained_begin_commit() */ + bdrv_drained_end(bs); + } + + /* state is freed by set_aio_context->clean() */ +} + +static void bdrv_set_aio_context_commit(void *opaque) +{ + BdrvStateSetAioContext *state = (BdrvStateSetAioContext *) opaque; + BlockDriverState *bs = (BlockDriverState *) state->bs; + AioContext *new_context = state->new_ctx; + assert_bdrv_graph_writable(bs); + + bdrv_detach_aio_context(bs); + bdrv_attach_aio_context(bs, new_context); +} + +static TransactionActionDrv set_aio_context = { + .commit = bdrv_set_aio_context_commit, + .clean = g_free, +}; + +static TransactionActionDrv drained_begin_end = { + .commit = bdrv_drained_begin_commit, + .clean = bdrv_drained_end_clean, +}; + +/* + * @visited will accumulate all visited BdrvChild object. The caller is + * responsible for freeing the list afterwards. + */ +bool bdrv_change_aio_context(BlockDriverState *bs, AioContext *ctx, + GSList **visited, Transaction *tran, + Error **errp) +{ + BdrvChild *c; + BdrvStateSetAioContext *state; + + GLOBAL_STATE_CODE(); + + if (bdrv_get_aio_context(bs) == ctx) { + return true; + } + + QLIST_FOREACH(c, &bs->parents, next_parent) { + if (!bdrv_parent_change_aio_context(c, ctx, visited, tran, errp)) { + return false; + } + } + + QLIST_FOREACH(c, &bs->children, next) { + if (!bdrv_child_change_aio_context(c, ctx, visited, tran, errp)) { + return false; + } + } + + state = g_new(BdrvStateSetAioContext, 1); + *state = (BdrvStateSetAioContext) { + .new_ctx = ctx, + .bs = bs, + }; + + /* First half of transactions are drains */ + tran_add(tran, &drained_begin_end, state); + /* + * Second half of transactions takes care of setting the + * AioContext and free the state + */ + tran_add_tail(tran, &set_aio_context, state); + + return true; +} + int bdrv_child_try_set_aio_context(BlockDriverState *bs, AioContext *ctx, BdrvChild *ignore_child, Error **errp) { @@ -7498,6 +7648,53 @@ int bdrv_child_try_set_aio_context(BlockDriverState *bs, AioContext *ctx, return 0; } +/* + * First, go recursively through all nodes in the graph, and see if they + * can change their AioContext. + * If so, add for each node a new transaction with a callback to change the + * AioContext with the new one. + * Once recursion is completed, if all nodes are allowed to change their + * AioContext then commit the transaction, running all callbacks in order. + * Otherwise don't do anything. + * + * This function still requires the caller to take the bs current + * AioContext lock, otherwise draining could fail since AIO_WAIT_WHILE + * assumes the lock is always held if bs is in another AioContext. + */ +int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ctx, + BdrvChild *ignore_child, Error **errp) +{ + Transaction *tran; + GSList *visited; + int ret; + GLOBAL_STATE_CODE(); + + tran = tran_new(); + visited = ignore_child ? g_slist_prepend(NULL, ignore_child) : NULL; + ret = bdrv_change_aio_context(bs, ctx, &visited, tran, errp); + g_slist_free(visited); + + if (!ret) { + /* just run clean() callbacks */ + tran_abort(tran); + return -EPERM; + } + + /* Acquire the new context, if necessary */ + /* TODO: why do we need to take this AioContext lock? */ + if (qemu_get_aio_context() != ctx) { + aio_context_acquire(ctx); + } + + tran_commit(tran); + + if (qemu_get_aio_context() != ctx) { + aio_context_release(ctx); + } + + return 0; +} + int bdrv_try_set_aio_context(BlockDriverState *bs, AioContext *ctx, Error **errp) { diff --git a/include/block/block-global-state.h b/include/block/block-global-state.h index 21265e3966..5847b64f95 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -229,6 +229,15 @@ bool bdrv_can_set_aio_context(BlockDriverState *bs, AioContext *ctx, GSList **ignore, Error **errp); AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c); +bool bdrv_child_change_aio_context(BdrvChild *c, AioContext *ctx, + GSList **visited, Transaction *tran, + Error **errp); +bool bdrv_change_aio_context(BlockDriverState *bs, AioContext *ctx, + GSList **visited, Transaction *tran, + Error **errp); +int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ctx, + BdrvChild *ignore_child, Error **errp); + int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz); int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo); diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h index 8947abab76..b35a0fe840 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -896,6 +896,9 @@ struct BdrvChildClass { GSList **ignore, Error **errp); void (*set_aio_ctx)(BdrvChild *child, AioContext *ctx, GSList **ignore); + bool (*change_aio_ctx)(BdrvChild *child, AioContext *ctx, + GSList **ignore, Transaction *tran, Error **errp); + AioContext *(*get_parent_aio_context)(BdrvChild *child); /* From patchwork Tue Jul 12 21:19:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1655641 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ekH1TUA5; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LjDGv1jySz9s09 for ; Wed, 13 Jul 2022 07:22:15 +1000 (AEST) Received: from localhost ([::1]:57166 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNKf-0006Xk-3R for incoming@patchwork.ozlabs.org; Tue, 12 Jul 2022 17:22:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHw-0001l6-5d for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:41950) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHt-0002H8-3z for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660760; 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=56ZSNQhnjAShwuCvHPubrJxnlWw8xkVVKANfX2Rx2X8=; b=ekH1TUA5dHZ8JECbUd5CObHtAW6dz8oiRW/qwxgBbIhW+fpH9fPCQGx0T/rnjzvQzadQ1d CVEQxZOKElKd8NdRcYWF/Aqv7jJhz1AfQAL8b4oHDD9aMz3jFf9yndnLDyptD596pww2Lc 68ouwigQsHjZmM2ShNSN4GmHRICGPIs= 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-49-Cq2GA6iiOB-mvxj4Sp5GAQ-1; Tue, 12 Jul 2022 17:19:19 -0400 X-MC-Unique: Cq2GA6iiOB-mvxj4Sp5GAQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 82E55811E76; Tue, 12 Jul 2022 21:19:18 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F8B02166B30; Tue, 12 Jul 2022 21:19:17 +0000 (UTC) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 4/8] blockjob: implement .change_aio_ctx in child_job Date: Tue, 12 Jul 2022 17:19:07 -0400 Message-Id: <20220712211911.1302836-5-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" child_job_change_aio_ctx() is very similar to child_job_can_set_aio_ctx(), but it implements a new transaction so that if all check pass, the new transaction's .commit() will take care of changin the BlockJob AioContext. child_job_set_aio_ctx_commit() is similar to child_job_set_aio_ctx(), but it doesn't need to invoke the recursion, as this is already taken care by child_job_change_aio_ctx(). Note: bdrv_child_try_change_aio_context() is not called by anyone at this point. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Hanna Reitz --- blockjob.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/blockjob.c b/blockjob.c index bb82e8d04c..9e26b06ed4 100644 --- a/blockjob.c +++ b/blockjob.c @@ -124,6 +124,50 @@ static void child_job_drained_end(BdrvChild *c, int *drained_end_counter) } } +typedef struct BdrvStateChildJobContext { + AioContext *new_ctx; + BlockJob *job; +} BdrvStateChildJobContext; + +static void child_job_set_aio_ctx_commit(void *opaque) +{ + BdrvStateChildJobContext *s = opaque; + BlockJob *job = s->job; + + job_set_aio_context(&job->job, s->new_ctx); +} + +static TransactionActionDrv change_child_job_context = { + .commit = child_job_set_aio_ctx_commit, + .clean = g_free, +}; + +static bool child_job_change_aio_ctx(BdrvChild *c, AioContext *ctx, + GSList **visited, Transaction *tran, + Error **errp) +{ + BlockJob *job = c->opaque; + BdrvStateChildJobContext *s; + GSList *l; + + for (l = job->nodes; l; l = l->next) { + BdrvChild *sibling = l->data; + if (!bdrv_child_change_aio_context(sibling, ctx, visited, + tran, errp)) { + return false; + } + } + + s = g_new(BdrvStateChildJobContext, 1); + *s = (BdrvStateChildJobContext) { + .new_ctx = ctx, + .job = job, + }; + + tran_add_tail(tran, &change_child_job_context, s); + return true; +} + static bool child_job_can_set_aio_ctx(BdrvChild *c, AioContext *ctx, GSList **ignore, Error **errp) { @@ -172,6 +216,7 @@ static const BdrvChildClass child_job = { .drained_end = child_job_drained_end, .can_set_aio_ctx = child_job_can_set_aio_ctx, .set_aio_ctx = child_job_set_aio_ctx, + .change_aio_ctx = child_job_change_aio_ctx, .stay_at_node = true, .get_parent_aio_context = child_job_get_parent_aio_context, }; From patchwork Tue Jul 12 21:19:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1655642 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=EB3cGdp3; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LjDHP6Bkhz9s09 for ; Wed, 13 Jul 2022 07:22:41 +1000 (AEST) Received: from localhost ([::1]:57896 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNL5-00074x-OG for incoming@patchwork.ozlabs.org; Tue, 12 Jul 2022 17:22:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNII-0002um-Vf for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41950) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHw-0002JM-Rf for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660762; 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=vKwPjhdkN7wHkXjdTPsWAmHmdOEoydYRqskDnLyohWw=; b=EB3cGdp3LvqcxS30vrCPTwAzbssxL2tkE3xXLA/TZ4oQXiCiIvS3oMSLG+9bG7ma4G6vb2 Fz5qWrhFr5TbQ0R8Zt3YN0VKpWpcO3r7/Yl1OfFoCnZjXaY6HEXhPUjBivmLHsK5pvYeuN 5UmDSXPhMWS4lctTDiqvIyYCSVCNOcI= 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-90-Lk2Pw80dNp2KGk9g7-HMZw-1; Tue, 12 Jul 2022 17:19:19 -0400 X-MC-Unique: Lk2Pw80dNp2KGk9g7-HMZw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4B5BE38041DA; Tue, 12 Jul 2022 21:19:19 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 50A3A2166B2A; Tue, 12 Jul 2022 21:19:17 +0000 (UTC) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 5/8] block: implement .change_aio_ctx in child_of_bds Date: Tue, 12 Jul 2022 17:19:08 -0400 Message-Id: <20220712211911.1302836-6-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" bdrv_child_cb_change_aio_ctx() is identical to bdrv_child_cb_can_set_aio_ctx(), as we only need to recursively go on the parent bs. Note: bdrv_child_try_change_aio_context() is not called by anyone at this point. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Hanna Reitz --- block.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/block.c b/block.c index bda4e1bcef..a7ba590dfa 100644 --- a/block.c +++ b/block.c @@ -1235,6 +1235,14 @@ static int bdrv_child_cb_inactivate(BdrvChild *child) return 0; } +static bool bdrv_child_cb_change_aio_ctx(BdrvChild *child, AioContext *ctx, + GSList **visited, Transaction *tran, + Error **errp) +{ + BlockDriverState *bs = child->opaque; + return bdrv_change_aio_context(bs, ctx, visited, tran, errp); +} + static bool bdrv_child_cb_can_set_aio_ctx(BdrvChild *child, AioContext *ctx, GSList **ignore, Error **errp) { @@ -1491,6 +1499,7 @@ const BdrvChildClass child_of_bds = { .inactivate = bdrv_child_cb_inactivate, .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, .set_aio_ctx = bdrv_child_cb_set_aio_ctx, + .change_aio_ctx = bdrv_child_cb_change_aio_ctx, .update_filename = bdrv_child_cb_update_filename, .get_parent_aio_context = child_of_bds_get_parent_aio_context, }; From patchwork Tue Jul 12 21:19:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1655645 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ggvO/rtj; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LjDNX2m4Kz9s09 for ; Wed, 13 Jul 2022 07:27:07 +1000 (AEST) Received: from localhost ([::1]:38048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNPL-0004dK-Kj for incoming@patchwork.ozlabs.org; Tue, 12 Jul 2022 17:27:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNIM-0002wM-Fr for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56966) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNI2-0002Mp-7U for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660769; 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=NpvCvejhmqLiBfSx0m/ogEG5b5mXA0Q5Q2NrIbV4hTE=; b=ggvO/rtj7k4+jdS+7heJrakOIhRTWF6woa0DHSML1qElfGagj9tHCSSwEgI8P3bfyP/IPm 0CgtxXR2H/KEm6i64hE3Zmly98d8jA196Q79tQvwT2+K1+91IRSYbcdtm4g62XMIcgqIVQ tQXPGjUWOxP7iVJINWouXVyPi00aBKc= 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-rxJZJ1E3OnmQF2k_j_PVWg-1; Tue, 12 Jul 2022 17:19:20 -0400 X-MC-Unique: rxJZJ1E3OnmQF2k_j_PVWg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9E67C101A58E; Tue, 12 Jul 2022 21:19:19 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id BEA952166B2F; Tue, 12 Jul 2022 21:19:18 +0000 (UTC) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 6/8] block-backend: implement .change_aio_ctx in child_root Date: Tue, 12 Jul 2022 17:19:09 -0400 Message-Id: <20220712211911.1302836-7-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" blk_root_change_aio_ctx() is very similar to blk_root_can_set_aio_ctx(), but implements a new transaction so that if all check pass, the new transaction's .commit will take care of changing the BlockBackend AioContext. blk_root_set_aio_ctx_commit() is the same as blk_root_set_aio_ctx(). Note: bdrv_child_try_change_aio_context() is not called by anyone at this point. Signed-off-by: Emanuele Giuseppe Esposito --- block/block-backend.c | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index f425b00793..674eaaa2bf 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -138,6 +138,9 @@ static bool blk_root_can_set_aio_ctx(BdrvChild *child, AioContext *ctx, GSList **ignore, Error **errp); static void blk_root_set_aio_ctx(BdrvChild *child, AioContext *ctx, GSList **ignore); +static bool blk_root_change_aio_ctx(BdrvChild *child, AioContext *ctx, + GSList **visited, Transaction *tran, + Error **errp); static char *blk_root_get_parent_desc(BdrvChild *child) { @@ -336,6 +339,7 @@ static const BdrvChildClass child_root = { .can_set_aio_ctx = blk_root_can_set_aio_ctx, .set_aio_ctx = blk_root_set_aio_ctx, + .change_aio_ctx = blk_root_change_aio_ctx, .get_parent_aio_context = blk_root_get_parent_aio_context, }; @@ -2208,6 +2212,56 @@ int blk_set_aio_context(BlockBackend *blk, AioContext *new_context, return blk_do_set_aio_context(blk, new_context, true, errp); } +typedef struct BdrvStateBlkRootContext { + AioContext *new_ctx; + BlockBackend *blk; +} BdrvStateBlkRootContext; + +static void blk_root_set_aio_ctx_commit(void *opaque) +{ + BdrvStateBlkRootContext *s = opaque; + BlockBackend *blk = s->blk; + + blk_do_set_aio_context(blk, s->new_ctx, false, &error_abort); +} + +static TransactionActionDrv set_blk_root_context = { + .commit = blk_root_set_aio_ctx_commit, + .clean = g_free, +}; + +static bool blk_root_change_aio_ctx(BdrvChild *child, AioContext *ctx, + GSList **visited, Transaction *tran, + Error **errp) +{ + BlockBackend *blk = child->opaque; + BdrvStateBlkRootContext *s; + + if (blk->allow_aio_context_change) { + goto finish; + } + + /* + * Only manually created BlockBackends that are not attached to anything + * can change their AioContext without updating their user. + */ + if (!blk->name || blk->dev) { + /* TODO Add BB name/QOM path */ + error_setg(errp, "Cannot change iothread of active block backend"); + return false; + } + +finish: + s = g_new(BdrvStateBlkRootContext, 1); + *s = (BdrvStateBlkRootContext) { + .new_ctx = ctx, + .blk = blk, + }; + + tran_add_tail(tran, &set_blk_root_context, s); + return true; +} + static bool blk_root_can_set_aio_ctx(BdrvChild *child, AioContext *ctx, GSList **ignore, Error **errp) { From patchwork Tue Jul 12 21:19:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1655643 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=MyatZ7D9; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LjDKl6wBnz9s09 for ; Wed, 13 Jul 2022 07:24:43 +1000 (AEST) Received: from localhost ([::1]:33734 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNN3-0001cf-81 for incoming@patchwork.ozlabs.org; Tue, 12 Jul 2022 17:24:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNIJ-0002un-1D for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52828) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHw-0002J7-RZ for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660762; 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=KybLU9IwFgMw2xhqFt7O9/VvMxuZ2cPdo4RsO4G9iaw=; b=MyatZ7D9tD1w34B33n1yjJqPIc5VzRneKZFrANBvzP+o0GNpr5wJvhSJzucpDv7WOtFqwN rpkiM1iqt4w/pCjVIcsbnheuSul0gK3PxFX2Cbhd57uWGeXIDEK3db9tXoKsP3O/Y2R+2u mcPpOR6c12qSb3j9vuiLPXw8p3Jl0ao= 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-584-SXNDNXHzNwibxhZnZjmj1A-1; Tue, 12 Jul 2022 17:19:21 -0400 X-MC-Unique: SXNDNXHzNwibxhZnZjmj1A-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 76E341C05145; Tue, 12 Jul 2022 21:19:20 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 803482166B2A; Tue, 12 Jul 2022 21:19:19 +0000 (UTC) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 7/8] block: use the new _change_ API instead of _can_set_ and _set_ Date: Tue, 12 Jul 2022 17:19:10 -0400 Message-Id: <20220712211911.1302836-8-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Replace all direct usage of ->can_set_aio_ctx and ->set_aio_ctx, and call bdrv_child_try_change_aio_context() in bdrv_try_set_aio_context(), the main function called through the whole block layer. From this point onwards, ->can_set_aio_ctx and ->set_aio_ctx won't be used anymore. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 30 ++++++++++++++++-------------- block/block-backend.c | 8 ++++++-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/block.c b/block.c index a7ba590dfa..101188a2d4 100644 --- a/block.c +++ b/block.c @@ -2966,17 +2966,18 @@ static void bdrv_attach_child_common_abort(void *opaque) } if (bdrv_child_get_parent_aio_context(child) != s->old_parent_ctx) { + Transaction *tran; GSList *ignore; + bool ret; - /* No need to ignore `child`, because it has been detached already */ - ignore = NULL; - child->klass->can_set_aio_ctx(child, s->old_parent_ctx, &ignore, - &error_abort); - g_slist_free(ignore); + tran = tran_new(); + /* No need to ignore `child`, because it has been detached already */ ignore = NULL; - child->klass->set_aio_ctx(child, s->old_parent_ctx, &ignore); + ret = child->klass->change_aio_ctx(child, s->old_parent_ctx, &ignore, + tran, &error_abort); g_slist_free(ignore); + tran_finalize(tran, ret ? ret : -1); } bdrv_unref(bs); @@ -3037,17 +3038,18 @@ static int bdrv_attach_child_common(BlockDriverState *child_bs, Error *local_err = NULL; int ret = bdrv_try_set_aio_context(child_bs, parent_ctx, &local_err); - if (ret < 0 && child_class->can_set_aio_ctx) { + if (ret < 0 && child_class->change_aio_ctx) { + Transaction *tran = tran_new(); GSList *ignore = g_slist_prepend(NULL, new_child); - if (child_class->can_set_aio_ctx(new_child, child_ctx, &ignore, - NULL)) - { + bool ret_child; + + ret_child = child_class->change_aio_ctx(new_child, child_ctx, + &ignore, tran, NULL); + if (ret_child) { error_free(local_err); ret = 0; - g_slist_free(ignore); - ignore = g_slist_prepend(NULL, new_child); - child_class->set_aio_ctx(new_child, child_ctx, &ignore); } + tran_finalize(tran, ret_child ? ret_child : -1); g_slist_free(ignore); } @@ -7708,7 +7710,7 @@ int bdrv_try_set_aio_context(BlockDriverState *bs, AioContext *ctx, Error **errp) { GLOBAL_STATE_CODE(); - return bdrv_child_try_set_aio_context(bs, ctx, NULL, errp); + return bdrv_child_try_change_aio_context(bs, ctx, NULL, errp); } void bdrv_add_aio_context_notifier(BlockDriverState *bs, diff --git a/block/block-backend.c b/block/block-backend.c index 674eaaa2bf..6e90ac3a6a 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2184,8 +2184,12 @@ static int blk_do_set_aio_context(BlockBackend *blk, AioContext *new_context, bdrv_ref(bs); if (update_root_node) { - ret = bdrv_child_try_set_aio_context(bs, new_context, blk->root, - errp); + /* + * update_root_node MUST be false for blk_root_set_aio_ctx_commit(), + * as we are already in the commit function of a transaction. + */ + ret = bdrv_child_try_change_aio_context(bs, new_context, blk->root, + errp); if (ret < 0) { bdrv_unref(bs); return ret; From patchwork Tue Jul 12 21:19:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emanuele Giuseppe Esposito X-Patchwork-Id: 1655644 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DkoAZdCX; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LjDKz38Jnz9s09 for ; Wed, 13 Jul 2022 07:24:55 +1000 (AEST) Received: from localhost ([::1]:34302 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNNF-0001ze-2H for incoming@patchwork.ozlabs.org; Tue, 12 Jul 2022 17:24:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNIK-0002ut-PO for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:60985) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHx-0002L3-UT for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:48 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660765; 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=pePwG8ZwqKYsNfcZobAmGxdftqc/BwZCeZvQfQvX01I=; b=DkoAZdCXQIvkGXKrGcz22pnLqlumLMfrqAp9/5JRzH+5uriAQ/7rsNwkiiHH1eZ/2fwgEQ l1yeoCVh55i/kkvc6r27CLdNqgvim9luEcel4C93zZHnPics/q1hjbTZZtAMJWU3tjrSjG Ht3qsaYQw/+clx1/9wDpplCaskjFALU= 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-669-cBaNBE9pO5CTXScsY0LqWg-1; Tue, 12 Jul 2022 17:19:22 -0400 X-MC-Unique: cBaNBE9pO5CTXScsY0LqWg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 672D11857F07; Tue, 12 Jul 2022 21:19:21 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 514F22166B30; Tue, 12 Jul 2022 21:19:20 +0000 (UTC) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 8/8] block: remove all unused ->can_set_aio_ctx and ->set_aio_ctx callbacks Date: Tue, 12 Jul 2022 17:19:11 -0400 Message-Id: <20220712211911.1302836-9-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Together with all _can_set_ and _set_ APIs, as they are not needed anymore. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 196 ----------------------------- block/block-backend.c | 33 ----- blockjob.c | 35 ------ include/block/block-global-state.h | 9 -- include/block/block_int-common.h | 4 - 5 files changed, 277 deletions(-) diff --git a/block.c b/block.c index 101188a2d4..d99784dff1 100644 --- a/block.c +++ b/block.c @@ -1243,20 +1243,6 @@ static bool bdrv_child_cb_change_aio_ctx(BdrvChild *child, AioContext *ctx, return bdrv_change_aio_context(bs, ctx, visited, tran, errp); } -static bool bdrv_child_cb_can_set_aio_ctx(BdrvChild *child, AioContext *ctx, - GSList **ignore, Error **errp) -{ - BlockDriverState *bs = child->opaque; - return bdrv_can_set_aio_context(bs, ctx, ignore, errp); -} - -static void bdrv_child_cb_set_aio_ctx(BdrvChild *child, AioContext *ctx, - GSList **ignore) -{ - BlockDriverState *bs = child->opaque; - return bdrv_set_aio_context_ignore(bs, ctx, ignore); -} - /* * Returns the options and flags that a temporary snapshot should get, based on * the originally requested flags (the originally requested image will have @@ -1497,8 +1483,6 @@ const BdrvChildClass child_of_bds = { .attach = bdrv_child_cb_attach, .detach = bdrv_child_cb_detach, .inactivate = bdrv_child_cb_inactivate, - .can_set_aio_ctx = bdrv_child_cb_can_set_aio_ctx, - .set_aio_ctx = bdrv_child_cb_set_aio_ctx, .change_aio_ctx = bdrv_child_cb_change_aio_ctx, .update_filename = bdrv_child_cb_update_filename, .get_parent_aio_context = child_of_bds_get_parent_aio_context, @@ -7329,125 +7313,6 @@ static void bdrv_attach_aio_context(BlockDriverState *bs, bs->walking_aio_notifiers = false; } -/* - * Changes the AioContext used for fd handlers, timers, and BHs by this - * BlockDriverState and all its children and parents. - * - * Must be called from the main AioContext. - * - * The caller must own the AioContext lock for the old AioContext of bs, but it - * must not own the AioContext lock for new_context (unless new_context is the - * same as the current context of bs). - * - * @ignore will accumulate all visited BdrvChild object. The caller is - * responsible for freeing the list afterwards. - */ -void bdrv_set_aio_context_ignore(BlockDriverState *bs, - AioContext *new_context, GSList **ignore) -{ - AioContext *old_context = bdrv_get_aio_context(bs); - GSList *children_to_process = NULL; - GSList *parents_to_process = NULL; - GSList *entry; - BdrvChild *child, *parent; - - g_assert(qemu_get_current_aio_context() == qemu_get_aio_context()); - GLOBAL_STATE_CODE(); - - if (old_context == new_context) { - return; - } - - bdrv_drained_begin(bs); - - QLIST_FOREACH(child, &bs->children, next) { - if (g_slist_find(*ignore, child)) { - continue; - } - *ignore = g_slist_prepend(*ignore, child); - children_to_process = g_slist_prepend(children_to_process, child); - } - - QLIST_FOREACH(parent, &bs->parents, next_parent) { - if (g_slist_find(*ignore, parent)) { - continue; - } - *ignore = g_slist_prepend(*ignore, parent); - parents_to_process = g_slist_prepend(parents_to_process, parent); - } - - for (entry = children_to_process; - entry != NULL; - entry = g_slist_next(entry)) { - child = entry->data; - bdrv_set_aio_context_ignore(child->bs, new_context, ignore); - } - g_slist_free(children_to_process); - - for (entry = parents_to_process; - entry != NULL; - entry = g_slist_next(entry)) { - parent = entry->data; - assert(parent->klass->set_aio_ctx); - parent->klass->set_aio_ctx(parent, new_context, ignore); - } - g_slist_free(parents_to_process); - - bdrv_detach_aio_context(bs); - - /* Acquire the new context, if necessary */ - if (qemu_get_aio_context() != new_context) { - aio_context_acquire(new_context); - } - - bdrv_attach_aio_context(bs, new_context); - - /* - * If this function was recursively called from - * bdrv_set_aio_context_ignore(), there may be nodes in the - * subtree that have not yet been moved to the new AioContext. - * Release the old one so bdrv_drained_end() can poll them. - */ - if (qemu_get_aio_context() != old_context) { - aio_context_release(old_context); - } - - bdrv_drained_end(bs); - - if (qemu_get_aio_context() != old_context) { - aio_context_acquire(old_context); - } - if (qemu_get_aio_context() != new_context) { - aio_context_release(new_context); - } -} - -static bool bdrv_parent_can_set_aio_context(BdrvChild *c, AioContext *ctx, - GSList **ignore, Error **errp) -{ - GLOBAL_STATE_CODE(); - if (g_slist_find(*ignore, c)) { - return true; - } - *ignore = g_slist_prepend(*ignore, c); - - /* - * A BdrvChildClass that doesn't handle AioContext changes cannot - * tolerate any AioContext changes - */ - if (!c->klass->can_set_aio_ctx) { - char *user = bdrv_child_user_desc(c); - error_setg(errp, "Changing iothreads is not supported by %s", user); - g_free(user); - return false; - } - if (!c->klass->can_set_aio_ctx(c, ctx, ignore, errp)) { - assert(!errp || *errp); - return false; - } - return true; -} - typedef struct BdrvStateSetAioContext { AioContext *new_ctx; BlockDriverState *bs; @@ -7493,17 +7358,6 @@ static bool bdrv_parent_change_aio_context(BdrvChild *c, AioContext *ctx, return true; } -bool bdrv_child_can_set_aio_context(BdrvChild *c, AioContext *ctx, - GSList **ignore, Error **errp) -{ - GLOBAL_STATE_CODE(); - if (g_slist_find(*ignore, c)) { - return true; - } - *ignore = g_slist_prepend(*ignore, c); - return bdrv_can_set_aio_context(c->bs, ctx, ignore, errp); -} - bool bdrv_child_change_aio_context(BdrvChild *c, AioContext *ctx, GSList **visited, Transaction *tran, Error **errp) @@ -7516,33 +7370,6 @@ bool bdrv_child_change_aio_context(BdrvChild *c, AioContext *ctx, return bdrv_change_aio_context(c->bs, ctx, visited, tran, errp); } -/* @ignore will accumulate all visited BdrvChild object. The caller is - * responsible for freeing the list afterwards. */ -bool bdrv_can_set_aio_context(BlockDriverState *bs, AioContext *ctx, - GSList **ignore, Error **errp) -{ - BdrvChild *c; - - if (bdrv_get_aio_context(bs) == ctx) { - return true; - } - - GLOBAL_STATE_CODE(); - - QLIST_FOREACH(c, &bs->parents, next_parent) { - if (!bdrv_parent_can_set_aio_context(c, ctx, ignore, errp)) { - return false; - } - } - QLIST_FOREACH(c, &bs->children, next) { - if (!bdrv_child_can_set_aio_context(c, ctx, ignore, errp)) { - return false; - } - } - - return true; -} - static void bdrv_drained_begin_commit(void *opaque) { BdrvStateSetAioContext *state = (BdrvStateSetAioContext *) opaque; @@ -7636,29 +7463,6 @@ bool bdrv_change_aio_context(BlockDriverState *bs, AioContext *ctx, return true; } -int bdrv_child_try_set_aio_context(BlockDriverState *bs, AioContext *ctx, - BdrvChild *ignore_child, Error **errp) -{ - GSList *ignore; - bool ret; - - GLOBAL_STATE_CODE(); - - ignore = ignore_child ? g_slist_prepend(NULL, ignore_child) : NULL; - ret = bdrv_can_set_aio_context(bs, ctx, &ignore, errp); - g_slist_free(ignore); - - if (!ret) { - return -EPERM; - } - - ignore = ignore_child ? g_slist_prepend(NULL, ignore_child) : NULL; - bdrv_set_aio_context_ignore(bs, ctx, &ignore); - g_slist_free(ignore); - - return 0; -} - /* * First, go recursively through all nodes in the graph, and see if they * can change their AioContext. diff --git a/block/block-backend.c b/block/block-backend.c index 6e90ac3a6a..9925663ca1 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -134,10 +134,6 @@ static void blk_root_drained_end(BdrvChild *child, int *drained_end_counter); static void blk_root_change_media(BdrvChild *child, bool load); static void blk_root_resize(BdrvChild *child); -static bool blk_root_can_set_aio_ctx(BdrvChild *child, AioContext *ctx, - GSList **ignore, Error **errp); -static void blk_root_set_aio_ctx(BdrvChild *child, AioContext *ctx, - GSList **ignore); static bool blk_root_change_aio_ctx(BdrvChild *child, AioContext *ctx, GSList **visited, Transaction *tran, Error **errp); @@ -337,8 +333,6 @@ static const BdrvChildClass child_root = { .attach = blk_root_attach, .detach = blk_root_detach, - .can_set_aio_ctx = blk_root_can_set_aio_ctx, - .set_aio_ctx = blk_root_set_aio_ctx, .change_aio_ctx = blk_root_change_aio_ctx, .get_parent_aio_context = blk_root_get_parent_aio_context, @@ -2266,33 +2260,6 @@ finish: return true; } -static bool blk_root_can_set_aio_ctx(BdrvChild *child, AioContext *ctx, - GSList **ignore, Error **errp) -{ - BlockBackend *blk = child->opaque; - - if (blk->allow_aio_context_change) { - return true; - } - - /* Only manually created BlockBackends that are not attached to anything - * can change their AioContext without updating their user. */ - if (!blk->name || blk->dev) { - /* TODO Add BB name/QOM path */ - error_setg(errp, "Cannot change iothread of active block backend"); - return false; - } - - return true; -} - -static void blk_root_set_aio_ctx(BdrvChild *child, AioContext *ctx, - GSList **ignore) -{ - BlockBackend *blk = child->opaque; - blk_do_set_aio_context(blk, ctx, false, &error_abort); -} - void blk_add_aio_context_notifier(BlockBackend *blk, void (*attached_aio_context)(AioContext *new_context, void *opaque), void (*detach_aio_context)(void *opaque), void *opaque) diff --git a/blockjob.c b/blockjob.c index 9e26b06ed4..219a444108 100644 --- a/blockjob.c +++ b/blockjob.c @@ -168,39 +168,6 @@ static bool child_job_change_aio_ctx(BdrvChild *c, AioContext *ctx, return true; } -static bool child_job_can_set_aio_ctx(BdrvChild *c, AioContext *ctx, - GSList **ignore, Error **errp) -{ - BlockJob *job = c->opaque; - GSList *l; - - for (l = job->nodes; l; l = l->next) { - BdrvChild *sibling = l->data; - if (!bdrv_child_can_set_aio_context(sibling, ctx, ignore, errp)) { - return false; - } - } - return true; -} - -static void child_job_set_aio_ctx(BdrvChild *c, AioContext *ctx, - GSList **ignore) -{ - BlockJob *job = c->opaque; - GSList *l; - - for (l = job->nodes; l; l = l->next) { - BdrvChild *sibling = l->data; - if (g_slist_find(*ignore, sibling)) { - continue; - } - *ignore = g_slist_prepend(*ignore, sibling); - bdrv_set_aio_context_ignore(sibling->bs, ctx, ignore); - } - - job_set_aio_context(&job->job, ctx); -} - static AioContext *child_job_get_parent_aio_context(BdrvChild *c) { BlockJob *job = c->opaque; @@ -214,8 +181,6 @@ static const BdrvChildClass child_job = { .drained_begin = child_job_drained_begin, .drained_poll = child_job_drained_poll, .drained_end = child_job_drained_end, - .can_set_aio_ctx = child_job_can_set_aio_ctx, - .set_aio_ctx = child_job_set_aio_ctx, .change_aio_ctx = child_job_change_aio_ctx, .stay_at_node = true, .get_parent_aio_context = child_job_get_parent_aio_context, diff --git a/include/block/block-global-state.h b/include/block/block-global-state.h index 5847b64f95..65262781ab 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -217,18 +217,9 @@ void coroutine_fn bdrv_co_lock(BlockDriverState *bs); */ void coroutine_fn bdrv_co_unlock(BlockDriverState *bs); -void bdrv_set_aio_context_ignore(BlockDriverState *bs, - AioContext *new_context, GSList **ignore); int bdrv_try_set_aio_context(BlockDriverState *bs, AioContext *ctx, Error **errp); -int bdrv_child_try_set_aio_context(BlockDriverState *bs, AioContext *ctx, - BdrvChild *ignore_child, Error **errp); -bool bdrv_child_can_set_aio_context(BdrvChild *c, AioContext *ctx, - GSList **ignore, Error **errp); -bool bdrv_can_set_aio_context(BlockDriverState *bs, AioContext *ctx, - GSList **ignore, Error **errp); AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c); - bool bdrv_child_change_aio_context(BdrvChild *c, AioContext *ctx, GSList **visited, Transaction *tran, Error **errp); diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h index b35a0fe840..3c0e059602 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -892,10 +892,6 @@ struct BdrvChildClass { int (*update_filename)(BdrvChild *child, BlockDriverState *new_base, const char *filename, Error **errp); - bool (*can_set_aio_ctx)(BdrvChild *child, AioContext *ctx, - GSList **ignore, Error **errp); - void (*set_aio_ctx)(BdrvChild *child, AioContext *ctx, GSList **ignore); - bool (*change_aio_ctx)(BdrvChild *child, AioContext *ctx, GSList **ignore, Transaction *tran, Error **errp);