From nobody Thu May 16 23:30:41 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=1666688729; cv=none; d=zohomail.com; s=zohoarc; b=E7hMoJxy0rrXsBpabw2dLj2eDXYaBuhHWrVJu4GM2UzAf9D9o146DCknqN80wNbD769dqFjLC8Y5nnIkovjIVTQ/cr2EJeW33kto0y/50xKUaI8wVHGjnbEyXpcWIXUz78nD9FT2HfMX5ObwWk8iOPGv46KRptEELVJzLqLooMM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666688729; 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=whEjjT48XOEVIrzNrJpiyDLIlKnH4wFBFDoICWBR4ZY=; b=aqf+mYGXg0wVZ1TEbqri0qWcf7xkoM7lNmLHeX7bTIa/5nLOcnbdIRzDF02p1RLw1bENKunDxqJbhDeeWeo9ihsoPn4u7qho/5Vp4TthXnVx1zQqBIMPPVTTL73zBAOJraCxvVK1DmSS/tdDvGXymKQbVNhqA12JsyDPp3AvMWU= 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 1666688729480193.77359821890207; Tue, 25 Oct 2022 02:05:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFm9-0003gB-Ek; Tue, 25 Oct 2022 04:59:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdV-0007Wu-Sk for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdL-0007W0-DR for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:12 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-267-8rPGW1OlOECPlgnJTi5IBw-1; Tue, 25 Oct 2022 04:49:56 -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 B5CEA87A9E1; Tue, 25 Oct 2022 08:49:54 +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 7054735429; Tue, 25 Oct 2022 08:49:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666687802; 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=whEjjT48XOEVIrzNrJpiyDLIlKnH4wFBFDoICWBR4ZY=; b=InDpTwU9Ztxmd3cLlpM96HHG+hXePnuv6cdbO3/YiDQqOcKvDlspPQS5117GsbRhAUJn9n QiGb8gL1Ycn+RreSTzCeHBMIxSqMFJyw+T3nBNeB8oC6vMAmZ0R09oZ4Ycx7LN76IjKYBL EQ0oMTCHX4wFEX3+AdXU43PvXQZ2g7M= X-MC-Unique: 8rPGW1OlOECPlgnJTi5IBw-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 v3 01/10] block.c: assert bs->aio_context is written under BQL and drains Date: Tue, 25 Oct 2022 04:49:43 -0400 Message-Id: <20221025084952.2139888-2-eesposit@redhat.com> In-Reply-To: <20221025084952.2139888-1-eesposit@redhat.com> References: <20221025084952.2139888-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.503, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666688730118100001 Content-Type: text/plain; charset="utf-8" Also here ->aio_context is read by I/O threads and written under BQL. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Reviewed-by: Hanna Reitz Suggested-by: Paolo Bonzini --- block.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block.c b/block.c index 554ce727c3..529be80759 100644 --- a/block.c +++ b/block.c @@ -7153,6 +7153,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 @@ -7166,6 +7167,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 23:30:41 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=1666688435; cv=none; d=zohomail.com; s=zohoarc; b=n9hTPKtbbrXb8zS8dyV7fwFXeBEGy4b1shJkdYnlullykiJEg6fVSjcGGe88x85NH0fbAYBLJ3WMgAobzq1A/NCrQLGZe5DGDRgDsLocjtvtsDbVP20fcW+LRFOaCDlt0b0xm6cwLQxlD4mHR+JP4q674KtcGgYjA9NaAMfMI8w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666688435; 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=CkgJGYKUAkXqQPaNBliUZ2NJ33K0BX8E/g+h86u13Dg=; b=nqprc7nyLvz1m3fLLkJfOa0dS+ywR8UnCYs3K76rBFhA7R+JsUwWk0BqWauY1AoOLBjAAFaNOSHYmHbpXZUdEsePUzCCsK0gBOICIuVP2/NSxn7o//uKV5BJ8rCWHYqEQMrFBKwthDaKfe0zDK2KhfRR8aqcnYS1elWNuuijwcw= 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 1666688435125876.3127618572355; Tue, 25 Oct 2022 02:00:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFlH-0001b5-UM; Tue, 25 Oct 2022 04:58:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdQ-0007Hp-MJ for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdI-0007Ua-UL for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:07 -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-96-ErrRprg2NciS8CuSzbIQlg-1; Tue, 25 Oct 2022 04:49:55 -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 164CF8582B9; Tue, 25 Oct 2022 08:49:55 +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 C081C23177; Tue, 25 Oct 2022 08:49:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666687799; 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=CkgJGYKUAkXqQPaNBliUZ2NJ33K0BX8E/g+h86u13Dg=; b=G1349wO3OnlAwTGiJfpipM8vlheJuanTFRIpphzqqG5N1rN0nfs9f/rNCyk0glejK6njG1 X7Z3rW4GMmMPsg3lKOT+/gkCJfbREDjF1hD2bU8yiErq4BcuVgI74PuZVLPuqlmGpPxfjO 11FVyOAQQA0QuqoGzceuSBMzT9SWab8= X-MC-Unique: ErrRprg2NciS8CuSzbIQlg-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 v3 02/10] block: use transactions as a replacement of ->{can_}set_aio_context() Date: Tue, 25 Oct 2022 04:49:44 -0400 Message-Id: <20221025084952.2139888-3-eesposit@redhat.com> In-Reply-To: <20221025084952.2139888-1-eesposit@redhat.com> References: <20221025084952.2139888-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.503, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666688436005100003 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 | 220 ++++++++++++++++++++++++++++- include/block/block-global-state.h | 6 + include/block/block_int-common.h | 3 + 3 files changed, 228 insertions(+), 1 deletion(-) diff --git a/block.c b/block.c index 529be80759..4da7526674 100644 --- a/block.c +++ b/block.c @@ -104,6 +104,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 @@ -7196,7 +7200,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, @@ -7305,6 +7309,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) { @@ -7316,6 +7352,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, @@ -7343,6 +7391,98 @@ bool bdrv_can_set_aio_context(BlockDriverState *bs, = AioContext *ctx, return true; } =20 +static void bdrv_set_aio_context_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; + AioContext *old_context =3D bdrv_get_aio_context(bs); + assert_bdrv_graph_writable(bs); + + /* + * Take the old AioContex when detaching it from bs. + * At this point, new_context lock is already acquired, and we are now + * also taking old_context. This is safe as long as bdrv_detach_aio_co= ntext + * does not call AIO_POLL_WHILE(). + */ + if (old_context !=3D qemu_get_aio_context()) { + aio_context_acquire(old_context); + } + bdrv_detach_aio_context(bs); + if (old_context !=3D qemu_get_aio_context()) { + aio_context_release(old_context); + } + bdrv_attach_aio_context(bs, new_context); +} + +static TransactionActionDrv set_aio_context =3D { + .commit =3D bdrv_set_aio_context_commit, + .clean =3D bdrv_set_aio_context_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 objects. 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_set_aio_context_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) { @@ -7366,6 +7506,84 @@ 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. + * + * 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 also holds the new AioContext, since + * bdrv_drained_end calls BDRV_POLL_WHILE that assumes the lock is taken t= oo. + * Therefore the new AioContext lock must not be taken by the caller. + */ +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. + * Take care of checking that all nodes support changing AioContext + * and drain them, builing a linear list of callbacks to run if everyt= hing + * is successful (the transaction itself). + */ + 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. + * Run all callbacks collected in the recursion to switch all nodes + * AioContext lock (transaction commit), or undo all changes done in t= he + * recursion (transaction abort). + */ + + 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 29a38d7e18..7b0095b419 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -232,6 +232,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 1f300ee7f6..9067a99249 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -910,6 +910,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 23:30:41 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=1666689232; cv=none; d=zohomail.com; s=zohoarc; b=NPpAfrlLqFEHly3ubWE87PUJXctI1C//Od7Y9KcgayN6yOwWl8jMg8EJj4eqn+kPVccu9OnQs+whDO4vgr2zpKuA9QfZm7B9+n9ESW0769voFFIyiIsqDznspPcqqh/cJNMIxY6u8X0PtBKj1139RZRt7laympkPhNN3lksXWuI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666689232; 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=WMPMKxRdFZc5XVi8BCyru4Ab+xE+tdDqXkClIl0h75E=; b=B57DHPP78wSq5a/+U+3gS3BY6E3BzNSJpUKPLNycWzczimHUeVJtxUYhx5jW7WSkoOjzSMB/S5Cmzl5NzU0iuTRtsewvuHKR+4m26KQ+O4ZLi8n2VZXHabyCqYcbHjgAd8rNgBWHBlSzv4v0U0pfrjMRSwjpLW2LPy3QXkt2cU0= 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 1666689232401266.7104991660316; Tue, 25 Oct 2022 02:13:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFmA-0004F5-V5; Tue, 25 Oct 2022 04:59:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdW-0007Xo-0G for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdL-0007Vq-7T for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:11 -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-613-wY3N2oL0MG--Ks5c6V9PUQ-1; Tue, 25 Oct 2022 04:49:55 -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 64A30858F13; Tue, 25 Oct 2022 08:49:55 +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 1F88935429; Tue, 25 Oct 2022 08:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666687802; 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=WMPMKxRdFZc5XVi8BCyru4Ab+xE+tdDqXkClIl0h75E=; b=Q+Whu1bDtmHo3l1X1p6Fq2yg2q0k5w8lPUyuLUK4oHw8G8Cn14C8zxx1ClYDYI0mlAJMsN ll7aUmNCPGrG5xGj/zTqyKtfPzNrYT/YGNh0j583sW8eWTiYBvOVqj/IfF/YZB6fKJ5H/M 9kwwg3gqYeT+VYVE/+0ATL53uCT4uS0= X-MC-Unique: wY3N2oL0MG--Ks5c6V9PUQ-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 v3 03/10] bdrv_change_aio_context: use hash table instead of list of visited nodes Date: Tue, 25 Oct 2022 04:49:45 -0400 Message-Id: <20221025084952.2139888-4-eesposit@redhat.com> In-Reply-To: <20221025084952.2139888-1-eesposit@redhat.com> References: <20221025084952.2139888-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.503, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666689233489100007 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 4da7526674..56c57d07fa 100644 --- a/block.c +++ b/block.c @@ -105,7 +105,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 */ @@ -7315,14 +7315,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 @@ -7353,14 +7354,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 @@ -7445,7 +7446,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; @@ -7524,7 +7525,7 @@ int bdrv_child_try_change_aio_context(BlockDriverStat= e *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(); @@ -7536,9 +7537,12 @@ int bdrv_child_try_change_aio_context(BlockDriverSta= te *bs, AioContext *ctx, * is successful (the transaction itself). */ 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. diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 7b0095b419..e7372ec541 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -233,7 +233,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 9067a99249..7ccbbdae05 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -911,7 +911,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 23:30:41 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=1666689230; cv=none; d=zohomail.com; s=zohoarc; b=T3fbd7uRkVVNTUIACdDf+s8quz2C+xDTeVgu4FIRBlmEizuWrWgCv6kcta/wqCkXNbeUcoNoTmBekQ9nEjB0BIvk94l+RUAuPYnBHpBcdLcsVHgvCj8tgIhhIKcIo4fh8e5fTdvdqx32rfqOrRbZOFk2y09ycRgj6agZUJul53k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666689230; 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=ZzK8Nvp5hWcQs1l+Px+GO6LAD7FMhoYv0HjAQM6gcfI=; b=W0Vdw59UJEZR5xlbKfrchEgik88yDdvn9/STMasmyJ1bCsI+87bEckS+XauJL4gX0/Ii+ij8kkE1PnTSc4z3mPX2ojniHlrVgjA+xKMp3AL+4dwQiG82kt8mXz02qOXy6aJHQU+ck3XpJSF1JVvT3fA82hiV9Qho9ZKDrhPhGN8= 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 1666689230024503.71119568956203; Tue, 25 Oct 2022 02:13:50 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFkx-0008DO-Pd; Tue, 25 Oct 2022 04:57:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdO-00070W-Ox for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:06 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdI-0007UL-U5 for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:06 -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-613-218pGt7mM7GV2pgnl1aKjA-1; Tue, 25 Oct 2022 04:49:56 -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 B20041C075A2; Tue, 25 Oct 2022 08:49:55 +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 6D41F17584; Tue, 25 Oct 2022 08:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666687798; 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=ZzK8Nvp5hWcQs1l+Px+GO6LAD7FMhoYv0HjAQM6gcfI=; b=Bbz1n3JJTlTTzbFr+W81gj8Gkxd9pIngnNhlr0J9uJXI1hpXie95hX55iEfpRDc5w6GptC ytA/8ic7ye6FIx9tPpjqQxYLjOPm6gEwjgHXBXE4xiwLIdyKcW+gI/sc1W2lWiVXjiaMT5 bP44wv7HJkMhR0rxkulkP2EACSyBiE4= X-MC-Unique: 218pGt7mM7GV2pgnl1aKjA-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 v3 04/10] blockjob: implement .change_aio_ctx in child_job Date: Tue, 25 Oct 2022 04:49:46 -0400 Message-Id: <20221025084952.2139888-5-eesposit@redhat.com> In-Reply-To: <20221025084952.2139888-1-eesposit@redhat.com> References: <20221025084952.2139888-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.503, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666689231491100003 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. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Hanna Reitz 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 bdf20a0e35..5a783b75c6 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 23:30:41 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=1666688367; cv=none; d=zohomail.com; s=zohoarc; b=dbTsfB2sfy4gDGB3KNfPo2mrZ2yCw8W08pVe/X0rrTHqX6HBDW2OK9k2dXOpV7Gl/0FEzc1riQjwahmBI5gohN11HlWyjgxpwLkFXoLv1KtXADCgyXwNVbhHz1vezAYMTeQZcoerlwSr6wDRHcFLB4qP1bjzKDH2NiBKW7m5FPU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666688367; 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=Ic29PN4mtqSatrezzdlNeX9E38F4X3tjYIFQ/mofawo=; b=Tr0tW6yZMtdLSFT5ueGfy6sVP9g87VxXL/DCoX+xvG8YTzuOWCOfCS2PJFehuUEW/kcp0+qn5pew1ESfp92SeAqvcj1Yxjzq48yS+M7jm+OmbVjYQ5HlXinzqVnReDMDCYcgzbCxEzS8hPu5iQFq0uq8wfT9/2NnlkZzY+1zTkM= 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 166668836732586.70535236464514; Tue, 25 Oct 2022 01:59:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFm4-0002wV-D0; Tue, 25 Oct 2022 04:59:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdR-0007Nl-DB for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdI-0007UJ-Qo for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:08 -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-655-Jnei6e7GM-6_P06Le_9dZw-1; Tue, 25 Oct 2022 04:49:56 -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 0B877811E75; Tue, 25 Oct 2022 08:49:56 +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 BB1BA35429; Tue, 25 Oct 2022 08:49:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666687797; 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=Ic29PN4mtqSatrezzdlNeX9E38F4X3tjYIFQ/mofawo=; b=f8eH9IuJbYRPRuY1eGnYurx74Eu+i0XpuQPOw5Y+nxvBUI3ZwQESn+pDUJPyFCD6vu5Ww3 sNj/k5WDGASCgRFzS4ElRQ8FaKM1FMClDmhCsTswga5cYIMBO7kCkMEWofMLOQuT3hbr2T ItmO0AmQkYOHHNbdqnDWYYNl5caayfo= X-MC-Unique: Jnei6e7GM-6_P06Le_9dZw-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 v3 05/10] block: implement .change_aio_ctx in child_of_bds Date: Tue, 25 Oct 2022 04:49:47 -0400 Message-Id: <20221025084952.2139888-6-eesposit@redhat.com> In-Reply-To: <20221025084952.2139888-1-eesposit@redhat.com> References: <20221025084952.2139888-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.503, 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 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: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666688369583100001 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. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Hanna Reitz 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 56c57d07fa..647297ca81 100644 --- a/block.c +++ b/block.c @@ -1242,6 +1242,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) { @@ -1534,6 +1542,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 23:30:41 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=1666688895; cv=none; d=zohomail.com; s=zohoarc; b=I+jLnA7A9C88zln1qFM9RV+zEQX9LiFKdVt1dJz+cmxzqVTwk57j5ML8Nv0lmKalLFdoNO7X0ny9mIEXkdgUvK9CcTd0dsAzmDglb99aqsZ+s6dnbImk5URISUJXKOvB5Bp79GAunNTS4lnTfV721M+0fNLhuBz753AKtgnjIFQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666688895; 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=k8VJpiDmOvkkeh8LGfXs396lXAJSFkDiOFq98gyZFxM=; b=TlbqlW85IsOrFZl7EBpJf4jSW2XEe5pq5e7+EkpYyZs0Xmx7YGFqV+sm62ThPQ0zeHYcTf91/C/ifTmBUuHXQwyotRRzhGavxNID41PsCd1uqI9yXI2xMwSDaKm5+KFZK61pzQtCX7ZfKpbwXTixUV30qXdpJwmb43MPQrOMhnQ= 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 1666688895405422.580171499598; Tue, 25 Oct 2022 02:08:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFmK-0005YU-24; Tue, 25 Oct 2022 04:59:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdj-0007vg-FA for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdN-0007ZI-JO for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:14 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-592-mbyWKYcvPg-oxUqTlG05rg-1; Tue, 25 Oct 2022 04:49:56 -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 5A61D1881423; Tue, 25 Oct 2022 08:49:56 +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 14DFB23177; Tue, 25 Oct 2022 08:49:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666687803; 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=k8VJpiDmOvkkeh8LGfXs396lXAJSFkDiOFq98gyZFxM=; b=PILvG0UaH0PT7F97jvpwQysGQhwjifOTUYX1SlmhkF0GO/pTwxLmv7W4UiNKGKrcMLPmFO azOduvQCZ/dAdWtk8bUU+fu9ZHsTk+PBx5qsN9vmP7u2Q94WxqqTo6CK/TqLbF5h6SZt7l 5OPU65FCoIRrzjkqvsVWQNpK8/z+SBk= X-MC-Unique: mbyWKYcvPg-oxUqTlG05rg-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 v3 06/10] block-backend: implement .change_aio_ctx in child_root Date: Tue, 25 Oct 2022 04:49:48 -0400 Message-Id: <20221025084952.2139888-7-eesposit@redhat.com> In-Reply-To: <20221025084952.2139888-1-eesposit@redhat.com> References: <20221025084952.2139888-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.503, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666688897110100002 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 aa4adf06ae..d87ae435a7 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, }; @@ -2177,6 +2181,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 23:30:41 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=1666689266; cv=none; d=zohomail.com; s=zohoarc; b=TyDFrjQ4m5x9NcB8GPiXWW2dk2WnuwDiGpIo+ccuB5Sp8VMvkVhIom0cdGjWkEws2iYPObiTw3vaujO2wdva48c1r6qHo4KmN2ued8zyMxvNoGWAqB+XVazlmtsmFphvQNQi2r7Mgc+aXMy0xlm7SAhYOEAs9Kytc5aXXsSnKyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666689266; 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=63eUcMpol0t2jp03PhUpUP5EPG6mrFCUlZoPo0L+PW8=; b=PtRWDFxIXeXlC36TEFm0naYPFFjvku+O5PrJhlVEy2XZILLfIub2utZCCaOSdVsAkz9LzGi3ggYEEGRJrPii8NYfrVonN3lXFb0OULV2VQ0b8JAEbR6pSC6SiF7MHq/5CZvnrS5Trc0JmUggO7iUUXqUhXeWxJlEZnG9F0viYUM= 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 1666689266246614.7372533580636; Tue, 25 Oct 2022 02:14:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFmE-0004jc-4b; Tue, 25 Oct 2022 04:59:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdV-0007Xb-W7 for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdL-0007VL-9S for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:11 -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-641-kFL2rcnLMruCZCO93w_EuQ-1; Tue, 25 Oct 2022 04:49:57 -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 A93A488434F; Tue, 25 Oct 2022 08:49:56 +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 6425439DB3; Tue, 25 Oct 2022 08:49:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666687801; 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=63eUcMpol0t2jp03PhUpUP5EPG6mrFCUlZoPo0L+PW8=; b=CbC0TuR8YhWehJDw0TK261gOFkdGuLiP8ZBB6qQfLjmPECodr2NZys5lGOPKbzDiWZxgE1 iqm+Mlp/4FNb6kG1GRIol7T5kEbLmXg9T+EKsBvGszyKhLgdZNcM7PryBWGIqVmUedXPsm akoihf4tgIknPp12nOV16obwMv9eVfc= X-MC-Unique: kFL2rcnLMruCZCO93w_EuQ-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 v3 07/10] block: use the new _change_ API instead of _can_set_ and _set_ Date: Tue, 25 Oct 2022 04:49:49 -0400 Message-Id: <20221025084952.2139888-8-eesposit@redhat.com> In-Reply-To: <20221025084952.2139888-1-eesposit@redhat.com> References: <20221025084952.2139888-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.503, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666689266544100001 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 647297ca81..2bdbdee910 100644 --- a/block.c +++ b/block.c @@ -2924,17 +2924,21 @@ static void bdrv_attach_child_common_abort(void *op= aque) } =20 if (bdrv_child_get_parent_aio_context(s->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; - s->child->klass->can_set_aio_ctx(s->child, s->old_parent_ctx, &ign= ore, - &error_abort); - g_slist_free(ignore); + tran =3D tran_new(); =20 - ignore =3D NULL; - s->child->klass->set_aio_ctx(s->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 s->child->klass->change_aio_ctx(s->child, s->old_parent_ct= x, + visited, 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); @@ -2989,18 +2993,20 @@ static BdrvChild *bdrv_attach_child_common(BlockDri= verState *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) { @@ -7601,7 +7607,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 d87ae435a7..ff417dbff9 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2153,8 +2153,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 23:30:41 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=1666688819; cv=none; d=zohomail.com; s=zohoarc; b=NFGHdiyeAv5U0dkSC0+NrKTtvFM0Tc7FVSzRDbttNQonr4c0sY77TPhDFVcnaMn9++rXZ1kykGgS78gV2w5wojLKRCTLNvLWjZw71rSi+6mMNoqBb284Lp2jzUw85ZlZ0486zqj0eOjbEF2Rr0CseOb0Ey2oFylaJaDteG3xtZc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666688819; 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=YKTBcrq+tJfWv5n7Nm744CJC0MYkqLrzRusLIHYpKMI=; b=Z5s/tHfh2hr6WhLFzz0Hjz94s6OaohWtTKrzf+2J3BFF/w/0XXQuvH3b9PnPGuLL4tw6WmODBi4EJ1GZtmwroIOReyqhhhXV0K4GLeNxJI0sKaJ/J6theKBmPwlrs9yiSxvtXqZ/kLhjvkPN3po9UU7p5A1HWZokycWVvil1pzI= 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 1666688819056805.4688481389222; Tue, 25 Oct 2022 02:06:59 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFlo-0002N8-Sa; Tue, 25 Oct 2022 04:58:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdS-0007Px-5g for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdK-0007Vd-Bo for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:09 -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-657-WcnxMeJ9PW-gq_S0PzYzdw-1; Tue, 25 Oct 2022 04:49:57 -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 0B2B33814587; Tue, 25 Oct 2022 08:49:57 +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 B43EF35429; Tue, 25 Oct 2022 08:49:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666687801; 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=YKTBcrq+tJfWv5n7Nm744CJC0MYkqLrzRusLIHYpKMI=; b=TRvRRmIl9U4b21amlTtY7bNONfT4mk00Dyn2wES7ioyMHRqWJBBTlqsBFnmrPpbTa3pN9y 1BVhmvc7Ft35oiA5TJYaewKAZLoFBYmZru+VI8DXN1bIHySXQCp30NfED2Q+r+EpF9TMVz 664wbKqvr+MePjDMNiKsRXvE7jKgLVE= X-MC-Unique: WcnxMeJ9PW-gq_S0PzYzdw-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 v3 08/10] block: remove all unused ->can_set_aio_ctx and ->set_aio_ctx callbacks Date: Tue, 25 Oct 2022 04:49:50 -0400 Message-Id: <20221025084952.2139888-9-eesposit@redhat.com> In-Reply-To: <20221025084952.2139888-1-eesposit@redhat.com> References: <20221025084952.2139888-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.503, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666688820823100003 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 2bdbdee910..3a59f7b7e0 100644 --- a/block.c +++ b/block.c @@ -1250,20 +1250,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 @@ -1540,8 +1526,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, @@ -7205,125 +7189,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; @@ -7357,17 +7222,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) @@ -7380,33 +7234,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_set_aio_context_clean(void *opaque) { BdrvStateSetAioContext *state =3D (BdrvStateSetAioContext *) opaque; @@ -7499,29 +7326,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 ff417dbff9..a91c8d3916 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, @@ -2233,33 +2227,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 5a783b75c6..2d86014fa5 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 e7372ec541..03d4ade7c2 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -220,18 +220,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 7ccbbdae05..c756b838e8 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -906,10 +906,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 23:30:41 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=1666688653; cv=none; d=zohomail.com; s=zohoarc; b=OzK7vgBA1T2nU/MsAMO/piETM2IemnQe61ZfWy/XGkzb1acDev/h8ndvex3yRkyzCaJpV79nno7UYB0HJcOqCLqUWBmV5ha64DwGceWdgCi6gVvM+tEtSBCkxCbEhBzNZZ8naxbQoy/Pgft6cGFe8QSDsU/tUsSQgrMsaHIV5dk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666688653; 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=r1fDW3dwvoO+gnQ2VDIACjQYspB1H17TcUXyWaGCtAw=; b=OBN6HdU9VDJYDp7drW1ApR2Y+RuIbdPVUyi41CXU1X5XTrn3noyhwZ7dz+ud9z16wv8P8YDWjlA5rfDWfmAfcFcWdf76Zu0s8E26S0zp+xqK1q9zmE6utnYVOMVVRTiktdLgTMF6zrSRz1PfuwTF6PphY+Dvafu9Ax9qbGQOYo8= 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 1666688653721442.12276762580586; Tue, 25 Oct 2022 02:04:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFm2-0002bp-4f; Tue, 25 Oct 2022 04:59:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdR-0007Ox-TW for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:13 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdK-0007V2-IR for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:09 -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-584-9csT-4m9N4izUFuFvUrqow-1; Tue, 25 Oct 2022 04:49:58 -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 58F4D381459A; Tue, 25 Oct 2022 08:49:57 +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 13E2635429; Tue, 25 Oct 2022 08:49:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666687800; 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=r1fDW3dwvoO+gnQ2VDIACjQYspB1H17TcUXyWaGCtAw=; b=YlhU/w7rXqrQQD0M4HDt13VXydcU1dy1A+izSQU5+42N0RZZ9UWANokGVXZGCNgPIMPobQ F84o0FNvtHQXOMKXQZ888NGwcbPxCYOUzHzi6BEibDATUAYV36w9lUJ4UAHqixLu8WBdW+ ewLxCtEJeomY5WYEYMBnDCMB269J7yA= X-MC-Unique: 9csT-4m9N4izUFuFvUrqow-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 v3 09/10] block: rename bdrv_child_try_change_aio_context in bdrv_try_change_aio_context Date: Tue, 25 Oct 2022 04:49:51 -0400 Message-Id: <20221025084952.2139888-10-eesposit@redhat.com> In-Reply-To: <20221025084952.2139888-1-eesposit@redhat.com> References: <20221025084952.2139888-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.503, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666688655723100005 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 | 6 +++--- block/block-backend.c | 3 +-- include/block/block-global-state.h | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/block.c b/block.c index 3a59f7b7e0..ad8bc167ee 100644 --- a/block.c +++ b/block.c @@ -7340,8 +7340,8 @@ static bool bdrv_change_aio_context(BlockDriverState = *bs, AioContext *ctx, * bdrv_drained_end calls BDRV_POLL_WHILE that assumes the lock is taken t= oo. * Therefore the new AioContext lock must not be taken by the caller. */ -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; GHashTable *visited; @@ -7411,7 +7411,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 a91c8d3916..705afef9b3 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2151,8 +2151,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 03d4ade7c2..8db3132e8f 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -226,8 +226,8 @@ 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); -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); =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 23:30:41 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=1666688615; cv=none; d=zohomail.com; s=zohoarc; b=i+fbE6PJ998hER6uuZ5WC447zO1VraEW5WiENqxg2MDg+66apEQ7BnWoYWwVZeiWaOdAIRX3iz6/tP595a7msgm9L6dTDhZUfbjgR9WSE+ThyG1vTT+y2cQvkdjqUoYqjVmyzrhlZ4xbrJFmCqhKjGCCAkdn7izi6bzDQuaH3Cc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1666688615; 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=8YBKW4zmEtDXTK6n6TI+llRYEW/ggSFUpzTlW3fXj1U=; b=S4Ulr1gMsDimeDhDuvYe2kw+NKhYJPHsPWa9VCANdEUSvj7EZ+ZkLFg48JPXqI3skKnk6ysS2DbbWj5BoBl9YFD4giFvl0u/QmIDvLNudrFDn0EFKR2oQfUKSgvxz0dBCp/kAFkA0/OvaHJ7i1m0EuXBGuCeVxUHdOhaAVrJY8s= 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 1666688615990569.4674309432802; Tue, 25 Oct 2022 02:03:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1onFmH-0005A7-NU; Tue, 25 Oct 2022 04:59:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdW-0007YW-AR for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:14 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1onFdL-0007WD-Ie for qemu-devel@nongnu.org; Tue, 25 Oct 2022 04:50:13 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-588-M-gmbcCBN2CqZMisU9YKAQ-1; Tue, 25 Oct 2022 04:49:58 -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 AEE1729AA3B2; Tue, 25 Oct 2022 08:49:57 +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 6498C35429; Tue, 25 Oct 2022 08:49:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666687802; 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=8YBKW4zmEtDXTK6n6TI+llRYEW/ggSFUpzTlW3fXj1U=; b=L39jeW3TuVhqO/HTiTOdi8spR/FXXirUs/4ZtKFFnLGjjdsGC7hxhWAq0Hvn2FynHg6BcG Mj/8KsUFGYtEnA4yVpqFt6A4y4vpI/SMlyRs9abigrk1zPGZXuYvO/8pSZClHgkRqVw+kp 9X/6gyROh4dkOGTyvanBYVz0bVl1XSA= X-MC-Unique: M-gmbcCBN2CqZMisU9YKAQ-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 v3 10/10] block: remove bdrv_try_set_aio_context and replace it with bdrv_try_change_aio_context Date: Tue, 25 Oct 2022 04:49:52 -0400 Message-Id: <20221025084952.2139888-11-eesposit@redhat.com> In-Reply-To: <20221025084952.2139888-1-eesposit@redhat.com> References: <20221025084952.2139888-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.503, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Qemu-devel" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1666688617443100003 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 ad8bc167ee..f3ed0808eb 100644 --- a/block.c +++ b/block.c @@ -2904,7 +2904,7 @@ static void bdrv_attach_child_common_abort(void *opaq= ue) bdrv_replace_child_noperm(s->child, NULL); =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(s->child) !=3D s->old_parent_ctx= ) { @@ -2975,7 +2975,8 @@ static BdrvChild *bdrv_attach_child_common(BlockDrive= rState *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(); @@ -3065,7 +3066,7 @@ static void bdrv_detach_child(BdrvChild *child) * 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 @@ -7407,13 +7408,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 a32bafc07a..9dd88d14d0 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1630,8 +1630,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); @@ -1792,12 +1792,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); @@ -1892,12 +1892,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; @@ -3194,12 +3194,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); @@ -3266,12 +3266,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); @@ -3767,7 +3767,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 8db3132e8f..73795a0095 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -220,8 +220,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 78feae05fb..72d57f0934 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 0eecf14310..09dc4a4891 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 def0709b2b..8ca5adec5e 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -765,7 +765,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); @@ -773,7 +773,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); @@ -783,7 +783,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); @@ -794,7 +794,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); @@ -806,7 +806,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