From nobody Sat Apr 20 01:04:24 2024 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=1673642648; cv=none; d=zohomail.com; s=zohoarc; b=bN61J0s/88XHP1f4cH7xDfcpWNmLdK/9nO8OT8av0MT3UUnao7BOfQr2XBrTrm9GnU3lRCAH2zG1Cvsp8EdRHImrbwqnd4csPOxExqzDBbfNMl1dBeH3mgnuXUIkQ5VbTb4Lwka6I6mQQDAXGxEJZCY3Xyo77HPWXtQ2fGIkLgg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673642648; 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=CVOPB379Jvnni2ccSM+vLxv3AvP2G5ZvVhvcaqpt0+k=; b=XG7JIEtW7qcqh/Ojr5ZJbKTGucglsuCEBTnWYyuEWPesUH0F0TypsuW5wmPRJFBa5LRoV51GbwDqcPIfktGor8WPYw7cSZT9BdncKIls24Dzxr5KSny1LOinovyEqY/sjE92EFYTzHaClREpR5JwaCdP9q1xXgIDFGNS01dkw4g= 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 167364264890829.93757427899891; Fri, 13 Jan 2023 12:44:08 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGQss-0008Ss-7G; Fri, 13 Jan 2023 15:42:42 -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 1pGQso-0008R5-Kl for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:39 -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 1pGQsm-00068x-Oa for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:37 -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-190-IcwNE-4FPXKeYmCls-j39w-1; Fri, 13 Jan 2023 15:42:32 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7894E1C02CBC; Fri, 13 Jan 2023 20:42:32 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.195.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 440752026D76; Fri, 13 Jan 2023 20:42:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673642556; 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=CVOPB379Jvnni2ccSM+vLxv3AvP2G5ZvVhvcaqpt0+k=; b=Nl7KCMOqgnnhAaUBPthRDtMrYz+1Kq18ySWifhFCqgy2ZvPMQzCnWR8NAyhMpxWl0Yx1YY AIpAkoX+Eu5ijHXivVknoWW1E1oYCV53DW7qDmoI3D9d7s6ehOV4cv+TFgFQU+ffpK/BRn OLQcG512IIUiDUGBeYzUeLlfFTtlNXU= X-MC-Unique: IcwNE-4FPXKeYmCls-j39w-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v2 01/14] block-coroutine-wrapper: support void functions Date: Fri, 13 Jan 2023 21:41:59 +0100 Message-Id: <20230113204212.359076-2-kwolf@redhat.com> In-Reply-To: <20230113204212.359076-1-kwolf@redhat.com> References: <20230113204212.359076-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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=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 @redhat.com) X-ZM-MESSAGEID: 1673642650575100002 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito Just omit the various 'return' when the return type is void. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Emanuele Giuseppe Esposito --- scripts/block-coroutine-wrapper.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts/block-coroutine-wrapper.py b/scripts/block-coroutine-w= rapper.py index 6e087fa0b7..0c5d7782b1 100644 --- a/scripts/block-coroutine-wrapper.py +++ b/scripts/block-coroutine-wrapper.py @@ -85,6 +85,16 @@ def __init__(self, return_type: str, name: str, args: st= r, ctx =3D 'qemu_get_aio_context()' self.ctx =3D ctx =20 + self.get_result =3D 's->ret =3D ' + self.ret =3D 'return s.ret;' + self.co_ret =3D 'return ' + self.return_field =3D self.return_type + " ret;" + if self.return_type =3D=3D 'void': + self.get_result =3D '' + self.ret =3D '' + self.co_ret =3D '' + self.return_field =3D '' + def gen_list(self, format: str) -> str: return ', '.join(format.format_map(arg.__dict__) for arg in self.a= rgs) =20 @@ -131,7 +141,7 @@ def create_mixed_wrapper(func: FuncDecl) -> str: {{ if (qemu_in_coroutine()) {{ {graph_assume_lock} - return {name}({ func.gen_list('{name}') }); + {func.co_ret}{name}({ func.gen_list('{name}') }); }} else {{ {struct_name} s =3D {{ .poll_state.ctx =3D {func.ctx}, @@ -143,7 +153,7 @@ def create_mixed_wrapper(func: FuncDecl) -> str: s.poll_state.co =3D qemu_coroutine_create({name}_entry, &s); =20 bdrv_poll_co(&s.poll_state); - return s.ret; + {func.ret} }} }}""" =20 @@ -168,7 +178,7 @@ def create_co_wrapper(func: FuncDecl) -> str: s.poll_state.co =3D qemu_coroutine_create({name}_entry, &s); =20 bdrv_poll_co(&s.poll_state); - return s.ret; + {func.ret} }}""" =20 =20 @@ -195,7 +205,7 @@ def gen_wrapper(func: FuncDecl) -> str: =20 typedef struct {struct_name} {{ BdrvPollCo poll_state; - {func.return_type} ret; + {func.return_field} { func.gen_block(' {decl};') } }} {struct_name}; =20 @@ -204,7 +214,7 @@ def gen_wrapper(func: FuncDecl) -> str: {struct_name} *s =3D opaque; =20 {graph_lock} - s->ret =3D {name}({ func.gen_list('s->{name}') }); + {func.get_result}{name}({ func.gen_list('s->{name}') }); {graph_unlock} s->poll_state.in_progress =3D false; =20 --=20 2.38.1 From nobody Sat Apr 20 01:04:24 2024 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=1673642640; cv=none; d=zohomail.com; s=zohoarc; b=fF+8cHrbdOG/fXAElRg4YDvxaZ1OJbYjBPMlXcybEdDKf6hracCPBXL9rNj7EkvfQrpYqZmNlWBn8etITN5NE2y4EXIEE2tT/3cxwbxjnWW9C75HbES/3mNn2xnBjf5UQ4Q/3Vkh43i9PWtqqC1Akql7Ygh7OSyQws5Rzd00ndg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673642640; 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=N/23Jbsr76qOT53WkSpccuz1clMzcufR+Z2eFiHJvRM=; b=Sqy7/BUwxjTxhAxSxFiuxuevR1S5LqlrJircdFHZ1KSB/99wreCqH/kRa3es/S4oLMVGWne9UhTDuTeIfTlsEUH55Q4bCXHBTpLHPAjZh2/0uJRLfmR3h9PH0M5Nw21jNoxD7IJmtOnhm0N5fQyz2H/5ubeH1DZ5qHwytaFznvw= 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 1673642640363556.7374795160952; Fri, 13 Jan 2023 12:44:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGQst-0008Ts-LG; Fri, 13 Jan 2023 15:42:43 -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 1pGQsp-0008Rr-OP for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:40 -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 1pGQso-00069L-4F for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:39 -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-306-2EWoaRQJO0iL9lAELt2N_g-1; Fri, 13 Jan 2023 15:42:34 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EAF0E281DE7C; Fri, 13 Jan 2023 20:42:33 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.195.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8CC72026D68; Fri, 13 Jan 2023 20:42:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673642557; 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=N/23Jbsr76qOT53WkSpccuz1clMzcufR+Z2eFiHJvRM=; b=EraxFWHxYo6IXWV3d/PmgxeT/W0J3qxj0CtPEThponYnqZruDgZI833Y2phXc8BjthHQ0E vM83p3aHNeDryVt0cJ36uCT2XmsTLv/eHKaVsJBlHm+pzzsmQqovyJYQ22My0trn8M1y3x PHzb5ZSk2w+iJnQVuskPFmiFWUvYn+Y= X-MC-Unique: 2EWoaRQJO0iL9lAELt2N_g-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v2 02/14] block: Convert bdrv_io_plug() to co_wrapper Date: Fri, 13 Jan 2023 21:42:00 +0100 Message-Id: <20230113204212.359076-3-kwolf@redhat.com> In-Reply-To: <20230113204212.359076-1-kwolf@redhat.com> References: <20230113204212.359076-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: 1673642642580100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito BlockDriver->bdrv_io_plug is categorized as IO callback, and it currently doesn't run in a coroutine. We should let it take a graph rdlock since the callback traverses the block nodes graph, which however is only possible in a coroutine. The only caller of this function is blk_io_plug(), therefore make blk_io_plug() a co_wrapper, so that we're always running in a coroutine where the lock can be taken. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 3 ++- include/block/block_int-common.h | 2 +- include/sysemu/block-backend-io.h | 4 +++- block/block-backend.c | 4 ++-- block/file-posix.c | 10 +++++----- block/io.c | 8 ++++---- block/nvme.c | 4 ++-- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 2ed6214909..d96168375e 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -217,7 +217,8 @@ void bdrv_coroutine_enter(BlockDriverState *bs, Corouti= ne *co); =20 AioContext *child_of_bds_get_parent_aio_context(BdrvChild *c); =20 -void bdrv_io_plug(BlockDriverState *bs); +void coroutine_fn bdrv_co_io_plug(BlockDriverState *bs); + void bdrv_io_unplug(BlockDriverState *bs); =20 bool coroutine_fn bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index c34c525fa6..a76bb76290 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -729,7 +729,7 @@ struct BlockDriver { void (*bdrv_debug_event)(BlockDriverState *bs, BlkdebugEvent event); =20 /* io queue for linux-aio */ - void (*bdrv_io_plug)(BlockDriverState *bs); + void coroutine_fn (*bdrv_co_io_plug)(BlockDriverState *bs); void (*bdrv_io_unplug)(BlockDriverState *bs); =20 /** diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index 7ec6d978d4..70b73f7d11 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -73,7 +73,9 @@ void blk_iostatus_set_err(BlockBackend *blk, int error); int blk_get_max_iov(BlockBackend *blk); int blk_get_max_hw_iov(BlockBackend *blk); =20 -void blk_io_plug(BlockBackend *blk); +void coroutine_fn blk_co_io_plug(BlockBackend *blk); +void co_wrapper blk_io_plug(BlockBackend *blk); + void blk_io_unplug(BlockBackend *blk); AioContext *blk_get_aio_context(BlockBackend *blk); BlockAcctStats *blk_get_stats(BlockBackend *blk); diff --git a/block/block-backend.c b/block/block-backend.c index ba7bf1d6bc..2bca5729e1 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2315,13 +2315,13 @@ void blk_add_insert_bs_notifier(BlockBackend *blk, = Notifier *notify) notifier_list_add(&blk->insert_bs_notifiers, notify); } =20 -void blk_io_plug(BlockBackend *blk) +void coroutine_fn blk_co_io_plug(BlockBackend *blk) { BlockDriverState *bs =3D blk_bs(blk); IO_CODE(); =20 if (bs) { - bdrv_io_plug(bs); + bdrv_co_io_plug(bs); } } =20 diff --git a/block/file-posix.c b/block/file-posix.c index b9647c5ffc..c8551c8110 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2136,7 +2136,7 @@ static int coroutine_fn raw_co_pwritev(BlockDriverSta= te *bs, int64_t offset, return raw_co_prw(bs, offset, bytes, qiov, QEMU_AIO_WRITE); } =20 -static void raw_aio_plug(BlockDriverState *bs) +static void coroutine_fn raw_co_io_plug(BlockDriverState *bs) { BDRVRawState __attribute__((unused)) *s =3D bs->opaque; #ifdef CONFIG_LINUX_AIO @@ -3321,7 +3321,7 @@ BlockDriver bdrv_file =3D { .bdrv_co_copy_range_from =3D raw_co_copy_range_from, .bdrv_co_copy_range_to =3D raw_co_copy_range_to, .bdrv_refresh_limits =3D raw_refresh_limits, - .bdrv_io_plug =3D raw_aio_plug, + .bdrv_co_io_plug =3D raw_co_io_plug, .bdrv_io_unplug =3D raw_aio_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 @@ -3693,7 +3693,7 @@ static BlockDriver bdrv_host_device =3D { .bdrv_co_copy_range_from =3D raw_co_copy_range_from, .bdrv_co_copy_range_to =3D raw_co_copy_range_to, .bdrv_refresh_limits =3D raw_refresh_limits, - .bdrv_io_plug =3D raw_aio_plug, + .bdrv_co_io_plug =3D raw_co_io_plug, .bdrv_io_unplug =3D raw_aio_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 @@ -3817,7 +3817,7 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_co_pwritev =3D raw_co_pwritev, .bdrv_co_flush_to_disk =3D raw_co_flush_to_disk, .bdrv_refresh_limits =3D raw_refresh_limits, - .bdrv_io_plug =3D raw_aio_plug, + .bdrv_co_io_plug =3D raw_co_io_plug, .bdrv_io_unplug =3D raw_aio_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 @@ -3947,7 +3947,7 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_co_pwritev =3D raw_co_pwritev, .bdrv_co_flush_to_disk =3D raw_co_flush_to_disk, .bdrv_refresh_limits =3D raw_refresh_limits, - .bdrv_io_plug =3D raw_aio_plug, + .bdrv_co_io_plug =3D raw_co_io_plug, .bdrv_io_unplug =3D raw_aio_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 diff --git a/block/io.c b/block/io.c index a09b1b34ab..c05fb89267 100644 --- a/block/io.c +++ b/block/io.c @@ -3136,19 +3136,19 @@ void *qemu_try_blockalign0(BlockDriverState *bs, si= ze_t size) return mem; } =20 -void bdrv_io_plug(BlockDriverState *bs) +void coroutine_fn bdrv_co_io_plug(BlockDriverState *bs) { BdrvChild *child; IO_CODE(); =20 QLIST_FOREACH(child, &bs->children, next) { - bdrv_io_plug(child->bs); + bdrv_co_io_plug(child->bs); } =20 if (qatomic_fetch_inc(&bs->io_plugged) =3D=3D 0) { BlockDriver *drv =3D bs->drv; - if (drv && drv->bdrv_io_plug) { - drv->bdrv_io_plug(bs); + if (drv && drv->bdrv_co_io_plug) { + drv->bdrv_co_io_plug(bs); } } } diff --git a/block/nvme.c b/block/nvme.c index 656624c585..1af911e396 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1566,7 +1566,7 @@ static void nvme_attach_aio_context(BlockDriverState = *bs, } } =20 -static void nvme_aio_plug(BlockDriverState *bs) +static void coroutine_fn nvme_co_io_plug(BlockDriverState *bs) { BDRVNVMeState *s =3D bs->opaque; assert(!s->plugged); @@ -1663,7 +1663,7 @@ static BlockDriver bdrv_nvme =3D { .bdrv_detach_aio_context =3D nvme_detach_aio_context, .bdrv_attach_aio_context =3D nvme_attach_aio_context, =20 - .bdrv_io_plug =3D nvme_aio_plug, + .bdrv_co_io_plug =3D nvme_co_io_plug, .bdrv_io_unplug =3D nvme_aio_unplug, =20 .bdrv_register_buf =3D nvme_register_buf, --=20 2.38.1 From nobody Sat Apr 20 01:04:24 2024 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=1673642690; cv=none; d=zohomail.com; s=zohoarc; b=dICi1CXyV2Y+aNOVCXYNdoeuu+81oIY12YBF02f7L/xyDni4LjveXom87LtkMfLZ3cav+z7tcfQFyne18tQF6zTv0oaPzNAkaYBCvch+PHRs0v07ABA1xbiGhXmIfqkdtYYeylZRLIeEGXYhSrJNyRCM3YpGnCuM2LxHWnmvKmk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673642690; 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=8KHattQ48tUFa2/tg/FpyjwFPmzYdgOuIArxf0dr2Js=; b=CQS51HDspNOnMoHRGHNrsGLPTMXuI3G41nAz65eCbqEQx40goDfJHLw2Z05HnFy5UQnNTE6S3iRyhNZffnTf9djM9DEUHkBhxWfhfzLAhQ5MFcMtw1c043uVlF3h5zSSQvuvBI9BOLzuKZisX7CiwR/cKp7d8w2FJ5PJvGDDtTw= 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 1673642690656672.0486906611853; Fri, 13 Jan 2023 12:44:50 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGQsv-0008Ug-9k; Fri, 13 Jan 2023 15:42:45 -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 1pGQst-0008TK-AR for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:43 -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 1pGQsq-0006A7-VJ for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:43 -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-563-VwiOPbVxOAuasucmqRvuGg-1; Fri, 13 Jan 2023 15:42:35 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6BC04380671C; Fri, 13 Jan 2023 20:42:35 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.195.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 368E12026D68; Fri, 13 Jan 2023 20:42:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673642560; 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=8KHattQ48tUFa2/tg/FpyjwFPmzYdgOuIArxf0dr2Js=; b=SWbMdBIU64qVI/F/dlBuR9WzFMZKvxEC5/qQew3Xyq0ZeNt3031N9t6jcnvqLj7EHoyrNy SVLlRFFoPypEM2CYtpM99sxeNkEGlBEOVij7rto1otN9ZPCMO17FRwQJQSNNE5RFEoYuPV Z4XAeLHOdOg++AdaVaXFWJCKqNtYi6Q= X-MC-Unique: VwiOPbVxOAuasucmqRvuGg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v2 03/14] block: Convert bdrv_io_unplug() to co_wrapper Date: Fri, 13 Jan 2023 21:42:01 +0100 Message-Id: <20230113204212.359076-4-kwolf@redhat.com> In-Reply-To: <20230113204212.359076-1-kwolf@redhat.com> References: <20230113204212.359076-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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.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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1673642692881100002 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito BlockDriver->bdrv_io_unplug is categorized as IO callback, and it currently doesn't run in a coroutine. We should let it take a graph rdlock since the callback traverses the block nodes graph, which however is only possible in a coroutine. The only caller of this function is blk_io_unplug(), therefore make blk_io_unplug() a co_wrapper, so that we're always running in a coroutine where the lock can be taken. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 3 +-- include/block/block_int-common.h | 2 +- include/sysemu/block-backend-io.h | 4 +++- block/blkio.c | 4 ++-- block/block-backend.c | 4 ++-- block/file-posix.c | 10 +++++----- block/io.c | 8 ++++---- block/nvme.c | 4 ++-- 8 files changed, 20 insertions(+), 19 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index d96168375e..3bf201f7f4 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -218,8 +218,7 @@ void bdrv_coroutine_enter(BlockDriverState *bs, Corouti= ne *co); AioContext *child_of_bds_get_parent_aio_context(BdrvChild *c); =20 void coroutine_fn bdrv_co_io_plug(BlockDriverState *bs); - -void bdrv_io_unplug(BlockDriverState *bs); +void coroutine_fn 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 a76bb76290..253df92509 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -730,7 +730,7 @@ struct BlockDriver { =20 /* io queue for linux-aio */ void coroutine_fn (*bdrv_co_io_plug)(BlockDriverState *bs); - void (*bdrv_io_unplug)(BlockDriverState *bs); + void coroutine_fn (*bdrv_co_io_unplug)(BlockDriverState *bs); =20 /** * bdrv_drain_begin is called if implemented in the beginning of a diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index 70b73f7d11..d8cc8d74f5 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -76,7 +76,9 @@ int blk_get_max_hw_iov(BlockBackend *blk); void coroutine_fn blk_co_io_plug(BlockBackend *blk); void co_wrapper blk_io_plug(BlockBackend *blk); =20 -void blk_io_unplug(BlockBackend *blk); +void coroutine_fn blk_co_io_unplug(BlockBackend *blk); +void co_wrapper blk_io_unplug(BlockBackend *blk); + AioContext *blk_get_aio_context(BlockBackend *blk); BlockAcctStats *blk_get_stats(BlockBackend *blk); void *blk_aio_get(const AIOCBInfo *aiocb_info, BlockBackend *blk, diff --git a/block/blkio.c b/block/blkio.c index 5eae3adfaf..1ff51ff4f3 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -477,7 +477,7 @@ static int coroutine_fn blkio_co_pwrite_zeroes(BlockDri= verState *bs, return cod.ret; } =20 -static void blkio_io_unplug(BlockDriverState *bs) +static void coroutine_fn blkio_co_io_unplug(BlockDriverState *bs) { BDRVBlkioState *s =3D bs->opaque; =20 @@ -1006,7 +1006,7 @@ static void blkio_refresh_limits(BlockDriverState *bs= , Error **errp) .bdrv_co_pwritev =3D blkio_co_pwritev, \ .bdrv_co_flush_to_disk =3D blkio_co_flush, \ .bdrv_co_pwrite_zeroes =3D blkio_co_pwrite_zeroes, \ - .bdrv_io_unplug =3D blkio_io_unplug, \ + .bdrv_co_io_unplug =3D blkio_co_io_unplug, \ .bdrv_refresh_limits =3D blkio_refresh_limits, \ .bdrv_register_buf =3D blkio_register_buf, \ .bdrv_unregister_buf =3D blkio_unregister_buf, \ diff --git a/block/block-backend.c b/block/block-backend.c index 2bca5729e1..71c7ef4004 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2325,13 +2325,13 @@ void coroutine_fn blk_co_io_plug(BlockBackend *blk) } } =20 -void blk_io_unplug(BlockBackend *blk) +void coroutine_fn blk_co_io_unplug(BlockBackend *blk) { BlockDriverState *bs =3D blk_bs(blk); IO_CODE(); =20 if (bs) { - bdrv_io_unplug(bs); + bdrv_co_io_unplug(bs); } } =20 diff --git a/block/file-posix.c b/block/file-posix.c index c8551c8110..dd1b8ec52a 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2153,7 +2153,7 @@ static void coroutine_fn raw_co_io_plug(BlockDriverSt= ate *bs) #endif } =20 -static void raw_aio_unplug(BlockDriverState *bs) +static void coroutine_fn raw_co_io_unplug(BlockDriverState *bs) { BDRVRawState __attribute__((unused)) *s =3D bs->opaque; #ifdef CONFIG_LINUX_AIO @@ -3322,7 +3322,7 @@ BlockDriver bdrv_file =3D { .bdrv_co_copy_range_to =3D raw_co_copy_range_to, .bdrv_refresh_limits =3D raw_refresh_limits, .bdrv_co_io_plug =3D raw_co_io_plug, - .bdrv_io_unplug =3D raw_aio_unplug, + .bdrv_co_io_unplug =3D raw_co_io_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 .bdrv_co_truncate =3D raw_co_truncate, @@ -3694,7 +3694,7 @@ static BlockDriver bdrv_host_device =3D { .bdrv_co_copy_range_to =3D raw_co_copy_range_to, .bdrv_refresh_limits =3D raw_refresh_limits, .bdrv_co_io_plug =3D raw_co_io_plug, - .bdrv_io_unplug =3D raw_aio_unplug, + .bdrv_co_io_unplug =3D raw_co_io_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 .bdrv_co_truncate =3D raw_co_truncate, @@ -3818,7 +3818,7 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_co_flush_to_disk =3D raw_co_flush_to_disk, .bdrv_refresh_limits =3D raw_refresh_limits, .bdrv_co_io_plug =3D raw_co_io_plug, - .bdrv_io_unplug =3D raw_aio_unplug, + .bdrv_co_io_unplug =3D raw_co_io_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 .bdrv_co_truncate =3D raw_co_truncate, @@ -3948,7 +3948,7 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_co_flush_to_disk =3D raw_co_flush_to_disk, .bdrv_refresh_limits =3D raw_refresh_limits, .bdrv_co_io_plug =3D raw_co_io_plug, - .bdrv_io_unplug =3D raw_aio_unplug, + .bdrv_co_io_unplug =3D raw_co_io_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 .bdrv_co_truncate =3D raw_co_truncate, diff --git a/block/io.c b/block/io.c index c05fb89267..32c744d546 100644 --- a/block/io.c +++ b/block/io.c @@ -3153,7 +3153,7 @@ void coroutine_fn bdrv_co_io_plug(BlockDriverState *b= s) } } =20 -void bdrv_io_unplug(BlockDriverState *bs) +void coroutine_fn bdrv_co_io_unplug(BlockDriverState *bs) { BdrvChild *child; IO_CODE(); @@ -3161,13 +3161,13 @@ void bdrv_io_unplug(BlockDriverState *bs) assert(bs->io_plugged); if (qatomic_fetch_dec(&bs->io_plugged) =3D=3D 1) { BlockDriver *drv =3D bs->drv; - if (drv && drv->bdrv_io_unplug) { - drv->bdrv_io_unplug(bs); + if (drv && drv->bdrv_co_io_unplug) { + drv->bdrv_co_io_unplug(bs); } } =20 QLIST_FOREACH(child, &bs->children, next) { - bdrv_io_unplug(child->bs); + bdrv_co_io_unplug(child->bs); } } =20 diff --git a/block/nvme.c b/block/nvme.c index 1af911e396..eb940f2846 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1573,7 +1573,7 @@ static void coroutine_fn nvme_co_io_plug(BlockDriverS= tate *bs) s->plugged =3D true; } =20 -static void nvme_aio_unplug(BlockDriverState *bs) +static void coroutine_fn nvme_co_io_unplug(BlockDriverState *bs) { BDRVNVMeState *s =3D bs->opaque; assert(s->plugged); @@ -1664,7 +1664,7 @@ static BlockDriver bdrv_nvme =3D { .bdrv_attach_aio_context =3D nvme_attach_aio_context, =20 .bdrv_co_io_plug =3D nvme_co_io_plug, - .bdrv_io_unplug =3D nvme_aio_unplug, + .bdrv_co_io_unplug =3D nvme_co_io_unplug, =20 .bdrv_register_buf =3D nvme_register_buf, .bdrv_unregister_buf =3D nvme_unregister_buf, --=20 2.38.1 From nobody Sat Apr 20 01:04:24 2024 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=1673642595; cv=none; d=zohomail.com; s=zohoarc; b=TH5Zbm/PeWajbT7M7GdJXXXbsWQGQABGgWsRQNEpq/69stObIGHBVTlGisunXM6C3VnxMRB8+B4p5HCByXOeON8/rLfNQ1bqbqdEX+yJrOL8p6WbbvFxVS8ZCMUnIfvrs6Ia1B9jZ8UKV+B/L7tiUvPc23MTLyiYnwpepFS/SDA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673642595; 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=HYxX9vuqv+vqkdB3PRRnsyeTCGX5MJZCiHSTQfjvhvk=; b=NnjiWRHyKmuHPIuymcavbSqaMcGDPGvMEG/t8y3fw56LanhK89wkHkaZld2QVVKHv4cjxKUAhjSTJaqZ/VkTYXMpLwGTCIX6hHCfEXSMv2vORhsULAVKvt6rWAU0kx85uGZ9JlObvNKSVp/JNQNdCiYdGsfHnnuiU6N8VOaoUUo= 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 1673642595226461.20804092855224; Fri, 13 Jan 2023 12:43:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGQsw-0008VC-3J; Fri, 13 Jan 2023 15:42:46 -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 1pGQst-0008TO-DM for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:43 -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 1pGQsr-0006AG-6s for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:43 -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-347-ggCHNurAPWaZgZfvULnhbA-1; Fri, 13 Jan 2023 15:42:37 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DB1523C01DFE; Fri, 13 Jan 2023 20:42:36 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.195.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id AB1FF2026D68; Fri, 13 Jan 2023 20:42:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673642560; 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=HYxX9vuqv+vqkdB3PRRnsyeTCGX5MJZCiHSTQfjvhvk=; b=HRkjWxAqwrBSJGmLaJmf05PL0jz03trZEsLFt+/jaabehN5KIQW8ngIz+hk9h6+NEqi+fW 6tTAgtW/OfYUqd/XI5gAvc4jJ+B5/g1W3tUw458T0ZbEXNY0T88qSUoROicjzLvu3mAHo0 4mbteMhD+oxpvSFGLv/HHvhnubA02jI= X-MC-Unique: ggCHNurAPWaZgZfvULnhbA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v2 04/14] block: Convert bdrv_is_inserted() to co_wrapper Date: Fri, 13 Jan 2023 21:42:02 +0100 Message-Id: <20230113204212.359076-5-kwolf@redhat.com> In-Reply-To: <20230113204212.359076-1-kwolf@redhat.com> References: <20230113204212.359076-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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.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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1673642597012100003 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito bdrv_is_inserted() is categorized as an I/O function, and it currently doesn't run in a coroutine. We should let it take a graph rdlock since it traverses the block nodes graph, which however is only possible in a coroutine. Therefore turn it into a co_wrapper to move the actual function into a coroutine where the lock can be taken. At the same time, add also blk_is_inserted as co_wrapper_mixed, since it is called in both coroutine and non-coroutine contexts. Because now this function creates a new coroutine and polls, we need to take the AioContext lock where it is missing, for the only reason that internally c_w_mixed_bdrv_rdlock calls AIO_WAIT_WHILE and it expects to release the AioContext lock. Once the rwlock is ultimated and placed in every place it needs to be, we will poll using AIO_WAIT_WHILE_UNLOCKED and remove the AioContext lock. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 5 ++++- include/block/block_int-common.h | 2 +- include/sysemu/block-backend-io.h | 5 ++++- block.c | 8 ++++---- block/block-backend.c | 4 ++-- block/file-posix.c | 8 ++++---- block/io.c | 12 ++++++------ blockdev.c | 8 +++++++- 8 files changed, 32 insertions(+), 20 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 3bf201f7f4..fe031360c4 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -133,7 +133,10 @@ bool bdrv_is_read_only(BlockDriverState *bs); bool bdrv_is_writable(BlockDriverState *bs); bool bdrv_is_sg(BlockDriverState *bs); int bdrv_get_flags(BlockDriverState *bs); -bool bdrv_is_inserted(BlockDriverState *bs); + +bool coroutine_fn bdrv_co_is_inserted(BlockDriverState *bs); +bool co_wrapper bdrv_is_inserted(BlockDriverState *bs); + void bdrv_lock_medium(BlockDriverState *bs, bool locked); void bdrv_eject(BlockDriverState *bs, bool eject_flag); const char *bdrv_get_format_name(BlockDriverState *bs); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 253df92509..e6229c64e6 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -708,7 +708,7 @@ struct BlockDriver { BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); =20 /* removable device specific */ - bool (*bdrv_is_inserted)(BlockDriverState *bs); + bool coroutine_fn (*bdrv_co_is_inserted)(BlockDriverState *bs); void (*bdrv_eject)(BlockDriverState *bs, bool eject_flag); void (*bdrv_lock_medium)(BlockDriverState *bs, bool locked); =20 diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index d8cc8d74f5..4358fc6476 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -53,7 +53,10 @@ BlockAIOCB *blk_aio_ioctl(BlockBackend *blk, unsigned lo= ng int req, void *buf, =20 void blk_inc_in_flight(BlockBackend *blk); void blk_dec_in_flight(BlockBackend *blk); -bool blk_is_inserted(BlockBackend *blk); + +bool coroutine_fn blk_co_is_inserted(BlockBackend *blk); +bool co_wrapper_mixed blk_is_inserted(BlockBackend *blk); + bool blk_is_available(BlockBackend *blk); void blk_lock_medium(BlockBackend *blk, bool locked); void blk_eject(BlockBackend *blk, bool eject_flag); diff --git a/block.c b/block.c index 9c2ac757e4..e89844557b 100644 --- a/block.c +++ b/block.c @@ -6781,7 +6781,7 @@ out: /** * Return TRUE if the media is present */ -bool bdrv_is_inserted(BlockDriverState *bs) +bool coroutine_fn bdrv_co_is_inserted(BlockDriverState *bs) { BlockDriver *drv =3D bs->drv; BdrvChild *child; @@ -6790,11 +6790,11 @@ bool bdrv_is_inserted(BlockDriverState *bs) if (!drv) { return false; } - if (drv->bdrv_is_inserted) { - return drv->bdrv_is_inserted(bs); + if (drv->bdrv_co_is_inserted) { + return drv->bdrv_co_is_inserted(bs); } QLIST_FOREACH(child, &bs->children, next) { - if (!bdrv_is_inserted(child->bs)) { + if (!bdrv_co_is_inserted(child->bs)) { return false; } } diff --git a/block/block-backend.c b/block/block-backend.c index 71c7ef4004..6e3b3b9fe8 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1983,12 +1983,12 @@ void blk_activate(BlockBackend *blk, Error **errp) bdrv_activate(bs, errp); } =20 -bool blk_is_inserted(BlockBackend *blk) +bool coroutine_fn blk_co_is_inserted(BlockBackend *blk) { BlockDriverState *bs =3D blk_bs(blk); IO_CODE(); =20 - return bs && bdrv_is_inserted(bs); + return bs && bdrv_co_is_inserted(bs); } =20 bool blk_is_available(BlockBackend *blk) diff --git a/block/file-posix.c b/block/file-posix.c index dd1b8ec52a..b29cd02b30 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3761,7 +3761,7 @@ out: return prio; } =20 -static bool cdrom_is_inserted(BlockDriverState *bs) +static bool coroutine_fn cdrom_co_is_inserted(BlockDriverState *bs) { BDRVRawState *s =3D bs->opaque; int ret; @@ -3828,7 +3828,7 @@ static BlockDriver bdrv_host_cdrom =3D { =3D raw_get_allocated_file_size, =20 /* removable device support */ - .bdrv_is_inserted =3D cdrom_is_inserted, + .bdrv_co_is_inserted =3D cdrom_co_is_inserted, .bdrv_eject =3D cdrom_eject, .bdrv_lock_medium =3D cdrom_lock_medium, =20 @@ -3887,7 +3887,7 @@ static int cdrom_reopen(BlockDriverState *bs) return 0; } =20 -static bool cdrom_is_inserted(BlockDriverState *bs) +static bool coroutine_fn cdrom_co_is_inserted(BlockDriverState *bs) { return raw_getlength(bs) > 0; } @@ -3958,7 +3958,7 @@ static BlockDriver bdrv_host_cdrom =3D { =3D raw_get_allocated_file_size, =20 /* removable device support */ - .bdrv_is_inserted =3D cdrom_is_inserted, + .bdrv_co_is_inserted =3D cdrom_co_is_inserted, .bdrv_eject =3D cdrom_eject, .bdrv_lock_medium =3D cdrom_lock_medium, }; diff --git a/block/io.c b/block/io.c index 32c744d546..03becd32d2 100644 --- a/block/io.c +++ b/block/io.c @@ -1621,7 +1621,7 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, =20 trace_bdrv_co_preadv_part(bs, offset, bytes, flags); =20 - if (!bdrv_is_inserted(bs)) { + if (!bdrv_co_is_inserted(bs)) { return -ENOMEDIUM; } =20 @@ -2066,7 +2066,7 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *chil= d, =20 trace_bdrv_co_pwritev_part(child->bs, offset, bytes, flags); =20 - if (!bdrv_is_inserted(bs)) { + if (!bdrv_co_is_inserted(bs)) { return -ENOMEDIUM; } =20 @@ -2834,7 +2834,7 @@ int coroutine_fn bdrv_co_flush(BlockDriverState *bs) =20 bdrv_inc_in_flight(bs); =20 - if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs) || + if (!bdrv_co_is_inserted(bs) || bdrv_is_read_only(bs) || bdrv_is_sg(bs)) { goto early_exit; } @@ -2958,7 +2958,7 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, i= nt64_t offset, BlockDriverState *bs =3D child->bs; IO_CODE(); =20 - if (!bs || !bs->drv || !bdrv_is_inserted(bs)) { + if (!bs || !bs->drv || !bdrv_co_is_inserted(bs)) { return -ENOMEDIUM; } =20 @@ -3240,7 +3240,7 @@ static int coroutine_fn bdrv_co_copy_range_internal( assert(!(read_flags & BDRV_REQ_NO_WAIT)); assert(!(write_flags & BDRV_REQ_NO_WAIT)); =20 - if (!dst || !dst->bs || !bdrv_is_inserted(dst->bs)) { + if (!dst || !dst->bs || !bdrv_co_is_inserted(dst->bs)) { return -ENOMEDIUM; } ret =3D bdrv_check_request32(dst_offset, bytes, NULL, 0); @@ -3251,7 +3251,7 @@ static int coroutine_fn bdrv_co_copy_range_internal( return bdrv_co_pwrite_zeroes(dst, dst_offset, bytes, write_flags); } =20 - if (!src || !src->bs || !bdrv_is_inserted(src->bs)) { + if (!src || !src->bs || !bdrv_co_is_inserted(src->bs)) { return -ENOMEDIUM; } ret =3D bdrv_check_request32(src_offset, bytes, NULL, 0); diff --git a/blockdev.c b/blockdev.c index ebf952cd21..ec9271ce49 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1023,6 +1023,7 @@ fail: static BlockDriverState *qmp_get_root_bs(const char *name, Error **errp) { BlockDriverState *bs; + AioContext *aio_context; =20 bs =3D bdrv_lookup_bs(name, name, errp); if (bs =3D=3D NULL) { @@ -1034,11 +1035,16 @@ static BlockDriverState *qmp_get_root_bs(const char= *name, Error **errp) return NULL; } =20 + aio_context =3D bdrv_get_aio_context(bs); + aio_context_acquire(aio_context); + if (!bdrv_is_inserted(bs)) { error_setg(errp, "Device has no medium"); - return NULL; + bs =3D NULL; } =20 + aio_context_release(aio_context); + return bs; } =20 --=20 2.38.1 From nobody Sat Apr 20 01:04:24 2024 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=1673642704; cv=none; d=zohomail.com; s=zohoarc; b=HzqIzJyUnUIG2WBIV8JjjQOn3lEqIKRBVCjPaCnDBPIi+ZIvq5t+2WueNUy1vuXMjmE8GU+iG+HselVqBOnqvvH9shAtbYg/tFDIeRKn7Z3/IkZt6M2lLz9yoJCfnEI9HTNFwCknjgI5ZxvVMcj9/jeZfmhFqG3JpmgYtEYp8V8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673642704; 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=sIbV6Io5SFMWMIK2saSNjq+6vb91PnROYlgpMfje74o=; b=Eb+ID25lwlkijE3lrUWnf6i2GhuH41j5IwoO4PiWQNyCVyP3YA+aUdUqabvaujLdmrPQFCmFGseqZOO/oGgN8D7OOncTgFRtIK04HdmpCbriQ+NSeY8QIy43jiX32YL8X8ZilOGvHY9Z+cvgHRERNORNozOjyMlby1Qz1gFH8f0= 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 1673642704025744.9612188359321; Fri, 13 Jan 2023 12:45:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGQsv-0008Uj-By; Fri, 13 Jan 2023 15:42:45 -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 1pGQsu-0008U4-2r for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:44 -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 1pGQss-0006Ae-EY for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:43 -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-596-38ZMUdYAPZKZUK4ExjxRzQ-1; Fri, 13 Jan 2023 15:42:38 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 523CC811E6E; Fri, 13 Jan 2023 20:42:38 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.195.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2546A2026D68; Fri, 13 Jan 2023 20:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673642561; 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=sIbV6Io5SFMWMIK2saSNjq+6vb91PnROYlgpMfje74o=; b=F4YH12oeFinRETreedUhFpow/uMA6HKMU6VrIANEfT2PWCwCdIVgRIniuKJBYht79Yb7M3 DKrLRXYZTQymz92UL9YvqIS53aN/zowpxZg2T6Xczf4YSJ/LVOuUf15BADaHEG2GGvQoTm +n/xY3rQbyb3L/Ue7ZLMz6UWimG8Mf0= X-MC-Unique: 38ZMUdYAPZKZUK4ExjxRzQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v2 05/14] block: Rename refresh_total_sectors to bdrv_refresh_total_sectors Date: Fri, 13 Jan 2023 21:42:03 +0100 Message-Id: <20230113204212.359076-6-kwolf@redhat.com> In-Reply-To: <20230113204212.359076-1-kwolf@redhat.com> References: <20230113204212.359076-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: 1673642704924100002 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito The name is not good, not the least because we are going to convert this to a generated co_wrapper, which adds a _co infix after the first part of the name. No functional change intended. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block_int-io.h | 2 +- block.c | 8 ++++---- block/io.c | 8 +++++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 8bc061ebb8..6b285fb520 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -120,7 +120,7 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src, = int64_t src_offset, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags); =20 -int refresh_total_sectors(BlockDriverState *bs, int64_t hint); +int bdrv_refresh_total_sectors(BlockDriverState *bs, int64_t hint); =20 BdrvChild *bdrv_cow_child(BlockDriverState *bs); BdrvChild *bdrv_filter_child(BlockDriverState *bs); diff --git a/block.c b/block.c index e89844557b..7c279fc0e6 100644 --- a/block.c +++ b/block.c @@ -1034,7 +1034,7 @@ static int find_image_format(BlockBackend *file, cons= t char *filename, * Set the current 'total_sectors' value * Return 0 on success, -errno on error. */ -int refresh_total_sectors(BlockDriverState *bs, int64_t hint) +int bdrv_refresh_total_sectors(BlockDriverState *bs, int64_t hint) { BlockDriver *drv =3D bs->drv; IO_CODE(); @@ -1651,7 +1651,7 @@ static int bdrv_open_driver(BlockDriverState *bs, Blo= ckDriver *drv, bs->supported_read_flags |=3D BDRV_REQ_REGISTERED_BUF; bs->supported_write_flags |=3D BDRV_REQ_REGISTERED_BUF; =20 - ret =3D refresh_total_sectors(bs, bs->total_sectors); + ret =3D bdrv_refresh_total_sectors(bs, bs->total_sectors); if (ret < 0) { error_setg_errno(errp, -ret, "Could not refresh total sector count= "); return ret; @@ -5808,7 +5808,7 @@ int64_t bdrv_nb_sectors(BlockDriverState *bs) return -ENOMEDIUM; =20 if (drv->has_variable_length) { - int ret =3D refresh_total_sectors(bs, bs->total_sectors); + int ret =3D bdrv_refresh_total_sectors(bs, bs->total_sectors); if (ret < 0) { return ret; } @@ -6590,7 +6590,7 @@ int bdrv_activate(BlockDriverState *bs, Error **errp) bdrv_dirty_bitmap_skip_store(bm, false); } =20 - ret =3D refresh_total_sectors(bs, bs->total_sectors); + ret =3D bdrv_refresh_total_sectors(bs, bs->total_sectors); if (ret < 0) { bs->open_flags |=3D BDRV_O_INACTIVE; error_setg_errno(errp, -ret, "Could not refresh total sector c= ount"); diff --git a/block/io.c b/block/io.c index 03becd32d2..e5e51563a5 100644 --- a/block/io.c +++ b/block/io.c @@ -3473,15 +3473,17 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child,= int64_t offset, bool exact, goto out; } =20 - ret =3D refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); + ret =3D bdrv_refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); if (ret < 0) { error_setg_errno(errp, -ret, "Could not refresh total sector count= "); } else { offset =3D bs->total_sectors * BDRV_SECTOR_SIZE; } - /* It's possible that truncation succeeded but refresh_total_sectors + /* + * It's possible that truncation succeeded but bdrv_refresh_total_sect= ors * failed, but the latter doesn't affect how we should finish the requ= est. - * Pass 0 as the last parameter so that dirty bitmaps etc. are handled= . */ + * Pass 0 as the last parameter so that dirty bitmaps etc. are handled. + */ bdrv_co_write_req_finish(child, offset - new_bytes, new_bytes, &req, 0= ); =20 out: --=20 2.38.1 From nobody Sat Apr 20 01:04:24 2024 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=1673642601; cv=none; d=zohomail.com; s=zohoarc; b=UprgECVtxsGoqSMhUT3fwFPZIH42UEDYAR+LLwhcBHBqcXni9Asdk7JkTwDvrWrU4mHBtxSEpy1DFDTCe8cwF4sdBCpmgpshnsjox0MLuMo1RU/zvlCUn/0sKFaXYpLBJczDAl1mMD4B8Angf3GhTqd1mvF9YLSYwVNj9fHVwmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673642601; 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=JjvDLTEPEKuTe78UX+Foo/snmMxV4GEU4/C50lOdrls=; b=VocWO4K+9tprzELOiYqlfVDEc6lw0vvA8NZMhQ4AkemS/sQ+qfvaMFrB0LzTZL1Yiu5hGbRbt0Rhg1uUr3Y8sMEIcicQddNA/qVbbfIBuRxaRLEQPBDat1R4kX6QOeprEAZ3I12ofOEGosEHJ5xTK0l6SrejRqmzxhh1diM6lVc= 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 1673642601768150.09634528001402; Fri, 13 Jan 2023 12:43:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGQt1-00006x-W5; Fri, 13 Jan 2023 15:42:52 -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 1pGQsz-000053-4p for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:49 -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 1pGQsu-0006BL-7y for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:48 -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-605-hpLUS7r3NMuibzIxDRsKBg-1; Fri, 13 Jan 2023 15:42:40 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 094443C01DFC; Fri, 13 Jan 2023 20:42:40 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.195.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 945AC2026D68; Fri, 13 Jan 2023 20:42:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673642563; 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=JjvDLTEPEKuTe78UX+Foo/snmMxV4GEU4/C50lOdrls=; b=Fszt96h+FY0bTNiSG3bRA+JBNO4Ia5Z71eIHG81zcb84+8bucT1iZibhS2Tq051ek3KccY xJGdCNgly4PN+n1IFm1ad9mOlEIBeGPYi9eM7/FmcKwjJfrUiljv5wgajWgvdszSKt4Tp2 F/D5klOA7sl4SEw1R84HiXPZAv4GRBk= X-MC-Unique: hpLUS7r3NMuibzIxDRsKBg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v2 06/14] block: Convert bdrv_refresh_total_sectors() to co_wrapper_mixed Date: Fri, 13 Jan 2023 21:42:04 +0100 Message-Id: <20230113204212.359076-7-kwolf@redhat.com> In-Reply-To: <20230113204212.359076-1-kwolf@redhat.com> References: <20230113204212.359076-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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.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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1673642602370100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito BlockDriver->bdrv_getlength is categorized as IO callback, and it currently doesn't run in a coroutine. We should let it take a graph rdlock since the callback traverses the block nodes graph, which however is only possible in a coroutine. Therefore turn it into a co_wrapper to move the actual function into a coroutine where the lock can be taken. Because now this function creates a new coroutine and polls, we need to take the AioContext lock where it is missing, for the only reason that internally co_wrapper calls AIO_WAIT_WHILE and it expects to release the AioContext lock. This is especially messy when a co_wrapper creates a coroutine and polls in bdrv_open_driver, because this function has so many callers in so many context that it can easily lead to deadlocks. Therefore the new rule for bdrv_open_driver is that the caller must always hold the AioContext lock of the given bs (except if it is a coroutine), because the function calls bdrv_refresh_total_sectors() which is now a co_wrapper. Once the rwlock is ultimated and placed in every place it needs to be, we will poll using AIO_WAIT_WHILE_UNLOCKED and remove the AioContext lock. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 8 ++++-- include/block/block_int-common.h | 2 +- include/block/block_int-io.h | 5 +++- include/sysemu/block-backend-io.h | 10 ++++++-- block.c | 32 +++++++++++++++++------ block/blkdebug.c | 6 ++--- block/blkio.c | 6 ++--- block/blklogwrites.c | 6 ++--- block/blkreplay.c | 6 ++--- block/blkverify.c | 6 ++--- block/block-backend.c | 10 +++++--- block/commit.c | 4 +-- block/copy-on-read.c | 6 ++--- block/crypto.c | 6 ++--- block/curl.c | 10 ++++---- block/file-posix.c | 42 +++++++++++++++---------------- block/file-win32.c | 8 +++--- block/filter-compress.c | 6 ++--- block/gluster.c | 12 ++++----- block/iscsi.c | 10 ++++---- block/mirror.c | 4 +-- block/nbd.c | 8 +++--- block/null.c | 6 ++--- block/nvme.c | 6 ++--- block/preallocate.c | 10 ++++---- block/qed.c | 4 +-- block/quorum.c | 8 +++--- block/raw-format.c | 6 ++--- block/rbd.c | 4 +-- block/replication.c | 6 ++--- block/ssh.c | 4 +-- block/throttle.c | 6 ++--- hw/scsi/scsi-disk.c | 5 ++++ tests/unit/test-block-iothread.c | 3 +++ block/meson.build | 1 + 35 files changed, 161 insertions(+), 121 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index fe031360c4..4dcb5f73fa 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -73,8 +73,12 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, int6= 4_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags = flags, Error **errp); =20 -int64_t bdrv_nb_sectors(BlockDriverState *bs); -int64_t bdrv_getlength(BlockDriverState *bs); +int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState *bs); +int64_t co_wrapper_mixed bdrv_nb_sectors(BlockDriverState *bs); + +int64_t coroutine_fn bdrv_co_getlength(BlockDriverState *bs); +int64_t co_wrapper_mixed bdrv_getlength(BlockDriverState *bs); + int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); BlockMeasureInfo *bdrv_measure(BlockDriver *drv, QemuOpts *opts, BlockDriverState *in_bs, Error **errp); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index e6229c64e6..6336c7239a 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -684,7 +684,7 @@ struct BlockDriver { int coroutine_fn (*bdrv_co_truncate)(BlockDriverState *bs, int64_t off= set, bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **e= rrp); - int64_t (*bdrv_getlength)(BlockDriverState *bs); + int64_t coroutine_fn (*bdrv_co_getlength)(BlockDriverState *bs); int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs); BlockMeasureInfo *(*bdrv_measure)(QemuOpts *opts, BlockDriverState *in= _bs, Error **errp); diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 6b285fb520..d1559a501f 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -120,7 +120,10 @@ int coroutine_fn bdrv_co_copy_range_to(BdrvChild *src,= int64_t src_offset, BdrvRequestFlags read_flags, BdrvRequestFlags write_flags); =20 -int bdrv_refresh_total_sectors(BlockDriverState *bs, int64_t hint); +int coroutine_fn bdrv_co_refresh_total_sectors(BlockDriverState *bs, + int64_t hint); +int co_wrapper_mixed +bdrv_refresh_total_sectors(BlockDriverState *bs, int64_t hint); =20 BdrvChild *bdrv_cow_child(BlockDriverState *bs); BdrvChild *bdrv_filter_child(BlockDriverState *bs); diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index 4358fc6476..a1eac6c00a 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -60,9 +60,15 @@ bool co_wrapper_mixed blk_is_inserted(BlockBackend *blk); bool blk_is_available(BlockBackend *blk); void blk_lock_medium(BlockBackend *blk, bool locked); void blk_eject(BlockBackend *blk, bool eject_flag); -int64_t blk_getlength(BlockBackend *blk); + +int64_t coroutine_fn blk_co_getlength(BlockBackend *blk); +int64_t co_wrapper_mixed blk_getlength(BlockBackend *blk); + void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr); -int64_t blk_nb_sectors(BlockBackend *blk); + +int64_t coroutine_fn blk_co_nb_sectors(BlockBackend *blk); +int64_t co_wrapper_mixed blk_nb_sectors(BlockBackend *blk); + void *blk_try_blockalign(BlockBackend *blk, size_t size); void *blk_blockalign(BlockBackend *blk, size_t size); bool blk_is_writable(BlockBackend *blk); diff --git a/block.c b/block.c index 7c279fc0e6..dd22a206f9 100644 --- a/block.c +++ b/block.c @@ -1034,7 +1034,8 @@ static int find_image_format(BlockBackend *file, cons= t char *filename, * Set the current 'total_sectors' value * Return 0 on success, -errno on error. */ -int bdrv_refresh_total_sectors(BlockDriverState *bs, int64_t hint) +int coroutine_fn bdrv_co_refresh_total_sectors(BlockDriverState *bs, + int64_t hint) { BlockDriver *drv =3D bs->drv; IO_CODE(); @@ -1043,13 +1044,13 @@ int bdrv_refresh_total_sectors(BlockDriverState *bs= , int64_t hint) return -ENOMEDIUM; } =20 - /* Do not attempt drv->bdrv_getlength() on scsi-generic devices */ + /* Do not attempt drv->bdrv_co_getlength() on scsi-generic devices */ if (bdrv_is_sg(bs)) return 0; =20 /* query actual device if possible, otherwise just trust the hint */ - if (drv->bdrv_getlength) { - int64_t length =3D drv->bdrv_getlength(bs); + if (drv->bdrv_co_getlength) { + int64_t length =3D drv->bdrv_co_getlength(bs); if (length < 0) { return length; } @@ -1600,6 +1601,11 @@ out: g_free(gen_node_name); } =20 +/* + * The caller must always hold @bs AioContext lock, because this function = calls + * bdrv_refresh_total_sectors() which polls when called from non-coroutine + * context. + */ static int bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv, const char *node_name, QDict *options, int open_flags, Error **errp) @@ -3795,6 +3801,10 @@ out: * The reference parameter may be used to specify an existing block device= which * should be opened. If specified, neither options nor a filename may be g= iven, * nor can an existing BDS be reused (that is, *pbs has to be NULL). + * + * The caller must always hold @filename AioContext lock, because this + * function eventually calls bdrv_refresh_total_sectors() which polls + * when called from non-coroutine context. */ static BlockDriverState *bdrv_open_inherit(const char *filename, const char *reference, @@ -4083,6 +4093,11 @@ close_and_fail: return NULL; } =20 +/* + * The caller must always hold @filename AioContext lock, because this + * function eventually calls bdrv_refresh_total_sectors() which polls + * when called from non-coroutine context. + */ BlockDriverState *bdrv_open(const char *filename, const char *reference, QDict *options, int flags, Error **errp) { @@ -5799,7 +5814,7 @@ BlockMeasureInfo *bdrv_measure(BlockDriver *drv, Qemu= Opts *opts, /** * Return number of sectors on success, -errno on error. */ -int64_t bdrv_nb_sectors(BlockDriverState *bs) +int64_t coroutine_fn bdrv_co_nb_sectors(BlockDriverState *bs) { BlockDriver *drv =3D bs->drv; IO_CODE(); @@ -5808,7 +5823,7 @@ int64_t bdrv_nb_sectors(BlockDriverState *bs) return -ENOMEDIUM; =20 if (drv->has_variable_length) { - int ret =3D bdrv_refresh_total_sectors(bs, bs->total_sectors); + int ret =3D bdrv_co_refresh_total_sectors(bs, bs->total_sectors); if (ret < 0) { return ret; } @@ -5820,11 +5835,12 @@ int64_t bdrv_nb_sectors(BlockDriverState *bs) * Return length in bytes on success, -errno on error. * The length is always a multiple of BDRV_SECTOR_SIZE. */ -int64_t bdrv_getlength(BlockDriverState *bs) +int64_t coroutine_fn bdrv_co_getlength(BlockDriverState *bs) { - int64_t ret =3D bdrv_nb_sectors(bs); + int64_t ret; IO_CODE(); =20 + ret =3D bdrv_co_nb_sectors(bs); if (ret < 0) { return ret; } diff --git a/block/blkdebug.c b/block/blkdebug.c index ca65b043f0..2294b0227b 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -965,9 +965,9 @@ static bool blkdebug_debug_is_suspended(BlockDriverStat= e *bs, const char *tag) return false; } =20 -static int64_t blkdebug_getlength(BlockDriverState *bs) +static int64_t coroutine_fn blkdebug_co_getlength(BlockDriverState *bs) { - return bdrv_getlength(bs->file->bs); + return bdrv_co_getlength(bs->file->bs); } =20 static void blkdebug_refresh_filename(BlockDriverState *bs) @@ -1074,7 +1074,7 @@ static BlockDriver bdrv_blkdebug =3D { .bdrv_reopen_prepare =3D blkdebug_reopen_prepare, .bdrv_child_perm =3D blkdebug_child_perm, =20 - .bdrv_getlength =3D blkdebug_getlength, + .bdrv_co_getlength =3D blkdebug_co_getlength, .bdrv_refresh_filename =3D blkdebug_refresh_filename, .bdrv_refresh_limits =3D blkdebug_refresh_limits, =20 diff --git a/block/blkio.c b/block/blkio.c index 1ff51ff4f3..2a3ab5a570 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -837,7 +837,7 @@ static void blkio_close(BlockDriverState *bs) } } =20 -static int64_t blkio_getlength(BlockDriverState *bs) +static int64_t coroutine_fn blkio_co_getlength(BlockDriverState *bs) { BDRVBlkioState *s =3D bs->opaque; uint64_t capacity; @@ -865,7 +865,7 @@ static int coroutine_fn blkio_truncate(BlockDriverState= *bs, int64_t offset, return -ENOTSUP; } =20 - current_length =3D blkio_getlength(bs); + current_length =3D blkio_co_getlength(bs); =20 if (offset > current_length) { error_setg(errp, "Cannot grow device"); @@ -996,7 +996,7 @@ static void blkio_refresh_limits(BlockDriverState *bs, = Error **errp) .instance_size =3D sizeof(BDRVBlkioState), \ .bdrv_file_open =3D blkio_file_open, \ .bdrv_close =3D blkio_close, \ - .bdrv_getlength =3D blkio_getlength, \ + .bdrv_co_getlength =3D blkio_co_getlength, \ .bdrv_co_truncate =3D blkio_truncate, \ .bdrv_get_info =3D blkio_get_info, \ .bdrv_attach_aio_context =3D blkio_attach_aio_context, \ diff --git a/block/blklogwrites.c b/block/blklogwrites.c index cef9efe55d..6cb48d6ada 100644 --- a/block/blklogwrites.c +++ b/block/blklogwrites.c @@ -266,9 +266,9 @@ static void blk_log_writes_close(BlockDriverState *bs) s->log_file =3D NULL; } =20 -static int64_t blk_log_writes_getlength(BlockDriverState *bs) +static int64_t coroutine_fn blk_log_writes_co_getlength(BlockDriverState *= bs) { - return bdrv_getlength(bs->file->bs); + return bdrv_co_getlength(bs->file->bs); } =20 static void blk_log_writes_child_perm(BlockDriverState *bs, BdrvChild *c, @@ -497,7 +497,7 @@ static BlockDriver bdrv_blk_log_writes =3D { =20 .bdrv_open =3D blk_log_writes_open, .bdrv_close =3D blk_log_writes_close, - .bdrv_getlength =3D blk_log_writes_getlength, + .bdrv_co_getlength =3D blk_log_writes_co_getlength, .bdrv_child_perm =3D blk_log_writes_child_perm, .bdrv_refresh_limits =3D blk_log_writes_refresh_limits, =20 diff --git a/block/blkreplay.c b/block/blkreplay.c index 76a0b8d12a..fa1073fe4a 100644 --- a/block/blkreplay.c +++ b/block/blkreplay.c @@ -39,9 +39,9 @@ fail: return ret; } =20 -static int64_t blkreplay_getlength(BlockDriverState *bs) +static int64_t coroutine_fn blkreplay_co_getlength(BlockDriverState *bs) { - return bdrv_getlength(bs->file->bs); + return bdrv_co_getlength(bs->file->bs); } =20 /* This bh is used for synchronization of return from coroutines. @@ -135,7 +135,7 @@ static BlockDriver bdrv_blkreplay =3D { =20 .bdrv_open =3D blkreplay_open, .bdrv_child_perm =3D bdrv_default_perms, - .bdrv_getlength =3D blkreplay_getlength, + .bdrv_co_getlength =3D blkreplay_co_getlength, =20 .bdrv_co_preadv =3D blkreplay_co_preadv, .bdrv_co_pwritev =3D blkreplay_co_pwritev, diff --git a/block/blkverify.c b/block/blkverify.c index c60a2dc624..acd730906d 100644 --- a/block/blkverify.c +++ b/block/blkverify.c @@ -154,11 +154,11 @@ static void blkverify_close(BlockDriverState *bs) s->test_file =3D NULL; } =20 -static int64_t blkverify_getlength(BlockDriverState *bs) +static int64_t coroutine_fn blkverify_co_getlength(BlockDriverState *bs) { BDRVBlkverifyState *s =3D bs->opaque; =20 - return bdrv_getlength(s->test_file->bs); + return bdrv_co_getlength(s->test_file->bs); } =20 static void coroutine_fn blkverify_do_test_req(void *opaque) @@ -313,7 +313,7 @@ static BlockDriver bdrv_blkverify =3D { .bdrv_file_open =3D blkverify_open, .bdrv_close =3D blkverify_close, .bdrv_child_perm =3D bdrv_default_perms, - .bdrv_getlength =3D blkverify_getlength, + .bdrv_co_getlength =3D blkverify_co_getlength, .bdrv_refresh_filename =3D blkverify_refresh_filename, .bdrv_dirname =3D blkverify_dirname, =20 diff --git a/block/block-backend.c b/block/block-backend.c index 6e3b3b9fe8..6e5e2693b3 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1599,14 +1599,15 @@ BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk= , int64_t offset, flags | BDRV_REQ_ZERO_WRITE, cb, opaque); } =20 -int64_t blk_getlength(BlockBackend *blk) +int64_t coroutine_fn blk_co_getlength(BlockBackend *blk) { IO_CODE(); + if (!blk_is_available(blk)) { return -ENOMEDIUM; } =20 - return bdrv_getlength(blk_bs(blk)); + return bdrv_co_getlength(blk_bs(blk)); } =20 void blk_get_geometry(BlockBackend *blk, uint64_t *nb_sectors_ptr) @@ -1619,14 +1620,15 @@ void blk_get_geometry(BlockBackend *blk, uint64_t *= nb_sectors_ptr) } } =20 -int64_t blk_nb_sectors(BlockBackend *blk) +int64_t coroutine_fn blk_co_nb_sectors(BlockBackend *blk) { IO_CODE(); + if (!blk_is_available(blk)) { return -ENOMEDIUM; } =20 - return bdrv_nb_sectors(blk_bs(blk)); + return bdrv_co_nb_sectors(blk_bs(blk)); } =20 BlockAIOCB *blk_aio_preadv(BlockBackend *blk, int64_t offset, diff --git a/block/commit.c b/block/commit.c index b346341767..41e3599281 100644 --- a/block/commit.c +++ b/block/commit.c @@ -123,13 +123,13 @@ static int coroutine_fn commit_run(Job *job, Error **= errp) QEMU_AUTO_VFREE void *buf =3D NULL; int64_t len, base_len; =20 - len =3D blk_getlength(s->top); + len =3D blk_co_getlength(s->top); if (len < 0) { return len; } job_progress_set_remaining(&s->common.job, len); =20 - base_len =3D blk_getlength(s->base); + base_len =3D blk_co_getlength(s->base); if (base_len < 0) { return base_len; } diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 815ac1d835..41777b87a4 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -120,9 +120,9 @@ static void cor_child_perm(BlockDriverState *bs, BdrvCh= ild *c, } =20 =20 -static int64_t cor_getlength(BlockDriverState *bs) +static int64_t coroutine_fn cor_co_getlength(BlockDriverState *bs) { - return bdrv_getlength(bs->file->bs); + return bdrv_co_getlength(bs->file->bs); } =20 =20 @@ -249,7 +249,7 @@ static BlockDriver bdrv_copy_on_read =3D { .bdrv_close =3D cor_close, .bdrv_child_perm =3D cor_child_perm, =20 - .bdrv_getlength =3D cor_getlength, + .bdrv_co_getlength =3D cor_co_getlength, =20 .bdrv_co_preadv_part =3D cor_co_preadv_part, .bdrv_co_pwritev_part =3D cor_co_pwritev_part, diff --git a/block/crypto.c b/block/crypto.c index bbeb9f437c..6d6c006887 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -531,10 +531,10 @@ static void block_crypto_refresh_limits(BlockDriverSt= ate *bs, Error **errp) } =20 =20 -static int64_t block_crypto_getlength(BlockDriverState *bs) +static int64_t coroutine_fn block_crypto_co_getlength(BlockDriverState *bs) { BlockCrypto *crypto =3D bs->opaque; - int64_t len =3D bdrv_getlength(bs->file->bs); + int64_t len =3D bdrv_co_getlength(bs->file->bs); =20 uint64_t offset =3D qcrypto_block_get_payload_offset(crypto->block); assert(offset < INT64_MAX); @@ -953,7 +953,7 @@ static BlockDriver bdrv_crypto_luks =3D { .bdrv_refresh_limits =3D block_crypto_refresh_limits, .bdrv_co_preadv =3D block_crypto_co_preadv, .bdrv_co_pwritev =3D block_crypto_co_pwritev, - .bdrv_getlength =3D block_crypto_getlength, + .bdrv_co_getlength =3D block_crypto_co_getlength, .bdrv_measure =3D block_crypto_measure, .bdrv_get_info =3D block_crypto_get_info_luks, .bdrv_get_specific_info =3D block_crypto_get_specific_info_luks, diff --git a/block/curl.c b/block/curl.c index cba4c4cac7..d60596e57f 100644 --- a/block/curl.c +++ b/block/curl.c @@ -957,7 +957,7 @@ static void curl_close(BlockDriverState *bs) g_free(s->proxypassword); } =20 -static int64_t curl_getlength(BlockDriverState *bs) +static int64_t coroutine_fn curl_co_getlength(BlockDriverState *bs) { BDRVCURLState *s =3D bs->opaque; return s->len; @@ -1001,7 +1001,7 @@ static BlockDriver bdrv_http =3D { .bdrv_parse_filename =3D curl_parse_filename, .bdrv_file_open =3D curl_open, .bdrv_close =3D curl_close, - .bdrv_getlength =3D curl_getlength, + .bdrv_co_getlength =3D curl_co_getlength, =20 .bdrv_co_preadv =3D curl_co_preadv, =20 @@ -1020,7 +1020,7 @@ static BlockDriver bdrv_https =3D { .bdrv_parse_filename =3D curl_parse_filename, .bdrv_file_open =3D curl_open, .bdrv_close =3D curl_close, - .bdrv_getlength =3D curl_getlength, + .bdrv_co_getlength =3D curl_co_getlength, =20 .bdrv_co_preadv =3D curl_co_preadv, =20 @@ -1039,7 +1039,7 @@ static BlockDriver bdrv_ftp =3D { .bdrv_parse_filename =3D curl_parse_filename, .bdrv_file_open =3D curl_open, .bdrv_close =3D curl_close, - .bdrv_getlength =3D curl_getlength, + .bdrv_co_getlength =3D curl_co_getlength, =20 .bdrv_co_preadv =3D curl_co_preadv, =20 @@ -1058,7 +1058,7 @@ static BlockDriver bdrv_ftps =3D { .bdrv_parse_filename =3D curl_parse_filename, .bdrv_file_open =3D curl_open, .bdrv_close =3D curl_close, - .bdrv_getlength =3D curl_getlength, + .bdrv_co_getlength =3D curl_co_getlength, =20 .bdrv_co_preadv =3D curl_co_preadv, =20 diff --git a/block/file-posix.c b/block/file-posix.c index b29cd02b30..d70e4ec95a 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -188,7 +188,7 @@ static int fd_open(BlockDriverState *bs) return -EIO; } =20 -static int64_t raw_getlength(BlockDriverState *bs); +static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs); =20 typedef struct RawPosixAIOData { BlockDriverState *bs; @@ -2284,7 +2284,7 @@ static int coroutine_fn raw_co_truncate(BlockDriverSt= ate *bs, int64_t offset, } =20 if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { - int64_t cur_length =3D raw_getlength(bs); + int64_t cur_length =3D raw_co_getlength(bs); =20 if (offset !=3D cur_length && exact) { error_setg(errp, "Cannot resize device files"); @@ -2302,7 +2302,7 @@ static int coroutine_fn raw_co_truncate(BlockDriverSt= ate *bs, int64_t offset, } =20 #ifdef __OpenBSD__ -static int64_t raw_getlength(BlockDriverState *bs) +static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs) { BDRVRawState *s =3D bs->opaque; int fd =3D s->fd; @@ -2321,7 +2321,7 @@ static int64_t raw_getlength(BlockDriverState *bs) return st.st_size; } #elif defined(__NetBSD__) -static int64_t raw_getlength(BlockDriverState *bs) +static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs) { BDRVRawState *s =3D bs->opaque; int fd =3D s->fd; @@ -2346,7 +2346,7 @@ static int64_t raw_getlength(BlockDriverState *bs) return st.st_size; } #elif defined(__sun__) -static int64_t raw_getlength(BlockDriverState *bs) +static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs) { BDRVRawState *s =3D bs->opaque; struct dk_minfo minfo; @@ -2377,7 +2377,7 @@ static int64_t raw_getlength(BlockDriverState *bs) return size; } #elif defined(CONFIG_BSD) -static int64_t raw_getlength(BlockDriverState *bs) +static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs) { BDRVRawState *s =3D bs->opaque; int fd =3D s->fd; @@ -2449,7 +2449,7 @@ again: return size; } #else -static int64_t raw_getlength(BlockDriverState *bs) +static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs) { BDRVRawState *s =3D bs->opaque; int ret; @@ -2834,7 +2834,7 @@ static int coroutine_fn raw_co_block_status(BlockDriv= erState *bs, * round up if necessary. */ if (!QEMU_IS_ALIGNED(*pnum, bs->bl.request_alignment)) { - int64_t file_length =3D raw_getlength(bs); + int64_t file_length =3D raw_co_getlength(bs); if (file_length > 0) { /* Ignore errors, this is just a safeguard */ assert(hole =3D=3D file_length); @@ -2856,7 +2856,7 @@ static int coroutine_fn raw_co_block_status(BlockDriv= erState *bs, =20 #if defined(__linux__) /* Verify that the file is not in the page cache */ -static void check_cache_dropped(BlockDriverState *bs, Error **errp) +static void coroutine_fn check_cache_dropped(BlockDriverState *bs, Error *= *errp) { const size_t window_size =3D 128 * 1024 * 1024; BDRVRawState *s =3D bs->opaque; @@ -2871,7 +2871,7 @@ static void check_cache_dropped(BlockDriverState *bs,= Error **errp) page_size =3D sysconf(_SC_PAGESIZE); vec =3D g_malloc(DIV_ROUND_UP(window_size, page_size)); =20 - end =3D raw_getlength(bs); + end =3D raw_co_getlength(bs); =20 for (offset =3D 0; offset < end; offset +=3D window_size) { void *new_window; @@ -3325,8 +3325,8 @@ BlockDriver bdrv_file =3D { .bdrv_co_io_unplug =3D raw_co_io_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 - .bdrv_co_truncate =3D raw_co_truncate, - .bdrv_getlength =3D raw_getlength, + .bdrv_co_truncate =3D raw_co_truncate, + .bdrv_co_getlength =3D raw_co_getlength, .bdrv_get_info =3D raw_get_info, .bdrv_get_allocated_file_size =3D raw_get_allocated_file_size, @@ -3697,8 +3697,8 @@ static BlockDriver bdrv_host_device =3D { .bdrv_co_io_unplug =3D raw_co_io_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 - .bdrv_co_truncate =3D raw_co_truncate, - .bdrv_getlength =3D raw_getlength, + .bdrv_co_truncate =3D raw_co_truncate, + .bdrv_co_getlength =3D raw_co_getlength, .bdrv_get_info =3D raw_get_info, .bdrv_get_allocated_file_size =3D raw_get_allocated_file_size, @@ -3821,9 +3821,9 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_co_io_unplug =3D raw_co_io_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 - .bdrv_co_truncate =3D raw_co_truncate, - .bdrv_getlength =3D raw_getlength, - .has_variable_length =3D true, + .bdrv_co_truncate =3D raw_co_truncate, + .bdrv_co_getlength =3D raw_co_getlength, + .has_variable_length =3D true, .bdrv_get_allocated_file_size =3D raw_get_allocated_file_size, =20 @@ -3889,7 +3889,7 @@ static int cdrom_reopen(BlockDriverState *bs) =20 static bool coroutine_fn cdrom_co_is_inserted(BlockDriverState *bs) { - return raw_getlength(bs) > 0; + return raw_co_getlength(bs) > 0; } =20 static void cdrom_eject(BlockDriverState *bs, bool eject_flag) @@ -3951,9 +3951,9 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_co_io_unplug =3D raw_co_io_unplug, .bdrv_attach_aio_context =3D raw_aio_attach_aio_context, =20 - .bdrv_co_truncate =3D raw_co_truncate, - .bdrv_getlength =3D raw_getlength, - .has_variable_length =3D true, + .bdrv_co_truncate =3D raw_co_truncate, + .bdrv_co_getlength =3D raw_co_getlength, + .has_variable_length =3D true, .bdrv_get_allocated_file_size =3D raw_get_allocated_file_size, =20 diff --git a/block/file-win32.c b/block/file-win32.c index ec9d64d0e4..aedee695dd 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -525,7 +525,7 @@ static int coroutine_fn raw_co_truncate(BlockDriverStat= e *bs, int64_t offset, return 0; } =20 -static int64_t raw_getlength(BlockDriverState *bs) +static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs) { BDRVRawState *s =3D bs->opaque; LARGE_INTEGER l; @@ -763,7 +763,7 @@ BlockDriver bdrv_file =3D { .bdrv_aio_flush =3D raw_aio_flush, =20 .bdrv_co_truncate =3D raw_co_truncate, - .bdrv_getlength =3D raw_getlength, + .bdrv_co_getlength =3D raw_co_getlength, .bdrv_get_allocated_file_size =3D raw_get_allocated_file_size, =20 @@ -932,8 +932,8 @@ static BlockDriver bdrv_host_device =3D { .bdrv_detach_aio_context =3D raw_detach_aio_context, .bdrv_attach_aio_context =3D raw_attach_aio_context, =20 - .bdrv_getlength =3D raw_getlength, - .has_variable_length =3D true, + .bdrv_co_getlength =3D raw_co_getlength, + .has_variable_length =3D true, =20 .bdrv_get_allocated_file_size =3D raw_get_allocated_file_size, diff --git a/block/filter-compress.c b/block/filter-compress.c index 305716c86c..1515fe5103 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -54,9 +54,9 @@ static int compress_open(BlockDriverState *bs, QDict *opt= ions, int flags, } =20 =20 -static int64_t compress_getlength(BlockDriverState *bs) +static int64_t coroutine_fn compress_co_getlength(BlockDriverState *bs) { - return bdrv_getlength(bs->file->bs); + return bdrv_co_getlength(bs->file->bs); } =20 =20 @@ -134,7 +134,7 @@ static BlockDriver bdrv_compress =3D { .bdrv_open =3D compress_open, .bdrv_child_perm =3D bdrv_default_perms, =20 - .bdrv_getlength =3D compress_getlength, + .bdrv_co_getlength =3D compress_co_getlength, =20 .bdrv_co_preadv_part =3D compress_co_preadv_part, .bdrv_co_pwritev_part =3D compress_co_pwritev_part, diff --git a/block/gluster.c b/block/gluster.c index 7efc296399..469cdf01d4 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1317,7 +1317,7 @@ static coroutine_fn int qemu_gluster_co_pdiscard(Bloc= kDriverState *bs, } #endif =20 -static int64_t qemu_gluster_getlength(BlockDriverState *bs) +static int64_t coroutine_fn qemu_gluster_co_getlength(BlockDriverState *bs) { BDRVGlusterState *s =3D bs->opaque; int64_t ret; @@ -1509,7 +1509,7 @@ static int coroutine_fn qemu_gluster_co_block_status(= BlockDriverState *bs, * round up if necessary. */ if (!QEMU_IS_ALIGNED(*pnum, bs->bl.request_alignment)) { - int64_t file_length =3D qemu_gluster_getlength(bs); + int64_t file_length =3D qemu_gluster_co_getlength(bs); if (file_length > 0) { /* Ignore errors, this is just a safeguard */ assert(hole =3D=3D file_length); @@ -1558,7 +1558,7 @@ static BlockDriver bdrv_gluster =3D { .bdrv_close =3D qemu_gluster_close, .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, - .bdrv_getlength =3D qemu_gluster_getlength, + .bdrv_co_getlength =3D qemu_gluster_co_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, .bdrv_co_truncate =3D qemu_gluster_co_truncate, .bdrv_co_readv =3D qemu_gluster_co_readv, @@ -1587,7 +1587,7 @@ static BlockDriver bdrv_gluster_tcp =3D { .bdrv_close =3D qemu_gluster_close, .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, - .bdrv_getlength =3D qemu_gluster_getlength, + .bdrv_co_getlength =3D qemu_gluster_co_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, .bdrv_co_truncate =3D qemu_gluster_co_truncate, .bdrv_co_readv =3D qemu_gluster_co_readv, @@ -1616,7 +1616,7 @@ static BlockDriver bdrv_gluster_unix =3D { .bdrv_close =3D qemu_gluster_close, .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, - .bdrv_getlength =3D qemu_gluster_getlength, + .bdrv_co_getlength =3D qemu_gluster_co_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, .bdrv_co_truncate =3D qemu_gluster_co_truncate, .bdrv_co_readv =3D qemu_gluster_co_readv, @@ -1651,7 +1651,7 @@ static BlockDriver bdrv_gluster_rdma =3D { .bdrv_close =3D qemu_gluster_close, .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, - .bdrv_getlength =3D qemu_gluster_getlength, + .bdrv_co_getlength =3D qemu_gluster_co_getlength, .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, .bdrv_co_truncate =3D qemu_gluster_co_truncate, .bdrv_co_readv =3D qemu_gluster_co_readv, diff --git a/block/iscsi.c b/block/iscsi.c index a316d46d96..df110dd1d2 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -1126,8 +1126,8 @@ static BlockAIOCB *iscsi_aio_ioctl(BlockDriverState *= bs, =20 #endif =20 -static int64_t -iscsi_getlength(BlockDriverState *bs) +static int64_t coroutine_fn +iscsi_co_getlength(BlockDriverState *bs) { IscsiLun *iscsilun =3D bs->opaque; int64_t len; @@ -2154,7 +2154,7 @@ static int coroutine_fn iscsi_co_truncate(BlockDriver= State *bs, int64_t offset, return -EIO; } =20 - cur_length =3D iscsi_getlength(bs); + cur_length =3D iscsi_co_getlength(bs); if (offset !=3D cur_length && exact) { error_setg(errp, "Cannot resize iSCSI devices"); return -ENOTSUP; @@ -2433,7 +2433,7 @@ static BlockDriver bdrv_iscsi =3D { .bdrv_reopen_commit =3D iscsi_reopen_commit, .bdrv_co_invalidate_cache =3D iscsi_co_invalidate_cache, =20 - .bdrv_getlength =3D iscsi_getlength, + .bdrv_co_getlength =3D iscsi_co_getlength, .bdrv_get_info =3D iscsi_get_info, .bdrv_co_truncate =3D iscsi_co_truncate, .bdrv_refresh_limits =3D iscsi_refresh_limits, @@ -2472,7 +2472,7 @@ static BlockDriver bdrv_iser =3D { .bdrv_reopen_commit =3D iscsi_reopen_commit, .bdrv_co_invalidate_cache =3D iscsi_co_invalidate_cache, =20 - .bdrv_getlength =3D iscsi_getlength, + .bdrv_co_getlength =3D iscsi_co_getlength, .bdrv_get_info =3D iscsi_get_info, .bdrv_co_truncate =3D iscsi_co_truncate, .bdrv_refresh_limits =3D iscsi_refresh_limits, diff --git a/block/mirror.c b/block/mirror.c index 251adc5ae0..c7d7ce2f8f 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -909,13 +909,13 @@ static int coroutine_fn mirror_run(Job *job, Error **= errp) goto immediate_exit; } =20 - s->bdev_length =3D bdrv_getlength(bs); + s->bdev_length =3D bdrv_co_getlength(bs); if (s->bdev_length < 0) { ret =3D s->bdev_length; goto immediate_exit; } =20 - target_length =3D blk_getlength(s->target); + target_length =3D blk_co_getlength(s->target); if (target_length < 0) { ret =3D target_length; goto immediate_exit; diff --git a/block/nbd.c b/block/nbd.c index 7d485c86d2..bf2894ad5c 100644 --- a/block/nbd.c +++ b/block/nbd.c @@ -1992,7 +1992,7 @@ static int coroutine_fn nbd_co_truncate(BlockDriverSt= ate *bs, int64_t offset, return 0; } =20 -static int64_t nbd_getlength(BlockDriverState *bs) +static int64_t coroutine_fn nbd_co_getlength(BlockDriverState *bs) { BDRVNBDState *s =3D bs->opaque; =20 @@ -2124,7 +2124,7 @@ static BlockDriver bdrv_nbd =3D { .bdrv_co_pdiscard =3D nbd_client_co_pdiscard, .bdrv_refresh_limits =3D nbd_refresh_limits, .bdrv_co_truncate =3D nbd_co_truncate, - .bdrv_getlength =3D nbd_getlength, + .bdrv_co_getlength =3D nbd_co_getlength, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, .bdrv_dirname =3D nbd_dirname, @@ -2152,7 +2152,7 @@ static BlockDriver bdrv_nbd_tcp =3D { .bdrv_co_pdiscard =3D nbd_client_co_pdiscard, .bdrv_refresh_limits =3D nbd_refresh_limits, .bdrv_co_truncate =3D nbd_co_truncate, - .bdrv_getlength =3D nbd_getlength, + .bdrv_co_getlength =3D nbd_co_getlength, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, .bdrv_dirname =3D nbd_dirname, @@ -2180,7 +2180,7 @@ static BlockDriver bdrv_nbd_unix =3D { .bdrv_co_pdiscard =3D nbd_client_co_pdiscard, .bdrv_refresh_limits =3D nbd_refresh_limits, .bdrv_co_truncate =3D nbd_co_truncate, - .bdrv_getlength =3D nbd_getlength, + .bdrv_co_getlength =3D nbd_co_getlength, .bdrv_refresh_filename =3D nbd_refresh_filename, .bdrv_co_block_status =3D nbd_client_co_block_status, .bdrv_dirname =3D nbd_dirname, diff --git a/block/null.c b/block/null.c index 75f7d0db40..05dde6d9ab 100644 --- a/block/null.c +++ b/block/null.c @@ -99,7 +99,7 @@ static int null_file_open(BlockDriverState *bs, QDict *op= tions, int flags, return ret; } =20 -static int64_t null_getlength(BlockDriverState *bs) +static int64_t coroutine_fn null_co_getlength(BlockDriverState *bs) { BDRVNullState *s =3D bs->opaque; return s->length; @@ -283,7 +283,7 @@ static BlockDriver bdrv_null_co =3D { =20 .bdrv_file_open =3D null_file_open, .bdrv_parse_filename =3D null_co_parse_filename, - .bdrv_getlength =3D null_getlength, + .bdrv_co_getlength =3D null_co_getlength, .bdrv_get_allocated_file_size =3D null_allocated_file_size, =20 .bdrv_co_preadv =3D null_co_preadv, @@ -304,7 +304,7 @@ static BlockDriver bdrv_null_aio =3D { =20 .bdrv_file_open =3D null_file_open, .bdrv_parse_filename =3D null_aio_parse_filename, - .bdrv_getlength =3D null_getlength, + .bdrv_co_getlength =3D null_co_getlength, .bdrv_get_allocated_file_size =3D null_allocated_file_size, =20 .bdrv_aio_preadv =3D null_aio_preadv, diff --git a/block/nvme.c b/block/nvme.c index eb940f2846..6958715758 100644 --- a/block/nvme.c +++ b/block/nvme.c @@ -1001,7 +1001,7 @@ fail: return ret; } =20 -static int64_t nvme_getlength(BlockDriverState *bs) +static int64_t coroutine_fn nvme_co_getlength(BlockDriverState *bs) { BDRVNVMeState *s =3D bs->opaque; return s->nsze << s->blkshift; @@ -1485,7 +1485,7 @@ static int coroutine_fn nvme_co_truncate(BlockDriverS= tate *bs, int64_t offset, return -ENOTSUP; } =20 - cur_length =3D nvme_getlength(bs); + cur_length =3D nvme_co_getlength(bs); if (offset !=3D cur_length && exact) { error_setg(errp, "Cannot resize NVMe devices"); return -ENOTSUP; @@ -1642,7 +1642,7 @@ static BlockDriver bdrv_nvme =3D { .bdrv_parse_filename =3D nvme_parse_filename, .bdrv_file_open =3D nvme_file_open, .bdrv_close =3D nvme_close, - .bdrv_getlength =3D nvme_getlength, + .bdrv_co_getlength =3D nvme_co_getlength, .bdrv_probe_blocksizes =3D nvme_probe_blocksizes, .bdrv_co_truncate =3D nvme_co_truncate, =20 diff --git a/block/preallocate.c b/block/preallocate.c index d50ee7f49b..94aa824e09 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -441,7 +441,7 @@ static int coroutine_fn preallocate_co_flush(BlockDrive= rState *bs) return bdrv_co_flush(bs->file->bs); } =20 -static int64_t preallocate_getlength(BlockDriverState *bs) +static int64_t coroutine_fn preallocate_co_getlength(BlockDriverState *bs) { int64_t ret; BDRVPreallocateState *s =3D bs->opaque; @@ -450,7 +450,7 @@ static int64_t preallocate_getlength(BlockDriverState *= bs) return s->data_end; } =20 - ret =3D bdrv_getlength(bs->file->bs); + ret =3D bdrv_co_getlength(bs->file->bs); =20 if (has_prealloc_perms(bs)) { s->file_end =3D s->zero_start =3D s->data_end =3D ret; @@ -536,9 +536,9 @@ BlockDriver bdrv_preallocate_filter =3D { .format_name =3D "preallocate", .instance_size =3D sizeof(BDRVPreallocateState), =20 - .bdrv_getlength =3D preallocate_getlength, - .bdrv_open =3D preallocate_open, - .bdrv_close =3D preallocate_close, + .bdrv_co_getlength =3D preallocate_co_getlength, + .bdrv_open =3D preallocate_open, + .bdrv_close =3D preallocate_close, =20 .bdrv_reopen_prepare =3D preallocate_reopen_prepare, .bdrv_reopen_commit =3D preallocate_reopen_commit, diff --git a/block/qed.c b/block/qed.c index faa606618e..c8f9045b72 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1480,7 +1480,7 @@ static int coroutine_fn bdrv_qed_co_truncate(BlockDri= verState *bs, return ret; } =20 -static int64_t bdrv_qed_getlength(BlockDriverState *bs) +static int64_t coroutine_fn bdrv_qed_co_getlength(BlockDriverState *bs) { BDRVQEDState *s =3D bs->opaque; return s->header.image_size; @@ -1653,7 +1653,7 @@ static BlockDriver bdrv_qed =3D { .bdrv_co_writev =3D bdrv_qed_co_writev, .bdrv_co_pwrite_zeroes =3D bdrv_qed_co_pwrite_zeroes, .bdrv_co_truncate =3D bdrv_qed_co_truncate, - .bdrv_getlength =3D bdrv_qed_getlength, + .bdrv_co_getlength =3D bdrv_qed_co_getlength, .bdrv_get_info =3D bdrv_qed_get_info, .bdrv_refresh_limits =3D bdrv_qed_refresh_limits, .bdrv_change_backing_file =3D bdrv_qed_change_backing_file, diff --git a/block/quorum.c b/block/quorum.c index 7f21c03f1f..d1dcf2eaba 100644 --- a/block/quorum.c +++ b/block/quorum.c @@ -754,19 +754,19 @@ static int coroutine_fn quorum_co_pwrite_zeroes(Block= DriverState *bs, flags | BDRV_REQ_ZERO_WRITE); } =20 -static int64_t quorum_getlength(BlockDriverState *bs) +static int64_t coroutine_fn quorum_co_getlength(BlockDriverState *bs) { BDRVQuorumState *s =3D bs->opaque; int64_t result; int i; =20 /* check that all file have the same length */ - result =3D bdrv_getlength(s->children[0]->bs); + result =3D bdrv_co_getlength(s->children[0]->bs); if (result < 0) { return result; } for (i =3D 1; i < s->num_children; i++) { - int64_t value =3D bdrv_getlength(s->children[i]->bs); + int64_t value =3D bdrv_co_getlength(s->children[i]->bs); if (value < 0) { return value; } @@ -1283,7 +1283,7 @@ static BlockDriver bdrv_quorum =3D { =20 .bdrv_co_flush =3D quorum_co_flush, =20 - .bdrv_getlength =3D quorum_getlength, + .bdrv_co_getlength =3D quorum_co_getlength, =20 .bdrv_co_preadv =3D quorum_co_preadv, .bdrv_co_pwritev =3D quorum_co_pwritev, diff --git a/block/raw-format.c b/block/raw-format.c index 28905b09ee..ccf23fe0b2 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -316,14 +316,14 @@ static int coroutine_fn raw_co_pdiscard(BlockDriverSt= ate *bs, return bdrv_co_pdiscard(bs->file, offset, bytes); } =20 -static int64_t raw_getlength(BlockDriverState *bs) +static int64_t coroutine_fn raw_co_getlength(BlockDriverState *bs) { int64_t len; BDRVRawState *s =3D bs->opaque; =20 /* Update size. It should not change unless the file was externally * modified. */ - len =3D bdrv_getlength(bs->file->bs); + len =3D bdrv_co_getlength(bs->file->bs); if (len < 0) { return len; } @@ -621,7 +621,7 @@ BlockDriver bdrv_raw =3D { .bdrv_co_copy_range_from =3D &raw_co_copy_range_from, .bdrv_co_copy_range_to =3D &raw_co_copy_range_to, .bdrv_co_truncate =3D &raw_co_truncate, - .bdrv_getlength =3D &raw_getlength, + .bdrv_co_getlength =3D &raw_co_getlength, .is_format =3D true, .has_variable_length =3D true, .bdrv_measure =3D &raw_measure, diff --git a/block/rbd.c b/block/rbd.c index 3aa6aae0e0..c67d30160a 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -1429,7 +1429,7 @@ static int coroutine_fn qemu_rbd_co_block_status(Bloc= kDriverState *bs, return status; } =20 -static int64_t qemu_rbd_getlength(BlockDriverState *bs) +static int64_t coroutine_fn qemu_rbd_co_getlength(BlockDriverState *bs) { BDRVRBDState *s =3D bs->opaque; int r; @@ -1653,7 +1653,7 @@ static BlockDriver bdrv_rbd =3D { .bdrv_get_info =3D qemu_rbd_getinfo, .bdrv_get_specific_info =3D qemu_rbd_get_specific_info, .create_opts =3D &qemu_rbd_create_opts, - .bdrv_getlength =3D qemu_rbd_getlength, + .bdrv_co_getlength =3D qemu_rbd_co_getlength, .bdrv_co_truncate =3D qemu_rbd_co_truncate, .protocol_name =3D "rbd", =20 diff --git a/block/replication.c b/block/replication.c index c62f48a874..a27417d310 100644 --- a/block/replication.c +++ b/block/replication.c @@ -179,9 +179,9 @@ static void replication_child_perm(BlockDriverState *bs= , BdrvChild *c, return; } =20 -static int64_t replication_getlength(BlockDriverState *bs) +static int64_t coroutine_fn replication_co_getlength(BlockDriverState *bs) { - return bdrv_getlength(bs->file->bs); + return bdrv_co_getlength(bs->file->bs); } =20 static int replication_get_io_status(BDRVReplicationState *s) @@ -758,7 +758,7 @@ static BlockDriver bdrv_replication =3D { .bdrv_close =3D replication_close, .bdrv_child_perm =3D replication_child_perm, =20 - .bdrv_getlength =3D replication_getlength, + .bdrv_co_getlength =3D replication_co_getlength, .bdrv_co_readv =3D replication_co_readv, .bdrv_co_writev =3D replication_co_writev, =20 diff --git a/block/ssh.c b/block/ssh.c index 8508710f2f..c374129c9a 100644 --- a/block/ssh.c +++ b/block/ssh.c @@ -1252,7 +1252,7 @@ static coroutine_fn int ssh_co_flush(BlockDriverState= *bs) return ret; } =20 -static int64_t ssh_getlength(BlockDriverState *bs) +static int64_t coroutine_fn ssh_co_getlength(BlockDriverState *bs) { BDRVSSHState *s =3D bs->opaque; int64_t length; @@ -1363,7 +1363,7 @@ static BlockDriver bdrv_ssh =3D { .bdrv_has_zero_init =3D ssh_has_zero_init, .bdrv_co_readv =3D ssh_co_readv, .bdrv_co_writev =3D ssh_co_writev, - .bdrv_getlength =3D ssh_getlength, + .bdrv_co_getlength =3D ssh_co_getlength, .bdrv_co_truncate =3D ssh_co_truncate, .bdrv_co_flush_to_disk =3D ssh_co_flush, .bdrv_refresh_filename =3D ssh_refresh_filename, diff --git a/block/throttle.c b/block/throttle.c index 88851c84f4..80b6395899 100644 --- a/block/throttle.c +++ b/block/throttle.c @@ -104,9 +104,9 @@ static void throttle_close(BlockDriverState *bs) } =20 =20 -static int64_t throttle_getlength(BlockDriverState *bs) +static int64_t coroutine_fn throttle_co_getlength(BlockDriverState *bs) { - return bdrv_getlength(bs->file->bs); + return bdrv_co_getlength(bs->file->bs); } =20 static int coroutine_fn throttle_co_preadv(BlockDriverState *bs, @@ -245,7 +245,7 @@ static BlockDriver bdrv_throttle =3D { =20 .bdrv_child_perm =3D bdrv_default_perms, =20 - .bdrv_getlength =3D throttle_getlength, + .bdrv_co_getlength =3D throttle_co_getlength, =20 .bdrv_co_preadv =3D throttle_co_preadv, .bdrv_co_pwritev =3D throttle_co_pwritev, diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c index e493c28814..d4e360850f 100644 --- a/hw/scsi/scsi-disk.c +++ b/hw/scsi/scsi-disk.c @@ -2332,10 +2332,15 @@ static void scsi_disk_reset(DeviceState *dev) { SCSIDiskState *s =3D DO_UPCAST(SCSIDiskState, qdev.qdev, dev); uint64_t nb_sectors; + AioContext *ctx; =20 scsi_device_purge_requests(&s->qdev, SENSE_CODE(RESET)); =20 + ctx =3D blk_get_aio_context(s->qdev.conf.blk); + aio_context_acquire(ctx); blk_get_geometry(s->qdev.conf.blk, &nb_sectors); + aio_context_release(ctx); + nb_sectors /=3D s->qdev.blocksize / BDRV_SECTOR_SIZE; if (nb_sectors) { nb_sectors--; diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 8ca5adec5e..e444aa707d 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -831,7 +831,10 @@ static void test_attach_second_node(void) qdict_put_str(options, "driver", "raw"); qdict_put_str(options, "file", "base"); =20 + aio_context_acquire(ctx); filter =3D bdrv_open(NULL, NULL, options, BDRV_O_RDWR, &error_abort); + aio_context_release(ctx); + g_assert(blk_get_aio_context(blk) =3D=3D ctx); g_assert(bdrv_get_aio_context(bs) =3D=3D ctx); g_assert(bdrv_get_aio_context(filter) =3D=3D ctx); diff --git a/block/meson.build b/block/meson.build index 90011a2805..3662852dc2 100644 --- a/block/meson.build +++ b/block/meson.build @@ -139,6 +139,7 @@ block_gen_c =3D custom_target('block-gen.c', input: files( '../include/block/block-io.h', '../include/block/dirty-bitmap.h', + '../include/block/block_int-io.h', '../include/block/block-global-state= .h', '../include/sysemu/block-backend-io.= h', 'coroutines.h' --=20 2.38.1 From nobody Sat Apr 20 01:04:24 2024 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=1673642637; cv=none; d=zohomail.com; s=zohoarc; b=QKDmKwY5hp6QU1Rr1ZsYL645SFfsB1XKCjMUz7p4adWfk2XruOPZliAyEZXUSjoCK4M5g4wmUaUczGUrlsx8rcaUeSBqqTZVq6U5WfwPcVtv+ha7cKILgME6x0ez95ybQjebS3qYsGRUXjRnoT+a67IgEe5DCZC7tBueH9PUUOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673642637; 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=H20gHh2RICS5DlQTc8FBpRqeaqX46d2Bknmirw2P0e4=; b=BXcDnw9HcCffFzCLK3HC65J1OGV3Vt8I1y6zaYyIW9jSim0YlwMDIKTT50+TB6VOblk8h2lmxtKgT7q/5N++QH9sHWvP2rC01MVZLmlPngOU50Jf77ZDoHHpKGmpk8aMup8rIfIag98mdz64okwYoDHWSyKHlnCwA/vZD6ygde4= 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 1673642637637951.8788438671515; Fri, 13 Jan 2023 12:43:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGQsy-00004r-Kh; Fri, 13 Jan 2023 15:42:48 -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 1pGQsw-0008VN-Pk for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:46 -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 1pGQsv-0006BW-Cp for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42: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-384-70rqa6lnMFOVbYx1SYI2lA-1; Fri, 13 Jan 2023 15:42:41 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 710923C01DF9; Fri, 13 Jan 2023 20:42:41 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.195.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 47C4D2026D68; Fri, 13 Jan 2023 20:42:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673642564; 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=H20gHh2RICS5DlQTc8FBpRqeaqX46d2Bknmirw2P0e4=; b=hBHDm2N0LRHygmz8gCnr111UGEMrkpnjik3U5F3z5pC/1L1YJV1kk3r//uQtYpXS9FBsiE 1Ul2tfsjWHXj2DQx6XALlRI2Emxm4EundEqNssbG+dUYFRKfqzEL+zPfn/2tkNTn+nNHc8 qEH5V8vqLk6hgIpVkfsdx5jWF9mU9g8= X-MC-Unique: 70rqa6lnMFOVbYx1SYI2lA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v2 07/14] block-backend: use bdrv_getlength instead of blk_getlength Date: Fri, 13 Jan 2023 21:42:05 +0100 Message-Id: <20230113204212.359076-8-kwolf@redhat.com> In-Reply-To: <20230113204212.359076-1-kwolf@redhat.com> References: <20230113204212.359076-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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=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 @redhat.com) X-ZM-MESSAGEID: 1673642638511100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito The only difference is that blk_ checks if the block is available, but this check is already performed above in blk_check_byte_request(). This is in preparation for the graph rdlock, which will be taken by both the callers of blk_check_byte_request() and blk_getlength(). Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Emanuele Giuseppe Esposito --- block/block-backend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/block-backend.c b/block/block-backend.c index 6e5e2693b3..37b51f409f 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1253,7 +1253,7 @@ static int blk_check_byte_request(BlockBackend *blk, = int64_t offset, } =20 if (!blk->allow_write_beyond_eof) { - len =3D blk_getlength(blk); + len =3D bdrv_getlength(blk_bs(blk)); if (len < 0) { return len; } --=20 2.38.1 From nobody Sat Apr 20 01:04:24 2024 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=1673642649; cv=none; d=zohomail.com; s=zohoarc; b=nbfqxhLY2FggNBZa/u1tlhjrLXVQfHDOcefLpWYGbp00j+N+Cc/4xRACpovAjh3HlYgrANxBtqLdivl0jJz2kQAcCaMccymPkym2rEVytefizIJewmEJweyNjo09KxlObUvQZWbUSwE4D65XTl7EfX7L7uYcwB/J1J0VEPyK51g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673642649; 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=mbcgUqHjO8wSWqgg1IeQSX7j5Xvk//AwBrcRYThdscQ=; b=j4/dYGsuXqo3YmQoeizSGwIarQuRDwLHGLhOIzK5E/kpxV0MoztPhPIXPKyc3F+JJoaucU6ZtdDcQCyZFuxaMmdPr56Rhu5c7NL0A6d/2tg3KTojiKaioLlE9HQN03BsSNS7wSbIu4dgj1Aht0jdw7hUOU2Ap8u4Vdjv7QoxoZo= 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 1673642649636638.3730893293441; Fri, 13 Jan 2023 12:44:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGQt0-00005f-Fx; Fri, 13 Jan 2023 15:42: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 1pGQsz-00004z-1h for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:49 -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 1pGQsx-0006CC-GD for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:48 -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-417-n3MI1v2EPSeq-ir5CrO1JA-1; Fri, 13 Jan 2023 15:42:43 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DAD55101A52E; Fri, 13 Jan 2023 20:42:42 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.195.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE5E62026D68; Fri, 13 Jan 2023 20:42:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673642566; 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=mbcgUqHjO8wSWqgg1IeQSX7j5Xvk//AwBrcRYThdscQ=; b=NeXc4k1XCTODNz6U/AYMpCXmCmqVQ7SJutV1MOzmMVcPuVWb/L9tOech8eu/R2WroSpVtG hgB3uHV/5xAP4RfG+TWinNt/rLkwys3866bSGLAYXwfh6Wyb0gD3cVSJmt+NelR7o3f7pu IKX/xG0GgG3dt474hFwXc1tBvMQPwZ8= X-MC-Unique: n3MI1v2EPSeq-ir5CrO1JA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v2 08/14] block: use bdrv_co_refresh_total_sectors when possible Date: Fri, 13 Jan 2023 21:42:06 +0100 Message-Id: <20230113204212.359076-9-kwolf@redhat.com> In-Reply-To: <20230113204212.359076-1-kwolf@redhat.com> References: <20230113204212.359076-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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.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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1673642650574100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito In some places we are sure we are always running in a coroutine, therefore it's useless to call the generated_co_wrapper, instead call directly the _co_ function. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Emanuele Giuseppe Esposito --- block/block-backend.c | 6 +++--- block/io.c | 4 ++-- block/preallocate.c | 6 +++--- block/qed.c | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 37b51f409f..fc08400544 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 int blk_check_byte_request(BlockBackend *blk, int64_t offset, - int64_t bytes) +static coroutine_fn int blk_check_byte_request(BlockBackend *blk, + int64_t offset, int64_t byt= es) { int64_t len; =20 @@ -1253,7 +1253,7 @@ static int blk_check_byte_request(BlockBackend *blk, = int64_t offset, } =20 if (!blk->allow_write_beyond_eof) { - len =3D bdrv_getlength(blk_bs(blk)); + len =3D bdrv_co_getlength(blk_bs(blk)); if (len < 0) { return len; } diff --git a/block/io.c b/block/io.c index e5e51563a5..fdc5ba9fb6 100644 --- a/block/io.c +++ b/block/io.c @@ -3443,7 +3443,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, bool exact, if (new_bytes && backing) { int64_t backing_len; =20 - backing_len =3D bdrv_getlength(backing->bs); + backing_len =3D bdrv_co_getlength(backing->bs); if (backing_len < 0) { ret =3D backing_len; error_setg_errno(errp, -ret, "Could not get backing file size"= ); @@ -3473,7 +3473,7 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, bool exact, goto out; } =20 - ret =3D bdrv_refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); + ret =3D bdrv_co_refresh_total_sectors(bs, offset >> BDRV_SECTOR_BITS); if (ret < 0) { error_setg_errno(errp, -ret, "Could not refresh total sector count= "); } else { diff --git a/block/preallocate.c b/block/preallocate.c index 94aa824e09..5815d7a78b 100644 --- a/block/preallocate.c +++ b/block/preallocate.c @@ -286,7 +286,7 @@ static bool coroutine_fn handle_write(BlockDriverState = *bs, int64_t offset, } =20 if (s->data_end < 0) { - s->data_end =3D bdrv_getlength(bs->file->bs); + s->data_end =3D bdrv_co_getlength(bs->file->bs); if (s->data_end < 0) { return false; } @@ -308,7 +308,7 @@ static bool coroutine_fn handle_write(BlockDriverState = *bs, int64_t offset, } =20 if (s->file_end < 0) { - s->file_end =3D bdrv_getlength(bs->file->bs); + s->file_end =3D bdrv_co_getlength(bs->file->bs); if (s->file_end < 0) { return false; } @@ -380,7 +380,7 @@ preallocate_co_truncate(BlockDriverState *bs, int64_t o= ffset, =20 if (s->data_end >=3D 0 && offset > s->data_end) { if (s->file_end < 0) { - s->file_end =3D bdrv_getlength(bs->file->bs); + s->file_end =3D bdrv_co_getlength(bs->file->bs); if (s->file_end < 0) { error_setg(errp, "failed to get file length"); return s->file_end; diff --git a/block/qed.c b/block/qed.c index c8f9045b72..16bf0cb080 100644 --- a/block/qed.c +++ b/block/qed.c @@ -424,7 +424,7 @@ static int coroutine_fn bdrv_qed_do_open(BlockDriverSta= te *bs, QDict *options, } =20 /* Round down file size to the last cluster */ - file_size =3D bdrv_getlength(bs->file->bs); + file_size =3D bdrv_co_getlength(bs->file->bs); if (file_size < 0) { error_setg(errp, "Failed to get file length"); return file_size; --=20 2.38.1 From nobody Sat Apr 20 01:04:24 2024 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=1673642669; cv=none; d=zohomail.com; s=zohoarc; b=ZFHdX0ONP6T/7/Td93tc1AmOT5Rh3Ef8HhlVrcpMbXH1IaISW+OjUSIrCwmTw+zpKffwj1NUJoOqi/bKt455INvXdEzUz7GCr55Fj4Ui4lAq95F5KyQgQpW09M3RiWzJY8Qdup0ghfE1e9owaoc5QV3QnXwN7jMw2Qdy6czTF44= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673642669; 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=Dh+y4/C7RIJtnMBasw9aix/sWKPREPMgdAW5/aFDiKk=; b=JUy4XByRxqDHu4OsngcZNTcGr7UKQ4vKXifuStid23GsnjR7VYFSNdb+uU711/Uz4Ez3Up49H5I5o0ivNgoFAhXM3kRkvTG9Hs/yoeEczFJw+ZuWOBaqrxH6mTCeYtlbXcQXCV39/TmHaLzP4K2nYjBIRmU8OXP3hb+cpfad4Z4= 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 1673642669762982.3830889452156; Fri, 13 Jan 2023 12:44:29 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGQt2-000070-LJ; Fri, 13 Jan 2023 15:42:52 -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 1pGQt0-00005t-JP for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:50 -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 1pGQsy-0006CS-B9 for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:50 -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-650-cC8IKU7fMFSnMoZueYBplQ-1; Fri, 13 Jan 2023 15:42:44 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 57C731C01B21; Fri, 13 Jan 2023 20:42:44 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.195.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 260392026D68; Fri, 13 Jan 2023 20:42:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673642567; 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=Dh+y4/C7RIJtnMBasw9aix/sWKPREPMgdAW5/aFDiKk=; b=hPrm8hamdwGJ/FdYcubloQszwRoc+w74gY0XmDQ15UPskVa4ZjQ3mEeJSS6C5j3S9yuosI 18mgDcHwGeuq2pNH9+iavGFrpIFkIwgdC92mO7vyXDsOF0C8vP2S5jeb5kC+nqvlSFy0s1 tSYc0L7EYt8qORm27vfiEAOGXQioyew= X-MC-Unique: cC8IKU7fMFSnMoZueYBplQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v2 09/14] block: Convert bdrv_get_allocated_file_size() to co_wrapper Date: Fri, 13 Jan 2023 21:42:07 +0100 Message-Id: <20230113204212.359076-10-kwolf@redhat.com> In-Reply-To: <20230113204212.359076-1-kwolf@redhat.com> References: <20230113204212.359076-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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=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 @redhat.com) X-ZM-MESSAGEID: 1673642670856100003 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito bdrv_get_allocated_file_size() is categorized as an I/O function, and it currently doesn't run in a coroutine. We should let it take a graph rdlock since it traverses the block nodes graph, which however is only possible in a coroutine. Therefore turn it into a co_wrapper to move the actual function into a coroutine where the lock can be taken. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 4 +++- include/block/block_int-common.h | 4 +++- block.c | 12 ++++++------ block/file-posix.c | 14 +++++--------- block/file-win32.c | 10 ++++------ block/gluster.c | 11 ++++++----- block/nfs.c | 4 ++-- block/null.c | 7 ++++--- block/qcow2-refcount.c | 2 +- block/vmdk.c | 9 +++++---- 10 files changed, 39 insertions(+), 38 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 4dcb5f73fa..0718554590 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -79,7 +79,9 @@ int64_t co_wrapper_mixed bdrv_nb_sectors(BlockDriverState= *bs); int64_t coroutine_fn bdrv_co_getlength(BlockDriverState *bs); int64_t co_wrapper_mixed bdrv_getlength(BlockDriverState *bs); =20 -int64_t bdrv_get_allocated_file_size(BlockDriverState *bs); +int64_t coroutine_fn bdrv_co_get_allocated_file_size(BlockDriverState *bs); +int64_t co_wrapper bdrv_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 6336c7239a..cc03c599e7 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -685,7 +685,9 @@ struct BlockDriver { bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **e= rrp); int64_t coroutine_fn (*bdrv_co_getlength)(BlockDriverState *bs); - int64_t (*bdrv_get_allocated_file_size)(BlockDriverState *bs); + int64_t coroutine_fn (*bdrv_co_get_allocated_file_size)( + BlockDriverState *bs); + BlockMeasureInfo *(*bdrv_measure)(QemuOpts *opts, BlockDriverState *in= _bs, Error **errp); =20 diff --git a/block.c b/block.c index dd22a206f9..82c6cb6dcd 100644 --- a/block.c +++ b/block.c @@ -5719,7 +5719,7 @@ exit: } =20 /** - * Implementation of BlockDriver.bdrv_get_allocated_file_size() that + * Implementation of BlockDriver.bdrv_co_get_allocated_file_size() that * sums the size of all data-bearing children. (This excludes backing * children.) */ @@ -5732,7 +5732,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; } @@ -5747,7 +5747,7 @@ static int64_t bdrv_sum_allocated_file_size(BlockDriv= erState *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(); @@ -5755,8 +5755,8 @@ int64_t bdrv_get_allocated_file_size(BlockDriverState= *bs) if (!drv) { return -ENOMEDIUM; } - if (drv->bdrv_get_allocated_file_size) { - return drv->bdrv_get_allocated_file_size(bs); + if (drv->bdrv_co_get_allocated_file_size) { + return drv->bdrv_co_get_allocated_file_size(bs); } =20 if (drv->bdrv_file_open) { @@ -5768,7 +5768,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/file-posix.c b/block/file-posix.c index d70e4ec95a..a22f93e4b2 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -2468,7 +2468,7 @@ static int64_t coroutine_fn raw_co_getlength(BlockDri= verState *bs) } #endif =20 -static int64_t raw_get_allocated_file_size(BlockDriverState *bs) +static int64_t coroutine_fn raw_co_get_allocated_file_size(BlockDriverStat= e *bs) { struct stat st; BDRVRawState *s =3D bs->opaque; @@ -3328,8 +3328,7 @@ BlockDriver bdrv_file =3D { .bdrv_co_truncate =3D raw_co_truncate, .bdrv_co_getlength =3D raw_co_getlength, .bdrv_get_info =3D raw_get_info, - .bdrv_get_allocated_file_size - =3D raw_get_allocated_file_size, + .bdrv_co_get_allocated_file_size =3D raw_co_get_allocated_file_size, .bdrv_get_specific_stats =3D raw_get_specific_stats, .bdrv_check_perm =3D raw_check_perm, .bdrv_set_perm =3D raw_set_perm, @@ -3700,8 +3699,7 @@ static BlockDriver bdrv_host_device =3D { .bdrv_co_truncate =3D raw_co_truncate, .bdrv_co_getlength =3D raw_co_getlength, .bdrv_get_info =3D raw_get_info, - .bdrv_get_allocated_file_size - =3D raw_get_allocated_file_size, + .bdrv_co_get_allocated_file_size =3D raw_co_get_allocated_file_size, .bdrv_get_specific_stats =3D hdev_get_specific_stats, .bdrv_check_perm =3D raw_check_perm, .bdrv_set_perm =3D raw_set_perm, @@ -3824,8 +3822,7 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_co_truncate =3D raw_co_truncate, .bdrv_co_getlength =3D raw_co_getlength, .has_variable_length =3D true, - .bdrv_get_allocated_file_size - =3D raw_get_allocated_file_size, + .bdrv_co_get_allocated_file_size =3D raw_co_get_allocated_file_size, =20 /* removable device support */ .bdrv_co_is_inserted =3D cdrom_co_is_inserted, @@ -3954,8 +3951,7 @@ static BlockDriver bdrv_host_cdrom =3D { .bdrv_co_truncate =3D raw_co_truncate, .bdrv_co_getlength =3D raw_co_getlength, .has_variable_length =3D true, - .bdrv_get_allocated_file_size - =3D raw_get_allocated_file_size, + .bdrv_co_get_allocated_file_size =3D raw_co_get_allocated_file_size, =20 /* removable device support */ .bdrv_co_is_inserted =3D cdrom_co_is_inserted, diff --git a/block/file-win32.c b/block/file-win32.c index aedee695dd..6ff576b20d 100644 --- a/block/file-win32.c +++ b/block/file-win32.c @@ -558,7 +558,7 @@ static int64_t coroutine_fn raw_co_getlength(BlockDrive= rState *bs) return l.QuadPart; } =20 -static int64_t raw_get_allocated_file_size(BlockDriverState *bs) +static int64_t coroutine_fn raw_co_get_allocated_file_size(BlockDriverStat= e *bs) { typedef DWORD (WINAPI * get_compressed_t)(const char *filename, DWORD * high); @@ -764,8 +764,8 @@ BlockDriver bdrv_file =3D { =20 .bdrv_co_truncate =3D raw_co_truncate, .bdrv_co_getlength =3D raw_co_getlength, - .bdrv_get_allocated_file_size - =3D raw_get_allocated_file_size, + .bdrv_co_get_allocated_file_size + =3D raw_co_get_allocated_file_size, =20 .create_opts =3D &raw_create_opts, }; @@ -934,9 +934,7 @@ static BlockDriver bdrv_host_device =3D { =20 .bdrv_co_getlength =3D raw_co_getlength, .has_variable_length =3D true, - - .bdrv_get_allocated_file_size - =3D raw_get_allocated_file_size, + .bdrv_co_get_allocated_file_size =3D raw_co_get_allocated_file_size, }; =20 static void bdrv_file_init(void) diff --git a/block/gluster.c b/block/gluster.c index 469cdf01d4..7b4e1dd795 100644 --- a/block/gluster.c +++ b/block/gluster.c @@ -1330,7 +1330,8 @@ static int64_t coroutine_fn qemu_gluster_co_getlength= (BlockDriverState *bs) } } =20 -static int64_t qemu_gluster_allocated_file_size(BlockDriverState *bs) +static int64_t coroutine_fn +qemu_gluster_co_get_allocated_file_size(BlockDriverState *bs) { BDRVGlusterState *s =3D bs->opaque; struct stat st; @@ -1559,7 +1560,7 @@ static BlockDriver bdrv_gluster =3D { .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_co_getlength =3D qemu_gluster_co_getlength, - .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, + .bdrv_co_get_allocated_file_size =3D qemu_gluster_co_get_allocated_fil= e_size, .bdrv_co_truncate =3D qemu_gluster_co_truncate, .bdrv_co_readv =3D qemu_gluster_co_readv, .bdrv_co_writev =3D qemu_gluster_co_writev, @@ -1588,7 +1589,7 @@ static BlockDriver bdrv_gluster_tcp =3D { .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_co_getlength =3D qemu_gluster_co_getlength, - .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, + .bdrv_co_get_allocated_file_size =3D qemu_gluster_co_get_allocated_fil= e_size, .bdrv_co_truncate =3D qemu_gluster_co_truncate, .bdrv_co_readv =3D qemu_gluster_co_readv, .bdrv_co_writev =3D qemu_gluster_co_writev, @@ -1617,7 +1618,7 @@ static BlockDriver bdrv_gluster_unix =3D { .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_co_getlength =3D qemu_gluster_co_getlength, - .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, + .bdrv_co_get_allocated_file_size =3D qemu_gluster_co_get_allocated_fil= e_size, .bdrv_co_truncate =3D qemu_gluster_co_truncate, .bdrv_co_readv =3D qemu_gluster_co_readv, .bdrv_co_writev =3D qemu_gluster_co_writev, @@ -1652,7 +1653,7 @@ static BlockDriver bdrv_gluster_rdma =3D { .bdrv_co_create =3D qemu_gluster_co_create, .bdrv_co_create_opts =3D qemu_gluster_co_create_opts, .bdrv_co_getlength =3D qemu_gluster_co_getlength, - .bdrv_get_allocated_file_size =3D qemu_gluster_allocated_file_size, + .bdrv_co_get_allocated_file_size =3D qemu_gluster_co_get_allocated_fil= e_size, .bdrv_co_truncate =3D qemu_gluster_co_truncate, .bdrv_co_readv =3D qemu_gluster_co_readv, .bdrv_co_writev =3D qemu_gluster_co_writev, diff --git a/block/nfs.c b/block/nfs.c index ece22353ac..cbf742661e 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -731,7 +731,7 @@ nfs_get_allocated_file_size_cb(int ret, struct nfs_cont= ext *nfs, void *data, bdrv_wakeup(task->bs); } =20 -static int64_t nfs_get_allocated_file_size(BlockDriverState *bs) +static int64_t coroutine_fn nfs_co_get_allocated_file_size(BlockDriverStat= e *bs) { NFSClient *client =3D bs->opaque; NFSRPC task =3D {0}; @@ -884,7 +884,7 @@ static BlockDriver bdrv_nfs =3D { .bdrv_has_zero_init =3D nfs_has_zero_init, /* libnfs does not provide the allocated filesize of a file on win32. */ #if !defined(_WIN32) - .bdrv_get_allocated_file_size =3D nfs_get_allocated_file_size, + .bdrv_co_get_allocated_file_size =3D nfs_co_get_allocated_file_size, #endif .bdrv_co_truncate =3D nfs_file_co_truncate, =20 diff --git a/block/null.c b/block/null.c index 05dde6d9ab..aa5931effa 100644 --- a/block/null.c +++ b/block/null.c @@ -264,7 +264,8 @@ static void null_refresh_filename(BlockDriverState *bs) bs->drv->format_name); } =20 -static int64_t null_allocated_file_size(BlockDriverState *bs) +static int64_t coroutine_fn +null_co_get_allocated_file_size(BlockDriverState *bs) { return 0; } @@ -284,7 +285,7 @@ static BlockDriver bdrv_null_co =3D { .bdrv_file_open =3D null_file_open, .bdrv_parse_filename =3D null_co_parse_filename, .bdrv_co_getlength =3D null_co_getlength, - .bdrv_get_allocated_file_size =3D null_allocated_file_size, + .bdrv_co_get_allocated_file_size =3D null_co_get_allocated_file_size, =20 .bdrv_co_preadv =3D null_co_preadv, .bdrv_co_pwritev =3D null_co_pwritev, @@ -305,7 +306,7 @@ static BlockDriver bdrv_null_aio =3D { .bdrv_file_open =3D null_file_open, .bdrv_parse_filename =3D null_aio_parse_filename, .bdrv_co_getlength =3D null_co_getlength, - .bdrv_get_allocated_file_size =3D null_allocated_file_size, + .bdrv_co_get_allocated_file_size =3D null_co_get_allocated_file_size, =20 .bdrv_aio_preadv =3D null_aio_preadv, .bdrv_aio_pwritev =3D null_aio_pwritev, 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/block/vmdk.c b/block/vmdk.c index 8894dac2d4..04f50d2e49 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2856,14 +2856,15 @@ static void vmdk_close(BlockDriverState *bs) error_free(s->migration_blocker); } =20 -static int64_t vmdk_get_allocated_file_size(BlockDriverState *bs) +static int64_t coroutine_fn +vmdk_co_get_allocated_file_size(BlockDriverState *bs) { int i; int64_t ret =3D 0; int64_t r; BDRVVmdkState *s =3D bs->opaque; =20 - ret =3D bdrv_get_allocated_file_size(bs->file->bs); + ret =3D bdrv_co_get_allocated_file_size(bs->file->bs); if (ret < 0) { return ret; } @@ -2871,7 +2872,7 @@ static int64_t vmdk_get_allocated_file_size(BlockDriv= erState *bs) if (s->extents[i].file =3D=3D bs->file) { continue; } - r =3D bdrv_get_allocated_file_size(s->extents[i].file->bs); + r =3D bdrv_co_get_allocated_file_size(s->extents[i].file->bs); if (r < 0) { return r; } @@ -3124,7 +3125,7 @@ static BlockDriver bdrv_vmdk =3D { .bdrv_co_create_opts =3D vmdk_co_create_opts, .bdrv_co_create =3D vmdk_co_create, .bdrv_co_block_status =3D vmdk_co_block_status, - .bdrv_get_allocated_file_size =3D vmdk_get_allocated_file_size, + .bdrv_co_get_allocated_file_size =3D vmdk_co_get_allocated_file_size, .bdrv_has_zero_init =3D vmdk_has_zero_init, .bdrv_get_specific_info =3D vmdk_get_specific_info, .bdrv_refresh_limits =3D vmdk_refresh_limits, --=20 2.38.1 From nobody Sat Apr 20 01:04:24 2024 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=1673642698; cv=none; d=zohomail.com; s=zohoarc; b=gqvibg7Ba30V9gW0y47FcIt9ruzDE6XJJ0C9VTxyr+T0n4k2dJpK/rrTmQ/Ei/xjf4sGV8Oks14N9oXDVlho8Pkrd+H6VhnBb7oPnMGYETpY7OLO2Aio8dgEH42yrbVAAVyBiJaEu3XKOgGzl/LU2uTK1p3Wtbxe2Dpeen0do7U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673642698; 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=2cw9DUCz5zZIydjHbNSWPOx3q2dCSUllateEZBK3pcI=; b=VMQVv3Mi4WU5coKJkTkYXNqmsldJHHvjmwAdUS+y4eRM1/mTWRaxwf1HcRpOcjNRNmaJ6ypOYSQ9B7dAu0NxpTHTkoTxZ5/GdJ9RMNKcqxfhvIZXEQ3RfgNSJki5m+1Ha3U1sLYLMWQF1aD2AAM6HgMQzZMWBNS5QYhutOvT6L0= 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 1673642698325443.658307699107; Fri, 13 Jan 2023 12:44:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGQt7-0000BJ-8B; Fri, 13 Jan 2023 15:42:57 -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 1pGQt2-000075-ME for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:52 -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 1pGQsz-0006D8-Rc for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:52 -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-100-1n-kqsc7MPaRptBS5KzYKg-1; Fri, 13 Jan 2023 15:42:46 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BF55D2A5956F; Fri, 13 Jan 2023 20:42:45 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.195.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9612F2026D68; Fri, 13 Jan 2023 20:42:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673642569; 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=2cw9DUCz5zZIydjHbNSWPOx3q2dCSUllateEZBK3pcI=; b=FY7Rq0Z+LunR08HUy8MS6PdN1hh0kICeqVRfLXEj0KgZK28WI+ELN4VwziiUVcBOinTYyk l9iwkXikr0uqgQeyK3tiKJMsWcNYm4biYLvh32PyJzifX90D8Wjq/mX9A4P1TO5EEBb8dJ eDo4DNrxF8dYYUMhlqADp2fDvmsdZ9Y= X-MC-Unique: 1n-kqsc7MPaRptBS5KzYKg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v2 10/14] block: Convert bdrv_get_info() to co_wrapper_mixed Date: Fri, 13 Jan 2023 21:42:08 +0100 Message-Id: <20230113204212.359076-11-kwolf@redhat.com> In-Reply-To: <20230113204212.359076-1-kwolf@redhat.com> References: <20230113204212.359076-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: 1673642698928100002 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito bdrv_get_info() is categorized as an I/O function, and it currently doesn't run in a coroutine. We should let it take a graph rdlock since it traverses the block nodes graph, which however is only possible in a coroutine. Therefore turn it into a co_wrapper to move the actual function into a coroutine where the lock can be taken. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 5 ++++- include/block/block_int-common.h | 3 ++- block.c | 8 ++++---- block/blkio.c | 5 +++-- block/crypto.c | 8 ++++---- block/file-posix.c | 7 ++++--- block/io.c | 8 ++++---- block/iscsi.c | 7 ++++--- block/mirror.c | 2 +- block/qcow.c | 5 +++-- block/qcow2.c | 5 +++-- block/qed.c | 5 +++-- block/raw-format.c | 7 ++++--- block/rbd.c | 5 +++-- block/vdi.c | 7 ++++--- block/vhdx.c | 5 +++-- block/vmdk.c | 5 +++-- block/vpc.c | 5 +++-- 18 files changed, 59 insertions(+), 43 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 0718554590..e27dc9787b 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -151,7 +151,10 @@ bool bdrv_supports_compressed_writes(BlockDriverState = *bs); const char *bdrv_get_node_name(const BlockDriverState *bs); const char *bdrv_get_device_name(const BlockDriverState *bs); const char *bdrv_get_device_or_node_name(const BlockDriverState *bs); -int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi); + +int coroutine_fn bdrv_co_get_info(BlockDriverState *bs, BlockDriverInfo *b= di); +int co_wrapper_mixed bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *= bdi); + ImageInfoSpecific *bdrv_get_specific_info(BlockDriverState *bs, Error **errp); BlockStatsSpecific *bdrv_get_specific_stats(BlockDriverState *bs); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index cc03c599e7..a6ac8afd5b 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -697,7 +697,8 @@ struct BlockDriver { int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset); =20 - int (*bdrv_get_info)(BlockDriverState *bs, BlockDriverInfo *bdi); + int coroutine_fn (*bdrv_co_get_info)(BlockDriverState *bs, + BlockDriverInfo *bdi); =20 ImageInfoSpecific *(*bdrv_get_specific_info)(BlockDriverState *bs, Error **errp); diff --git a/block.c b/block.c index 82c6cb6dcd..2707069ab6 100644 --- a/block.c +++ b/block.c @@ -6300,7 +6300,7 @@ void bdrv_get_backing_filename(BlockDriverState *bs, pstrcpy(filename, filename_size, bs->backing_file); } =20 -int bdrv_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +int coroutine_fn bdrv_co_get_info(BlockDriverState *bs, BlockDriverInfo *b= di) { int ret; BlockDriver *drv =3D bs->drv; @@ -6309,15 +6309,15 @@ int bdrv_get_info(BlockDriverState *bs, BlockDriver= Info *bdi) if (!drv) { return -ENOMEDIUM; } - if (!drv->bdrv_get_info) { + if (!drv->bdrv_co_get_info) { BlockDriverState *filtered =3D bdrv_filter_bs(bs); if (filtered) { - return bdrv_get_info(filtered, bdi); + return bdrv_co_get_info(filtered, bdi); } return -ENOTSUP; } memset(bdi, 0, sizeof(*bdi)); - ret =3D drv->bdrv_get_info(bs, bdi); + ret =3D drv->bdrv_co_get_info(bs, bdi); if (ret < 0) { return ret; } diff --git a/block/blkio.c b/block/blkio.c index 2a3ab5a570..fc83e0fe13 100644 --- a/block/blkio.c +++ b/block/blkio.c @@ -878,7 +878,8 @@ static int coroutine_fn blkio_truncate(BlockDriverState= *bs, int64_t offset, return 0; } =20 -static int blkio_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +static int coroutine_fn +blkio_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { return 0; } @@ -998,7 +999,7 @@ static void blkio_refresh_limits(BlockDriverState *bs, = Error **errp) .bdrv_close =3D blkio_close, \ .bdrv_co_getlength =3D blkio_co_getlength, \ .bdrv_co_truncate =3D blkio_truncate, \ - .bdrv_get_info =3D blkio_get_info, \ + .bdrv_co_get_info =3D blkio_co_get_info, \ .bdrv_attach_aio_context =3D blkio_attach_aio_context, \ .bdrv_detach_aio_context =3D blkio_detach_aio_context, \ .bdrv_co_pdiscard =3D blkio_co_pdiscard, \ diff --git a/block/crypto.c b/block/crypto.c index 6d6c006887..b70cec97c7 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -737,13 +737,13 @@ fail: return ret; } =20 -static int block_crypto_get_info_luks(BlockDriverState *bs, - BlockDriverInfo *bdi) +static int coroutine_fn +block_crypto_co_get_info_luks(BlockDriverState *bs, BlockDriverInfo *bdi) { BlockDriverInfo subbdi; int ret; =20 - ret =3D bdrv_get_info(bs->file->bs, &subbdi); + ret =3D bdrv_co_get_info(bs->file->bs, &subbdi); if (ret !=3D 0) { return ret; } @@ -955,7 +955,7 @@ static BlockDriver bdrv_crypto_luks =3D { .bdrv_co_pwritev =3D block_crypto_co_pwritev, .bdrv_co_getlength =3D block_crypto_co_getlength, .bdrv_measure =3D block_crypto_measure, - .bdrv_get_info =3D block_crypto_get_info_luks, + .bdrv_co_get_info =3D block_crypto_co_get_info_luks, .bdrv_get_specific_info =3D block_crypto_get_specific_info_luks, .bdrv_amend_options =3D block_crypto_amend_options_luks, .bdrv_co_amend =3D block_crypto_co_amend_luks, diff --git a/block/file-posix.c b/block/file-posix.c index a22f93e4b2..f128071231 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3090,7 +3090,8 @@ static int coroutine_fn raw_co_pwrite_zeroes( return raw_do_pwrite_zeroes(bs, offset, bytes, flags, false); } =20 -static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +static int coroutine_fn +raw_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { return 0; } @@ -3327,7 +3328,7 @@ BlockDriver bdrv_file =3D { =20 .bdrv_co_truncate =3D raw_co_truncate, .bdrv_co_getlength =3D raw_co_getlength, - .bdrv_get_info =3D raw_get_info, + .bdrv_co_get_info =3D raw_co_get_info, .bdrv_co_get_allocated_file_size =3D raw_co_get_allocated_file_size, .bdrv_get_specific_stats =3D raw_get_specific_stats, .bdrv_check_perm =3D raw_check_perm, @@ -3698,7 +3699,7 @@ static BlockDriver bdrv_host_device =3D { =20 .bdrv_co_truncate =3D raw_co_truncate, .bdrv_co_getlength =3D raw_co_getlength, - .bdrv_get_info =3D raw_get_info, + .bdrv_co_get_info =3D raw_co_get_info, .bdrv_co_get_allocated_file_size =3D raw_co_get_allocated_file_size, .bdrv_get_specific_stats =3D hdev_get_specific_stats, .bdrv_check_perm =3D raw_check_perm, diff --git a/block/io.c b/block/io.c index fdc5ba9fb6..c43637f5c1 100644 --- a/block/io.c +++ b/block/io.c @@ -721,14 +721,14 @@ BdrvTrackedRequest *coroutine_fn bdrv_co_get_self_req= uest(BlockDriverState *bs) /** * Round a region to cluster boundaries */ -void bdrv_round_to_clusters(BlockDriverState *bs, +void coroutine_fn bdrv_round_to_clusters(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *cluster_offset, int64_t *cluster_bytes) { BlockDriverInfo bdi; IO_CODE(); - if (bdrv_get_info(bs, &bdi) < 0 || bdi.cluster_size =3D=3D 0) { + if (bdrv_co_get_info(bs, &bdi) < 0 || bdi.cluster_size =3D=3D 0) { *cluster_offset =3D offset; *cluster_bytes =3D bytes; } else { @@ -738,12 +738,12 @@ void bdrv_round_to_clusters(BlockDriverState *bs, } } =20 -static int bdrv_get_cluster_size(BlockDriverState *bs) +static coroutine_fn int bdrv_get_cluster_size(BlockDriverState *bs) { BlockDriverInfo bdi; int ret; =20 - ret =3D bdrv_get_info(bs, &bdi); + ret =3D bdrv_co_get_info(bs, &bdi); if (ret < 0 || bdi.cluster_size =3D=3D 0) { return bs->bl.request_alignment; } else { diff --git a/block/iscsi.c b/block/iscsi.c index df110dd1d2..b17b86cffd 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -2170,7 +2170,8 @@ static int coroutine_fn iscsi_co_truncate(BlockDriver= State *bs, int64_t offset, return 0; } =20 -static int iscsi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +static int coroutine_fn +iscsi_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { IscsiLun *iscsilun =3D bs->opaque; bdi->cluster_size =3D iscsilun->cluster_size; @@ -2434,7 +2435,7 @@ static BlockDriver bdrv_iscsi =3D { .bdrv_co_invalidate_cache =3D iscsi_co_invalidate_cache, =20 .bdrv_co_getlength =3D iscsi_co_getlength, - .bdrv_get_info =3D iscsi_get_info, + .bdrv_co_get_info =3D iscsi_co_get_info, .bdrv_co_truncate =3D iscsi_co_truncate, .bdrv_refresh_limits =3D iscsi_refresh_limits, =20 @@ -2473,7 +2474,7 @@ static BlockDriver bdrv_iser =3D { .bdrv_co_invalidate_cache =3D iscsi_co_invalidate_cache, =20 .bdrv_co_getlength =3D iscsi_co_getlength, - .bdrv_get_info =3D iscsi_get_info, + .bdrv_co_get_info =3D iscsi_co_get_info, .bdrv_co_truncate =3D iscsi_co_truncate, .bdrv_refresh_limits =3D iscsi_refresh_limits, =20 diff --git a/block/mirror.c b/block/mirror.c index c7d7ce2f8f..26db3ad0d7 100644 --- a/block/mirror.c +++ b/block/mirror.c @@ -956,7 +956,7 @@ static int coroutine_fn mirror_run(Job *job, Error **er= rp) */ bdrv_get_backing_filename(target_bs, backing_filename, sizeof(backing_filename)); - if (!bdrv_get_info(target_bs, &bdi) && bdi.cluster_size) { + if (!bdrv_co_get_info(target_bs, &bdi) && bdi.cluster_size) { s->target_cluster_size =3D bdi.cluster_size; } else { s->target_cluster_size =3D BDRV_SECTOR_SIZE; diff --git a/block/qcow.c b/block/qcow.c index 5d99f00411..5f0801f545 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -1129,7 +1129,8 @@ fail: return ret; } =20 -static int qcow_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +static int coroutine_fn +qcow_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { BDRVQcowState *s =3D bs->opaque; bdi->cluster_size =3D s->cluster_size; @@ -1198,7 +1199,7 @@ static BlockDriver bdrv_qcow =3D { =20 .bdrv_make_empty =3D qcow_make_empty, .bdrv_co_pwritev_compressed =3D qcow_co_pwritev_compressed, - .bdrv_get_info =3D qcow_get_info, + .bdrv_co_get_info =3D qcow_co_get_info, =20 .create_opts =3D &qcow_create_opts, .strong_runtime_opts =3D qcow_strong_runtime_opts, diff --git a/block/qcow2.c b/block/qcow2.c index bafbd077b9..460579b70a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -5142,7 +5142,8 @@ err: return NULL; } =20 -static int qcow2_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +static int coroutine_fn +qcow2_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { BDRVQcow2State *s =3D bs->opaque; bdi->cluster_size =3D s->cluster_size; @@ -6076,7 +6077,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_snapshot_list =3D qcow2_snapshot_list, .bdrv_snapshot_load_tmp =3D qcow2_snapshot_load_tmp, .bdrv_measure =3D qcow2_measure, - .bdrv_get_info =3D qcow2_get_info, + .bdrv_co_get_info =3D qcow2_co_get_info, .bdrv_get_specific_info =3D qcow2_get_specific_info, =20 .bdrv_save_vmstate =3D qcow2_save_vmstate, diff --git a/block/qed.c b/block/qed.c index 16bf0cb080..4473465bba 100644 --- a/block/qed.c +++ b/block/qed.c @@ -1486,7 +1486,8 @@ static int64_t coroutine_fn bdrv_qed_co_getlength(Blo= ckDriverState *bs) return s->header.image_size; } =20 -static int bdrv_qed_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +static int coroutine_fn +bdrv_qed_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { BDRVQEDState *s =3D bs->opaque; =20 @@ -1654,7 +1655,7 @@ static BlockDriver bdrv_qed =3D { .bdrv_co_pwrite_zeroes =3D bdrv_qed_co_pwrite_zeroes, .bdrv_co_truncate =3D bdrv_qed_co_truncate, .bdrv_co_getlength =3D bdrv_qed_co_getlength, - .bdrv_get_info =3D bdrv_qed_get_info, + .bdrv_co_get_info =3D bdrv_qed_co_get_info, .bdrv_refresh_limits =3D bdrv_qed_refresh_limits, .bdrv_change_backing_file =3D bdrv_qed_change_backing_file, .bdrv_co_invalidate_cache =3D bdrv_qed_co_invalidate_cache, diff --git a/block/raw-format.c b/block/raw-format.c index ccf23fe0b2..08f5c74838 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -367,9 +367,10 @@ static BlockMeasureInfo *raw_measure(QemuOpts *opts, B= lockDriverState *in_bs, return info; } =20 -static int raw_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +static int coroutine_fn +raw_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { - return bdrv_get_info(bs->file->bs, bdi); + return bdrv_co_get_info(bs->file->bs, bdi); } =20 static void raw_refresh_limits(BlockDriverState *bs, Error **errp) @@ -625,7 +626,7 @@ BlockDriver bdrv_raw =3D { .is_format =3D true, .has_variable_length =3D true, .bdrv_measure =3D &raw_measure, - .bdrv_get_info =3D &raw_get_info, + .bdrv_co_get_info =3D &raw_co_get_info, .bdrv_refresh_limits =3D &raw_refresh_limits, .bdrv_probe_blocksizes =3D &raw_probe_blocksizes, .bdrv_probe_geometry =3D &raw_probe_geometry, diff --git a/block/rbd.c b/block/rbd.c index c67d30160a..2c03ab8408 100644 --- a/block/rbd.c +++ b/block/rbd.c @@ -1239,7 +1239,8 @@ coroutine_fn qemu_rbd_co_pwrite_zeroes(BlockDriverSta= te *bs, int64_t offset, } #endif =20 -static int qemu_rbd_getinfo(BlockDriverState *bs, BlockDriverInfo *bdi) +static int coroutine_fn +qemu_rbd_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { BDRVRBDState *s =3D bs->opaque; bdi->cluster_size =3D s->object_size; @@ -1650,7 +1651,7 @@ static BlockDriver bdrv_rbd =3D { .bdrv_co_create =3D qemu_rbd_co_create, .bdrv_co_create_opts =3D qemu_rbd_co_create_opts, .bdrv_has_zero_init =3D bdrv_has_zero_init_1, - .bdrv_get_info =3D qemu_rbd_getinfo, + .bdrv_co_get_info =3D qemu_rbd_co_get_info, .bdrv_get_specific_info =3D qemu_rbd_get_specific_info, .create_opts =3D &qemu_rbd_create_opts, .bdrv_co_getlength =3D qemu_rbd_co_getlength, diff --git a/block/vdi.c b/block/vdi.c index 479bcfe820..9c8736b26f 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -327,9 +327,10 @@ static int coroutine_fn vdi_co_check(BlockDriverState = *bs, BdrvCheckResult *res, return 0; } =20 -static int vdi_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +static int coroutine_fn +vdi_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { - /* TODO: vdi_get_info would be needed for machine snapshots. + /* TODO: vdi_co_get_info would be needed for machine snapshots. vm_state_offset is still missing. */ BDRVVdiState *s =3D (BDRVVdiState *)bs->opaque; logout("\n"); @@ -1049,7 +1050,7 @@ static BlockDriver bdrv_vdi =3D { .bdrv_co_pwritev =3D vdi_co_pwritev, #endif =20 - .bdrv_get_info =3D vdi_get_info, + .bdrv_co_get_info =3D vdi_co_get_info, =20 .is_format =3D true, .create_opts =3D &vdi_create_opts, diff --git a/block/vhdx.c b/block/vhdx.c index 4c929800fe..ef1f65d917 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1161,7 +1161,8 @@ static void vhdx_block_translate(BDRVVHDXState *s, in= t64_t sector_num, } =20 =20 -static int vhdx_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +static int coroutine_fn +vhdx_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { BDRVVHDXState *s =3D bs->opaque; =20 @@ -2245,7 +2246,7 @@ static BlockDriver bdrv_vhdx =3D { .bdrv_co_writev =3D vhdx_co_writev, .bdrv_co_create =3D vhdx_co_create, .bdrv_co_create_opts =3D vhdx_co_create_opts, - .bdrv_get_info =3D vhdx_get_info, + .bdrv_co_get_info =3D vhdx_co_get_info, .bdrv_co_check =3D vhdx_co_check, .bdrv_has_zero_init =3D vhdx_has_zero_init, =20 diff --git a/block/vmdk.c b/block/vmdk.c index 04f50d2e49..1bba61ad7d 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -3012,7 +3012,8 @@ static bool vmdk_extents_type_eq(const VmdkExtent *a,= const VmdkExtent *b) (a->flat || a->cluster_sectors =3D=3D b->cluster_sectors); } =20 -static int vmdk_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +static int coroutine_fn +vmdk_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { int i; BDRVVmdkState *s =3D bs->opaque; @@ -3129,7 +3130,7 @@ static BlockDriver bdrv_vmdk =3D { .bdrv_has_zero_init =3D vmdk_has_zero_init, .bdrv_get_specific_info =3D vmdk_get_specific_info, .bdrv_refresh_limits =3D vmdk_refresh_limits, - .bdrv_get_info =3D vmdk_get_info, + .bdrv_co_get_info =3D vmdk_co_get_info, .bdrv_gather_child_options =3D vmdk_gather_child_options, =20 .is_format =3D true, diff --git a/block/vpc.c b/block/vpc.c index 6ee95dcb96..cfdea7db80 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -598,7 +598,8 @@ fail: return ret; } =20 -static int vpc_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +static int coroutine_fn +vpc_co_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) { BDRVVPCState *s =3D (BDRVVPCState *)bs->opaque; =20 @@ -1240,7 +1241,7 @@ static BlockDriver bdrv_vpc =3D { .bdrv_co_pwritev =3D vpc_co_pwritev, .bdrv_co_block_status =3D vpc_co_block_status, =20 - .bdrv_get_info =3D vpc_get_info, + .bdrv_co_get_info =3D vpc_co_get_info, =20 .is_format =3D true, .create_opts =3D &vpc_create_opts, --=20 2.38.1 From nobody Sat Apr 20 01:04:24 2024 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=1673642684; cv=none; d=zohomail.com; s=zohoarc; b=OYUHJIXH+7C70ATOdH21kJlH0UfSzXLItuwcAYFGTVN6e95BonZgtEBA76UMcBYG99SbSngZ68wNxp5KEXl7SaUfUc0ppRUnb0NxYuRtUI9oLJkk0k2QDb/pjadbWP9gyC41Lp/0u7Y15CPq+GrZTUAOGeXFvprahu2GKe81Cd0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673642684; 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=nTXs2E+DeFR5RLPG0BVqzc8EWRfjlpGIVmG7TBaJ6qk=; b=VobkKGRtNDVkSgZvxQQXTFubI4T7OjQ/9Pec96xW4498Af6/2fx3Ixfes0vCvasGPmbwe+pcf9xnMyTMrIotzB4gWDlk9UooGnFfnKB/MOdcnI2IZlMq+lVHP1zY6CKtuUlS/Z7gZ/0rOpHmGiUBVhM+xP3XDXo/2r1ZULJJW8Q= 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 1673642684607347.0101604740586; Fri, 13 Jan 2023 12:44:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGQt7-0000BG-8C; Fri, 13 Jan 2023 15:42:57 -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 1pGQt4-0000AG-T0 for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:54 -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 1pGQt3-0006EB-3W for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:54 -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-152-ld1fco6PN_WrW_NpzuR56w-1; Fri, 13 Jan 2023 15:42:47 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 311BE858F09; Fri, 13 Jan 2023 20:42:47 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.195.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 078332026D68; Fri, 13 Jan 2023 20:42:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673642572; 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=nTXs2E+DeFR5RLPG0BVqzc8EWRfjlpGIVmG7TBaJ6qk=; b=N3lAl4UGhucj4AlbEZx+OY9GLPVs2mS32/3zr9mCLB3imQtK6IO2byBpealJxiDgcrOEAe qOLvZi2MOacIiJd5mClQZ13B9a3Ei3D5L6HPnyx26vq5/ofaznjNSeHbitjYR44xifjZuS +gCDmgzM8M9mI7w8vHFkK0nJ69qMUWo= X-MC-Unique: ld1fco6PN_WrW_NpzuR56w-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v2 11/14] block: Convert bdrv_eject() to co_wrapper Date: Fri, 13 Jan 2023 21:42:09 +0100 Message-Id: <20230113204212.359076-12-kwolf@redhat.com> In-Reply-To: <20230113204212.359076-1-kwolf@redhat.com> References: <20230113204212.359076-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: 1673642684873100003 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito bdrv_eject() is categorized as an I/O function, and it currently doesn't run in a coroutine. We should let it take a graph rdlock since it traverses the block nodes graph, which however is only possible in a coroutine. The only caller of this function is blk_eject(). Therefore make blk_eject() a co_wrapper, so that it always creates a new coroutine, and then make bdrv_eject() coroutine_fn where the lock can be taken. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 3 ++- include/block/block_int-common.h | 2 +- include/sysemu/block-backend-io.h | 4 +++- block.c | 6 +++--- block/block-backend.c | 4 ++-- block/copy-on-read.c | 6 +++--- block/file-posix.c | 8 ++++---- block/filter-compress.c | 7 ++++--- block/raw-format.c | 6 +++--- 9 files changed, 25 insertions(+), 21 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index e27dc9787b..f3d49ea05f 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -144,7 +144,8 @@ bool coroutine_fn bdrv_co_is_inserted(BlockDriverState = *bs); bool co_wrapper bdrv_is_inserted(BlockDriverState *bs); =20 void bdrv_lock_medium(BlockDriverState *bs, bool locked); -void bdrv_eject(BlockDriverState *bs, bool eject_flag); +void coroutine_fn bdrv_co_eject(BlockDriverState *bs, bool eject_flag); + const char *bdrv_get_format_name(BlockDriverState *bs); =20 bool bdrv_supports_compressed_writes(BlockDriverState *bs); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index a6ac8afd5b..1631a26427 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -712,7 +712,7 @@ struct BlockDriver { =20 /* removable device specific */ bool coroutine_fn (*bdrv_co_is_inserted)(BlockDriverState *bs); - void (*bdrv_eject)(BlockDriverState *bs, bool eject_flag); + void coroutine_fn (*bdrv_co_eject)(BlockDriverState *bs, bool eject_fl= ag); void (*bdrv_lock_medium)(BlockDriverState *bs, bool locked); =20 /* to control generic scsi devices */ diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index a1eac6c00a..00209625e1 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -59,7 +59,9 @@ bool co_wrapper_mixed blk_is_inserted(BlockBackend *blk); =20 bool blk_is_available(BlockBackend *blk); void blk_lock_medium(BlockBackend *blk, bool locked); -void blk_eject(BlockBackend *blk, bool eject_flag); + +void coroutine_fn blk_co_eject(BlockBackend *blk, bool eject_flag); +void co_wrapper blk_eject(BlockBackend *blk, bool eject_flag); =20 int64_t coroutine_fn blk_co_getlength(BlockBackend *blk); int64_t co_wrapper_mixed blk_getlength(BlockBackend *blk); diff --git a/block.c b/block.c index 2707069ab6..d8415c9519 100644 --- a/block.c +++ b/block.c @@ -6820,13 +6820,13 @@ bool coroutine_fn bdrv_co_is_inserted(BlockDriverSt= ate *bs) /** * If eject_flag is TRUE, eject the media. Otherwise, close the tray */ -void bdrv_eject(BlockDriverState *bs, bool eject_flag) +void coroutine_fn bdrv_co_eject(BlockDriverState *bs, bool eject_flag) { BlockDriver *drv =3D bs->drv; IO_CODE(); =20 - if (drv && drv->bdrv_eject) { - drv->bdrv_eject(bs, eject_flag); + if (drv && drv->bdrv_co_eject) { + drv->bdrv_co_eject(bs, eject_flag); } } =20 diff --git a/block/block-backend.c b/block/block-backend.c index fc08400544..7320081814 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -2009,14 +2009,14 @@ void blk_lock_medium(BlockBackend *blk, bool locked) } } =20 -void blk_eject(BlockBackend *blk, bool eject_flag) +void coroutine_fn blk_co_eject(BlockBackend *blk, bool eject_flag) { BlockDriverState *bs =3D blk_bs(blk); char *id; IO_CODE(); =20 if (bs) { - bdrv_eject(bs, eject_flag); + bdrv_co_eject(bs, eject_flag); } =20 /* Whether or not we ejected on the backend, diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 41777b87a4..43f09514dc 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -216,9 +216,9 @@ static int coroutine_fn cor_co_pwritev_compressed(Block= DriverState *bs, } =20 =20 -static void cor_eject(BlockDriverState *bs, bool eject_flag) +static void coroutine_fn cor_co_eject(BlockDriverState *bs, bool eject_fla= g) { - bdrv_eject(bs->file->bs, eject_flag); + bdrv_co_eject(bs->file->bs, eject_flag); } =20 =20 @@ -257,7 +257,7 @@ static BlockDriver bdrv_copy_on_read =3D { .bdrv_co_pdiscard =3D cor_co_pdiscard, .bdrv_co_pwritev_compressed =3D cor_co_pwritev_compressed, =20 - .bdrv_eject =3D cor_eject, + .bdrv_co_eject =3D cor_co_eject, .bdrv_lock_medium =3D cor_lock_medium, =20 .has_variable_length =3D true, diff --git a/block/file-posix.c b/block/file-posix.c index f128071231..21f49f9782 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3769,7 +3769,7 @@ static bool coroutine_fn cdrom_co_is_inserted(BlockDr= iverState *bs) return ret =3D=3D CDS_DISC_OK; } =20 -static void cdrom_eject(BlockDriverState *bs, bool eject_flag) +static void coroutine_fn cdrom_co_eject(BlockDriverState *bs, bool eject_f= lag) { BDRVRawState *s =3D bs->opaque; =20 @@ -3827,7 +3827,7 @@ static BlockDriver bdrv_host_cdrom =3D { =20 /* removable device support */ .bdrv_co_is_inserted =3D cdrom_co_is_inserted, - .bdrv_eject =3D cdrom_eject, + .bdrv_co_eject =3D cdrom_co_eject, .bdrv_lock_medium =3D cdrom_lock_medium, =20 /* generic scsi device */ @@ -3890,7 +3890,7 @@ static bool coroutine_fn cdrom_co_is_inserted(BlockDr= iverState *bs) return raw_co_getlength(bs) > 0; } =20 -static void cdrom_eject(BlockDriverState *bs, bool eject_flag) +static void coroutine_fn cdrom_co_eject(BlockDriverState *bs, bool eject_f= lag) { BDRVRawState *s =3D bs->opaque; =20 @@ -3956,7 +3956,7 @@ static BlockDriver bdrv_host_cdrom =3D { =20 /* removable device support */ .bdrv_co_is_inserted =3D cdrom_co_is_inserted, - .bdrv_eject =3D cdrom_eject, + .bdrv_co_eject =3D cdrom_co_eject, .bdrv_lock_medium =3D cdrom_lock_medium, }; #endif /* __FreeBSD__ */ diff --git a/block/filter-compress.c b/block/filter-compress.c index 1515fe5103..97adb3de19 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -116,9 +116,10 @@ static void compress_refresh_limits(BlockDriverState *= bs, Error **errp) } =20 =20 -static void compress_eject(BlockDriverState *bs, bool eject_flag) +static void coroutine_fn +compress_co_eject(BlockDriverState *bs, bool eject_flag) { - bdrv_eject(bs->file->bs, eject_flag); + bdrv_co_eject(bs->file->bs, eject_flag); } =20 =20 @@ -142,7 +143,7 @@ static BlockDriver bdrv_compress =3D { .bdrv_co_pdiscard =3D compress_co_pdiscard, .bdrv_refresh_limits =3D compress_refresh_limits, =20 - .bdrv_eject =3D compress_eject, + .bdrv_co_eject =3D compress_co_eject, .bdrv_lock_medium =3D compress_lock_medium, =20 .has_variable_length =3D true, diff --git a/block/raw-format.c b/block/raw-format.c index 08f5c74838..2585e9ef96 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -404,9 +404,9 @@ static int coroutine_fn raw_co_truncate(BlockDriverStat= e *bs, int64_t offset, return bdrv_co_truncate(bs->file, offset, exact, prealloc, flags, errp= ); } =20 -static void raw_eject(BlockDriverState *bs, bool eject_flag) +static void coroutine_fn raw_co_eject(BlockDriverState *bs, bool eject_fla= g) { - bdrv_eject(bs->file->bs, eject_flag); + bdrv_co_eject(bs->file->bs, eject_flag); } =20 static void raw_lock_medium(BlockDriverState *bs, bool locked) @@ -630,7 +630,7 @@ BlockDriver bdrv_raw =3D { .bdrv_refresh_limits =3D &raw_refresh_limits, .bdrv_probe_blocksizes =3D &raw_probe_blocksizes, .bdrv_probe_geometry =3D &raw_probe_geometry, - .bdrv_eject =3D &raw_eject, + .bdrv_co_eject =3D &raw_co_eject, .bdrv_lock_medium =3D &raw_lock_medium, .bdrv_co_ioctl =3D &raw_co_ioctl, .create_opts =3D &raw_create_opts, --=20 2.38.1 From nobody Sat Apr 20 01:04:24 2024 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=1673642660; cv=none; d=zohomail.com; s=zohoarc; b=er9iV6b/sBHNSxSPtj12kfoyhiO2BsTGpYtIUcA5i1YygLl1NUFs7+Dw9fQs8Qvv+hL9HxY9U3hh8yVCIsQN09MHwXQVPG+/MfZ57UXurSdtrEYancDshe27Xptxj07xd8W+h1U45ZRDBk0OdwiG90TskpVpTN0G3mLwmn63cVk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673642660; 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=R0Fw5S4R8JiKyy7j8E2+vB0YDvtiKDgJJa2hopxF7E4=; b=TPBMoGPNY/nfLlaLj7a0kDZEqVu2iwDMYdNdJsNvVww2nmIX0pDZYuEFaXm90TljNBtqbxFaoWjxkGWvecCH3l4mcuVtoJnDPz02+qUe/mI8WE4mlR++++3L7WttfTob3dK3uOTcmwdD/hzQ+KTPi8ur5wisLoid84LwWMfFolc= 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 1673642660037907.7495045213476; Fri, 13 Jan 2023 12:44:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGQt9-0000CQ-6r; Fri, 13 Jan 2023 15:42:59 -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 1pGQt5-0000Ac-5b for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:55 -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 1pGQt3-0006EG-Br for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:54 -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-625-SkM0-DIfPkegPnYHstBGEg-1; Fri, 13 Jan 2023 15:42:49 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9C1BD380671C; Fri, 13 Jan 2023 20:42:48 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.195.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F4FC2026D68; Fri, 13 Jan 2023 20:42:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673642572; 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=R0Fw5S4R8JiKyy7j8E2+vB0YDvtiKDgJJa2hopxF7E4=; b=gzIjOcs1HSTHqneNsGozkz/rJqEyEqTHWBk6a6kw+mpOf2N2vOWyohlw6IYM3ztynisfH9 Opod4frLU+d1kcJ7ZD3VSJ/42hhUNtcuyQD06Mm0ldg/ES1Ed8DLh7PCl1W+em4N8O42d7 eYJy8Mnj8Sd70CMYqgbsdrOvdF7MRP0= X-MC-Unique: SkM0-DIfPkegPnYHstBGEg-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v2 12/14] block: Convert bdrv_lock_medium() to co_wrapper Date: Fri, 13 Jan 2023 21:42:10 +0100 Message-Id: <20230113204212.359076-13-kwolf@redhat.com> In-Reply-To: <20230113204212.359076-1-kwolf@redhat.com> References: <20230113204212.359076-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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.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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1673642660811100001 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito bdrv_lock_medium() is categorized as an I/O function, and it currently doesn't run in a coroutine. We should let it take a graph rdlock since it traverses the block nodes graph, which however is only possible in a coroutine. The only caller of this function is blk_lock_medium(). Therefore make blk_lock_medium() a co_wrapper, so that it always creates a new coroutine, and then make bdrv_lock_medium() a coroutine_fn where the lock can be taken. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 2 +- include/block/block_int-common.h | 2 +- include/sysemu/block-backend-io.h | 4 +++- block.c | 6 +++--- block/block-backend.c | 4 ++-- block/copy-on-read.c | 6 +++--- block/file-posix.c | 8 ++++---- block/filter-compress.c | 7 ++++--- block/raw-format.c | 6 +++--- 9 files changed, 24 insertions(+), 21 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index f3d49ea05f..7e76bb647a 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -143,7 +143,7 @@ int bdrv_get_flags(BlockDriverState *bs); bool coroutine_fn bdrv_co_is_inserted(BlockDriverState *bs); bool co_wrapper bdrv_is_inserted(BlockDriverState *bs); =20 -void bdrv_lock_medium(BlockDriverState *bs, bool locked); +void coroutine_fn bdrv_co_lock_medium(BlockDriverState *bs, bool locked); void coroutine_fn bdrv_co_eject(BlockDriverState *bs, bool eject_flag); =20 const char *bdrv_get_format_name(BlockDriverState *bs); diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 1631a26427..1174f13a2f 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -713,7 +713,7 @@ struct BlockDriver { /* removable device specific */ bool coroutine_fn (*bdrv_co_is_inserted)(BlockDriverState *bs); void coroutine_fn (*bdrv_co_eject)(BlockDriverState *bs, bool eject_fl= ag); - void (*bdrv_lock_medium)(BlockDriverState *bs, bool locked); + void coroutine_fn (*bdrv_co_lock_medium)(BlockDriverState *bs, bool lo= cked); =20 /* to control generic scsi devices */ BlockAIOCB *(*bdrv_aio_ioctl)(BlockDriverState *bs, diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index 00209625e1..780c1e5f77 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -58,7 +58,9 @@ bool coroutine_fn blk_co_is_inserted(BlockBackend *blk); bool co_wrapper_mixed blk_is_inserted(BlockBackend *blk); =20 bool blk_is_available(BlockBackend *blk); -void blk_lock_medium(BlockBackend *blk, bool locked); + +void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked); +void co_wrapper blk_lock_medium(BlockBackend *blk, bool locked); =20 void coroutine_fn blk_co_eject(BlockBackend *blk, bool eject_flag); void co_wrapper blk_eject(BlockBackend *blk, bool eject_flag); diff --git a/block.c b/block.c index d8415c9519..b7ccb44184 100644 --- a/block.c +++ b/block.c @@ -6834,14 +6834,14 @@ void coroutine_fn bdrv_co_eject(BlockDriverState *b= s, bool eject_flag) * Lock or unlock the media (if it is locked, the user won't be able * to eject it manually). */ -void bdrv_lock_medium(BlockDriverState *bs, bool locked) +void coroutine_fn bdrv_co_lock_medium(BlockDriverState *bs, bool locked) { BlockDriver *drv =3D bs->drv; IO_CODE(); trace_bdrv_lock_medium(bs, locked); =20 - if (drv && drv->bdrv_lock_medium) { - drv->bdrv_lock_medium(bs, locked); + if (drv && drv->bdrv_co_lock_medium) { + drv->bdrv_co_lock_medium(bs, locked); } } =20 diff --git a/block/block-backend.c b/block/block-backend.c index 7320081814..11e46ecb51 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1999,13 +1999,13 @@ bool blk_is_available(BlockBackend *blk) return blk_is_inserted(blk) && !blk_dev_is_tray_open(blk); } =20 -void blk_lock_medium(BlockBackend *blk, bool locked) +void coroutine_fn blk_co_lock_medium(BlockBackend *blk, bool locked) { BlockDriverState *bs =3D blk_bs(blk); IO_CODE(); =20 if (bs) { - bdrv_lock_medium(bs, locked); + bdrv_co_lock_medium(bs, locked); } } =20 diff --git a/block/copy-on-read.c b/block/copy-on-read.c index 43f09514dc..5032b78efc 100644 --- a/block/copy-on-read.c +++ b/block/copy-on-read.c @@ -222,9 +222,9 @@ static void coroutine_fn cor_co_eject(BlockDriverState = *bs, bool eject_flag) } =20 =20 -static void cor_lock_medium(BlockDriverState *bs, bool locked) +static void coroutine_fn cor_co_lock_medium(BlockDriverState *bs, bool loc= ked) { - bdrv_lock_medium(bs->file->bs, locked); + bdrv_co_lock_medium(bs->file->bs, locked); } =20 =20 @@ -258,7 +258,7 @@ static BlockDriver bdrv_copy_on_read =3D { .bdrv_co_pwritev_compressed =3D cor_co_pwritev_compressed, =20 .bdrv_co_eject =3D cor_co_eject, - .bdrv_lock_medium =3D cor_lock_medium, + .bdrv_co_lock_medium =3D cor_co_lock_medium, =20 .has_variable_length =3D true, .is_filter =3D true, diff --git a/block/file-posix.c b/block/file-posix.c index 21f49f9782..0dc4546740 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -3782,7 +3782,7 @@ static void coroutine_fn cdrom_co_eject(BlockDriverSt= ate *bs, bool eject_flag) } } =20 -static void cdrom_lock_medium(BlockDriverState *bs, bool locked) +static void coroutine_fn cdrom_co_lock_medium(BlockDriverState *bs, bool l= ocked) { BDRVRawState *s =3D bs->opaque; =20 @@ -3828,7 +3828,7 @@ static BlockDriver bdrv_host_cdrom =3D { /* removable device support */ .bdrv_co_is_inserted =3D cdrom_co_is_inserted, .bdrv_co_eject =3D cdrom_co_eject, - .bdrv_lock_medium =3D cdrom_lock_medium, + .bdrv_co_lock_medium =3D cdrom_co_lock_medium, =20 /* generic scsi device */ .bdrv_co_ioctl =3D hdev_co_ioctl, @@ -3910,7 +3910,7 @@ static void coroutine_fn cdrom_co_eject(BlockDriverSt= ate *bs, bool eject_flag) cdrom_reopen(bs); } =20 -static void cdrom_lock_medium(BlockDriverState *bs, bool locked) +static void coroutine_fn cdrom_co_lock_medium(BlockDriverState *bs, bool l= ocked) { BDRVRawState *s =3D bs->opaque; =20 @@ -3957,7 +3957,7 @@ static BlockDriver bdrv_host_cdrom =3D { /* removable device support */ .bdrv_co_is_inserted =3D cdrom_co_is_inserted, .bdrv_co_eject =3D cdrom_co_eject, - .bdrv_lock_medium =3D cdrom_lock_medium, + .bdrv_co_lock_medium =3D cdrom_co_lock_medium, }; #endif /* __FreeBSD__ */ =20 diff --git a/block/filter-compress.c b/block/filter-compress.c index 97adb3de19..a4e7b191bd 100644 --- a/block/filter-compress.c +++ b/block/filter-compress.c @@ -123,9 +123,10 @@ compress_co_eject(BlockDriverState *bs, bool eject_fla= g) } =20 =20 -static void compress_lock_medium(BlockDriverState *bs, bool locked) +static void coroutine_fn +compress_co_lock_medium(BlockDriverState *bs, bool locked) { - bdrv_lock_medium(bs->file->bs, locked); + bdrv_co_lock_medium(bs->file->bs, locked); } =20 =20 @@ -144,7 +145,7 @@ static BlockDriver bdrv_compress =3D { .bdrv_refresh_limits =3D compress_refresh_limits, =20 .bdrv_co_eject =3D compress_co_eject, - .bdrv_lock_medium =3D compress_lock_medium, + .bdrv_co_lock_medium =3D compress_co_lock_medium, =20 .has_variable_length =3D true, .is_filter =3D true, diff --git a/block/raw-format.c b/block/raw-format.c index 2585e9ef96..44d2e8a727 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -409,9 +409,9 @@ static void coroutine_fn raw_co_eject(BlockDriverState = *bs, bool eject_flag) bdrv_co_eject(bs->file->bs, eject_flag); } =20 -static void raw_lock_medium(BlockDriverState *bs, bool locked) +static void coroutine_fn raw_co_lock_medium(BlockDriverState *bs, bool loc= ked) { - bdrv_lock_medium(bs->file->bs, locked); + bdrv_co_lock_medium(bs->file->bs, locked); } =20 static int coroutine_fn raw_co_ioctl(BlockDriverState *bs, @@ -631,7 +631,7 @@ BlockDriver bdrv_raw =3D { .bdrv_probe_blocksizes =3D &raw_probe_blocksizes, .bdrv_probe_geometry =3D &raw_probe_geometry, .bdrv_co_eject =3D &raw_co_eject, - .bdrv_lock_medium =3D &raw_lock_medium, + .bdrv_co_lock_medium =3D &raw_co_lock_medium, .bdrv_co_ioctl =3D &raw_co_ioctl, .create_opts =3D &raw_create_opts, .bdrv_has_zero_init =3D &raw_has_zero_init, --=20 2.38.1 From nobody Sat Apr 20 01:04:24 2024 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=1673642684; cv=none; d=zohomail.com; s=zohoarc; b=Lzx7BYfQJRRfP+2npLm/8TfNdtuZT8l4VNYzcpNcD4h+CnSIPcsZ2/44GjYWSJEoboW65UsHNeYYDVxMi3ebk3FQrKGewFifxW94PcTEC85fMaQBvJzKhb66E1Q23cq2rTHi4XsVV0HsQ51B/ZTtJGpP/DrKxvHgV6aTKp7+A7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673642684; 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=HnFhnt7suoH9y+klP6s7oLgHVocxZtgqwjMhiQri7MQ=; b=RhkC7cBUNZjn9JtsvPZKoCIqvB3ABogeBc8c9PmnizkWaZF6Ov9BHury0iBEMlCjcXQgzvjDn4MQ0talqZ/c2H80c3U++QSnObgNitvjodRcBvZF4UL65tQi9IswG7BtPWf+Kj1Jl/Lf4q0LsFHw/C2J/56h4gTeEao4f8qJ7Aw= 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 1673642684247284.2120322265981; Fri, 13 Jan 2023 12:44:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGQt5-0000Ax-L9; Fri, 13 Jan 2023 15:42: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 1pGQt3-00009z-SF for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:53 -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 1pGQt2-0006Dn-3k for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:53 -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-444-rsLRhIKFM-6lcJ3KnWhhpQ-1; Fri, 13 Jan 2023 15:42:50 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1904E38123B9; Fri, 13 Jan 2023 20:42:50 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.195.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA43E2026D68; Fri, 13 Jan 2023 20:42:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673642571; 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=HnFhnt7suoH9y+klP6s7oLgHVocxZtgqwjMhiQri7MQ=; b=Mg4dSkRe02OjqLd2BK/Bk14FvPrtwHJdnV51gpkXD8aQNJTvRhYwiC1NvT1YoIOE/iARZJ nhfGYIat/cRfOe1WsrUofz+RI7NBftKVsJuvMzwzr5YM0qT6X528x4PQofocfrcO4tKtNz SlYZHLoFsLxyJBocq49MXJmcreeq5DI= X-MC-Unique: rsLRhIKFM-6lcJ3KnWhhpQ-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v2 13/14] block: Convert bdrv_debug_event() to co_wrapper_mixed Date: Fri, 13 Jan 2023 21:42:11 +0100 Message-Id: <20230113204212.359076-14-kwolf@redhat.com> In-Reply-To: <20230113204212.359076-1-kwolf@redhat.com> References: <20230113204212.359076-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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: 1673642684837100002 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito bdrv_debug_event() is categorized as an I/O function, and it currently doesn't run in a coroutine. We should let it take a graph rdlock since it traverses the block nodes graph, which however is only possible in a coroutine. Therefore turn it into a co_wrapper_mixed to move the actual function into a coroutine where the lock can be taken. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block-io.h | 5 ++++- include/block/block_int-common.h | 3 ++- block.c | 6 +++--- block/blkdebug.c | 5 +++-- block/io.c | 22 +++++++++++----------- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/include/block/block-io.h b/include/block/block-io.h index 7e76bb647a..9737fc63cb 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -188,7 +188,10 @@ void *qemu_try_blockalign0(BlockDriverState *bs, size_= t size); void bdrv_enable_copy_on_read(BlockDriverState *bs); void bdrv_disable_copy_on_read(BlockDriverState *bs); =20 -void bdrv_debug_event(BlockDriverState *bs, BlkdebugEvent event); +void coroutine_fn bdrv_co_debug_event(BlockDriverState *bs, + BlkdebugEvent event); +void co_wrapper_mixed bdrv_debug_event(BlockDriverState *bs, + BlkdebugEvent event); =20 #define BLKDBG_EVENT(child, evt) \ do { \ diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 1174f13a2f..93d4350f24 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -729,7 +729,8 @@ struct BlockDriver { int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_check)( BlockDriverState *bs, BdrvCheckResult *result, BdrvCheckMode fix); =20 - void (*bdrv_debug_event)(BlockDriverState *bs, BlkdebugEvent event); + void coroutine_fn (*bdrv_co_debug_event)(BlockDriverState *bs, + BlkdebugEvent event); =20 /* io queue for linux-aio */ void coroutine_fn (*bdrv_co_io_plug)(BlockDriverState *bs); diff --git a/block.c b/block.c index b7ccb44184..eebb4560c4 100644 --- a/block.c +++ b/block.c @@ -6350,14 +6350,14 @@ BlockStatsSpecific *bdrv_get_specific_stats(BlockDr= iverState *bs) return drv->bdrv_get_specific_stats(bs); } =20 -void bdrv_debug_event(BlockDriverState *bs, BlkdebugEvent event) +void coroutine_fn bdrv_co_debug_event(BlockDriverState *bs, BlkdebugEvent = event) { IO_CODE(); - if (!bs || !bs->drv || !bs->drv->bdrv_debug_event) { + if (!bs || !bs->drv || !bs->drv->bdrv_co_debug_event) { return; } =20 - bs->drv->bdrv_debug_event(bs, event); + bs->drv->bdrv_co_debug_event(bs, event); } =20 static BlockDriverState *bdrv_find_debug_node(BlockDriverState *bs) diff --git a/block/blkdebug.c b/block/blkdebug.c index 2294b0227b..69aa7aa43d 100644 --- a/block/blkdebug.c +++ b/block/blkdebug.c @@ -835,7 +835,8 @@ static void process_rule(BlockDriverState *bs, struct B= lkdebugRule *rule, } } =20 -static void blkdebug_debug_event(BlockDriverState *bs, BlkdebugEvent event) +static void coroutine_fn +blkdebug_co_debug_event(BlockDriverState *bs, BlkdebugEvent event) { BDRVBlkdebugState *s =3D bs->opaque; struct BlkdebugRule *rule, *next; @@ -1085,7 +1086,7 @@ static BlockDriver bdrv_blkdebug =3D { .bdrv_co_pdiscard =3D blkdebug_co_pdiscard, .bdrv_co_block_status =3D blkdebug_co_block_status, =20 - .bdrv_debug_event =3D blkdebug_debug_event, + .bdrv_co_debug_event =3D blkdebug_co_debug_event, .bdrv_debug_breakpoint =3D blkdebug_debug_breakpoint, .bdrv_debug_remove_breakpoint =3D blkdebug_debug_remove_breakpoint, diff --git a/block/io.c b/block/io.c index c43637f5c1..cd1cea2515 100644 --- a/block/io.c +++ b/block/io.c @@ -1250,7 +1250,7 @@ static int coroutine_fn bdrv_co_do_copy_on_readv(Bdrv= Child *child, goto err; } =20 - bdrv_debug_event(bs, BLKDBG_COR_WRITE); + bdrv_co_debug_event(bs, BLKDBG_COR_WRITE); if (drv->bdrv_co_pwrite_zeroes && buffer_is_zero(bounce_buffer, pnum)) { /* FIXME: Should we (perhaps conditionally) be setting @@ -1495,10 +1495,10 @@ static coroutine_fn int bdrv_padding_rmw_read(BdrvC= hild *child, qemu_iovec_init_buf(&local_qiov, pad->buf, bytes); =20 if (pad->head) { - bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_HEAD); + bdrv_co_debug_event(bs, BLKDBG_PWRITEV_RMW_HEAD); } if (pad->merge_reads && pad->tail) { - bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_TAIL); + bdrv_co_debug_event(bs, BLKDBG_PWRITEV_RMW_TAIL); } ret =3D bdrv_aligned_preadv(child, req, req->overlap_offset, bytes, align, &local_qiov, 0, 0); @@ -1506,10 +1506,10 @@ static coroutine_fn int bdrv_padding_rmw_read(BdrvC= hild *child, return ret; } if (pad->head) { - bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_HEAD); + bdrv_co_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_HEAD); } if (pad->merge_reads && pad->tail) { - bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_TAIL); + bdrv_co_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_TAIL); } =20 if (pad->merge_reads) { @@ -1520,7 +1520,7 @@ static coroutine_fn int bdrv_padding_rmw_read(BdrvChi= ld *child, if (pad->tail) { qemu_iovec_init_buf(&local_qiov, pad->tail_buf, align); =20 - bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_TAIL); + bdrv_co_debug_event(bs, BLKDBG_PWRITEV_RMW_TAIL); ret =3D bdrv_aligned_preadv( child, req, req->overlap_offset + req->overlap_bytes - align, @@ -1528,7 +1528,7 @@ static coroutine_fn int bdrv_padding_rmw_read(BdrvChi= ld *child, if (ret < 0) { return ret; } - bdrv_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_TAIL); + bdrv_co_debug_event(bs, BLKDBG_PWRITEV_RMW_AFTER_TAIL); } =20 zero_mem: @@ -1930,16 +1930,16 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvCh= ild *child, if (ret < 0) { /* Do nothing, write notifier decided to fail this request */ } else if (flags & BDRV_REQ_ZERO_WRITE) { - bdrv_debug_event(bs, BLKDBG_PWRITEV_ZERO); + bdrv_co_debug_event(bs, BLKDBG_PWRITEV_ZERO); ret =3D bdrv_co_do_pwrite_zeroes(bs, offset, bytes, flags); } else if (flags & BDRV_REQ_WRITE_COMPRESSED) { ret =3D bdrv_driver_pwritev_compressed(bs, offset, bytes, qiov, qiov_offset); } else if (bytes <=3D max_transfer) { - bdrv_debug_event(bs, BLKDBG_PWRITEV); + bdrv_co_debug_event(bs, BLKDBG_PWRITEV); ret =3D bdrv_driver_pwritev(bs, offset, bytes, qiov, qiov_offset, = flags); } else { - bdrv_debug_event(bs, BLKDBG_PWRITEV); + bdrv_co_debug_event(bs, BLKDBG_PWRITEV); while (bytes_remaining) { int num =3D MIN(bytes_remaining, max_transfer); int local_flags =3D flags; @@ -1962,7 +1962,7 @@ static int coroutine_fn bdrv_aligned_pwritev(BdrvChil= d *child, bytes_remaining -=3D num; } } - bdrv_debug_event(bs, BLKDBG_PWRITEV_DONE); + bdrv_co_debug_event(bs, BLKDBG_PWRITEV_DONE); =20 if (ret >=3D 0) { ret =3D 0; --=20 2.38.1 From nobody Sat Apr 20 01:04:24 2024 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=1673642687; cv=none; d=zohomail.com; s=zohoarc; b=OTpNsn52tIVliB+rYRDEp5RfxrsnzAQnuLN5WX1qi1VYUjNhU4upHVlr5vcS1FEgefPvs/RbOUuy3TliGGutLCGrbFdFjvUuf6uhEc6q7rs5lJ0ZvNwioEopga0syDirff0SM76/Jx/HQcdUe00ztu12ZoRSVUIvuUycZqAs63o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673642687; 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=qEFdT+64m/Zt6OcrqolD720WMNagtS1mk6rPtOnmYOQ=; b=HrSK5yVmh2R1pVhdCTSqRVkrABii4TLYbFGdR4j6c5uh4mL9NY4N0GGYipY4WEZZM0pTxgAcr0pJQwUT7aSuTNjkOznkBAijy3s/vLn/gdSNp78zxl7RcdZLySz4LDFP9YhlBBxvpDwV2KKH3alGzyydSzd1gz25A7xSKosqcKg= 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 1673642687912451.2775338574305; Fri, 13 Jan 2023 12:44:47 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pGQt8-0000CM-Uw; Fri, 13 Jan 2023 15:42: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 1pGQt7-0000BL-7G for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:57 -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 1pGQt5-0006F7-KY for qemu-devel@nongnu.org; Fri, 13 Jan 2023 15:42:56 -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-331-Ih6ID9y7P6ugWlYHu1UXDA-1; Fri, 13 Jan 2023 15:42:51 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 821D2281DE7C; Fri, 13 Jan 2023 20:42:51 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.195.6]) by smtp.corp.redhat.com (Postfix) with ESMTP id 560532026D68; Fri, 13 Jan 2023 20:42:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673642575; 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=qEFdT+64m/Zt6OcrqolD720WMNagtS1mk6rPtOnmYOQ=; b=XxgN9FZysnl7J9F0uoeuV8yuNwqxharaJJpzmfOA+oPrNqiHT3WgXmGIe7nl8+dIAcydfl jcd6TbJtXkNgokOWOgFGkEGammRe3WqtlJHWgvfXTyd0f+hq9FoSYsUZTJPUxGK1J8M55L 6P0b0AgzPuAk/rN1Y19C8fXYIBHEmJ4= X-MC-Unique: Ih6ID9y7P6ugWlYHu1UXDA-1 From: Kevin Wolf To: qemu-block@nongnu.org Cc: kwolf@redhat.com, hreitz@redhat.com, eesposit@redhat.com, pbonzini@redhat.com, vsementsov@yandex-team.ru, qemu-devel@nongnu.org Subject: [PATCH v2 14/14] block: Rename bdrv_load/save_vmstate() to bdrv_co_load/save_vmstate() Date: Fri, 13 Jan 2023 21:42:12 +0100 Message-Id: <20230113204212.359076-15-kwolf@redhat.com> In-Reply-To: <20230113204212.359076-1-kwolf@redhat.com> References: <20230113204212.359076-1-kwolf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 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.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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1673642688850100010 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito Since these functions always run in coroutine context, adjust their name to include "_co_", just like all other BlockDriver callbacks. No functional change intended. Signed-off-by: Emanuele Giuseppe Esposito Signed-off-by: Kevin Wolf Reviewed-by: Emanuele Giuseppe Esposito --- include/block/block_int-common.h | 4 ++-- block/io.c | 8 ++++---- block/qcow2.c | 12 ++++++------ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/block/block_int-common.h b/include/block/block_int-com= mon.h index 93d4350f24..fd8ccaefee 100644 --- a/include/block/block_int-common.h +++ b/include/block/block_int-common.h @@ -704,10 +704,10 @@ struct BlockDriver { Error **errp); BlockStatsSpecific *(*bdrv_get_specific_stats)(BlockDriverState *bs); =20 - int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_save_vmstate)( + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_save_vmstate)( BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); =20 - int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_load_vmstate)( + int coroutine_fn GRAPH_RDLOCK_PTR (*bdrv_co_load_vmstate)( BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); =20 /* removable device specific */ diff --git a/block/io.c b/block/io.c index cd1cea2515..445c757c2a 100644 --- a/block/io.c +++ b/block/io.c @@ -2719,8 +2719,8 @@ bdrv_co_readv_vmstate(BlockDriverState *bs, QEMUIOVec= tor *qiov, int64_t pos) =20 bdrv_inc_in_flight(bs); =20 - if (drv->bdrv_load_vmstate) { - ret =3D drv->bdrv_load_vmstate(bs, qiov, pos); + if (drv->bdrv_co_load_vmstate) { + ret =3D drv->bdrv_co_load_vmstate(bs, qiov, pos); } else if (child_bs) { ret =3D bdrv_co_readv_vmstate(child_bs, qiov, pos); } else { @@ -2752,8 +2752,8 @@ bdrv_co_writev_vmstate(BlockDriverState *bs, QEMUIOVe= ctor *qiov, int64_t pos) =20 bdrv_inc_in_flight(bs); =20 - if (drv->bdrv_save_vmstate) { - ret =3D drv->bdrv_save_vmstate(bs, qiov, pos); + if (drv->bdrv_co_save_vmstate) { + ret =3D drv->bdrv_co_save_vmstate(bs, qiov, pos); } else if (child_bs) { ret =3D bdrv_co_writev_vmstate(child_bs, qiov, pos); } else { diff --git a/block/qcow2.c b/block/qcow2.c index 460579b70a..ce644dfc59 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -5286,8 +5286,8 @@ static int64_t qcow2_check_vmstate_request(BlockDrive= rState *bs, return pos; } =20 -static coroutine_fn int qcow2_save_vmstate(BlockDriverState *bs, - QEMUIOVector *qiov, int64_t pos) +static coroutine_fn int qcow2_co_save_vmstate(BlockDriverState *bs, + QEMUIOVector *qiov, int64_t = pos) { int64_t offset =3D qcow2_check_vmstate_request(bs, qiov, pos); if (offset < 0) { @@ -5298,8 +5298,8 @@ static coroutine_fn int qcow2_save_vmstate(BlockDrive= rState *bs, return bs->drv->bdrv_co_pwritev_part(bs, offset, qiov->size, qiov, 0, = 0); } =20 -static coroutine_fn int qcow2_load_vmstate(BlockDriverState *bs, - QEMUIOVector *qiov, int64_t pos) +static coroutine_fn int qcow2_co_load_vmstate(BlockDriverState *bs, + QEMUIOVector *qiov, int64_t = pos) { int64_t offset =3D qcow2_check_vmstate_request(bs, qiov, pos); if (offset < 0) { @@ -6080,8 +6080,8 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_co_get_info =3D qcow2_co_get_info, .bdrv_get_specific_info =3D qcow2_get_specific_info, =20 - .bdrv_save_vmstate =3D qcow2_save_vmstate, - .bdrv_load_vmstate =3D qcow2_load_vmstate, + .bdrv_co_save_vmstate =3D qcow2_co_save_vmstate, + .bdrv_co_load_vmstate =3D qcow2_co_load_vmstate, =20 .is_format =3D true, .supports_backing =3D true, --=20 2.38.1