From nobody Sat Jul 12 05:30:46 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=suse.de ARC-Seal: i=1; a=rsa-sha256; t=1686342047; cv=none; d=zohomail.com; s=zohoarc; b=RDVZLnaACaWikAkN5f9xM8EiG+wXhSLQBP8PwoPNr4gIuU1W4IgYCE98EvFDob1DqVhVtmqtDbf1OX+lQkGMEFURXyzl+Dwo5E5t7AL280ZjbMD2DJN48hndrmVrUEvhvY02w/BCeb511iNu62Jvnwoyv+erWpIqhf+emvq8pg8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1686342047; 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=enuupaTJDX4N+4BscN7GlbxD/HxwHwJVr5Z+5Z5sObA=; b=jswXu7r9GaLBUcWgxEDlT+ljRlO90nJFeBtEReajbyWpJRD1S1VjQBHzqssjylpPaIm2bJPqYtIOMU3yDYvIaI3/3YU65T7EPYvVR4EzA9pM4a7EBCbIxayD1U4gvpQh0jYO0YePUvUY+sSpE5jq40RmoRkByHKXK8l8KOMqK2E= 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 1686342047957448.64687608599013; Fri, 9 Jun 2023 13:20:47 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q7iaW-000268-MT; Fri, 09 Jun 2023 16:20:00 -0400 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 1q7iaT-00024O-CR; Fri, 09 Jun 2023 16:19:57 -0400 Received: from smtp-out1.suse.de ([2001:67c:2178:6::1c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q7iaR-0000EO-HK; Fri, 09 Jun 2023 16:19:57 -0400 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id DA5E321A8C; Fri, 9 Jun 2023 20:19:46 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id C348D139C8; Fri, 9 Jun 2023 20:19:43 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6N+2IV+Jg2R/SwAAMHmgww (envelope-from ); Fri, 09 Jun 2023 20:19:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1686341986; h=from:from:reply-to: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=enuupaTJDX4N+4BscN7GlbxD/HxwHwJVr5Z+5Z5sObA=; b=kaUPKoAYt5RDGsGfdaCO2116pTjaxBy093NXvyjeqcHMBtAg+kj2bkKQMmlqgEbv2wHrY/ w+WbyHa5YTPnolIwU6QgIqvEBA7Pqgp15IJwHW0w85jVc8WyKBzp/1Bc+r+XBgXflhXIM4 HoLyYEZ7Rhzn+GghfQyE3nwPjAbVYzU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1686341986; h=from:from:reply-to: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=enuupaTJDX4N+4BscN7GlbxD/HxwHwJVr5Z+5Z5sObA=; b=BHNsJbxSScxTewwhqltYKgYpZj4upKBgqTEYeWoJ76mMYS83dlugUXUi4gFiEe+kqBUth1 3VV3zoWprYqGeGAg== From: Fabiano Rosas To: qemu-devel@nongnu.org Cc: qemu-block@nongnu.org, Kevin Wolf , Hanna Reitz , Markus Armbruster , =?UTF-8?q?Jo=C3=A3o=20Silva?= , Lin Ma , Claudio Fontana , Dario Faggioli , Eric Blake , "Dr. David Alan Gilbert" Subject: [PATCH v2 09/10] block: Convert qmp_query_block() to coroutine_fn Date: Fri, 9 Jun 2023 17:19:09 -0300 Message-Id: <20230609201910.12100-10-farosas@suse.de> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230609201910.12100-1-farosas@suse.de> References: <20230609201910.12100-1-farosas@suse.de> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2001:67c:2178:6::1c; envelope-from=farosas@suse.de; helo=smtp-out1.suse.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @suse.de) X-ZM-MESSAGEID: 1686342048364100003 Content-Type: text/plain; charset="utf-8" This is another caller of bdrv_get_allocated_file_size() that needs to be converted to a coroutine because that function will be made asynchronous when called (indirectly) from the QMP dispatcher. This QMP command is a candidate because it calls bdrv_do_query_node_info(), which in turn calls bdrv_get_allocated_file_size(). We've determined bdrv_do_query_node_info() to be coroutine-safe (see previous commits), so we can just put this QMP command in a coroutine. Since qmp_query_block() now expects to run in a coroutine, its callers need to be converted as well. Convert hmp_info_block(), which calls only coroutine-safe code, including qmp_query_named_block_nodes() which has been converted to coroutine in the previous patches. Now that all callers of bdrv_[co_]block_device_info() are using the coroutine version, a few things happen: - we can return to using bdrv_block_device_info() without a wrapper; - bdrv_get_allocated_file_size() can stop being mixed; - bdrv_co_get_allocated_file_size() needs to be put under the graph lock because it is being called wthout the wrapper; - bdrv_do_query_node_info() doesn't need to acquire the AioContext because it doesn't call aio_poll anymore; Signed-off-by: Fabiano Rosas --- block.c | 2 +- block/monitor/block-hmp-cmds.c | 2 +- block/qapi.c | 18 +++++++++--------- hmp-commands-info.hx | 1 + include/block/block-hmp-cmds.h | 2 +- include/block/block-io.h | 2 +- include/block/qapi.h | 12 ++++-------- qapi/block-core.json | 2 +- 8 files changed, 19 insertions(+), 22 deletions(-) diff --git a/block.c b/block.c index abed744b60..f94cee8930 100644 --- a/block.c +++ b/block.c @@ -6148,7 +6148,7 @@ BlockDeviceInfoList *bdrv_named_nodes_list(bool flat, =20 list =3D NULL; QTAILQ_FOREACH(bs, &graph_bdrv_states, node_list) { - BlockDeviceInfo *info =3D bdrv_co_block_device_info(NULL, bs, flat= , errp); + BlockDeviceInfo *info =3D bdrv_block_device_info(NULL, bs, flat, e= rrp); if (!info) { qapi_free_BlockDeviceInfoList(list); return NULL; diff --git a/block/monitor/block-hmp-cmds.c b/block/monitor/block-hmp-cmds.c index 26116fe831..1049f9b006 100644 --- a/block/monitor/block-hmp-cmds.c +++ b/block/monitor/block-hmp-cmds.c @@ -742,7 +742,7 @@ static void print_block_info(Monitor *mon, BlockInfo *i= nfo, } } =20 -void hmp_info_block(Monitor *mon, const QDict *qdict) +void coroutine_fn hmp_info_block(Monitor *mon, const QDict *qdict) { BlockInfoList *block_list, *info; BlockDeviceInfoList *blockdev_list, *blockdev; diff --git a/block/qapi.c b/block/qapi.c index 20660e15d6..3b4bc0b782 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -41,10 +41,10 @@ #include "qemu/qemu-print.h" #include "sysemu/block-backend.h" =20 -BlockDeviceInfo *coroutine_fn bdrv_co_block_device_info(BlockBackend *blk, - BlockDriverState *= bs, - bool flat, - Error **errp) +BlockDeviceInfo *coroutine_fn bdrv_block_device_info(BlockBackend *blk, + BlockDriverState *bs, + bool flat, + Error **errp) { ImageInfo **p_image_info; ImageInfo *backing_info; @@ -235,8 +235,6 @@ static void bdrv_do_query_node_info(BlockDriverState *b= s, int ret; Error *err =3D NULL; =20 - aio_context_acquire(bdrv_get_aio_context(bs)); - size =3D bdrv_getlength(bs); if (size < 0) { error_setg_errno(errp, -size, "Can't get image size '%s'", @@ -249,7 +247,9 @@ static void bdrv_do_query_node_info(BlockDriverState *b= s, info->filename =3D g_strdup(bs->filename); info->format =3D g_strdup(bdrv_get_format_name(bs)); info->virtual_size =3D size; - info->actual_size =3D bdrv_get_allocated_file_size(bs); + bdrv_graph_co_rdlock(); + info->actual_size =3D bdrv_co_get_allocated_file_size(bs); + bdrv_graph_co_rdunlock(); info->has_actual_size =3D info->actual_size >=3D 0; if (bs->encrypted) { info->encrypted =3D true; @@ -305,7 +305,7 @@ static void bdrv_do_query_node_info(BlockDriverState *b= s, } =20 out: - aio_context_release(bdrv_get_aio_context(bs)); + return; } =20 /** @@ -668,7 +668,7 @@ bdrv_query_bds_stats(BlockDriverState *bs, bool blk_lev= el) return s; } =20 -BlockInfoList *qmp_query_block(Error **errp) +BlockInfoList *coroutine_fn qmp_query_block(Error **errp) { BlockInfoList *head =3D NULL, **p_next =3D &head; BlockBackend *blk; diff --git a/hmp-commands-info.hx b/hmp-commands-info.hx index 47d63d26db..996895f417 100644 --- a/hmp-commands-info.hx +++ b/hmp-commands-info.hx @@ -65,6 +65,7 @@ ERST .help =3D "show info of one block device or all block device= s " "(-n: show named nodes; -v: show details)", .cmd =3D hmp_info_block, + .coroutine =3D true, }, =20 SRST diff --git a/include/block/block-hmp-cmds.h b/include/block/block-hmp-cmds.h index 71113cd7ef..6d9152318f 100644 --- a/include/block/block-hmp-cmds.h +++ b/include/block/block-hmp-cmds.h @@ -48,7 +48,7 @@ void hmp_eject(Monitor *mon, const QDict *qdict); =20 void hmp_qemu_io(Monitor *mon, const QDict *qdict); =20 -void hmp_info_block(Monitor *mon, const QDict *qdict); +void coroutine_fn hmp_info_block(Monitor *mon, const QDict *qdict); void hmp_info_blockstats(Monitor *mon, const QDict *qdict); void hmp_info_block_jobs(Monitor *mon, const QDict *qdict); void hmp_info_snapshots(Monitor *mon, const QDict *qdict); diff --git a/include/block/block-io.h b/include/block/block-io.h index f31e25cf56..43af816d75 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -87,7 +87,7 @@ int64_t co_wrapper_mixed_bdrv_rdlock bdrv_getlength(Block= DriverState *bs); int64_t coroutine_fn GRAPH_RDLOCK bdrv_co_get_allocated_file_size(BlockDriverState *bs); =20 -int64_t co_wrapper_mixed_bdrv_rdlock +int64_t co_wrapper_bdrv_rdlock bdrv_get_allocated_file_size(BlockDriverState *bs); =20 BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *opts, diff --git a/include/block/qapi.h b/include/block/qapi.h index 5cb0202791..c37cba2a09 100644 --- a/include/block/qapi.h +++ b/include/block/qapi.h @@ -30,14 +30,10 @@ #include "block/snapshot.h" #include "qapi/qapi-types-block-core.h" =20 -BlockDeviceInfo *coroutine_fn bdrv_co_block_device_info(BlockBackend *blk, - BlockDriverState *= bs, - bool flat, - Error **errp); -BlockDeviceInfo *co_wrapper bdrv_block_device_info(BlockBackend *blk, - BlockDriverState *bs, - bool flat, - Error **errp); +BlockDeviceInfo *coroutine_fn bdrv_block_device_info(BlockBackend *blk, + BlockDriverState *bs, + bool flat, + Error **errp); int bdrv_query_snapshot_info_list(BlockDriverState *bs, SnapshotInfoList **p_list, Error **errp); diff --git a/qapi/block-core.json b/qapi/block-core.json index 9d4c92f2c9..a78dc92493 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -838,7 +838,7 @@ # } ## { 'command': 'query-block', 'returns': ['BlockInfo'], - 'allow-preconfig': true } + 'allow-preconfig': true, 'coroutine': true } =20 ## # @BlockDeviceTimedStats: --=20 2.35.3