From nobody Tue May 13 11:36:58 2025 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1675437901; cv=none; d=zohomail.com; s=zohoarc; b=A9hERpYikHYf/gxSfZvqGFPtmUOLhAf4patG8Vr0Z1FGxkrznzF2BR9WkI3uk2N0Iq+Flx0eJok2/+HFOHk/g7ZRE4TO4BHjpASI2goKac3WtgcV0W610D3Vc0Qf2Dg1MZWESrwhhM6sQlznBgmvUwXAo3mGSM6FOr0Z/dndKuM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1675437901; 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=loal9xD94xXkwbGWgi/vz2iclG599UJkU2NqA3mfoww=; b=eevbRaWE1RRquaohD7aPwlmRylxXiJ9j+kcdHt2GCsDJsDd0poNKEPFsgqX6SalgNYoqVnJfTw1qVA8k9ImP+hNhekEVlyonkgfL0fmUnwHBFNkHeWKFJbUlLTEw3CebB8MDdiwEqy9uI4P0kObgphuDZyZTHXsUB/6LTkgqKM4= 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+importer2=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 1675437901048592.1112244836739; Fri, 3 Feb 2023 07:25:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pNxuF-0007lB-PC; Fri, 03 Feb 2023 10:23:15 -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 1pNxuC-0007hE-JT for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:12 -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 1pNxuA-0005QI-KR for qemu-devel@nongnu.org; Fri, 03 Feb 2023 10:23:12 -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-640-RdHuAAO8MV6Ake_H5SiwIQ-1; Fri, 03 Feb 2023 10:23:06 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 46413800B24; Fri, 3 Feb 2023 15:23:06 +0000 (UTC) Received: from merkur.fritz.box (unknown [10.39.194.116]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4CDC840168B7; Fri, 3 Feb 2023 15:23:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675437790; 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=loal9xD94xXkwbGWgi/vz2iclG599UJkU2NqA3mfoww=; b=dypCl26nb9NdPPKWAC93eneBKXKIBd3zvdlPKQcdR44P5MDxsJ0Cr1JzOxetmTrzwu65uD dhIff4beBUckQe70brf9LkoRDHiXqa/u6ciRGz9J0exrH8NkyxuxMbbusnyQJVGd0EqQYh jXGsu9JPEv+d8QYVFGz5aBFgAwVEsjs= X-MC-Unique: RdHuAAO8MV6Ake_H5SiwIQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, eesposit@redhat.com, qemu-devel@nongnu.org Subject: [PATCH 23/23] block: Mark bdrv_co_refresh_total_sectors() and callers GRAPH_RDLOCK Date: Fri, 3 Feb 2023 16:22:02 +0100 Message-Id: <20230203152202.49054-24-kwolf@redhat.com> In-Reply-To: <20230203152202.49054-1-kwolf@redhat.com> References: <20230203152202.49054-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 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+importer2=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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1675437903110100003 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 --- 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 1e378e881d..1f1e63c468 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; @@ -5820,6 +5821,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; @@ -5841,6 +5843,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 28f870f33c..88b092e1a4 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -531,7 +531,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.38.1