From nobody Mon May 13 23:33:56 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=1677178439; cv=none; d=zohomail.com; s=zohoarc; b=Dt7f6NEIZbQtWNnFo3tgvk2aXmy2CzHHxoY9a0KOA1nDQ3i9OlJ/MCSz9WYk4Rop+CeqCyCZQd04QZ2ICQx+yms8gYA8G9GyzaAbXrEek2iYml9ViK3BkFElsHjZRr50j9DzfApZmbCxh32qTp59LTI3sYCEPUTVTmEcPcCNbaE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178439; 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=5FvBBZeRjtNw67/DCFkZuO/ETPX1qY4CPmmC2EXKCEM=; b=Ik9ytUxdERLhuiVjoXcTjLKudPtIGtVM3RwbXMjYRaU+R9KukIRuADYSV6bV9g5huDVreDUKcWnublSTUMiFVuUa9aNXpRMdXLgB22TOLbvV1ZevovVcqtHs1QiO+KGTUxAnIpWyjeOXYMDIW9p+EVI5RyIu4jm9XQnbt/+AsJg= 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 167717843933367.09043756840697; Thu, 23 Feb 2023 10:53:59 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhG-0006kD-7I; Thu, 23 Feb 2023 13:52:02 -0500 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 1pVGhF-0006jJ-3k for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:01 -0500 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 1pVGhD-0002r8-7P for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:00 -0500 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-492-UwEU6hyRP56YyUkO-aPf1A-1; Thu, 23 Feb 2023 13:51:52 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8CB3B802D38; Thu, 23 Feb 2023 18:51:52 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id D26BB1121314; Thu, 23 Feb 2023 18:51:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178317; 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=5FvBBZeRjtNw67/DCFkZuO/ETPX1qY4CPmmC2EXKCEM=; b=FhXQNs4R78qWhqH/lMIM7I45RTpAZp+806mxA7K52xxqXFkAsnlPpw74Lg40sLGRGgC6/W IUyAJQqhS2EM5il8G/wbPT1HK9g47gV7/vF8JjjZyNUklmMZVtA2d53kiG5mUIPVotxbRe Ot/Nl/HlGTkeMooYkC1kU8s4l+nOrnA= X-MC-Unique: UwEU6hyRP56YyUkO-aPf1A-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 01/29] block: Make bdrv_can_set_read_only() static Date: Thu, 23 Feb 2023 19:51:18 +0100 Message-Id: <20230223185146.306454-2-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178440816100009 Content-Type: text/plain; charset="utf-8" It is never called outside of block.c. Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-2-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf --- include/block/block-io.h | 2 -- block.c | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 614cbd7eda..f9fa88204d 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -134,8 +134,6 @@ int bdrv_is_allocated_above(BlockDriverState *top, Bloc= kDriverState *base, int coroutine_fn bdrv_co_is_zero_fast(BlockDriverState *bs, int64_t offset, int64_t bytes); =20 -int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, - bool ignore_allow_rdw, Error **errp); int bdrv_apply_auto_read_only(BlockDriverState *bs, const char *errmsg, Error **errp); bool bdrv_is_read_only(BlockDriverState *bs); diff --git a/block.c b/block.c index 0c807d15cd..31f13092cb 100644 --- a/block.c +++ b/block.c @@ -277,8 +277,8 @@ bool bdrv_is_read_only(BlockDriverState *bs) return !(bs->open_flags & BDRV_O_RDWR); } =20 -int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, - bool ignore_allow_rdw, Error **errp) +static int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, + bool ignore_allow_rdw, Error **errp) { IO_CODE(); =20 --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178361; cv=none; d=zohomail.com; s=zohoarc; b=m6+43KgeZtxxyFmLqbtgm1oV/KaUFPjVqvtwPFY9+Gzjam+7zgiW8vC7L1xt0ziTJdDLkf16aDFjLRFaGvZPBk3bkzs27ac30ccyrqEEsGQU4Sb3vroOct7e3nL+Kb1VWVOx740p9fQsUnMOeHLUUE7XVCkP2/OXVZrwkMxUSlw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178361; 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=yuWWuA2ClE7EGvnZOUFjsvYflGX+2qlq70Du1Ss8tvs=; b=nHE6nLTaIGpbvs376oyFJtf80Y7nTrsOwhLq7b5HPLzeuFPtPAaEv63UUKDrNp4ylaixpAJJj12cMJQLQ0ObppkH9tRzDSFdrEmgjV7KgE2bf6QSiFzVmg6nRJonp+G8YAQyqtKxH6HSD4gJ4IQngMr/0cCz5c3R7mCMUGl0nkA= 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 167717836150036.538642662799475; Thu, 23 Feb 2023 10:52:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhF-0006jm-HA; Thu, 23 Feb 2023 13:52:01 -0500 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 1pVGhD-0006ij-Do for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:51:59 -0500 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 1pVGhB-0002q1-D9 for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:51:59 -0500 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-546-6ppaI173PZuZRy0HyqcTBg-1; Thu, 23 Feb 2023 13:51:53 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 767F23C0D843; Thu, 23 Feb 2023 18:51:53 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id C25B21121314; Thu, 23 Feb 2023 18:51:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178315; 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=yuWWuA2ClE7EGvnZOUFjsvYflGX+2qlq70Du1Ss8tvs=; b=AfM6cWZEkWDvehVy/t98E0c6G7LKbCUqWI9KKjni2oBxDOSsDxGJfs3WdGVbiyNCyRuq3K BDBBX41vM69s7y/Go9rPit1cHTdDa/CYY32tOaoMkiofgTt/oc3pjlR2NRrEadCTgf0vc+ eTDNG6MgMbpNsW1Rew6EdmdYJBm+sdc= X-MC-Unique: 6ppaI173PZuZRy0HyqcTBg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 02/29] mirror: Fix access of uninitialised fields during start Date: Thu, 23 Feb 2023 19:51:19 +0100 Message-Id: <20230223185146.306454-3-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178362566100002 Content-Type: text/plain; charset="utf-8" bdrv_mirror_top_pwritev() accesses the job object when active mirroring is enabled. It disables this code during early initialisation while s->job isn't set yet. However, s->job is still set way too early when the job object isn't fully initialised. For example, &s->ops_in_flight isn't initialised yet and the in_flight bitmap doesn't exist yet. This causes crashes when a write request comes in too early. Move the assignment of s->job to when the mirror job is actually fully initialised to make sure that the mirror_top driver doesn't access it too early. Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-3-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Kevin Wolf --- block/mirror.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/block/mirror.c b/block/mirror.c index ab326b67c9..fbbb4f619e 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -896,6 +896,7 @@ static int coroutine_fn mirror_run(Job *job, Error **er= rp) { MirrorBlockJob *s =3D container_of(job, MirrorBlockJob, common.job); BlockDriverState *bs =3D s->mirror_top_bs->backing->bs; + MirrorBDSOpaque *mirror_top_opaque =3D s->mirror_top_bs->opaque; BlockDriverState *target_bs =3D blk_bs(s->target); bool need_drain =3D true; BlockDeviceIoStatus iostatus; @@ -985,6 +986,12 @@ static int coroutine_fn mirror_run(Job *job, Error **e= rrp) } } =20 + /* + * Only now the job is fully initialised and mirror_top_bs should start + * accessing it. + */ + mirror_top_opaque->job =3D s; + assert(!s->dbi); s->dbi =3D bdrv_dirty_iter_new(s->dirty_bitmap); for (;;) { @@ -1704,7 +1711,6 @@ static BlockJob *mirror_start_job( if (!s) { goto fail; } - bs_opaque->job =3D s; =20 /* The block job now has a reference to this node */ bdrv_unref(mirror_top_bs); --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178429; cv=none; d=zohomail.com; s=zohoarc; b=hOBXstpwm940F+1Yo1Je2Og6NupV97b7PWClMb2l1LkaDJWh2QbI3AtREEPSm3d5iBbIj0yn0c5ROBXYS5fnyv3lL0k4ElzjQDAxIfUq7BJ06CC9RGQpHZdFxx2wMjJFVlTSZ0hnjMnwqDFqCw3Yrji8R8dPHOv8jAtH4o9MqAk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178429; 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=Bak/FlvANa78AZhSestxHeGPA9VbPJ0w1GZ6s1tM5KE=; b=RODM16Sn/iJZBjx6WSyf6fuE/nFO8UxQikM24AIeCzZwMbIRLMROi6U90uAPDCAPIffatB3YGr1xuLbNuZJubHG5hQAWlTL26y/GN1ZiMNAeAh6frflphawYkztfrP27o+O5UcuHcxkay9a79nfSgBAbym1IS0euWFe1jfoeV8A= 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 1677178429790469.40182107334726; Thu, 23 Feb 2023 10:53:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhL-0006ob-Q7; Thu, 23 Feb 2023 13:52:08 -0500 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 1pVGhH-0006lj-BS for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:03 -0500 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 1pVGhF-0002xS-9I for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:03 -0500 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-1RG4dhEwNHakt8RTKwPSvQ-1; Thu, 23 Feb 2023 13:51:54 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 604681C17427; Thu, 23 Feb 2023 18:51:54 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id ACAD31121314; Thu, 23 Feb 2023 18:51:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178320; 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=Bak/FlvANa78AZhSestxHeGPA9VbPJ0w1GZ6s1tM5KE=; b=U/cc/LB8FJWte6iceQys+F4IKLHS/RTDKVwJ9tNCBKe1eo+Ev6Xvr7emyLd34jXdqjQZyE UdwaxOwDxdRSQnoLF+iD0tE2kCuUbMiSY6lVxPqt6Kn5nQa6Sg8O/iByGwIjHZWcgUFAiP 8VlvzukNezig/7wQwK+KfAJOROYCzn8= X-MC-Unique: 1RG4dhEwNHakt8RTKwPSvQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 03/29] block: Mark bdrv_co_truncate() and callers GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:20 +0100 Message-Id: <20230223185146.306454-4-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178430824100001 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_truncate() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-4-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- include/block/block-io.h | 6 +++--- include/block/block_int-common.h | 7 ++++--- block/block-backend.c | 1 + block/crypto.c | 2 +- block/io.c | 1 + block/parallels.c | 14 ++++++++------ block/preallocate.c | 2 +- block/qcow.c | 17 ++++++++++++----- block/qcow2.c | 14 ++++++++------ block/raw-format.c | 6 +++--- block/vmdk.c | 2 ++ 11 files changed, 44 insertions(+), 28 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index f9fa88204d..9a09ec2bdd 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -72,9 +72,9 @@ int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, in= t64_t offset, int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, int64_t bytes, BdrvRequestFlags fla= gs); =20 -int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool e= xact, - PreallocMode prealloc, BdrvRequestFlags = flags, - Error **errp); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact, + PreallocMode prealloc, BdrvRequestFlags flags, Error **er= rp); =20 int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState *bs); int64_t co_wrapper_mixed bdrv_nb_sectors(BlockDriverState *bs); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index ba2e0fce25..eaf62beaff 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -677,9 +677,10 @@ struct BlockDriver { * If @exact is true and this function fails but would succeed * with @exact =3D false, it should return -ENOTSUP. */ - int coroutine_fn (*bdrv_co_truncate)(BlockDriverState *bs, int64_t off= set, - bool exact, PreallocMode prealloc, - BdrvRequestFlags flags, Error **e= rrp); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_truncate)( + BlockDriverState *bs, int64_t offset, bool exact, + PreallocMode prealloc, BdrvRequestFlags flags, Error **errp); + int64_t coroutine_fn (*bdrv_co_getlength)(BlockDriverState *bs); int64_t coroutine_fn (*bdrv_co_get_allocated_file_size)( BlockDriverState *bs); diff --git a/block/block-backend.c b/block/block-backend.c index ef512f7c48..f25f3ba5e7 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2372,6 +2372,7 @@ int coroutine_fn blk_co_truncate(BlockBackend *blk, i= nt64_t offset, bool exact, Error **errp) { IO_OR_GS_CODE(); + GRAPH_RDLOCK_GUARD(); if (!blk_is_available(blk)) { error_setg(errp, "No medium inserted"); return -ENOMEDIUM; diff --git a/block/crypto.c b/block/crypto.c index 72ac30568c..a15f77521f 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -359,7 +359,7 @@ block_crypto_co_create_generic(BlockDriverState *bs, in= t64_t size, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK block_crypto_co_truncate(BlockDriverState *bs, int64_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **errp) diff --git a/block/io.c b/block/io.c index d2be37b11e..35025fc11b 100644 --- a/block/io.c +++ b/block/io.c @@ -3380,6 +3380,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, bool exact, int64_t old_size, new_bytes; int ret; IO_CODE(); + assert_bdrv_graph_readable(); =20 /* if bs->drv =3D=3D NULL, bs is closed, so there's nothing to do here= */ if (!drv) { diff --git a/block/parallels.c b/block/parallels.c index d4378e09de..36c9de8a8a 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -165,9 +165,9 @@ static int64_t block_status(BDRVParallelsState *s, int6= 4_t sector_num, return start_off; } =20 -static coroutine_fn int64_t allocate_clusters(BlockDriverState *bs, - int64_t sector_num, - int nb_sectors, int *pnum) +static int64_t coroutine_fn GRAPH_RDLOCK +allocate_clusters(BlockDriverState *bs, int64_t sector_num, + int nb_sectors, int *pnum) { int ret =3D 0; BDRVParallelsState *s =3D bs->opaque; @@ -329,6 +329,8 @@ static coroutine_fn int parallels_co_writev(BlockDriver= State *bs, QEMUIOVector hd_qiov; int ret =3D 0; =20 + assume_graph_lock(); /* FIXME */ + qemu_iovec_init(&hd_qiov, qiov->niov); =20 while (nb_sectors > 0) { @@ -414,9 +416,9 @@ static coroutine_fn int parallels_co_readv(BlockDriverS= tate *bs, } =20 =20 -static int coroutine_fn parallels_co_check(BlockDriverState *bs, - BdrvCheckResult *res, - BdrvCheckMode fix) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_check(BlockDriverState *bs, BdrvCheckResult *res, + BdrvCheckMode fix) { BDRVParallelsState *s =3D bs->opaque; int64_t size, prev_off, high_off; diff --git a/block/preallocate.c b/block/preallocate.c index c0dcf8c346..42da9cb9f1 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -370,7 +370,7 @@ static coroutine_fn int preallocate_co_pwritev_part(Blo= ckDriverState *bs, flags); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK preallocate_co_truncate(BlockDriverState *bs, int64_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **errp) diff --git a/block/qcow.c b/block/qcow.c index 20c53b447b..5eb1ab5e59 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -350,11 +350,10 @@ static int qcow_reopen_prepare(BDRVReopenState *state, * return 0 if not allocated, 1 if *result is assigned, and negative * errno on failure. */ -static int coroutine_fn get_cluster_offset(BlockDriverState *bs, - uint64_t offset, int allocate, - int compressed_size, - int n_start, int n_end, - uint64_t *result) +static int coroutine_fn GRAPH_RDLOCK +get_cluster_offset(BlockDriverState *bs, uint64_t offset, int allocate, + int compressed_size, int n_start, int n_end, + uint64_t *result) { BDRVQcowState *s =3D bs->opaque; int min_index, i, j, l1_index, l2_index, ret; @@ -536,6 +535,8 @@ static int coroutine_fn qcow_co_block_status(BlockDrive= rState *bs, int64_t n; uint64_t cluster_offset; =20 + assume_graph_lock(); /* FIXME */ + qemu_co_mutex_lock(&s->lock); ret =3D get_cluster_offset(bs, offset, 0, 0, 0, 0, &cluster_offset); qemu_co_mutex_unlock(&s->lock); @@ -630,6 +631,8 @@ static coroutine_fn int qcow_co_preadv(BlockDriverState= *bs, int64_t offset, uint8_t *buf; void *orig_buf; =20 + assume_graph_lock(); /* FIXME */ + if (qiov->niov > 1) { buf =3D orig_buf =3D qemu_try_blockalign(bs, qiov->size); if (buf =3D=3D NULL) { @@ -726,6 +729,8 @@ static coroutine_fn int qcow_co_pwritev(BlockDriverStat= e *bs, int64_t offset, uint8_t *buf; void *orig_buf; =20 + assume_graph_lock(); /* FIXME */ + s->cluster_cache_offset =3D -1; /* disable compressed cache */ =20 /* We must always copy the iov when encrypting, so we @@ -1056,6 +1061,8 @@ qcow_co_pwritev_compressed(BlockDriverState *bs, int6= 4_t offset, int64_t bytes, uint8_t *buf, *out_buf; uint64_t cluster_offset; =20 + assume_graph_lock(); /* FIXME */ + buf =3D qemu_blockalign(bs, s->cluster_size); if (bytes !=3D s->cluster_size) { if (bytes > s->cluster_size || diff --git a/block/qcow2.c b/block/qcow2.c index ee0e5b45cc..e06ea7b5ff 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3183,9 +3183,9 @@ static int qcow2_set_up_encryption(BlockDriverState *= bs, * * Returns: 0 on success, -errno on failure. */ -static int coroutine_fn preallocate_co(BlockDriverState *bs, uint64_t offs= et, - uint64_t new_length, PreallocMode m= ode, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co(BlockDriverState *bs, uint64_t offset, uint64_t new_length, + PreallocMode mode, Error **errp) { BDRVQcow2State *s =3D bs->opaque; uint64_t bytes; @@ -4209,9 +4209,9 @@ fail: return ret; } =20 -static int coroutine_fn qcow2_co_truncate(BlockDriverState *bs, int64_t of= fset, - bool exact, PreallocMode preallo= c, - BdrvRequestFlags flags, Error **= errp) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_truncate(BlockDriverState *bs, int64_t offset, bool exact, + PreallocMode prealloc, BdrvRequestFlags flags, Error **e= rrp) { BDRVQcow2State *s =3D bs->opaque; uint64_t old_length; @@ -4672,6 +4672,8 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs, AioTaskPool *aio =3D NULL; int ret =3D 0; =20 + assume_graph_lock(); /* FIXME */ + if (has_data_file(bs)) { return -ENOTSUP; } diff --git a/block/raw-format.c b/block/raw-format.c index 0dc469b629..f39e1f502b 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -384,9 +384,9 @@ static void raw_refresh_limits(BlockDriverState *bs, Er= ror **errp) } } =20 -static int coroutine_fn raw_co_truncate(BlockDriverState *bs, int64_t offs= et, - bool exact, PreallocMode prealloc, - BdrvRequestFlags flags, Error **er= rp) +static int coroutine_fn GRAPH_RDLOCK +raw_co_truncate(BlockDriverState *bs, int64_t offset, bool exact, + PreallocMode prealloc, BdrvRequestFlags flags, Error **err= p) { BDRVRawState *s =3D bs->opaque; =20 diff --git a/block/vmdk.c b/block/vmdk.c index 171c9272ca..3fcb75319f 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2130,6 +2130,8 @@ static int coroutine_fn vmdk_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t b= ytes, QEMUIOVector *qiov) { + assume_graph_lock(); /* FIXME */ + if (bytes =3D=3D 0) { /* The caller will write bytes 0 to signal EOF. * When receive it, we align EOF to a sector boundary. */ --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178623; cv=none; d=zohomail.com; s=zohoarc; b=hsasqfkY6oJVtdktqZvUCrPh0jM+yYnxuTHkVH88JuSsy45B05fT8OIj3zU24ilOLR8rv2JnJg8uGjhzMJQigF+5ivzymGdDjZMsbRXK6JgucR7Y3YgvTG98y+sv9cVDYBmTZIHJQlAhaOPaKYAU9ItFk4YeLOxNiU7feww4UJg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178623; 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=GDRGbnEDbcsZxBLgnF6tSdN5oYvYd7u38MD2XJZG2xg=; b=J02PtdTC4/FAlQYF+0ed5m7MHtEL1hC1nWgp5ziO/qIVLqHHLtGEwqIWO+dJA04Siqwnx6Nq7uqd8/obFVq8tbmXlfHMdGRSx6TnTOG988n/cKuz+Nzn0+2RHG3mrfSKNn1ET1hxFiB7qZ/CsS+zrZQKjgATT+aNvXiBuIyVCDw= 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 1677178623857462.3833143120937; Thu, 23 Feb 2023 10:57:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhI-0006mF-JP; Thu, 23 Feb 2023 13:52:04 -0500 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 1pVGhG-0006kP-AK for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:02 -0500 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 1pVGhD-0002ue-QR for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:02 -0500 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-211-u2tQm1NeMGqvABmg-sJyGA-1; Thu, 23 Feb 2023 13:51:55 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6489C86C14C; Thu, 23 Feb 2023 18:51:55 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9776A1121314; Thu, 23 Feb 2023 18:51:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178319; 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=GDRGbnEDbcsZxBLgnF6tSdN5oYvYd7u38MD2XJZG2xg=; b=KwaA7Lmtee9IDNqxhj6ngmNDflTHHoKdsRnInaFuWeHltuK2xWlx1m/qGOJLLXXPOkhTxf t/cfvoLs6sZmu/Rg0xsSzbKQyDvVd60NqDpJUYE2KQxMOuwkJJI4J3R/i7ZJCu7aYvN1AL FMXwtSNI5EzyqsABhoa+F5ns3jySYXs= X-MC-Unique: u2tQm1NeMGqvABmg-sJyGA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 04/29] block: Mark bdrv_co_block_status() and callers GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:21 +0100 Message-Id: <20230223185146.306454-5-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178626046100010 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_block_status() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-5-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- block/coroutines.h | 2 +- include/block/block-copy.h | 6 +++--- include/block/block-io.h | 22 +++++++++++----------- include/block/block_int-common.h | 3 ++- block/backup.c | 3 +++ block/block-backend.c | 2 ++ block/block-copy.c | 19 +++++++++++-------- block/io.c | 13 ++++++++----- block/mirror.c | 14 +++++++++----- block/qcow.c | 11 ++++------- block/quorum.c | 9 ++++----- block/stream.c | 32 ++++++++++++++++++-------------- qemu-img.c | 4 +++- tests/unit/test-block-iothread.c | 3 ++- 14 files changed, 81 insertions(+), 62 deletions(-) diff --git a/block/coroutines.h b/block/coroutines.h index 2a1e0b3c9d..dd9f3d449b 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -43,7 +43,7 @@ bdrv_co_check(BlockDriverState *bs, BdrvCheckResult *res,= BdrvCheckMode fix); int coroutine_fn GRAPH_RDLOCK bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp); =20 -int coroutine_fn +int coroutine_fn GRAPH_RDLOCK bdrv_co_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, bool include_base, diff --git a/include/block/block-copy.h b/include/block/block-copy.h index d0f8386554..0700953ab8 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -36,9 +36,9 @@ void block_copy_set_progress_meter(BlockCopyState *s, Pro= gressMeter *pm); void block_copy_state_free(BlockCopyState *s); =20 void block_copy_reset(BlockCopyState *s, int64_t offset, int64_t bytes); -int64_t coroutine_fn block_copy_reset_unallocated(BlockCopyState *s, - int64_t offset, - int64_t *count); + +int64_t coroutine_fn GRAPH_RDLOCK +block_copy_reset_unallocated(BlockCopyState *s, int64_t offset, int64_t *c= ount); =20 int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t byt= es, bool ignore_ratelimit, uint64_t timeout_ns, diff --git a/include/block/block-io.h b/include/block/block-io.h index 9a09ec2bdd..6303501b0f 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -109,24 +109,24 @@ int bdrv_block_status(BlockDriverState *bs, int64_t o= ffset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); =20 -int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - int64_t offset, int64_t bytes, - int64_t *pnum, int64_t *map, - BlockDriverState **file); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_block_status_above(BlockDriverState *bs, BlockDriverState *base, + int64_t offset, int64_t bytes, int64_t *pnum, + int64_t *map, BlockDriverState **file); int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); =20 -int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t offset, - int64_t bytes, int64_t *pnum); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, + int64_t *pnum); int bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum); =20 -int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top, - BlockDriverState *base, - bool include_base, int64_t off= set, - int64_t bytes, int64_t *pnum); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_is_allocated_above(BlockDriverState *top, BlockDriverState *base, + bool include_base, int64_t offset, int64_t byte= s, + int64_t *pnum); int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, bool include_base, int64_t offset, int64_t byt= es, int64_t *pnum); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index eaf62beaff..5f0104a1af 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -606,7 +606,8 @@ struct BlockDriver { * *pnum value for the block-status cache on protocol nodes, prior * to clamping *pnum for return to its caller. */ - int coroutine_fn (*bdrv_co_block_status)(BlockDriverState *bs, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_block_status)( + BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); =20 diff --git a/block/backup.c b/block/backup.c index 824d39acaa..46fca2459d 100644 --- a/block/backup.c +++ b/block/backup.c @@ -270,7 +270,10 @@ static int coroutine_fn backup_run(Job *job, Error **e= rrp) return -ECANCELED; } =20 + /* rdlock protects the subsequent call to bdrv_is_allocated() = */ + bdrv_graph_co_rdlock(); ret =3D block_copy_reset_unallocated(s->bcs, offset, &count); + bdrv_graph_co_rdunlock(); if (ret < 0) { return ret; } diff --git a/block/block-backend.c b/block/block-backend.c index f25f3ba5e7..f5d9e3e269 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1431,6 +1431,7 @@ int coroutine_fn blk_co_block_status_above(BlockBacke= nd *blk, BlockDriverState **file) { IO_CODE(); + GRAPH_RDLOCK_GUARD(); return bdrv_co_block_status_above(blk_bs(blk), base, offset, bytes, pn= um, map, file); } @@ -1441,6 +1442,7 @@ int coroutine_fn blk_co_is_allocated_above(BlockBacke= nd *blk, int64_t bytes, int64_t *pnum) { IO_CODE(); + GRAPH_RDLOCK_GUARD(); return bdrv_co_is_allocated_above(blk_bs(blk), base, include_base, off= set, bytes, pnum); } diff --git a/block/block-copy.c b/block/block-copy.c index 30a4da0f2e..d299fac7cc 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -581,9 +581,9 @@ static coroutine_fn int block_copy_task_entry(AioTask *= task) return ret; } =20 -static coroutine_fn int block_copy_block_status(BlockCopyState *s, - int64_t offset, - int64_t bytes, int64_t *pn= um) +static coroutine_fn GRAPH_RDLOCK +int block_copy_block_status(BlockCopyState *s, int64_t offset, int64_t byt= es, + int64_t *pnum) { int64_t num; BlockDriverState *base; @@ -618,9 +618,9 @@ static coroutine_fn int block_copy_block_status(BlockCo= pyState *s, * Check if the cluster starting at offset is allocated or not. * return via pnum the number of contiguous clusters sharing this allocati= on. */ -static int coroutine_fn block_copy_is_cluster_allocated(BlockCopyState *s, - int64_t offset, - int64_t *pnum) +static int coroutine_fn GRAPH_RDLOCK +block_copy_is_cluster_allocated(BlockCopyState *s, int64_t offset, + int64_t *pnum) { BlockDriverState *bs =3D s->source->bs; int64_t count, total_count =3D 0; @@ -630,6 +630,7 @@ static int coroutine_fn block_copy_is_cluster_allocated= (BlockCopyState *s, assert(QEMU_IS_ALIGNED(offset, s->cluster_size)); =20 while (true) { + /* protected in backup_run() */ ret =3D bdrv_co_is_allocated(bs, offset, bytes, &count); if (ret < 0) { return ret; @@ -704,7 +705,7 @@ int64_t coroutine_fn block_copy_reset_unallocated(Block= CopyState *s, * Returns 1 if dirty clusters found and successfully copied, 0 if no dirty * clusters found and -errno on failure. */ -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK block_copy_dirty_clusters(BlockCopyCallState *call_state) { BlockCopyState *s =3D call_state->s; @@ -827,7 +828,8 @@ void block_copy_kick(BlockCopyCallState *call_state) * it means that some I/O operation failed in context of _this_ block_copy= call, * not some parallel operation. */ -static int coroutine_fn block_copy_common(BlockCopyCallState *call_state) +static int coroutine_fn GRAPH_RDLOCK +block_copy_common(BlockCopyCallState *call_state) { int ret; BlockCopyState *s =3D call_state->s; @@ -892,6 +894,7 @@ static int coroutine_fn block_copy_common(BlockCopyCall= State *call_state) =20 static void coroutine_fn block_copy_async_co_entry(void *opaque) { + GRAPH_RDLOCK_GUARD(); block_copy_common(opaque); } =20 diff --git a/block/io.c b/block/io.c index 35025fc11b..a0f8efc9a1 100644 --- a/block/io.c +++ b/block/io.c @@ -2224,11 +2224,10 @@ int bdrv_flush_all(void) * BDRV_BLOCK_OFFSET_VALID bit is set, 'map' and 'file' (if non-NULL) are * set to the host mapping and BDS corresponding to the guest offset. */ -static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs, - bool want_zero, - int64_t offset, int64_t bytes, - int64_t *pnum, int64_t *map, - BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +bdrv_co_block_status(BlockDriverState *bs, bool want_zero, + int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, BlockDriverState **file) { int64_t total_size; int64_t n; /* bytes */ @@ -2240,6 +2239,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, bool has_filtered_child; =20 assert(pnum); + assert_bdrv_graph_readable(); *pnum =3D 0; total_size =3D bdrv_getlength(bs); if (total_size < 0) { @@ -2470,6 +2470,7 @@ bdrv_co_common_block_status_above(BlockDriverState *b= s, IO_CODE(); =20 assert(!include_base || base); /* Can't include NULL base */ + assert_bdrv_graph_readable(); =20 if (!depth) { depth =3D &dummy; @@ -2595,6 +2596,8 @@ int coroutine_fn bdrv_co_is_zero_fast(BlockDriverStat= e *bs, int64_t offset, int64_t pnum =3D bytes; IO_CODE(); =20 + assume_graph_lock(); /* FIXME */ + if (!bytes) { return 1; } diff --git a/block/mirror.c b/block/mirror.c index fbbb4f619e..94c523af28 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -558,9 +558,11 @@ static uint64_t coroutine_fn mirror_iteration(MirrorBl= ockJob *s) MirrorMethod mirror_method =3D MIRROR_METHOD_COPY; =20 assert(!(offset % s->granularity)); - ret =3D bdrv_block_status_above(source, NULL, offset, - nb_chunks * s->granularity, - &io_bytes, NULL, NULL); + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D bdrv_block_status_above(source, NULL, offset, + nb_chunks * s->granularity, + &io_bytes, NULL, NULL); + } if (ret < 0) { io_bytes =3D MIN(nb_chunks * s->granularity, max_io_bytes); } else if (ret & BDRV_BLOCK_DATA) { @@ -863,8 +865,10 @@ static int coroutine_fn mirror_dirty_init(MirrorBlockJ= ob *s) return 0; } =20 - ret =3D bdrv_is_allocated_above(bs, s->base_overlay, true, offset,= bytes, - &count); + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D bdrv_is_allocated_above(bs, s->base_overlay, true, off= set, + bytes, &count); + } if (ret < 0) { return ret; } diff --git a/block/qcow.c b/block/qcow.c index 5eb1ab5e59..2d19a78818 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -524,19 +524,16 @@ get_cluster_offset(BlockDriverState *bs, uint64_t off= set, int allocate, return 1; } =20 -static int coroutine_fn qcow_co_block_status(BlockDriverState *bs, - bool want_zero, - int64_t offset, int64_t bytes, - int64_t *pnum, int64_t *map, - BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +qcow_co_block_status(BlockDriverState *bs, bool want_zero, + int64_t offset, int64_t bytes, int64_t *pnum, + int64_t *map, BlockDriverState **file) { BDRVQcowState *s =3D bs->opaque; int index_in_cluster, ret; int64_t n; uint64_t cluster_offset; =20 - assume_graph_lock(); /* FIXME */ - qemu_co_mutex_lock(&s->lock); ret =3D get_cluster_offset(bs, offset, 0, 0, 0, 0, &cluster_offset); qemu_co_mutex_unlock(&s->lock); diff --git a/block/quorum.c b/block/quorum.c index d1dcf2eaba..f3fe067541 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -1217,11 +1217,10 @@ static void quorum_child_perm(BlockDriverState *bs,= BdrvChild *c, * return BDRV_BLOCK_ZERO if *all* children agree that a certain * region contains zeroes, and BDRV_BLOCK_DATA otherwise. */ -static int coroutine_fn quorum_co_block_status(BlockDriverState *bs, - bool want_zero, - int64_t offset, int64_t cou= nt, - int64_t *pnum, int64_t *map, - BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +quorum_co_block_status(BlockDriverState *bs, bool want_zero, + int64_t offset, int64_t count, + int64_t *pnum, int64_t *map, BlockDriverState **fil= e) { BDRVQuorumState *s =3D bs->opaque; int i, ret; diff --git a/block/stream.c b/block/stream.c index 8744ad103f..22368ce186 100644 --- a/block/stream.c +++ b/block/stream.c @@ -161,21 +161,25 @@ static int coroutine_fn stream_run(Job *job, Error **= errp) =20 copy =3D false; =20 - ret =3D bdrv_is_allocated(unfiltered_bs, offset, STREAM_CHUNK, &n); - if (ret =3D=3D 1) { - /* Allocated in the top, no need to copy. */ - } else if (ret >=3D 0) { - /* Copy if allocated in the intermediate images. Limit to the - * known-unallocated area [offset, offset+n*BDRV_SECTOR_SIZE).= */ - ret =3D bdrv_is_allocated_above(bdrv_cow_bs(unfiltered_bs), - s->base_overlay, true, - offset, n, &n); - /* Finish early if end of backing file has been reached */ - if (ret =3D=3D 0 && n =3D=3D 0) { - n =3D len - offset; + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D bdrv_is_allocated(unfiltered_bs, offset, STREAM_CHUNK,= &n); + if (ret =3D=3D 1) { + /* Allocated in the top, no need to copy. */ + } else if (ret >=3D 0) { + /* + * Copy if allocated in the intermediate images. Limit to= the + * known-unallocated area [offset, offset+n*BDRV_SECTOR_SI= ZE). + */ + ret =3D bdrv_is_allocated_above(bdrv_cow_bs(unfiltered_bs), + s->base_overlay, true, + offset, n, &n); + /* Finish early if end of backing file has been reached */ + if (ret =3D=3D 0 && n =3D=3D 0) { + n =3D len - offset; + } + + copy =3D (ret > 0); } - - copy =3D (ret > 0); } trace_stream_one_iteration(s, offset, n, ret); if (copy) { diff --git a/qemu-img.c b/qemu-img.c index 7c05931866..cd0178b51b 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -1991,7 +1991,9 @@ static void coroutine_fn convert_co_do_copy(void *opa= que) qemu_co_mutex_unlock(&s->lock); break; } - n =3D convert_iteration_sectors(s, s->sector_num); + WITH_GRAPH_RDLOCK_GUARD() { + n =3D convert_iteration_sectors(s, s->sector_num); + } if (n < 0) { qemu_co_mutex_unlock(&s->lock); s->ret =3D n; diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 6dfac6468a..3a5e1eb2c4 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -312,7 +312,8 @@ static void test_sync_op_blk_truncate(BlockBackend *blk) g_assert_cmpint(ret, =3D=3D, -EINVAL); } =20 -static void test_sync_op_block_status(BdrvChild *c) +/* Disable TSA to make bdrv_test.bdrv_co_block_status writable */ +static void TSA_NO_TSA test_sync_op_block_status(BdrvChild *c) { int ret; int64_t n; --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178623; cv=none; d=zohomail.com; s=zohoarc; b=oGsYjC3hfdy+BPdJKg5TEN/zBiKhlw7nyTswoMwP9KAwrdkwM4dlHnLreqEAvVM/rOjBLnUfx2Cjyd6Z+yaFyXsZr3lLAPS5bptbLFj+CLXh+3vzq8ZI5UHOUku84zsCZ2nlq0udIUbLYBpXbUB+6tusS5YgW5ayLOIQ+hvLd64= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178623; 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=ZFkd+Z22RrEnNXMI5Wod+NzsDY3BkYb9SJg3xZPB1Aw=; b=S9hiGHxbl1Pty2TyoXQNM+94zl/lOkskNIR5YEtgBMgCgX1s0dkVU60fLvX5ZoA1iJoQcZUGFTgK+lc/GSF7Gx98DVBQZOtmPOrlcTFPZHwhHENci0QcbzeCuULd2cxF5r2X43/h1tapbIq85ZuXcSz1fvhZ1M5g635eCqsplNE= 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 1677178623292792.8072031184082; Thu, 23 Feb 2023 10:57:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhI-0006ml-VE; Thu, 23 Feb 2023 13:52:04 -0500 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 1pVGhG-0006lS-Vs for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:03 -0500 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 1pVGhE-0002v4-HJ for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:02 -0500 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-159-a3JWAbUSODWaIDGn3VZthQ-1; Thu, 23 Feb 2023 13:51:56 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4D6C1280048D; Thu, 23 Feb 2023 18:51:56 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A78B1121314; Thu, 23 Feb 2023 18:51:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178319; 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=ZFkd+Z22RrEnNXMI5Wod+NzsDY3BkYb9SJg3xZPB1Aw=; b=VbGdmWGwwBzZ4JuMecx6Adu/lPDgYp8PalkAzb+p1iwTOyVspv/dZtB42A9SnF3DEzk9ZN hYQKpLO6tOSjUo0v25lpyaPJTlkHTudUc6aM+V4gDguZO3cB01n3a+eSm3O427klcPOPsM tjMjvF7kJ2Ac3D8tZkPAqwJc2Y4sFAg= X-MC-Unique: a3JWAbUSODWaIDGn3VZthQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 05/29] block: Mark bdrv_co_ioctl() and callers GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:22 +0100 Message-Id: <20230223185146.306454-6-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178624036100002 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_ioctl() need to hold a reader lock for the graph. Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-6-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- include/block/block-io.h | 3 ++- include/block/block_int-common.h | 9 +++++---- block/block-backend.c | 1 + block/io.c | 1 + block/raw-format.c | 4 ++-- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 6303501b0f..3f42c76f23 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -97,7 +97,8 @@ void bdrv_aio_cancel(BlockAIOCB *acb); void bdrv_aio_cancel_async(BlockAIOCB *acb); =20 /* sg packet commands */ -int coroutine_fn bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); =20 /* Ensure contents are flushed to disk. */ int coroutine_fn bdrv_co_flush(BlockDriverState *bs); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 5f0104a1af..64700daf38 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -714,11 +714,12 @@ struct BlockDriver { void coroutine_fn (*bdrv_co_lock_medium)(BlockDriverState *bs, bool lo= cked); =20 /* to control generic scsi devices */ - BlockAIOCB *(*bdrv_aio_ioctl)(BlockDriverState *bs, - unsigned long int req, void *buf, + BlockAIOCB *coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_aio_ioctl)( + BlockDriverState *bs, unsigned long int req, void *buf, BlockCompletionFunc *cb, void *opaque); - int coroutine_fn (*bdrv_co_ioctl)(BlockDriverState *bs, - unsigned long int req, void *buf); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_ioctl)( + BlockDriverState *bs, unsigned long int req, void *buf); =20 /* * Returns 0 for completed check, -errno for internal errors. diff --git a/block/block-backend.c b/block/block-backend.c index f5d9e3e269..5c731a1c6c 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1672,6 +1672,7 @@ blk_co_do_ioctl(BlockBackend *blk, unsigned long int = req, void *buf) IO_CODE(); =20 blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); =20 if (!blk_is_available(blk)) { return -ENOMEDIUM; diff --git a/block/io.c b/block/io.c index a0f8efc9a1..c03233ae94 100644 --- a/block/io.c +++ b/block/io.c @@ -3083,6 +3083,7 @@ int coroutine_fn bdrv_co_ioctl(BlockDriverState *bs, = int req, void *buf) }; BlockAIOCB *acb; IO_CODE(); + assert_bdrv_graph_readable(); =20 bdrv_inc_in_flight(bs); if (!drv || (!drv->bdrv_aio_ioctl && !drv->bdrv_co_ioctl)) { diff --git a/block/raw-format.c b/block/raw-format.c index f39e1f502b..202acb1232 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -415,8 +415,8 @@ static void coroutine_fn raw_co_lock_medium(BlockDriver= State *bs, bool locked) bdrv_co_lock_medium(bs->file->bs, locked); } =20 -static int coroutine_fn raw_co_ioctl(BlockDriverState *bs, - unsigned long int req, void *buf) +static int coroutine_fn GRAPH_RDLOCK +raw_co_ioctl(BlockDriverState *bs, unsigned long int req, void *buf) { BDRVRawState *s =3D bs->opaque; if (s->offset || s->has_size) { --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178412; cv=none; d=zohomail.com; s=zohoarc; b=i4Q2/CFVOEIwvjjoVIIkwnADwLE7maPvPh2hxR+sxh0rxISjLhnIwxgP52A37i1wSUIDUWo0H+HhRg7R8GSGXgQHDjO6njGcftoa9mQERv6blWWecCyrj/Yg3S7zy5ry3IFLAq9r77/riNk5VPNWV/KZ1pB2eiaNCDS2J6Gf9j4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178412; 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=eRfUwW7W+NRR0iIjypfr/5pPgmRwfhMP49v359YeetA=; b=KcOJexmw93z8UD6nSge+YRFG8w4/PtMkQ9vbe7Ye7KfBnFF7xVcql96vxCHIMqx0dSkaH1Gfq1IVt4fg/6qwdLu+Y055asXFcKLIsljWOWEHEd382CsYDQVnSwKWxUkA6TBs/+j518Hq9VRL8nHXBzj1MoyrAkT6f/XPXGVpeIo= 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 1677178412929326.5636194261183; Thu, 23 Feb 2023 10:53:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhL-0006nx-LX; Thu, 23 Feb 2023 13:52:07 -0500 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 1pVGhI-0006lt-20 for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:04 -0500 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 1pVGhG-00031E-9J for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:03 -0500 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-77-sXBmeTwXMUy99Qxn21GSmA-1; Thu, 23 Feb 2023 13:51:57 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3570738173CC; Thu, 23 Feb 2023 18:51:57 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82E151121314; Thu, 23 Feb 2023 18:51:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178321; 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=eRfUwW7W+NRR0iIjypfr/5pPgmRwfhMP49v359YeetA=; b=BoXEfNtnjVt1Ht+cebEC2HfXF2tT2V5bAl+3/LhX2Vaqd3irTRWmXZ2TnI720uAFOxqiQU 4Cx6M6wOcX3U4U0jhI3BTWjozTNPlKZHksMOw3qnjZw1VG1SLkbESHDXSJUqZ0MQekuplK xH32DCgqF4RQuDPqAeMYSrz08OOt7Og= X-MC-Unique: sXBmeTwXMUy99Qxn21GSmA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 06/29] block/qed: add missing graph rdlock in qed_need_check_timer_entry Date: Thu, 23 Feb 2023 19:51:23 +0100 Message-Id: <20230223185146.306454-7-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178414623100002 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This function is called in two different places: - timer callback, which does not take the graph rdlock. - bdrv_qed_drain_begin(), which is .bdrv_drain_begin() callback documented as function that does not take the lock. Since it calls recursive functions that traverse the graph, we need to protect them with the graph rdlock. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-7-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- block/qed.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/qed.c b/block/qed.c index 175a46c67b..7690d0215d 100644 --- a/block/qed.c +++ b/block/qed.c @@ -282,11 +282,12 @@ static void coroutine_fn qed_unplug_allocating_write_= reqs(BDRVQEDState *s) qemu_co_mutex_unlock(&s->table_lock); } =20 -static void coroutine_fn qed_need_check_timer(BDRVQEDState *s) +static void coroutine_fn GRAPH_RDLOCK qed_need_check_timer(BDRVQEDState *s) { int ret; =20 trace_qed_need_check_timer_cb(s); + assert_bdrv_graph_readable(); =20 if (!qed_plug_allocating_write_reqs(s)) { return; @@ -312,6 +313,7 @@ static void coroutine_fn qed_need_check_timer(BDRVQEDSt= ate *s) static void coroutine_fn qed_need_check_timer_entry(void *opaque) { BDRVQEDState *s =3D opaque; + GRAPH_RDLOCK_GUARD(); =20 qed_need_check_timer(opaque); bdrv_dec_in_flight(s->bs); --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178640; cv=none; d=zohomail.com; s=zohoarc; b=PWVSVEgT+CdLfZ0rXl9DbqXQh6y9aAHDnYwN0xKfY3KGWAFkL/2cDxGIKx+qt5cPiugftJRqcUTPMWKH0uQCfIObERT/6D2kBlEVvTxJROXwgV/8J2VGwbD9EiD1COffLeKQDAoCxoMDxYVb6cc1RSYxohto/DbF9UXTN5wzVqI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178640; 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=+l5BiCRTOkG4ePBIaZmhyP81REPgwjl5X5eo/FTiKt0=; b=h//Ep8Q5QfJB6sGOlbz1tzbLgGy/VWeERxmiKmNO9JAPDn0o1KuPNkEqG7ZwEV+M7vu/Viu9IkQQ7bflo7pkW2YRWJOrHeKF1ukTGETDNOdx53bsrpybsQ/eJk8/xJ79hW3PLsR1uiofm5hsGHPg1wRpX9XW2L6DIxixn5ilxaI= 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 167717864008951.304360275889394; Thu, 23 Feb 2023 10:57:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhP-0006qL-IB; Thu, 23 Feb 2023 13:52:11 -0500 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 1pVGhK-0006o9-8v for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:07 -0500 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 1pVGhG-00031X-FM for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:06 -0500 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-257-9Bd4_KcmORyWfYBrsOZHfA-1; Thu, 23 Feb 2023 13:51:58 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2125E802D2A; Thu, 23 Feb 2023 18:51:58 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D1E01121314; Thu, 23 Feb 2023 18:51:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178321; 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=+l5BiCRTOkG4ePBIaZmhyP81REPgwjl5X5eo/FTiKt0=; b=Ovc1uZYVEIjVVxc11Td8wMfC36gh+3oorm9nHQqBd7Gd8zD5uM2WdYfRkw29y7Rz2kQWHb un0J+1fAj+nUgzdbby4XVoQ39Qvjkg7SfVh3967kxfWFi7FZVdP6FQXvABVMpEc2sjQGky +PRJlcHJaVCid9Yqb6zsOQLwH2sBWw0= X-MC-Unique: 9Bd4_KcmORyWfYBrsOZHfA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 07/29] block: Mark bdrv_co_flush() and callers GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:24 +0100 Message-Id: <20230223185146.306454-8-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178642194100006 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_flush() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-8-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- block/qcow2.h | 5 +++- block/qed.h | 29 +++++++++++++-------- include/block/block-io.h | 2 +- include/block/block_int-common.h | 12 +++++---- block/blkdebug.c | 2 +- block/blklogwrites.c | 21 ++++++++++----- block/blkreplay.c | 2 +- block/blkverify.c | 2 +- block/block-backend.c | 3 ++- block/copy-before-write.c | 2 +- block/file-posix.c | 4 +-- block/io.c | 7 +++++ block/mirror.c | 2 +- block/preallocate.c | 2 +- block/qed-check.c | 3 ++- block/qed-table.c | 6 ++--- block/qed.c | 44 +++++++++++++++++++------------- block/quorum.c | 2 +- block/throttle.c | 2 +- block/vmdk.c | 6 +++-- 20 files changed, 98 insertions(+), 60 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 2285f18a73..7a02699bfa 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -900,7 +900,10 @@ int coroutine_fn qcow2_detect_metadata_preallocation(B= lockDriverState *bs); /* qcow2-cluster.c functions */ int qcow2_grow_l1_table(BlockDriverState *bs, uint64_t min_size, bool exact_size); -int coroutine_fn qcow2_shrink_l1_table(BlockDriverState *bs, uint64_t max_= size); + +int coroutine_fn GRAPH_RDLOCK +qcow2_shrink_l1_table(BlockDriverState *bs, uint64_t max_size); + int qcow2_write_l1_entry(BlockDriverState *bs, int l1_index); int qcow2_encrypt_sectors(BDRVQcow2State *s, int64_t sector_num, uint8_t *buf, int nb_sectors, bool enc, Error **= errp); diff --git a/block/qed.h b/block/qed.h index 3d12bf78d4..e48f7c2480 100644 --- a/block/qed.h +++ b/block/qed.h @@ -201,20 +201,25 @@ void qed_commit_l2_cache_entry(L2TableCache *l2_cache= , CachedL2Table *l2_table); * Table I/O functions */ int coroutine_fn qed_read_l1_table_sync(BDRVQEDState *s); -int coroutine_fn qed_write_l1_table(BDRVQEDState *s, unsigned int index, - unsigned int n); -int coroutine_fn qed_write_l1_table_sync(BDRVQEDState *s, unsigned int ind= ex, - unsigned int n); + +int coroutine_fn GRAPH_RDLOCK +qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n); + +int coroutine_fn GRAPH_RDLOCK +qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index, unsigned int = n); + int coroutine_fn qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *reque= st, uint64_t offset); int coroutine_fn qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset); -int coroutine_fn qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, - unsigned int index, unsigned int n, - bool flush); -int coroutine_fn qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *requ= est, - unsigned int index, unsigned int = n, - bool flush); + +int coroutine_fn GRAPH_RDLOCK +qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, unsigned int inde= x, + unsigned int n, bool flush); + +int coroutine_fn GRAPH_RDLOCK +qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *request, + unsigned int index, unsigned int n, bool flush); =20 /** * Cluster functions @@ -226,7 +231,9 @@ int coroutine_fn qed_find_cluster(BDRVQEDState *s, QEDR= equest *request, /** * Consistency check */ -int coroutine_fn qed_check(BDRVQEDState *s, BdrvCheckResult *result, bool = fix); +int coroutine_fn GRAPH_RDLOCK +qed_check(BDRVQEDState *s, BdrvCheckResult *result, bool fix); + =20 QEDTable *qed_alloc_table(BDRVQEDState *s); =20 diff --git a/include/block/block-io.h b/include/block/block-io.h index 3f42c76f23..7e96506138 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -101,7 +101,7 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); =20 /* Ensure contents are flushed to disk. */ -int coroutine_fn bdrv_co_flush(BlockDriverState *bs); +int coroutine_fn GRAPH_RDLOCK bdrv_co_flush(BlockDriverState *bs); =20 int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 64700daf38..51eaabd9d1 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -477,8 +477,8 @@ struct BlockDriver { BlockAIOCB *(*bdrv_aio_pwritev)(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque); - BlockAIOCB *(*bdrv_aio_flush)(BlockDriverState *bs, - BlockCompletionFunc *cb, void *opaque); + BlockAIOCB * GRAPH_RDLOCK_PTR (*bdrv_aio_flush)( + BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque); BlockAIOCB *(*bdrv_aio_pdiscard)(BlockDriverState *bs, int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque); @@ -646,7 +646,7 @@ struct BlockDriver { * layers, if needed. This function is needed for deterministic * synchronization of the flush finishing callback. */ - int coroutine_fn (*bdrv_co_flush)(BlockDriverState *bs); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_flush)(BlockDriverState *b= s); =20 /* Delete a created file. */ int coroutine_fn (*bdrv_co_delete_file)(BlockDriverState *bs, @@ -656,14 +656,16 @@ struct BlockDriver { * Flushes all data that was already written to the OS all the way dow= n to * the disk (for example file-posix.c calls fsync()). */ - int coroutine_fn (*bdrv_co_flush_to_disk)(BlockDriverState *bs); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_flush_to_disk)( + BlockDriverState *bs); =20 /* * Flushes all internal caches to the OS. The data may still sit in a * writeback cache of the host OS, but it will survive a crash of the = qemu * process. */ - int coroutine_fn (*bdrv_co_flush_to_os)(BlockDriverState *bs); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_flush_to_os)( + BlockDriverState *bs); =20 /* * Truncate @bs to @offset bytes using the given @prealloc mode diff --git a/block/blkdebug.c b/block/blkdebug.c index 28772be73f..5ba3766a2c 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -668,7 +668,7 @@ blkdebug_co_pwritev(BlockDriverState *bs, int64_t offse= t, int64_t bytes, return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags); } =20 -static int coroutine_fn blkdebug_co_flush(BlockDriverState *bs) +static int GRAPH_RDLOCK coroutine_fn blkdebug_co_flush(BlockDriverState *b= s) { int err =3D rule_check(bs, 0, 0, BLKDEBUG_IO_TYPE_FLUSH); =20 diff --git a/block/blklogwrites.c b/block/blklogwrites.c index b00b8a6dd0..5ec1d23f29 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -307,7 +307,7 @@ typedef struct BlkLogWritesFileReq { uint64_t bytes; int file_flags; QEMUIOVector *qiov; - int (*func)(struct BlkLogWritesFileReq *r); + int GRAPH_RDLOCK_PTR (*func)(struct BlkLogWritesFileReq *r); int file_ret; } BlkLogWritesFileReq; =20 @@ -319,7 +319,8 @@ typedef struct { int log_ret; } BlkLogWritesLogReq; =20 -static void coroutine_fn blk_log_writes_co_do_log(BlkLogWritesLogReq *lr) +static void coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_do_log(BlkLogWritesLogReq *lr) { BDRVBlkLogWritesState *s =3D lr->bs->opaque; uint64_t cur_log_offset =3D s->cur_log_sector << s->sectorbits; @@ -368,15 +369,16 @@ static void coroutine_fn blk_log_writes_co_do_log(Blk= LogWritesLogReq *lr) } } =20 -static void coroutine_fn blk_log_writes_co_do_file(BlkLogWritesFileReq *fr) +static void coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_do_file(BlkLogWritesFileReq *fr) { fr->file_ret =3D fr->func(fr); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_log(BlockDriverState *bs, uint64_t offset, uint64_t byte= s, QEMUIOVector *qiov, int flags, - int (*file_func)(BlkLogWritesFileReq *r), + int /*GRAPH_RDLOCK*/ (*file_func)(BlkLogWritesFileRe= q *r), uint64_t entry_flags, bool is_zero_write) { QEMUIOVector log_qiov; @@ -442,7 +444,8 @@ blk_log_writes_co_do_file_pwrite_zeroes(BlkLogWritesFil= eReq *fr) fr->file_flags); } =20 -static int coroutine_fn blk_log_writes_co_do_file_flush(BlkLogWritesFileRe= q *fr) +static int coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_do_file_flush(BlkLogWritesFileReq *fr) { return bdrv_co_flush(fr->bs->file->bs); } @@ -457,6 +460,7 @@ static int coroutine_fn blk_log_writes_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t by= tes, QEMUIOVector *qiov, BdrvRequestFlags flags) { + assume_graph_lock(); /* FIXME */ return blk_log_writes_co_log(bs, offset, bytes, qiov, flags, blk_log_writes_co_do_file_pwritev, 0, fal= se); } @@ -465,12 +469,14 @@ static int coroutine_fn blk_log_writes_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, BdrvRequestFlags flags) { + assume_graph_lock(); /* FIXME */ return blk_log_writes_co_log(bs, offset, bytes, NULL, flags, blk_log_writes_co_do_file_pwrite_zeroes, = 0, true); } =20 -static int coroutine_fn blk_log_writes_co_flush_to_disk(BlockDriverState *= bs) +static int coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_flush_to_disk(BlockDriverState *bs) { return blk_log_writes_co_log(bs, 0, 0, NULL, 0, blk_log_writes_co_do_file_flush, @@ -480,6 +486,7 @@ static int coroutine_fn blk_log_writes_co_flush_to_disk= (BlockDriverState *bs) static int coroutine_fn blk_log_writes_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t b= ytes) { + assume_graph_lock(); /* FIXME */ return blk_log_writes_co_log(bs, offset, bytes, NULL, 0, blk_log_writes_co_do_file_pdiscard, LOG_DISCARD_FLAG, false); diff --git a/block/blkreplay.c b/block/blkreplay.c index 16543f585a..ce13fa5ba5 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -113,7 +113,7 @@ static int coroutine_fn blkreplay_co_pdiscard(BlockDriv= erState *bs, return ret; } =20 -static int coroutine_fn blkreplay_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK blkreplay_co_flush(BlockDriverState *= bs) { uint64_t reqid =3D blkreplay_next_id(); int ret =3D bdrv_co_flush(bs->file->bs); diff --git a/block/blkverify.c b/block/blkverify.c index edf1a550f2..8c11c2eae4 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -256,7 +256,7 @@ blkverify_co_pwritev(BlockDriverState *bs, int64_t offs= et, int64_t bytes, return blkverify_co_prwv(bs, &r, offset, bytes, qiov, qiov, flags, tru= e); } =20 -static int coroutine_fn blkverify_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK blkverify_co_flush(BlockDriverState *= bs) { BDRVBlkverifyState *s =3D bs->opaque; =20 diff --git a/block/block-backend.c b/block/block-backend.c index 5c731a1c6c..3e58b95b8a 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1762,8 +1762,9 @@ int coroutine_fn blk_co_pdiscard(BlockBackend *blk, i= nt64_t offset, /* To be called between exactly one pair of blk_inc/dec_in_flight() */ static int coroutine_fn blk_co_do_flush(BlockBackend *blk) { - blk_wait_while_drained(blk); IO_CODE(); + blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); =20 if (!blk_is_available(blk)) { return -ENOMEDIUM; diff --git a/block/copy-before-write.c b/block/copy-before-write.c index c9fb809ba0..4ba72c6309 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -185,7 +185,7 @@ static coroutine_fn int cbw_co_pwritev(BlockDriverState= *bs, return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags); } =20 -static int coroutine_fn cbw_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK cbw_co_flush(BlockDriverState *bs) { if (!bs->file) { return 0; diff --git a/block/file-posix.c b/block/file-posix.c index 9a99111f45..d106f4efa5 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2920,8 +2920,8 @@ static void coroutine_fn check_cache_dropped(BlockDri= verState *bs, Error **errp) } #endif /* __linux__ */ =20 -static void coroutine_fn raw_co_invalidate_cache(BlockDriverState *bs, - Error **errp) +static void coroutine_fn GRAPH_RDLOCK +raw_co_invalidate_cache(BlockDriverState *bs, Error **errp) { BDRVRawState *s =3D bs->opaque; int ret; diff --git a/block/io.c b/block/io.c index c03233ae94..cfc93dc912 100644 --- a/block/io.c +++ b/block/io.c @@ -933,6 +933,8 @@ int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, = int64_t offset, int ret; IO_CODE(); =20 + assume_graph_lock(); /* FIXME */ + ret =3D bdrv_co_pwrite(child, offset, bytes, buf, flags); if (ret < 0) { return ret; @@ -1041,6 +1043,8 @@ static int coroutine_fn bdrv_driver_pwritev(BlockDriv= erState *bs, QEMUIOVector local_qiov; int ret; =20 + assume_graph_lock(); /* FIXME */ + bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 if (!drv) { @@ -1680,6 +1684,8 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(Bloc= kDriverState *bs, int head =3D 0; int tail =3D 0; =20 + assume_graph_lock(); /* FIXME */ + int64_t max_write_zeroes =3D MIN_NON_ZERO(bs->bl.max_pwrite_zeroes, INT64_MAX); int alignment =3D MAX(bs->bl.pwrite_zeroes_alignment, @@ -2839,6 +2845,7 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) int ret =3D 0; IO_CODE(); =20 + assert_bdrv_graph_readable(); bdrv_inc_in_flight(bs); =20 if (!bdrv_co_is_inserted(bs) || bdrv_is_read_only(bs) || diff --git a/block/mirror.c b/block/mirror.c index 94c523af28..d1d79f2319 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1535,7 +1535,7 @@ static int coroutine_fn bdrv_mirror_top_pwritev(Block= DriverState *bs, return ret; } =20 -static int coroutine_fn bdrv_mirror_top_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK bdrv_mirror_top_flush(BlockDriverStat= e *bs) { if (bs->backing =3D=3D NULL) { /* we can be here after failed bdrv_append in mirror_start_job */ diff --git a/block/preallocate.c b/block/preallocate.c index 42da9cb9f1..483b596280 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -437,7 +437,7 @@ preallocate_co_truncate(BlockDriverState *bs, int64_t o= ffset, return 0; } =20 -static int coroutine_fn preallocate_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK preallocate_co_flush(BlockDriverState= *bs) { return bdrv_co_flush(bs->file->bs); } diff --git a/block/qed-check.c b/block/qed-check.c index a6612be00f..8fd94f405e 100644 --- a/block/qed-check.c +++ b/block/qed-check.c @@ -107,7 +107,8 @@ static unsigned int qed_check_l2_table(QEDCheck *check,= QEDTable *table) /** * Descend tables and check each cluster is referenced once only */ -static int coroutine_fn qed_check_l1_table(QEDCheck *check, QEDTable *tabl= e) +static int coroutine_fn GRAPH_RDLOCK +qed_check_l1_table(QEDCheck *check, QEDTable *table) { BDRVQEDState *s =3D check->s; unsigned int i, num_invalid_l1 =3D 0; diff --git a/block/qed-table.c b/block/qed-table.c index e41c87a157..e9c72814c8 100644 --- a/block/qed-table.c +++ b/block/qed-table.c @@ -63,9 +63,9 @@ out: * * Called with table_lock held. */ -static int coroutine_fn qed_write_table(BDRVQEDState *s, uint64_t offset, - QEDTable *table, unsigned int inde= x, - unsigned int n, bool flush) +static int coroutine_fn GRAPH_RDLOCK +qed_write_table(BDRVQEDState *s, uint64_t offset, QEDTable *table, + unsigned int index, unsigned int n, bool flush) { unsigned int sector_mask =3D BDRV_SECTOR_SIZE / sizeof(uint64_t) - 1; unsigned int start, end, i; diff --git a/block/qed.c b/block/qed.c index 7690d0215d..cf794a1add 100644 --- a/block/qed.c +++ b/block/qed.c @@ -395,8 +395,8 @@ static void bdrv_qed_init_state(BlockDriverState *bs) } =20 /* Called with table_lock held. */ -static int coroutine_fn bdrv_qed_do_open(BlockDriverState *bs, QDict *opti= ons, - int flags, Error **errp) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_do_open(BlockDriverState *bs, QDict *options, int flags, Error **= errp) { BDRVQEDState *s =3D bs->opaque; QEDHeader le_header; @@ -557,7 +557,7 @@ typedef struct QEDOpenCo { int ret; } QEDOpenCo; =20 -static void coroutine_fn bdrv_qed_open_entry(void *opaque) +static void coroutine_fn GRAPH_RDLOCK bdrv_qed_open_entry(void *opaque) { QEDOpenCo *qoc =3D opaque; BDRVQEDState *s =3D qoc->bs->opaque; @@ -579,6 +579,8 @@ static int bdrv_qed_open(BlockDriverState *bs, QDict *o= ptions, int flags, }; int ret; =20 + assume_graph_lock(); /* FIXME */ + ret =3D bdrv_open_file_child(NULL, options, "file", bs, errp); if (ret < 0) { return ret; @@ -995,7 +997,7 @@ static void coroutine_fn qed_aio_complete(QEDAIOCB *acb) * * Called with table_lock held. */ -static int coroutine_fn qed_aio_write_l1_update(QEDAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK qed_aio_write_l1_update(QEDAIOCB *acb) { BDRVQEDState *s =3D acb_to_s(acb); CachedL2Table *l2_table =3D acb->request.l2_table; @@ -1025,7 +1027,8 @@ static int coroutine_fn qed_aio_write_l1_update(QEDAI= OCB *acb) * * Called with table_lock held. */ -static int coroutine_fn qed_aio_write_l2_update(QEDAIOCB *acb, uint64_t of= fset) +static int coroutine_fn GRAPH_RDLOCK +qed_aio_write_l2_update(QEDAIOCB *acb, uint64_t offset) { BDRVQEDState *s =3D acb_to_s(acb); bool need_alloc =3D acb->find_cluster_ret =3D=3D QED_CLUSTER_L1; @@ -1081,7 +1084,7 @@ static int coroutine_fn qed_aio_write_main(QEDAIOCB *= acb) * * Called with table_lock held. */ -static int coroutine_fn qed_aio_write_cow(QEDAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK qed_aio_write_cow(QEDAIOCB *acb) { BDRVQEDState *s =3D acb_to_s(acb); uint64_t start, len, offset; @@ -1159,7 +1162,8 @@ static bool qed_should_set_need_check(BDRVQEDState *s) * * Called with table_lock held. */ -static int coroutine_fn qed_aio_write_alloc(QEDAIOCB *acb, size_t len) +static int coroutine_fn GRAPH_RDLOCK +qed_aio_write_alloc(QEDAIOCB *acb, size_t len) { BDRVQEDState *s =3D acb_to_s(acb); int ret; @@ -1265,8 +1269,8 @@ out: * * Called with table_lock held. */ -static int coroutine_fn qed_aio_write_data(void *opaque, int ret, - uint64_t offset, size_t len) +static int coroutine_fn GRAPH_RDLOCK +qed_aio_write_data(void *opaque, int ret, uint64_t offset, size_t len) { QEDAIOCB *acb =3D opaque; =20 @@ -1336,7 +1340,7 @@ static int coroutine_fn qed_aio_read_data(void *opaqu= e, int ret, /** * Begin next I/O or complete the request */ -static int coroutine_fn qed_aio_next_io(QEDAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK qed_aio_next_io(QEDAIOCB *acb) { BDRVQEDState *s =3D acb_to_s(acb); uint64_t offset; @@ -1381,9 +1385,9 @@ static int coroutine_fn qed_aio_next_io(QEDAIOCB *acb) return ret; } =20 -static int coroutine_fn qed_co_request(BlockDriverState *bs, int64_t secto= r_num, - QEMUIOVector *qiov, int nb_sectors, - int flags) +static int coroutine_fn GRAPH_RDLOCK +qed_co_request(BlockDriverState *bs, int64_t sector_num, QEMUIOVector *qio= v, + int nb_sectors, int flags) { QEDAIOCB acb =3D { .bs =3D bs, @@ -1404,6 +1408,7 @@ static int coroutine_fn bdrv_qed_co_readv(BlockDriver= State *bs, int64_t sector_num, int nb_secto= rs, QEMUIOVector *qiov) { + assume_graph_lock(); /* FIXME */ return qed_co_request(bs, sector_num, qiov, nb_sectors, 0); } =20 @@ -1411,6 +1416,7 @@ static int coroutine_fn bdrv_qed_co_writev(BlockDrive= rState *bs, int64_t sector_num, int nb_sect= ors, QEMUIOVector *qiov, int flags) { + assume_graph_lock(); /* FIXME */ return qed_co_request(bs, sector_num, qiov, nb_sectors, QED_AIOCB_WRIT= E); } =20 @@ -1421,6 +1427,8 @@ static int coroutine_fn bdrv_qed_co_pwrite_zeroes(Blo= ckDriverState *bs, { BDRVQEDState *s =3D bs->opaque; =20 + assume_graph_lock(); /* FIXME */ + /* * Zero writes start without an I/O buffer. If a buffer becomes neces= sary * then it will be allocated during request processing. @@ -1571,8 +1579,8 @@ static int bdrv_qed_change_backing_file(BlockDriverSt= ate *bs, return ret; } =20 -static void coroutine_fn bdrv_qed_co_invalidate_cache(BlockDriverState *bs, - Error **errp) +static void coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_invalidate_cache(BlockDriverState *bs, Error **errp) { BDRVQEDState *s =3D bs->opaque; int ret; @@ -1588,9 +1596,9 @@ static void coroutine_fn bdrv_qed_co_invalidate_cache= (BlockDriverState *bs, } } =20 -static int coroutine_fn bdrv_qed_co_check(BlockDriverState *bs, - BdrvCheckResult *result, - BdrvCheckMode fix) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_check(BlockDriverState *bs, BdrvCheckResult *result, + BdrvCheckMode fix) { BDRVQEDState *s =3D bs->opaque; int ret; diff --git a/block/quorum.c b/block/quorum.c index f3fe067541..3fe3791ab2 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -778,7 +778,7 @@ static int64_t coroutine_fn quorum_co_getlength(BlockDr= iverState *bs) return result; } =20 -static coroutine_fn int quorum_co_flush(BlockDriverState *bs) +static coroutine_fn GRAPH_RDLOCK int quorum_co_flush(BlockDriverState *bs) { BDRVQuorumState *s =3D bs->opaque; QuorumVoteVersion *winner =3D NULL; diff --git a/block/throttle.c b/block/throttle.c index 64fa0f5acc..a0db840927 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -162,7 +162,7 @@ static int coroutine_fn throttle_co_pwritev_compressed(= BlockDriverState *bs, BDRV_REQ_WRITE_COMPRESSED); } =20 -static int coroutine_fn throttle_co_flush(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK throttle_co_flush(BlockDriverState *b= s) { return bdrv_co_flush(bs->file->bs); } diff --git a/block/vmdk.c b/block/vmdk.c index 3fcb75319f..d074f696aa 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1484,8 +1484,8 @@ exit: return ret; } =20 -static int coroutine_fn vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_= data, - uint32_t offset) +static int coroutine_fn GRAPH_RDLOCK +vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_data, uint32_t offset) { offset =3D cpu_to_le32(offset); /* update L2 table */ @@ -2028,6 +2028,8 @@ static int coroutine_fn vmdk_pwritev(BlockDriverState= *bs, uint64_t offset, uint64_t bytes_done =3D 0; VmdkMetaData m_data; =20 + assume_graph_lock(); /* FIXME */ + if (DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) > bs->total_sectors) { error_report("Wrong offset: offset=3D0x%" PRIx64 " total_sectors=3D0x%" PRIx64, --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178575; cv=none; d=zohomail.com; s=zohoarc; b=H5OBpmxpZAMYwzjb0JlmdKnQ9/6SdJ2yhjgxjBJGBSufdGqzN92/C8ZdKAGguOV8AITiKr8qWpAVvIYJcZrpnGas0jIuKKoKU3cE0Q0pVSkc6EXVw95sv9vI/ndC6hFqLZEiaPbqHYDsZFmH+AIElQziqxI1VhKb8rutkbChHBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178575; 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=9IinxE0ZJHYLBpHdPljOF/TZJjN/xClaWSlZqHeDK24=; b=Og0u44+aNKC5G8oywdpaYR+EM+jjiK1HM41EvDV264Q+jDgbXJgz5g4PI/a3twuh0O2tbdEqRWLgKw2CrHp6r7W2w/URoT8oz70SD472n5dIwYmLQoNkZb2DSkJHFLGDv4PjkxkYYWrmGks+YKdck4Rp8pUXgmpIsLwt1pHGkNU= 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 1677178575839733.323875629935; Thu, 23 Feb 2023 10:56:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhQ-0006rD-9Y; Thu, 23 Feb 2023 13:52:12 -0500 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 1pVGhJ-0006np-Vc for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:05 -0500 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 1pVGhH-00032A-AK for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:05 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-226-g_hTaun4PpuM_Z0niJ2Mrw-1; Thu, 23 Feb 2023 13:51:59 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0C59F811E6E; Thu, 23 Feb 2023 18:51:59 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57B871121314; Thu, 23 Feb 2023 18:51:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178322; 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=9IinxE0ZJHYLBpHdPljOF/TZJjN/xClaWSlZqHeDK24=; b=FfJA967fH0A0IgM9RQFpWJDtCfuDQyJhDx14YPrLnkR3X28Fu3OSCyRZ8F2oUHGjOTiajL IrJxRGnVJoiUr0AU5E2FXz41Q3S/W+6BbNBT2BU5hTYcKb2u3qYOEXL/GB//Qw67ZnCzFU wFvLXselRFzoUDUI5KYp7R+MkWoKh1c= X-MC-Unique: g_hTaun4PpuM_Z0niJ2Mrw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 08/29] block: Mark bdrv_co_pdiscard() and callers GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:25 +0100 Message-Id: <20230223185146.306454-9-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178577731100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_pdiscard() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-9-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- include/block/block-io.h | 5 +++-- include/block/block_int-common.h | 15 +++++++++------ include/block/block_int-io.h | 2 +- block/blkdebug.c | 4 ++-- block/blklogwrites.c | 5 ++--- block/blkreplay.c | 4 ++-- block/block-backend.c | 1 + block/copy-before-write.c | 8 ++++---- block/copy-on-read.c | 4 ++-- block/filter-compress.c | 4 ++-- block/io.c | 2 ++ block/mirror.c | 14 +++++++++----- block/preallocate.c | 4 ++-- block/raw-format.c | 4 ++-- block/snapshot-access.c | 4 ++-- block/throttle.c | 4 ++-- 16 files changed, 47 insertions(+), 37 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 7e96506138..627061fd5f 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -103,8 +103,9 @@ bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); /* Ensure contents are flushed to disk. */ int coroutine_fn GRAPH_RDLOCK bdrv_co_flush(BlockDriverState *bs); =20 -int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, - int64_t bytes); +int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard(BdrvChild *child, int64_t o= ffset, + int64_t bytes); + bool bdrv_can_write_zeroes_with_unmap(BlockDriverState *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 51eaabd9d1..c52190abdb 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -479,8 +479,9 @@ struct BlockDriver { BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque); BlockAIOCB * GRAPH_RDLOCK_PTR (*bdrv_aio_flush)( BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque); - BlockAIOCB *(*bdrv_aio_pdiscard)(BlockDriverState *bs, - int64_t offset, int bytes, + + BlockAIOCB * GRAPH_RDLOCK_PTR (*bdrv_aio_pdiscard)( + BlockDriverState *bs, int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque); =20 int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs, @@ -543,8 +544,9 @@ struct BlockDriver { */ int coroutine_fn (*bdrv_co_pwrite_zeroes)(BlockDriverState *bs, int64_t offset, int64_t bytes, BdrvRequestFlags flags); - int coroutine_fn (*bdrv_co_pdiscard)(BlockDriverState *bs, - int64_t offset, int64_t bytes); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pdiscard)( + BlockDriverState *bs, int64_t offset, int64_t bytes); =20 /* * Map [offset, offset + nbytes) range onto a child of @bs to copy fro= m, @@ -632,8 +634,9 @@ struct BlockDriver { int coroutine_fn (*bdrv_co_snapshot_block_status)(BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); - int coroutine_fn (*bdrv_co_pdiscard_snapshot)(BlockDriverState *bs, - int64_t offset, int64_t bytes); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pdiscard_snapshot)( + BlockDriverState *bs, int64_t offset, int64_t bytes); =20 /* * Invalidate any cached meta-data. diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 4430bf4c4a..4bb6ccaa34 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -40,7 +40,7 @@ int coroutine_fn bdrv_co_preadv_snapshot(BdrvChild *child, int coroutine_fn bdrv_co_snapshot_block_status(BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); -int coroutine_fn bdrv_co_pdiscard_snapshot(BlockDriverState *bs, +int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard_snapshot(BlockDriverState *= bs, int64_t offset, int64_t bytes); =20 =20 diff --git a/block/blkdebug.c b/block/blkdebug.c index 5ba3766a2c..8506004707 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -712,8 +712,8 @@ static int coroutine_fn blkdebug_co_pwrite_zeroes(Block= DriverState *bs, return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } =20 -static int coroutine_fn blkdebug_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +blkdebug_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { uint32_t align =3D bs->bl.pdiscard_alignment; int err; diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 5ec1d23f29..3033f5035b 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -450,7 +450,7 @@ blk_log_writes_co_do_file_flush(BlkLogWritesFileReq *fr) return bdrv_co_flush(fr->bs->file->bs); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_do_file_pdiscard(BlkLogWritesFileReq *fr) { return bdrv_co_pdiscard(fr->bs->file, fr->offset, fr->bytes); @@ -483,10 +483,9 @@ blk_log_writes_co_flush_to_disk(BlockDriverState *bs) LOG_FLUSH_FLAG, false); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t b= ytes) { - assume_graph_lock(); /* FIXME */ return blk_log_writes_co_log(bs, offset, bytes, NULL, 0, blk_log_writes_co_do_file_pdiscard, LOG_DISCARD_FLAG, false); diff --git a/block/blkreplay.c b/block/blkreplay.c index ce13fa5ba5..c18d3a755d 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -102,8 +102,8 @@ static int coroutine_fn blkreplay_co_pwrite_zeroes(Bloc= kDriverState *bs, return ret; } =20 -static int coroutine_fn blkreplay_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t byte= s) +static int coroutine_fn GRAPH_RDLOCK +blkreplay_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { uint64_t reqid =3D blkreplay_next_id(); int ret =3D bdrv_co_pdiscard(bs->file, offset, bytes); diff --git a/block/block-backend.c b/block/block-backend.c index 3e58b95b8a..b4d2387947 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1719,6 +1719,7 @@ blk_co_do_pdiscard(BlockBackend *blk, int64_t offset,= int64_t bytes) IO_CODE(); =20 blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); =20 ret =3D blk_check_byte_request(blk, offset, bytes); if (ret < 0) { diff --git a/block/copy-before-write.c b/block/copy-before-write.c index 4ba72c6309..42b46e746a 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -149,8 +149,8 @@ static coroutine_fn int cbw_do_copy_before_write(BlockD= riverState *bs, return 0; } =20 -static int coroutine_fn cbw_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +cbw_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { int ret =3D cbw_do_copy_before_write(bs, offset, bytes, 0); if (ret < 0) { @@ -322,8 +322,8 @@ cbw_co_snapshot_block_status(BlockDriverState *bs, return ret; } =20 -static int coroutine_fn cbw_co_pdiscard_snapshot(BlockDriverState *bs, - int64_t offset, int64_t b= ytes) +static int coroutine_fn GRAPH_RDLOCK +cbw_co_pdiscard_snapshot(BlockDriverState *bs, int64_t offset, int64_t byt= es) { BDRVCopyBeforeWriteState *s =3D bs->opaque; =20 diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 3280eb2feb..b564f1ca3f 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -200,8 +200,8 @@ static int coroutine_fn cor_co_pwrite_zeroes(BlockDrive= rState *bs, } =20 =20 -static int coroutine_fn cor_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +cor_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { return bdrv_co_pdiscard(bs->file, offset, bytes); } diff --git a/block/filter-compress.c b/block/filter-compress.c index 2e2a65966c..083aaef53c 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -92,8 +92,8 @@ static int coroutine_fn compress_co_pwrite_zeroes(BlockDr= iverState *bs, } =20 =20 -static int coroutine_fn compress_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +compress_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { return bdrv_co_pdiscard(bs->file, offset, bytes); } diff --git a/block/io.c b/block/io.c index cfc93dc912..e97adb5ba4 100644 --- a/block/io.c +++ b/block/io.c @@ -2971,6 +2971,7 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, i= nt64_t offset, int head, tail, align; BlockDriverState *bs =3D child->bs; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!bs || !bs->drv || !bdrv_co_is_inserted(bs)) { return -ENOMEDIUM; @@ -3577,6 +3578,7 @@ bdrv_co_pdiscard_snapshot(BlockDriverState *bs, int64= _t offset, int64_t bytes) BlockDriver *drv =3D bs->drv; int ret; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!drv) { return -ENOMEDIUM; diff --git a/block/mirror.c b/block/mirror.c index d1d79f2319..b67e8b14f8 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1443,9 +1443,10 @@ static int coroutine_fn bdrv_mirror_top_preadv(Block= DriverState *bs, return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags); } =20 -static int coroutine_fn bdrv_mirror_top_do_write(BlockDriverState *bs, - MirrorMethod method, uint64_t offset, uint64_t bytes, QEMUIOVector *qi= ov, - int flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_do_write(BlockDriverState *bs, MirrorMethod method, + uint64_t offset, uint64_t bytes, QEMUIOVector *qi= ov, + int flags) { MirrorOp *op =3D NULL; MirrorBDSOpaque *s =3D bs->opaque; @@ -1503,6 +1504,8 @@ static int coroutine_fn bdrv_mirror_top_pwritev(Block= DriverState *bs, int ret =3D 0; bool copy_to_target =3D false; =20 + assume_graph_lock(); /* FIXME */ + if (s->job) { copy_to_target =3D s->job->ret >=3D 0 && !job_is_cancelled(&s->job->common.job) && @@ -1547,12 +1550,13 @@ static int coroutine_fn GRAPH_RDLOCK bdrv_mirror_to= p_flush(BlockDriverState *bs) static int coroutine_fn bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, BdrvRequestFlags flags) { + assume_graph_lock(); /* FIXME */ return bdrv_mirror_top_do_write(bs, MIRROR_METHOD_ZERO, offset, bytes,= NULL, flags); } =20 -static int coroutine_fn bdrv_mirror_top_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_pdiscard(BlockDriverState *bs, int64_t offset, int64_t byt= es) { return bdrv_mirror_top_do_write(bs, MIRROR_METHOD_DISCARD, offset, byt= es, NULL, 0); diff --git a/block/preallocate.c b/block/preallocate.c index 483b596280..c2c2dc8a8c 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -234,8 +234,8 @@ static coroutine_fn int preallocate_co_preadv_part( flags); } =20 -static int coroutine_fn preallocate_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t byt= es) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t byte= s) { return bdrv_co_pdiscard(bs->file, offset, bytes); } diff --git a/block/raw-format.c b/block/raw-format.c index 202acb1232..7f1036ebed 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -305,8 +305,8 @@ static int coroutine_fn raw_co_pwrite_zeroes(BlockDrive= rState *bs, return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } =20 -static int coroutine_fn raw_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +raw_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { int ret; =20 diff --git a/block/snapshot-access.c b/block/snapshot-access.c index 0a30ec6cd9..009cc4aea0 100644 --- a/block/snapshot-access.c +++ b/block/snapshot-access.c @@ -49,8 +49,8 @@ snapshot_access_co_block_status(BlockDriverState *bs, bytes, pnum, map, file); } =20 -static int coroutine_fn snapshot_access_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +snapshot_access_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t = bytes) { return bdrv_co_pdiscard_snapshot(bs->file->bs, offset, bytes); } diff --git a/block/throttle.c b/block/throttle.c index a0db840927..b07d853c0a 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -144,8 +144,8 @@ static int coroutine_fn throttle_co_pwrite_zeroes(Block= DriverState *bs, return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } =20 -static int coroutine_fn throttle_co_pdiscard(BlockDriverState *bs, - int64_t offset, int64_t bytes) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_pdiscard(BlockDriverState *bs, int64_t offset, int64_t bytes) { ThrottleGroupMember *tgm =3D bs->opaque; throttle_group_co_io_limits_intercept(tgm, bytes, true); --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178640; cv=none; d=zohomail.com; s=zohoarc; b=K0ko0LGfxAWJIf8QXmtPLRrPjI2Wq/q3OBLfUHremt6ml+wMJ7cxrhekWzDMHAj2RiBcBQ9gJ6aRTRJF3Iv1nJhOVn1oHu9KcEe1/thMmz1jWfPz5q2ks+8ECv4Z+HsHBg3b9weLcYu5UH/8DSikGxffGnHdOg8U5t8sUQFdWvk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178640; 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=gZWadILoWUksiS0KjCZg8zbq9RgX0lVki/lMxezM3Gg=; b=R2mtRSCr3oNW/RZn04IfTh87Xr72PVB+tit0hzd7/v3tEVWyfkZ8eRW5Lx2uqrbp2G4iEAnLnObyKxRqjUwe3nNwRv/NFiTzCHdeSGxWlu43YAq+h6CMI+uEdRwRuH6+gUK7GrTh+OekAYH7MgXj1IZAZXC71yEOokN1+HU8vFs= 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 1677178640897996.1898175603874; Thu, 23 Feb 2023 10:57:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhP-0006r7-RH; Thu, 23 Feb 2023 13:52:11 -0500 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 1pVGhM-0006p9-Ea for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:08 -0500 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 1pVGhI-000364-HA for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:07 -0500 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-662-7iTi1N8-M--Kiwho4n0X2w-1; Thu, 23 Feb 2023 13:52:00 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E9A7B86C165; Thu, 23 Feb 2023 18:51:59 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42B231121314; Thu, 23 Feb 2023 18:51:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178323; 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=gZWadILoWUksiS0KjCZg8zbq9RgX0lVki/lMxezM3Gg=; b=FWJGgLIcLjnX12HXyBimAAdRLJUBqaCp39AFRHSMSkt1DG3ndNpmgtl4GZVp7RiOqHVmBX vbllogUQ9KBYZL18q6PKL2lzVT0nxQPSDwgFAm26rWrjHEySrHm/fSDokNaLw75+fcscMX yVQbM/EsD4IJ8RxeoSmshfJ1KE0/Zqs= X-MC-Unique: 7iTi1N8-M--Kiwho4n0X2w-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 09/29] block: Mark bdrv_co_pwrite_zeroes() and callers GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:26 +0100 Message-Id: <20230223185146.306454-10-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178642194100005 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_pwrite_zeroes() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-10-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- block/qcow2.h | 6 ++++-- include/block/block-io.h | 9 +++++---- include/block/block_int-common.h | 5 +++-- block/blkdebug.c | 6 +++--- block/blklogwrites.c | 5 ++--- block/blkreplay.c | 5 +++-- block/block-copy.c | 13 +++++++------ block/copy-before-write.c | 5 +++-- block/copy-on-read.c | 6 +++--- block/filter-compress.c | 6 +++--- block/io.c | 12 +++++++++--- block/mirror.c | 6 +++--- block/preallocate.c | 11 +++++++---- block/qcow2.c | 30 ++++++++++++++++++------------ block/qed.c | 9 +++------ block/quorum.c | 15 ++++++++++----- block/raw-format.c | 6 +++--- block/throttle.c | 6 +++--- 18 files changed, 92 insertions(+), 69 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 7a02699bfa..82cd1664cf 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -927,8 +927,10 @@ void qcow2_alloc_cluster_abort(BlockDriverState *bs, Q= CowL2Meta *m); int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset, uint64_t bytes, enum qcow2_discard_type type, bool full_discard); -int coroutine_fn qcow2_subcluster_zeroize(BlockDriverState *bs, uint64_t o= ffset, - uint64_t bytes, int flags); + +int coroutine_fn GRAPH_RDLOCK +qcow2_subcluster_zeroize(BlockDriverState *bs, uint64_t offset, uint64_t b= ytes, + int flags); =20 int qcow2_expand_zero_clusters(BlockDriverState *bs, BlockDriverAmendStatusCB *status_cb, diff --git a/include/block/block-io.h b/include/block/block-io.h index 627061fd5f..ec26f07d60 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -69,8 +69,9 @@ int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, in= t64_t offset, * function is not suitable for zeroing the entire image in a single reque= st * because it may allocate memory for the entire region. */ -int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, - int64_t bytes, BdrvRequestFlags fla= gs); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, int64_t bytes, + BdrvRequestFlags flags); =20 int coroutine_fn GRAPH_RDLOCK bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact, @@ -133,8 +134,8 @@ int bdrv_is_allocated_above(BlockDriverState *top, Bloc= kDriverState *base, bool include_base, int64_t offset, int64_t byt= es, int64_t *pnum); =20 -int coroutine_fn bdrv_co_is_zero_fast(BlockDriverState *bs, int64_t offset, - int64_t bytes); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_is_zero_fast(BlockDriverState *bs, int64_t offset, int64_t bytes); =20 int bdrv_apply_auto_read_only(BlockDriverState *bs, const char *errmsg, Error **errp); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index c52190abdb..21b4cb1101 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -542,8 +542,9 @@ struct BlockDriver { * function pointer may be NULL or return -ENOSUP and .bdrv_co_writev() * will be called instead. */ - int coroutine_fn (*bdrv_co_pwrite_zeroes)(BlockDriverState *bs, - int64_t offset, int64_t bytes, BdrvRequestFlags flags); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwrite_zeroes)( + BlockDriverState *bs, int64_t offset, int64_t bytes, + BdrvRequestFlags flags); =20 int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pdiscard)( BlockDriverState *bs, int64_t offset, int64_t bytes); diff --git a/block/blkdebug.c b/block/blkdebug.c index 8506004707..eed03bfe7e 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -679,9 +679,9 @@ static int GRAPH_RDLOCK coroutine_fn blkdebug_co_flush(= BlockDriverState *bs) return bdrv_co_flush(bs->file->bs); } =20 -static int coroutine_fn blkdebug_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t = bytes, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +blkdebug_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t by= tes, + BdrvRequestFlags flags) { uint32_t align =3D MAX(bs->bl.request_alignment, bs->bl.pwrite_zeroes_alignment); diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 3033f5035b..bdaa2a57a2 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -437,7 +437,7 @@ blk_log_writes_co_do_file_pwritev(BlkLogWritesFileReq *= fr) fr->qiov, fr->file_flags); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_do_file_pwrite_zeroes(BlkLogWritesFileReq *fr) { return bdrv_co_pwrite_zeroes(fr->bs->file, fr->offset, fr->bytes, @@ -465,11 +465,10 @@ blk_log_writes_co_pwritev(BlockDriverState *bs, int64= _t offset, int64_t bytes, blk_log_writes_co_do_file_pwritev, 0, fal= se); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, BdrvRequestFlags flags) { - assume_graph_lock(); /* FIXME */ return blk_log_writes_co_log(bs, offset, bytes, NULL, flags, blk_log_writes_co_do_file_pwrite_zeroes, = 0, true); diff --git a/block/blkreplay.c b/block/blkreplay.c index c18d3a755d..2703a0c8c6 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -91,8 +91,9 @@ static int coroutine_fn blkreplay_co_pwritev(BlockDriverS= tate *bs, return ret; } =20 -static int coroutine_fn blkreplay_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +blkreplay_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t b= ytes, + BdrvRequestFlags flags) { uint64_t reqid =3D blkreplay_next_id(); int ret =3D bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); diff --git a/block/block-copy.c b/block/block-copy.c index d299fac7cc..e13d7bc6b6 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -469,10 +469,9 @@ static coroutine_fn int block_copy_task_run(AioTaskPoo= l *pool, * value of @method should be used for subsequent tasks. * Returns 0 on success. */ -static int coroutine_fn block_copy_do_copy(BlockCopyState *s, - int64_t offset, int64_t bytes, - BlockCopyMethod *method, - bool *error_is_read) +static int coroutine_fn GRAPH_RDLOCK +block_copy_do_copy(BlockCopyState *s, int64_t offset, int64_t bytes, + BlockCopyMethod *method, bool *error_is_read) { int ret; int64_t nbytes =3D MIN(offset + bytes, s->len) - offset; @@ -558,8 +557,10 @@ static coroutine_fn int block_copy_task_entry(AioTask = *task) BlockCopyMethod method =3D t->method; int ret; =20 - ret =3D block_copy_do_copy(s, t->req.offset, t->req.bytes, &method, - &error_is_read); + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D block_copy_do_copy(s, t->req.offset, t->req.bytes, &method, + &error_is_read); + } =20 WITH_QEMU_LOCK_GUARD(&s->lock) { if (s->method =3D=3D t->method) { diff --git a/block/copy-before-write.c b/block/copy-before-write.c index 42b46e746a..61854beae2 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -160,8 +160,9 @@ cbw_co_pdiscard(BlockDriverState *bs, int64_t offset, i= nt64_t bytes) return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 -static int coroutine_fn cbw_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cbw_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, + BdrvRequestFlags flags) { int ret =3D cbw_do_copy_before_write(bs, offset, bytes, flags); if (ret < 0) { diff --git a/block/copy-on-read.c b/block/copy-on-read.c index b564f1ca3f..ebf6864dd3 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -192,9 +192,9 @@ static int coroutine_fn cor_co_pwritev_part(BlockDriver= State *bs, } =20 =20 -static int coroutine_fn cor_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cor_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, + BdrvRequestFlags flags) { return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } diff --git a/block/filter-compress.c b/block/filter-compress.c index 083aaef53c..7a632f47fe 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -84,9 +84,9 @@ static int coroutine_fn compress_co_pwritev_part(BlockDri= verState *bs, } =20 =20 -static int coroutine_fn compress_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t = bytes, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +compress_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t by= tes, + BdrvRequestFlags flags) { return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } diff --git a/block/io.c b/block/io.c index e97adb5ba4..00843362e9 100644 --- a/block/io.c +++ b/block/io.c @@ -1172,6 +1172,8 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(Bdrv= Child *child, int64_t progress =3D 0; bool skip_write; =20 + assume_graph_lock(); /* FIXME */ + bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 if (!drv) { @@ -1692,6 +1694,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(Bloc= kDriverState *bs, bs->bl.request_alignment); int max_transfer =3D MIN_NON_ZERO(bs->bl.max_transfer, MAX_BOUNCE_BUFF= ER); =20 + assert_bdrv_graph_readable(); bdrv_check_request(offset, bytes, &error_abort); =20 if (!drv) { @@ -1907,6 +1910,8 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChil= d *child, int64_t bytes_remaining =3D bytes; int max_transfer; =20 + assume_graph_lock(); /* FIXME */ + bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 if (!drv) { @@ -2159,6 +2164,7 @@ int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *chi= ld, int64_t offset, { IO_CODE(); trace_bdrv_co_pwrite_zeroes(child->bs, offset, bytes, flags); + assert_bdrv_graph_readable(); =20 if (!(child->bs->open_flags & BDRV_O_UNMAP)) { flags &=3D ~BDRV_REQ_MAY_UNMAP; @@ -2602,8 +2608,6 @@ int coroutine_fn bdrv_co_is_zero_fast(BlockDriverStat= e *bs, int64_t offset, int64_t pnum =3D bytes; IO_CODE(); =20 - assume_graph_lock(); /* FIXME */ - if (!bytes) { return 1; } @@ -3241,7 +3245,7 @@ void bdrv_unregister_buf(BlockDriverState *bs, void *= host, size_t size) } } =20 -static int coroutine_fn bdrv_co_copy_range_internal( +static int coroutine_fn GRAPH_RDLOCK bdrv_co_copy_range_internal( BdrvChild *src, int64_t src_offset, BdrvChild *dst, int64_t dst_offset, int64_t bytes, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags, @@ -3330,6 +3334,7 @@ int coroutine_fn bdrv_co_copy_range_from(BdrvChild *s= rc, int64_t src_offset, BdrvRequestFlags write_flags) { IO_CODE(); + assume_graph_lock(); /* FIXME */ trace_bdrv_co_copy_range_from(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, @@ -3347,6 +3352,7 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src= , int64_t src_offset, BdrvRequestFlags write_flags) { IO_CODE(); + assume_graph_lock(); /* FIXME */ trace_bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, diff --git a/block/mirror.c b/block/mirror.c index b67e8b14f8..a6f4ec6282 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -1547,10 +1547,10 @@ static int coroutine_fn GRAPH_RDLOCK bdrv_mirror_to= p_flush(BlockDriverState *bs) return bdrv_co_flush(bs->backing->bs); } =20 -static int coroutine_fn bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_pwrite_zeroes(BlockDriverState *bs, int64_t offset, + int64_t bytes, BdrvRequestFlags flags) { - assume_graph_lock(); /* FIXME */ return bdrv_mirror_top_do_write(bs, MIRROR_METHOD_ZERO, offset, bytes,= NULL, flags); } diff --git a/block/preallocate.c b/block/preallocate.c index c2c2dc8a8c..91d73c81c6 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -269,8 +269,9 @@ static bool has_prealloc_perms(BlockDriverState *bs) * want_merge_zero is used to merge write-zero request with preallocation = in * one bdrv_co_pwrite_zeroes() call. */ -static bool coroutine_fn handle_write(BlockDriverState *bs, int64_t offset, - int64_t bytes, bool want_merge_zero) +static bool coroutine_fn GRAPH_RDLOCK +handle_write(BlockDriverState *bs, int64_t offset, int64_t bytes, + bool want_merge_zero) { BDRVPreallocateState *s =3D bs->opaque; int64_t end =3D offset + bytes; @@ -345,8 +346,9 @@ static bool coroutine_fn handle_write(BlockDriverState = *bs, int64_t offset, return want_merge_zero; } =20 -static int coroutine_fn preallocate_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, + int64_t bytes, BdrvRequestFlags flags) { bool want_merge_zero =3D !(flags & ~(BDRV_REQ_ZERO_WRITE | BDRV_REQ_NO_FALLBACK)); @@ -364,6 +366,7 @@ static coroutine_fn int preallocate_co_pwritev_part(Blo= ckDriverState *bs, size_t qiov_offset, BdrvRequestFlags flags) { + assume_graph_lock(); /* FIXME */ handle_write(bs, offset, bytes, false); =20 return bdrv_co_pwritev_part(bs->file, offset, bytes, qiov, qiov_offset, diff --git a/block/qcow2.c b/block/qcow2.c index e06ea7b5ff..89c3edbd61 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2450,7 +2450,8 @@ static bool merge_cow(uint64_t offset, unsigned bytes, * Return 1 if the COW regions read as zeroes, 0 if not, < 0 on error. * Note that returning 0 does not guarantee non-zero data. */ -static int coroutine_fn is_zero_cow(BlockDriverState *bs, QCowL2Meta *m) +static int coroutine_fn GRAPH_RDLOCK +is_zero_cow(BlockDriverState *bs, QCowL2Meta *m) { /* * This check is designed for optimization shortcut so it must be @@ -2468,8 +2469,8 @@ static int coroutine_fn is_zero_cow(BlockDriverState = *bs, QCowL2Meta *m) m->cow_end.nb_bytes); } =20 -static int coroutine_fn handle_alloc_space(BlockDriverState *bs, - QCowL2Meta *l2meta) +static int coroutine_fn GRAPH_RDLOCK +handle_alloc_space(BlockDriverState *bs, QCowL2Meta *l2meta) { BDRVQcow2State *s =3D bs->opaque; QCowL2Meta *m; @@ -2532,12 +2533,10 @@ static int coroutine_fn handle_alloc_space(BlockDri= verState *bs, * l2meta - if not NULL, qcow2_co_pwritev_task() will consume it. Caller = must * not use it somehow after qcow2_co_pwritev_task() call */ -static coroutine_fn int qcow2_co_pwritev_task(BlockDriverState *bs, - uint64_t host_offset, - uint64_t offset, uint64_t by= tes, - QEMUIOVector *qiov, - uint64_t qiov_offset, - QCowL2Meta *l2meta) +static coroutine_fn GRAPH_RDLOCK +int qcow2_co_pwritev_task(BlockDriverState *bs, uint64_t host_offset, + uint64_t offset, uint64_t bytes, QEMUIOVector *q= iov, + uint64_t qiov_offset, QCowL2Meta *l2meta) { int ret; BDRVQcow2State *s =3D bs->opaque; @@ -2603,7 +2602,11 @@ out_locked: return ret; } =20 -static coroutine_fn int qcow2_co_pwritev_task_entry(AioTask *task) +/* + * This function can count as GRAPH_RDLOCK because qcow2_co_pwritev_part()= holds + * the graph lock and keeps it until this coroutine has terminated. + */ +static coroutine_fn GRAPH_RDLOCK int qcow2_co_pwritev_task_entry(AioTask *= task) { Qcow2AioTask *t =3D container_of(task, Qcow2AioTask, task); =20 @@ -2626,6 +2629,8 @@ static coroutine_fn int qcow2_co_pwritev_part( QCowL2Meta *l2meta =3D NULL; AioTaskPool *aio =3D NULL; =20 + assume_graph_lock(); /* FIXME */ + trace_qcow2_writev_start_req(qemu_coroutine_self(), offset, bytes); =20 while (bytes !=3D 0 && aio_task_pool_status(aio) =3D=3D 0) { @@ -3974,8 +3979,9 @@ static bool is_zero(BlockDriverState *bs, int64_t off= set, int64_t bytes) return res >=3D 0 && (res & BDRV_BLOCK_ZERO) && bytes =3D=3D 0; } =20 -static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, + BdrvRequestFlags flags) { int ret; BDRVQcow2State *s =3D bs->opaque; diff --git a/block/qed.c b/block/qed.c index cf794a1add..bdcb6de6df 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1420,15 +1420,12 @@ static int coroutine_fn bdrv_qed_co_writev(BlockDri= verState *bs, return qed_co_request(bs, sector_num, qiov, nb_sectors, QED_AIOCB_WRIT= E); } =20 -static int coroutine_fn bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t by= tes, + BdrvRequestFlags flags) { BDRVQEDState *s =3D bs->opaque; =20 - assume_graph_lock(); /* FIXME */ - /* * Zero writes start without an I/O buffer. If a buffer becomes neces= sary * then it will be allocated during request processing. diff --git a/block/quorum.c b/block/quorum.c index 3fe3791ab2..02ae0d8343 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -683,7 +683,11 @@ static int coroutine_fn quorum_co_preadv(BlockDriverSt= ate *bs, return ret; } =20 -static void coroutine_fn write_quorum_entry(void *opaque) +/* + * This function can count as GRAPH_RDLOCK because quorum_co_pwritev() hol= ds the + * graph lock and keeps it until this coroutine has terminated. + */ +static void coroutine_fn GRAPH_RDLOCK write_quorum_entry(void *opaque) { QuorumCo *co =3D opaque; QuorumAIOCB *acb =3D co->acb; @@ -722,6 +726,8 @@ static int coroutine_fn quorum_co_pwritev(BlockDriverSt= ate *bs, int64_t offset, QuorumAIOCB *acb =3D quorum_aio_get(bs, qiov, offset, bytes, flags); int i, ret; =20 + assume_graph_lock(); /* FIXME */ + for (i =3D 0; i < s->num_children; i++) { Coroutine *co; QuorumCo data =3D { @@ -745,10 +751,9 @@ static int coroutine_fn quorum_co_pwritev(BlockDriverS= tate *bs, int64_t offset, return ret; } =20 -static int coroutine_fn quorum_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t by= tes, - BdrvRequestFlags flags) - +static int coroutine_fn GRAPH_RDLOCK +quorum_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t byte= s, + BdrvRequestFlags flags) { return quorum_co_pwritev(bs, offset, bytes, NULL, flags | BDRV_REQ_ZERO_WRITE); diff --git a/block/raw-format.c b/block/raw-format.c index 7f1036ebed..007d7f6e42 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -292,9 +292,9 @@ static int coroutine_fn raw_co_block_status(BlockDriver= State *bs, return BDRV_BLOCK_RAW | BDRV_BLOCK_OFFSET_VALID; } =20 -static int coroutine_fn raw_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, + BdrvRequestFlags flags) { int ret; =20 diff --git a/block/throttle.c b/block/throttle.c index b07d853c0a..3db4fa3c40 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -134,9 +134,9 @@ static int coroutine_fn throttle_co_pwritev(BlockDriver= State *bs, return bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags); } =20 -static int coroutine_fn throttle_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t = bytes, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t by= tes, + BdrvRequestFlags flags) { ThrottleGroupMember *tgm =3D bs->opaque; throttle_group_co_io_limits_intercept(tgm, bytes, true); --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178600; cv=none; d=zohomail.com; s=zohoarc; b=IRlifGuLs4ctjyHDU96bCQZjtaPxabSmu+DqgU5JAjgghI3wwgelX1FMGy3k70mAjhwHHuJ7lJcgGp7Pg9FLxM3lC/rwq5Xa6na8gjiOLIETJ0ObkbZF/eU+ByzhJ6qG7LM1D3GRp8NAxX/Xy9l5PcIvgAN6/ahuyYJHdL8Dy6w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178600; 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=R5Q/VvFwkATjpQ4YPFTOVd38AhVyK7rV+eBNuMfX2SM=; b=QwfiLD2VrONfiIJ22CGla4Lu+AQ1M/YXd1S3Z8RFQw3qwQsVbu+XuP93mY3EgVgcreHdoYuxibEhkJprZkd8gI+6SR5O+j+E7X6naFcpCNK/XXv4ptRRSkOjOJC0mPUN5d5b72fzDLyDM0wlqGTLk4m5DeSiMBhWcdQtBI6GnXQ= 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 1677178600660368.3352738507414; Thu, 23 Feb 2023 10:56:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhW-0006vL-KR; Thu, 23 Feb 2023 13:52:18 -0500 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 1pVGhM-0006pA-Ib for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:08 -0500 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 1pVGhJ-00038B-4J for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:08 -0500 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-524-Pd6vDK5YOYGvDDX2tVA6hg-1; Thu, 23 Feb 2023 13:52:01 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E12F4857A88; Thu, 23 Feb 2023 18:52:00 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3207D1121315; Thu, 23 Feb 2023 18:52:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178324; 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=R5Q/VvFwkATjpQ4YPFTOVd38AhVyK7rV+eBNuMfX2SM=; b=bdG1s25xZvvoIS8SeWZzOGnr2fc2QVMYYfmLJpo861iQV3ddjgPpVlFE6ZEIsMffw/0VqQ JveXx+3FnI/R4xCANKfSIwiC7twMUsCSJJY5Pn+uEo8BTnwRMeKfWOqKaIk+U6aQ3gL1NK ovrc1dlVDKqA/BTlG7aTQRUb3srSSfw= X-MC-Unique: Pd6vDK5YOYGvDDX2tVA6hg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 10/29] block: Mark read/write in block/io.c GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:27 +0100 Message-Id: <20230223185146.306454-11-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178601919100001 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_driver_*() need to hold a reader lock for the graph. It doesn't add the annotation to public functions yet. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-11-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- block/qcow2.h | 5 ++- include/block/block_int-common.h | 40 ++++++++++--------- block/io.c | 66 +++++++++++++++----------------- block/parallels.c | 8 ++-- block/qcow.c | 20 ++++------ block/qcow2-cluster.c | 10 ++--- block/qcow2.c | 37 ++++++++++-------- block/qed.c | 14 +++---- block/quorum.c | 8 ++-- block/vmdk.c | 4 +- 10 files changed, 101 insertions(+), 111 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 82cd1664cf..46dca53e45 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -921,8 +921,9 @@ int coroutine_fn qcow2_alloc_compressed_cluster_offset(= BlockDriverState *bs, void qcow2_parse_compressed_l2_entry(BlockDriverState *bs, uint64_t l2_ent= ry, uint64_t *coffset, int *csize); =20 -int coroutine_fn qcow2_alloc_cluster_link_l2(BlockDriverState *bs, - QCowL2Meta *m); +int coroutine_fn GRAPH_RDLOCK +qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m); + void qcow2_alloc_cluster_abort(BlockDriverState *bs, QCowL2Meta *m); int qcow2_cluster_discard(BlockDriverState *bs, uint64_t offset, uint64_t bytes, enum qcow2_discard_type type, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 21b4cb1101..192841f040 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -471,12 +471,14 @@ struct BlockDriver { Error **errp); =20 /* aio */ - BlockAIOCB *(*bdrv_aio_preadv)(BlockDriverState *bs, + BlockAIOCB * GRAPH_RDLOCK_PTR (*bdrv_aio_preadv)(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque); - BlockAIOCB *(*bdrv_aio_pwritev)(BlockDriverState *bs, + + BlockAIOCB * GRAPH_RDLOCK_PTR (*bdrv_aio_pwritev)(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags, BlockCompletionFunc *cb, void *opaque); + BlockAIOCB * GRAPH_RDLOCK_PTR (*bdrv_aio_flush)( BlockDriverState *bs, BlockCompletionFunc *cb, void *opaque); =20 @@ -484,7 +486,7 @@ struct BlockDriver { BlockDriverState *bs, int64_t offset, int bytes, BlockCompletionFunc *cb, void *opaque); =20 - int coroutine_fn (*bdrv_co_readv)(BlockDriverState *bs, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_readv)(BlockDriverState *b= s, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov); =20 /** @@ -502,16 +504,16 @@ struct BlockDriver { * * The buffer in @qiov may point directly to guest memory. */ - int coroutine_fn (*bdrv_co_preadv)(BlockDriverState *bs, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_preadv)(BlockDriverState *= bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); =20 - int coroutine_fn (*bdrv_co_preadv_part)(BlockDriverState *bs, - int64_t offset, int64_t bytes, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_preadv_part)( + BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags); =20 - int coroutine_fn (*bdrv_co_writev)(BlockDriverState *bs, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_writev)(BlockDriverState *= bs, int64_t sector_num, int nb_sectors, QEMUIOVector *qiov, int flags); /** @@ -529,12 +531,12 @@ struct BlockDriver { * * The buffer in @qiov may point directly to guest memory. */ - int coroutine_fn (*bdrv_co_pwritev)(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags); - int coroutine_fn (*bdrv_co_pwritev_part)(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_off= set, + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwritev)( + BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector = *qiov, BdrvRequestFlags flags); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwritev_part)( + BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector = *qiov, + size_t qiov_offset, BdrvRequestFlags flags); =20 /* * Efficiently zero a region of the disk image. Typically an image fo= rmat @@ -695,11 +697,13 @@ struct BlockDriver { BlockMeasureInfo *(*bdrv_measure)(QemuOpts *opts, BlockDriverState *in= _bs, Error **errp); =20 - int coroutine_fn (*bdrv_co_pwritev_compressed)(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov); - int coroutine_fn (*bdrv_co_pwritev_compressed_part)(BlockDriverState *= bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, - size_t qiov_offset); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwritev_compressed)( + BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pwritev_compressed_part)( + BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset); =20 int coroutine_fn (*bdrv_co_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi); @@ -764,7 +768,7 @@ struct BlockDriver { BlockDriverState *bs, const char *name, Error **errp); }; =20 -static inline bool block_driver_can_compress(BlockDriver *drv) +static inline bool TSA_NO_TSA block_driver_can_compress(BlockDriver *drv) { return drv->bdrv_co_pwritev_compressed || drv->bdrv_co_pwritev_compressed_part; diff --git a/block/io.c b/block/io.c index 00843362e9..2dda1cf5c2 100644 --- a/block/io.c +++ b/block/io.c @@ -160,6 +160,7 @@ void bdrv_refresh_limits(BlockDriverState *bs, Transact= ion *tran, Error **errp) bool have_limits; =20 GLOBAL_STATE_CODE(); + assume_graph_lock(); /* FIXME */ =20 if (tran) { BdrvRefreshLimitsState *s =3D g_new(BdrvRefreshLimitsState, 1); @@ -961,10 +962,9 @@ static void bdrv_co_io_em_complete(void *opaque, int r= et) aio_co_wake(co->coroutine); } =20 -static int coroutine_fn bdrv_driver_preadv(BlockDriverState *bs, - int64_t offset, int64_t bytes, - QEMUIOVector *qiov, - size_t qiov_offset, int flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_driver_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset, int flags) { BlockDriver *drv =3D bs->drv; int64_t sector_num; @@ -1030,11 +1030,10 @@ out: return ret; } =20 -static int coroutine_fn bdrv_driver_pwritev(BlockDriverState *bs, - int64_t offset, int64_t bytes, - QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_driver_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { BlockDriver *drv =3D bs->drv; bool emulate_fua =3D false; @@ -1043,8 +1042,6 @@ static int coroutine_fn bdrv_driver_pwritev(BlockDriv= erState *bs, QEMUIOVector local_qiov; int ret; =20 - assume_graph_lock(); /* FIXME */ - bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 if (!drv) { @@ -1114,7 +1111,7 @@ emulate_flags: return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK bdrv_driver_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset) @@ -1149,9 +1146,9 @@ bdrv_driver_pwritev_compressed(BlockDriverState *bs, = int64_t offset, return ret; } =20 -static int coroutine_fn bdrv_co_do_copy_on_readv(BdrvChild *child, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, - size_t qiov_offset, int flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_co_do_copy_on_readv(BdrvChild *child, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset, int flags) { BlockDriverState *bs =3D child->bs; =20 @@ -1172,8 +1169,6 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(Bdrv= Child *child, int64_t progress =3D 0; bool skip_write; =20 - assume_graph_lock(); /* FIXME */ - bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 if (!drv) { @@ -1315,9 +1310,10 @@ err: * handles copy on read, zeroing after EOF, and fragmentation of large * reads; any other features must be implemented by the caller. */ -static int coroutine_fn bdrv_aligned_preadv(BdrvChild *child, - BdrvTrackedRequest *req, int64_t offset, int64_t bytes, - int64_t align, QEMUIOVector *qiov, size_t qiov_offset, int flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_aligned_preadv(BdrvChild *child, BdrvTrackedRequest *req, + int64_t offset, int64_t bytes, int64_t align, + QEMUIOVector *qiov, size_t qiov_offset, int flags) { BlockDriverState *bs =3D child->bs; int64_t total_bytes, max_bytes; @@ -1484,10 +1480,9 @@ static bool bdrv_init_padding(BlockDriverState *bs, return true; } =20 -static coroutine_fn int bdrv_padding_rmw_read(BdrvChild *child, - BdrvTrackedRequest *req, - BdrvRequestPadding *pad, - bool zero_middle) +static int coroutine_fn GRAPH_RDLOCK +bdrv_padding_rmw_read(BdrvChild *child, BdrvTrackedRequest *req, + BdrvRequestPadding *pad, bool zero_middle) { QEMUIOVector local_qiov; BlockDriverState *bs =3D child->bs; @@ -1626,6 +1621,8 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, int ret; IO_CODE(); =20 + assume_graph_lock(); /* FIXME */ + trace_bdrv_co_preadv_part(bs, offset, bytes, flags); =20 if (!bdrv_co_is_inserted(bs)) { @@ -1898,10 +1895,11 @@ bdrv_co_write_req_finish(BdrvChild *child, int64_t = offset, int64_t bytes, * Forwards an already correctly aligned write request to the BlockDriver, * after possibly fragmenting it. */ -static int coroutine_fn bdrv_aligned_pwritev(BdrvChild *child, - BdrvTrackedRequest *req, int64_t offset, int64_t bytes, - int64_t align, QEMUIOVector *qiov, size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_aligned_pwritev(BdrvChild *child, BdrvTrackedRequest *req, + int64_t offset, int64_t bytes, int64_t align, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { BlockDriverState *bs =3D child->bs; BlockDriver *drv =3D bs->drv; @@ -1910,8 +1908,6 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChil= d *child, int64_t bytes_remaining =3D bytes; int max_transfer; =20 - assume_graph_lock(); /* FIXME */ - bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 if (!drv) { @@ -1987,11 +1983,9 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChi= ld *child, return ret; } =20 -static int coroutine_fn bdrv_co_do_zero_pwritev(BdrvChild *child, - int64_t offset, - int64_t bytes, - BdrvRequestFlags flags, - BdrvTrackedRequest *req) +static int coroutine_fn GRAPH_RDLOCK +bdrv_co_do_zero_pwritev(BdrvChild *child, int64_t offset, int64_t bytes, + BdrvRequestFlags flags, BdrvTrackedRequest *req) { BlockDriverState *bs =3D child->bs; QEMUIOVector local_qiov; @@ -2079,6 +2073,8 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *chil= d, bool padded =3D false; IO_CODE(); =20 + assume_graph_lock(); /* FIXME */ + trace_bdrv_co_pwritev_part(child->bs, offset, bytes, flags); =20 if (!bdrv_co_is_inserted(bs)) { diff --git a/block/parallels.c b/block/parallels.c index 36c9de8a8a..2cf5061524 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -320,17 +320,15 @@ static int coroutine_fn parallels_co_block_status(Blo= ckDriverState *bs, return BDRV_BLOCK_DATA | BDRV_BLOCK_OFFSET_VALID; } =20 -static coroutine_fn int parallels_co_writev(BlockDriverState *bs, - int64_t sector_num, int nb_sec= tors, - QEMUIOVector *qiov, int flags) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_secto= rs, + QEMUIOVector *qiov, int flags) { BDRVParallelsState *s =3D bs->opaque; uint64_t bytes_done =3D 0; QEMUIOVector hd_qiov; int ret =3D 0; =20 - assume_graph_lock(); /* FIXME */ - qemu_iovec_init(&hd_qiov, qiov->niov); =20 while (nb_sectors > 0) { diff --git a/block/qcow.c b/block/qcow.c index 2d19a78818..1e1d1792d0 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -617,9 +617,9 @@ static void qcow_refresh_limits(BlockDriverState *bs, E= rror **errp) bs->bl.request_alignment =3D BDRV_SECTOR_SIZE; } =20 -static coroutine_fn int qcow_co_preadv(BlockDriverState *bs, int64_t offse= t, - int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +qcow_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { BDRVQcowState *s =3D bs->opaque; int offset_in_cluster; @@ -628,8 +628,6 @@ static coroutine_fn int qcow_co_preadv(BlockDriverState= *bs, int64_t offset, uint8_t *buf; void *orig_buf; =20 - assume_graph_lock(); /* FIXME */ - if (qiov->niov > 1) { buf =3D orig_buf =3D qemu_try_blockalign(bs, qiov->size); if (buf =3D=3D NULL) { @@ -715,9 +713,9 @@ static coroutine_fn int qcow_co_preadv(BlockDriverState= *bs, int64_t offset, return ret; } =20 -static coroutine_fn int qcow_co_pwritev(BlockDriverState *bs, int64_t offs= et, - int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +qcow_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { BDRVQcowState *s =3D bs->opaque; int offset_in_cluster; @@ -726,8 +724,6 @@ static coroutine_fn int qcow_co_pwritev(BlockDriverStat= e *bs, int64_t offset, uint8_t *buf; void *orig_buf; =20 - assume_graph_lock(); /* FIXME */ - s->cluster_cache_offset =3D -1; /* disable compressed cache */ =20 /* We must always copy the iov when encrypting, so we @@ -1048,7 +1044,7 @@ static int qcow_make_empty(BlockDriverState *bs) =20 /* XXX: put compressed sectors first, then all the cluster aligned tables to avoid losing bytes in alignment */ -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK qcow_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t b= ytes, QEMUIOVector *qiov) { @@ -1058,8 +1054,6 @@ qcow_co_pwritev_compressed(BlockDriverState *bs, int6= 4_t offset, int64_t bytes, uint8_t *buf, *out_buf; uint64_t cluster_offset; =20 - assume_graph_lock(); /* FIXME */ - buf =3D qemu_blockalign(bs, s->cluster_size); if (bytes !=3D s->cluster_size) { if (bytes > s->cluster_size || diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 870be106b6..a22607d90d 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -491,10 +491,9 @@ static int count_contiguous_subclusters(BlockDriverSta= te *bs, int nb_clusters, return count; } =20 -static int coroutine_fn do_perform_cow_read(BlockDriverState *bs, - uint64_t src_cluster_offset, - unsigned offset_in_cluster, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +do_perform_cow_read(BlockDriverState *bs, uint64_t src_cluster_offset, + unsigned offset_in_cluster, QEMUIOVector *qiov) { int ret; =20 @@ -886,7 +885,8 @@ int coroutine_fn qcow2_alloc_compressed_cluster_offset(= BlockDriverState *bs, return 0; } =20 -static int coroutine_fn perform_cow(BlockDriverState *bs, QCowL2Meta *m) +static int coroutine_fn GRAPH_RDLOCK +perform_cow(BlockDriverState *bs, QCowL2Meta *m) { BDRVQcow2State *s =3D bs->opaque; Qcow2COWRegion *start =3D &m->cow_start; diff --git a/block/qcow2.c b/block/qcow2.c index 89c3edbd61..8f5ad75984 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -2137,9 +2137,8 @@ static int coroutine_fn qcow2_co_block_status(BlockDr= iverState *bs, return status; } =20 -static coroutine_fn int qcow2_handle_l2meta(BlockDriverState *bs, - QCowL2Meta **pl2meta, - bool link_l2) +static int coroutine_fn GRAPH_RDLOCK +qcow2_handle_l2meta(BlockDriverState *bs, QCowL2Meta **pl2meta, bool link_= l2) { int ret =3D 0; QCowL2Meta *l2meta =3D *pl2meta; @@ -2617,9 +2616,10 @@ static coroutine_fn GRAPH_RDLOCK int qcow2_co_pwrite= v_task_entry(AioTask *task) t->l2meta); } =20 -static coroutine_fn int qcow2_co_pwritev_part( - BlockDriverState *bs, int64_t offset, int64_t bytes, - QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_pwritev_part(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { BDRVQcow2State *s =3D bs->opaque; int offset_in_cluster; @@ -2629,8 +2629,6 @@ static coroutine_fn int qcow2_co_pwritev_part( QCowL2Meta *l2meta =3D NULL; AioTaskPool *aio =3D NULL; =20 - assume_graph_lock(); /* FIXME */ - trace_qcow2_writev_start_req(qemu_coroutine_self(), offset, bytes); =20 while (bytes !=3D 0 && aio_task_pool_status(aio) =3D=3D 0) { @@ -4160,6 +4158,7 @@ qcow2_co_copy_range_to(BlockDriverState *bs, uint64_t host_offset; QCowL2Meta *l2meta =3D NULL; =20 + assume_graph_lock(); /* FIXME */ assert(!bs->encrypted); =20 qemu_co_mutex_lock(&s->lock); @@ -4591,7 +4590,7 @@ fail: return ret; } =20 -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK qcow2_co_pwritev_compressed_task(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, size_t qiov_offset) @@ -4655,7 +4654,13 @@ fail: return ret; } =20 -static coroutine_fn int qcow2_co_pwritev_compressed_task_entry(AioTask *ta= sk) +/* + * This function can count as GRAPH_RDLOCK because + * qcow2_co_pwritev_compressed_part() holds the graph lock and keeps it un= til + * this coroutine has terminated. + */ +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_pwritev_compressed_task_entry(AioTask *task) { Qcow2AioTask *t =3D container_of(task, Qcow2AioTask, task); =20 @@ -4669,7 +4674,7 @@ static coroutine_fn int qcow2_co_pwritev_compressed_t= ask_entry(AioTask *task) * XXX: put compressed sectors first, then all the cluster aligned * tables to avoid losing bytes in alignment */ -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK qcow2_co_pwritev_compressed_part(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset) @@ -4678,8 +4683,6 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs, AioTaskPool *aio =3D NULL; int ret =3D 0; =20 - assume_graph_lock(); /* FIXME */ - if (has_data_file(bs)) { return -ENOTSUP; } @@ -5296,8 +5299,8 @@ static int64_t qcow2_check_vmstate_request(BlockDrive= rState *bs, return pos; } =20 -static coroutine_fn int qcow2_co_save_vmstate(BlockDriverState *bs, - QEMUIOVector *qiov, int64_t = pos) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t po= s) { int64_t offset =3D qcow2_check_vmstate_request(bs, qiov, pos); if (offset < 0) { @@ -5308,8 +5311,8 @@ static coroutine_fn int qcow2_co_save_vmstate(BlockDr= iverState *bs, return bs->drv->bdrv_co_pwritev_part(bs, offset, qiov->size, qiov, 0, = 0); } =20 -static coroutine_fn int qcow2_co_load_vmstate(BlockDriverState *bs, - QEMUIOVector *qiov, int64_t = pos) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_load_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t po= s) { int64_t offset =3D qcow2_check_vmstate_request(bs, qiov, pos); if (offset < 0) { diff --git a/block/qed.c b/block/qed.c index bdcb6de6df..a4a74e59ef 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1404,19 +1404,17 @@ qed_co_request(BlockDriverState *bs, int64_t sector= _num, QEMUIOVector *qiov, return qed_aio_next_io(&acb); } =20 -static int coroutine_fn bdrv_qed_co_readv(BlockDriverState *bs, - int64_t sector_num, int nb_secto= rs, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, + QEMUIOVector *qiov) { - assume_graph_lock(); /* FIXME */ return qed_co_request(bs, sector_num, qiov, nb_sectors, 0); } =20 -static int coroutine_fn bdrv_qed_co_writev(BlockDriverState *bs, - int64_t sector_num, int nb_sect= ors, - QEMUIOVector *qiov, int flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sector= s, + QEMUIOVector *qiov, int flags) { - assume_graph_lock(); /* FIXME */ return qed_co_request(bs, sector_num, qiov, nb_sectors, QED_AIOCB_WRIT= E); } =20 diff --git a/block/quorum.c b/block/quorum.c index 02ae0d8343..ef6cda2868 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -718,16 +718,14 @@ static void coroutine_fn GRAPH_RDLOCK write_quorum_en= try(void *opaque) } } =20 -static int coroutine_fn quorum_co_pwritev(BlockDriverState *bs, int64_t of= fset, - int64_t bytes, QEMUIOVector *qio= v, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +quorum_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { BDRVQuorumState *s =3D bs->opaque; QuorumAIOCB *acb =3D quorum_aio_get(bs, qiov, offset, bytes, flags); int i, ret; =20 - assume_graph_lock(); /* FIXME */ - for (i =3D 0; i < s->num_children; i++) { Coroutine *co; QuorumCo data =3D { diff --git a/block/vmdk.c b/block/vmdk.c index d074f696aa..8b844300f4 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2128,12 +2128,10 @@ vmdk_co_pwritev(BlockDriverState *bs, int64_t offse= t, int64_t bytes, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vmdk_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t b= ytes, QEMUIOVector *qiov) { - assume_graph_lock(); /* FIXME */ - if (bytes =3D=3D 0) { /* The caller will write bytes 0 to signal EOF. * When receive it, we align EOF to a sector boundary. */ --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178640; cv=none; d=zohomail.com; s=zohoarc; b=EJqDXcjfc3ajImwlbEt06tF5FrI30KuCf99UjJeDmr7YlL4Zr0q6cs6IBh8bqWkkf0IvP4mBpdThcvpSKZd7+cHZooyRAAoEToCfWdX+7QD1HAOuq+2hkpuxBQagUBVLcLYQZ9fiTfG3XZP2i3s35zcR+TqqZ4iufWSX6/fKh+s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178640; 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=bP0xLKpnZjLL+XyMCalBjnNVhHD8Pd4vdl313PAlFCo=; b=cnnXB/QBQh80BHgGhlX7F9gIDK+jFWFx8ZiIpK6qbtxGF74c06SE5dAi249Yxld5lkJHJ+2U7l0TdRYktWa7FiHM+sAp9GAH2iVG/PDlk8+/Fo5a3kgu6ZNnjSmVhROUzYzzr9TQD9IngLk/P36EmfdLf7auUW7IlKV7uK5wOZA= 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 1677178640284618.0812777759301; Thu, 23 Feb 2023 10:57:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhR-0006ro-Ti; Thu, 23 Feb 2023 13:52:13 -0500 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 1pVGhO-0006q1-4w for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:10 -0500 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 1pVGhK-00038b-Cg for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:09 -0500 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-547-lqfbSksPMayJzy10QinKSQ-1; Thu, 23 Feb 2023 13:52:02 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E70E32800486; Thu, 23 Feb 2023 18:52:01 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 225691121314; Thu, 23 Feb 2023 18:52:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178325; 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=bP0xLKpnZjLL+XyMCalBjnNVhHD8Pd4vdl313PAlFCo=; b=CM2omWASkbsM/gqZyu87eu5j41KWF4/GsYod5h58QfxbRnjp1hAAV/9Qvwo+9uueE/Zo+F WTco2H6Wek+7yvPNvS7qHalW8OwcSnSgqIAyHzvxtvFutTaIWo8C/2ePKTO1ohcNUNbtxI +1m/HfYNfH1G3so4MAvyUSAOBkM14zw= X-MC-Unique: lqfbSksPMayJzy10QinKSQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 11/29] block: Mark public read/write functions GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:28 +0100 Message-Id: <20230223185146.306454-12-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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, T_FILL_THIS_FORM_SHORT=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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178642232100009 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_pread*/pwrite*() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-12-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- block/qcow2.h | 9 ++--- block/qed.h | 18 +++++----- include/block/block_int-io.h | 14 ++++---- block/blkdebug.c | 4 +-- block/blklogwrites.c | 7 ++-- block/blkreplay.c | 10 +++--- block/block-backend.c | 2 ++ block/bochs.c | 2 +- block/commit.c | 5 +-- block/copy-before-write.c | 16 ++++----- block/copy-on-read.c | 26 ++++++--------- block/crypto.c | 4 +-- block/filter-compress.c | 19 +++++------ block/io.c | 7 ++-- block/mirror.c | 18 +++++----- block/parallels.c | 8 +++-- block/preallocate.c | 18 +++++----- block/qcow.c | 8 ++--- block/qcow2-cluster.c | 7 ++-- block/qcow2.c | 53 +++++++++++++++-------------- block/qed-table.c | 4 +-- block/qed.c | 31 +++++++++-------- block/quorum.c | 29 ++++++++++------ block/raw-format.c | 12 +++---- block/replication.c | 15 ++++----- block/throttle.c | 21 +++++------- block/vdi.c | 4 +-- block/vhdx.c | 11 +++--- block/vmdk.c | 65 +++++++++++++++--------------------- block/vpc.c | 4 +-- tests/unit/test-bdrv-drain.c | 20 ++++++----- 31 files changed, 233 insertions(+), 238 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 46dca53e45..7487bcfcf9 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -846,7 +846,7 @@ int qcow2_validate_table(BlockDriverState *bs, uint64_t= offset, Error **errp); =20 /* qcow2-refcount.c functions */ -int coroutine_fn qcow2_refcount_init(BlockDriverState *bs); +int coroutine_fn GRAPH_RDLOCK qcow2_refcount_init(BlockDriverState *bs); void qcow2_refcount_close(BlockDriverState *bs); =20 int qcow2_get_refcount(BlockDriverState *bs, int64_t cluster_index, @@ -954,9 +954,10 @@ void qcow2_free_snapshots(BlockDriverState *bs); int qcow2_read_snapshots(BlockDriverState *bs, Error **errp); int qcow2_write_snapshots(BlockDriverState *bs); =20 -int coroutine_fn qcow2_check_read_snapshot_table(BlockDriverState *bs, - BdrvCheckResult *result, - BdrvCheckMode fix); +int coroutine_fn GRAPH_RDLOCK +qcow2_check_read_snapshot_table(BlockDriverState *bs, BdrvCheckResult *res= ult, + BdrvCheckMode fix); + int coroutine_fn qcow2_check_fix_snapshot_table(BlockDriverState *bs, BdrvCheckResult *result, BdrvCheckMode fix); diff --git a/block/qed.h b/block/qed.h index e48f7c2480..988654cb86 100644 --- a/block/qed.h +++ b/block/qed.h @@ -200,7 +200,7 @@ void qed_commit_l2_cache_entry(L2TableCache *l2_cache, = CachedL2Table *l2_table); /** * Table I/O functions */ -int coroutine_fn qed_read_l1_table_sync(BDRVQEDState *s); +int coroutine_fn GRAPH_RDLOCK qed_read_l1_table_sync(BDRVQEDState *s); =20 int coroutine_fn GRAPH_RDLOCK qed_write_l1_table(BDRVQEDState *s, unsigned int index, unsigned int n); @@ -208,10 +208,11 @@ qed_write_l1_table(BDRVQEDState *s, unsigned int inde= x, unsigned int n); int coroutine_fn GRAPH_RDLOCK qed_write_l1_table_sync(BDRVQEDState *s, unsigned int index, unsigned int = n); =20 -int coroutine_fn qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *reque= st, - uint64_t offset); -int coroutine_fn qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, - uint64_t offset); +int coroutine_fn GRAPH_RDLOCK +qed_read_l2_table_sync(BDRVQEDState *s, QEDRequest *request, uint64_t offs= et); + +int coroutine_fn GRAPH_RDLOCK +qed_read_l2_table(BDRVQEDState *s, QEDRequest *request, uint64_t offset); =20 int coroutine_fn GRAPH_RDLOCK qed_write_l2_table(BDRVQEDState *s, QEDRequest *request, unsigned int inde= x, @@ -224,9 +225,9 @@ qed_write_l2_table_sync(BDRVQEDState *s, QEDRequest *re= quest, /** * Cluster functions */ -int coroutine_fn qed_find_cluster(BDRVQEDState *s, QEDRequest *request, - uint64_t pos, size_t *len, - uint64_t *img_offset); +int coroutine_fn GRAPH_RDLOCK +qed_find_cluster(BDRVQEDState *s, QEDRequest *request, uint64_t pos, + size_t *len, uint64_t *img_offset); =20 /** * Consistency check @@ -234,7 +235,6 @@ int coroutine_fn qed_find_cluster(BDRVQEDState *s, QEDR= equest *request, int coroutine_fn GRAPH_RDLOCK qed_check(BDRVQEDState *s, BdrvCheckResult *result, bool fix); =20 - QEDTable *qed_alloc_table(BDRVQEDState *s); =20 /** diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 4bb6ccaa34..34d4b0fb8e 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -44,33 +44,35 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard_snapshot= (BlockDriverState *bs, int64_t offset, int64_t bytes); =20 =20 -int coroutine_fn bdrv_co_preadv(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_preadv(BdrvChild *child, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); -int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_preadv_part(BdrvChild *child, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags); -int coroutine_fn bdrv_co_pwritev(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_pwritev(BdrvChild *child, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); -int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_pwritev_part(BdrvChild *child, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags); =20 -static inline int coroutine_fn bdrv_co_pread(BdrvChild *child, +static inline int coroutine_fn GRAPH_RDLOCK bdrv_co_pread(BdrvChild *child, int64_t offset, int64_t bytes, void *buf, BdrvRequestFlags flags) { QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); IO_CODE(); + assert_bdrv_graph_readable(); =20 return bdrv_co_preadv(child, offset, bytes, &qiov, flags); } =20 -static inline int coroutine_fn bdrv_co_pwrite(BdrvChild *child, +static inline int coroutine_fn GRAPH_RDLOCK bdrv_co_pwrite(BdrvChild *chil= d, int64_t offset, int64_t bytes, const void *buf, BdrvRequestFlags flags) { QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); IO_CODE(); + assert_bdrv_graph_readable(); =20 return bdrv_co_pwritev(child, offset, bytes, &qiov, flags); } diff --git a/block/blkdebug.c b/block/blkdebug.c index eed03bfe7e..f418a90873 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -626,7 +626,7 @@ static int rule_check(BlockDriverState *bs, uint64_t of= fset, uint64_t bytes, return -error; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blkdebug_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -647,7 +647,7 @@ blkdebug_co_preadv(BlockDriverState *bs, int64_t offset= , int64_t bytes, return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blkdebug_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { diff --git a/block/blklogwrites.c b/block/blklogwrites.c index bdaa2a57a2..93086c31e1 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -294,7 +294,7 @@ static void blk_log_writes_refresh_limits(BlockDriverSt= ate *bs, Error **errp) bs->bl.request_alignment =3D s->sectorsize; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_preadv(BlockDriverState *bs, int64_t offset, int64_t byt= es, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -430,7 +430,7 @@ blk_log_writes_co_log(BlockDriverState *bs, uint64_t of= fset, uint64_t bytes, return fr.file_ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_do_file_pwritev(BlkLogWritesFileReq *fr) { return bdrv_co_pwritev(fr->bs->file, fr->offset, fr->bytes, @@ -456,11 +456,10 @@ blk_log_writes_co_do_file_pdiscard(BlkLogWritesFileRe= q *fr) return bdrv_co_pdiscard(fr->bs->file, fr->offset, fr->bytes); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK blk_log_writes_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t by= tes, QEMUIOVector *qiov, BdrvRequestFlags flags) { - assume_graph_lock(); /* FIXME */ return blk_log_writes_co_log(bs, offset, bytes, qiov, flags, blk_log_writes_co_do_file_pwritev, 0, fal= se); } diff --git a/block/blkreplay.c b/block/blkreplay.c index 2703a0c8c6..bc96bbd41e 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -69,8 +69,9 @@ static void block_request_create(uint64_t reqid, BlockDri= verState *bs, replay_block_event(req->bh, reqid); } =20 -static int coroutine_fn blkreplay_co_preadv(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags fl= ags) +static int coroutine_fn GRAPH_RDLOCK +blkreplay_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { uint64_t reqid =3D blkreplay_next_id(); int ret =3D bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); @@ -80,8 +81,9 @@ static int coroutine_fn blkreplay_co_preadv(BlockDriverSt= ate *bs, return ret; } =20 -static int coroutine_fn blkreplay_co_pwritev(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags fl= ags) +static int coroutine_fn GRAPH_RDLOCK +blkreplay_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { uint64_t reqid =3D blkreplay_next_id(); int ret =3D bdrv_co_pwritev(bs->file, offset, bytes, qiov, flags); diff --git a/block/block-backend.c b/block/block-backend.c index b4d2387947..146ef91547 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1289,6 +1289,7 @@ blk_co_do_preadv_part(BlockBackend *blk, int64_t offs= et, int64_t bytes, IO_CODE(); =20 blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); =20 /* Call blk_bs() only after waiting, the graph may have changed */ bs =3D blk_bs(blk); @@ -1363,6 +1364,7 @@ blk_co_do_pwritev_part(BlockBackend *blk, int64_t off= set, int64_t bytes, IO_CODE(); =20 blk_wait_while_drained(blk); + GRAPH_RDLOCK_GUARD(); =20 /* Call blk_bs() only after waiting, the graph may have changed */ bs =3D blk_bs(blk); diff --git a/block/bochs.c b/block/bochs.c index 46e7958316..2f5ae52c90 100644 --- a/block/bochs.c +++ b/block/bochs.c @@ -237,7 +237,7 @@ static int64_t seek_to_sector(BlockDriverState *bs, int= 64_t sector_num) return bitmap_offset + (512 * (s->bitmap_blocks + extent_offset)); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK bochs_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { diff --git a/block/commit.c b/block/commit.c index 41e3599281..10f6512e07 100644 --- a/block/commit.c +++ b/block/commit.c @@ -207,8 +207,9 @@ static const BlockJobDriver commit_job_driver =3D { }, }; =20 -static int coroutine_fn bdrv_commit_top_preadv(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags fl= ags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_commit_top_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags); } diff --git a/block/copy-before-write.c b/block/copy-before-write.c index 61854beae2..e223e37300 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -78,9 +78,9 @@ typedef struct BDRVCopyBeforeWriteState { int snapshot_error; } BDRVCopyBeforeWriteState; =20 -static coroutine_fn int cbw_co_preadv( - BlockDriverState *bs, int64_t offset, int64_t bytes, - QEMUIOVector *qiov, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cbw_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); } @@ -172,11 +172,9 @@ cbw_co_pwrite_zeroes(BlockDriverState *bs, int64_t off= set, int64_t bytes, return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } =20 -static coroutine_fn int cbw_co_pwritev(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - QEMUIOVector *qiov, - BdrvRequestFlags flags) +static coroutine_fn GRAPH_RDLOCK +int cbw_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { int ret =3D cbw_do_copy_before_write(bs, offset, bytes, flags); if (ret < 0) { @@ -266,6 +264,8 @@ cbw_co_preadv_snapshot(BlockDriverState *bs, int64_t of= fset, int64_t bytes, BdrvChild *file; int ret; =20 + assume_graph_lock(); /* FIXME */ + /* TODO: upgrade to async loop using AioTask */ while (bytes) { int64_t cur_bytes; diff --git a/block/copy-on-read.c b/block/copy-on-read.c index ebf6864dd3..78da353f88 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -127,11 +127,10 @@ static int64_t coroutine_fn cor_co_getlength(BlockDri= verState *bs) } =20 =20 -static int coroutine_fn cor_co_preadv_part(BlockDriverState *bs, - int64_t offset, int64_t bytes, - QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cor_co_preadv_part(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { int64_t n; int local_flags; @@ -180,12 +179,10 @@ static int coroutine_fn cor_co_preadv_part(BlockDrive= rState *bs, } =20 =20 -static int coroutine_fn cor_co_pwritev_part(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +cor_co_pwritev_part(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { return bdrv_co_pwritev_part(bs->file, offset, bytes, qiov, qiov_offset, flags); @@ -207,10 +204,9 @@ cor_co_pdiscard(BlockDriverState *bs, int64_t offset, = int64_t bytes) } =20 =20 -static int coroutine_fn cor_co_pwritev_compressed(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +cor_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, int64_t by= tes, + QEMUIOVector *qiov) { return bdrv_co_pwritev(bs->file, offset, bytes, qiov, BDRV_REQ_WRITE_COMPRESSED); diff --git a/block/crypto.c b/block/crypto.c index a15f77521f..0ebb846534 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -397,7 +397,7 @@ static int block_crypto_reopen_prepare(BDRVReopenState = *state, */ #define BLOCK_CRYPTO_MAX_IO_SIZE (1024 * 1024) =20 -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK block_crypto_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -459,7 +459,7 @@ block_crypto_co_preadv(BlockDriverState *bs, int64_t of= fset, int64_t bytes, } =20 =20 -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK block_crypto_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t byte= s, QEMUIOVector *qiov, BdrvRequestFlags flags) { diff --git a/block/filter-compress.c b/block/filter-compress.c index 7a632f47fe..0dd5606410 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -61,23 +61,20 @@ static int64_t coroutine_fn compress_co_getlength(Block= DriverState *bs) } =20 =20 -static int coroutine_fn compress_co_preadv_part(BlockDriverState *bs, - int64_t offset, int64_t by= tes, - QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +compress_co_preadv_part(BlockDriverState *bs, int64_t offset, int64_t byte= s, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { return bdrv_co_preadv_part(bs->file, offset, bytes, qiov, qiov_offset, flags); } =20 =20 -static int coroutine_fn compress_co_pwritev_part(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +compress_co_pwritev_part(BlockDriverState *bs, int64_t offset, int64_t byt= es, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { return bdrv_co_pwritev_part(bs->file, offset, bytes, qiov, qiov_offset, flags | BDRV_REQ_WRITE_COMPRESSED); diff --git a/block/io.c b/block/io.c index 2dda1cf5c2..ec8b317818 100644 --- a/block/io.c +++ b/block/io.c @@ -971,6 +971,7 @@ bdrv_driver_preadv(BlockDriverState *bs, int64_t offset= , int64_t bytes, unsigned int nb_sectors; QEMUIOVector local_qiov; int ret; + assert_bdrv_graph_readable(); =20 bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); assert(!(flags & ~bs->supported_read_flags)); @@ -1041,6 +1042,7 @@ bdrv_driver_pwritev(BlockDriverState *bs, int64_t off= set, int64_t bytes, unsigned int nb_sectors; QEMUIOVector local_qiov; int ret; + assert_bdrv_graph_readable(); =20 bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 @@ -1119,6 +1121,7 @@ bdrv_driver_pwritev_compressed(BlockDriverState *bs, = int64_t offset, BlockDriver *drv =3D bs->drv; QEMUIOVector local_qiov; int ret; + assert_bdrv_graph_readable(); =20 bdrv_check_qiov_request(offset, bytes, qiov, qiov_offset, &error_abort= ); =20 @@ -1621,8 +1624,6 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, int ret; IO_CODE(); =20 - assume_graph_lock(); /* FIXME */ - trace_bdrv_co_preadv_part(bs, offset, bytes, flags); =20 if (!bdrv_co_is_inserted(bs)) { @@ -2073,8 +2074,6 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *chil= d, bool padded =3D false; IO_CODE(); =20 - assume_graph_lock(); /* FIXME */ - trace_bdrv_co_pwritev_part(child->bs, offset, bytes, flags); =20 if (!bdrv_co_is_inserted(bs)) { diff --git a/block/mirror.c b/block/mirror.c index a6f4ec6282..ec5cd22a7c 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -390,8 +390,10 @@ static void coroutine_fn mirror_co_read(void *opaque) op->is_in_flight =3D true; trace_mirror_one_iteration(s, op->offset, op->bytes); =20 - ret =3D bdrv_co_preadv(s->mirror_top_bs->backing, op->offset, op->byte= s, - &op->qiov, 0); + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D bdrv_co_preadv(s->mirror_top_bs->backing, op->offset, op->= bytes, + &op->qiov, 0); + } mirror_read_complete(op, ret); } =20 @@ -1437,8 +1439,9 @@ static void coroutine_fn active_write_settle(MirrorOp= *op) g_free(op); } =20 -static int coroutine_fn bdrv_mirror_top_preadv(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags fl= ags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { return bdrv_co_preadv(bs->backing, offset, bytes, qiov, flags); } @@ -1495,8 +1498,9 @@ out: return ret; } =20 -static int coroutine_fn bdrv_mirror_top_pwritev(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags fl= ags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_mirror_top_pwritev(BlockDriverState *bs, int64_t offset, int64_t byte= s, + QEMUIOVector *qiov, BdrvRequestFlags flags) { MirrorBDSOpaque *s =3D bs->opaque; QEMUIOVector bounce_qiov; @@ -1504,8 +1508,6 @@ static int coroutine_fn bdrv_mirror_top_pwritev(Block= DriverState *bs, int ret =3D 0; bool copy_to_target =3D false; =20 - assume_graph_lock(); /* FIXME */ - if (s->job) { copy_to_target =3D s->job->ret >=3D 0 && !job_is_cancelled(&s->job->common.job) && diff --git a/block/parallels.c b/block/parallels.c index 2cf5061524..a7e9cad146 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -261,7 +261,8 @@ allocate_clusters(BlockDriverState *bs, int64_t sector_= num, } =20 =20 -static coroutine_fn int parallels_co_flush_to_os(BlockDriverState *bs) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_flush_to_os(BlockDriverState *bs) { BDRVParallelsState *s =3D bs->opaque; unsigned long size =3D DIV_ROUND_UP(s->header_size, s->bat_dirty_block= ); @@ -363,8 +364,9 @@ parallels_co_writev(BlockDriverState *bs, int64_t secto= r_num, int nb_sectors, return ret; } =20 -static coroutine_fn int parallels_co_readv(BlockDriverState *bs, - int64_t sector_num, int nb_sectors, QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sector= s, + QEMUIOVector *qiov) { BDRVParallelsState *s =3D bs->opaque; uint64_t bytes_done =3D 0; diff --git a/block/preallocate.c b/block/preallocate.c index 91d73c81c6..63a296882d 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -226,9 +226,10 @@ static void preallocate_reopen_abort(BDRVReopenState *= state) state->opaque =3D NULL; } =20 -static coroutine_fn int preallocate_co_preadv_part( - BlockDriverState *bs, int64_t offset, int64_t bytes, - QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co_preadv_part(BlockDriverState *bs, int64_t offset, int64_t b= ytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { return bdrv_co_preadv_part(bs->file, offset, bytes, qiov, qiov_offset, flags); @@ -359,14 +360,11 @@ preallocate_co_pwrite_zeroes(BlockDriverState *bs, in= t64_t offset, return bdrv_co_pwrite_zeroes(bs->file, offset, bytes, flags); } =20 -static coroutine_fn int preallocate_co_pwritev_part(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +preallocate_co_pwritev_part(BlockDriverState *bs, int64_t offset, int64_t = bytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { - assume_graph_lock(); /* FIXME */ handle_write(bs, offset, bytes, false); =20 return bdrv_co_pwritev_part(bs->file, offset, bytes, qiov, qiov_offset, diff --git a/block/qcow.c b/block/qcow.c index 1e1d1792d0..58a0b4e2f0 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -92,8 +92,8 @@ typedef struct BDRVQcowState { =20 static QemuOptsList qcow_create_opts; =20 -static int coroutine_fn decompress_cluster(BlockDriverState *bs, - uint64_t cluster_offset); +static int coroutine_fn GRAPH_RDLOCK +decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset); =20 static int qcow_probe(const uint8_t *buf, int buf_size, const char *filena= me) { @@ -584,8 +584,8 @@ static int decompress_buffer(uint8_t *out_buf, int out_= buf_size, return 0; } =20 -static int coroutine_fn decompress_cluster(BlockDriverState *bs, - uint64_t cluster_offset) +static int coroutine_fn GRAPH_RDLOCK +decompress_cluster(BlockDriverState *bs, uint64_t cluster_offset) { BDRVQcowState *s =3D bs->opaque; int ret, csize; diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index a22607d90d..a9e6622fe3 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -534,10 +534,9 @@ do_perform_cow_read(BlockDriverState *bs, uint64_t src= _cluster_offset, return 0; } =20 -static int coroutine_fn do_perform_cow_write(BlockDriverState *bs, - uint64_t cluster_offset, - unsigned offset_in_cluster, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +do_perform_cow_write(BlockDriverState *bs, uint64_t cluster_offset, + unsigned offset_in_cluster, QEMUIOVector *qiov) { BDRVQcow2State *s =3D bs->opaque; int ret; diff --git a/block/qcow2.c b/block/qcow2.c index 8f5ad75984..ddf9394bf0 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -601,9 +601,9 @@ static void qcow2_add_check_result(BdrvCheckResult *out, } } =20 -static int coroutine_fn qcow2_co_check_locked(BlockDriverState *bs, - BdrvCheckResult *result, - BdrvCheckMode fix) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_check_locked(BlockDriverState *bs, BdrvCheckResult *result, + BdrvCheckMode fix) { BdrvCheckResult snapshot_res =3D {}; BdrvCheckResult refcount_res =3D {}; @@ -640,9 +640,9 @@ static int coroutine_fn qcow2_co_check_locked(BlockDriv= erState *bs, return ret; } =20 -static int coroutine_fn qcow2_co_check(BlockDriverState *bs, - BdrvCheckResult *result, - BdrvCheckMode fix) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_check(BlockDriverState *bs, BdrvCheckResult *result, + BdrvCheckMode fix) { BDRVQcow2State *s =3D bs->opaque; int ret; @@ -1294,9 +1294,9 @@ static int validate_compression_type(BDRVQcow2State *= s, Error **errp) } =20 /* Called with s->lock held. */ -static int coroutine_fn qcow2_do_open(BlockDriverState *bs, QDict *options, - int flags, bool open_data_file, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +qcow2_do_open(BlockDriverState *bs, QDict *options, int flags, + bool open_data_file, Error **errp) { ERRP_GUARD(); BDRVQcow2State *s =3D bs->opaque; @@ -1890,6 +1890,8 @@ static void coroutine_fn qcow2_open_entry(void *opaqu= e) QCow2OpenCo *qoc =3D opaque; BDRVQcow2State *s =3D qoc->bs->opaque; =20 + assume_graph_lock(); /* FIXME */ + qemu_co_mutex_lock(&s->lock); qoc->ret =3D qcow2_do_open(qoc->bs, qoc->options, qoc->flags, true, qoc->errp); @@ -2169,7 +2171,7 @@ out: return ret; } =20 -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK qcow2_co_preadv_encrypted(BlockDriverState *bs, uint64_t host_offset, uint64_t offset, @@ -2270,12 +2272,10 @@ static coroutine_fn int qcow2_add_task(BlockDriverS= tate *bs, return 0; } =20 -static coroutine_fn int qcow2_co_preadv_task(BlockDriverState *bs, - QCow2SubclusterType subc_type, - uint64_t host_offset, - uint64_t offset, uint64_t byt= es, - QEMUIOVector *qiov, - size_t qiov_offset) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_preadv_task(BlockDriverState *bs, QCow2SubclusterType subc_type, + uint64_t host_offset, uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset) { BDRVQcow2State *s =3D bs->opaque; =20 @@ -2314,7 +2314,11 @@ static coroutine_fn int qcow2_co_preadv_task(BlockDr= iverState *bs, g_assert_not_reached(); } =20 -static coroutine_fn int qcow2_co_preadv_task_entry(AioTask *task) +/* + * This function can count as GRAPH_RDLOCK because qcow2_co_preadv_part() = holds + * the graph lock and keeps it until this coroutine has terminated. + */ +static int coroutine_fn GRAPH_RDLOCK qcow2_co_preadv_task_entry(AioTask *t= ask) { Qcow2AioTask *t =3D container_of(task, Qcow2AioTask, task); =20 @@ -2325,11 +2329,10 @@ static coroutine_fn int qcow2_co_preadv_task_entry(= AioTask *task) t->qiov, t->qiov_offset); } =20 -static coroutine_fn int qcow2_co_preadv_part(BlockDriverState *bs, - int64_t offset, int64_t bytes, - QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_preadv_part(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) { BDRVQcow2State *s =3D bs->opaque; int ret =3D 0; @@ -2774,8 +2777,8 @@ static void qcow2_close(BlockDriverState *bs) qcow2_do_close(bs, true); } =20 -static void coroutine_fn qcow2_co_invalidate_cache(BlockDriverState *bs, - Error **errp) +static void coroutine_fn GRAPH_RDLOCK +qcow2_co_invalidate_cache(BlockDriverState *bs, Error **errp) { ERRP_GUARD(); BDRVQcow2State *s =3D bs->opaque; @@ -4737,7 +4740,7 @@ qcow2_co_pwritev_compressed_part(BlockDriverState *bs, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK qcow2_co_preadv_compressed(BlockDriverState *bs, uint64_t l2_entry, uint64_t offset, diff --git a/block/qed-table.c b/block/qed-table.c index e9c72814c8..3b331ce709 100644 --- a/block/qed-table.c +++ b/block/qed-table.c @@ -21,8 +21,8 @@ #include "qemu/memalign.h" =20 /* Called with table_lock held. */ -static int coroutine_fn qed_read_table(BDRVQEDState *s, uint64_t offset, - QEDTable *table) +static int coroutine_fn GRAPH_RDLOCK +qed_read_table(BDRVQEDState *s, uint64_t offset, QEDTable *table) { unsigned int bytes =3D s->header.cluster_size * s->header.table_size; =20 diff --git a/block/qed.c b/block/qed.c index a4a74e59ef..c969b31e2c 100644 --- a/block/qed.c +++ b/block/qed.c @@ -100,7 +100,7 @@ int qed_write_header_sync(BDRVQEDState *s) * * No new allocating reqs can start while this function runs. */ -static int coroutine_fn qed_write_header(BDRVQEDState *s) +static int coroutine_fn GRAPH_RDLOCK qed_write_header(BDRVQEDState *s) { /* We must write full sectors for O_DIRECT but cannot necessarily gene= rate * the data following the header if an unrecognized compat feature is @@ -826,11 +826,10 @@ fail: return ret; } =20 -static int coroutine_fn bdrv_qed_co_block_status(BlockDriverState *bs, - bool want_zero, - int64_t pos, int64_t byte= s, - int64_t *pnum, int64_t *m= ap, - BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_block_status(BlockDriverState *bs, bool want_zero, int64_t pos, + int64_t bytes, int64_t *pnum, int64_t *map, + BlockDriverState **file) { BDRVQEDState *s =3D bs->opaque; size_t len =3D MIN(bytes, SIZE_MAX); @@ -883,8 +882,8 @@ static BDRVQEDState *acb_to_s(QEDAIOCB *acb) * This function reads qiov->size bytes starting at pos from the backing f= ile. * If there is no backing file then zeroes are read. */ -static int coroutine_fn qed_read_backing_file(BDRVQEDState *s, uint64_t po= s, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +qed_read_backing_file(BDRVQEDState *s, uint64_t pos, QEMUIOVector *qiov) { if (s->bs->backing) { BLKDBG_EVENT(s->bs->file, BLKDBG_READ_BACKING_AIO); @@ -902,9 +901,9 @@ static int coroutine_fn qed_read_backing_file(BDRVQEDSt= ate *s, uint64_t pos, * @len: Number of bytes * @offset: Byte offset in image file */ -static int coroutine_fn qed_copy_from_backing_file(BDRVQEDState *s, - uint64_t pos, uint64_t = len, - uint64_t offset) +static int coroutine_fn GRAPH_RDLOCK +qed_copy_from_backing_file(BDRVQEDState *s, uint64_t pos, uint64_t len, + uint64_t offset) { QEMUIOVector qiov; int ret; @@ -1066,7 +1065,7 @@ qed_aio_write_l2_update(QEDAIOCB *acb, uint64_t offse= t) * * Called with table_lock *not* held. */ -static int coroutine_fn qed_aio_write_main(QEDAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK qed_aio_write_main(QEDAIOCB *acb) { BDRVQEDState *s =3D acb_to_s(acb); uint64_t offset =3D acb->cur_cluster + @@ -1226,8 +1225,8 @@ qed_aio_write_alloc(QEDAIOCB *acb, size_t len) * * Called with table_lock held. */ -static int coroutine_fn qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offs= et, - size_t len) +static int coroutine_fn GRAPH_RDLOCK +qed_aio_write_inplace(QEDAIOCB *acb, uint64_t offset, size_t len) { BDRVQEDState *s =3D acb_to_s(acb); int r; @@ -1302,8 +1301,8 @@ qed_aio_write_data(void *opaque, int ret, uint64_t of= fset, size_t len) * * Called with table_lock held. */ -static int coroutine_fn qed_aio_read_data(void *opaque, int ret, - uint64_t offset, size_t len) +static int coroutine_fn GRAPH_RDLOCK +qed_aio_read_data(void *opaque, int ret, uint64_t offset, size_t len) { QEDAIOCB *acb =3D opaque; BDRVQEDState *s =3D acb_to_s(acb); diff --git a/block/quorum.c b/block/quorum.c index ef6cda2868..d58f86d3a5 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -270,7 +270,11 @@ static void quorum_report_bad_versions(BDRVQuorumState= *s, } } =20 -static void coroutine_fn quorum_rewrite_entry(void *opaque) +/* + * This function can count as GRAPH_RDLOCK because read_quorum_children() = holds + * the graph lock and keeps it until this coroutine has terminated. + */ +static void coroutine_fn GRAPH_RDLOCK quorum_rewrite_entry(void *opaque) { QuorumCo *co =3D opaque; QuorumAIOCB *acb =3D co->acb; @@ -290,8 +294,8 @@ static void coroutine_fn quorum_rewrite_entry(void *opa= que) } } =20 -static bool quorum_rewrite_bad_versions(QuorumAIOCB *acb, - QuorumVoteValue *value) +static bool coroutine_fn GRAPH_RDLOCK +quorum_rewrite_bad_versions(QuorumAIOCB *acb, QuorumVoteValue *value) { QuorumVoteVersion *version; QuorumVoteItem *item; @@ -491,7 +495,7 @@ static int quorum_vote_error(QuorumAIOCB *acb) return ret; } =20 -static void quorum_vote(QuorumAIOCB *acb) +static void coroutine_fn GRAPH_RDLOCK quorum_vote(QuorumAIOCB *acb) { bool quorum =3D true; int i, j, ret; @@ -571,7 +575,11 @@ free_exit: quorum_free_vote_list(&acb->votes); } =20 -static void coroutine_fn read_quorum_children_entry(void *opaque) +/* + * This function can count as GRAPH_RDLOCK because read_quorum_children() = holds + * the graph lock and keeps it until this coroutine has terminated. + */ +static void coroutine_fn GRAPH_RDLOCK read_quorum_children_entry(void *opa= que) { QuorumCo *co =3D opaque; QuorumAIOCB *acb =3D co->acb; @@ -599,7 +607,7 @@ static void coroutine_fn read_quorum_children_entry(voi= d *opaque) } } =20 -static int coroutine_fn read_quorum_children(QuorumAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK read_quorum_children(QuorumAIOCB *acb) { BDRVQuorumState *s =3D acb->bs->opaque; int i; @@ -640,7 +648,7 @@ static int coroutine_fn read_quorum_children(QuorumAIOC= B *acb) return acb->vote_ret; } =20 -static int coroutine_fn read_fifo_child(QuorumAIOCB *acb) +static int coroutine_fn GRAPH_RDLOCK read_fifo_child(QuorumAIOCB *acb) { BDRVQuorumState *s =3D acb->bs->opaque; int n, ret; @@ -661,10 +669,9 @@ static int coroutine_fn read_fifo_child(QuorumAIOCB *a= cb) return ret; } =20 -static int coroutine_fn quorum_co_preadv(BlockDriverState *bs, - int64_t offset, int64_t bytes, - QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +quorum_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { BDRVQuorumState *s =3D bs->opaque; QuorumAIOCB *acb =3D quorum_aio_get(bs, qiov, offset, bytes, flags); diff --git a/block/raw-format.c b/block/raw-format.c index 007d7f6e42..92adf97ab0 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -203,9 +203,9 @@ static inline int raw_adjust_offset(BlockDriverState *b= s, int64_t *offset, return 0; } =20 -static int coroutine_fn raw_co_preadv(BlockDriverState *bs, int64_t offset, - int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { int ret; =20 @@ -218,9 +218,9 @@ static int coroutine_fn raw_co_preadv(BlockDriverState = *bs, int64_t offset, return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); } =20 -static int coroutine_fn raw_co_pwritev(BlockDriverState *bs, int64_t offse= t, - int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { void *buf =3D NULL; BlockDriver *drv; diff --git a/block/replication.c b/block/replication.c index a27417d310..f9f899bfc8 100644 --- a/block/replication.c +++ b/block/replication.c @@ -220,10 +220,9 @@ static int replication_return_value(BDRVReplicationSta= te *s, int ret) return ret; } =20 -static coroutine_fn int replication_co_readv(BlockDriverState *bs, - int64_t sector_num, - int remaining_sectors, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +replication_co_readv(BlockDriverState *bs, int64_t sector_num, + int remaining_sectors, QEMUIOVector *qiov) { BDRVReplicationState *s =3D bs->opaque; int ret; @@ -244,11 +243,9 @@ static coroutine_fn int replication_co_readv(BlockDriv= erState *bs, return replication_return_value(s, ret); } =20 -static coroutine_fn int replication_co_writev(BlockDriverState *bs, - int64_t sector_num, - int remaining_sectors, - QEMUIOVector *qiov, - int flags) +static int coroutine_fn GRAPH_RDLOCK +replication_co_writev(BlockDriverState *bs, int64_t sector_num, + int remaining_sectors, QEMUIOVector *qiov, int flags) { BDRVReplicationState *s =3D bs->opaque; QEMUIOVector hd_qiov; diff --git a/block/throttle.c b/block/throttle.c index 3db4fa3c40..5cfea3d5f8 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -111,10 +111,9 @@ static int64_t coroutine_fn throttle_co_getlength(Bloc= kDriverState *bs) return bdrv_co_getlength(bs->file->bs); } =20 -static int coroutine_fn throttle_co_preadv(BlockDriverState *bs, - int64_t offset, int64_t bytes, - QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { =20 ThrottleGroupMember *tgm =3D bs->opaque; @@ -123,10 +122,9 @@ static int coroutine_fn throttle_co_preadv(BlockDriver= State *bs, return bdrv_co_preadv(bs->file, offset, bytes, qiov, flags); } =20 -static int coroutine_fn throttle_co_pwritev(BlockDriverState *bs, - int64_t offset, int64_t bytes, - QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { ThrottleGroupMember *tgm =3D bs->opaque; throttle_group_co_io_limits_intercept(tgm, bytes, true); @@ -153,10 +151,9 @@ throttle_co_pdiscard(BlockDriverState *bs, int64_t off= set, int64_t bytes) return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 -static int coroutine_fn throttle_co_pwritev_compressed(BlockDriverState *b= s, - int64_t offset, - int64_t bytes, - QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +throttle_co_pwritev_compressed(BlockDriverState *bs, int64_t offset, + int64_t bytes, QEMUIOVector *qiov) { return throttle_co_pwritev(bs, offset, bytes, qiov, BDRV_REQ_WRITE_COMPRESSED); diff --git a/block/vdi.c b/block/vdi.c index 27db67d493..b50c0b7277 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -544,7 +544,7 @@ static int coroutine_fn vdi_co_block_status(BlockDriver= State *bs, (s->header.image_type =3D=3D VDI_TYPE_STATIC ? BDRV_BLOCK_RECURSE = : 0); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vdi_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -600,7 +600,7 @@ vdi_co_preadv(BlockDriverState *bs, int64_t offset, int= 64_t bytes, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vdi_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { diff --git a/block/vhdx.c b/block/vhdx.c index 59fbdb413b..ffa4455e82 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1172,8 +1172,9 @@ vhdx_co_get_info(BlockDriverState *bs, BlockDriverInf= o *bdi) } =20 =20 -static coroutine_fn int vhdx_co_readv(BlockDriverState *bs, int64_t sector= _num, - int nb_sectors, QEMUIOVector *qiov) +static int coroutine_fn GRAPH_RDLOCK +vhdx_co_readv(BlockDriverState *bs, int64_t sector_num, int nb_sectors, + QEMUIOVector *qiov) { BDRVVHDXState *s =3D bs->opaque; int ret =3D 0; @@ -1324,9 +1325,9 @@ int vhdx_user_visible_write(BlockDriverState *bs, BDR= VVHDXState *s) return ret; } =20 -static coroutine_fn int vhdx_co_writev(BlockDriverState *bs, int64_t secto= r_num, - int nb_sectors, QEMUIOVector *qiov, - int flags) +static int coroutine_fn GRAPH_RDLOCK +vhdx_co_writev(BlockDriverState *bs, int64_t sector_num, int nb_sectors, + QEMUIOVector *qiov, int flags) { int ret =3D -ENOTSUP; BDRVVHDXState *s =3D bs->opaque; diff --git a/block/vmdk.c b/block/vmdk.c index 8b844300f4..c601ca85f4 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1403,13 +1403,11 @@ static void vmdk_refresh_limits(BlockDriverState *b= s, Error **errp) * [@skip_start_sector, @skip_end_sector) is not copied or written, and le= ave * it for call to write user data in the request. */ -static int coroutine_fn get_whole_cluster(BlockDriverState *bs, - VmdkExtent *extent, - uint64_t cluster_offset, - uint64_t offset, - uint64_t skip_start_bytes, - uint64_t skip_end_bytes, - bool zeroed) +static int coroutine_fn GRAPH_RDLOCK +get_whole_cluster(BlockDriverState *bs, VmdkExtent *extent, + uint64_t cluster_offset, uint64_t offset, + uint64_t skip_start_bytes, uint64_t skip_end_bytes, + bool zeroed) { int ret =3D VMDK_OK; int64_t cluster_bytes; @@ -1536,14 +1534,11 @@ vmdk_L2update(VmdkExtent *extent, VmdkMetaData *m_d= ata, uint32_t offset) * VMDK_UNALLOC if cluster is not mapped and @allocate is false. * VMDK_ERROR if failed. */ -static int coroutine_fn get_cluster_offset(BlockDriverState *bs, - VmdkExtent *extent, - VmdkMetaData *m_data, - uint64_t offset, - bool allocate, - uint64_t *cluster_offset, - uint64_t skip_start_bytes, - uint64_t skip_end_bytes) +static int coroutine_fn GRAPH_RDLOCK +get_cluster_offset(BlockDriverState *bs, VmdkExtent *extent, + VmdkMetaData *m_data, uint64_t offset, bool allocate, + uint64_t *cluster_offset, uint64_t skip_start_bytes, + uint64_t skip_end_bytes) { unsigned int l1_index, l2_offset, l2_index; int min_index, i, j; @@ -1736,11 +1731,10 @@ static inline uint64_t vmdk_find_offset_in_cluster(= VmdkExtent *extent, return extent_relative_offset % cluster_size; } =20 -static int coroutine_fn vmdk_co_block_status(BlockDriverState *bs, - bool want_zero, - int64_t offset, int64_t bytes, - int64_t *pnum, int64_t *map, - BlockDriverState **file) +static int coroutine_fn GRAPH_RDLOCK +vmdk_co_block_status(BlockDriverState *bs, bool want_zero, + int64_t offset, int64_t bytes, int64_t *pnum, + int64_t *map, BlockDriverState **file) { BDRVVmdkState *s =3D bs->opaque; int64_t index_in_cluster, n, ret; @@ -1785,7 +1779,7 @@ static int coroutine_fn vmdk_co_block_status(BlockDri= verState *bs, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vmdk_write_extent(VmdkExtent *extent, int64_t cluster_offset, int64_t offset_in_cluster, QEMUIOVector *qiov, uint64_t qiov_offset, uint64_t n_bytes, @@ -1867,10 +1861,9 @@ vmdk_write_extent(VmdkExtent *extent, int64_t cluste= r_offset, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vmdk_read_extent(VmdkExtent *extent, int64_t cluster_offset, - int64_t offset_in_cluster, QEMUIOVector *qiov, - int bytes) + int64_t offset_in_cluster, QEMUIOVector *qiov, int bytes) { int ret; int cluster_bytes, buf_bytes; @@ -1934,7 +1927,7 @@ vmdk_read_extent(VmdkExtent *extent, int64_t cluster_= offset, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vmdk_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -2016,9 +2009,9 @@ fail: * * Returns: error code with 0 for success. */ -static int coroutine_fn vmdk_pwritev(BlockDriverState *bs, uint64_t offset, - uint64_t bytes, QEMUIOVector *qiov, - bool zeroed, bool zero_dry_run) +static int coroutine_fn GRAPH_RDLOCK +vmdk_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, + QEMUIOVector *qiov, bool zeroed, bool zero_dry_run) { BDRVVmdkState *s =3D bs->opaque; VmdkExtent *extent =3D NULL; @@ -2028,8 +2021,6 @@ static int coroutine_fn vmdk_pwritev(BlockDriverState= *bs, uint64_t offset, uint64_t bytes_done =3D 0; VmdkMetaData m_data; =20 - assume_graph_lock(); /* FIXME */ - if (DIV_ROUND_UP(offset, BDRV_SECTOR_SIZE) > bs->total_sectors) { error_report("Wrong offset: offset=3D0x%" PRIx64 " total_sectors=3D0x%" PRIx64, @@ -2116,7 +2107,7 @@ static int coroutine_fn vmdk_pwritev(BlockDriverState= *bs, uint64_t offset, return 0; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vmdk_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -2156,10 +2147,9 @@ vmdk_co_pwritev_compressed(BlockDriverState *bs, int= 64_t offset, int64_t bytes, return vmdk_co_pwritev(bs, offset, bytes, qiov, 0); } =20 -static int coroutine_fn vmdk_co_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +vmdk_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t bytes, + BdrvRequestFlags flags) { int ret; BDRVVmdkState *s =3D bs->opaque; @@ -2920,9 +2910,8 @@ static VmdkExtentInfo *vmdk_get_extent_info(VmdkExten= t *extent) return info; } =20 -static int coroutine_fn vmdk_co_check(BlockDriverState *bs, - BdrvCheckResult *result, - BdrvCheckMode fix) +static int coroutine_fn GRAPH_RDLOCK +vmdk_co_check(BlockDriverState *bs, BdrvCheckResult *result, BdrvCheckMode= fix) { BDRVVmdkState *s =3D bs->opaque; VmdkExtent *extent =3D NULL; diff --git a/block/vpc.c b/block/vpc.c index 3c256fc5a4..1f0f26c0c4 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -610,7 +610,7 @@ vpc_co_get_info(BlockDriverState *bs, BlockDriverInfo *= bdi) return 0; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vpc_co_preadv(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { @@ -660,7 +660,7 @@ fail: return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK vpc_co_pwritev(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags) { diff --git a/tests/unit/test-bdrv-drain.c b/tests/unit/test-bdrv-drain.c index 4fed8b751f..d9d3807062 100644 --- a/tests/unit/test-bdrv-drain.c +++ b/tests/unit/test-bdrv-drain.c @@ -933,10 +933,9 @@ static void bdrv_test_top_close(BlockDriverState *bs) } } =20 -static int coroutine_fn bdrv_test_top_co_preadv(BlockDriverState *bs, - int64_t offset, int64_t by= tes, - QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_test_top_co_preadv(BlockDriverState *bs, int64_t offset, int64_t byte= s, + QEMUIOVector *qiov, BdrvRequestFlags flags) { BDRVTestTopState *tts =3D bs->opaque; return bdrv_co_preadv(tts->wait_child, offset, bytes, qiov, flags); @@ -967,6 +966,8 @@ static void coroutine_fn test_co_delete_by_drain(void *= opaque) void *buffer =3D g_malloc(65536); QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buffer, 65536); =20 + GRAPH_RDLOCK_GUARD(); + /* Pretend some internal write operation from parent to child. * Important: We have to read from the child, not from the parent! * Draining works by first propagating it all up the tree to the @@ -1698,11 +1699,9 @@ static void bdrv_replace_test_close(BlockDriverState= *bs) * Otherwise: * Set .has_read to true and return success. */ -static int coroutine_fn bdrv_replace_test_co_preadv(BlockDriverState *bs, - int64_t offset, - int64_t bytes, - QEMUIOVector *qiov, - BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_replace_test_co_preadv(BlockDriverState *bs, int64_t offset, int64_t = bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags) { BDRVReplaceTestState *s =3D bs->opaque; =20 @@ -1778,7 +1777,10 @@ static void coroutine_fn bdrv_replace_test_read_entr= y(void *opaque) int ret; =20 /* Queue a read request post-drain */ + bdrv_graph_co_rdlock(); ret =3D bdrv_replace_test_co_preadv(bs, 0, 1, &qiov, 0); + bdrv_graph_co_rdunlock(); + g_assert(ret >=3D 0); bdrv_dec_in_flight(bs); } --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178518; cv=none; d=zohomail.com; s=zohoarc; b=AWoYU/rQGM6PifVP3LngtGNkxuPVXLgQWrG+uNxQI/2b2NVHQgiKbRHmR5u1dKqcK5DOM1t56+2StKn1gaSWBU/2h84EnQFOKzKc8HnyVzderVUm+blH/BJgC18BhrS+GUV/ewXX0JFXzLfqUnFGVB+kfJvQEsdy0xmBzmZDcBk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178518; 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=9Mgac+mvWOZl/8gjSxUCtrPRlYH1SMNILRMsDZSgyFY=; b=ZhI8aN6b0kDBR7inlSN9xPYuS902pchEJmebYcB2Wa/6AXKo0iBmcM5bI2bf0dfkwJNOpshzC2T3es8y975c0q8UFbU2EBa72p5+bNwMFLaUOunnH/dGZ3iKJrGhiytqwtJo3XsT8GEoLN2RQP64EBmBLVJFZnuPBKaMQpgNFo8= 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 1677178518922412.44077607138934; Thu, 23 Feb 2023 10:55:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhS-0006s9-5K; Thu, 23 Feb 2023 13:52:14 -0500 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 1pVGhN-0006pb-D3 for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:09 -0500 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 1pVGhL-00038z-0y for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:09 -0500 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-444-Q1anvWjUO_S8soF0NuE0WQ-1; Thu, 23 Feb 2023 13:52:03 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CFCE586C176; Thu, 23 Feb 2023 18:52:02 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 28E4D1121314; Thu, 23 Feb 2023 18:52:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178326; 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=9Mgac+mvWOZl/8gjSxUCtrPRlYH1SMNILRMsDZSgyFY=; b=NjaJfgxQqmLPdwNIvTTkFsvgMUQKivCXjqK4si/sFYMcbArjgCjlwmZpl2QoUvsm4Am0+6 Lu17zRGqgO91b05sDqp41WrgXPh/oZnq2xFslGD33nidHcADtkeY9B7IHmdGRiDhRqSVv1 MCFBwrNBvV4ljzCCGt03yJ2RHEa4BAg= X-MC-Unique: Q1anvWjUO_S8soF0NuE0WQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 12/29] block: Mark bdrv_co_pwrite_sync() and callers GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:29 +0100 Message-Id: <20230223185146.306454-13-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178519434100001 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_pwrite_sync() need to hold a reader lock for the graph. For some places, we know that they will hold the lock, but we don't have the GRAPH_RDLOCK annotations yet. In this case, add assume_graph_lock() with a FIXME comment. These places will be removed once everything is properly annotated. Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-13-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- block/qcow2.h | 2 +- include/block/block-io.h | 7 ++++--- block/io.c | 3 +-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/block/qcow2.h b/block/qcow2.h index 7487bcfcf9..c59e33c01c 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -893,7 +893,7 @@ int qcow2_inc_refcounts_imrt(BlockDriverState *bs, Bdrv= CheckResult *res, int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order, BlockDriverAmendStatusCB *status_cb, void *cb_opaque, Error **errp); -int coroutine_fn qcow2_shrink_reftable(BlockDriverState *bs); +int coroutine_fn GRAPH_RDLOCK qcow2_shrink_reftable(BlockDriverState *bs); int64_t qcow2_get_last_cluster(BlockDriverState *bs, int64_t size); int coroutine_fn qcow2_detect_metadata_preallocation(BlockDriverState *bs); =20 diff --git a/include/block/block-io.h b/include/block/block-io.h index ec26f07d60..bbe8a5659a 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -60,9 +60,10 @@ int co_wrapper_mixed_bdrv_rdlock bdrv_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes, const void *buf, BdrvRequestFlags flags); =20 -int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset, - int64_t bytes, const void *buf, - BdrvRequestFlags flags); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes, + const void *buf, BdrvRequestFlags flags); + /* * Efficiently zero a region of the disk image. Note that this is a regul= ar * I/O request like read or write and should have a reasonable size. This diff --git a/block/io.c b/block/io.c index ec8b317818..2593823f62 100644 --- a/block/io.c +++ b/block/io.c @@ -933,8 +933,7 @@ int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, = int64_t offset, { int ret; IO_CODE(); - - assume_graph_lock(); /* FIXME */ + assert_bdrv_graph_readable(); =20 ret =3D bdrv_co_pwrite(child, offset, bytes, buf, flags); if (ret < 0) { --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178461; cv=none; d=zohomail.com; s=zohoarc; b=bFvuDjrUp2p9iswGtve74Ql64VzDuayT8BLshAtDbklWW+xWT6z7J6/sDmOhjzQlFrqPwPQpgec1k3oxv/M9RyhAeKwAPyUHa9Lz8QE0aX3vp+K4GlDX05DT/NROMHs+n/KkUXXlW8BE6pAh+0wY883sTNFRsDY8xfqvk7Pz7vE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178461; 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=oa+DThSt3b/h3Y/YTVqy3GFKLTnRjraQAw4VOgHLIS0=; b=PYf2z9ZkxuTauai2FW2FUH8BNc1O2PfR2Nm3Cat09RVmjwEHSIFH8HiHBIJp0oMDLYlCs37v2U11M6gpgv0cnrLhgLcLuVSfzYuKNE+1qpeAs5247SC1DtQfUPl+ow5KiR1ul7tKUt0+MSC4B44QC72WgLUZCTNm6SsBr1Mh2GU= 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 1677178461648657.675721412311; Thu, 23 Feb 2023 10:54:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhS-0006s8-4L; Thu, 23 Feb 2023 13:52:14 -0500 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 1pVGhQ-0006rK-Df for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:13 -0500 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 1pVGhO-0003AQ-SM for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:12 -0500 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-156-IKyJto0VOCKxwJPYJdF_xw-1; Thu, 23 Feb 2023 13:52:04 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B7EC8280048D; Thu, 23 Feb 2023 18:52:03 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1113D1121314; Thu, 23 Feb 2023 18:52:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178330; 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=oa+DThSt3b/h3Y/YTVqy3GFKLTnRjraQAw4VOgHLIS0=; b=J2+SPV6j6QB8TsQMBkMvZ/RAXHanqU6NQOlu1TPfjOxkUDIiCuLOGxiZsVfMl7XLfYcJF7 0vFz6pj0GKfc7k6P4oiO1VK0uFS3dzAxjhI5CpL3nAjpxyuviwkKoKUQzixpY/oasNO8AW u0b06sYv6oXMsIRJV2KIlwUfsfk9bUk= X-MC-Unique: IKyJto0VOCKxwJPYJdF_xw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 13/29] block: Mark bdrv_co_do_pwrite_zeroes() GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:30 +0100 Message-Id: <20230223185146.306454-14-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178463020100005 Content-Type: text/plain; charset="utf-8" All callers are already GRAPH_RDLOCK, so just add the annotation and remove assume_graph_lock(). Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-14-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- block/io.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/block/io.c b/block/io.c index 2593823f62..628b350002 100644 --- a/block/io.c +++ b/block/io.c @@ -1672,8 +1672,9 @@ fail: return ret; } =20 -static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, - int64_t offset, int64_t bytes, BdrvRequestFlags flags) +static int coroutine_fn GRAPH_RDLOCK +bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int64_t byt= es, + BdrvRequestFlags flags) { BlockDriver *drv =3D bs->drv; QEMUIOVector qiov; @@ -1683,8 +1684,6 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(Bloc= kDriverState *bs, int head =3D 0; int tail =3D 0; =20 - assume_graph_lock(); /* FIXME */ - int64_t max_write_zeroes =3D MIN_NON_ZERO(bs->bl.max_pwrite_zeroes, INT64_MAX); int alignment =3D MAX(bs->bl.pwrite_zeroes_alignment, --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178624; cv=none; d=zohomail.com; s=zohoarc; b=gvsUYg58MgTjdZhP0YzImw2Su3Ou7EYcTYfAh/c+ODTA/UFqTL23x+U5BYDXPIt6cXFmLELonyzLsFu3Fd4ahT6RM6CgCm7bFggkD95pHE0gG8XucZfTiwlYmwiG0uXGXyxKqjuAMjr/DilD57u44rOhg5BGFpPZrIW1ycafchY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178624; 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=efuwshswUNH9W5KguHoxBNUCy3/Fc5/WAxyBkN+jEXw=; b=AfN6oUJXolSYlC9bAlqX+h7/kX0PguZ0Sb1Yk3ngTVWj4/m26G9WZrFkn1vSwtEUPlIhrpXH7B8XkPFNgROpYkaBL0C1QeoXez3pxNOCxEVDuFAuCm63FCTuYn4U4Jk3Cm4eGKd/lGn0mdefdTW7DzmEtklBDQUUlosbpRd18zw= 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 16771786247781009.147957791386; Thu, 23 Feb 2023 10:57:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhZ-0006zG-C2; Thu, 23 Feb 2023 13:52:21 -0500 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 1pVGhP-0006qh-4d for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:11 -0500 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 1pVGhN-00039e-5p for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:10 -0500 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-138-GjdHt4idMO2d8SAuqVVjiA-1; Thu, 23 Feb 2023 13:52:05 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A1C0C1816ECE; Thu, 23 Feb 2023 18:52:04 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id EEA2F1121315; Thu, 23 Feb 2023 18:52:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178328; 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=efuwshswUNH9W5KguHoxBNUCy3/Fc5/WAxyBkN+jEXw=; b=bIHpVqYkLwHhoNOE6yKmDMRgxYXJu+rylm5ke/IZ/E2MShjTJZKY3u2NeGpzDmAZWMuRO1 oCa7ryMuTV9pkbQmNikukRBXKKbc80WCgcx4STsZqj4bTgdQ2CabF7p0UPuVvqXCQ2NyCM lxiahr0aBjCQgERnje7QlQOaf/hZgcU= X-MC-Unique: GjdHt4idMO2d8SAuqVVjiA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 14/29] block: Mark bdrv_co_copy_range() GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:31 +0100 Message-Id: <20230223185146.306454-15-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178626042100009 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_copy_range() need to hold a reader lock for the graph. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-15-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- include/block/block-io.h | 9 +++++---- include/block/block_int-common.h | 24 ++++++++---------------- include/block/block_int-io.h | 20 ++++++++++---------- block/block-backend.c | 2 ++ block/file-posix.c | 16 +++++++--------- block/io.c | 7 +++++-- block/iscsi.c | 28 ++++++++++++---------------- block/qcow2.c | 5 ++--- block/raw-format.c | 28 ++++++++++++---------------- qemu-img.c | 4 +++- 10 files changed, 66 insertions(+), 77 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index bbe8a5659a..c551742a86 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -274,10 +274,11 @@ bool co_wrapper bdrv_can_store_new_dirty_bitmap(Block= DriverState *bs, * * Returns: 0 if succeeded; negative error code if failed. **/ -int coroutine_fn bdrv_co_copy_range(BdrvChild *src, int64_t src_offset, - BdrvChild *dst, int64_t dst_offset, - int64_t bytes, BdrvRequestFlags read_f= lags, - BdrvRequestFlags write_flags); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_copy_range(BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags); =20 /* * "I/O or GS" API functions. These functions can run without diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 192841f040..29b230cc0b 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -559,14 +559,10 @@ struct BlockDriver { * See the comment of bdrv_co_copy_range for the parameter and return = value * semantics. */ - int coroutine_fn (*bdrv_co_copy_range_from)(BlockDriverState *bs, - BdrvChild *src, - int64_t offset, - BdrvChild *dst, - int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_flag= s, - BdrvRequestFlags write_fla= gs); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_copy_range_from)( + BlockDriverState *bs, BdrvChild *src, int64_t offset, + BdrvChild *dst, int64_t dst_offset, int64_t bytes, + BdrvRequestFlags read_flags, BdrvRequestFlags write_flags); =20 /* * Map [offset, offset + nbytes) range onto a child of bs to copy data= to, @@ -577,14 +573,10 @@ struct BlockDriver { * See the comment of bdrv_co_copy_range for the parameter and return = value * semantics. */ - int coroutine_fn (*bdrv_co_copy_range_to)(BlockDriverState *bs, - BdrvChild *src, - int64_t src_offset, - BdrvChild *dst, - int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_flags, - BdrvRequestFlags write_flags= ); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_copy_range_to)( + BlockDriverState *bs, BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, int64_t bytes, + BdrvRequestFlags read_flags, BdrvRequestFlags write_flags); =20 /* * Building block for bdrv_block_status[_above] and diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 34d4b0fb8e..5788bd66ba 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -113,16 +113,16 @@ void bdrv_dirty_bitmap_merge_internal(BdrvDirtyBitmap= *dest, void bdrv_inc_in_flight(BlockDriverState *bs); void bdrv_dec_in_flight(BlockDriverState *bs); =20 -int coroutine_fn bdrv_co_copy_range_from(BdrvChild *src, int64_t src_offse= t, - BdrvChild *dst, int64_t dst_offse= t, - int64_t bytes, - BdrvRequestFlags read_flags, - BdrvRequestFlags write_flags); -int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offset, - BdrvChild *dst, int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_flags, - BdrvRequestFlags write_flags); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_copy_range_from(BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags); =20 int coroutine_fn bdrv_co_refresh_total_sectors(BlockDriverState *bs, int64_t hint); diff --git a/block/block-backend.c b/block/block-backend.c index 146ef91547..fdb1e1d5f7 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2644,6 +2644,8 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_= in, int64_t off_in, if (r) { return r; } + + GRAPH_RDLOCK_GUARD(); return bdrv_co_copy_range(blk_in->root, off_in, blk_out->root, off_out, bytes, read_flags, write_flags); diff --git a/block/file-posix.c b/block/file-posix.c index d106f4efa5..13da095efa 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3272,7 +3272,7 @@ static void raw_abort_perm_update(BlockDriverState *b= s) raw_handle_perm_lock(bs, RAW_PL_ABORT, 0, 0, NULL); } =20 -static int coroutine_fn raw_co_copy_range_from( +static int coroutine_fn GRAPH_RDLOCK raw_co_copy_range_from( BlockDriverState *bs, BdrvChild *src, int64_t src_offset, BdrvChild *dst, int64_t dst_offset, int64_t bytes, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags) @@ -3281,14 +3281,12 @@ static int coroutine_fn raw_co_copy_range_from( read_flags, write_flags); } =20 -static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, - BdrvChild *src, - int64_t src_offset, - BdrvChild *dst, - int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_flags, - BdrvRequestFlags write_flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_copy_range_to(BlockDriverState *bs, + BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { RawPosixAIOData acb; BDRVRawState *s =3D bs->opaque; diff --git a/block/io.c b/block/io.c index 628b350002..86e5ea362d 100644 --- a/block/io.c +++ b/block/io.c @@ -3246,6 +3246,7 @@ static int coroutine_fn GRAPH_RDLOCK bdrv_co_copy_ran= ge_internal( { BdrvTrackedRequest req; int ret; + assert_bdrv_graph_readable(); =20 /* TODO We can support BDRV_REQ_NO_FALLBACK here */ assert(!(read_flags & BDRV_REQ_NO_FALLBACK)); @@ -3327,7 +3328,7 @@ int coroutine_fn bdrv_co_copy_range_from(BdrvChild *s= rc, int64_t src_offset, BdrvRequestFlags write_flags) { IO_CODE(); - assume_graph_lock(); /* FIXME */ + assert_bdrv_graph_readable(); trace_bdrv_co_copy_range_from(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, @@ -3345,7 +3346,7 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src= , int64_t src_offset, BdrvRequestFlags write_flags) { IO_CODE(); - assume_graph_lock(); /* FIXME */ + assert_bdrv_graph_readable(); trace_bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); return bdrv_co_copy_range_internal(src, src_offset, dst, dst_offset, @@ -3358,6 +3359,8 @@ int coroutine_fn bdrv_co_copy_range(BdrvChild *src, i= nt64_t src_offset, BdrvRequestFlags write_flags) { IO_CODE(); + assert_bdrv_graph_readable(); + return bdrv_co_copy_range_from(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); diff --git a/block/iscsi.c b/block/iscsi.c index dc9a33bbff..9fc0bed90b 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2190,14 +2190,12 @@ static void coroutine_fn iscsi_co_invalidate_cache(= BlockDriverState *bs, iscsi_allocmap_invalidate(iscsilun); } =20 -static int coroutine_fn iscsi_co_copy_range_from(BlockDriverState *bs, - BdrvChild *src, - int64_t src_offset, - BdrvChild *dst, - int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_fla= gs, - BdrvRequestFlags write_fl= ags) +static int coroutine_fn GRAPH_RDLOCK +iscsi_co_copy_range_from(BlockDriverState *bs, + BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { return bdrv_co_copy_range_to(src, src_offset, dst, dst_offset, bytes, read_flags, write_flags); @@ -2331,14 +2329,12 @@ static void iscsi_xcopy_data(struct iscsi_data *dat= a, src_lba, dst_lba); } =20 -static int coroutine_fn iscsi_co_copy_range_to(BlockDriverState *bs, - BdrvChild *src, - int64_t src_offset, - BdrvChild *dst, - int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_flags, - BdrvRequestFlags write_flag= s) +static int coroutine_fn GRAPH_RDLOCK +iscsi_co_copy_range_to(BlockDriverState *bs, + BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { IscsiLun *dst_lun =3D dst->bs->opaque; IscsiLun *src_lun; diff --git a/block/qcow2.c b/block/qcow2.c index ddf9394bf0..c318f41f38 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -4065,7 +4065,7 @@ static coroutine_fn int qcow2_co_pdiscard(BlockDriver= State *bs, return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK qcow2_co_copy_range_from(BlockDriverState *bs, BdrvChild *src, int64_t src_offset, BdrvChild *dst, int64_t dst_offset, @@ -4148,7 +4148,7 @@ out: return ret; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK qcow2_co_copy_range_to(BlockDriverState *bs, BdrvChild *src, int64_t src_offset, BdrvChild *dst, int64_t dst_offset, @@ -4161,7 +4161,6 @@ qcow2_co_copy_range_to(BlockDriverState *bs, uint64_t host_offset; QCowL2Meta *l2meta =3D NULL; =20 - assume_graph_lock(); /* FIXME */ assert(!bs->encrypted); =20 qemu_co_mutex_lock(&s->lock); diff --git a/block/raw-format.c b/block/raw-format.c index 92adf97ab0..9913cb8174 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -536,14 +536,12 @@ static int raw_probe_geometry(BlockDriverState *bs, H= DGeometry *geo) return bdrv_probe_geometry(bs->file->bs, geo); } =20 -static int coroutine_fn raw_co_copy_range_from(BlockDriverState *bs, - BdrvChild *src, - int64_t src_offset, - BdrvChild *dst, - int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_flags, - BdrvRequestFlags write_flag= s) +static int coroutine_fn GRAPH_RDLOCK +raw_co_copy_range_from(BlockDriverState *bs, + BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { int ret; =20 @@ -555,14 +553,12 @@ static int coroutine_fn raw_co_copy_range_from(BlockD= riverState *bs, bytes, read_flags, write_flags); } =20 -static int coroutine_fn raw_co_copy_range_to(BlockDriverState *bs, - BdrvChild *src, - int64_t src_offset, - BdrvChild *dst, - int64_t dst_offset, - int64_t bytes, - BdrvRequestFlags read_flags, - BdrvRequestFlags write_flags) +static int coroutine_fn GRAPH_RDLOCK +raw_co_copy_range_to(BlockDriverState *bs, + BdrvChild *src, int64_t src_offset, + BdrvChild *dst, int64_t dst_offset, + int64_t bytes, BdrvRequestFlags read_flags, + BdrvRequestFlags write_flags) { int ret; =20 diff --git a/qemu-img.c b/qemu-img.c index cd0178b51b..9aeac69fa6 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2041,7 +2041,9 @@ retry: =20 if (s->ret =3D=3D -EINPROGRESS) { if (copy_range) { - ret =3D convert_co_copy_range(s, sector_num, n); + WITH_GRAPH_RDLOCK_GUARD() { + ret =3D convert_co_copy_range(s, sector_num, n); + } if (ret) { s->copy_range =3D false; goto retry; --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178551; cv=none; d=zohomail.com; s=zohoarc; b=GYgOkdkHcs5f3OXRqC55AhfnsFXhgH0KHNrhXf/5Q6gumTMM99pEUPP7gS6lCy63MAE3OFMAzGVIvqb6xF/rHUOUE4m2MjkIbZJyL//mPfskmg8Y+OO3A5rsPhNp7gr8AAVIUkhLrZLJWiw/s58zgl8bvLmYqYCpO3lIQSKQhZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178551; 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=vIsHGYadWGIXLYI8Vzux3OCNbRSAt/zxSTFxmrR0sXo=; b=JoO6QBRBZYd0PUkxZMq2MglYQtBW+X8suqPqoMKMeo2tODm3Jn68CYJykvKLW1S+/h+j93msA1HwbwnJQl8o8eo6NlFcr3GFlCUDlzA6CZMaXUlm6KUOeiCBs3oyTngcthPRogXAJJ29NNuG4UqRHUX8lS7hPXtiwGVvQ+TBmjU= 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 1677178551354252.91753115101653; Thu, 23 Feb 2023 10:55:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhW-0006us-CC; Thu, 23 Feb 2023 13:52:18 -0500 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 1pVGhP-0006qi-Gm for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:11 -0500 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 1pVGhN-00039z-Vo for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:11 -0500 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-343--S7QF1LEOZaUnPQLfUkq4w-1; Thu, 23 Feb 2023 13:52:06 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8D24D3C0D840; Thu, 23 Feb 2023 18:52:05 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id D798A1121314; Thu, 23 Feb 2023 18:52:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178329; 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=vIsHGYadWGIXLYI8Vzux3OCNbRSAt/zxSTFxmrR0sXo=; b=iqxg1S0dpz2IgC1CqHJpeS/BXq/341o7j/tMEvlC1nxGHT96G4+xzBTG1fpPEFHpCro/VI UBH6tfQttsLDTjdH67JpYzLrUvTv9ywJRYDe59oecpWjai07myWSwhlLL0rATGfVQIj/+z FU/3DOFQM3SgYSAsmDEMfgrgNrJG6gg= X-MC-Unique: -S7QF1LEOZaUnPQLfUkq4w-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 15/29] block: Mark preadv_snapshot/snapshot_block_status GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:32 +0100 Message-Id: <20230223185146.306454-16-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178553522100003 Content-Type: text/plain; charset="utf-8" Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-16-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- include/block/block_int-common.h | 12 +++++++----- include/block/block_int-io.h | 8 ++++---- block/copy-before-write.c | 6 ++---- block/io.c | 2 ++ block/snapshot-access.c | 4 ++-- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 29b230cc0b..7d8309ba5a 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -624,11 +624,13 @@ struct BlockDriver { * - receive the snapshot's actual length (which may differ from bs's * length) */ - int coroutine_fn (*bdrv_co_preadv_snapshot)(BlockDriverState *bs, - int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_off= set); - int coroutine_fn (*bdrv_co_snapshot_block_status)(BlockDriverState *bs, - bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, - int64_t *map, BlockDriverState **file); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_preadv_snapshot)( + BlockDriverState *bs, int64_t offset, int64_t bytes, + QEMUIOVector *qiov, size_t qiov_offset); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_snapshot_block_status)( + BlockDriverState *bs, bool want_zero, int64_t offset, int64_t byte= s, + int64_t *pnum, int64_t *map, BlockDriverState **file); =20 int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_pdiscard_snapshot)( BlockDriverState *bs, int64_t offset, int64_t bytes); diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 5788bd66ba..612e5ddf99 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -35,11 +35,11 @@ * the I/O API. */ =20 -int coroutine_fn bdrv_co_preadv_snapshot(BdrvChild *child, +int coroutine_fn GRAPH_RDLOCK bdrv_co_preadv_snapshot(BdrvChild *child, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset); -int coroutine_fn bdrv_co_snapshot_block_status(BlockDriverState *bs, - bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, - int64_t *map, BlockDriverState **file); +int coroutine_fn GRAPH_RDLOCK bdrv_co_snapshot_block_status( + BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, BlockDriverState **file); int coroutine_fn GRAPH_RDLOCK bdrv_co_pdiscard_snapshot(BlockDriverState *= bs, int64_t offset, int64_t bytes); =20 diff --git a/block/copy-before-write.c b/block/copy-before-write.c index e223e37300..646d8227a4 100644 --- a/block/copy-before-write.c +++ b/block/copy-before-write.c @@ -256,7 +256,7 @@ cbw_snapshot_read_unlock(BlockDriverState *bs, BlockReq= *req) g_free(req); } =20 -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK cbw_co_preadv_snapshot(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset) { @@ -264,8 +264,6 @@ cbw_co_preadv_snapshot(BlockDriverState *bs, int64_t of= fset, int64_t bytes, BdrvChild *file; int ret; =20 - assume_graph_lock(); /* FIXME */ - /* TODO: upgrade to async loop using AioTask */ while (bytes) { int64_t cur_bytes; @@ -290,7 +288,7 @@ cbw_co_preadv_snapshot(BlockDriverState *bs, int64_t of= fset, int64_t bytes, return 0; } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK cbw_co_snapshot_block_status(BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, diff --git a/block/io.c b/block/io.c index 86e5ea362d..d9c1594960 100644 --- a/block/io.c +++ b/block/io.c @@ -3532,6 +3532,7 @@ bdrv_co_preadv_snapshot(BdrvChild *child, int64_t off= set, int64_t bytes, BlockDriver *drv =3D bs->drv; int ret; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!drv) { return -ENOMEDIUM; @@ -3557,6 +3558,7 @@ bdrv_co_snapshot_block_status(BlockDriverState *bs, BlockDriver *drv =3D bs->drv; int ret; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!drv) { return -ENOMEDIUM; diff --git a/block/snapshot-access.c b/block/snapshot-access.c index 009cc4aea0..67ea339da9 100644 --- a/block/snapshot-access.c +++ b/block/snapshot-access.c @@ -26,7 +26,7 @@ #include "qemu/cutils.h" #include "block/block_int.h" =20 -static coroutine_fn int +static int coroutine_fn GRAPH_RDLOCK snapshot_access_co_preadv_part(BlockDriverState *bs, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, @@ -39,7 +39,7 @@ snapshot_access_co_preadv_part(BlockDriverState *bs, return bdrv_co_preadv_snapshot(bs->file, offset, bytes, qiov, qiov_off= set); } =20 -static int coroutine_fn +static int coroutine_fn GRAPH_RDLOCK snapshot_access_co_block_status(BlockDriverState *bs, bool want_zero, int64_t offset, int64_t bytes, int64_t *pnum, --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178437; cv=none; d=zohomail.com; s=zohoarc; b=EkbGCnIHWzfBRcuNijA27iFaGygoAvr3laCZqFEwubNHl9lMuViQphnn8VGI/9vnFGipUHoMD1tNBrCAyYOqu30Dylh13HUUKECNmaDhgAIKSldNfM4LGrtAL+hM6b7q+OuJNwinnN9H8KNsnU1rPGeyieC0vF44bTqNZ8mH348= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178437; 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=I2M2MMnWHpNbaUsLgPJyxj1jwZlYF526syKi6HFUx+g=; b=C1j9T5ove1eTKt41+Xj8V9nfc1C53nxUoq9har9iZMVrDGLcj0wfwAcvRnwU01C2tpVH6XbKwo3yRN82vSJ9McLEjEWB43dBB8jOQl6atfKCDibmYSfNDSmv74df61imEogILvcVBfjLJ6vcfsBMxjZ2KZ7mxrobcotnfjfL+kw= 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 1677178437532613.8990390086205; Thu, 23 Feb 2023 10:53:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGi6-0007Ix-EC; Thu, 23 Feb 2023 13:52:58 -0500 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 1pVGhk-00077P-Sl for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:34 -0500 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 1pVGhi-0003Ho-OC for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:32 -0500 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-441-smYG0xdNNmy5aiSd5XVWVw-1; Thu, 23 Feb 2023 13:52:14 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 75BD1185A78B; Thu, 23 Feb 2023 18:52:06 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1EA81121314; Thu, 23 Feb 2023 18:52:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178349; 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=I2M2MMnWHpNbaUsLgPJyxj1jwZlYF526syKi6HFUx+g=; b=cNth8ma4SrDncj9926P1Tf9x58C+jeoTUsoUGscgC5RHUgJA+0WJvVCn+tLcTgoS2VEjBF nLnNeepAPB+t3763EAoaQeK3JZOKaggrpPWYVd56juDXzGcafu2LL3yLs2JKl7OqJE4TMG +xn9p2rTVl27ZPBHchQ73kT2s/NAazk= X-MC-Unique: smYG0xdNNmy5aiSd5XVWVw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 16/29] block: Mark bdrv_co_create() and callers GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:33 +0100 Message-Id: <20230223185146.306454-17-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178438881100005 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_create() need to hold a reader lock for the graph. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-17-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- include/block/block-global-state.h | 14 ++++--- include/block/block_int-common.h | 11 +++--- block.c | 1 + block/create.c | 9 ++++- block/crypto.c | 7 ++-- block/file-posix.c | 7 ++-- block/file-win32.c | 7 ++-- block/parallels.c | 7 ++-- block/qcow.c | 6 +-- block/qcow2.c | 7 ++-- block/qed.c | 7 ++-- block/raw-format.c | 7 ++-- block/vdi.c | 7 ++-- block/vhdx.c | 7 ++-- block/vmdk.c | 63 ++++++++++++++---------------- block/vpc.c | 7 ++-- 16 files changed, 84 insertions(+), 90 deletions(-) diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 447176414e..399200a9a3 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -58,13 +58,15 @@ BlockDriver *bdrv_find_protocol(const char *filename, Error **errp); BlockDriver *bdrv_find_format(const char *format_name); =20 -int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename, - QemuOpts *opts, Error **errp); -int co_wrapper bdrv_create(BlockDriver *drv, const char *filename, - QemuOpts *opts, Error **errp); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_create(BlockDriver *drv, const char *filename, QemuOpts *opts, + Error **errp); =20 -int coroutine_fn bdrv_co_create_file(const char *filename, QemuOpts *opts, - Error **errp); +int co_wrapper_bdrv_rdlock bdrv_create(BlockDriver *drv, const char *filen= ame, + QemuOpts *opts, Error **errp); + +int coroutine_fn GRAPH_RDLOCK +bdrv_co_create_file(const char *filename, QemuOpts *opts, Error **errp); =20 BlockDriverState *bdrv_new(void); int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 7d8309ba5a..6b8fd22c71 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -246,12 +246,11 @@ struct BlockDriver { Error **errp); void (*bdrv_close)(BlockDriverState *bs); =20 - int coroutine_fn (*bdrv_co_create)(BlockdevCreateOptions *opts, - Error **errp); - int coroutine_fn (*bdrv_co_create_opts)(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create)( + BlockdevCreateOptions *opts, Error **errp); + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_create_opts)( + BlockDriver *drv, const char *filename, QemuOpts *opts, Error **er= rp); =20 int (*bdrv_amend_options)(BlockDriverState *bs, QemuOpts *opts, diff --git a/block.c b/block.c index 31f13092cb..484f48ae2d 100644 --- a/block.c +++ b/block.c @@ -533,6 +533,7 @@ int coroutine_fn bdrv_co_create(BlockDriver *drv, const= char *filename, int ret; GLOBAL_STATE_CODE(); ERRP_GUARD(); + assert_bdrv_graph_readable(); =20 if (!drv->bdrv_co_create_opts) { error_setg(errp, "Driver '%s' does not support image creation", diff --git a/block/create.c b/block/create.c index 4df43f11f4..bf67b9947c 100644 --- a/block/create.c +++ b/block/create.c @@ -43,6 +43,7 @@ static int coroutine_fn blockdev_create_run(Job *job, Err= or **errp) int ret; =20 GLOBAL_STATE_CODE(); + GRAPH_RDLOCK_GUARD(); =20 job_progress_set_remaining(&s->common, 1); ret =3D s->drv->bdrv_co_create(s->opts, errp); @@ -59,6 +60,12 @@ static const JobDriver blockdev_create_job_driver =3D { .run =3D blockdev_create_run, }; =20 +/* Checking whether the function is present doesn't require the graph lock= */ +static inline bool TSA_NO_TSA has_bdrv_co_create(BlockDriver *drv) +{ + return drv->bdrv_co_create; +} + void qmp_blockdev_create(const char *job_id, BlockdevCreateOptions *option= s, Error **errp) { @@ -79,7 +86,7 @@ void qmp_blockdev_create(const char *job_id, BlockdevCrea= teOptions *options, } =20 /* Error out if the driver doesn't support .bdrv_co_create */ - if (!drv->bdrv_co_create) { + if (!has_bdrv_co_create(drv)) { error_setg(errp, "Driver does not support blockdev-create"); return; } diff --git a/block/crypto.c b/block/crypto.c index 0ebb846534..e77790ac8a 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -664,10 +664,9 @@ fail: return ret; } =20 -static int coroutine_fn block_crypto_co_create_opts_luks(BlockDriver *drv, - const char *filen= ame, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +block_crypto_co_create_opts_luks(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { QCryptoBlockCreateOptions *create_opts =3D NULL; BlockDriverState *bs =3D NULL; diff --git a/block/file-posix.c b/block/file-posix.c index 13da095efa..5760cf22d1 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2607,10 +2607,9 @@ out: return result; } =20 -static int coroutine_fn raw_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +raw_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { BlockdevCreateOptions options; int64_t total_size =3D 0; diff --git a/block/file-win32.c b/block/file-win32.c index 200d244116..c7d0b85306 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -613,10 +613,9 @@ static int raw_co_create(BlockdevCreateOptions *option= s, Error **errp) return 0; } =20 -static int coroutine_fn raw_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +raw_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { BlockdevCreateOptions options; int64_t total_size =3D 0; diff --git a/block/parallels.c b/block/parallels.c index a7e9cad146..013684801a 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -622,10 +622,9 @@ exit: goto out; } =20 -static int coroutine_fn parallels_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +parallels_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { BlockdevCreateOptions *create_options =3D NULL; BlockDriverState *bs =3D NULL; diff --git a/block/qcow.c b/block/qcow.c index 58a0b4e2f0..490e4f819e 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -921,9 +921,9 @@ exit: return ret; } =20 -static int coroutine_fn qcow_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, Error **errp) +static int coroutine_fn GRAPH_RDLOCK +qcow_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { BlockdevCreateOptions *create_options =3D NULL; BlockDriverState *bs =3D NULL; diff --git a/block/qcow2.c b/block/qcow2.c index c318f41f38..30fd53fa64 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3816,10 +3816,9 @@ out: return ret; } =20 -static int coroutine_fn qcow2_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +qcow2_co_create_opts(BlockDriver *drv, const char *filename, QemuOpts *opt= s, + Error **errp) { BlockdevCreateOptions *create_options =3D NULL; QDict *qdict; diff --git a/block/qed.c b/block/qed.c index c969b31e2c..ed94bb61ca 100644 --- a/block/qed.c +++ b/block/qed.c @@ -754,10 +754,9 @@ out: return ret; } =20 -static int coroutine_fn bdrv_qed_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +bdrv_qed_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { BlockdevCreateOptions *create_options =3D NULL; QDict *qdict; diff --git a/block/raw-format.c b/block/raw-format.c index 9913cb8174..646606e223 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -430,10 +430,9 @@ static int raw_has_zero_init(BlockDriverState *bs) return bdrv_has_zero_init(bs->file->bs); } =20 -static int coroutine_fn raw_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +raw_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { return bdrv_co_create_file(filename, opts, errp); } diff --git a/block/vdi.c b/block/vdi.c index b50c0b7277..f2434d6153 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -898,10 +898,9 @@ static int coroutine_fn vdi_co_create(BlockdevCreateOp= tions *create_options, return vdi_co_do_create(create_options, DEFAULT_CLUSTER_SIZE, errp); } =20 -static int coroutine_fn vdi_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vdi_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { QDict *qdict =3D NULL; BlockdevCreateOptions *create_options =3D NULL; diff --git a/block/vhdx.c b/block/vhdx.c index ffa4455e82..81420722a1 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -2059,10 +2059,9 @@ delete_and_exit: return ret; } =20 -static int coroutine_fn vhdx_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vhdx_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { BlockdevCreateOptions *create_options =3D NULL; QDict *qdict; diff --git a/block/vmdk.c b/block/vmdk.c index c601ca85f4..f5f49018fe 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2277,11 +2277,10 @@ exit: return ret; } =20 -static int coroutine_fn vmdk_create_extent(const char *filename, - int64_t filesize, bool flat, - bool compress, bool zeroed_grai= n, - BlockBackend **pbb, - QemuOpts *opts, Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vmdk_create_extent(const char *filename, int64_t filesize, bool flat, + bool compress, bool zeroed_grain, BlockBackend **pbb, + QemuOpts *opts, Error **errp) { int ret; BlockBackend *blk =3D NULL; @@ -2359,14 +2358,10 @@ static int filename_decompose(const char *filename,= char *path, char *prefix, * non-split format. * idx >=3D 1: get the n-th extent if in a split subformat */ -typedef BlockBackend * coroutine_fn (*vmdk_create_extent_fn)(int64_t size, - int idx, - bool flat, - bool split, - bool compress, - bool zeroed_g= rain, - void *opaque, - Error **errp); +typedef BlockBackend * coroutine_fn /* GRAPH_RDLOCK */ + (*vmdk_create_extent_fn)(int64_t size, int idx, bool flat, bool split, + bool compress, bool zeroed_grain, void *opaqu= e, + Error **errp); =20 static void vmdk_desc_add_extent(GString *desc, const char *extent_line_fmt, @@ -2379,17 +2374,18 @@ static void vmdk_desc_add_extent(GString *desc, g_free(basename); } =20 -static int coroutine_fn vmdk_co_do_create(int64_t size, - BlockdevVmdkSubformat subformat, - BlockdevVmdkAdapterType adapter_= type, - const char *backing_file, - const char *hw_version, - const char *toolsversion, - bool compat6, - bool zeroed_grain, - vmdk_create_extent_fn extent_fn, - void *opaque, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vmdk_co_do_create(int64_t size, + BlockdevVmdkSubformat subformat, + BlockdevVmdkAdapterType adapter_type, + const char *backing_file, + const char *hw_version, + const char *toolsversion, + bool compat6, + bool zeroed_grain, + vmdk_create_extent_fn extent_fn, + void *opaque, + Error **errp) { int extent_idx; BlockBackend *blk =3D NULL; @@ -2609,10 +2605,10 @@ typedef struct { QemuOpts *opts; } VMDKCreateOptsData; =20 -static BlockBackend * coroutine_fn vmdk_co_create_opts_cb(int64_t size, in= t idx, - bool flat, bool split, bool co= mpress, - bool zeroed_grain, void *opaqu= e, - Error **errp) +static BlockBackend * coroutine_fn GRAPH_RDLOCK +vmdk_co_create_opts_cb(int64_t size, int idx, bool flat, bool split, + bool compress, bool zeroed_grain, void *opaque, + Error **errp) { BlockBackend *blk =3D NULL; BlockDriverState *bs =3D NULL; @@ -2651,10 +2647,9 @@ exit: return blk; } =20 -static int coroutine_fn vmdk_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vmdk_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { Error *local_err =3D NULL; char *desc =3D NULL; @@ -2814,8 +2809,8 @@ static BlockBackend * coroutine_fn vmdk_co_create_cb(= int64_t size, int idx, return blk; } =20 -static int coroutine_fn vmdk_co_create(BlockdevCreateOptions *create_optio= ns, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vmdk_co_create(BlockdevCreateOptions *create_options, Error **errp) { BlockdevCreateOptionsVmdk *opts; =20 diff --git a/block/vpc.c b/block/vpc.c index 1f0f26c0c4..b89b0ff8e2 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -1087,10 +1087,9 @@ out: return ret; } =20 -static int coroutine_fn vpc_co_create_opts(BlockDriver *drv, - const char *filename, - QemuOpts *opts, - Error **errp) +static int coroutine_fn GRAPH_RDLOCK +vpc_co_create_opts(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { BlockdevCreateOptions *create_options =3D NULL; QDict *qdict; --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178577; cv=none; d=zohomail.com; s=zohoarc; b=XaiJJHOyReDA6LHnGQGnZMNkG/AHuZzR/sPY1fNf891I1Jf+HG5v7xbk6S6T5CUMHDVmADSZOaac3Jz8ai9PEzIHszyvsd3jgUfP6wsbv9Matx1YrN+SLc1l0NuuWBNb41evmPPrC1L6iHdScf07V+D9+UurRkXNe/Sur8hIWag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178577; 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=aL+hvOHiNFmfkdkOkc67vQaQWPprJfiLmS/AQXCBTb0=; b=TVvY443cIksqXh7ugutUrtfXWqI4zDZjQOS2rtioD8s6GiK4lS+S3YCSsgS6fIrG0/q45Fd1dxZaWymlC/qZK7ZHjnAjqsNvmBkiDBILAkfxG81c2U/UMV/UvuUIOJKZSgt4qSjRcWMJhIDyttX+TKJDv4v6PJqog0+1YtiAfjA= 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 1677178577849901.1038255626818; Thu, 23 Feb 2023 10:56:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhc-00071K-3C; Thu, 23 Feb 2023 13:52:24 -0500 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 1pVGhY-0006xd-BJ for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:20 -0500 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 1pVGhW-0003Dv-8T for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:20 -0500 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-627-q54sQZhwNj6sF9PbepdA3g-1; Thu, 23 Feb 2023 13:52:12 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5DCE1280048A; Thu, 23 Feb 2023 18:52:07 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB0261121314; Thu, 23 Feb 2023 18:52:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178337; 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=aL+hvOHiNFmfkdkOkc67vQaQWPprJfiLmS/AQXCBTb0=; b=Ba2dviUi8jzh0YINMnzrjeTQWbdfwFpkPbUGu2xWRWpTKsHugdF+y1Ca6E+xNvHydQtwdx +FWIsANfzgon4PGiCxlMdeJmHfKjToTq5an6wjTJb0Jv6qWjmODTMDGYMhSF/90n1SwyPs 1em3MJzN7d5blSevx1ayAdBjtIZx8eg= X-MC-Unique: q54sQZhwNj6sF9PbepdA3g-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 17/29] block: Mark bdrv_co_io_(un)plug() and callers GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:34 +0100 Message-Id: <20230223185146.306454-18-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178579651100003 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_io_plug() and bdrv_co_io_unplug() need to hold a reader lock for the graph. Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-18-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- include/block/block-io.h | 4 ++-- include/block/block_int-common.h | 5 +++-- block/block-backend.c | 2 ++ block/io.c | 2 ++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index c551742a86..b8f99741a3 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -233,8 +233,8 @@ void coroutine_fn bdrv_co_leave(BlockDriverState *bs, A= ioContext *old_ctx); =20 AioContext *child_of_bds_get_parent_aio_context(BdrvChild *c); =20 -void coroutine_fn bdrv_co_io_plug(BlockDriverState *bs); -void coroutine_fn bdrv_co_io_unplug(BlockDriverState *bs); +void coroutine_fn GRAPH_RDLOCK bdrv_co_io_plug(BlockDriverState *bs); +void coroutine_fn GRAPH_RDLOCK bdrv_co_io_unplug(BlockDriverState *bs); =20 bool coroutine_fn bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 6b8fd22c71..61f894bcf6 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -735,8 +735,9 @@ struct BlockDriver { BlkdebugEvent event); =20 /* io queue for linux-aio */ - void coroutine_fn (*bdrv_co_io_plug)(BlockDriverState *bs); - void coroutine_fn (*bdrv_co_io_unplug)(BlockDriverState *bs); + void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_io_plug)(BlockDriverState= *bs); + void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_io_unplug)( + BlockDriverState *bs); =20 /** * bdrv_drain_begin is called if implemented in the beginning of a diff --git a/block/block-backend.c b/block/block-backend.c index fdb1e1d5f7..3661a066b3 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2328,6 +2328,7 @@ void coroutine_fn blk_co_io_plug(BlockBackend *blk) { BlockDriverState *bs =3D blk_bs(blk); IO_CODE(); + GRAPH_RDLOCK_GUARD(); =20 if (bs) { bdrv_co_io_plug(bs); @@ -2338,6 +2339,7 @@ void coroutine_fn blk_co_io_unplug(BlockBackend *blk) { BlockDriverState *bs =3D blk_bs(blk); IO_CODE(); + GRAPH_RDLOCK_GUARD(); =20 if (bs) { bdrv_co_io_unplug(bs); diff --git a/block/io.c b/block/io.c index d9c1594960..b5459c2f41 100644 --- a/block/io.c +++ b/block/io.c @@ -3153,6 +3153,7 @@ void coroutine_fn bdrv_co_io_plug(BlockDriverState *b= s) { BdrvChild *child; IO_CODE(); + assert_bdrv_graph_readable(); =20 QLIST_FOREACH(child, &bs->children, next) { bdrv_co_io_plug(child->bs); @@ -3170,6 +3171,7 @@ void coroutine_fn bdrv_co_io_unplug(BlockDriverState = *bs) { BdrvChild *child; IO_CODE(); + assert_bdrv_graph_readable(); =20 assert(bs->io_plugged); if (qatomic_fetch_dec(&bs->io_plugged) =3D=3D 1) { --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178449; cv=none; d=zohomail.com; s=zohoarc; b=F4O7V26QP2wqzohslgRj75K4IuhNAhc88VFK9ZI6XLSFkcHvQgPuokKMj7UgAFcTxGWnVf8URsEZXZl2mvJhx5KHMGQ9D3GgwCkXU3srBYuYKrwKKb1rol7czLeZipl87+ismtdrIrtLeMl/7Z0NQXghKWnX5YzqAnjd9erVFto= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178449; 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=jG946PdQUa/nsU6Qrgid5EDq8LNPqKVXy8p9PH6OlOI=; b=VeHNQKBwUNZiaxL9PjqH5RUMLWee6wGW4DNf8oz6wvg45M4ChBSW8vAgKWikY42vk5GbmlB5fKU/j/c5vTao+6vyH3u5vBJFsQxz1n/P8bfisoNktiIU86UmOxVkbC9gWgK2wIFO3PMDYicbWxxOdTckV3S5BQ9SwDmZU6XndAo= 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 1677178449709751.8238800090274; Thu, 23 Feb 2023 10:54:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhY-0006yS-Pa; Thu, 23 Feb 2023 13:52:20 -0500 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 1pVGhS-0006sP-N3 for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:15 -0500 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 1pVGhQ-0003BN-VV for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:14 -0500 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-425-Cyd5NJazNL6lAg8d_ZB7HQ-1; Thu, 23 Feb 2023 13:52:08 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 46AFD86C164; Thu, 23 Feb 2023 18:52:08 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 941461121314; Thu, 23 Feb 2023 18:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178331; 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=jG946PdQUa/nsU6Qrgid5EDq8LNPqKVXy8p9PH6OlOI=; b=ca6+3OKn/NyE4sVM8Y2Z6FupoYe6aiAmlSOTpZNRL2DkaE5i0mRaMb4RvCeqVkz9REzZ3A rzM/j0jeGxoYtM21/qtk7Ro5D/IWEMs8+d/v8ZLoigaHwu9OB/gWMz0NY+Iad/YJvzFuKY nXpxphh78G4M8T7QqhNvHzWYH5fQOw4= X-MC-Unique: Cyd5NJazNL6lAg8d_ZB7HQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 18/29] block: Mark bdrv_co_is_inserted() and callers GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:35 +0100 Message-Id: <20230223185146.306454-19-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178450904100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_is_inserted() need to hold a reader lock for the graph. blk_is_inserted() is done as a co_wrapper_mixed_bdrv_rdlock (unlike most other blk_* functions) because it is called a lot from other blk_co_*() functions that already hold the lock. These calls go through blk_is_available(), which becomes a co_wrapper_mixed_bdrv_rdlock, too, for the same reason. Functions that run in a coroutine and can call bdrv_co_is_available() directly are changed to do so, which results in better TSA coverage. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-19-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- include/block/block-io.h | 4 ++-- include/block/block_int-common.h | 3 ++- include/sysemu/block-backend-io.h | 7 ++++--- block.c | 1 + block/block-backend.c | 25 ++++++++++++++----------- 5 files changed, 23 insertions(+), 17 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index b8f99741a3..88db63492a 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -145,8 +145,8 @@ bool bdrv_is_writable(BlockDriverState *bs); bool bdrv_is_sg(BlockDriverState *bs); int bdrv_get_flags(BlockDriverState *bs); =20 -bool coroutine_fn bdrv_co_is_inserted(BlockDriverState *bs); -bool co_wrapper bdrv_is_inserted(BlockDriverState *bs); +bool coroutine_fn GRAPH_RDLOCK bdrv_co_is_inserted(BlockDriverState *bs); +bool co_wrapper_bdrv_rdlock bdrv_is_inserted(BlockDriverState *bs); =20 void coroutine_fn bdrv_co_lock_medium(BlockDriverState *bs, bool locked); void coroutine_fn bdrv_co_eject(BlockDriverState *bs, bool eject_flag); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 61f894bcf6..b4a82269e5 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -712,7 +712,8 @@ struct BlockDriver { BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); =20 /* removable device specific */ - bool coroutine_fn (*bdrv_co_is_inserted)(BlockDriverState *bs); + bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_is_inserted)( + BlockDriverState *bs); void coroutine_fn (*bdrv_co_eject)(BlockDriverState *bs, bool eject_fl= ag); void coroutine_fn (*bdrv_co_lock_medium)(BlockDriverState *bs, bool lo= cked); =20 diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index b1196ab93c..40ab178719 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -55,10 +55,11 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned l= ong int req, void *buf, void blk_inc_in_flight(BlockBackend *blk); void blk_dec_in_flight(BlockBackend *blk); =20 -bool coroutine_fn blk_co_is_inserted(BlockBackend *blk); -bool co_wrapper_mixed blk_is_inserted(BlockBackend *blk); +bool coroutine_fn GRAPH_RDLOCK blk_co_is_inserted(BlockBackend *blk); +bool co_wrapper_mixed_bdrv_rdlock blk_is_inserted(BlockBackend *blk); =20 -bool blk_is_available(BlockBackend *blk); +bool coroutine_fn GRAPH_RDLOCK blk_co_is_available(BlockBackend *blk); +bool co_wrapper_mixed_bdrv_rdlock blk_is_available(BlockBackend *blk); =20 void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked); void co_wrapper blk_lock_medium(BlockBackend *blk, bool locked); diff --git a/block.c b/block.c index 484f48ae2d..738b42046c 100644 --- a/block.c +++ b/block.c @@ -6826,6 +6826,7 @@ bool coroutine_fn bdrv_co_is_inserted(BlockDriverStat= e *bs) BlockDriver *drv =3D bs->drv; BdrvChild *child; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!drv) { return false; diff --git a/block/block-backend.c b/block/block-backend.c index 3661a066b3..20af699f00 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1235,8 +1235,8 @@ void blk_set_disable_request_queuing(BlockBackend *bl= k, bool disable) blk->disable_request_queuing =3D disable; } =20 -static coroutine_fn int blk_check_byte_request(BlockBackend *blk, - int64_t offset, int64_t byt= es) +static int coroutine_fn GRAPH_RDLOCK +blk_check_byte_request(BlockBackend *blk, int64_t offset, int64_t bytes) { int64_t len; =20 @@ -1244,7 +1244,7 @@ static coroutine_fn int blk_check_byte_request(BlockB= ackend *blk, return -EIO; } =20 - if (!blk_is_available(blk)) { + if (!blk_co_is_available(blk)) { return -ENOMEDIUM; } =20 @@ -1606,8 +1606,9 @@ BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, = int64_t offset, int64_t coroutine_fn blk_co_getlength(BlockBackend *blk) { IO_CODE(); + GRAPH_RDLOCK_GUARD(); =20 - if (!blk_is_available(blk)) { + if (!blk_co_is_available(blk)) { return -ENOMEDIUM; } =20 @@ -1627,8 +1628,9 @@ void blk_get_geometry(BlockBackend *blk, uint64_t *nb= _sectors_ptr) int64_t coroutine_fn blk_co_nb_sectors(BlockBackend *blk) { IO_CODE(); + GRAPH_RDLOCK_GUARD(); =20 - if (!blk_is_available(blk)) { + if (!blk_co_is_available(blk)) { return -ENOMEDIUM; } =20 @@ -1676,7 +1678,7 @@ blk_co_do_ioctl(BlockBackend *blk, unsigned long int = req, void *buf) blk_wait_while_drained(blk); GRAPH_RDLOCK_GUARD(); =20 - if (!blk_is_available(blk)) { + if (!blk_co_is_available(blk)) { return -ENOMEDIUM; } =20 @@ -1769,7 +1771,7 @@ static int coroutine_fn blk_co_do_flush(BlockBackend = *blk) blk_wait_while_drained(blk); GRAPH_RDLOCK_GUARD(); =20 - if (!blk_is_available(blk)) { + if (!blk_co_is_available(blk)) { return -ENOMEDIUM; } =20 @@ -1996,14 +1998,15 @@ bool coroutine_fn blk_co_is_inserted(BlockBackend *= blk) { BlockDriverState *bs =3D blk_bs(blk); IO_CODE(); + assert_bdrv_graph_readable(); =20 return bs && bdrv_co_is_inserted(bs); } =20 -bool blk_is_available(BlockBackend *blk) +bool coroutine_fn blk_co_is_available(BlockBackend *blk) { IO_CODE(); - return blk_is_inserted(blk) && !blk_dev_is_tray_open(blk); + return blk_co_is_inserted(blk) && !blk_dev_is_tray_open(blk); } =20 void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked) @@ -2382,7 +2385,7 @@ int coroutine_fn blk_co_truncate(BlockBackend *blk, i= nt64_t offset, bool exact, { IO_OR_GS_CODE(); GRAPH_RDLOCK_GUARD(); - if (!blk_is_available(blk)) { + if (!blk_co_is_available(blk)) { error_setg(errp, "No medium inserted"); return -ENOMEDIUM; } @@ -2637,6 +2640,7 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_= in, int64_t off_in, { int r; IO_CODE(); + GRAPH_RDLOCK_GUARD(); =20 r =3D blk_check_byte_request(blk_in, off_in, bytes); if (r) { @@ -2647,7 +2651,6 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_= in, int64_t off_in, return r; } =20 - GRAPH_RDLOCK_GUARD(); return bdrv_co_copy_range(blk_in->root, off_in, blk_out->root, off_out, bytes, read_flags, write_flags); --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178623; cv=none; d=zohomail.com; s=zohoarc; b=P80Il3gXOJ3+IMW7+yTOhWGpQiylkX9dBEoLKUFyTjmijRV7JMiuFLBaS9CLjKoBug+saw5o+PeVs5FCKYR5OuMKDU5zldYb/Qaype7+xBwKIdLBNS9CZ3J+rum1FSTc0iq5KLZ/9vDkqICIrHZQgwu45Er4rw6nhzFHqHkcQ9o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178623; 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=0aX19loUnvz4eVtXt5ZbOL2UKg0Uz6K3mCszEj/MO8k=; b=TyEnjepDFJjiLY9gP3cuidCssdfNslPxNDTGdEObKFaZcyVkG6oFTMd78Mbv7RpebR7EZo08jFOUmOvCECrVvs8Hyl5Ue2fUE2h8h6KgJYQrND3lDeiL4zn3R4rvvFYWOd1vGv0QhiLRVQPq4QF0WpaoYu0n7cSZbXyj3Wc4Xtc= 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 167717862368646.215234343524; Thu, 23 Feb 2023 10:57:03 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhZ-0006zS-U3; Thu, 23 Feb 2023 13:52:21 -0500 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 1pVGhR-0006rY-HM for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:13 -0500 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 1pVGhP-0003B4-QI for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:13 -0500 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-400-h0dq3DL0MtOg64P1GkZ3Jw-1; Thu, 23 Feb 2023 13:52:09 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2F5641C05140; Thu, 23 Feb 2023 18:52:09 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7C6791121314; Thu, 23 Feb 2023 18:52:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178331; 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=0aX19loUnvz4eVtXt5ZbOL2UKg0Uz6K3mCszEj/MO8k=; b=WL51JMnIKj4oUiS6oZp6Wy+ZGaer5idZLg3WV1Q0A+FM3bzjRkHnLeGm8OKCn+HWbCmXOU I22c39vUchVNo96kp+eABDWP1C657/bkvbMK3a/oDqPorjWsbZ9U2Zp5s5mfmsxLPTThGH zJwJ4qTte9ZppJIhcQPmIC7w+8u85mo= X-MC-Unique: h0dq3DL0MtOg64P1GkZ3Jw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 19/29] block: Mark bdrv_co_eject/lock_medium() and callers GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:36 +0100 Message-Id: <20230223185146.306454-20-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178624056100004 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_eject() and bdrv_co_lock_medium() need to hold a reader lock for the graph. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-20-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- include/block/block-io.h | 7 +++++-- include/block/block_int-common.h | 6 ++++-- block.c | 2 ++ block/block-backend.c | 2 ++ block/copy-on-read.c | 6 ++++-- block/filter-compress.c | 4 ++-- block/raw-format.c | 6 ++++-- 7 files changed, 23 insertions(+), 10 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 88db63492a..bf2748011e 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -148,8 +148,11 @@ int bdrv_get_flags(BlockDriverState *bs); bool coroutine_fn GRAPH_RDLOCK bdrv_co_is_inserted(BlockDriverState *bs); bool co_wrapper_bdrv_rdlock bdrv_is_inserted(BlockDriverState *bs); =20 -void coroutine_fn bdrv_co_lock_medium(BlockDriverState *bs, bool locked); -void coroutine_fn bdrv_co_eject(BlockDriverState *bs, bool eject_flag); +void coroutine_fn GRAPH_RDLOCK +bdrv_co_lock_medium(BlockDriverState *bs, bool locked); + +void coroutine_fn GRAPH_RDLOCK +bdrv_co_eject(BlockDriverState *bs, bool eject_flag); =20 const char *bdrv_get_format_name(BlockDriverState *bs); =20 diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index b4a82269e5..30e6bd4909 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -714,8 +714,10 @@ struct BlockDriver { /* removable device specific */ bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_is_inserted)( BlockDriverState *bs); - void coroutine_fn (*bdrv_co_eject)(BlockDriverState *bs, bool eject_fl= ag); - void coroutine_fn (*bdrv_co_lock_medium)(BlockDriverState *bs, bool lo= cked); + void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_eject)( + BlockDriverState *bs, bool eject_flag); + void coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_lock_medium)( + BlockDriverState *bs, bool locked); =20 /* to control generic scsi devices */ BlockAIOCB *coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_aio_ioctl)( diff --git a/block.c b/block.c index 738b42046c..1060194e8f 100644 --- a/block.c +++ b/block.c @@ -6849,6 +6849,7 @@ void coroutine_fn bdrv_co_eject(BlockDriverState *bs,= bool eject_flag) { BlockDriver *drv =3D bs->drv; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (drv && drv->bdrv_co_eject) { drv->bdrv_co_eject(bs, eject_flag); @@ -6863,6 +6864,7 @@ void coroutine_fn bdrv_co_lock_medium(BlockDriverStat= e *bs, bool locked) { BlockDriver *drv =3D bs->drv; IO_CODE(); + assert_bdrv_graph_readable(); trace_bdrv_lock_medium(bs, locked); =20 if (drv && drv->bdrv_co_lock_medium) { diff --git a/block/block-backend.c b/block/block-backend.c index 20af699f00..278b04ce69 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2013,6 +2013,7 @@ void coroutine_fn blk_co_lock_medium(BlockBackend *bl= k, bool locked) { BlockDriverState *bs =3D blk_bs(blk); IO_CODE(); + GRAPH_RDLOCK_GUARD(); =20 if (bs) { bdrv_co_lock_medium(bs, locked); @@ -2024,6 +2025,7 @@ void coroutine_fn blk_co_eject(BlockBackend *blk, boo= l eject_flag) BlockDriverState *bs =3D blk_bs(blk); char *id; IO_CODE(); + GRAPH_RDLOCK_GUARD(); =20 if (bs) { bdrv_co_eject(bs, eject_flag); diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 78da353f88..20215cff93 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -213,13 +213,15 @@ cor_co_pwritev_compressed(BlockDriverState *bs, int64= _t offset, int64_t bytes, } =20 =20 -static void coroutine_fn cor_co_eject(BlockDriverState *bs, bool eject_fla= g) +static void coroutine_fn GRAPH_RDLOCK +cor_co_eject(BlockDriverState *bs, bool eject_flag) { bdrv_co_eject(bs->file->bs, eject_flag); } =20 =20 -static void coroutine_fn cor_co_lock_medium(BlockDriverState *bs, bool loc= ked) +static void coroutine_fn GRAPH_RDLOCK +cor_co_lock_medium(BlockDriverState *bs, bool locked) { bdrv_co_lock_medium(bs->file->bs, locked); } diff --git a/block/filter-compress.c b/block/filter-compress.c index 0dd5606410..c7d50a67a7 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -114,14 +114,14 @@ static void compress_refresh_limits(BlockDriverState = *bs, Error **errp) } =20 =20 -static void coroutine_fn +static void coroutine_fn GRAPH_RDLOCK compress_co_eject(BlockDriverState *bs, bool eject_flag) { bdrv_co_eject(bs->file->bs, eject_flag); } =20 =20 -static void coroutine_fn +static void coroutine_fn GRAPH_RDLOCK compress_co_lock_medium(BlockDriverState *bs, bool locked) { bdrv_co_lock_medium(bs->file->bs, locked); diff --git a/block/raw-format.c b/block/raw-format.c index 646606e223..f4203d4806 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -405,12 +405,14 @@ raw_co_truncate(BlockDriverState *bs, int64_t offset,= bool exact, return bdrv_co_truncate(bs->file, offset, exact, prealloc, flags, errp= ); } =20 -static void coroutine_fn raw_co_eject(BlockDriverState *bs, bool eject_fla= g) +static void coroutine_fn GRAPH_RDLOCK +raw_co_eject(BlockDriverState *bs, bool eject_flag) { bdrv_co_eject(bs->file->bs, eject_flag); } =20 -static void coroutine_fn raw_co_lock_medium(BlockDriverState *bs, bool loc= ked) +static void coroutine_fn GRAPH_RDLOCK +raw_co_lock_medium(BlockDriverState *bs, bool locked) { bdrv_co_lock_medium(bs->file->bs, locked); } --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178627; cv=none; d=zohomail.com; s=zohoarc; b=nSAbHj7NyvUOOxoAC6pEmiaPVpd8HXHNE91SPu0W5v++Sg0x24ZlVgCtAV12kKmuqRq/EfKtCnCorEcyOAlBcYoaOgMCcnjD8srvZRoY7HlMOwE+2z/mHR0/nRXbDYjfJk027/xZc5tzEoGyTgruZJ83mN1p47SlPljmTUR8nms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178627; 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=lB4vXXS10jcq4HSHMF1ZG7MJWiFjNP2BuY1AKEKBvyw=; b=TupiKuEPGKPphniilb4oyEgeRrdWFFDCyAcuLO5TGB+lj4r/e24I+d3+cQ3KGbrA5EKsSeYvSHzuC7c1Jz9Zwn4wI9aSAU/beD4O9MiDE1Ozrs7CGiytYHfcsIsltkujoKWwHUaR3Da/ttqhZGVQFYBPLMz9DmjcjqLS27AUGqw= 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 1677178627591494.1624262983802; Thu, 23 Feb 2023 10:57:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhX-0006vq-AT; Thu, 23 Feb 2023 13:52:19 -0500 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 1pVGhU-0006sZ-1M for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:17 -0500 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 1pVGhS-0003CA-Jb for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:15 -0500 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-zFSs1KrbNCONzszzxjtfCA-1; Thu, 23 Feb 2023 13:52:10 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 19B5E1816EC2; Thu, 23 Feb 2023 18:52:10 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6615B1121314; Thu, 23 Feb 2023 18:52:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178334; 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=lB4vXXS10jcq4HSHMF1ZG7MJWiFjNP2BuY1AKEKBvyw=; b=bGSR1h3FmpCCjwzhK8pXswOAAsODSE4vbWMeNgQ5LdwMGqGlJY7/Bb/rRdnQfExK+6dAiM VNNmzqU+OGLlmvL3MD6En4vLvsupP09q7wiecLURfHIXGsBfoe+EY6PXDqjYFU9lWUOgc9 BYZ+INREa3mQg3o92KvwEhIx7cTXApo= X-MC-Unique: zFSs1KrbNCONzszzxjtfCA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 20/29] block: Mark bdrv_(un)register_buf() GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:37 +0100 Message-Id: <20230223185146.306454-21-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178628042100018 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_register_buf() and bdrv_unregister_buf() need to hold a reader lock for the graph. Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-21-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- include/block/block_int-common.h | 7 ++++--- block/io.c | 14 ++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 30e6bd4909..88d9897c97 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -445,9 +445,10 @@ struct BlockDriver { * * Returns: true on success, false on failure */ - bool (*bdrv_register_buf)(BlockDriverState *bs, void *host, size_t siz= e, - Error **errp); - void (*bdrv_unregister_buf)(BlockDriverState *bs, void *host, size_t s= ize); + bool GRAPH_RDLOCK_PTR (*bdrv_register_buf)( + BlockDriverState *bs, void *host, size_t size, Error **errp); + void GRAPH_RDLOCK_PTR (*bdrv_unregister_buf)( + BlockDriverState *bs, void *host, size_t size); =20 /* * This field is modified only under the BQL, and is part of diff --git a/block/io.c b/block/io.c index b5459c2f41..8974d46941 100644 --- a/block/io.c +++ b/block/io.c @@ -3187,13 +3187,15 @@ void coroutine_fn bdrv_co_io_unplug(BlockDriverStat= e *bs) } =20 /* Helper that undoes bdrv_register_buf() when it fails partway through */ -static void bdrv_register_buf_rollback(BlockDriverState *bs, - void *host, - size_t size, - BdrvChild *final_child) +static void GRAPH_RDLOCK +bdrv_register_buf_rollback(BlockDriverState *bs, void *host, size_t size, + BdrvChild *final_child) { BdrvChild *child; =20 + GLOBAL_STATE_CODE(); + assert_bdrv_graph_readable(); + QLIST_FOREACH(child, &bs->children, next) { if (child =3D=3D final_child) { break; @@ -3213,6 +3215,8 @@ bool bdrv_register_buf(BlockDriverState *bs, void *ho= st, size_t size, BdrvChild *child; =20 GLOBAL_STATE_CODE(); + GRAPH_RDLOCK_GUARD_MAINLOOP(); + if (bs->drv && bs->drv->bdrv_register_buf) { if (!bs->drv->bdrv_register_buf(bs, host, size, errp)) { return false; @@ -3232,6 +3236,8 @@ void bdrv_unregister_buf(BlockDriverState *bs, void *= host, size_t size) BdrvChild *child; =20 GLOBAL_STATE_CODE(); + GRAPH_RDLOCK_GUARD_MAINLOOP(); + if (bs->drv && bs->drv->bdrv_unregister_buf) { bs->drv->bdrv_unregister_buf(bs, host, size); } --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178515; cv=none; d=zohomail.com; s=zohoarc; b=LCB+UOAYYP2s1Ya8PnWoX/byQmWDZQDZNVMjbloXa6t6xmlyro/abvHSwrLoI+iFnb7fn2YjgBvHEExLlpGcHzUNhev8PW1+Uaey2cwVyLMWBedtkgre7Yvb2nwgmes+qyQImUBuRABxeTr5dxgGfzcFyZIoNzQybvJfxC7olKE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178515; 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=mbQEWXoS+454MXml6OIOjPROv+sT3BtpFvnr/TQ/aEA=; b=SQ5k7jPH/vUoVS4qW9SX0ak1omTUQkt3v+zq0DqIaQENSYqhcUk/cdX4qMS62y4o913NoPVLLITPTuAWJn2jggwaYIKmFxOYilBVfleesrcZHCPWM64oRQtLOjm71l2lML4v4ecE/j7jqSKYoERs2S1E+LRCXI/6Ry3YCm8zGJQ= 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 1677178515076917.3465746073789; Thu, 23 Feb 2023 10:55:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhZ-0006zX-W3; Thu, 23 Feb 2023 13:52:22 -0500 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 1pVGhT-0006sW-P6 for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:17 -0500 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 1pVGhR-0003Bs-ME for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:15 -0500 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-212-ZFIx1x5YN8auaGnaLOhzWg-1; Thu, 23 Feb 2023 13:52:11 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 03061280048E; Thu, 23 Feb 2023 18:52:11 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F8951121314; Thu, 23 Feb 2023 18:52:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178333; 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=mbQEWXoS+454MXml6OIOjPROv+sT3BtpFvnr/TQ/aEA=; b=bZx50EYMVqr65Ps2MrhJ7HVEcTg5Es/V3fnP7n89pkFEZP5dYNkZ8oHp5G5zh6R0YrzHKV pG4NnyP/TdfB+S7yoJBz1ME8xscHLoN8lTMTzG6DAqUxz1JLbcDhxS8qSHlgjnRbFh7VsL ZE300T2TuiJ587tEasjEbOhPmyTgyqU= X-MC-Unique: ZFIx1x5YN8auaGnaLOhzWg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 21/29] block: Mark bdrv_co_delete_file() and callers GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:38 +0100 Message-Id: <20230223185146.306454-22-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178515412100001 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_delete_file() need to hold a reader lock for the graph. Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-22-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- include/block/block-io.h | 8 ++++++-- include/block/block_int-common.h | 4 ++-- block.c | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index bf2748011e..a195a9fb11 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -90,8 +90,12 @@ int64_t co_wrapper bdrv_get_allocated_file_size(BlockDri= verState *bs); BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *opts, BlockDriverState *in_bs, Error **errp); void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); -int coroutine_fn bdrv_co_delete_file(BlockDriverState *bs, Error **errp); -void coroutine_fn bdrv_co_delete_file_noerr(BlockDriverState *bs); + +int coroutine_fn GRAPH_RDLOCK +bdrv_co_delete_file(BlockDriverState *bs, Error **errp); + +void coroutine_fn GRAPH_RDLOCK +bdrv_co_delete_file_noerr(BlockDriverState *bs); =20 =20 /* async block I/O */ diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 88d9897c97..257a9d18c6 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -649,8 +649,8 @@ struct BlockDriver { int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_flush)(BlockDriverState *b= s); =20 /* Delete a created file. */ - int coroutine_fn (*bdrv_co_delete_file)(BlockDriverState *bs, - Error **errp); + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_delete_file)( + BlockDriverState *bs, Error **errp); =20 /* * Flushes all data that was already written to the OS all the way dow= n to diff --git a/block.c b/block.c index 1060194e8f..c4c67d09d4 100644 --- a/block.c +++ b/block.c @@ -740,6 +740,7 @@ int coroutine_fn bdrv_co_delete_file(BlockDriverState *= bs, Error **errp) =20 IO_CODE(); assert(bs !=3D NULL); + assert_bdrv_graph_readable(); =20 if (!bs->drv) { error_setg(errp, "Block node '%s' is not opened", bs->filename); --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178608; cv=none; d=zohomail.com; s=zohoarc; b=k8d1rgw0RV4PFmLQDh80YoPgK+E0Uz3Um89tdzJQEjKxlEYX4ekGbz98c7WLi971YSUO8izzwSIMGxuo4cLKZb286KirYzSJxk82bkzh/azTyrDBYN2AT1TNZB57Ql/6YwPGrdANBTj0ZWCTystLAC/GMdbZHYkIx07nHWe8pc4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178608; 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=nI+mVlP2GuKEDS80xw+uJKrxQXToY80jWjpuvbDatLE=; b=aWw0KKNREE2ynkTZY8yVIBvRs2Foxsy7yhgBK0ldYs8hBIL9i2jAfK43jmsLjkqHjKk1VmKk6hxv3Xhvr/p9KoZpVxKNmW1xX/LB5K9Mm9FR9t3M3cCyRGcmD8ilToPbv0/oiwAQZ78v7VfNdzYBRwRB8Y2jVmjzgSf5ir+xIDc= 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 1677178608833809.695062164037; Thu, 23 Feb 2023 10:56:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhb-00070Z-11; Thu, 23 Feb 2023 13:52:23 -0500 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 1pVGhV-0006u5-Uz for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:17 -0500 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 1pVGhU-0003Cv-35 for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:17 -0500 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-344-DqdCHW21MbKat-2-HCpm7g-1; Thu, 23 Feb 2023 13:52:12 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E1458811E6E; Thu, 23 Feb 2023 18:52:11 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38C5E1121314; Thu, 23 Feb 2023 18:52:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178335; 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=nI+mVlP2GuKEDS80xw+uJKrxQXToY80jWjpuvbDatLE=; b=Syj+c5CVv4Ru0UcW+2rNRBsIO5ML5yIsgmERNGwlQP77F0UWip3quWWH0ovMIKWS0VnZG6 Ae64XHKkYW0od9D1zPEXSI6gBzRTIKnu23qR9RLTq7bMOKjKF7cZurhJDQQaBvxVLjVoKO 2Q8mn+huZyw+XwllwGzbZiPpdrZ51bc= X-MC-Unique: DqdCHW21MbKat-2-HCpm7g-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 22/29] block: Mark bdrv_*_dirty_bitmap() and callers GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:39 +0100 Message-Id: <20230223185146.306454-23-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178609952100002 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_*_dirty_bitmap() need to hold a reader lock for the graph. Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-23-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- include/block/block-io.h | 14 ++++++-------- include/block/block_int-common.h | 6 ++++-- include/block/dirty-bitmap.h | 12 ++++++------ block/dirty-bitmap.c | 2 ++ 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index a195a9fb11..95bcc79b75 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -243,14 +243,12 @@ AioContext *child_of_bds_get_parent_aio_context(BdrvC= hild *c); void coroutine_fn GRAPH_RDLOCK bdrv_co_io_plug(BlockDriverState *bs); void coroutine_fn GRAPH_RDLOCK bdrv_co_io_unplug(BlockDriverState *bs); =20 -bool coroutine_fn bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, - const char *name, - uint32_t granularity, - Error **errp); -bool co_wrapper bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, - const char *name, - uint32_t granularity, - Error **errp); +bool coroutine_fn GRAPH_RDLOCK +bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name, + uint32_t granularity, Error **errp); +bool co_wrapper_bdrv_rdlock +bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name, + uint32_t granularity, Error **errp); =20 /** * diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 257a9d18c6..d72e31aba3 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -759,10 +759,12 @@ struct BlockDriver { void (*bdrv_drain_end)(BlockDriverState *bs); =20 bool (*bdrv_supports_persistent_dirty_bitmap)(BlockDriverState *bs); - bool coroutine_fn (*bdrv_co_can_store_new_dirty_bitmap)( + + bool coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_can_store_new_dirty_bitma= p)( BlockDriverState *bs, const char *name, uint32_t granularity, Error **errp); - int coroutine_fn (*bdrv_co_remove_persistent_dirty_bitmap)( + + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_remove_persistent_dirty_bi= tmap)( BlockDriverState *bs, const char *name, Error **errp); }; =20 diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 233535ef2d..fa956debfb 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -36,12 +36,12 @@ int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitm= ap, uint32_t flags, void bdrv_release_dirty_bitmap(BdrvDirtyBitmap *bitmap); void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs); =20 -int coroutine_fn bdrv_co_remove_persistent_dirty_bitmap(BlockDriverState *= bs, - const char *name, - Error **errp); -int co_wrapper bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, - const char *name, - Error **errp); +int coroutine_fn GRAPH_RDLOCK +bdrv_co_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *n= ame, + Error **errp); +int co_wrapper_bdrv_rdlock +bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name, + Error **errp); =20 void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap); void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap); diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 1e7aee4010..13a1979755 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -394,6 +394,7 @@ int coroutine_fn bdrv_co_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *n= ame, Error **errp) { + assert_bdrv_graph_readable(); if (bs->drv && bs->drv->bdrv_co_remove_persistent_dirty_bitmap) { return bs->drv->bdrv_co_remove_persistent_dirty_bitmap(bs, name, e= rrp); } @@ -415,6 +416,7 @@ bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs= , const char *name, uint32_t granularity, Error **errp) { BlockDriver *drv =3D bs->drv; + assert_bdrv_graph_readable(); =20 if (!drv) { error_setg_errno(errp, ENOMEDIUM, --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178375; cv=none; d=zohomail.com; s=zohoarc; b=TXVzWURZ4kOMT58DeZD3tOrrhUS8xH8IKAZnGfzfGozT1Q4+llH3Cd3tv7DUx8+WmUV4hRwiqqjyhPRZ+Q1IIXq/m9y83SVLgDz6waERsh96cnbmN4GUxQ5NgS9xMVj698is3n+6tYXgcKdL703ZFmGLGy6secZcqxSp3etP0mk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178375; 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=nC3ovy7qtk9aruUXNIG3lMrB0IpueMp54Ynv+J0TinI=; b=mqkFQkr8RtXPoFTKXBaLR/+YoRrCBzUZcp/+eKAeekONHs6l5QCCDuMjeJbE0wjiXYdgVsWV56xeuMJmxh5wcdfYntlQmDr30OmRRv7PWQ7iKqAkq1Y0CUSpEVGmhuaegNEndox3TobGsLJDJ5y2dcl7T6pOTjbfFmaOpYRwkA0= 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 1677178375088110.40278769343536; Thu, 23 Feb 2023 10:52:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGha-00070G-Ft; Thu, 23 Feb 2023 13:52:22 -0500 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 1pVGhX-0006wO-Mu for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:19 -0500 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 1pVGhV-0003DX-MA for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:19 -0500 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-320-dAab6fNxOQey4-lKR2bznw-1; Thu, 23 Feb 2023 13:52:13 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CD473858F0E; Thu, 23 Feb 2023 18:52:12 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 242E81121314; Thu, 23 Feb 2023 18:52:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178337; 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=nC3ovy7qtk9aruUXNIG3lMrB0IpueMp54Ynv+J0TinI=; b=QfZlzUy2Yt0glwUgT0RzJxzP9RGS3W0NUb+BW9aOvbKXvBLa/74+LfRb87eIP4rxP9Y7FP MK5Z8E9b9FxMqkJAhu1f314n90xn1UqzAd53adf91+enj8sQTHSvlXUQ/2j3kA3YvzLgCo Z7iB4C//bqcMR6zg61pgGO6g6wVQyBA= X-MC-Unique: dAab6fNxOQey4-lKR2bznw-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 23/29] block: Mark bdrv_co_refresh_total_sectors() and callers GRAPH_RDLOCK Date: Thu, 23 Feb 2023 19:51:40 +0100 Message-Id: <20230223185146.306454-24-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178376711100002 Content-Type: text/plain; charset="utf-8" This adds GRAPH_RDLOCK annotations to declare that callers of bdrv_co_refresh_total_sectors() need to hold a reader lock for the graph. Signed-off-by: Kevin Wolf Message-Id: <20230203152202.49054-24-kwolf@redhat.com> Reviewed-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf --- include/block/block-io.h | 8 ++++---- include/block/block_int-common.h | 4 +++- include/block/block_int-io.h | 7 ++++--- block.c | 3 +++ block/blkdebug.c | 3 ++- block/blklogwrites.c | 3 ++- block/blkreplay.c | 3 ++- block/blkverify.c | 3 ++- block/copy-on-read.c | 2 +- block/crypto.c | 3 ++- block/filter-compress.c | 3 ++- block/mirror.c | 3 +++ block/preallocate.c | 3 ++- block/quorum.c | 3 ++- block/raw-format.c | 3 ++- block/replication.c | 3 ++- block/stream.c | 8 +++++--- block/throttle.c | 3 ++- 18 files changed, 45 insertions(+), 23 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 95bcc79b75..5da99d4d60 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -78,11 +78,11 @@ int coroutine_fn GRAPH_RDLOCK bdrv_co_truncate(BdrvChild *child, int64_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **er= rp); =20 -int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState *bs); -int64_t co_wrapper_mixed bdrv_nb_sectors(BlockDriverState *bs); +int64_t coroutine_fn GRAPH_RDLOCK bdrv_co_nb_sectors(BlockDriverState *bs); +int64_t co_wrapper_mixed_bdrv_rdlock bdrv_nb_sectors(BlockDriverState *bs); =20 -int64_t coroutine_fn bdrv_co_getlength(BlockDriverState *bs); -int64_t co_wrapper_mixed bdrv_getlength(BlockDriverState *bs); +int64_t coroutine_fn GRAPH_RDLOCK bdrv_co_getlength(BlockDriverState *bs); +int64_t co_wrapper_mixed_bdrv_rdlock bdrv_getlength(BlockDriverState *bs); =20 int64_t coroutine_fn bdrv_co_get_allocated_file_size(BlockDriverState *bs); int64_t co_wrapper bdrv_get_allocated_file_size(BlockDriverState *bs); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index d72e31aba3..d419017328 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -684,7 +684,9 @@ struct BlockDriver { BlockDriverState *bs, int64_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **errp); =20 - int64_t coroutine_fn (*bdrv_co_getlength)(BlockDriverState *bs); + int64_t coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_getlength)( + BlockDriverState *bs); + int64_t coroutine_fn (*bdrv_co_get_allocated_file_size)( BlockDriverState *bs); =20 diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 612e5ddf99..eb0da7232e 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -124,9 +124,10 @@ bdrv_co_copy_range_to(BdrvChild *src, int64_t src_offs= et, int64_t bytes, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags); =20 -int coroutine_fn bdrv_co_refresh_total_sectors(BlockDriverState *bs, - int64_t hint); -int co_wrapper_mixed +int coroutine_fn GRAPH_RDLOCK +bdrv_co_refresh_total_sectors(BlockDriverState *bs, int64_t hint); + +int co_wrapper_mixed_bdrv_rdlock bdrv_refresh_total_sectors(BlockDriverState *bs, int64_t hint); =20 BdrvChild *bdrv_cow_child(BlockDriverState *bs); diff --git a/block.c b/block.c index c4c67d09d4..0dd604d0f6 100644 --- a/block.c +++ b/block.c @@ -1042,6 +1042,7 @@ int coroutine_fn bdrv_co_refresh_total_sectors(BlockD= riverState *bs, { BlockDriver *drv =3D bs->drv; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!drv) { return -ENOMEDIUM; @@ -5843,6 +5844,7 @@ int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverSt= ate *bs) { BlockDriver *drv =3D bs->drv; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!drv) return -ENOMEDIUM; @@ -5864,6 +5866,7 @@ int64_t coroutine_fn bdrv_co_getlength(BlockDriverSta= te *bs) { int64_t ret; IO_CODE(); + assert_bdrv_graph_readable(); =20 ret =3D bdrv_co_nb_sectors(bs); if (ret < 0) { diff --git a/block/blkdebug.c b/block/blkdebug.c index f418a90873..978c8cff9e 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -967,7 +967,8 @@ static bool blkdebug_debug_is_suspended(BlockDriverStat= e *bs, const char *tag) return false; } =20 -static int64_t coroutine_fn blkdebug_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +blkdebug_co_getlength(BlockDriverState *bs) { return bdrv_co_getlength(bs->file->bs); } diff --git a/block/blklogwrites.c b/block/blklogwrites.c index 93086c31e1..3ea7141cb5 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -267,7 +267,8 @@ static void blk_log_writes_close(BlockDriverState *bs) s->log_file =3D NULL; } =20 -static int64_t coroutine_fn blk_log_writes_co_getlength(BlockDriverState *= bs) +static int64_t coroutine_fn GRAPH_RDLOCK +blk_log_writes_co_getlength(BlockDriverState *bs) { return bdrv_co_getlength(bs->file->bs); } diff --git a/block/blkreplay.c b/block/blkreplay.c index bc96bbd41e..04f53eea41 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -40,7 +40,8 @@ fail: return ret; } =20 -static int64_t coroutine_fn blkreplay_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +blkreplay_co_getlength(BlockDriverState *bs) { return bdrv_co_getlength(bs->file->bs); } diff --git a/block/blkverify.c b/block/blkverify.c index 8c11c2eae4..1c16f86b2e 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -155,7 +155,8 @@ static void blkverify_close(BlockDriverState *bs) s->test_file =3D NULL; } =20 -static int64_t coroutine_fn blkverify_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +blkverify_co_getlength(BlockDriverState *bs) { BDRVBlkverifyState *s =3D bs->opaque; =20 diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 20215cff93..cc0f848b0f 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -121,7 +121,7 @@ static void cor_child_perm(BlockDriverState *bs, BdrvCh= ild *c, } =20 =20 -static int64_t coroutine_fn cor_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK cor_co_getlength(BlockDriverState= *bs) { return bdrv_co_getlength(bs->file->bs); } diff --git a/block/crypto.c b/block/crypto.c index e77790ac8a..ca67289187 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -530,7 +530,8 @@ static void block_crypto_refresh_limits(BlockDriverStat= e *bs, Error **errp) } =20 =20 -static int64_t coroutine_fn block_crypto_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +block_crypto_co_getlength(BlockDriverState *bs) { BlockCrypto *crypto =3D bs->opaque; int64_t len =3D bdrv_co_getlength(bs->file->bs); diff --git a/block/filter-compress.c b/block/filter-compress.c index c7d50a67a7..ac285f4b66 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -55,7 +55,8 @@ static int compress_open(BlockDriverState *bs, QDict *opt= ions, int flags, } =20 =20 -static int64_t coroutine_fn compress_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +compress_co_getlength(BlockDriverState *bs) { return bdrv_co_getlength(bs->file->bs); } diff --git a/block/mirror.c b/block/mirror.c index ec5cd22a7c..97c6a5777d 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -917,7 +917,10 @@ static int coroutine_fn mirror_run(Job *job, Error **e= rrp) goto immediate_exit; } =20 + bdrv_graph_co_rdlock(); s->bdev_length =3D bdrv_co_getlength(bs); + bdrv_graph_co_rdunlock(); + if (s->bdev_length < 0) { ret =3D s->bdev_length; goto immediate_exit; diff --git a/block/preallocate.c b/block/preallocate.c index 63a296882d..71c3601809 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -443,7 +443,8 @@ static int coroutine_fn GRAPH_RDLOCK preallocate_co_flu= sh(BlockDriverState *bs) return bdrv_co_flush(bs->file->bs); } =20 -static int64_t coroutine_fn preallocate_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +preallocate_co_getlength(BlockDriverState *bs) { int64_t ret; BDRVPreallocateState *s =3D bs->opaque; diff --git a/block/quorum.c b/block/quorum.c index d58f86d3a5..ff5a0a2da3 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -764,7 +764,8 @@ quorum_co_pwrite_zeroes(BlockDriverState *bs, int64_t o= ffset, int64_t bytes, flags | BDRV_REQ_ZERO_WRITE); } =20 -static int64_t coroutine_fn quorum_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +quorum_co_getlength(BlockDriverState *bs) { BDRVQuorumState *s =3D bs->opaque; int64_t result; diff --git a/block/raw-format.c b/block/raw-format.c index f4203d4806..66783ed8e7 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -317,7 +317,8 @@ raw_co_pdiscard(BlockDriverState *bs, int64_t offset, i= nt64_t bytes) return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 -static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +raw_co_getlength(BlockDriverState *bs) { int64_t len; BDRVRawState *s =3D bs->opaque; diff --git a/block/replication.c b/block/replication.c index f9f899bfc8..de01f96184 100644 --- a/block/replication.c +++ b/block/replication.c @@ -179,7 +179,8 @@ static void replication_child_perm(BlockDriverState *bs= , BdrvChild *c, return; } =20 -static int64_t coroutine_fn replication_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +replication_co_getlength(BlockDriverState *bs) { return bdrv_co_getlength(bs->file->bs); } diff --git a/block/stream.c b/block/stream.c index 22368ce186..68018699de 100644 --- a/block/stream.c +++ b/block/stream.c @@ -141,9 +141,11 @@ static int coroutine_fn stream_run(Job *job, Error **e= rrp) return 0; } =20 - len =3D bdrv_getlength(s->target_bs); - if (len < 0) { - return len; + WITH_GRAPH_RDLOCK_GUARD() { + len =3D bdrv_co_getlength(s->target_bs); + if (len < 0) { + return len; + } } job_progress_set_remaining(&s->common.job, len); =20 diff --git a/block/throttle.c b/block/throttle.c index 5cfea3d5f8..3aaef18d4e 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -106,7 +106,8 @@ static void throttle_close(BlockDriverState *bs) } =20 =20 -static int64_t coroutine_fn throttle_co_getlength(BlockDriverState *bs) +static int64_t coroutine_fn GRAPH_RDLOCK +throttle_co_getlength(BlockDriverState *bs) { return bdrv_co_getlength(bs->file->bs); } --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178473; cv=none; d=zohomail.com; s=zohoarc; b=l/t9uMX8RZVmeWNpvEnTi1Lq/YQveYX9Kgz4FRHV07tlm/crbgXRwa7sxN135vhnWKpj/L7pt89LBDAvOYGb8c2qKp9S4TjcTywFJy3pwwvPu1Ed2++QSft+4VaNu9kapSR3InvN5sPvuvkRWJ9ib7LfPhF48KijWoFkHEFU1UI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178473; 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=eXGuWY5GcYB0GoeELyWGeMtMA4Nwy98ast6Owuep290=; b=Z/OMBcleaT2ABkVqI0PIBVGxDEwi2kmlcOVDvFya6zSFmtgWoKC5gjEuvq9HeYbIctzqzDnVvCTUyPfuXiCEV9gLGZfuM1r5P0pnlkAi2P+buAl2NfBPLRkwsJKZwuBWJnzhvc2Fp38O2uc2qvK7d48pETV8pAQq8sZEMIbsBuM= 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 1677178473519308.7863020956315; Thu, 23 Feb 2023 10:54:33 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhe-00072u-Ti; Thu, 23 Feb 2023 13:52:27 -0500 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 1pVGhV-0006u8-Vr for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:18 -0500 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 1pVGhU-0003Cl-1Z for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:17 -0500 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-353-aKp906-INCiGWj6frYF_aQ-1; Thu, 23 Feb 2023 13:52:14 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B71DA86C14B; Thu, 23 Feb 2023 18:52:13 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F1191121314; Thu, 23 Feb 2023 18:52:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178335; 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=eXGuWY5GcYB0GoeELyWGeMtMA4Nwy98ast6Owuep290=; b=JL9yM3uwaVEc01jYs1J04AbbZjr70goftx5IuNyJnYmP7tYdG+xZrKaEemSSHDaqzVg9Tf LqlDB7CtsBOFxNTbvlazZaj8Vmz9LcHZ8CAHq2eeyqh08hmSQDxPAkn0jo8QDP4JwgY+Xp 7C0XM4sGuMVTeYs1TJAP0t2GB5kbUeo= X-MC-Unique: aKp906-INCiGWj6frYF_aQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 24/29] scsi: protect req->aiocb with AioContext lock Date: Thu, 23 Feb 2023 19:51:41 +0100 Message-Id: <20230223185146.306454-25-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178475054100005 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi If requests are being processed in the IOThread when a SCSIDevice is unplugged, scsi_device_purge_requests() -> scsi_req_cancel_async() races with I/O completion callbacks. Both threads load and store req->aiocb. This can lead to assert(r->req.aiocb =3D=3D NULL) failures and undefined behavior. Protect r->req.aiocb with the AioContext lock to prevent the race. Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi Message-Id: <20230221212218.1378734-2-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- hw/scsi/scsi-disk.c | 23 ++++++++++++++++------- hw/scsi/scsi-generic.c | 11 ++++++----- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index d4e360850f..115584f8b9 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -273,9 +273,11 @@ static void scsi_aio_complete(void *opaque, int ret) SCSIDiskReq *r =3D (SCSIDiskReq *)opaque; SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); =20 + aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); + assert(r->req.aiocb !=3D NULL); r->req.aiocb =3D NULL; - aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); + if (scsi_disk_req_check_error(r, ret, true)) { goto done; } @@ -357,10 +359,11 @@ static void scsi_dma_complete(void *opaque, int ret) SCSIDiskReq *r =3D (SCSIDiskReq *)opaque; SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); =20 + aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); + assert(r->req.aiocb !=3D NULL); r->req.aiocb =3D NULL; =20 - aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); if (ret < 0) { block_acct_failed(blk_get_stats(s->qdev.conf.blk), &r->acct); } else { @@ -393,10 +396,11 @@ static void scsi_read_complete(void *opaque, int ret) SCSIDiskReq *r =3D (SCSIDiskReq *)opaque; SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); =20 + aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); + assert(r->req.aiocb !=3D NULL); r->req.aiocb =3D NULL; =20 - aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); if (ret < 0) { block_acct_failed(blk_get_stats(s->qdev.conf.blk), &r->acct); } else { @@ -446,10 +450,11 @@ static void scsi_do_read_cb(void *opaque, int ret) SCSIDiskReq *r =3D (SCSIDiskReq *)opaque; SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); =20 + aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); + assert (r->req.aiocb !=3D NULL); r->req.aiocb =3D NULL; =20 - aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); if (ret < 0) { block_acct_failed(blk_get_stats(s->qdev.conf.blk), &r->acct); } else { @@ -530,10 +535,11 @@ static void scsi_write_complete(void * opaque, int re= t) SCSIDiskReq *r =3D (SCSIDiskReq *)opaque; SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); =20 + aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); + assert (r->req.aiocb !=3D NULL); r->req.aiocb =3D NULL; =20 - aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); if (ret < 0) { block_acct_failed(blk_get_stats(s->qdev.conf.blk), &r->acct); } else { @@ -1737,10 +1743,11 @@ static void scsi_unmap_complete(void *opaque, int r= et) SCSIDiskReq *r =3D data->r; SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); =20 + aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); + assert(r->req.aiocb !=3D NULL); r->req.aiocb =3D NULL; =20 - aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); if (scsi_disk_req_check_error(r, ret, true)) { scsi_req_unref(&r->req); g_free(data); @@ -1816,9 +1823,11 @@ static void scsi_write_same_complete(void *opaque, i= nt ret) SCSIDiskReq *r =3D data->r; SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); =20 + aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); + assert(r->req.aiocb !=3D NULL); r->req.aiocb =3D NULL; - aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); + if (scsi_disk_req_check_error(r, ret, true)) { goto done; } diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c index 92cce20a4d..ac9fa662b4 100644 --- a/hw/scsi/scsi-generic.c +++ b/hw/scsi/scsi-generic.c @@ -111,10 +111,11 @@ static void scsi_command_complete(void *opaque, int r= et) SCSIGenericReq *r =3D (SCSIGenericReq *)opaque; SCSIDevice *s =3D r->req.dev; =20 + aio_context_acquire(blk_get_aio_context(s->conf.blk)); + assert(r->req.aiocb !=3D NULL); r->req.aiocb =3D NULL; =20 - aio_context_acquire(blk_get_aio_context(s->conf.blk)); scsi_command_complete_noio(r, ret); aio_context_release(blk_get_aio_context(s->conf.blk)); } @@ -269,11 +270,11 @@ static void scsi_read_complete(void * opaque, int ret) SCSIDevice *s =3D r->req.dev; int len; =20 + aio_context_acquire(blk_get_aio_context(s->conf.blk)); + assert(r->req.aiocb !=3D NULL); r->req.aiocb =3D NULL; =20 - aio_context_acquire(blk_get_aio_context(s->conf.blk)); - if (ret || r->req.io_canceled) { scsi_command_complete_noio(r, ret); goto done; @@ -386,11 +387,11 @@ static void scsi_write_complete(void * opaque, int re= t) =20 trace_scsi_generic_write_complete(ret); =20 + aio_context_acquire(blk_get_aio_context(s->conf.blk)); + assert(r->req.aiocb !=3D NULL); r->req.aiocb =3D NULL; =20 - aio_context_acquire(blk_get_aio_context(s->conf.blk)); - if (ret || r->req.io_canceled) { scsi_command_complete_noio(r, ret); goto done; --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178436; cv=none; d=zohomail.com; s=zohoarc; b=WYe7Qv0J+vANdBWikf7swRARwNpUT4Vl43i+fYxs5+doj5M4RKD7ZIzMIOSGuuN4R8D3HykebbC4fdf2I+eMPAJa6Ezc6+/T4zolsYlrb8eccRnPqsC3AzJu7YEU3nzz2AdT4rRmuC1t5lfoBhCmjgErZCj5u5ltQ08xW9Ht9Wc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178436; 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=YkCmyw0pDtYMagunRFX0qUCfWPHTOPKsHXude52+u7Y=; b=ViTzJZ4XQqvhvjhaBX9Q8C2/N8v9gIoAu4n3cP6Ey1VlZf0Qrm73Ih1GB/3t4qjXb9TkpHrmMlEzAtBZ0Swagjk4kOqkT0IlZT09wjJsyA2RMr68Vl14mKoq8ZzgD1eDdEeNFl5FWjYoyNKXv2U/YsM1bdguZen0/f5xV1JMDqc= 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 1677178436396707.6699561556925; Thu, 23 Feb 2023 10:53:56 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhi-00076G-Tk; Thu, 23 Feb 2023 13:52:30 -0500 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 1pVGhZ-0006zB-7C for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:21 -0500 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 1pVGhW-0003EV-PH for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:20 -0500 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-490-OKjnTxW0MASuz0JzWcTuQA-1; Thu, 23 Feb 2023 13:52:15 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A27171816EC0; Thu, 23 Feb 2023 18:52:14 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id ECB691121314; Thu, 23 Feb 2023 18:52:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178338; 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=YkCmyw0pDtYMagunRFX0qUCfWPHTOPKsHXude52+u7Y=; b=h3U5+713w8BcEq+eTawwYCeX3qdqxT5Gg6SROM39ZRO6/Pvwx2xxKbQkWN8y7k8uHMvPT3 QIal2CucwaFmNbVmPna+WMKefA+JgYRYs3LylljrYl62yCeaUgp7lK8QdIZFsNy8VmpG7l jXCTydBLkDiQN/jBzTcZbfq+CPaafkk= X-MC-Unique: OKjnTxW0MASuz0JzWcTuQA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 25/29] dma-helpers: prevent dma_blk_cb() vs dma_aio_cancel() race Date: Thu, 23 Feb 2023 19:51:42 +0100 Message-Id: <20230223185146.306454-26-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178436818100001 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi dma_blk_cb() only takes the AioContext lock around ->io_func(). That means the rest of dma_blk_cb() is not protected. In particular, the DMAAIOCB field accesses happen outside the lock. There is a race when the main loop thread holds the AioContext lock and invokes scsi_device_purge_requests() -> bdrv_aio_cancel() -> dma_aio_cancel() while an IOThread executes dma_blk_cb(). The dbs->acb field determines how cancellation proceeds. If dma_aio_cancel() sees dbs->acb =3D=3D NULL while dma_blk_cb() is still running, the request can be completed twice (-ECANCELED and the actual return value). The following assertion can occur with virtio-scsi when an IOThread is used: ../hw/scsi/scsi-disk.c:368: scsi_dma_complete: Assertion `r->req.aiocb != =3D NULL' failed. Fix the race by holding the AioContext across dma_blk_cb(). Now dma_aio_cancel() under the AioContext lock will not see inconsistent/intermediate states. Cc: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Stefan Hajnoczi Message-Id: <20230221212218.1378734-3-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- hw/scsi/scsi-disk.c | 4 +--- softmmu/dma-helpers.c | 12 +++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index 115584f8b9..97c9b1c8cd 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -354,13 +354,12 @@ done: scsi_req_unref(&r->req); } =20 +/* Called with AioContext lock held */ static void scsi_dma_complete(void *opaque, int ret) { SCSIDiskReq *r =3D (SCSIDiskReq *)opaque; SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev, r->req.dev); =20 - aio_context_acquire(blk_get_aio_context(s->qdev.conf.blk)); - assert(r->req.aiocb !=3D NULL); r->req.aiocb =3D NULL; =20 @@ -370,7 +369,6 @@ static void scsi_dma_complete(void *opaque, int ret) block_acct_done(blk_get_stats(s->qdev.conf.blk), &r->acct); } scsi_dma_complete_noio(r, ret); - aio_context_release(blk_get_aio_context(s->qdev.conf.blk)); } =20 static void scsi_read_complete_noio(SCSIDiskReq *r, int ret) diff --git a/softmmu/dma-helpers.c b/softmmu/dma-helpers.c index 7820fec54c..2463964805 100644 --- a/softmmu/dma-helpers.c +++ b/softmmu/dma-helpers.c @@ -113,17 +113,19 @@ static void dma_complete(DMAAIOCB *dbs, int ret) static void dma_blk_cb(void *opaque, int ret) { DMAAIOCB *dbs =3D (DMAAIOCB *)opaque; + AioContext *ctx =3D dbs->ctx; dma_addr_t cur_addr, cur_len; void *mem; =20 trace_dma_blk_cb(dbs, ret); =20 + aio_context_acquire(ctx); dbs->acb =3D NULL; dbs->offset +=3D dbs->iov.size; =20 if (dbs->sg_cur_index =3D=3D dbs->sg->nsg || ret < 0) { dma_complete(dbs, ret); - return; + goto out; } dma_blk_unmap(dbs); =20 @@ -164,9 +166,9 @@ static void dma_blk_cb(void *opaque, int ret) =20 if (dbs->iov.size =3D=3D 0) { trace_dma_map_wait(dbs); - dbs->bh =3D aio_bh_new(dbs->ctx, reschedule_dma, dbs); + dbs->bh =3D aio_bh_new(ctx, reschedule_dma, dbs); cpu_register_map_client(dbs->bh); - return; + goto out; } =20 if (!QEMU_IS_ALIGNED(dbs->iov.size, dbs->align)) { @@ -174,11 +176,11 @@ static void dma_blk_cb(void *opaque, int ret) QEMU_ALIGN_DOWN(dbs->iov.size, dbs->align)= ); } =20 - aio_context_acquire(dbs->ctx); dbs->acb =3D dbs->io_func(dbs->offset, &dbs->iov, dma_blk_cb, dbs, dbs->io_func_opaque); - aio_context_release(dbs->ctx); assert(dbs->acb); +out: + aio_context_release(ctx); } =20 static void dma_aio_cancel(BlockAIOCB *acb) --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178518; cv=none; d=zohomail.com; s=zohoarc; b=eetIGBzmvaSMzGhoipIwSd8KExIWQCHFnPOrz80pIFRbktO1etA9/qqw0V0eAUz288CHZuyhMcLRtu+3j55e+HeldzwZmxfsukTA+AsdYOK8nUj3QHRjlJpChuPtMQUfqX2Zc4RKlpdD7DVtxT48ZvyIMHUpdHGFn3CULdwTNpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178518; 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=65Pep8dtLnKno2lzMQjyAsdAOSdRGEztNGHVCs4boR4=; b=cshO6Yj/d5pPMH8SVb6YgA+bUhGKaRKFkc+GZZIkcmWFjGKIWf1IPX3euXQ2byvIA1LdBrpjlaFJ7QPW82IkNWSBT9p3r40M6lwfQ0G/svLislrxxnUCT1BfjpyfTqQTpN+bjwKRuRembA+lV6OIHLgNZMMYDud6/ZQtWOYdBOs= 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 1677178518058553.1220133382961; Thu, 23 Feb 2023 10:55:18 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGi2-0007Fn-JK; Thu, 23 Feb 2023 13:52:50 -0500 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 1pVGhc-00071n-JH for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:24 -0500 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 1pVGhZ-0003Fn-UI for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:24 -0500 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-542-8yPPTH63Mg2QqMjrqYCX3A-1; Thu, 23 Feb 2023 13:52:15 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8AE18857A89; Thu, 23 Feb 2023 18:52:15 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id D65F11121314; Thu, 23 Feb 2023 18:52:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178341; 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=65Pep8dtLnKno2lzMQjyAsdAOSdRGEztNGHVCs4boR4=; b=ZsskvK3LMq+3npIzIVnUjV+PM5MFObXckjxs8Qj44/fbdar7YeAxsZGlbPDLR0qKuHpKrb 9M1zwGo2lGxfsvXRT0kiqfGQijbCdtAJ9xQseXMSMzn77MwgPbt+7HOohbzN9rHO4s7AHg nS8nSktTxSp3Gy59PyeeoRkapQl5FZU= X-MC-Unique: 8yPPTH63Mg2QqMjrqYCX3A-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 26/29] virtio-scsi: reset SCSI devices from main loop thread Date: Thu, 23 Feb 2023 19:51:43 +0100 Message-Id: <20230223185146.306454-27-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178519446100002 Content-Type: text/plain; charset="utf-8" From: Stefan Hajnoczi When an IOThread is configured, the ctrl virtqueue is processed in the IOThread. TMFs that reset SCSI devices are currently called directly from the IOThread and trigger an assertion failure in blk_drain() from the following call stack: virtio_scsi_handle_ctrl_req -> virtio_scsi_do_tmf -> device_code_reset -> scsi_disk_reset -> scsi_device_purge_requests -> blk_drain ../block/block-backend.c:1780: void blk_drain(BlockBackend *): Assertion = `qemu_in_main_thread()' failed. The blk_drain() function is not designed to be called from an IOThread because it needs the Big QEMU Lock (BQL). This patch defers TMFs that reset SCSI devices to a Bottom Half (BH) that runs in the main loop thread under the BQL. This way it's safe to call blk_drain() and the assertion failure is avoided. Introduce s->tmf_bh_list for tracking TMF requests that have been deferred to the BH. When the BH runs it will grab the entire list and process all requests. Care must be taken to clear the list when the virtio-scsi device is reset or unrealized. Otherwise deferred TMF requests could execute later and lead to use-after-free or other undefined behavior. The s->resetting counter that's used by TMFs that reset SCSI devices is accessed from multiple threads. This patch makes that explicit by using atomic accessor functions. With this patch applied the counter is only modified by the main loop thread under the BQL but can be read by any thread. Reported-by: Qing Wang Cc: Paolo Bonzini Reviewed-by: Eric Blake Signed-off-by: Stefan Hajnoczi Message-Id: <20230221212218.1378734-4-stefanha@redhat.com> Signed-off-by: Kevin Wolf --- include/hw/virtio/virtio-scsi.h | 11 ++- hw/scsi/virtio-scsi.c | 169 +++++++++++++++++++++++++------- 2 files changed, 143 insertions(+), 37 deletions(-) diff --git a/include/hw/virtio/virtio-scsi.h b/include/hw/virtio/virtio-scs= i.h index 37b75e15e3..779568ab5d 100644 --- a/include/hw/virtio/virtio-scsi.h +++ b/include/hw/virtio/virtio-scsi.h @@ -74,13 +74,22 @@ struct VirtIOSCSICommon { VirtQueue **cmd_vqs; }; =20 +struct VirtIOSCSIReq; + struct VirtIOSCSI { VirtIOSCSICommon parent_obj; =20 SCSIBus bus; - int resetting; + int resetting; /* written from main loop thread, read from any thread = */ bool events_dropped; =20 + /* + * TMFs deferred to main loop BH. These fields are protected by + * virtio_scsi_acquire(). + */ + QEMUBH *tmf_bh; + QTAILQ_HEAD(, VirtIOSCSIReq) tmf_bh_list; + /* Fields for dataplane below */ AioContext *ctx; /* one iothread per virtio-scsi-pci for now */ =20 diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index 2b649ca976..612c525d9d 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -43,13 +43,11 @@ typedef struct VirtIOSCSIReq { QEMUSGList qsgl; QEMUIOVector resp_iov; =20 - union { - /* Used for two-stage request submission */ - QTAILQ_ENTRY(VirtIOSCSIReq) next; + /* Used for two-stage request submission and TMFs deferred to BH */ + QTAILQ_ENTRY(VirtIOSCSIReq) next; =20 - /* Used for cancellation of request during TMFs */ - int remaining; - }; + /* Used for cancellation of request during TMFs */ + int remaining; =20 SCSIRequest *sreq; size_t resp_size; @@ -294,6 +292,122 @@ static inline void virtio_scsi_ctx_check(VirtIOSCSI *= s, SCSIDevice *d) } } =20 +static void virtio_scsi_do_one_tmf_bh(VirtIOSCSIReq *req) +{ + VirtIOSCSI *s =3D req->dev; + SCSIDevice *d =3D virtio_scsi_device_get(s, req->req.tmf.lun); + BusChild *kid; + int target; + + switch (req->req.tmf.subtype) { + case VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET: + if (!d) { + req->resp.tmf.response =3D VIRTIO_SCSI_S_BAD_TARGET; + goto out; + } + if (d->lun !=3D virtio_scsi_get_lun(req->req.tmf.lun)) { + req->resp.tmf.response =3D VIRTIO_SCSI_S_INCORRECT_LUN; + goto out; + } + qatomic_inc(&s->resetting); + device_cold_reset(&d->qdev); + qatomic_dec(&s->resetting); + break; + + case VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET: + target =3D req->req.tmf.lun[1]; + qatomic_inc(&s->resetting); + + rcu_read_lock(); + QTAILQ_FOREACH_RCU(kid, &s->bus.qbus.children, sibling) { + SCSIDevice *d1 =3D SCSI_DEVICE(kid->child); + if (d1->channel =3D=3D 0 && d1->id =3D=3D target) { + device_cold_reset(&d1->qdev); + } + } + rcu_read_unlock(); + + qatomic_dec(&s->resetting); + break; + + default: + g_assert_not_reached(); + break; + } + +out: + object_unref(OBJECT(d)); + + virtio_scsi_acquire(s); + virtio_scsi_complete_req(req); + virtio_scsi_release(s); +} + +/* Some TMFs must be processed from the main loop thread */ +static void virtio_scsi_do_tmf_bh(void *opaque) +{ + VirtIOSCSI *s =3D opaque; + QTAILQ_HEAD(, VirtIOSCSIReq) reqs =3D QTAILQ_HEAD_INITIALIZER(reqs); + VirtIOSCSIReq *req; + VirtIOSCSIReq *tmp; + + GLOBAL_STATE_CODE(); + + virtio_scsi_acquire(s); + + QTAILQ_FOREACH_SAFE(req, &s->tmf_bh_list, next, tmp) { + QTAILQ_REMOVE(&s->tmf_bh_list, req, next); + QTAILQ_INSERT_TAIL(&reqs, req, next); + } + + qemu_bh_delete(s->tmf_bh); + s->tmf_bh =3D NULL; + + virtio_scsi_release(s); + + QTAILQ_FOREACH_SAFE(req, &reqs, next, tmp) { + QTAILQ_REMOVE(&reqs, req, next); + virtio_scsi_do_one_tmf_bh(req); + } +} + +static void virtio_scsi_reset_tmf_bh(VirtIOSCSI *s) +{ + VirtIOSCSIReq *req; + VirtIOSCSIReq *tmp; + + GLOBAL_STATE_CODE(); + + virtio_scsi_acquire(s); + + if (s->tmf_bh) { + qemu_bh_delete(s->tmf_bh); + s->tmf_bh =3D NULL; + } + + QTAILQ_FOREACH_SAFE(req, &s->tmf_bh_list, next, tmp) { + QTAILQ_REMOVE(&s->tmf_bh_list, req, next); + + /* SAM-6 6.3.2 Hard reset */ + req->resp.tmf.response =3D VIRTIO_SCSI_S_TARGET_FAILURE; + virtio_scsi_complete_req(req); + } + + virtio_scsi_release(s); +} + +static void virtio_scsi_defer_tmf_to_bh(VirtIOSCSIReq *req) +{ + VirtIOSCSI *s =3D req->dev; + + QTAILQ_INSERT_TAIL(&s->tmf_bh_list, req, next); + + if (!s->tmf_bh) { + s->tmf_bh =3D qemu_bh_new(virtio_scsi_do_tmf_bh, s); + qemu_bh_schedule(s->tmf_bh); + } +} + /* Return 0 if the request is ready to be completed and return to guest; * -EINPROGRESS if the request is submitted and will be completed later, i= n the * case of async cancellation. */ @@ -301,8 +415,6 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCSI= Req *req) { SCSIDevice *d =3D virtio_scsi_device_get(s, req->req.tmf.lun); SCSIRequest *r, *next; - BusChild *kid; - int target; int ret =3D 0; =20 virtio_scsi_ctx_check(s, d); @@ -359,15 +471,9 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCS= IReq *req) break; =20 case VIRTIO_SCSI_T_TMF_LOGICAL_UNIT_RESET: - if (!d) { - goto fail; - } - if (d->lun !=3D virtio_scsi_get_lun(req->req.tmf.lun)) { - goto incorrect_lun; - } - s->resetting++; - device_cold_reset(&d->qdev); - s->resetting--; + case VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET: + virtio_scsi_defer_tmf_to_bh(req); + ret =3D -EINPROGRESS; break; =20 case VIRTIO_SCSI_T_TMF_ABORT_TASK_SET: @@ -410,22 +516,6 @@ static int virtio_scsi_do_tmf(VirtIOSCSI *s, VirtIOSCS= IReq *req) } break; =20 - case VIRTIO_SCSI_T_TMF_I_T_NEXUS_RESET: - target =3D req->req.tmf.lun[1]; - s->resetting++; - - rcu_read_lock(); - QTAILQ_FOREACH_RCU(kid, &s->bus.qbus.children, sibling) { - SCSIDevice *d1 =3D SCSI_DEVICE(kid->child); - if (d1->channel =3D=3D 0 && d1->id =3D=3D target) { - device_cold_reset(&d1->qdev); - } - } - rcu_read_unlock(); - - s->resetting--; - break; - case VIRTIO_SCSI_T_TMF_CLEAR_ACA: default: req->resp.tmf.response =3D VIRTIO_SCSI_S_FUNCTION_REJECTED; @@ -655,7 +745,7 @@ static void virtio_scsi_request_cancelled(SCSIRequest *= r) if (!req) { return; } - if (req->dev->resetting) { + if (qatomic_read(&req->dev->resetting)) { req->resp.cmd.response =3D VIRTIO_SCSI_S_RESET; } else { req->resp.cmd.response =3D VIRTIO_SCSI_S_ABORTED; @@ -831,9 +921,12 @@ static void virtio_scsi_reset(VirtIODevice *vdev) VirtIOSCSICommon *vs =3D VIRTIO_SCSI_COMMON(vdev); =20 assert(!s->dataplane_started); - s->resetting++; + + virtio_scsi_reset_tmf_bh(s); + + qatomic_inc(&s->resetting); bus_cold_reset(BUS(&s->bus)); - s->resetting--; + qatomic_dec(&s->resetting); =20 vs->sense_size =3D VIRTIO_SCSI_SENSE_DEFAULT_SIZE; vs->cdb_size =3D VIRTIO_SCSI_CDB_DEFAULT_SIZE; @@ -1053,6 +1146,8 @@ static void virtio_scsi_device_realize(DeviceState *d= ev, Error **errp) VirtIOSCSI *s =3D VIRTIO_SCSI(dev); Error *err =3D NULL; =20 + QTAILQ_INIT(&s->tmf_bh_list); + virtio_scsi_common_realize(dev, virtio_scsi_handle_ctrl, virtio_scsi_handle_event, @@ -1090,6 +1185,8 @@ static void virtio_scsi_device_unrealize(DeviceState = *dev) { VirtIOSCSI *s =3D VIRTIO_SCSI(dev); =20 + virtio_scsi_reset_tmf_bh(s); + qbus_set_hotplug_handler(BUS(&s->bus), NULL); virtio_scsi_common_unrealize(dev); } --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178472; cv=none; d=zohomail.com; s=zohoarc; b=IgL8RPp1Ny/Ikp1Gpktg0lKNPE8oFBLeyjykqnh0pIsfSuzNEKiuAKcoDgEVsDTD5/QDLizYM23chH4eDxlRV3a8Mqip5UQ96qXSxzwsVixmdnF3jMpcZJUxCVMyAgz1waZBSTBSWODtjQhvui89Nq1K/OLaHyzPAdkR9uMQ+yU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178472; 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=oUB96iEf8D3+hhXsE8FlQ2IWhxJiAJqsEBpFmNj3UWk=; b=G4Hd4UUns17ytb17jthLn2jisCfzO1ufOTMoGTdemPk7vjfWR81UiHQ+cu3hvvt0w5tnST6wp+aNJwgMgEgY3nVjDCFpB8UyDneRwi68bDABsjzZlftv/6fTAFV5lykqalM+Ri5kmCjOYnUZpzDcBOACRWV5d+NHkaqAr1i7Tic= 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 1677178472774398.2063431061599; Thu, 23 Feb 2023 10:54:32 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhp-00078W-Uv; Thu, 23 Feb 2023 13:52:38 -0500 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 1pVGhY-0006yy-Vi for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:20 -0500 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 1pVGhW-0003ER-LA for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:20 -0500 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-14-UvlSCbezM1a4BjnqlEPB7A-1; Thu, 23 Feb 2023 13:52:16 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 74738800050; Thu, 23 Feb 2023 18:52:16 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF3981121314; Thu, 23 Feb 2023 18:52:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178338; 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=oUB96iEf8D3+hhXsE8FlQ2IWhxJiAJqsEBpFmNj3UWk=; b=bQJiLEy+t71ZGYFmjsHlywPPia5bw8eVxI3m+BLy5fjCZ9s2UvRZ4PdyxeOUGM+bNum54j aRtIFjQSTkJLjaFOv0VbiTmbVe7yQy9KTATdl/V95vw0oQqlK+wnrai+iiBB9vjqAIldVi pV/8tk7acN0LRx0OsN0Z+F2qkzcN3Os= X-MC-Unique: UvlSCbezM1a4BjnqlEPB7A-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 27/29] block/rbd: Remove redundant stack variable passphrase_len Date: Thu, 23 Feb 2023 19:51:44 +0100 Message-Id: <20230223185146.306454-28-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178473073100001 Content-Type: text/plain; charset="utf-8" From: Or Ozeri Signed-off-by: Or Ozeri Message-Id: <20230129113120.722708-2-oro@oro.sl.cloud9.ibm.com> Reviewed-by: Ilya Dryomov Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- block/rbd.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/block/rbd.c b/block/rbd.c index 5e102fea0d..4bd75c9bb7 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -386,7 +386,6 @@ static int qemu_rbd_encryption_format(rbd_image_t image, { int r =3D 0; g_autofree char *passphrase =3D NULL; - size_t passphrase_len; rbd_encryption_format_t format; rbd_encryption_options_t opts; rbd_encryption_luks1_format_options_t luks_opts; @@ -408,12 +407,12 @@ static int qemu_rbd_encryption_format(rbd_image_t ima= ge, opts_size =3D sizeof(luks_opts); r =3D qemu_rbd_convert_luks_create_options( qapi_RbdEncryptionCreateOptionsLUKS_base(&encrypt->u.l= uks), - &luks_opts.alg, &passphrase, &passphrase_len, errp); + &luks_opts.alg, &passphrase, &luks_opts.passphrase_siz= e, + errp); if (r < 0) { return r; } luks_opts.passphrase =3D passphrase; - luks_opts.passphrase_size =3D passphrase_len; break; } case RBD_IMAGE_ENCRYPTION_FORMAT_LUKS2: { @@ -424,12 +423,12 @@ static int qemu_rbd_encryption_format(rbd_image_t ima= ge, r =3D qemu_rbd_convert_luks_create_options( qapi_RbdEncryptionCreateOptionsLUKS2_base( &encrypt->u.luks2), - &luks2_opts.alg, &passphrase, &passphrase_len, errp); + &luks2_opts.alg, &passphrase, &luks2_opts.passphrase_s= ize, + errp); if (r < 0) { return r; } luks2_opts.passphrase =3D passphrase; - luks2_opts.passphrase_size =3D passphrase_len; break; } default: { @@ -468,7 +467,6 @@ static int qemu_rbd_encryption_load(rbd_image_t image, { int r =3D 0; g_autofree char *passphrase =3D NULL; - size_t passphrase_len; rbd_encryption_luks1_format_options_t luks_opts; rbd_encryption_luks2_format_options_t luks2_opts; rbd_encryption_format_t format; @@ -483,12 +481,11 @@ static int qemu_rbd_encryption_load(rbd_image_t image, opts_size =3D sizeof(luks_opts); r =3D qemu_rbd_convert_luks_options( qapi_RbdEncryptionOptionsLUKS_base(&encrypt->u.luks), - &passphrase, &passphrase_len, errp); + &passphrase, &luks_opts.passphrase_size, errp); if (r < 0) { return r; } luks_opts.passphrase =3D passphrase; - luks_opts.passphrase_size =3D passphrase_len; break; } case RBD_IMAGE_ENCRYPTION_FORMAT_LUKS2: { @@ -498,12 +495,11 @@ static int qemu_rbd_encryption_load(rbd_image_t image, opts_size =3D sizeof(luks2_opts); r =3D qemu_rbd_convert_luks_options( qapi_RbdEncryptionOptionsLUKS2_base(&encrypt->u.luks2), - &passphrase, &passphrase_len, errp); + &passphrase, &luks2_opts.passphrase_size, errp); if (r < 0) { return r; } luks2_opts.passphrase =3D passphrase; - luks2_opts.passphrase_size =3D passphrase_len; break; } default: { --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178459; cv=none; d=zohomail.com; s=zohoarc; b=U7UyAbFl9LyzFnsTg4NCULyZ75zDSflATsq7GaOOPYfHq3TkjYRFiNxLukHfgUtBDSjt7j6Z0Tb4x56rZScjvJSeBEwKl1QYEXmcBD6L8WRHlfeiPcJiYo41XCZYEnHz7P36jx1hHA6VsaoM+FPgdhOnqRW23a5Eh2Mfz643JVE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178459; 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=gyPnP6uoUuSZ+QQsWtJUfaOBuq8JS2ltvmKgcVci0/8=; b=Nq94I0am5wdQUY9N8Fh+nu1gFAS07Npv3pscVLcchpdtJkyy1qIsV6DuUUUXgd/Snb1W/QWL3rFmNllL6ndhMv74S8737HcfLtH8mfxwkoVUjMs0kmAGxOq9bak8XJfRrddDq59sVj35tal3qhczBgLeQOnrgYb+t+8TQXdNQnI= 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 1677178459372679.4244646078164; Thu, 23 Feb 2023 10:54:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGhk-000779-G9; Thu, 23 Feb 2023 13:52:32 -0500 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 1pVGhb-00070y-C6 for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:23 -0500 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 1pVGhZ-0003Fd-Ix for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:22 -0500 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-529-GPJmaVM5O0qvMfXilh-eTA-1; Thu, 23 Feb 2023 13:52:17 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 60AF3802D2A; Thu, 23 Feb 2023 18:52:17 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD2971121314; Thu, 23 Feb 2023 18:52:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178341; 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=gyPnP6uoUuSZ+QQsWtJUfaOBuq8JS2ltvmKgcVci0/8=; b=cDmB36tr/UbEzi57nY7gNdTmx9la8MlSym7jfyJQsBtXmVcl+C9m13zGB6DlSRCQMDyNgc QmTn5pOtUL5iur/LRHZL1DoJSlYCaDvRg2frP7unN8BSWhK7SQO8tU5GJhzXLvWOLxXEH3 mMZxGkqliy1mxw/wrCsXG9A1e4X+XEc= X-MC-Unique: GPJmaVM5O0qvMfXilh-eTA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 28/29] block/rbd: Add luks-any encryption opening option Date: Thu, 23 Feb 2023 19:51:45 +0100 Message-Id: <20230223185146.306454-29-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178461054100002 Content-Type: text/plain; charset="utf-8" From: Or Ozeri Ceph RBD encryption API required specifying the encryption format for loading encryption. The supported formats were LUKS (v1) and LUKS2. Starting from Reef release, RBD also supports loading with "luks-any" forma= t, which works for both versions of LUKS. This commit extends the qemu rbd driver API to enable qemu users to use this luks-any wildcard format. Signed-off-by: Or Ozeri Message-Id: <20230129113120.722708-3-oro@oro.sl.cloud9.ibm.com> Reviewed-by: Ilya Dryomov Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qapi/block-core.json | 16 ++++++++++++++-- block/rbd.c | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 7f331eb8ea..5f09b1d31a 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3922,10 +3922,12 @@ ## # @RbdImageEncryptionFormat: # +# @luks-any: Used for opening either luks or luks2 (Since 8.0) +# # Since: 6.1 ## { 'enum': 'RbdImageEncryptionFormat', - 'data': [ 'luks', 'luks2' ] } + 'data': [ 'luks', 'luks2', 'luks-any' ] } =20 ## # @RbdEncryptionOptionsLUKSBase: @@ -3967,6 +3969,15 @@ 'base': 'RbdEncryptionOptionsLUKSBase', 'data': { } } =20 +## +# @RbdEncryptionOptionsLUKSAny: +# +# Since: 8.0 +## +{ 'struct': 'RbdEncryptionOptionsLUKSAny', + 'base': 'RbdEncryptionOptionsLUKSBase', + 'data': { } } + ## # @RbdEncryptionCreateOptionsLUKS: # @@ -3994,7 +4005,8 @@ 'base': { 'format': 'RbdImageEncryptionFormat' }, 'discriminator': 'format', 'data': { 'luks': 'RbdEncryptionOptionsLUKS', - 'luks2': 'RbdEncryptionOptionsLUKS2' } } + 'luks2': 'RbdEncryptionOptionsLUKS2', + 'luks-any': 'RbdEncryptionOptionsLUKSAny'} } =20 ## # @RbdEncryptionCreateOptions: diff --git a/block/rbd.c b/block/rbd.c index 4bd75c9bb7..744f84c222 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -469,6 +469,9 @@ static int qemu_rbd_encryption_load(rbd_image_t image, g_autofree char *passphrase =3D NULL; rbd_encryption_luks1_format_options_t luks_opts; rbd_encryption_luks2_format_options_t luks2_opts; +#ifdef LIBRBD_SUPPORTS_ENCRYPTION_LOAD2 + rbd_encryption_luks_format_options_t luks_any_opts; +#endif rbd_encryption_format_t format; rbd_encryption_options_t opts; size_t opts_size; @@ -502,6 +505,22 @@ static int qemu_rbd_encryption_load(rbd_image_t image, luks2_opts.passphrase =3D passphrase; break; } +#ifdef LIBRBD_SUPPORTS_ENCRYPTION_LOAD2 + case RBD_IMAGE_ENCRYPTION_FORMAT_LUKS_ANY: { + memset(&luks_any_opts, 0, sizeof(luks_any_opts)); + format =3D RBD_ENCRYPTION_FORMAT_LUKS; + opts =3D &luks_any_opts; + opts_size =3D sizeof(luks_any_opts); + r =3D qemu_rbd_convert_luks_options( + qapi_RbdEncryptionOptionsLUKSAny_base(&encrypt->u.luks= _any), + &passphrase, &luks_any_opts.passphrase_size, errp); + if (r < 0) { + return r; + } + luks_any_opts.passphrase =3D passphrase; + break; + } +#endif default: { r =3D -ENOTSUP; error_setg_errno( --=20 2.39.2 From nobody Mon May 13 23:33:56 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=1677178513; cv=none; d=zohomail.com; s=zohoarc; b=U0DsjfLJxJp45w3+wIEAdgTJZNg9LVN8A8iMuSylOEtjxA0YlDb6WmjK08vQsxSbxFN02kRRf+yvAMIDZ20krE5KMiCdWseftRHq+ZF009Gw6DZ6dIR/bKIjK/a30h8Z6eIx/AJlRorH1G4nizI+dbyqxZ0jP4rMlxq7I1wPscg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1677178513; 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=u021ZoNvpw0FUMmDOwHQFXjd7nE1mAh/K7or6T7sIbI=; b=hEYzGcu4RoLepQiUdn5af1Hi0yATjFT2M0ZNVEhWxKcevn76T+nFGN/FBRrh37gV9ubCjfid3bNqmWDpPH6KQXQFx36C7uLY4KdiC4NOpz96Q48Iq5i0EXthpDCw0fLGTQZ+YdTaZIXdALoY+pUOJ6sNH7vPmq/0A25P/y6DJhQ= 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 1677178513659470.9306216877495; Thu, 23 Feb 2023 10:55:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pVGiE-0007V4-Rc; Thu, 23 Feb 2023 13:53:02 -0500 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 1pVGhd-00072P-09 for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:26 -0500 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 1pVGhb-0003G7-67 for qemu-devel@nongnu.org; Thu, 23 Feb 2023 13:52:24 -0500 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-511-OpJTCKEPPfG5rGuidGWClg-1; Thu, 23 Feb 2023 13:52:18 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4B1011816EC1; Thu, 23 Feb 2023 18:52:18 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.192.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id 966621121314; Thu, 23 Feb 2023 18:52:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677178342; 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=u021ZoNvpw0FUMmDOwHQFXjd7nE1mAh/K7or6T7sIbI=; b=QNQN+8mzBnhXK9B5YwoGTCa+fzNFjvEyV/Urg2fq4n1oXzaU+hQND8A4cdubhZWoXP8gWP wJajNnLUtKqoPStI1O7lfmLqPB9Df2yt04nhuTjymMgd0MiEF4Q31SONZ35kboiYgMUv3z mKaWssu9EQCI+iiOz0+1ge1vFTF2f5Q= X-MC-Unique: OpJTCKEPPfG5rGuidGWClg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Subject: [PULL 29/29] block/rbd: Add support for layered encryption Date: Thu, 23 Feb 2023 19:51:46 +0100 Message-Id: <20230223185146.306454-30-kwolf@redhat.com> In-Reply-To: <20230223185146.306454-1-kwolf@redhat.com> References: <20230223185146.306454-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1677178515448100002 Content-Type: text/plain; charset="utf-8" From: Or Ozeri Starting from ceph Reef, RBD has built-in support for layered encryption, where each ancestor image (in a cloned image setting) can be possibly encrypted using a unique passphrase. A new function, rbd_encryption_load2, was added to librbd API. This new function supports an array of passphrases (via "spec" structs). This commit extends the qemu rbd driver API to use this new librbd API, in order to support this new layered encryption feature. Signed-off-by: Or Ozeri Message-Id: <20230129113120.722708-4-oro@oro.sl.cloud9.ibm.com> Reviewed-by: Ilya Dryomov Reviewed-by: Kevin Wolf Signed-off-by: Kevin Wolf --- qapi/block-core.json | 11 +++- block/rbd.c | 153 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 162 insertions(+), 2 deletions(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 5f09b1d31a..c05ad0c07e 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -3999,10 +3999,19 @@ ## # @RbdEncryptionOptions: # +# @format: Encryption format. +# +# @parent: Parent image encryption options (for cloned images). +# Can be left unspecified if this cloned image is encrypted +# using the same format and secret as its parent image (i.e. +# not explicitly formatted) or if its parent image is not +# encrypted. (Since 8.0) +# # Since: 6.1 ## { 'union': 'RbdEncryptionOptions', - 'base': { 'format': 'RbdImageEncryptionFormat' }, + 'base': { 'format': 'RbdImageEncryptionFormat', + '*parent': 'RbdEncryptionOptions' }, 'discriminator': 'format', 'data': { 'luks': 'RbdEncryptionOptionsLUKS', 'luks2': 'RbdEncryptionOptionsLUKS2', diff --git a/block/rbd.c b/block/rbd.c index 744f84c222..978671411e 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -72,6 +72,16 @@ static const char rbd_luks2_header_verification[ 'L', 'U', 'K', 'S', 0xBA, 0xBE, 0, 2 }; =20 +static const char rbd_layered_luks_header_verification[ + RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN] =3D { + 'R', 'B', 'D', 'L', 0xBA, 0xBE, 0, 1 +}; + +static const char rbd_layered_luks2_header_verification[ + RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN] =3D { + 'R', 'B', 'D', 'L', 0xBA, 0xBE, 0, 2 +}; + typedef enum { RBD_AIO_READ, RBD_AIO_WRITE, @@ -538,6 +548,128 @@ static int qemu_rbd_encryption_load(rbd_image_t image, =20 return 0; } + +#ifdef LIBRBD_SUPPORTS_ENCRYPTION_LOAD2 +static int qemu_rbd_encryption_load2(rbd_image_t image, + RbdEncryptionOptions *encrypt, + Error **errp) +{ + int r =3D 0; + int encrypt_count =3D 1; + int i; + RbdEncryptionOptions *curr_encrypt; + rbd_encryption_spec_t *specs; + rbd_encryption_luks1_format_options_t *luks_opts; + rbd_encryption_luks2_format_options_t *luks2_opts; + rbd_encryption_luks_format_options_t *luks_any_opts; + + /* count encryption options */ + for (curr_encrypt =3D encrypt->parent; curr_encrypt; + curr_encrypt =3D curr_encrypt->parent) { + ++encrypt_count; + } + + specs =3D g_new0(rbd_encryption_spec_t, encrypt_count); + + curr_encrypt =3D encrypt; + for (i =3D 0; i < encrypt_count; ++i) { + switch (curr_encrypt->format) { + case RBD_IMAGE_ENCRYPTION_FORMAT_LUKS: { + specs[i].format =3D RBD_ENCRYPTION_FORMAT_LUKS1; + + luks_opts =3D g_new0(rbd_encryption_luks1_format_options_t= , 1); + specs[i].opts =3D luks_opts; + specs[i].opts_size =3D sizeof(*luks_opts); + + r =3D qemu_rbd_convert_luks_options( + qapi_RbdEncryptionOptionsLUKS_base( + &curr_encrypt->u.luks), + (char **)&luks_opts->passphrase, + &luks_opts->passphrase_size, + errp); + break; + } + case RBD_IMAGE_ENCRYPTION_FORMAT_LUKS2: { + specs[i].format =3D RBD_ENCRYPTION_FORMAT_LUKS2; + + luks2_opts =3D g_new0(rbd_encryption_luks2_format_options_= t, 1); + specs[i].opts =3D luks2_opts; + specs[i].opts_size =3D sizeof(*luks2_opts); + + r =3D qemu_rbd_convert_luks_options( + qapi_RbdEncryptionOptionsLUKS2_base( + &curr_encrypt->u.luks2), + (char **)&luks2_opts->passphrase, + &luks2_opts->passphrase_size, + errp); + break; + } + case RBD_IMAGE_ENCRYPTION_FORMAT_LUKS_ANY: { + specs[i].format =3D RBD_ENCRYPTION_FORMAT_LUKS; + + luks_any_opts =3D g_new0(rbd_encryption_luks_format_option= s_t, 1); + specs[i].opts =3D luks_any_opts; + specs[i].opts_size =3D sizeof(*luks_any_opts); + + r =3D qemu_rbd_convert_luks_options( + qapi_RbdEncryptionOptionsLUKSAny_base( + &curr_encrypt->u.luks_any), + (char **)&luks_any_opts->passphrase, + &luks_any_opts->passphrase_size, + errp); + break; + } + default: { + r =3D -ENOTSUP; + error_setg_errno( + errp, -r, "unknown image encryption format: %u", + curr_encrypt->format); + } + } + + if (r < 0) { + goto exit; + } + + curr_encrypt =3D curr_encrypt->parent; + } + + r =3D rbd_encryption_load2(image, specs, encrypt_count); + if (r < 0) { + error_setg_errno(errp, -r, "layered encryption load fail"); + goto exit; + } + +exit: + for (i =3D 0; i < encrypt_count; ++i) { + if (!specs[i].opts) { + break; + } + + switch (specs[i].format) { + case RBD_ENCRYPTION_FORMAT_LUKS1: { + luks_opts =3D specs[i].opts; + g_free((void *)luks_opts->passphrase); + break; + } + case RBD_ENCRYPTION_FORMAT_LUKS2: { + luks2_opts =3D specs[i].opts; + g_free((void *)luks2_opts->passphrase); + break; + } + case RBD_ENCRYPTION_FORMAT_LUKS: { + luks_any_opts =3D specs[i].opts; + g_free((void *)luks_any_opts->passphrase); + break; + } + } + + g_free(specs[i].opts); + } + g_free(specs); + return r; +} +#endif #endif =20 /* FIXME Deprecate and remove keypairs or make it available in QMP. */ @@ -1004,7 +1136,16 @@ static int qemu_rbd_open(BlockDriverState *bs, QDict= *options, int flags, =20 if (opts->encrypt) { #ifdef LIBRBD_SUPPORTS_ENCRYPTION - r =3D qemu_rbd_encryption_load(s->image, opts->encrypt, errp); + if (opts->encrypt->parent) { +#ifdef LIBRBD_SUPPORTS_ENCRYPTION_LOAD2 + r =3D qemu_rbd_encryption_load2(s->image, opts->encrypt, errp); +#else + r =3D -ENOTSUP; + error_setg(errp, "RBD library does not support layered encrypt= ion"); +#endif + } else { + r =3D qemu_rbd_encryption_load(s->image, opts->encrypt, errp); + } if (r < 0) { goto failed_post_open; } @@ -1296,6 +1437,16 @@ static ImageInfoSpecific *qemu_rbd_get_specific_info= (BlockDriverState *bs, spec_info->u.rbd.data->encryption_format =3D RBD_IMAGE_ENCRYPTION_FORMAT_LUKS2; spec_info->u.rbd.data->has_encryption_format =3D true; + } else if (memcmp(buf, rbd_layered_luks_header_verification, + RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) =3D=3D 0) { + spec_info->u.rbd.data->encryption_format =3D + RBD_IMAGE_ENCRYPTION_FORMAT_LUKS; + spec_info->u.rbd.data->has_encryption_format =3D true; + } else if (memcmp(buf, rbd_layered_luks2_header_verification, + RBD_ENCRYPTION_LUKS_HEADER_VERIFICATION_LEN) =3D=3D 0) { + spec_info->u.rbd.data->encryption_format =3D + RBD_IMAGE_ENCRYPTION_FORMAT_LUKS2; + spec_info->u.rbd.data->has_encryption_format =3D true; } else { spec_info->u.rbd.data->has_encryption_format =3D false; } --=20 2.39.2