From nobody Mon Feb 9 12:46:11 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=1646414698; cv=none; d=zohomail.com; s=zohoarc; b=ItjiBREDgexpzjvrI/3cDF9e3fkyIqBMxzyEKKTlA97QwgOycihCgqzZvSz+UHmuYPWCoWRwU4LwsoYL4/UrgSSHHP3mXShNPqipwfw0ZzxWuGk+kzqRmv+0VJiH9cCU69GbCmhjSnaxiFWpTXx2JM3+TCC5MnFzFVjxwWzQGVg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1646414698; h=Content-Type: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=lwdYSln28P0cgho2n9dOjg1ckh7jWGmPCv0bJAJkjRs=; b=mYLeqgL0fE+/Q7o3gsguDjIdZIFceiQ//aX7Gm4rGAAj3uXqRbaOjoYXzenj8dz5t2u10Goh8q83FY2eLGoWaJ96j6YEVWYYvkW8lChmyNlT8vuUsAxrucVAaqp3vGBf8IAyVV/6hyc+t+w6Cs7gYoWglaluwu/+i5jdUFXMsCk= 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 164641469865846.966109536765885; Fri, 4 Mar 2022 09:24:58 -0800 (PST) Received: from localhost ([::1]:38936 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nQBfl-00061A-Ji for importer@patchew.org; Fri, 04 Mar 2022 12:24:57 -0500 Received: from eggs.gnu.org ([209.51.188.92]:52188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQB65-0005e5-0x for qemu-devel@nongnu.org; Fri, 04 Mar 2022 11:48:06 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:21538) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nQB60-0007UQ-Fl for qemu-devel@nongnu.org; Fri, 04 Mar 2022 11:48:02 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-515-oJ8kLsqfOQWy6cGFvKG5LA-1; Fri, 04 Mar 2022 11:47:54 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B22FA180FD72; Fri, 4 Mar 2022 16:47:52 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.194.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5F4383BF9; Fri, 4 Mar 2022 16:47:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1646412479; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lwdYSln28P0cgho2n9dOjg1ckh7jWGmPCv0bJAJkjRs=; b=QjEUI4wxVp8KybbHMcg3/l+CJJqNIR/g+wg8L43grd3p0YXSuDgvkURQFmbQka+mem56UQ 0kEWb8yrt3XFpvcTvE7XyDUl5st5WPrDSf0vzSoP/G/UDxYH4fr+xASKxIJxs5A/762MH0 yok72DIW3VotEAkYM4krXj2zApq2lws= X-MC-Unique: oJ8kLsqfOQWy6cGFvKG5LA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 27/50] block: introduce assert_bdrv_graph_writable Date: Fri, 4 Mar 2022 17:46:48 +0100 Message-Id: <20220304164711.474713-28-kwolf@redhat.com> In-Reply-To: <20220304164711.474713-1-kwolf@redhat.com> References: <20220304164711.474713-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, 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: , Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1646414699817100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito We want to be sure that the functions that write the child and parent list of a bs are under BQL and drain. BQL prevents from concurrent writings from the GS API, while drains protect from I/O. TODO: drains are missing in some functions using this assert. Therefore a proper assertion will fail. Because adding drains requires additional discussions, they will be added in future series. Signed-off-by: Emanuele Giuseppe Esposito Message-Id: <20220303151616.325444-15-eesposit@redhat.com> Signed-off-by: Kevin Wolf --- include/block/block_int-global-state.h | 17 +++++++++++++++++ block.c | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/include/block/block_int-global-state.h b/include/block/block_i= nt-global-state.h index 5078d6a6ea..0f21b0570b 100644 --- a/include/block/block_int-global-state.h +++ b/include/block/block_int-global-state.h @@ -309,4 +309,21 @@ void bdrv_remove_aio_context_notifier(BlockDriverState= *bs, */ void bdrv_drain_all_end_quiesce(BlockDriverState *bs); =20 +/** + * Make sure that the function is running under both drain and BQL. + * The latter protects from concurrent writings + * from the GS API, while the former prevents concurrent reads + * from I/O. + */ +static inline void assert_bdrv_graph_writable(BlockDriverState *bs) +{ + /* + * TODO: this function is incomplete. Because the users of this + * assert lack the necessary drains, check only for BQL. + * Once the necessary drains are added, + * assert also for qatomic_read(&bs->quiesce_counter) > 0 + */ + assert(qemu_in_main_thread()); +} + #endif /* BLOCK_INT_GLOBAL_STATE */ diff --git a/block.c b/block.c index f2a7350548..fe05df471a 100644 --- a/block.c +++ b/block.c @@ -1420,6 +1420,7 @@ static void bdrv_child_cb_attach(BdrvChild *child) { BlockDriverState *bs =3D child->opaque; =20 + assert_bdrv_graph_writable(bs); QLIST_INSERT_HEAD(&bs->children, child, next); =20 if (child->role & BDRV_CHILD_COW) { @@ -1439,6 +1440,7 @@ static void bdrv_child_cb_detach(BdrvChild *child) =20 bdrv_unapply_subtree_drain(child, bs); =20 + assert_bdrv_graph_writable(bs); QLIST_REMOVE(child, next); } =20 @@ -2829,6 +2831,7 @@ static void bdrv_replace_child_noperm(BdrvChild **chi= ldp, if (child->klass->detach) { child->klass->detach(child); } + assert_bdrv_graph_writable(old_bs); QLIST_REMOVE(child, next_parent); } =20 @@ -2838,6 +2841,7 @@ static void bdrv_replace_child_noperm(BdrvChild **chi= ldp, } =20 if (new_bs) { + assert_bdrv_graph_writable(new_bs); QLIST_INSERT_HEAD(&new_bs->parents, child, next_parent); =20 /* --=20 2.35.1