From nobody Wed Feb 11 03:24:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1668607908; cv=none; d=zohomail.com; s=zohoarc; b=CpaiIlrx8lz1wqk8OIDSeS89Jwm506Mm9q9p3QNrqHVxCTHFDAiDc+IXSLzdj1yu2RyIxI5lQQhqQ6ONy2BSf1Jq6uPyIE54Cxahvqhol+aUsLZH0l7VuDlL8mNWDq+aM0fc/iOnxibwxItTPtub4tD0fMma8J1uZS8zsvWgxBA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668607908; 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=ofv4pS8f2mCmUoMSq24yvD4pA5jOYOOMvJoBvadaHDk=; b=ercCSraWOcEtaMCxyaSf/62iI8asSzpU6dNwEkKdem/RUhNeaF/qi0NqATgksgDzo+1hZO59x+IB36b80QEsgrNyxfwzKzh1+vj1m2+Hcw/ax4zGky0X6O2pwdV8jW7PPF7PmsZrX7M+nisJ30fqs+2YGzlS/PnKIuZJz8r5ogA= 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 16686079089464.370920559175602; Wed, 16 Nov 2022 06:11:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ovJ51-0000wp-Fi; Wed, 16 Nov 2022 09:07:55 -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 1ovJ4s-0000l6-Om for qemu-devel@nongnu.org; Wed, 16 Nov 2022 09:07:47 -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 1ovJ4q-00068C-1N for qemu-devel@nongnu.org; Wed, 16 Nov 2022 09:07:46 -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-558-nQCHXKHoPtyrVf3x2v9Zkg-1; Wed, 16 Nov 2022 09:07:39 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 365B63810D3B; Wed, 16 Nov 2022 14:07:38 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A64BC1908A; Wed, 16 Nov 2022 14:07:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1668607660; 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=ofv4pS8f2mCmUoMSq24yvD4pA5jOYOOMvJoBvadaHDk=; b=TWojiLY4YU6pZrXLOuBNRPOQEnRYScuXhRNo1t+Cajqqx9gfOZrw/km82YPXpUSherMgqT WVXYkkuEQkdnpUwQ1PJavV/gw9TNb7lm8P6+nnzUa4dWHiiEXXqBB2D3kAkv4hwIxJcUKk V0NvFRRB7RXO2XDpG65UunSRgE2gHSo= X-MC-Unique: nQCHXKHoPtyrVf3x2v9Zkg-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Hanna Reitz , Stefan Hajnoczi , Ari Sundholm , Pavel Dovgalyuk , Paolo Bonzini , John Snow , Vladimir Sementsov-Ogievskiy , Stefan Weil , Fam Zheng , Ronnie Sahlberg , Peter Lieven , Eric Blake , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Alberto Garcia , Ilya Dryomov , Wen Congyang , Xie Changlong , "Richard W.M. Jones" , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, integration@gluster.org, Emanuele Giuseppe Esposito Subject: [PATCH 06/15] block: convert bdrv_get_allocated_file_size in generated_co_wrapper_simple Date: Wed, 16 Nov 2022 09:07:21 -0500 Message-Id: <20221116140730.3056048-7-eesposit@redhat.com> In-Reply-To: <20221116140730.3056048-1-eesposit@redhat.com> References: <20221116140730.3056048-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -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: 1668607910353100001 Content-Type: text/plain; charset="utf-8" BlockDriver->bdrv_get_allocated_file_size is categorized as IO callback, a= nd it currently doesn't run in a coroutine. This makes very difficult to add the graph rdlock, since the callback traverses the block nodes graph. Therefore use generated_co_wrapper_simple to automatically create a wrapper with the same name that will take care of always calling the function in a coroutine. This is a generated_co_wrapper_simple callback, which means it assumes that bdrv_get_allocated_file_size is never caled in a coroutine context. Signed-off-by: Emanuele Giuseppe Esposito --- block.c | 7 ++++--- block/qcow2-refcount.c | 2 +- include/block/block-io.h | 5 ++++- include/block/block_int-common.h | 3 ++- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/block.c b/block.c index c7b32ba17a..5650d6fe63 100644 --- a/block.c +++ b/block.c @@ -5708,7 +5708,7 @@ static int64_t bdrv_sum_allocated_file_size(BlockDriv= erState *bs) if (child->role & (BDRV_CHILD_DATA | BDRV_CHILD_METADATA | BDRV_CHILD_FILTERED)) { - child_size =3D bdrv_get_allocated_file_size(child->bs); + child_size =3D bdrv_co_get_allocated_file_size(child->bs); if (child_size < 0) { return child_size; } @@ -5723,10 +5723,11 @@ static int64_t bdrv_sum_allocated_file_size(BlockDr= iverState *bs) * Length of a allocated file in bytes. Sparse files are counted by actual * allocated space. Return < 0 if error or unknown. */ -int64_t bdrv_get_allocated_file_size(BlockDriverState *bs) +int64_t coroutine_fn bdrv_co_get_allocated_file_size(BlockDriverState *bs) { BlockDriver *drv =3D bs->drv; IO_CODE(); + assert_bdrv_graph_readable(); =20 if (!drv) { return -ENOMEDIUM; @@ -5744,7 +5745,7 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState= *bs) return -ENOTSUP; } else if (drv->is_filter) { /* Filter drivers default to the size of their filtered child */ - return bdrv_get_allocated_file_size(bdrv_filter_bs(bs)); + return bdrv_co_get_allocated_file_size(bdrv_filter_bs(bs)); } else { /* Other drivers default to summing their children's sizes */ return bdrv_sum_allocated_file_size(bs); diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 81264740f0..487681d85e 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -3719,7 +3719,7 @@ int coroutine_fn qcow2_detect_metadata_preallocation(= BlockDriverState *bs) return file_length; } =20 - real_allocation =3D bdrv_get_allocated_file_size(bs->file->bs); + real_allocation =3D bdrv_co_get_allocated_file_size(bs->file->bs); if (real_allocation < 0) { return real_allocation; } diff --git a/include/block/block-io.h b/include/block/block-io.h index 4fb95e9b7a..ac509c461f 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -74,7 +74,10 @@ int64_t generated_co_wrapper bdrv_nb_sectors(BlockDriver= State *bs); int64_t coroutine_fn bdrv_co_getlength(BlockDriverState *bs); int64_t generated_co_wrapper bdrv_getlength(BlockDriverState *bs); =20 -int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); +int64_t generated_co_wrapper_simple bdrv_get_allocated_file_size( + BlockDriverState *= bs); +int64_t coroutine_fn bdrv_co_get_allocated_file_size(BlockDriverState *bs); + BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *opts, BlockDriverState *in_bs, Error **errp); void bdrv_get_geometry(BlockDriverState *bs, uint64_t *nb_sectors_ptr); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index d1cf52d4f7..42daf86c65 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -725,7 +725,8 @@ struct BlockDriver { BdrvRequestFlags flags, Error **e= rrp); /* Called with graph rdlock held. */ int64_t coroutine_fn (*bdrv_getlength)(BlockDriverState *bs); - int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs); + /* Called with graph rdlock held. */ + int64_t coroutine_fn (*bdrv_get_allocated_file_size)(BlockDriverState = *bs); =20 /* Does not need graph rdlock, since it does not traverse the graph */ BlockMeasureInfo *(*bdrv_measure)(QemuOpts *opts, BlockDriverState *in= _bs, --=20 2.31.1