From nobody Thu May 16 11:13:54 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=1658752733; cv=none; d=zohomail.com; s=zohoarc; b=WzJW1HBgBt5P90OjVsxVOC32N/Dh5MZURmxUKr4J+dsdwyepm7dBfok8EzFy2nDX1sh5rrLYzx62EKEgIYD2qFT3B7LojOxpbgGeVNWDBhpHInpgFldd6Ag62bWGaRjyn/PE066QXSajYI7nXSKmltMM9CAGIG7n7ee9vyCLrHE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658752733; 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=f1IynO/DIKz5PQrjl6tEhXmKZBpuDkDzoYvqzGnYbhk=; b=EN75kDfYbY6WsS7EeI/tL3uXgoFz+tmx3hcYLliJoYEY/JNG6lMKEqSheU2qEwolBoDPSJV/9wg3ajdP+cgDlDcbsccXrsQbjXApXLfsrn8XUZelDFVa3jxC9+rh23Gu6xqt1HQTSddd16VbyG0TGVcsSdC+BCZ1rhMmcHraKxs= 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 1658752733555924.3094821000747; Mon, 25 Jul 2022 05:38:53 -0700 (PDT) Received: from localhost ([::1]:46400 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFxMI-0002QE-Te for importer@patchew.org; Mon, 25 Jul 2022 08:38:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48692) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5c-0002Yu-DM for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:22961) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5Y-00062e-QG for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:34 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-544-RdzDLaDHMR-csg0yLEZNIw-1; Mon, 25 Jul 2022 08:21:25 -0400 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 1D4D010AF82E; Mon, 25 Jul 2022 12:21:23 +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 CD46D9458A; Mon, 25 Jul 2022 12:21:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658751691; 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=f1IynO/DIKz5PQrjl6tEhXmKZBpuDkDzoYvqzGnYbhk=; b=GGOq+F8746zqjkBjVCXKLt5R95QOr6S7GpVDsHn64asIjskFLkViNDZd7cSudoeYm87LlI AMizI1JiAz0gkOcbkIUMrDsdnRtG3mEm/C0V0/lRoGjdfbeub6Hq3w29zQU++3Fo+Wgt2a X1gUrtEh314lMaS7KQIkBw7ZAKI/EE8= X-MC-Unique: RdzDLaDHMR-csg0yLEZNIw-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Paolo Bonzini , John Snow , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Stefan Hajnoczi , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v2 01/11] block.c: assert bs->aio_context is written under BQL and drains Date: Mon, 25 Jul 2022 08:21:10 -0400 Message-Id: <20220725122120.309236-2-eesposit@redhat.com> In-Reply-To: <20220725122120.309236-1-eesposit@redhat.com> References: <20220725122120.309236-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 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=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658752735186100001 Content-Type: text/plain; charset="utf-8" Also here ->aio_context is read by I/O threads and written under BQL. Reviewed-by: Hanna Reitz Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Suggested-by: Paolo Bonzini --- block.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block.c b/block.c index 7559965dbc..58a9cfc8b7 100644 --- a/block.c +++ b/block.c @@ -7282,6 +7282,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 =3D NULL; } =20 @@ -7295,6 +7296,7 @@ static void bdrv_attach_aio_context(BlockDriverState = *bs, aio_disable_external(new_context); } =20 + assert_bdrv_graph_writable(bs); bs->aio_context =3D new_context; =20 if (bs->drv && bs->drv->bdrv_attach_aio_context) { --=20 2.31.1 From nobody Thu May 16 11:13:54 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=1658752287; cv=none; d=zohomail.com; s=zohoarc; b=manqpmeA0RwQNyB6ZoDAmAXE7IaLxDET4skFeNg4Gpf1FvIbVnC/zkb9gPbDvn8pDiTkSYJ7JpTrcCR4EUyfdY5Nz4cxxQQg6Q9FyBrH9CnI4dtMKQ+peemGWoeM8dAZmdHS4CcsMj4fN80VQQn6w1yhgDgHslu8ICJwSlwp0FQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658752287; 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=oN5wWzOsRyt5FOcDC3/xM5sconI9JSHzEbmmUPdeX8c=; b=b1iScCaE8KyeDC2QVR6AJbVwOkKysjnov6d7mXJ6RKYYZo1dVsT+RDjuFkZRGysUICCVhWeE22PQmwLE2yeOWiSLyqG+kPLYN6Q6UozoyaAz5SjKGG8htW1GTrx+PAkmPd6SMtbBOVeluqXKLVshKoYvKoCZmDafk4vUjuG6+U8= 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 165875228781561.19477242741175; Mon, 25 Jul 2022 05:31:27 -0700 (PDT) Received: from localhost ([::1]:37264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFxF8-0003Vj-99 for importer@patchew.org; Mon, 25 Jul 2022 08:31:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5Z-0002Xc-Ez for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:23915) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5U-00061p-Ir for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:32 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-27-zOjS2PayPPOlF2sfl0KQuw-1; Mon, 25 Jul 2022 08:21:26 -0400 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 6D84E2999B2D; Mon, 25 Jul 2022 12:21:23 +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 251D9909FE; Mon, 25 Jul 2022 12:21:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658751688; 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=oN5wWzOsRyt5FOcDC3/xM5sconI9JSHzEbmmUPdeX8c=; b=EbNbV84FVxjagqIKL++VV5ziQOipajA76xCPjGSLD0dJe1BVg1BjbYrKu/viuD6w5qnVLw 15AUzR4pWsBRCO9fMtfbTa70Mi387HrNtpj0PjFrUCCOQhhIEcmdrHynbDmRBtz18dg1wY KqGGHpB99/znbCxkitAG5GGBRzD0G7I= X-MC-Unique: zOjS2PayPPOlF2sfl0KQuw-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Paolo Bonzini , John Snow , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Stefan Hajnoczi , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v2 02/11] block: use transactions as a replacement of ->{can_}set_aio_context() Date: Mon, 25 Jul 2022 08:21:11 -0400 Message-Id: <20220725122120.309236-3-eesposit@redhat.com> In-Reply-To: <20220725122120.309236-1-eesposit@redhat.com> References: <20220725122120.309236-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 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=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658752291433100002 Content-Type: text/plain; charset="utf-8" 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, drain it and add a new transac= tion that implements a callback that effectively changes the aiocontext. - Once done, the recursive function returns if *all* nodes can change the AioContext. If so, commit the above transactions. Regardless of the outcome, call transaction.clean() to undo all drains done in the recursion. - The transaction list is scanned only after all nodes are being drained, so we are sure that they all are in the same context, and then we switch their AioContext, concluding the drain only after all nodes switched to the new 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 Suggested-by: Paolo Bonzini --- block.c | 203 ++++++++++++++++++++++++++++- include/block/block-global-state.h | 6 + include/block/block_int-common.h | 3 + 3 files changed, 211 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 58a9cfc8b7..c80e49009a 100644 --- a/block.c +++ b/block.c @@ -108,6 +108,10 @@ static void bdrv_reopen_abort(BDRVReopenState *reopen_= state); =20 static bool bdrv_backing_overridden(BlockDriverState *bs); =20 +static bool bdrv_change_aio_context(BlockDriverState *bs, AioContext *ctx, + GSList **visited, Transaction *tran, + Error **errp); + /* If non-zero, use only whitelisted block drivers */ static int use_bdrv_whitelist; =20 @@ -7325,7 +7329,7 @@ static void bdrv_attach_aio_context(BlockDriverState = *bs, * 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 + * @ignore will accumulate all visited BdrvChild objects. The caller is * responsible for freeing the list afterwards. */ void bdrv_set_aio_context_ignore(BlockDriverState *bs, @@ -7434,6 +7438,38 @@ static bool bdrv_parent_can_set_aio_context(BdrvChil= d *c, AioContext *ctx, return true; } =20 +typedef struct BdrvStateSetAioContext { + AioContext *new_ctx; + BlockDriverState *bs; +} BdrvStateSetAioContext; + +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 =3D 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 =3D 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) { @@ -7445,6 +7481,18 @@ bool bdrv_child_can_set_aio_context(BdrvChild *c, Ai= oContext *ctx, return bdrv_can_set_aio_context(c->bs, ctx, ignore, errp); } =20 +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 =3D 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, @@ -7472,6 +7520,85 @@ bool bdrv_can_set_aio_context(BlockDriverState *bs, = AioContext *ctx, return true; } =20 +static void bdrv_drained_end_clean(void *opaque) +{ + BdrvStateSetAioContext *state =3D (BdrvStateSetAioContext *) opaque; + BlockDriverState *bs =3D (BlockDriverState *) state->bs; + + /* Paired with bdrv_drained_begin in bdrv_change_aio_context() */ + bdrv_drained_end(bs); + + g_free(state); +} + +static void bdrv_set_aio_context_commit(void *opaque) +{ + BdrvStateSetAioContext *state =3D (BdrvStateSetAioContext *) opaque; + BlockDriverState *bs =3D (BlockDriverState *) state->bs; + AioContext *new_context =3D 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 =3D { + .commit =3D bdrv_set_aio_context_commit, + .clean =3D bdrv_drained_end_clean, +}; + +/* + * 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, b= ut 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_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) =3D=3D 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 =3D g_new(BdrvStateSetAioContext, 1); + *state =3D (BdrvStateSetAioContext) { + .new_ctx =3D ctx, + .bs =3D bs, + }; + + /* Paired with bdrv_drained_end in bdrv_drained_end_clean() */ + bdrv_drained_begin(bs); + + tran_add(tran, &set_aio_context, state); + + return true; +} + int bdrv_child_try_set_aio_context(BlockDriverState *bs, AioContext *ctx, BdrvChild *ignore_child, Error **errp) { @@ -7495,6 +7622,80 @@ int bdrv_child_try_set_aio_context(BlockDriverState = *bs, AioContext *ctx, return 0; } =20 +/* + * Change bs's and recursively all of its parents' and children's AioConte= xt + * to the given new context, returning an error if that isn't possible. + * + * There are two phases: recursion check and linear change + * Recursion takes care of checking that all nodes support changing AioCon= text + * and drains them, builing a linear list of callbacks to run if it is + * successful (the transaction itself). + * Linear change consists in running all callbacks collected in the recurs= ion + * to switch all nodes AioContext lock (transaction commit). + * + * If ignore_child is not NULL, that child (and its subgraph) will not + * be touched. + * + * This function still requires the caller to take the bs current + * AioContext lock, otherwise draining will fail since AIO_WAIT_WHILE + * assumes the lock is always held if bs is in another AioContext. + * For the same reason, it temporarily holds also the new AioContext, since + * bdrv_drained_end calls BDRV_POLL_WHILE that assumes the lock is taken t= oo. + */ +int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ct= x, + BdrvChild *ignore_child, Error **err= p) +{ + Transaction *tran; + GSList *visited; + int ret; + AioContext *old_context =3D bdrv_get_aio_context(bs); + GLOBAL_STATE_CODE(); + + /* Recursion phase: go through all nodes of the graph */ + tran =3D tran_new(); + visited =3D ignore_child ? g_slist_prepend(NULL, ignore_child) : NULL; + ret =3D bdrv_change_aio_context(bs, ctx, &visited, tran, errp); + g_slist_free(visited); + + /* Linear phase: go through all callbacks collected in the transaction= */ + + if (!ret) { + /* Just run clean() callbacks. No AioContext changed. */ + tran_abort(tran); + return -EPERM; + } + + /* + * Release old AioContext, it won't be needed anymore, as all + * bdrv_drained_begin() have been called already. + */ + if (qemu_get_aio_context() !=3D old_context) { + aio_context_release(old_context); + } + + /* + * Acquire new AioContext since bdrv_drained_end() is going to be call= ed + * after we switched all nodes in the new AioContext, and the function + * assumes that the lock of the bs is always taken. + */ + if (qemu_get_aio_context() !=3D ctx) { + aio_context_acquire(ctx); + } + + tran_commit(tran); + + if (qemu_get_aio_context() !=3D ctx) { + aio_context_release(ctx); + } + + /* Re-acquire the old AioContext, since the caller takes and releases = it. */ + if (qemu_get_aio_context() !=3D old_context) { + aio_context_acquire(old_context); + } + + 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-globa= l-state.h index 21265e3966..fdcb81a175 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -229,6 +229,12 @@ bool bdrv_can_set_aio_context(BlockDriverState *bs, Ai= oContext *ctx, GSList **ignore, Error **errp); AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c); =20 +bool bdrv_child_change_aio_context(BdrvChild *c, AioContext *ctx, + GSList **visited, Transaction *tran, + Error **errp); +int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ct= x, + BdrvChild *ignore_child, Error **err= p); + int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz); int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo); =20 diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 8947abab76..43828cf74f 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= ); =20 + bool (*change_aio_ctx)(BdrvChild *child, AioContext *ctx, + GSList **visited, Transaction *tran, Error **er= rp); + AioContext *(*get_parent_aio_context)(BdrvChild *child); =20 /* --=20 2.31.1 From nobody Thu May 16 11:13:54 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=1658751856; cv=none; d=zohomail.com; s=zohoarc; b=Wd5Wm5aWyDN01QPqCUmFfI/6NMIU7vUe4ll1H9LDhiEruMil7ITJp5aqfJ/Sut/G8wd3k3RB/tAQtlBOzzS0rC1zC+2Clj3t9hwL8KqAO66li/QacUH5P/af1AzAFEtTnJe+oG/Qxp+fGueRRbE+c1i8xYIs+5pqFKBJ9D/G0Ps= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658751856; 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=xl16RQ27IbssBeTxi2z23S4vpV8WJZdQC/pP649MYjo=; b=Nv25dXRXuouqFNJaY/toHPSBFHqZYN+E1tZH7qVWPaSoG083TqHMnr4+r8grDlAzHhgyU8irjM0ozJkRqmIFOUlTElz6OX61DusingEnhhNkIVuVJ4H3zApbv1wGmGq4hSlhVAzDtXas3fGCoogxtC7p2IKS0ApV6QP2gTBRwmM= 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 1658751856016804.8035793352665; Mon, 25 Jul 2022 05:24:16 -0700 (PDT) Received: from localhost ([::1]:56260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFx89-0005Pu-Ba for importer@patchew.org; Mon, 25 Jul 2022 08:24:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5X-0002XV-SV for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:39497) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5U-00061a-0K for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:30 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-457-zw5qGrT8MPGuOR0wh5cT5Q-1; Mon, 25 Jul 2022 08:21:26 -0400 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 C44628853AB; Mon, 25 Jul 2022 12:21:23 +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 753E618EB5; Mon, 25 Jul 2022 12:21:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658751687; 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=xl16RQ27IbssBeTxi2z23S4vpV8WJZdQC/pP649MYjo=; b=gbUgGS0lYulxZj8dttigI2cBcbm7X/zCqixcE0Ng47fGYZ8JJQtM4yKoCtWLAEij6UMSAV EF5BN7WgzhP6ku72adczoeSx9u0G6yd1Dmz6f1lE68ohxf3A5DPWXggqTL7x0agAidANd0 oyTBhQHURt68TI1ey/TyZuR9H6SPEXQ= X-MC-Unique: zw5qGrT8MPGuOR0wh5cT5Q-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Paolo Bonzini , John Snow , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Stefan Hajnoczi , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v2 03/11] bdrv_change_aio_context: use hash table instead of list of visited nodes Date: Mon, 25 Jul 2022 08:21:12 -0400 Message-Id: <20220725122120.309236-4-eesposit@redhat.com> In-Reply-To: <20220725122120.309236-1-eesposit@redhat.com> References: <20220725122120.309236-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 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=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658751857820100001 Content-Type: text/plain; charset="utf-8" Minor performance improvement, but given that we have hash tables available, avoid iterating in the visited nodes list every time just to check if a node has been already visited. The data structure is not actually a proper hash map, but an hash set, as we are just adding nodes and not key,value pairs. Suggested-by: Hanna Reitz Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Suggested-by: Paolo Bonzini --- block.c | 28 ++++++++++++++++------------ include/block/block-global-state.h | 2 +- include/block/block_int-common.h | 3 ++- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/block.c b/block.c index c80e49009a..c02a628336 100644 --- a/block.c +++ b/block.c @@ -109,7 +109,7 @@ static void bdrv_reopen_abort(BDRVReopenState *reopen_s= tate); static bool bdrv_backing_overridden(BlockDriverState *bs); =20 static bool bdrv_change_aio_context(BlockDriverState *bs, AioContext *ctx, - GSList **visited, Transaction *tran, + GHashTable *visited, Transaction *tran, Error **errp); =20 /* If non-zero, use only whitelisted block drivers */ @@ -7444,14 +7444,15 @@ typedef struct BdrvStateSetAioContext { } BdrvStateSetAioContext; =20 static bool bdrv_parent_change_aio_context(BdrvChild *c, AioContext *ctx, - GSList **visited, Transaction *= tran, + GHashTable *visited, + Transaction *tran, Error **errp) { GLOBAL_STATE_CODE(); - if (g_slist_find(*visited, c)) { + if (g_hash_table_contains(visited, c)) { return true; } - *visited =3D g_slist_prepend(*visited, c); + g_hash_table_add(visited, c); =20 /* * A BdrvChildClass that doesn't handle AioContext changes cannot @@ -7482,14 +7483,14 @@ bool bdrv_child_can_set_aio_context(BdrvChild *c, A= ioContext *ctx, } =20 bool bdrv_child_change_aio_context(BdrvChild *c, AioContext *ctx, - GSList **visited, Transaction *tran, + GHashTable *visited, Transaction *tran, Error **errp) { GLOBAL_STATE_CODE(); - if (g_slist_find(*visited, c)) { + if (g_hash_table_contains(visited, c)) { return true; } - *visited =3D g_slist_prepend(*visited, c); + g_hash_table_add(visited, c); return bdrv_change_aio_context(c->bs, ctx, visited, tran, errp); } =20 @@ -7561,7 +7562,7 @@ static TransactionActionDrv set_aio_context =3D { * responsible for freeing the list afterwards. */ static bool bdrv_change_aio_context(BlockDriverState *bs, AioContext *ctx, - GSList **visited, Transaction *tran, + GHashTable *visited, Transaction *tran, Error **errp) { BdrvChild *c; @@ -7646,16 +7647,19 @@ int bdrv_child_try_change_aio_context(BlockDriverSt= ate *bs, AioContext *ctx, BdrvChild *ignore_child, Error **err= p) { Transaction *tran; - GSList *visited; + GHashTable *visited; int ret; AioContext *old_context =3D bdrv_get_aio_context(bs); GLOBAL_STATE_CODE(); =20 /* Recursion phase: go through all nodes of the graph */ tran =3D tran_new(); - visited =3D ignore_child ? g_slist_prepend(NULL, ignore_child) : NULL; - ret =3D bdrv_change_aio_context(bs, ctx, &visited, tran, errp); - g_slist_free(visited); + visited =3D g_hash_table_new(NULL, NULL); + if (ignore_child) { + g_hash_table_add(visited, ignore_child); + } + ret =3D bdrv_change_aio_context(bs, ctx, visited, tran, errp); + g_hash_table_destroy(visited); =20 /* Linear phase: go through all callbacks collected in the transaction= */ =20 diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index fdcb81a175..ceecf0aa8e 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -230,7 +230,7 @@ bool bdrv_can_set_aio_context(BlockDriverState *bs, Aio= Context *ctx, AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c); =20 bool bdrv_child_change_aio_context(BdrvChild *c, AioContext *ctx, - GSList **visited, Transaction *tran, + GHashTable *visited, Transaction *tran, Error **errp); int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ct= x, BdrvChild *ignore_child, Error **err= p); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 43828cf74f..c639873487 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -897,7 +897,8 @@ struct BdrvChildClass { void (*set_aio_ctx)(BdrvChild *child, AioContext *ctx, GSList **ignore= ); =20 bool (*change_aio_ctx)(BdrvChild *child, AioContext *ctx, - GSList **visited, Transaction *tran, Error **er= rp); + GHashTable *visited, Transaction *tran, + Error **errp); =20 AioContext *(*get_parent_aio_context)(BdrvChild *child); =20 --=20 2.31.1 From nobody Thu May 16 11:13:54 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=1658751865; cv=none; d=zohomail.com; s=zohoarc; b=ml/1EupUFjrZiNbGN1igGdLAWFWNoAdLJC2TLfRvQ29lDBQb3FFOuys58CzYB5PW2z/0BUXzCxPDm2AlysjtusdZi/GPUuSmUHTlosB6dlSqMPrgz7eFhOCg40z+XS7nanaVVc7GC5zgZvhwmvptqqabcrHTykDzG7Hr4j0bLww= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658751865; 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=Bx79kqpmq1a7uj5+8p7ruAYDnXjpbMAKJvdsMpPZ064=; b=gKFeGDcAbZUVpwny5SeeMn9htwfgJKSj2TcbT43GGVdW8OHn9B8KoxfomvBB3DRTiLRsh58YBTt5l4YSRRkTaz4ax9/KqfbO5uFBnpm2/c37mEQX3AgYmulC0DAaTne6Z+8gJwapDOmLdbA+/lFerULlgHwRFw2bL2XPiuNEDEw= 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 1658751865319306.9491635165473; Mon, 25 Jul 2022 05:24:25 -0700 (PDT) Received: from localhost ([::1]:57076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFx8K-0005yW-AQ for importer@patchew.org; Mon, 25 Jul 2022 08:24:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48606) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5Z-0002Xa-Cd for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:36237) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5U-00061m-GM for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:30 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-300-2peHmXULPDm9J2gnfzMv7A-1; Mon, 25 Jul 2022 08:21:26 -0400 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 3687318F0271; Mon, 25 Jul 2022 12:21:24 +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 CBB6218EB5; Mon, 25 Jul 2022 12:21:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658751688; 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=Bx79kqpmq1a7uj5+8p7ruAYDnXjpbMAKJvdsMpPZ064=; b=No8muXSsjlAXW2yusSNRgTppq7yzrJ9Y8PN5YRqauUlKQPqBN/E19epfUdG1x9XkxKHuPl roKYlyLDsIGYrluIjFWtuC47xrVLCja0fVhbHvKJT8wrQXzaoW9sgVWzn1akxft9sEJCGw 8162vDKcM01XbLFbwahcWjdRYEWw14c= X-MC-Unique: 2peHmXULPDm9J2gnfzMv7A-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Paolo Bonzini , John Snow , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Stefan Hajnoczi , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v2 04/11] bdrv_child_try_change_aio_context: add transaction parameter Date: Mon, 25 Jul 2022 08:21:13 -0400 Message-Id: <20220725122120.309236-5-eesposit@redhat.com> In-Reply-To: <20220725122120.309236-1-eesposit@redhat.com> References: <20220725122120.309236-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 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=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658751867867100001 Content-Type: text/plain; charset="utf-8" This enables the caller to use the same transaction to also keep track of aiocontext changes. Signed-off-by: Emanuele Giuseppe Esposito Suggested-by: Paolo Bonzini --- block.c | 31 ++++++++++++++++++++++++------ include/block/block-global-state.h | 5 +++++ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index c02a628336..221bf90268 100644 --- a/block.c +++ b/block.c @@ -7643,17 +7643,16 @@ int bdrv_child_try_set_aio_context(BlockDriverState= *bs, AioContext *ctx, * For the same reason, it temporarily holds also the new AioContext, since * bdrv_drained_end calls BDRV_POLL_WHILE that assumes the lock is taken t= oo. */ -int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ct= x, - BdrvChild *ignore_child, Error **err= p) +int bdrv_child_try_change_aio_context_tran(BlockDriverState *bs, + AioContext *ctx, + BdrvChild *ignore_child, + Transaction *tran, + Error **errp) { - Transaction *tran; GHashTable *visited; int ret; - AioContext *old_context =3D bdrv_get_aio_context(bs); GLOBAL_STATE_CODE(); =20 - /* Recursion phase: go through all nodes of the graph */ - tran =3D tran_new(); visited =3D g_hash_table_new(NULL, NULL); if (ignore_child) { g_hash_table_add(visited, ignore_child); @@ -7661,6 +7660,26 @@ int bdrv_child_try_change_aio_context(BlockDriverSta= te *bs, AioContext *ctx, ret =3D bdrv_change_aio_context(bs, ctx, visited, tran, errp); g_hash_table_destroy(visited); =20 + return ret; +} + +/* + * See bdrv_child_try_change_aio_context_tran for invariants on + * AioContext locks. + */ +int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ct= x, + BdrvChild *ignore_child, Error **err= p) +{ + Transaction *tran; + int ret; + AioContext *old_context =3D bdrv_get_aio_context(bs); + GLOBAL_STATE_CODE(); + + /* Recursion phase: go through all nodes of the graph */ + tran =3D tran_new(); + ret =3D bdrv_child_try_change_aio_context_tran(bs, ctx, ignore_child, = tran, + errp); + /* Linear phase: go through all callbacks collected in the transaction= */ =20 if (!ret) { diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index ceecf0aa8e..1bd445b507 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -234,6 +234,11 @@ bool bdrv_child_change_aio_context(BdrvChild *c, AioCo= ntext *ctx, Error **errp); int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ct= x, BdrvChild *ignore_child, Error **err= p); +int bdrv_child_try_change_aio_context_tran(BlockDriverState *bs, + AioContext *ctx, + BdrvChild *ignore_child, + Transaction *tran, + Error **errp); =20 int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz); int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo); --=20 2.31.1 From nobody Thu May 16 11:13:54 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=1658752283; cv=none; d=zohomail.com; s=zohoarc; b=HCT5NouQeBcxbyCMyH6pLDnKgHcSkv0yy3BJMuYp9ZkayeBTpVPudtSgoNWdl2cb66aRYC+MX0nxCgN3GBTR9dsfPY7HbZozj5nBhXcc3gdS/Em+hduDS0BtA4xRgA9eXV43IKek1JuLCmvY54io1EX09Q1j7ac0qaGL6G5SZN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658752283; 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=DAGUeXclJ6pUHUUdH773Td/+ts3heV5wZQx0iy+XGsg=; b=Nmczrsenm4c0HNQYPwje/cL54zfNFNQ3ZzGwG1CBv+1KKdIcMpc12J+qQ7APBg4z6lckm3szDhoqiCiIhXd0teRl/EmTJW0Rp7SqNGw/8EwdSmeu5jbKR+MhoPw3OMWspicp0PyH5YBj0Ra/Ei6CbxbbMPJPFyuK/JuX1PScZJU= 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 1658752283128540.3444626478694; Mon, 25 Jul 2022 05:31:23 -0700 (PDT) Received: from localhost ([::1]:37118 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFxF3-0003P5-LW for importer@patchew.org; Mon, 25 Jul 2022 08:31:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48608) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5Z-0002Xb-Ck for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:56364) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5U-00061w-Oz for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:32 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-133-Dyed4fYVPquo3oYHXqHDtA-1; Mon, 25 Jul 2022 08:21:26 -0400 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 7BB4619705A9; Mon, 25 Jul 2022 12:21:24 +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 35E8094642; Mon, 25 Jul 2022 12:21:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658751688; 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=DAGUeXclJ6pUHUUdH773Td/+ts3heV5wZQx0iy+XGsg=; b=BrCrQt2e/LcAxyqeop92t5dmo9bekbxGw9Gnw0IMDSIKJgf5fSK7VgRXK2kaiZRbeDqz1W vNtnmUXo6DUIXyA9zC4pQ/7H8HMeyw3B+lK91UMAQZo56xL697/bar8xqbqk/t6q1smu5J Ty5gEPlGL8GMP7IkIPb41dzQCU97nUE= X-MC-Unique: Dyed4fYVPquo3oYHXqHDtA-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Paolo Bonzini , John Snow , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Stefan Hajnoczi , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v2 05/11] blockjob: implement .change_aio_ctx in child_job Date: Mon, 25 Jul 2022 08:21:14 -0400 Message-Id: <20220725122120.309236-6-eesposit@redhat.com> In-Reply-To: <20220725122120.309236-1-eesposit@redhat.com> References: <20220725122120.309236-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 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=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658752285346100001 Content-Type: text/plain; charset="utf-8" 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. Reviewed-by: Hanna Reitz Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Suggested-by: Paolo Bonzini --- blockjob.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/blockjob.c b/blockjob.c index 375c90e4b8..704bab060f 100644 --- a/blockjob.c +++ b/blockjob.c @@ -126,6 +126,50 @@ static void child_job_drained_end(BdrvChild *c, int *d= rained_end_counter) job_resume(&job->job); } =20 +typedef struct BdrvStateChildJobContext { + AioContext *new_ctx; + BlockJob *job; +} BdrvStateChildJobContext; + +static void child_job_set_aio_ctx_commit(void *opaque) +{ + BdrvStateChildJobContext *s =3D opaque; + BlockJob *job =3D s->job; + + job_set_aio_context(&job->job, s->new_ctx); +} + +static TransactionActionDrv change_child_job_context =3D { + .commit =3D child_job_set_aio_ctx_commit, + .clean =3D g_free, +}; + +static bool child_job_change_aio_ctx(BdrvChild *c, AioContext *ctx, + GHashTable *visited, Transaction *tra= n, + Error **errp) +{ + BlockJob *job =3D c->opaque; + BdrvStateChildJobContext *s; + GSList *l; + + for (l =3D job->nodes; l; l =3D l->next) { + BdrvChild *sibling =3D l->data; + if (!bdrv_child_change_aio_context(sibling, ctx, visited, + tran, errp)) { + return false; + } + } + + s =3D g_new(BdrvStateChildJobContext, 1); + *s =3D (BdrvStateChildJobContext) { + .new_ctx =3D ctx, + .job =3D job, + }; + + tran_add(tran, &change_child_job_context, s); + return true; +} + static bool child_job_can_set_aio_ctx(BdrvChild *c, AioContext *ctx, GSList **ignore, Error **errp) { @@ -174,6 +218,7 @@ static const BdrvChildClass child_job =3D { .drained_end =3D child_job_drained_end, .can_set_aio_ctx =3D child_job_can_set_aio_ctx, .set_aio_ctx =3D child_job_set_aio_ctx, + .change_aio_ctx =3D child_job_change_aio_ctx, .stay_at_node =3D true, .get_parent_aio_context =3D child_job_get_parent_aio_context, }; --=20 2.31.1 From nobody Thu May 16 11:13:54 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=1658752290; cv=none; d=zohomail.com; s=zohoarc; b=lDUsTdgot/uQlUrAZC01LrqeGKVxjnYkD/NIkWvILpgSvxjBL4JtK18sF/H2R5DHzv8r0svn5LC6KM61CtvhJPc7zDcvh3UcOFveu5njD1aEUPiSs1kFPPVBqmqcFXHSPuMbadCwq2wOzbE7rkIJsyPhiE2DvEI5mLQh4gpdo9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658752290; 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=EEeBNZaq3ZiHcT6fAlUg9SzkwLF04CX/AvxtutJPL7A=; b=f9DR3lWFKovtso2wU/eDhD58IzH9FE8hWGL5vbsvxf53WXYkufpFResV4LN6ugFCzYaelvqDq4mQ238qAQZtlYYtfYIr6Qs6xJRXz6Z5Od+G2UyT+7ILGapVnJG+e7cfUA6SHu4o0V1n37wufdeSWMmAkTXngqp9jZBrejLsgqg= 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 165875229039856.350588501687525; Mon, 25 Jul 2022 05:31:30 -0700 (PDT) Received: from localhost ([::1]:37494 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFxFB-0003fM-4h for importer@patchew.org; Mon, 25 Jul 2022 08:31:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48640) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5Z-0002Xg-OW for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:33 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38697) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5W-00062B-CS for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:33 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-578-enH1YTHxPp2PLLFMJh1-DQ-1; Mon, 25 Jul 2022 08:21:27 -0400 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 C495919705C4; Mon, 25 Jul 2022 12:21:24 +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 8323A18EB5; Mon, 25 Jul 2022 12:21:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658751688; 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=EEeBNZaq3ZiHcT6fAlUg9SzkwLF04CX/AvxtutJPL7A=; b=HQCqqjBKbz9twtfDzcsnUXq1Q+5YFEOmi8VWEp1mWv+mm7F4QDagG8HkdyfQj5gWuktWeC WF79xs67R7U9v3Jb/094NZo2/sHKtXJzGkxW02t6GahJ5SIH7RoHH1hD4hkci52+2REkU7 QPAq/PL285NkEMGbMvzwoRfe+L0c6qE= X-MC-Unique: enH1YTHxPp2PLLFMJh1-DQ-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Paolo Bonzini , John Snow , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Stefan Hajnoczi , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v2 06/11] block: implement .change_aio_ctx in child_of_bds Date: Mon, 25 Jul 2022 08:21:15 -0400 Message-Id: <20220725122120.309236-7-eesposit@redhat.com> In-Reply-To: <20220725122120.309236-1-eesposit@redhat.com> References: <20220725122120.309236-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 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=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658752291405100001 Content-Type: text/plain; charset="utf-8" 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. Reviewed-by: Hanna Reitz Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Suggested-by: Paolo Bonzini --- block.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/block.c b/block.c index 221bf90268..bcc9b0d099 100644 --- a/block.c +++ b/block.c @@ -1239,6 +1239,14 @@ static int bdrv_child_cb_inactivate(BdrvChild *child) return 0; } =20 +static bool bdrv_child_cb_change_aio_ctx(BdrvChild *child, AioContext *ctx, + GHashTable *visited, Transaction = *tran, + Error **errp) +{ + BlockDriverState *bs =3D child->opaque; + return bdrv_change_aio_context(bs, ctx, visited, tran, errp); +} + static bool bdrv_child_cb_can_set_aio_ctx(BdrvChild *child, AioContext *ct= x, GSList **ignore, Error **errp) { @@ -1495,6 +1503,7 @@ const BdrvChildClass child_of_bds =3D { .inactivate =3D bdrv_child_cb_inactivate, .can_set_aio_ctx =3D bdrv_child_cb_can_set_aio_ctx, .set_aio_ctx =3D bdrv_child_cb_set_aio_ctx, + .change_aio_ctx =3D bdrv_child_cb_change_aio_ctx, .update_filename =3D bdrv_child_cb_update_filename, .get_parent_aio_context =3D child_of_bds_get_parent_aio_context, }; --=20 2.31.1 From nobody Thu May 16 11:13:54 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=1658751866; cv=none; d=zohomail.com; s=zohoarc; b=Ptex9OrSMp9dBy1/59Th4Wk3lDpYJxKavQxkXDW7Tm1qsfaOUI322W/EZToxewAoo9gHrycDdUnn20rJn2S6XO4IOKFjNrmlln0CeNEuiW9ns5V0NsZzyMwx3F3p4GM2vKchpURi2+x6wFVOaP5Gq8YEpXzfOM153x9JbDCWxi8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658751866; 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=ibePkfzDt/wBtcTJ6xHX6w7CbYK24Namjfp2PXdQc0k=; b=YCbupVI8J+mnrONQPoM0kdRBsEt7+JPi1lDkpHdcTIGzHK1m3caS9o7xO64Jy+K0Y6hmI3QUBdFt20gz+y4L7HyUtJgkF1f5JFuf1a+fPlkMaM4gHHPzW6ykw6Uc1mNF9kV0l5tRBc1t2CL+6QoQcWbVwR7jNtXiAJ3TW1YtbGY= 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 1658751866666735.8943481975751; Mon, 25 Jul 2022 05:24:26 -0700 (PDT) Received: from localhost ([::1]:57068 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFx8L-0005y9-Bs for importer@patchew.org; Mon, 25 Jul 2022 08:24:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5c-0002Yv-DJ for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:38 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:47322) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5Z-00062t-0o for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:34 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-644-9eFepM5zO3ma0__2V5EVvg-1; Mon, 25 Jul 2022 08:21:28 -0400 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 6437D1C05AAB; Mon, 25 Jul 2022 12:21:25 +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 CCB8518EB5; Mon, 25 Jul 2022 12:21:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658751691; 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=ibePkfzDt/wBtcTJ6xHX6w7CbYK24Namjfp2PXdQc0k=; b=HFGZNFeXvb6dWUd5i3xYaORMyf86JffqOL5kHaAb9EXd3tKJOWgiSpt3zNTq7bu+ZMKv4m ayxHe5pRE+bvmAgBJ4Ceb1fYJdTJmwQaCPkHIw6wPmPyOSWj8gqwyAoEpvNp2t9Bhu4W/u u6TvrPiBALfi2+XOyaGy8/eqXNzmUPM= X-MC-Unique: 9eFepM5zO3ma0__2V5EVvg-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Paolo Bonzini , John Snow , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Stefan Hajnoczi , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v2 07/11] block-backend: implement .change_aio_ctx in child_root Date: Mon, 25 Jul 2022 08:21:16 -0400 Message-Id: <20220725122120.309236-8-eesposit@redhat.com> In-Reply-To: <20220725122120.309236-1-eesposit@redhat.com> References: <20220725122120.309236-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 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=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658751868050100003 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Kevin Wolf Suggested-by: Paolo Bonzini --- block/block-backend.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index f425b00793..b4951c6e21 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, + GHashTable *visited, Transaction *tran, + Error **errp); =20 static char *blk_root_get_parent_desc(BdrvChild *child) { @@ -336,6 +339,7 @@ static const BdrvChildClass child_root =3D { =20 .can_set_aio_ctx =3D blk_root_can_set_aio_ctx, .set_aio_ctx =3D blk_root_set_aio_ctx, + .change_aio_ctx =3D blk_root_change_aio_ctx, =20 .get_parent_aio_context =3D blk_root_get_parent_aio_context, }; @@ -2208,6 +2212,54 @@ int blk_set_aio_context(BlockBackend *blk, AioContex= t *new_context, return blk_do_set_aio_context(blk, new_context, true, errp); } =20 +typedef struct BdrvStateBlkRootContext { + AioContext *new_ctx; + BlockBackend *blk; +} BdrvStateBlkRootContext; + +static void blk_root_set_aio_ctx_commit(void *opaque) +{ + BdrvStateBlkRootContext *s =3D opaque; + BlockBackend *blk =3D s->blk; + + blk_do_set_aio_context(blk, s->new_ctx, false, &error_abort); +} + +static TransactionActionDrv set_blk_root_context =3D { + .commit =3D blk_root_set_aio_ctx_commit, + .clean =3D g_free, +}; + +static bool blk_root_change_aio_ctx(BdrvChild *child, AioContext *ctx, + GHashTable *visited, Transaction *tran, + Error **errp) +{ + BlockBackend *blk =3D child->opaque; + BdrvStateBlkRootContext *s; + + if (!blk->allow_aio_context_change) { + /* + * Manually created BlockBackends (those with a name) that are not + * attached to anything can change their AioContext without updati= ng + * their user; return an error for others. + */ + if (!blk->name || blk->dev) { + /* TODO Add BB name/QOM path */ + error_setg(errp, "Cannot change iothread of active block backe= nd"); + return false; + } + } + + s =3D g_new(BdrvStateBlkRootContext, 1); + *s =3D (BdrvStateBlkRootContext) { + .new_ctx =3D ctx, + .blk =3D blk, + }; + + tran_add(tran, &set_blk_root_context, s); + return true; +} + static bool blk_root_can_set_aio_ctx(BdrvChild *child, AioContext *ctx, GSList **ignore, Error **errp) { --=20 2.31.1 From nobody Thu May 16 11:13:54 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=1658752748; cv=none; d=zohomail.com; s=zohoarc; b=Bnr07Igh56J7i4qL6eEhGDgIijHG5chVYiGh1/gxxYI4f5N6d412kmcKhqu5r7yUE+l8vL5wDI0Q5oYvjEXLO07LYQ5yEiSdFCNSP5NUPHpldlvyxlwI1uwBNOfjvh6/+h97cN83wsXNWcqlf9ZU7bgj0yIu6qrtxZEUwNSz+kI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658752748; 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=QZc/V6yFNZqX368tkz9lUtNf7KB1xzUrf6fToh59Kjs=; b=BmpAP1HgF5vzqOKe+ZaphbZB2sSulyDjcbmj+wU26KgLtvXkCSi+ybWYAZUSz+/3iTkqwZepVJp+uPfXdcebxgLBfGl7lBTQXAVm77/qSqnzD+MPiEgsvPQDRh7dqGobvJiE7scgSkERVPkMlzWmIWq9lcpmPjF4LHz0pF3l7Tw= 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 1658752748931931.5375171119274; Mon, 25 Jul 2022 05:39:08 -0700 (PDT) Received: from localhost ([::1]:47136 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFxMZ-00033K-OY for importer@patchew.org; Mon, 25 Jul 2022 08:39:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5g-0002aP-RG for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:54212) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5c-000643-Sm for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:39 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-648-wMcUrmYjOJu9oaJScKIWYg-1; Mon, 25 Jul 2022 08:21:30 -0400 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 BA2988C0803; Mon, 25 Jul 2022 12:21:25 +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 6BD45909FE; Mon, 25 Jul 2022 12:21:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658751694; 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=QZc/V6yFNZqX368tkz9lUtNf7KB1xzUrf6fToh59Kjs=; b=B5zQvR2Dbk0byMicvZ+3jAFdH3BpwQmmtcdlKhdaEjFPRC9WeCdFdOUX5x/V+FVPrYwLCx AFhoRJLnAPQfuHxPOZmVDHq/LCgiuCk33L3IVZCqQsWunLeZEndz07+JL5+RI81XYri3JE 2exrXMP3OCBEU6hcSvFClzH0nOeCLDo= X-MC-Unique: wMcUrmYjOJu9oaJScKIWYg-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Paolo Bonzini , John Snow , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Stefan Hajnoczi , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v2 08/11] block: use the new _change_ API instead of _can_set_ and _set_ Date: Mon, 25 Jul 2022 08:21:17 -0400 Message-Id: <20220725122120.309236-9-eesposit@redhat.com> In-Reply-To: <20220725122120.309236-1-eesposit@redhat.com> References: <20220725122120.309236-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 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=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658752751297100001 Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Kevin Wolf Suggested-by: Paolo Bonzini --- block.c | 44 ++++++++++++++++++++++++------------------- block/block-backend.c | 8 ++++++-- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/block.c b/block.c index bcc9b0d099..9b47aacad2 100644 --- a/block.c +++ b/block.c @@ -2970,17 +2970,21 @@ static void bdrv_attach_child_common_abort(void *op= aque) } =20 if (bdrv_child_get_parent_aio_context(child) !=3D s->old_parent_ctx) { - GSList *ignore; + Transaction *tran; + GHashTable *visited; + bool ret; =20 - /* No need to ignore `child`, because it has been detached already= */ - ignore =3D NULL; - child->klass->can_set_aio_ctx(child, s->old_parent_ctx, &ignore, - &error_abort); - g_slist_free(ignore); + tran =3D tran_new(); =20 - ignore =3D NULL; - child->klass->set_aio_ctx(child, s->old_parent_ctx, &ignore); - g_slist_free(ignore); + /* No need to visit `child`, because it has been detached already = */ + visited =3D g_hash_table_new(NULL, NULL); + ret =3D child->klass->change_aio_ctx(child, s->old_parent_ctx, vis= ited, + tran, &error_abort); + g_hash_table_destroy(visited); + + /* transaction is supposed to always succeed */ + assert(ret =3D=3D true); + tran_commit(tran); } =20 bdrv_unref(bs); @@ -3041,18 +3045,20 @@ static int bdrv_attach_child_common(BlockDriverStat= e *child_bs, Error *local_err =3D NULL; int ret =3D bdrv_try_set_aio_context(child_bs, parent_ctx, &local_= err); =20 - if (ret < 0 && child_class->can_set_aio_ctx) { - GSList *ignore =3D g_slist_prepend(NULL, new_child); - if (child_class->can_set_aio_ctx(new_child, child_ctx, &ignore, - NULL)) - { + if (ret < 0 && child_class->change_aio_ctx) { + Transaction *tran =3D tran_new(); + GHashTable *visited =3D g_hash_table_new(NULL, NULL); + bool ret_child; + + g_hash_table_add(visited, new_child); + ret_child =3D child_class->change_aio_ctx(new_child, child_ctx, + visited, tran, NULL); + if (ret_child =3D=3D true) { error_free(local_err); ret =3D 0; - g_slist_free(ignore); - ignore =3D g_slist_prepend(NULL, new_child); - child_class->set_aio_ctx(new_child, child_ctx, &ignore); } - g_slist_free(ignore); + tran_finalize(tran, ret_child =3D=3D true ? 0 : -1); + g_hash_table_destroy(visited); } =20 if (ret < 0) { @@ -7732,7 +7738,7 @@ int bdrv_try_set_aio_context(BlockDriverState *bs, Ai= oContext *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); } =20 void bdrv_add_aio_context_notifier(BlockDriverState *bs, diff --git a/block/block-backend.c b/block/block-backend.c index b4951c6e21..3046b4cc54 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); =20 if (update_root_node) { - ret =3D bdrv_child_try_set_aio_context(bs, new_context, blk->r= oot, - errp); + /* + * update_root_node MUST be false for blk_root_set_aio_ctx_com= mit(), + * as we are already in the commit function of a transaction. + */ + ret =3D bdrv_child_try_change_aio_context(bs, new_context, blk= ->root, + errp); if (ret < 0) { bdrv_unref(bs); return ret; --=20 2.31.1 From nobody Thu May 16 11:13:54 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=1658752299; cv=none; d=zohomail.com; s=zohoarc; b=Hkm59kajDG9kvSGwyPAJOriyVRYCm7X9+NLkb8gEbNaZ2Q6vG0XEE2c7of4OB/veOgyslauG6XOBcqqUys49oonh7ltlIbBx8k5/uvMdagVNswQnOipMPAhSecPAXNrsRaVJ6oI6ZPauiUFcL69bvXCuY4NvJUhklz60GHcIe5U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658752299; 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=aflsxyqV2PY2bBSJ3ntXY9CIh+jpY2Cxb5V1co3Ae1Y=; b=a9eFFypNTv0pYAakzgmdcLxGtsEYuy0rKAIE7JArVjrwOQwUdqXzuLOHbhJRh3E+XPh8yYMCd/6xc20toL1ZJtiG3OCRK0V6nt2jDaosIQwkZF4KD5b7Td5LJ6Wjpsvm2aZao4uJO5y7rkSD09ZKlCIj8ntcyfSm2ZUFgjVNc1Q= 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 1658752299973536.4803302142298; Mon, 25 Jul 2022 05:31:39 -0700 (PDT) Received: from localhost ([::1]:38020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFxFK-000415-T4 for importer@patchew.org; Mon, 25 Jul 2022 08:31:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48744) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5e-0002ZU-VU for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:38717) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5b-00063m-5j for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:38 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-226-oy-bLe0XMEWyC2eBfL57-w-1; Mon, 25 Jul 2022 08:21:28 -0400 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 36E2E85178C; Mon, 25 Jul 2022 12:21:26 +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 C17D090A00; Mon, 25 Jul 2022 12:21:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658751693; 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=aflsxyqV2PY2bBSJ3ntXY9CIh+jpY2Cxb5V1co3Ae1Y=; b=AxoEVgUh/GSAIBimW9CGBZCiVC9DYxrj66x8vOOdBzI/dPC+HmTtYE5P3/2D709UWWL6Os drwh0HdwzmP3ThQAxCslVRh7N/Yp6FojSr0VFLL4FzvLmR2aS8dXfRjbmq8RW3Ddn2IYA7 6DIa35BoKUVau2BQGuM3lEkbJFHKeks= X-MC-Unique: oy-bLe0XMEWyC2eBfL57-w-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Paolo Bonzini , John Snow , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Stefan Hajnoczi , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v2 09/11] block: remove all unused ->can_set_aio_ctx and ->set_aio_ctx callbacks Date: Mon, 25 Jul 2022 08:21:18 -0400 Message-Id: <20220725122120.309236-10-eesposit@redhat.com> In-Reply-To: <20220725122120.309236-1-eesposit@redhat.com> References: <20220725122120.309236-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 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=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658752301220100001 Content-Type: text/plain; charset="utf-8" Together with all _can_set_ and _set_ APIs, as they are not needed anymore. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Suggested-by: Paolo Bonzini --- 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 9b47aacad2..c066b41c8c 100644 --- a/block.c +++ b/block.c @@ -1247,20 +1247,6 @@ static bool bdrv_child_cb_change_aio_ctx(BdrvChild *= child, AioContext *ctx, return bdrv_change_aio_context(bs, ctx, visited, tran, errp); } =20 -static bool bdrv_child_cb_can_set_aio_ctx(BdrvChild *child, AioContext *ct= x, - GSList **ignore, Error **errp) -{ - BlockDriverState *bs =3D 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 =3D child->opaque; - return bdrv_set_aio_context_ignore(bs, ctx, ignore); -} - /* * Returns the options and flags that a temporary snapshot should get, bas= ed on * the originally requested flags (the originally requested image will have @@ -1501,8 +1487,6 @@ const BdrvChildClass child_of_bds =3D { .attach =3D bdrv_child_cb_attach, .detach =3D bdrv_child_cb_detach, .inactivate =3D bdrv_child_cb_inactivate, - .can_set_aio_ctx =3D bdrv_child_cb_can_set_aio_ctx, - .set_aio_ctx =3D bdrv_child_cb_set_aio_ctx, .change_aio_ctx =3D bdrv_child_cb_change_aio_ctx, .update_filename =3D bdrv_child_cb_update_filename, .get_parent_aio_context =3D child_of_bds_get_parent_aio_context, @@ -7334,125 +7318,6 @@ static void bdrv_attach_aio_context(BlockDriverStat= e *bs, bs->walking_aio_notifiers =3D false; } =20 -/* - * 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, b= ut 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 objects. 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 =3D bdrv_get_aio_context(bs); - GSList *children_to_process =3D NULL; - GSList *parents_to_process =3D NULL; - GSList *entry; - BdrvChild *child, *parent; - - g_assert(qemu_get_current_aio_context() =3D=3D qemu_get_aio_context()); - GLOBAL_STATE_CODE(); - - if (old_context =3D=3D new_context) { - return; - } - - bdrv_drained_begin(bs); - - QLIST_FOREACH(child, &bs->children, next) { - if (g_slist_find(*ignore, child)) { - continue; - } - *ignore =3D g_slist_prepend(*ignore, child); - children_to_process =3D g_slist_prepend(children_to_process, child= ); - } - - QLIST_FOREACH(parent, &bs->parents, next_parent) { - if (g_slist_find(*ignore, parent)) { - continue; - } - *ignore =3D g_slist_prepend(*ignore, parent); - parents_to_process =3D g_slist_prepend(parents_to_process, parent); - } - - for (entry =3D children_to_process; - entry !=3D NULL; - entry =3D g_slist_next(entry)) { - child =3D entry->data; - bdrv_set_aio_context_ignore(child->bs, new_context, ignore); - } - g_slist_free(children_to_process); - - for (entry =3D parents_to_process; - entry !=3D NULL; - entry =3D g_slist_next(entry)) { - parent =3D 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() !=3D 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() !=3D old_context) { - aio_context_release(old_context); - } - - bdrv_drained_end(bs); - - if (qemu_get_aio_context() !=3D old_context) { - aio_context_acquire(old_context); - } - if (qemu_get_aio_context() !=3D 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 =3D 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 =3D 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; @@ -7486,17 +7351,6 @@ static bool bdrv_parent_change_aio_context(BdrvChild= *c, AioContext *ctx, return true; } =20 -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 =3D 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, GHashTable *visited, Transaction *tran, Error **errp) @@ -7509,33 +7363,6 @@ bool bdrv_child_change_aio_context(BdrvChild *c, Aio= Context *ctx, return bdrv_change_aio_context(c->bs, ctx, visited, tran, errp); } =20 -/* @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) =3D=3D 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_end_clean(void *opaque) { BdrvStateSetAioContext *state =3D (BdrvStateSetAioContext *) opaque; @@ -7615,29 +7442,6 @@ static bool bdrv_change_aio_context(BlockDriverState= *bs, AioContext *ctx, return true; } =20 -int bdrv_child_try_set_aio_context(BlockDriverState *bs, AioContext *ctx, - BdrvChild *ignore_child, Error **errp) -{ - GSList *ignore; - bool ret; - - GLOBAL_STATE_CODE(); - - ignore =3D ignore_child ? g_slist_prepend(NULL, ignore_child) : NULL; - ret =3D bdrv_can_set_aio_context(bs, ctx, &ignore, errp); - g_slist_free(ignore); - - if (!ret) { - return -EPERM; - } - - ignore =3D ignore_child ? g_slist_prepend(NULL, ignore_child) : NULL; - bdrv_set_aio_context_ignore(bs, ctx, &ignore); - g_slist_free(ignore); - - return 0; -} - /* * Change bs's and recursively all of its parents' and children's AioConte= xt * to the given new context, returning an error if that isn't possible. diff --git a/block/block-backend.c b/block/block-backend.c index 3046b4cc54..a27b8b7a89 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); =20 -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, GHashTable *visited, Transaction *tran, Error **errp); @@ -337,8 +333,6 @@ static const BdrvChildClass child_root =3D { .attach =3D blk_root_attach, .detach =3D blk_root_detach, =20 - .can_set_aio_ctx =3D blk_root_can_set_aio_ctx, - .set_aio_ctx =3D blk_root_set_aio_ctx, .change_aio_ctx =3D blk_root_change_aio_ctx, =20 .get_parent_aio_context =3D blk_root_get_parent_aio_context, @@ -2264,33 +2258,6 @@ static bool blk_root_change_aio_ctx(BdrvChild *child= , AioContext *ctx, return true; } =20 -static bool blk_root_can_set_aio_ctx(BdrvChild *child, AioContext *ctx, - GSList **ignore, Error **errp) -{ - BlockBackend *blk =3D child->opaque; - - if (blk->allow_aio_context_change) { - return true; - } - - /* Only manually created BlockBackends that are not attached to anythi= ng - * 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 =3D 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 704bab060f..dadb2feca4 100644 --- a/blockjob.c +++ b/blockjob.c @@ -170,39 +170,6 @@ static bool child_job_change_aio_ctx(BdrvChild *c, Aio= Context *ctx, return true; } =20 -static bool child_job_can_set_aio_ctx(BdrvChild *c, AioContext *ctx, - GSList **ignore, Error **errp) -{ - BlockJob *job =3D c->opaque; - GSList *l; - - for (l =3D job->nodes; l; l =3D l->next) { - BdrvChild *sibling =3D 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 =3D c->opaque; - GSList *l; - - for (l =3D job->nodes; l; l =3D l->next) { - BdrvChild *sibling =3D l->data; - if (g_slist_find(*ignore, sibling)) { - continue; - } - *ignore =3D 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 =3D c->opaque; @@ -216,8 +183,6 @@ static const BdrvChildClass child_job =3D { .drained_begin =3D child_job_drained_begin, .drained_poll =3D child_job_drained_poll, .drained_end =3D child_job_drained_end, - .can_set_aio_ctx =3D child_job_can_set_aio_ctx, - .set_aio_ctx =3D child_job_set_aio_ctx, .change_aio_ctx =3D child_job_change_aio_ctx, .stay_at_node =3D true, .get_parent_aio_context =3D child_job_get_parent_aio_context, diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 1bd445b507..54fd008442 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); =20 -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, GHashTable *visited, Transaction *tran, Error **errp); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index c639873487..8f3102cc3d 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); =20 - 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, GHashTable *visited, Transaction *tran, Error **errp); --=20 2.31.1 From nobody Thu May 16 11:13:54 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=1658753014; cv=none; d=zohomail.com; s=zohoarc; b=E4CEWXda4lFfGbqyfFmLBNFA0OaQtYOtZKjuL9iwekjHwn4qa+x5UsXrHuZ+7em8+8Ks7th6R2FqgfIxUoDTg+xWKXo0pWbbkYP+kczDTZW1WKW+YSHtfV7x19iGUABWYjpokzlpXKTZgRu+OwTgOdfstsSU7s9QeZqH6071rRc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658753014; 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=rtAkzJgmgSvnZY++3nStSUz9Dq0gU/2gwy5wg4aQA/0=; b=aFJ/rnoYhqVR7a7ouobcCTFm+WooEfD+lYyCUnwv0vp81fqUYydVgDRV6fBXXHeEEcLzgybs5k1lydNXOd+WQbdIyM24HeB5bO+VV+nt2nwbcyyYvCL7ATP2De5xc0xQsJck+fhyFDqHC889X8DNbuYTYMSQjhtC9Rshb8RxWK0= 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 165875301497597.50013976790717; Mon, 25 Jul 2022 05:43:34 -0700 (PDT) Received: from localhost ([::1]:56364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFxQr-0000yS-5f for importer@patchew.org; Mon, 25 Jul 2022 08:43:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5g-0002aQ-S5 for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:32678) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5c-00064M-Ts for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:39 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-647-jUqwIB8JMJyAB5abW27ApA-1; Mon, 25 Jul 2022 08:21:31 -0400 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 913092811383; Mon, 25 Jul 2022 12:21:26 +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 3EA7390A04; Mon, 25 Jul 2022 12:21:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658751695; 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=rtAkzJgmgSvnZY++3nStSUz9Dq0gU/2gwy5wg4aQA/0=; b=ZDWY+ZTbtjt3CTeSNQW8zsgiX59X3Iz86Da6fVf4tpwpgMB9VArx2p8cDr1rKgSFKjOykU taRyIQUXTdMc2sxZxlZXqUh0jhRmx8V0KmR4FX7XaAhLXCV7NTzgfblZZjxbfUw4eWJnHE dESEJe3GN7DGOM/PciPhi3AKTKP/d1Y= X-MC-Unique: jUqwIB8JMJyAB5abW27ApA-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Paolo Bonzini , John Snow , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Stefan Hajnoczi , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v2 10/11] block: rename bdrv_child_try_change_aio_context in bdrv_try_change_aio_context Date: Mon, 25 Jul 2022 08:21:19 -0400 Message-Id: <20220725122120.309236-11-eesposit@redhat.com> In-Reply-To: <20220725122120.309236-1-eesposit@redhat.com> References: <20220725122120.309236-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 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=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658753016205100001 Content-Type: text/plain; charset="utf-8" No functional changes intended. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Suggested-by: Paolo Bonzini --- block.c | 19 ++++++++----------- block/block-backend.c | 3 +-- include/block/block-global-state.h | 12 +++++------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/block.c b/block.c index c066b41c8c..b82eb0ba6d 100644 --- a/block.c +++ b/block.c @@ -7462,11 +7462,9 @@ static bool bdrv_change_aio_context(BlockDriverState= *bs, AioContext *ctx, * For the same reason, it temporarily holds also the new AioContext, since * bdrv_drained_end calls BDRV_POLL_WHILE that assumes the lock is taken t= oo. */ -int bdrv_child_try_change_aio_context_tran(BlockDriverState *bs, - AioContext *ctx, - BdrvChild *ignore_child, - Transaction *tran, - Error **errp) +int bdrv_try_change_aio_context_tran(BlockDriverState *bs, AioContext *ctx, + BdrvChild *ignore_child, Transaction = *tran, + Error **errp) { GHashTable *visited; int ret; @@ -7483,11 +7481,11 @@ int bdrv_child_try_change_aio_context_tran(BlockDri= verState *bs, } =20 /* - * See bdrv_child_try_change_aio_context_tran for invariants on + * See bdrv_try_change_aio_context_tran for invariants on * AioContext locks. */ -int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ct= x, - BdrvChild *ignore_child, Error **err= p) +int bdrv_try_change_aio_context(BlockDriverState *bs, AioContext *ctx, + BdrvChild *ignore_child, Error **errp) { Transaction *tran; int ret; @@ -7496,8 +7494,7 @@ int bdrv_child_try_change_aio_context(BlockDriverStat= e *bs, AioContext *ctx, =20 /* Recursion phase: go through all nodes of the graph */ tran =3D tran_new(); - ret =3D bdrv_child_try_change_aio_context_tran(bs, ctx, ignore_child, = tran, - errp); + ret =3D bdrv_try_change_aio_context_tran(bs, ctx, ignore_child, tran, = errp); =20 /* Linear phase: go through all callbacks collected in the transaction= */ =20 @@ -7542,7 +7539,7 @@ int bdrv_try_set_aio_context(BlockDriverState *bs, Ai= oContext *ctx, Error **errp) { GLOBAL_STATE_CODE(); - return bdrv_child_try_change_aio_context(bs, ctx, NULL, errp); + return bdrv_try_change_aio_context(bs, ctx, NULL, errp); } =20 void bdrv_add_aio_context_notifier(BlockDriverState *bs, diff --git a/block/block-backend.c b/block/block-backend.c index a27b8b7a89..f785c1e7e2 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2182,8 +2182,7 @@ static int blk_do_set_aio_context(BlockBackend *blk, = AioContext *new_context, * update_root_node MUST be false for blk_root_set_aio_ctx_com= mit(), * as we are already in the commit function of a transaction. */ - ret =3D bdrv_child_try_change_aio_context(bs, new_context, blk= ->root, - errp); + ret =3D bdrv_try_change_aio_context(bs, new_context, blk->root= , errp); if (ret < 0) { bdrv_unref(bs); return ret; diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 54fd008442..11f80768c3 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -223,13 +223,11 @@ AioContext *bdrv_child_get_parent_aio_context(BdrvChi= ld *c); bool bdrv_child_change_aio_context(BdrvChild *c, AioContext *ctx, GHashTable *visited, Transaction *tran, Error **errp); -int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ct= x, - BdrvChild *ignore_child, Error **err= p); -int bdrv_child_try_change_aio_context_tran(BlockDriverState *bs, - AioContext *ctx, - BdrvChild *ignore_child, - Transaction *tran, - Error **errp); +int bdrv_try_change_aio_context(BlockDriverState *bs, AioContext *ctx, + BdrvChild *ignore_child, Error **errp); +int bdrv_try_change_aio_context_tran(BlockDriverState *bs, AioContext *ctx, + BdrvChild *ignore_child, Transaction = *tran, + Error **errp); =20 int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz); int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo); --=20 2.31.1 From nobody Thu May 16 11:13:54 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=1658752733; cv=none; d=zohomail.com; s=zohoarc; b=k83N3fHTCMGjO2eYWCtl9tDz/TOaELqspwQYe3oy/U1SoFuvtdyJZXURCU0YMQE5QBipaoZEbEQ/5QYR+YqVLxPbhVDIXogZPxp/KFh6UA6NaVyx9vC84XPudHm/U8EDLNS81Z/Obdt+gtH+go7GvVbET23AbkhgJQzHcZBr7Wk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1658752733; 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=XerYKIamNmCB+98DrpjXdwOn/dQDkZtIG63giaAKlJg=; b=FtJHwLs2kbcTq6NurbybK/Hr/1my+LXwexgAuyhpn9vpYWQkkaid2GbTFEaQjzD2OMC8b6+6vSHqtpzNVbixoO8DuvoL3QhuG3rZpgdAnqruWs53vR2V8uqqgdSqd8QEp48iL8KsLXeOT1HP0hNpmf/1G2IGX9ssjMojAe4pBng= 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 1658752733921123.84174140725145; Mon, 25 Jul 2022 05:38:53 -0700 (PDT) Received: from localhost ([::1]:46422 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oFxMJ-0002R8-Fs for importer@patchew.org; Mon, 25 Jul 2022 08:38:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48784) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5g-0002aR-TN for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:41 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:29277) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oFx5e-00065y-1B for qemu-devel@nongnu.org; Mon, 25 Jul 2022 08:21:40 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-653-Z24oC9CMNQWpE9qH6UYUgQ-1; Mon, 25 Jul 2022 08:21:32 -0400 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 294BA891093; Mon, 25 Jul 2022 12:21:27 +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 98C2A9457F; Mon, 25 Jul 2022 12:21:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658751697; 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=XerYKIamNmCB+98DrpjXdwOn/dQDkZtIG63giaAKlJg=; b=fSxfW10FoekUr315MzrWRNuh0TIEQ/A8zRpm16Ak4JMPmSgRWqiuE59jl2u0Xktfx3SeHa aGffi5fj/ja7lUleBk10F1Cwhf1pXfhwcWmo00QZ2jRzl7TtLNt1RK/37LQ9/2Ej1+2sGM SMWBoDwhexvsre5ajAzDjWnfrBrzMGw= X-MC-Unique: Z24oC9CMNQWpE9qH6UYUgQ-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Paolo Bonzini , John Snow , Vladimir Sementsov-Ogievskiy , Markus Armbruster , Stefan Hajnoczi , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v2 11/11] block: remove bdrv_try_set_aio_context and replace it with bdrv_try_change_aio_context Date: Mon, 25 Jul 2022 08:21:20 -0400 Message-Id: <20220725122120.309236-12-eesposit@redhat.com> In-Reply-To: <20220725122120.309236-1-eesposit@redhat.com> References: <20220725122120.309236-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.79 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=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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1658752735261100003 Content-Type: text/plain; charset="utf-8" No functional change intended. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Suggested-by: Paolo Bonzini --- block.c | 14 ++++---------- block/export/export.c | 2 +- blockdev.c | 22 +++++++++++----------- docs/devel/multiple-iothreads.txt | 4 ++-- include/block/block-global-state.h | 2 -- job.c | 2 +- tests/unit/test-bdrv-drain.c | 6 +++--- tests/unit/test-block-iothread.c | 10 +++++----- 8 files changed, 27 insertions(+), 35 deletions(-) diff --git a/block.c b/block.c index b82eb0ba6d..435e8fe731 100644 --- a/block.c +++ b/block.c @@ -2950,7 +2950,7 @@ static void bdrv_attach_child_common_abort(void *opaq= ue) bdrv_replace_child_noperm(s->child, NULL, false); =20 if (bdrv_get_aio_context(bs) !=3D s->old_child_ctx) { - bdrv_try_set_aio_context(bs, s->old_child_ctx, &error_abort); + bdrv_try_change_aio_context(bs, s->old_child_ctx, NULL, &error_abo= rt); } =20 if (bdrv_child_get_parent_aio_context(child) !=3D s->old_parent_ctx) { @@ -3027,7 +3027,8 @@ static int bdrv_attach_child_common(BlockDriverState = *child_bs, parent_ctx =3D bdrv_child_get_parent_aio_context(new_child); if (child_ctx !=3D parent_ctx) { Error *local_err =3D NULL; - int ret =3D bdrv_try_set_aio_context(child_bs, parent_ctx, &local_= err); + int ret =3D bdrv_try_change_aio_context(child_bs, parent_ctx, NULL, + &local_err); =20 if (ret < 0 && child_class->change_aio_ctx) { Transaction *tran =3D tran_new(); @@ -3130,7 +3131,7 @@ static void bdrv_detach_child(BdrvChild **childp) * When the parent requiring a non-default AioContext is removed, = the * node moves back to the main AioContext */ - bdrv_try_set_aio_context(old_bs, qemu_get_aio_context(), NULL); + bdrv_try_change_aio_context(old_bs, qemu_get_aio_context(), NULL, = NULL); } } =20 @@ -7535,13 +7536,6 @@ int bdrv_try_change_aio_context(BlockDriverState *bs= , AioContext *ctx, return 0; } =20 -int bdrv_try_set_aio_context(BlockDriverState *bs, AioContext *ctx, - Error **errp) -{ - GLOBAL_STATE_CODE(); - return bdrv_try_change_aio_context(bs, ctx, NULL, errp); -} - void bdrv_add_aio_context_notifier(BlockDriverState *bs, void (*attached_aio_context)(AioContext *new_context, void *opaque= ), void (*detach_aio_context)(void *opaque), void *opaque) diff --git a/block/export/export.c b/block/export/export.c index 4744862915..7cc0c25c1c 100644 --- a/block/export/export.c +++ b/block/export/export.c @@ -129,7 +129,7 @@ BlockExport *blk_exp_add(BlockExportOptions *export, Er= ror **errp) =20 /* Ignore errors with fixed-iothread=3Dfalse */ set_context_errp =3D fixed_iothread ? errp : NULL; - ret =3D bdrv_try_set_aio_context(bs, new_ctx, set_context_errp); + ret =3D bdrv_try_change_aio_context(bs, new_ctx, NULL, set_context= _errp); if (ret =3D=3D 0) { aio_context_release(ctx); aio_context_acquire(new_ctx); diff --git a/blockdev.c b/blockdev.c index 2cd84d206c..fb0ec67523 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1619,8 +1619,8 @@ static void external_snapshot_abort(BlkActionState *c= ommon) aio_context_release(aio_context); aio_context_acquire(tmp_context); =20 - ret =3D bdrv_try_set_aio_context(state->old_bs, - aio_context, NULL); + ret =3D bdrv_try_change_aio_context(state->old_bs, + aio_context, NULL, NULL); assert(ret =3D=3D 0); =20 aio_context_release(tmp_context); @@ -1781,12 +1781,12 @@ static void drive_backup_prepare(BlkActionState *co= mmon, Error **errp) goto out; } =20 - /* Honor bdrv_try_set_aio_context() context acquisition requirements. = */ + /* Honor bdrv_try_change_aio_context() context acquisition requirement= s. */ old_context =3D bdrv_get_aio_context(target_bs); aio_context_release(aio_context); aio_context_acquire(old_context); =20 - ret =3D bdrv_try_set_aio_context(target_bs, aio_context, errp); + ret =3D bdrv_try_change_aio_context(target_bs, aio_context, NULL, errp= ); if (ret < 0) { bdrv_unref(target_bs); aio_context_release(old_context); @@ -1881,12 +1881,12 @@ static void blockdev_backup_prepare(BlkActionState = *common, Error **errp) return; } =20 - /* Honor bdrv_try_set_aio_context() context acquisition requirements. = */ + /* Honor bdrv_try_change_aio_context() context acquisition requirement= s. */ aio_context =3D bdrv_get_aio_context(bs); old_context =3D bdrv_get_aio_context(target_bs); aio_context_acquire(old_context); =20 - ret =3D bdrv_try_set_aio_context(target_bs, aio_context, errp); + ret =3D bdrv_try_change_aio_context(target_bs, aio_context, NULL, errp= ); if (ret < 0) { aio_context_release(old_context); return; @@ -3183,12 +3183,12 @@ void qmp_drive_mirror(DriveMirror *arg, Error **err= p) !bdrv_has_zero_init(target_bs))); =20 =20 - /* Honor bdrv_try_set_aio_context() context acquisition requirements. = */ + /* Honor bdrv_try_change_aio_context() context acquisition requirement= s. */ old_context =3D bdrv_get_aio_context(target_bs); aio_context_release(aio_context); aio_context_acquire(old_context); =20 - ret =3D bdrv_try_set_aio_context(target_bs, aio_context, errp); + ret =3D bdrv_try_change_aio_context(target_bs, aio_context, NULL, errp= ); if (ret < 0) { bdrv_unref(target_bs); aio_context_release(old_context); @@ -3255,12 +3255,12 @@ void qmp_blockdev_mirror(bool has_job_id, const cha= r *job_id, =20 zero_target =3D (sync =3D=3D MIRROR_SYNC_MODE_FULL); =20 - /* Honor bdrv_try_set_aio_context() context acquisition requirements. = */ + /* Honor bdrv_try_change_aio_context() context acquisition requirement= s. */ old_context =3D bdrv_get_aio_context(target_bs); aio_context =3D bdrv_get_aio_context(bs); aio_context_acquire(old_context); =20 - ret =3D bdrv_try_set_aio_context(target_bs, aio_context, errp); + ret =3D bdrv_try_change_aio_context(target_bs, aio_context, NULL, errp= ); =20 aio_context_release(old_context); aio_context_acquire(aio_context); @@ -3756,7 +3756,7 @@ void qmp_x_blockdev_set_iothread(const char *node_nam= e, StrOrNull *iothread, old_context =3D bdrv_get_aio_context(bs); aio_context_acquire(old_context); =20 - bdrv_try_set_aio_context(bs, new_context, errp); + bdrv_try_change_aio_context(bs, new_context, NULL, errp); =20 aio_context_release(old_context); } diff --git a/docs/devel/multiple-iothreads.txt b/docs/devel/multiple-iothre= ads.txt index aeb997bed5..343120f2ef 100644 --- a/docs/devel/multiple-iothreads.txt +++ b/docs/devel/multiple-iothreads.txt @@ -109,7 +109,7 @@ The AioContext originates from the QEMU block layer, ev= en though nowadays AioContext is a generic event loop that can be used by any QEMU subsystem. =20 The block layer has support for AioContext integrated. Each BlockDriverSt= ate -is associated with an AioContext using bdrv_try_set_aio_context() and +is associated with an AioContext using bdrv_try_change_aio_context() and bdrv_get_aio_context(). This allows block layer code to process I/O insid= e the right AioContext. Other subsystems may wish to follow a similar approach. =20 @@ -134,5 +134,5 @@ Long-running jobs (usually in the form of coroutines) a= re best scheduled in the BlockDriverState's AioContext to avoid the need to acquire/release aro= und each bdrv_*() call. The functions bdrv_add/remove_aio_context_notifier, or alternatively blk_add/remove_aio_context_notifier if you use BlockBacke= nds, -can be used to get a notification whenever bdrv_try_set_aio_context() move= s a +can be used to get a notification whenever bdrv_try_change_aio_context() m= oves a BlockDriverState to a different AioContext. diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 11f80768c3..3c5a8fb61b 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -217,8 +217,6 @@ void coroutine_fn bdrv_co_lock(BlockDriverState *bs); */ void coroutine_fn bdrv_co_unlock(BlockDriverState *bs); =20 -int bdrv_try_set_aio_context(BlockDriverState *bs, AioContext *ctx, - Error **errp); AioContext *bdrv_child_get_parent_aio_context(BdrvChild *c); bool bdrv_child_change_aio_context(BdrvChild *c, AioContext *ctx, GHashTable *visited, Transaction *tran, diff --git a/job.c b/job.c index 747871c2e5..637bc6592c 100644 --- a/job.c +++ b/job.c @@ -588,7 +588,7 @@ static void coroutine_fn job_do_yield_locked(Job *job, = uint64_t ns) next_aio_context =3D job->aio_context; /* * Coroutine has resumed, but in the meanwhile the job AioContext - * might have changed via bdrv_try_set_aio_context(), so we need to mo= ve + * might have changed via bdrv_try_change_aio_context(), so we need to= move * the coroutine too in the new aiocontext. */ while (qemu_get_current_aio_context() !=3D next_aio_context) { diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 4924ceb562..e465e4349d 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -1538,16 +1538,16 @@ static void test_set_aio_context(void) &error_abort); =20 bdrv_drained_begin(bs); - bdrv_try_set_aio_context(bs, ctx_a, &error_abort); + bdrv_try_change_aio_context(bs, ctx_a, NULL, &error_abort); =20 aio_context_acquire(ctx_a); bdrv_drained_end(bs); =20 bdrv_drained_begin(bs); - bdrv_try_set_aio_context(bs, ctx_b, &error_abort); + bdrv_try_change_aio_context(bs, ctx_b, NULL, &error_abort); aio_context_release(ctx_a); aio_context_acquire(ctx_b); - bdrv_try_set_aio_context(bs, qemu_get_aio_context(), &error_abort); + bdrv_try_change_aio_context(bs, qemu_get_aio_context(), NULL, &error_a= bort); aio_context_release(ctx_b); bdrv_drained_end(bs); =20 diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 9d7c8be00f..0626ab83a6 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -638,7 +638,7 @@ static void test_propagate_mirror(void) filter =3D bdrv_find_node("filter_node"); =20 /* Change the AioContext of src */ - bdrv_try_set_aio_context(src, ctx, &error_abort); + bdrv_try_change_aio_context(src, ctx, NULL, &error_abort); g_assert(bdrv_get_aio_context(src) =3D=3D ctx); g_assert(bdrv_get_aio_context(target) =3D=3D ctx); g_assert(bdrv_get_aio_context(filter) =3D=3D ctx); @@ -646,7 +646,7 @@ static void test_propagate_mirror(void) =20 /* Change the AioContext of target */ aio_context_acquire(ctx); - bdrv_try_set_aio_context(target, main_ctx, &error_abort); + bdrv_try_change_aio_context(target, main_ctx, NULL, &error_abort); aio_context_release(ctx); g_assert(bdrv_get_aio_context(src) =3D=3D main_ctx); g_assert(bdrv_get_aio_context(target) =3D=3D main_ctx); @@ -656,7 +656,7 @@ static void test_propagate_mirror(void) blk =3D blk_new(qemu_get_aio_context(), 0, BLK_PERM_ALL); blk_insert_bs(blk, src, &error_abort); =20 - bdrv_try_set_aio_context(target, ctx, &local_err); + bdrv_try_change_aio_context(target, ctx, NULL, &local_err); error_free_or_abort(&local_err); =20 g_assert(blk_get_aio_context(blk) =3D=3D main_ctx); @@ -667,7 +667,7 @@ static void test_propagate_mirror(void) /* ...unless we explicitly allow it */ aio_context_acquire(ctx); blk_set_allow_aio_context_change(blk, true); - bdrv_try_set_aio_context(target, ctx, &error_abort); + bdrv_try_change_aio_context(target, ctx, NULL, &error_abort); aio_context_release(ctx); =20 g_assert(blk_get_aio_context(blk) =3D=3D ctx); @@ -679,7 +679,7 @@ static void test_propagate_mirror(void) =20 aio_context_acquire(ctx); blk_set_aio_context(blk, main_ctx, &error_abort); - bdrv_try_set_aio_context(target, main_ctx, &error_abort); + bdrv_try_change_aio_context(target, main_ctx, NULL, &error_abort); aio_context_release(ctx); =20 blk_unref(blk); --=20 2.31.1