From nobody Mon Feb 9 19:30:24 2026 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=1657660860; cv=none; d=zohomail.com; s=zohoarc; b=nSoYQYsk1Q0sVCaiQMYdH2WJnggkZTzxqvKaMZtq+L770Od1RCYx4VUuuYsG895jFB/InCYrAHIisIbh6Ip9vUJFAbTkW7XmYdRXX9DSDUYxlK6BLrfMabzCJllcJEhvj9p0INeVPi9pxBviHSTOrZK7OfTRRqwaFTGAui0gEpw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657660860; 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=CwFlJAPVPl7sXnM2XXETPNJr8tA5re5ZBNuQxF0Xujg=; b=m3VVA+8KNS2l7Cmfz7oUprY8BJEtkKsRGOLBxbr8FRgIPuhDvucv6ryf8KOtQDEzsCFXVW9zoBPVWqdYl8zWH9rHdEGYxtTvcptbm+zYLd+ZCxew32GY2sgRSmrcOF0jsuXWKquali2GWO9tM/V3/6kKe3uhErAytJ0iDfYKbkQ= 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 1657660860654893.6002467418768; Tue, 12 Jul 2022 14:21:00 -0700 (PDT) Received: from localhost ([::1]:53856 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNJS-00047Y-BD for importer@patchew.org; Tue, 12 Jul 2022 17:20:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34048) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHv-0001jJ-EE for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:21606) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHr-0002Gj-RM for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:21 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-655-mSsKEi9kO9mPUutM8hbhog-1; Tue, 12 Jul 2022 17:19:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 85E0485A585; Tue, 12 Jul 2022 21:19:16 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 764672166B30; Tue, 12 Jul 2022 21:19:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660758; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CwFlJAPVPl7sXnM2XXETPNJr8tA5re5ZBNuQxF0Xujg=; b=Vsq6jX38NNjjSk/8OdKnYZICSaYWJtWilD5tiYUw4nYbYd72dDcbwvrY5uva5MnZ9DDDHn m9kuLaj8C6w8feAmDpCXq5gUyI2RihpOcwEcKSrktmi2OSP21gltoVrXOI7V1qh4z74EXR w6a0704Tq/VL/8VwiKwgbIHmq7oR3yk= X-MC-Unique: mSsKEi9kO9mPUutM8hbhog-1 From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 1/8] block.c: assert bs->aio_context is written under BQL and drains Date: Tue, 12 Jul 2022 17:19:04 -0400 Message-Id: <20220712211911.1302836-2-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1657660862922100003 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: Hanna Reitz Suggested-by: Paolo Bonzini --- block.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/block.c b/block.c index d0db104d71..267a39c0de 100644 --- a/block.c +++ b/block.c @@ -7285,6 +7285,7 @@ static void bdrv_detach_aio_context(BlockDriverState = *bs) if (bs->quiesce_counter) { aio_enable_external(bs->aio_context); } + assert_bdrv_graph_writable(bs); bs->aio_context =3D NULL; } =20 @@ -7298,6 +7299,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 Mon Feb 9 19:30:24 2026 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=1657660860; cv=none; d=zohomail.com; s=zohoarc; b=JmsTduhCjpemCUlOadWs2YesLvRnjJNyxdCfqV7RH1/4f1kE3yVqFMLJa1maeivvxGFElBITYeOCslzWFU2UsjKHyswC8DyLw0AdurgVmYfUA906Pg4A7KfxR52EaPUXnthm/RffBgaBl7hUNh837BUeP5gA7vgEYZ1f3yYjC+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657660860; 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=xamwRQcHxp0nHCghcr5xA3P05s95yhuo/GJ5eC+ybY4=; b=mD32NWSO4ioy7XaejEMj9IBvi+YsPIgxm4MgUT0YQAS33a2lFzSyUnzbmzBTmcRjl8SUQYXNPCvrx+geKMs+pHYC+iAQyAzDcs/lCW/wUggs4+wkzLtywoj4LCLQM5IYV6vNS0t8PhCifgPX7+mUkGpOlnqWs9XHig5MDDLyGsU= 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 1657660860770579.1843280111434; Tue, 12 Jul 2022 14:21:00 -0700 (PDT) Received: from localhost ([::1]:53954 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNJT-0004Bk-P4 for importer@patchew.org; Tue, 12 Jul 2022 17:20:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34098) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHv-0001kI-MF for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:54546) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHs-0002Gp-Fc for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:23 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-91-QUwRMY_6P2-4i11lsLqDgw-1; Tue, 12 Jul 2022 17:19:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DEF67294EDC5; Tue, 12 Jul 2022 21:19:16 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id F29AE2166B2F; Tue, 12 Jul 2022 21:19:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660759; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xamwRQcHxp0nHCghcr5xA3P05s95yhuo/GJ5eC+ybY4=; b=DQkr4dwR5PXKtwTcy7mfNA8k5vcUfTptOpAG2yzIVt8oQDlAGYvBedsJhiATjC9wyuI6D4 iP0lTu8kscI3tt0Xhka+9prUWz+jwU6+38KVj7vZOO2gU+TQ33EcnTBofRUI63cTzwVznP /x8dxsX6mdNeM8KEAZTGZHHUyNHVHG0= X-MC-Unique: QUwRMY_6P2-4i11lsLqDgw-1 From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 2/8] transactions: add tran_add_back Date: Tue, 12 Jul 2022 17:19:05 -0400 Message-Id: <20220712211911.1302836-3-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1657660862929100004 Content-Type: text/plain; charset="utf-8" First change the transactions from a QLIST to QSIMPLEQ, then use it to implement tran_add_tail, which allows adding elements to the end of list transactions. This is useful if we have some "preparation" transiction callbacks that we want to run before the others but still only when invoking finalize/commit/abort. For example (A and B are lists transaction callbacks): for (i=3D0; i < 3; i++) { tran_add(A[i]); tran_add_tail(B[i]); } tran_commit(); Will process transactions in this order: A2 - A1 - A0 - B0 - B1 - B2 Signed-off-by: Emanuele Giuseppe Esposito Suggested-by: Paolo Bonzini --- include/qemu/transactions.h | 9 +++++++++ util/transactions.c | 29 +++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/include/qemu/transactions.h b/include/qemu/transactions.h index 2f2060acd9..42783720b9 100644 --- a/include/qemu/transactions.h +++ b/include/qemu/transactions.h @@ -50,7 +50,16 @@ typedef struct TransactionActionDrv { typedef struct Transaction Transaction; =20 Transaction *tran_new(void); +/* + * Add transaction at the beginning of the transaction list. + * @tran will be the first transaction to be processed in finalize/commit/= abort. + */ void tran_add(Transaction *tran, TransactionActionDrv *drv, void *opaque); +/* + * Add transaction at the end of the transaction list. + * @tran will be the last transaction to be processed in finalize/commit/a= bort. + */ +void tran_add_tail(Transaction *tran, TransactionActionDrv *drv, void *opa= que); void tran_abort(Transaction *tran); void tran_commit(Transaction *tran); =20 diff --git a/util/transactions.c b/util/transactions.c index 2dbdedce95..89e541c4a4 100644 --- a/util/transactions.c +++ b/util/transactions.c @@ -28,18 +28,18 @@ typedef struct TransactionAction { TransactionActionDrv *drv; void *opaque; - QSLIST_ENTRY(TransactionAction) entry; + QSIMPLEQ_ENTRY(TransactionAction) entry; } TransactionAction; =20 struct Transaction { - QSLIST_HEAD(, TransactionAction) actions; + QSIMPLEQ_HEAD(, TransactionAction) actions; }; =20 Transaction *tran_new(void) { Transaction *tran =3D g_new(Transaction, 1); =20 - QSLIST_INIT(&tran->actions); + QSIMPLEQ_INIT(&tran->actions); =20 return tran; } @@ -54,20 +54,33 @@ void tran_add(Transaction *tran, TransactionActionDrv *= drv, void *opaque) .opaque =3D opaque }; =20 - QSLIST_INSERT_HEAD(&tran->actions, act, entry); + QSIMPLEQ_INSERT_HEAD(&tran->actions, act, entry); +} + +void tran_add_tail(Transaction *tran, TransactionActionDrv *drv, void *opa= que) +{ + TransactionAction *act; + + act =3D g_new(TransactionAction, 1); + *act =3D (TransactionAction) { + .drv =3D drv, + .opaque =3D opaque + }; + + QSIMPLEQ_INSERT_TAIL(&tran->actions, act, entry); } =20 void tran_abort(Transaction *tran) { TransactionAction *act, *next; =20 - QSLIST_FOREACH(act, &tran->actions, entry) { + QSIMPLEQ_FOREACH(act, &tran->actions, entry) { if (act->drv->abort) { act->drv->abort(act->opaque); } } =20 - QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) { + QSIMPLEQ_FOREACH_SAFE(act, &tran->actions, entry, next) { if (act->drv->clean) { act->drv->clean(act->opaque); } @@ -82,13 +95,13 @@ void tran_commit(Transaction *tran) { TransactionAction *act, *next; =20 - QSLIST_FOREACH(act, &tran->actions, entry) { + QSIMPLEQ_FOREACH(act, &tran->actions, entry) { if (act->drv->commit) { act->drv->commit(act->opaque); } } =20 - QSLIST_FOREACH_SAFE(act, &tran->actions, entry, next) { + QSIMPLEQ_FOREACH_SAFE(act, &tran->actions, entry, next) { if (act->drv->clean) { act->drv->clean(act->opaque); } --=20 2.31.1 From nobody Mon Feb 9 19:30:24 2026 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=1657661283; cv=none; d=zohomail.com; s=zohoarc; b=TLMFPUEyYKYlQhdbr7SxvkYBKqPn47vS2VuCkyqrTLfGUOxmMOovE51ArYNOPKGCBRAJc2EQ6XBlHIhpZ5iWndj359kJ3ohn8giZ+BzzSvZpYUmHgWpfBcdSTrpC/uCnpfEYy/X8n9VukJFy28+W8gDVNqei4qHHjGdFdqMWKDM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657661283; 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=WWecrIp5grNRw02rHzhY/pOKGKu5Ck6LqGuw+60u3jA=; b=fkdD0ZSM4rCLPzFBrWCHe5QQobwNQNA7HeeFkRGLeUYzIQAniJ3+LuSyx9qZ7mleAE67owQrFzyZCr+0xHqKQCX9BEn7IJLPIPSru09i4HAZvll/31tdClDk0WOqCOV2bmSy5+x4vsWYL1VjBKSf1XquhNJy9C8bWjsJHKLD+UU= 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 1657661283048713.0572338838109; Tue, 12 Jul 2022 14:28:03 -0700 (PDT) Received: from localhost ([::1]:41402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNQH-0006qb-5j for importer@patchew.org; Tue, 12 Jul 2022 17:28:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34706) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNIL-0002uv-9g for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:28452) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNI0-0002Ls-7B for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:49 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-516-bpfnTv5-P6ek1aI8kEkeXQ-1; Tue, 12 Jul 2022 17:19:18 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AF930101A595; Tue, 12 Jul 2022 21:19:17 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA3582166B2A; Tue, 12 Jul 2022 21:19:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660767; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WWecrIp5grNRw02rHzhY/pOKGKu5Ck6LqGuw+60u3jA=; b=Rl0pX8LsUJvykHXhlbyRh+UfrE2wMh/ZU656NaMnGD1SMz/Ss2kWUXgx2CxzXM8V2V6q0q 5EO0u9G7UOyRcdaIeESv2R+q8ELCY+NObu3jY078khCWjSRsnIeoacjJTlh7Yf+d7Iun5P /fcXXFYuAWWvCUUQ+cPdxCyCAdvK/QI= X-MC-Unique: bpfnTv5-P6ek1aI8kEkeXQ-1 From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 3/8] RFC: block: use transactions as a replacement of ->{can_}set_aio_context() Date: Tue, 12 Jul 2022 17:19:06 -0400 Message-Id: <20220712211911.1302836-4-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1657661283515100001 Content-Type: text/plain; charset="utf-8" Suggested-by: Paolo Bonzini --------- RFC because I am not sure about the AioContext locks. - Do we need to take the new AioContext lock? what does it protect? - Taking the old AioContext lock is required now, because of bdrv_drained_begin calling AIO_WAIT_WHILE that unlocks the aiocontext. If we replace it with AIO_WAIT_WHILE_UNLOCKED, could we get rid of taking every time the old AioContext? drain would be enough to protect the graph modification. ---------- Simplify the way the aiocontext can be changed in a BDS graph. There are currently two problems in bdrv_try_set_aio_context: - There is a confusion of AioContext locks taken and released, because we assume that old aiocontext is always taken and new one is taken inside. - It doesn't look very safe to call bdrv_drained_begin while some nodes have already switched to the new aiocontext and others haven't. This could be especially dangerous because bdrv_drained_begin polls, so something else could be executed while graph is in an inconsistent state. Additional minor nitpick: can_set and set_ callbacks both traverse the graph, both using the ignored list of visited nodes in a different way. Therefore, get rid of all of this and introduce a new callback, change_aio_context, that uses transactions to efficiently, cleanly and most importantly safely change the aiocontext of a graph. This new callback is a "merge" of the two previous ones: - Just like can_set_aio_context, recursively traverses the graph. Marks all nodes that are visited using a GList, and checks if they *could* change the aio_context. - For each node that passes the above check, add a new transaction that implements a callback that effectively changes the aiocontext. - If a node is a BDS, add two transactions: one taking care of draining the node at the beginning of the list (so that will be executed first) and one at the end taking care of changing the AioContext. - Once done, the recursive function returns if *all* nodes can change the AioContext. If so, commit the above transactions. Otherwise don't do anything. - The transaction list contains first all "drain" transactions, so we are sure we are draining all nodes in the same context, and then all the other switch the AioContext. In this way we make sure that bdrv_drained_begin() is always called under the old AioContext, and bdrv_drained_end() under the new one. - Because of the above, we don't need to release and re-acquire the old AioContext every time, as everything is done once (and not per-node drain and aiocontext change). Note that the "change" API is not yet invoked anywhere. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 197 +++++++++++++++++++++++++++++ include/block/block-global-state.h | 9 ++ include/block/block_int-common.h | 3 + 3 files changed, 209 insertions(+) diff --git a/block.c b/block.c index 267a39c0de..bda4e1bcef 100644 --- a/block.c +++ b/block.c @@ -7437,6 +7437,51 @@ static bool bdrv_parent_can_set_aio_context(BdrvChil= d *c, AioContext *ctx, return true; } =20 +typedef struct BdrvStateSetAioContext { + AioContext *new_ctx; + BlockDriverState *bs; +} BdrvStateSetAioContext; + +/* + * Changes the AioContext used for fd handlers, timers, and BHs by this + * BlockDriverState and all its children and parents. + * + * Must be called from the main AioContext. + * + * The caller must own the AioContext lock for the old AioContext of bs, b= ut it + * must not own the AioContext lock for new_context (unless new_context is= the + * same as the current context of bs). + * + * @visited will accumulate all visited BdrvChild object. The caller is + * responsible for freeing the list afterwards. + */ +static bool bdrv_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) { @@ -7448,6 +7493,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, @@ -7475,6 +7532,99 @@ bool bdrv_can_set_aio_context(BlockDriverState *bs, = AioContext *ctx, return true; } =20 +static void bdrv_drained_begin_commit(void *opaque) +{ + BdrvStateSetAioContext *state =3D (BdrvStateSetAioContext *) opaque; + + /* Paired with bdrv_drained_end in bdrv_drained_end_clean() */ + bdrv_drained_begin(state->bs); +} + +static void bdrv_drained_end_clean(void *opaque) +{ + BdrvStateSetAioContext *state =3D (BdrvStateSetAioContext *) opaque; + BlockDriverState *bs =3D (BlockDriverState *) state->bs; + AioContext *new_context =3D state->new_ctx; + + /* + * drain only if bdrv_drained_begin_commit() and + * bdrv_set_aio_context_commit() executed + */ + if (bdrv_get_aio_context(bs) =3D=3D new_context) { + /* Paired with bdrv_drained_begin in bdrv_drained_begin_commit() */ + bdrv_drained_end(bs); + } + + /* state is freed by set_aio_context->clean() */ +} + +static void bdrv_set_aio_context_commit(void *opaque) +{ + BdrvStateSetAioContext *state =3D (BdrvStateSetAioContext *) opaque; + BlockDriverState *bs =3D (BlockDriverState *) state->bs; + AioContext *new_context =3D state->new_ctx; + assert_bdrv_graph_writable(bs); + + bdrv_detach_aio_context(bs); + bdrv_attach_aio_context(bs, new_context); +} + +static TransactionActionDrv set_aio_context =3D { + .commit =3D bdrv_set_aio_context_commit, + .clean =3D g_free, +}; + +static TransactionActionDrv drained_begin_end =3D { + .commit =3D bdrv_drained_begin_commit, + .clean =3D bdrv_drained_end_clean, +}; + +/* + * @visited will accumulate all visited BdrvChild object. The caller is + * responsible for freeing the list afterwards. + */ +bool bdrv_change_aio_context(BlockDriverState *bs, AioContext *ctx, + GSList **visited, Transaction *tran, + Error **errp) +{ + BdrvChild *c; + BdrvStateSetAioContext *state; + + GLOBAL_STATE_CODE(); + + if (bdrv_get_aio_context(bs) =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, + }; + + /* First half of transactions are drains */ + tran_add(tran, &drained_begin_end, state); + /* + * Second half of transactions takes care of setting the + * AioContext and free the state + */ + tran_add_tail(tran, &set_aio_context, state); + + return true; +} + int bdrv_child_try_set_aio_context(BlockDriverState *bs, AioContext *ctx, BdrvChild *ignore_child, Error **errp) { @@ -7498,6 +7648,53 @@ int bdrv_child_try_set_aio_context(BlockDriverState = *bs, AioContext *ctx, return 0; } =20 +/* + * First, go recursively through all nodes in the graph, and see if they + * can change their AioContext. + * If so, add for each node a new transaction with a callback to change the + * AioContext with the new one. + * Once recursion is completed, if all nodes are allowed to change their + * AioContext then commit the transaction, running all callbacks in order. + * Otherwise don't do anything. + * + * This function still requires the caller to take the bs current + * AioContext lock, otherwise draining could fail since AIO_WAIT_WHILE + * assumes the lock is always held if bs is in another AioContext. + */ +int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ct= x, + BdrvChild *ignore_child, Error **err= p) +{ + Transaction *tran; + GSList *visited; + int ret; + GLOBAL_STATE_CODE(); + + 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); + + if (!ret) { + /* just run clean() callbacks */ + tran_abort(tran); + return -EPERM; + } + + /* Acquire the new context, if necessary */ + /* TODO: why do we need to take this AioContext lock? */ + if (qemu_get_aio_context() !=3D ctx) { + aio_context_acquire(ctx); + } + + tran_commit(tran); + + if (qemu_get_aio_context() !=3D ctx) { + aio_context_release(ctx); + } + + return 0; +} + int bdrv_try_set_aio_context(BlockDriverState *bs, AioContext *ctx, Error **errp) { diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 21265e3966..5847b64f95 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -229,6 +229,15 @@ bool bdrv_can_set_aio_context(BlockDriverState *bs, 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); +bool bdrv_change_aio_context(BlockDriverState *bs, AioContext *ctx, + GSList **visited, Transaction *tran, + Error **errp); +int bdrv_child_try_change_aio_context(BlockDriverState *bs, AioContext *ct= x, + BdrvChild *ignore_child, Error **err= p); + int bdrv_probe_blocksizes(BlockDriverState *bs, BlockSizes *bsz); int bdrv_probe_geometry(BlockDriverState *bs, HDGeometry *geo); =20 diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 8947abab76..b35a0fe840 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -896,6 +896,9 @@ struct BdrvChildClass { GSList **ignore, Error **errp); void (*set_aio_ctx)(BdrvChild *child, AioContext *ctx, GSList **ignore= ); =20 + bool (*change_aio_ctx)(BdrvChild *child, AioContext *ctx, + GSList **ignore, Transaction *tran, Error **err= p); + AioContext *(*get_parent_aio_context)(BdrvChild *child); =20 /* --=20 2.31.1 From nobody Mon Feb 9 19:30:24 2026 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=1657660989; cv=none; d=zohomail.com; s=zohoarc; b=gCtvuGYS+Da6PcT1ZuO1UA35LtzY+vMiMMcSuAMcKdBPHEj3y3/0K2VuF8r+0+VeK7vBEIc4baZoKWn7zpfXjKYJsX4HWnvo0sHezBz3TixaYNMmvqq0X9iGyHTPXmfZzMrG/w0ckXwH+RINQaa/2vbuUaGTJRQCL+RcXM6Zilo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657660989; 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=56ZSNQhnjAShwuCvHPubrJxnlWw8xkVVKANfX2Rx2X8=; b=g40zRHwVbdfSiAZsQBGqMQhPqyc+URlpJ9DR7xQVgbpAQI2pNRX56M9TGOkL9GTv16BiHo+g3IjMvCJO+fYn2Xr6nizQKmv3kXoys28ewdJ5NrZIrhVrcub3kUAJW0u2LTq9RNs+J2adeVtKN/dH2daMzoDaa118pk3DEi2t+Cs= 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 1657660989413267.3471155525949; Tue, 12 Jul 2022 14:23:09 -0700 (PDT) Received: from localhost ([::1]:59764 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNLY-00005v-6v for importer@patchew.org; Tue, 12 Jul 2022 17:23:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34116) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHw-0001l6-5d for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:24 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:41950) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHt-0002H8-3z for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:22 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-49-Cq2GA6iiOB-mvxj4Sp5GAQ-1; Tue, 12 Jul 2022 17:19:19 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 82E55811E76; Tue, 12 Jul 2022 21:19:18 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8F8B02166B30; Tue, 12 Jul 2022 21:19:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660760; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=56ZSNQhnjAShwuCvHPubrJxnlWw8xkVVKANfX2Rx2X8=; b=ekH1TUA5dHZ8JECbUd5CObHtAW6dz8oiRW/qwxgBbIhW+fpH9fPCQGx0T/rnjzvQzadQ1d CVEQxZOKElKd8NdRcYWF/Aqv7jJhz1AfQAL8b4oHDD9aMz3jFf9yndnLDyptD596pww2Lc 68ouwigQsHjZmM2ShNSN4GmHRICGPIs= X-MC-Unique: Cq2GA6iiOB-mvxj4Sp5GAQ-1 From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 4/8] blockjob: implement .change_aio_ctx in child_job Date: Tue, 12 Jul 2022 17:19:07 -0400 Message-Id: <20220712211911.1302836-5-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1657660991535100001 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 Suggested-by: Paolo Bonzini --- blockjob.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/blockjob.c b/blockjob.c index bb82e8d04c..9e26b06ed4 100644 --- a/blockjob.c +++ b/blockjob.c @@ -124,6 +124,50 @@ static void child_job_drained_end(BdrvChild *c, int *d= rained_end_counter) } } =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, + GSList **visited, Transaction *tran, + 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_tail(tran, &change_child_job_context, s); + return true; +} + static bool child_job_can_set_aio_ctx(BdrvChild *c, AioContext *ctx, GSList **ignore, Error **errp) { @@ -172,6 +216,7 @@ static const BdrvChildClass child_job =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 Mon Feb 9 19:30:24 2026 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=1657660998; cv=none; d=zohomail.com; s=zohoarc; b=FxOlKR8QUxlgW+17XllVWiXAFO2P7qANvlygY/qHYPImhlX6dz0BxkazcsP+7h4QfgyTmO79RifNYZ7zV5CoLTN/tXHEV1h4tgzZuhATXHxXrUGNUPybUvjnNyw2+/JH4xak+2QkNA/FUIIVJL9Dn5TomSnuQqVnzTmsdl1YNUc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657660998; 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=vKwPjhdkN7wHkXjdTPsWAmHmdOEoydYRqskDnLyohWw=; b=m9dmBe1zM2YrJ9uYwpTbJm1bneGOL8PlnbYJqa5xs+sjzjbuywoiCvuHtf7ihhTjB1QgIKh+D9ifb6Q/9spldbZ2rueKsvM1BglQQh6x32qFm/UMD88/XExmbLIXZdqSIZYzKqvQvTjsf7OxRZghQ52M8EJcERqaKT5TrDTi2Ag= 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 1657660998523473.1892721693523; Tue, 12 Jul 2022 14:23:18 -0700 (PDT) Received: from localhost ([::1]:60226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNLh-0000Ql-IW for importer@patchew.org; Tue, 12 Jul 2022 17:23:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNII-0002um-Vf for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:41950) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHw-0002JM-Rf for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:46 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-90-Lk2Pw80dNp2KGk9g7-HMZw-1; Tue, 12 Jul 2022 17:19:19 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4B5BE38041DA; Tue, 12 Jul 2022 21:19:19 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 50A3A2166B2A; Tue, 12 Jul 2022 21:19:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660762; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vKwPjhdkN7wHkXjdTPsWAmHmdOEoydYRqskDnLyohWw=; b=EB3cGdp3LvqcxS30vrCPTwAzbssxL2tkE3xXLA/TZ4oQXiCiIvS3oMSLG+9bG7ma4G6vb2 Fz5qWrhFr5TbQ0R8Zt3YN0VKpWpcO3r7/Yl1OfFoCnZjXaY6HEXhPUjBivmLHsK5pvYeuN 5UmDSXPhMWS4lctTDiqvIyYCSVCNOcI= X-MC-Unique: Lk2Pw80dNp2KGk9g7-HMZw-1 From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 5/8] block: implement .change_aio_ctx in child_of_bds Date: Tue, 12 Jul 2022 17:19:08 -0400 Message-Id: <20220712211911.1302836-6-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1657660999603100003 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 Suggested-by: Paolo Bonzini --- block.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/block.c b/block.c index bda4e1bcef..a7ba590dfa 100644 --- a/block.c +++ b/block.c @@ -1235,6 +1235,14 @@ static int bdrv_child_cb_inactivate(BdrvChild *child) return 0; } =20 +static bool bdrv_child_cb_change_aio_ctx(BdrvChild *child, AioContext *ctx, + GSList **visited, Transaction *tr= an, + 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) { @@ -1491,6 +1499,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 Mon Feb 9 19:30:24 2026 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=1657661257; cv=none; d=zohomail.com; s=zohoarc; b=LnmRZXI3oTnfnF7PRTBOn580n76aO84zxv8rOcHU/CY92guUY/bjJGne1kB1jBiwFjBDaZnNgKsJDwVySoSxGpAsc5xVf0IVrGHLCGIn+cUs9M8CZpqvGn6qQQPbN17Cyw83du2OnJl0+LWwOJueFhjqzpoIS+IrkL+ROwFS8Ag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657661257; 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=NpvCvejhmqLiBfSx0m/ogEG5b5mXA0Q5Q2NrIbV4hTE=; b=SGYBZn92+x5MMk5KBEf8iNZVvdj6fOMH/0NuubhvTtf6J+EVLEO/PwiG4flFmtWTsqMduJfz2WILgXQKrpGsAQM3WEtfh/EhV4UuyIDAirovHvykEzZaVkW32lSRxJKtLQ+dbcJAqJrUrmpd2XqTY5z5OJPxso6CsRfxN8gSfB0= 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 1657661257374505.98211342910895; Tue, 12 Jul 2022 14:27:37 -0700 (PDT) Received: from localhost ([::1]:40012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNPr-0005uw-JD for importer@patchew.org; Tue, 12 Jul 2022 17:27:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNIM-0002wM-Fr for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:51 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56966) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNI2-0002Mp-7U for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:49 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-146-rxJZJ1E3OnmQF2k_j_PVWg-1; Tue, 12 Jul 2022 17:19:20 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9E67C101A58E; Tue, 12 Jul 2022 21:19:19 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id BEA952166B2F; Tue, 12 Jul 2022 21:19:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660769; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NpvCvejhmqLiBfSx0m/ogEG5b5mXA0Q5Q2NrIbV4hTE=; b=ggvO/rtj7k4+jdS+7heJrakOIhRTWF6woa0DHSML1qElfGagj9tHCSSwEgI8P3bfyP/IPm 0CgtxXR2H/KEm6i64hE3Zmly98d8jA196Q79tQvwT2+K1+91IRSYbcdtm4g62XMIcgqIVQ tQXPGjUWOxP7iVJINWouXVyPi00aBKc= X-MC-Unique: rxJZJ1E3OnmQF2k_j_PVWg-1 From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 6/8] block-backend: implement .change_aio_ctx in child_root Date: Tue, 12 Jul 2022 17:19:09 -0400 Message-Id: <20220712211911.1302836-7-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1657661259300100001 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 Suggested-by: Paolo Bonzini --- block/block-backend.c | 54 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/block/block-backend.c b/block/block-backend.c index f425b00793..674eaaa2bf 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -138,6 +138,9 @@ static bool blk_root_can_set_aio_ctx(BdrvChild *child, = AioContext *ctx, GSList **ignore, Error **errp); static void blk_root_set_aio_ctx(BdrvChild *child, AioContext *ctx, GSList **ignore); +static bool blk_root_change_aio_ctx(BdrvChild *child, AioContext *ctx, + GSList **visited, Transaction *tran, + Error **errp); =20 static char *blk_root_get_parent_desc(BdrvChild *child) { @@ -336,6 +339,7 @@ static const BdrvChildClass child_root =3D { =20 .can_set_aio_ctx =3D blk_root_can_set_aio_ctx, .set_aio_ctx =3D blk_root_set_aio_ctx, + .change_aio_ctx =3D blk_root_change_aio_ctx, =20 .get_parent_aio_context =3D blk_root_get_parent_aio_context, }; @@ -2208,6 +2212,56 @@ 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, + GSList **visited, Transaction *tran, + Error **errp) +{ + BlockBackend *blk =3D child->opaque; + BdrvStateBlkRootContext *s; + + if (blk->allow_aio_context_change) { + goto finish; + } + + /* + * 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; + } + +finish: + s =3D g_new(BdrvStateBlkRootContext, 1); + *s =3D (BdrvStateBlkRootContext) { + .new_ctx =3D ctx, + .blk =3D blk, + }; + + tran_add_tail(tran, &set_blk_root_context, s); + return true; +} + static bool blk_root_can_set_aio_ctx(BdrvChild *child, AioContext *ctx, GSList **ignore, Error **errp) { --=20 2.31.1 From nobody Mon Feb 9 19:30:24 2026 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=1657661160; cv=none; d=zohomail.com; s=zohoarc; b=WG2x8u2W+jo0URVCaICyp8DQkLsU8z63J7BL34Fy6Za/SRD3OjBqNXkarKDYkounhxg4+dx9Uf015HKwR+8NRyFUqbsYIrJjcd4EEHc44OehLRaT1GEy59JmQVFHAlTZokYMCDeYBwLdM2JH6mY34OIqQzC0IxTH+EKNDaMHsD4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657661160; 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=KybLU9IwFgMw2xhqFt7O9/VvMxuZ2cPdo4RsO4G9iaw=; b=Kma+g+vboLTyOVnyZ6w3VGrXeEb+KI8NWkPYCfh0rwmZMF81XoV0GjyRr7voGYrplFkdGgN8BsDq1GCYnno/gKgIKgA2kpC/N/Wglx6IwBblyaKswjIKvJcyQDp541PeImnCoooI+fon0OS1vdVzdzhS1dG+wgGyVp6yW/DYxvU= 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 165766116001939.80550145273435; Tue, 12 Jul 2022 14:26:00 -0700 (PDT) Received: from localhost ([::1]:35768 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNOJ-000300-0u for importer@patchew.org; Tue, 12 Jul 2022 17:25:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34628) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNIJ-0002un-1D for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52828) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHw-0002J7-RZ for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:46 -0400 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-584-SXNDNXHzNwibxhZnZjmj1A-1; Tue, 12 Jul 2022 17:19:21 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 76E341C05145; Tue, 12 Jul 2022 21:19:20 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 803482166B2A; Tue, 12 Jul 2022 21:19:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660762; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KybLU9IwFgMw2xhqFt7O9/VvMxuZ2cPdo4RsO4G9iaw=; b=MyatZ7D9tD1w34B33n1yjJqPIc5VzRneKZFrANBvzP+o0GNpr5wJvhSJzucpDv7WOtFqwN rpkiM1iqt4w/pCjVIcsbnheuSul0gK3PxFX2Cbhd57uWGeXIDEK3db9tXoKsP3O/Y2R+2u mcPpOR6c12qSb3j9vuiLPXw8p3Jl0ao= X-MC-Unique: SXNDNXHzNwibxhZnZjmj1A-1 From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 7/8] block: use the new _change_ API instead of _can_set_ and _set_ Date: Tue, 12 Jul 2022 17:19:10 -0400 Message-Id: <20220712211911.1302836-8-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1657661160848100001 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 Suggested-by: Paolo Bonzini --- block.c | 30 ++++++++++++++++-------------- block/block-backend.c | 8 ++++++-- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/block.c b/block.c index a7ba590dfa..101188a2d4 100644 --- a/block.c +++ b/block.c @@ -2966,17 +2966,18 @@ static void bdrv_attach_child_common_abort(void *op= aque) } =20 if (bdrv_child_get_parent_aio_context(child) !=3D s->old_parent_ctx) { + Transaction *tran; GSList *ignore; + bool ret; =20 - /* No need to ignore `child`, because it has been detached already= */ - ignore =3D NULL; - child->klass->can_set_aio_ctx(child, s->old_parent_ctx, &ignore, - &error_abort); - g_slist_free(ignore); + tran =3D tran_new(); =20 + /* No need to ignore `child`, because it has been detached already= */ ignore =3D NULL; - child->klass->set_aio_ctx(child, s->old_parent_ctx, &ignore); + ret =3D child->klass->change_aio_ctx(child, s->old_parent_ctx, &ig= nore, + tran, &error_abort); g_slist_free(ignore); + tran_finalize(tran, ret ? ret : -1); } =20 bdrv_unref(bs); @@ -3037,17 +3038,18 @@ static int bdrv_attach_child_common(BlockDriverStat= e *child_bs, Error *local_err =3D NULL; int ret =3D bdrv_try_set_aio_context(child_bs, parent_ctx, &local_= err); =20 - if (ret < 0 && child_class->can_set_aio_ctx) { + if (ret < 0 && child_class->change_aio_ctx) { + Transaction *tran =3D tran_new(); GSList *ignore =3D g_slist_prepend(NULL, new_child); - if (child_class->can_set_aio_ctx(new_child, child_ctx, &ignore, - NULL)) - { + bool ret_child; + + ret_child =3D child_class->change_aio_ctx(new_child, child_ctx, + &ignore, tran, NULL); + if (ret_child) { 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); } + tran_finalize(tran, ret_child ? ret_child : -1); g_slist_free(ignore); } =20 @@ -7708,7 +7710,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 674eaaa2bf..6e90ac3a6a 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2184,8 +2184,12 @@ static int blk_do_set_aio_context(BlockBackend *blk,= AioContext *new_context, bdrv_ref(bs); =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 Mon Feb 9 19:30:24 2026 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=1657661170; cv=none; d=zohomail.com; s=zohoarc; b=aYDnX+X7e4nvbBwYhqAeHYfkuLdAtt3kPp6v6yLc/6tDSzJcFf79nMhDnhW3KoNlhETgJo2DDiiWHZF9i0rm0wdv1bAfeqC8fGpK9rqu0AfFHm67ZtRPzTHEoSH86Zi5sFi4ewPwueJO9JCy8pm3UkT9MAR4XYiuNQL1qtO2s4g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657661170; 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=pePwG8ZwqKYsNfcZobAmGxdftqc/BwZCeZvQfQvX01I=; b=d1aAWOJuQGYDK6/vZVqhhLtbEXxdWW1Danq13hHrEv/BNmQltcguBpMKER1BGz8kJdGYh6PaLPhExhpZecpTPjjEsTjd1vK6izUCRtlWFuFHZZYDDj+g6lmYhe5rLhXxkPjht0ZHeIDBWKvQmMLP3SKgdgmiLrR1kXHVSjCXWFM= 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 1657661170206663.0348738936361; Tue, 12 Jul 2022 14:26:10 -0700 (PDT) Received: from localhost ([::1]:36374 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBNOS-0003Qx-9O for importer@patchew.org; Tue, 12 Jul 2022 17:26:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNIK-0002ut-PO for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:50 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:60985) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBNHx-0002L3-UT for qemu-devel@nongnu.org; Tue, 12 Jul 2022 17:19:48 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-669-cBaNBE9pO5CTXScsY0LqWg-1; Tue, 12 Jul 2022 17:19:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 672D11857F07; Tue, 12 Jul 2022 21:19:21 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 514F22166B30; Tue, 12 Jul 2022 21:19:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657660765; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pePwG8ZwqKYsNfcZobAmGxdftqc/BwZCeZvQfQvX01I=; b=DkoAZdCXQIvkGXKrGcz22pnLqlumLMfrqAp9/5JRzH+5uriAQ/7rsNwkiiHH1eZ/2fwgEQ l1yeoCVh55i/kkvc6r27CLdNqgvim9luEcel4C93zZHnPics/q1hjbTZZtAMJWU3tjrSjG Ht3qsaYQw/+clx1/9wDpplCaskjFALU= X-MC-Unique: cBaNBE9pO5CTXScsY0LqWg-1 From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Cc: Kevin Wolf , Hanna Reitz , John Snow , Stefan Hajnoczi , Paolo Bonzini , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Emanuele Giuseppe Esposito Subject: [RFC PATCH 8/8] block: remove all unused ->can_set_aio_ctx and ->set_aio_ctx callbacks Date: Tue, 12 Jul 2022 17:19:11 -0400 Message-Id: <20220712211911.1302836-9-eesposit@redhat.com> In-Reply-To: <20220712211911.1302836-1-eesposit@redhat.com> References: <20220712211911.1302836-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1657661170898100001 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 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 101188a2d4..d99784dff1 100644 --- a/block.c +++ b/block.c @@ -1243,20 +1243,6 @@ static bool bdrv_child_cb_change_aio_ctx(BdrvChild *= child, AioContext *ctx, return bdrv_change_aio_context(bs, ctx, visited, tran, errp); } =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 @@ -1497,8 +1483,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, @@ -7329,125 +7313,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 object. The caller is - * responsible for freeing the list afterwards. - */ -void bdrv_set_aio_context_ignore(BlockDriverState *bs, - AioContext *new_context, GSList **ignore) -{ - AioContext *old_context =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; @@ -7493,17 +7358,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, GSList **visited, Transaction *tran, Error **errp) @@ -7516,33 +7370,6 @@ bool bdrv_child_change_aio_context(BdrvChild *c, Aio= Context *ctx, return bdrv_change_aio_context(c->bs, ctx, visited, tran, errp); } =20 -/* @ignore will accumulate all visited BdrvChild object. The caller is - * responsible for freeing the list afterwards. */ -bool bdrv_can_set_aio_context(BlockDriverState *bs, AioContext *ctx, - GSList **ignore, Error **errp) -{ - BdrvChild *c; - - if (bdrv_get_aio_context(bs) =3D=3D ctx) { - return true; - } - - GLOBAL_STATE_CODE(); - - QLIST_FOREACH(c, &bs->parents, next_parent) { - if (!bdrv_parent_can_set_aio_context(c, ctx, ignore, errp)) { - return false; - } - } - QLIST_FOREACH(c, &bs->children, next) { - if (!bdrv_child_can_set_aio_context(c, ctx, ignore, errp)) { - return false; - } - } - - return true; -} - static void bdrv_drained_begin_commit(void *opaque) { BdrvStateSetAioContext *state =3D (BdrvStateSetAioContext *) opaque; @@ -7636,29 +7463,6 @@ bool bdrv_change_aio_context(BlockDriverState *bs, A= ioContext *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; -} - /* * First, go recursively through all nodes in the graph, and see if they * can change their AioContext. diff --git a/block/block-backend.c b/block/block-backend.c index 6e90ac3a6a..9925663ca1 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -134,10 +134,6 @@ static void blk_root_drained_end(BdrvChild *child, int= *drained_end_counter); static void blk_root_change_media(BdrvChild *child, bool load); static void blk_root_resize(BdrvChild *child); =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, GSList **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, @@ -2266,33 +2260,6 @@ finish: 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 9e26b06ed4..219a444108 100644 --- a/blockjob.c +++ b/blockjob.c @@ -168,39 +168,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; @@ -214,8 +181,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 5847b64f95..65262781ab 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -217,18 +217,9 @@ void coroutine_fn bdrv_co_lock(BlockDriverState *bs); */ void coroutine_fn bdrv_co_unlock(BlockDriverState *bs); =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, GSList **visited, Transaction *tran, Error **errp); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index b35a0fe840..3c0e059602 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -892,10 +892,6 @@ struct BdrvChildClass { int (*update_filename)(BdrvChild *child, BlockDriverState *new_base, const char *filename, Error **errp); =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, GSList **ignore, Transaction *tran, Error **err= p); =20 --=20 2.31.1