From nobody Mon May 6 00:41:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669383750; cv=none; d=zohomail.com; s=zohoarc; b=a5BqqArzR/P1tf9AoNjPWGMG4JI/Om9wuux5bfqaCIY1L15VY5S9ho3QCoMLRb0RWYLCBsJq+JPeYQFNvassP76mfmMhobFaJRDQw1J6GsV5r7RFW+gfy+/9axPhKuKKWtu0lMVxbymVnORXaWSe6zTKszk9+CtMnMHVx67+pY4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669383750; 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=0MegTA9Glc87FAKqb9YJl0uFOzu0+Mn/9y75BuZRgzc=; b=R/8GNouumz9fCc5RLBsNrW3j8Tlr3um/Tgqsb8wFs6lcbcdINJIh4/xlC/AgEH7GkXinwZWGYQ/tNYeKLH6eo16ar8+Q2dd4zDcbxjtLsnJb4pO4pDGzi4V5armvewPZr7zmIzXteFJBtYfV+OLxrBXtJqxxdLADE8jZxMUk2cs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669383750302384.3993374916827; Fri, 25 Nov 2022 05:42:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyYs0-0006kE-9F; Fri, 25 Nov 2022 08:35:56 -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 1oyYrc-0006Rj-BR for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:35 -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 1oyYrX-0005Bm-J9 for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:31 -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-595-g1wcu9-PPqONAE-_G0YOkw-1; Fri, 25 Nov 2022 08:35:22 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DE667101A528; Fri, 25 Nov 2022 13:35:21 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D9772166B46; Fri, 25 Nov 2022 13:35:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669383324; 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=0MegTA9Glc87FAKqb9YJl0uFOzu0+Mn/9y75BuZRgzc=; b=HI9n98Wo+F7kfhmWQ5aOk3Y8mVSi6hVbsGxlnVs5+PuuZyo6opHV1lIqgfsv61b/BxKm8Y +eKSQwHi9Q2zPvW1Q8efMLrXUq32fs9/Y94LrJuI+PdnBWo09OJfisrs8D+4bqwtwrMPy6 90ljV6KwnsvWuVrtUpyWa98yS2apkQU= X-MC-Unique: g1wcu9-PPqONAE-_G0YOkw-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v6 01/14] block-io: introduce coroutine_fn duplicates for bdrv_common_block_status_above callers Date: Fri, 25 Nov 2022 08:35:05 -0500 Message-Id: <20221125133518.418328-2-eesposit@redhat.com> In-Reply-To: <20221125133518.418328-1-eesposit@redhat.com> References: <20221125133518.418328-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669383751214100001 Content-Type: text/plain; charset="utf-8" bdrv_common_block_status_above() is a g_c_w, and it is being called by many "wrapper" functions like bdrv_is_allocated(), bdrv_is_allocated_above() and bdrv_block_status_above(). Because we want to eventually split the coroutine from non-coroutine case in g_c_w, create duplicate wrappers that take care of directly calling the same coroutine functions called in the g_c_w. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/io.c | 58 +++++++++++++++++++++++++++++++++++++--- include/block/block-io.h | 15 +++++++++++ 2 files changed, 70 insertions(+), 3 deletions(-) diff --git a/block/io.c b/block/io.c index 38e57d1f67..f4444b7777 100644 --- a/block/io.c +++ b/block/io.c @@ -2533,6 +2533,17 @@ bdrv_co_common_block_status_above(BlockDriverState *= bs, return ret; } =20 +int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, + BlockDriverState **file) +{ + IO_CODE(); + return bdrv_co_common_block_status_above(bs, base, false, true, offset, + bytes, pnum, map, file, NULL); +} + int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file) @@ -2578,6 +2589,22 @@ int coroutine_fn bdrv_co_is_zero_fast(BlockDriverSta= te *bs, int64_t offset, return (pnum =3D=3D bytes) && (ret & BDRV_BLOCK_ZERO); } =20 +int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t offset, + int64_t bytes, int64_t *pnum) +{ + int ret; + int64_t dummy; + IO_CODE(); + + ret =3D bdrv_co_common_block_status_above(bs, bs, true, false, offset, + bytes, pnum ? pnum : &dummy, N= ULL, + NULL, NULL); + if (ret < 0) { + return ret; + } + return !!(ret & BDRV_BLOCK_ALLOCATED); +} + int bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum) { @@ -2594,6 +2621,29 @@ int bdrv_is_allocated(BlockDriverState *bs, int64_t = offset, int64_t bytes, return !!(ret & BDRV_BLOCK_ALLOCATED); } =20 +/* See bdrv_is_allocated_above for documentation */ +int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top, + BlockDriverState *base, + bool include_base, int64_t off= set, + int64_t bytes, int64_t *pnum) +{ + int depth; + int ret; + IO_CODE(); + + ret =3D bdrv_co_common_block_status_above(top, base, include_base, fal= se, + offset, bytes, pnum, NULL, NUL= L, + &depth); + if (ret < 0) { + return ret; + } + + if (ret & BDRV_BLOCK_ALLOCATED) { + return depth; + } + return 0; +} + /* * Given an image chain: ... -> [BASE] -> [INTER1] -> [INTER2] -> [TOP] * @@ -2617,10 +2667,12 @@ int bdrv_is_allocated_above(BlockDriverState *top, int64_t bytes, int64_t *pnum) { int depth; - int ret =3D bdrv_common_block_status_above(top, base, include_base, fa= lse, - offset, bytes, pnum, NULL, NU= LL, - &depth); + int ret; IO_CODE(); + + ret =3D bdrv_common_block_status_above(top, base, include_base, false, + offset, bytes, pnum, NULL, NULL, + &depth); if (ret < 0) { return ret; } diff --git a/include/block/block-io.h b/include/block/block-io.h index 92aaa7c1e9..72919254cd 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -94,14 +94,29 @@ bool bdrv_can_write_zeroes_with_unmap(BlockDriverState = *bs); int bdrv_block_status(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); + +int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, + BlockDriverState **file); int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file); + +int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, int64_t offset, + int64_t bytes, int64_t *pnum); int bdrv_is_allocated(BlockDriverState *bs, int64_t offset, int64_t bytes, int64_t *pnum); + +int coroutine_fn bdrv_co_is_allocated_above(BlockDriverState *top, + BlockDriverState *base, + bool include_base, int64_t off= set, + int64_t bytes, int64_t *pnum); int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, bool include_base, int64_t offset, int64_t byt= es, int64_t *pnum); + int coroutine_fn bdrv_co_is_zero_fast(BlockDriverState *bs, int64_t offset, int64_t bytes); =20 --=20 2.31.1 From nobody Mon May 6 00:41:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669383351; cv=none; d=zohomail.com; s=zohoarc; b=mbmcrHJDvwNiHZpycU12vbIkJW9SeCmeofCBPg30ffM3IS72XPNHh+GPtjzIWE8ASyAB5g+4JbSk4whoviexphTlCMGExGPhLjaTnT9XBCz8zfLKGndc2mWK/qtcik/VgoKDztE82PEpO886FwfXk3KelS8BUUA/hjiTebm+2lw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669383351; 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=ardzZcBk1n7NVeJCeLR1pwuuircUxVh1xjNhb/fRo/s=; b=nGYmdm7YKRo0zkeblXNzK0iVz5piDAMH1n21uYEgpuPxhaAllVioC7Cdo4DlmIzdw1VNtSwbnXAzmwP/Fzv1Mq37mUe+xpW1AQl4DteNdJOY2+kN/3H9AsINdehjk5HhvJ4FMDUTXuQsFfeUbxyVH78MgrJ8lOuwb32Q1lRP4Mg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669383351552210.47871581381173; Fri, 25 Nov 2022 05:35:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyYrj-0006Up-Fq; Fri, 25 Nov 2022 08:35:41 -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 1oyYrc-0006Rk-Bj for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:35 -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 1oyYrY-0005Cr-2m for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:31 -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-216-Q2F3_rQOP3a15yeX-7mF9w-1; Fri, 25 Nov 2022 08:35:23 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 53F61185A7AB; Fri, 25 Nov 2022 13:35:22 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id E85012166B46; Fri, 25 Nov 2022 13:35:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669383327; 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=ardzZcBk1n7NVeJCeLR1pwuuircUxVh1xjNhb/fRo/s=; b=Jvg7NuLJv6xiz/n5WGuAZVcTkGZiQhL8NyF+TJxMFEXT/zYBhip61QMZujxKRTHcf39vSo j9Q6cZN0z1i7L5YF/kLa++AOEht7M/8hIoU4/qupN3XuIvo9A+GQih+3hhpvRXNCt/5wRI AC8SRpGiWIPQmbvA/yLvqpSlrRcqoo8= X-MC-Unique: Q2F3_rQOP3a15yeX-7mF9w-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v6 02/14] block-copy: add missing coroutine_fn annotations Date: Fri, 25 Nov 2022 08:35:06 -0500 Message-Id: <20221125133518.418328-3-eesposit@redhat.com> In-Reply-To: <20221125133518.418328-1-eesposit@redhat.com> References: <20221125133518.418328-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669383354319100003 Content-Type: text/plain; charset="utf-8" These functions end up calling bdrv_common_block_status_above(), a generated_co_wrapper function. In addition, they also happen to be always called in coroutine context, meaning all callers are coroutine_fn. This means that the g_c_w function will enter the qemu_in_coroutine() case and eventually suspend (or in other words call qemu_coroutine_yield()). Therefore we need to mark such functions coroutine_fn too. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Paolo Bonzini Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/block-copy.c | 21 ++++++++++++--------- include/block/block-copy.h | 5 +++-- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/block/block-copy.c b/block/block-copy.c index bb947afdda..5e59d6262f 100644 --- a/block/block-copy.c +++ b/block/block-copy.c @@ -577,8 +577,9 @@ static coroutine_fn int block_copy_task_entry(AioTask *= task) return ret; } =20 -static int block_copy_block_status(BlockCopyState *s, int64_t offset, - int64_t bytes, int64_t *pnum) +static coroutine_fn int block_copy_block_status(BlockCopyState *s, + int64_t offset, + int64_t bytes, int64_t *pn= um) { int64_t num; BlockDriverState *base; @@ -590,8 +591,8 @@ static int block_copy_block_status(BlockCopyState *s, i= nt64_t offset, base =3D NULL; } =20 - ret =3D bdrv_block_status_above(s->source->bs, base, offset, bytes, &n= um, - NULL, NULL); + ret =3D bdrv_co_block_status_above(s->source->bs, base, offset, bytes,= &num, + NULL, NULL); if (ret < 0 || num < s->cluster_size) { /* * On error or if failed to obtain large enough chunk just fallbac= k to @@ -613,8 +614,9 @@ static int block_copy_block_status(BlockCopyState *s, i= nt64_t offset, * Check if the cluster starting at offset is allocated or not. * return via pnum the number of contiguous clusters sharing this allocati= on. */ -static int block_copy_is_cluster_allocated(BlockCopyState *s, int64_t offs= et, - int64_t *pnum) +static int coroutine_fn block_copy_is_cluster_allocated(BlockCopyState *s, + int64_t offset, + int64_t *pnum) { BlockDriverState *bs =3D s->source->bs; int64_t count, total_count =3D 0; @@ -624,7 +626,7 @@ static int block_copy_is_cluster_allocated(BlockCopySta= te *s, int64_t offset, assert(QEMU_IS_ALIGNED(offset, s->cluster_size)); =20 while (true) { - ret =3D bdrv_is_allocated(bs, offset, bytes, &count); + ret =3D bdrv_co_is_allocated(bs, offset, bytes, &count); if (ret < 0) { return ret; } @@ -669,8 +671,9 @@ void block_copy_reset(BlockCopyState *s, int64_t offset= , int64_t bytes) * @return 0 when the cluster at @offset was unallocated, * 1 otherwise, and -ret on error. */ -int64_t block_copy_reset_unallocated(BlockCopyState *s, - int64_t offset, int64_t *count) +int64_t coroutine_fn block_copy_reset_unallocated(BlockCopyState *s, + int64_t offset, + int64_t *count) { int ret; int64_t clusters, bytes; diff --git a/include/block/block-copy.h b/include/block/block-copy.h index ba0b425d78..8cea4f9b90 100644 --- a/include/block/block-copy.h +++ b/include/block/block-copy.h @@ -36,8 +36,9 @@ void block_copy_set_progress_meter(BlockCopyState *s, Pro= gressMeter *pm); void block_copy_state_free(BlockCopyState *s); =20 void block_copy_reset(BlockCopyState *s, int64_t offset, int64_t bytes); -int64_t block_copy_reset_unallocated(BlockCopyState *s, - int64_t offset, int64_t *count); +int64_t coroutine_fn block_copy_reset_unallocated(BlockCopyState *s, + int64_t offset, + int64_t *count); =20 int coroutine_fn block_copy(BlockCopyState *s, int64_t offset, int64_t byt= es, bool ignore_ratelimit, uint64_t timeout_ns, --=20 2.31.1 From nobody Mon May 6 00:41:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669383412; cv=none; d=zohomail.com; s=zohoarc; b=YqiSYuR0FIKx0Uy+IlUyxqp3xjgOouArgYaj1Iy/e16uTfZW0Wq2Ju68mzd5kFJbqjmZ2k+UVCJ/G1lA8NR6S810RHMtAECvjW5fwWcZLNQN/qDpC2EXEIPRst9lPKX/X4LMsOOdlsk6QVww/UdubMFZfQlWT2oxbd0IWJMMQu4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669383412; 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=l5mhEB3GpUVtkdgHT2dRAZqBoIFGapKzT71cX76wirU=; b=DC4HBUSS1XQRWiVzTCFcDCjGBs4Jwtpz3kW9PmgKgKX0a2CbeZHiSCHUGTNbB/9Cuh0VU8X7oQbcl1SFxrDes0wx13jGW6J/jp70IQFFCrxLqRkn4UibJ3FVNTYcHDQfKcCVVTGf9lP+vucwB+9zxI/BFFhT3KYYDf1xJUKCpVw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669383412428557.1242961567655; Fri, 25 Nov 2022 05:36:52 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyYrz-0006gS-7L; Fri, 25 Nov 2022 08:35: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 1oyYrd-0006Rz-Hn for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:35 -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 1oyYrY-0005Cn-Ir for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:33 -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-379-Wdlxt5OLOmyp98p_0PMR8w-1; Fri, 25 Nov 2022 08:35:24 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BD92C800186; Fri, 25 Nov 2022 13:35:22 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DF922166B46; Fri, 25 Nov 2022 13:35:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669383327; 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=l5mhEB3GpUVtkdgHT2dRAZqBoIFGapKzT71cX76wirU=; b=ESVhxgiX+50wkfmqGbNggu0olj8QkzS+BxlWcVqOb6MBDOe3ZzbQglnczf+Rzl2eYUx42m c9h4tShqom9tB+MUAWd0+iX2JI3/tv5ydCFBCh5ZYfM3TSkJlZuMrmuQdf2T1MqC0RCxn2 OYI9kjY42RY1zyT92RxrjWtVcXsMqhQ= X-MC-Unique: Wdlxt5OLOmyp98p_0PMR8w-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v6 03/14] nbd/server.c: add missing coroutine_fn annotations Date: Fri, 25 Nov 2022 08:35:07 -0500 Message-Id: <20221125133518.418328-4-eesposit@redhat.com> In-Reply-To: <20221125133518.418328-1-eesposit@redhat.com> References: <20221125133518.418328-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669383413487100001 Content-Type: text/plain; charset="utf-8" These functions end up calling bdrv_*() implemented as generated_co_wrapper functions. In addition, they also happen to be always called in coroutine context, meaning all callers are coroutine_fn. This means that the g_c_w function will enter the qemu_in_coroutine() case and eventually suspend (or in other words call qemu_coroutine_yield()). Therefore we need to mark such functions coroutine_fn too. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Reviewed-by: Paolo Bonzini Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index ada16089f3..4af5c793a7 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2141,14 +2141,15 @@ static int nbd_extent_array_add(NBDExtentArray *ea, return 0; } =20 -static int blockstatus_to_extents(BlockDriverState *bs, uint64_t offset, - uint64_t bytes, NBDExtentArray *ea) +static int coroutine_fn blockstatus_to_extents(BlockDriverState *bs, + uint64_t offset, uint64_t b= ytes, + NBDExtentArray *ea) { while (bytes) { uint32_t flags; int64_t num; - int ret =3D bdrv_block_status_above(bs, NULL, offset, bytes, &num, - NULL, NULL); + int ret =3D bdrv_co_block_status_above(bs, NULL, offset, bytes, &n= um, + NULL, NULL); =20 if (ret < 0) { return ret; @@ -2168,13 +2169,14 @@ static int blockstatus_to_extents(BlockDriverState = *bs, uint64_t offset, return 0; } =20 -static int blockalloc_to_extents(BlockDriverState *bs, uint64_t offset, - uint64_t bytes, NBDExtentArray *ea) +static int coroutine_fn blockalloc_to_extents(BlockDriverState *bs, + uint64_t offset, uint64_t by= tes, + NBDExtentArray *ea) { while (bytes) { int64_t num; - int ret =3D bdrv_is_allocated_above(bs, NULL, false, offset, bytes, - &num); + int ret =3D bdrv_co_is_allocated_above(bs, NULL, false, offset, by= tes, + &num); =20 if (ret < 0) { return ret; @@ -2220,11 +2222,12 @@ static int nbd_co_send_extents(NBDClient *client, u= int64_t handle, } =20 /* Get block status from the exported device and send it to the client */ -static int nbd_co_send_block_status(NBDClient *client, uint64_t handle, - BlockDriverState *bs, uint64_t offset, - uint32_t length, bool dont_fragment, - bool last, uint32_t context_id, - Error **errp) +static int +coroutine_fn nbd_co_send_block_status(NBDClient *client, uint64_t handle, + BlockDriverState *bs, uint64_t offse= t, + uint32_t length, bool dont_fragment, + bool last, uint32_t context_id, + Error **errp) { int ret; unsigned int nb_extents =3D dont_fragment ? 1 : NBD_MAX_BLOCK_STATUS_E= XTENTS; --=20 2.31.1 From nobody Mon May 6 00:41:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669383614; cv=none; d=zohomail.com; s=zohoarc; b=ZrD1xgG6rEJQ5bbq51QXImSFlVANnTiGuDzmKN/AKbFbkBaKlfpNIWoof0O6J3H80XxyOdgohzDchc/239ej0wSNe7b2qfmw9RuhIiMhsnSXhYdh9BStN9eZqAXazHovdmCrQGTK+5wJSyrvuCKNdHZUydGXqf/wdV+9mnyY+bU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669383614; 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=qQmkivbD68RMCwd0WpB/LrwSrDoD74hm5fxeuQVw2NQ=; b=VHgpD+r6SJv2L4AS1dqMo+55HBoI7HpcSk1j67ycA2MMq4H2FsnKixWLBkFDqJZcs8zg268eCeOLyy/WUoVV60fMOLd3TTmEGrbtQV7SL8WkefKSmqwLxFhsYxBAmkvni+nSXiF5FWRQQLTCNf+d0x+pK9r1lzdw+x9n7ycyW5w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669383614179448.64668535272824; Fri, 25 Nov 2022 05:40:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyYrx-0006c9-7c; Fri, 25 Nov 2022 08:35:53 -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 1oyYrb-0006Rd-P4 for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:35 -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 1oyYrX-0005C4-6g for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:31 -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-651-Fx9btnATNmqxphP1P64pyA-1; Fri, 25 Nov 2022 08:35:24 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 32058185A7AA; Fri, 25 Nov 2022 13:35:23 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7B9F2166B46; Fri, 25 Nov 2022 13:35:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669383325; 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=qQmkivbD68RMCwd0WpB/LrwSrDoD74hm5fxeuQVw2NQ=; b=btkxY34Y61wlRY8lB4HTA7RCYs8sZXl64v8IEGQERf8WZx6/nsxrMOsJVpgvOQvzi4OQv/ ikRmkj9Hb+3rghXEC7BA0lhjjYzn811K1Eb0RJh+2JrKUtqhzvJer6sj9VKL1qZSNET/jN CyRXsJ8+z/IHZYKOUhFtmiI24Ke/m4o= X-MC-Unique: Fx9btnATNmqxphP1P64pyA-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v6 04/14] block-backend: replace bdrv_*_above with blk_*_above Date: Fri, 25 Nov 2022 08:35:08 -0500 Message-Id: <20221125133518.418328-5-eesposit@redhat.com> In-Reply-To: <20221125133518.418328-1-eesposit@redhat.com> References: <20221125133518.418328-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669383614852100002 Content-Type: text/plain; charset="utf-8" Avoid mixing bdrv_* functions with blk_*, so create blk_* counterparts for bdrv_block_status_above and bdrv_is_allocated_above. Note that since blk_co_block_status_above only calls the g_c_w function bdrv_common_block_status_above and is marked as coroutine_fn, call directly bdrv_co_common_block_status_above() to avoid using a g_c_w. Same applies to blk_co_is_allocated_above. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/block-backend.c | 21 ++++++++++++++++++++ block/commit.c | 4 ++-- include/sysemu/block-backend-io.h | 9 +++++++++ nbd/server.c | 32 +++++++++++++++---------------- 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 742efa7955..1d2d8526ef 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1424,6 +1424,27 @@ int coroutine_fn blk_co_pwritev(BlockBackend *blk, i= nt64_t offset, return blk_co_pwritev_part(blk, offset, bytes, qiov, 0, flags); } =20 +int coroutine_fn blk_co_block_status_above(BlockBackend *blk, + BlockDriverState *base, + int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, + BlockDriverState **file) +{ + IO_CODE(); + return bdrv_co_block_status_above(blk_bs(blk), base, offset, bytes, pn= um, + map, file); +} + +int coroutine_fn blk_co_is_allocated_above(BlockBackend *blk, + BlockDriverState *base, + bool include_base, int64_t offs= et, + int64_t bytes, int64_t *pnum) +{ + IO_CODE(); + return bdrv_co_is_allocated_above(blk_bs(blk), base, include_base, off= set, + bytes, pnum); +} + typedef struct BlkRwCo { BlockBackend *blk; int64_t offset; diff --git a/block/commit.c b/block/commit.c index 0029b31944..b346341767 100644 --- a/block/commit.c +++ b/block/commit.c @@ -155,8 +155,8 @@ static int coroutine_fn commit_run(Job *job, Error **er= rp) break; } /* Copy if allocated above the base */ - ret =3D bdrv_is_allocated_above(blk_bs(s->top), s->base_overlay, t= rue, - offset, COMMIT_BUFFER_SIZE, &n); + ret =3D blk_co_is_allocated_above(s->top, s->base_overlay, true, + offset, COMMIT_BUFFER_SIZE, &n); copy =3D (ret > 0); trace_commit_one_iteration(s, offset, n, ret); if (copy) { diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index 50f5aa2e07..ee3eb12610 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -92,6 +92,15 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in,= int64_t off_in, int64_t bytes, BdrvRequestFlags read_fl= ags, BdrvRequestFlags write_flags); =20 +int coroutine_fn blk_co_block_status_above(BlockBackend *blk, + BlockDriverState *base, + int64_t offset, int64_t bytes, + int64_t *pnum, int64_t *map, + BlockDriverState **file); +int coroutine_fn blk_co_is_allocated_above(BlockBackend *blk, + BlockDriverState *base, + bool include_base, int64_t offs= et, + int64_t bytes, int64_t *pnum); =20 /* * "I/O or GS" API functions. These functions can run without diff --git a/nbd/server.c b/nbd/server.c index 4af5c793a7..c53c39560e 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1991,7 +1991,7 @@ static int coroutine_fn nbd_co_send_structured_error(= NBDClient *client, } =20 /* Do a sparse read and send the structured reply to the client. - * Returns -errno if sending fails. bdrv_block_status_above() failure is + * Returns -errno if sending fails. blk_co_block_status_above() failure is * reported to the client, at which point this function succeeds. */ static int coroutine_fn nbd_co_send_sparse_read(NBDClient *client, @@ -2007,10 +2007,10 @@ static int coroutine_fn nbd_co_send_sparse_read(NBD= Client *client, =20 while (progress < size) { int64_t pnum; - int status =3D bdrv_block_status_above(blk_bs(exp->common.blk), NU= LL, - offset + progress, - size - progress, &pnum, NULL, - NULL); + int status =3D blk_co_block_status_above(exp->common.blk, NULL, + offset + progress, + size - progress, &pnum, NUL= L, + NULL); bool final; =20 if (status < 0) { @@ -2141,15 +2141,15 @@ static int nbd_extent_array_add(NBDExtentArray *ea, return 0; } =20 -static int coroutine_fn blockstatus_to_extents(BlockDriverState *bs, +static int coroutine_fn blockstatus_to_extents(BlockBackend *blk, uint64_t offset, uint64_t b= ytes, NBDExtentArray *ea) { while (bytes) { uint32_t flags; int64_t num; - int ret =3D bdrv_co_block_status_above(bs, NULL, offset, bytes, &n= um, - NULL, NULL); + int ret =3D blk_co_block_status_above(blk, NULL, offset, bytes, &n= um, + NULL, NULL); =20 if (ret < 0) { return ret; @@ -2169,14 +2169,14 @@ static int coroutine_fn blockstatus_to_extents(Bloc= kDriverState *bs, return 0; } =20 -static int coroutine_fn blockalloc_to_extents(BlockDriverState *bs, +static int coroutine_fn blockalloc_to_extents(BlockBackend *blk, uint64_t offset, uint64_t by= tes, NBDExtentArray *ea) { while (bytes) { int64_t num; - int ret =3D bdrv_co_is_allocated_above(bs, NULL, false, offset, by= tes, - &num); + int ret =3D blk_co_is_allocated_above(blk, NULL, false, offset, by= tes, + &num); =20 if (ret < 0) { return ret; @@ -2224,7 +2224,7 @@ static int nbd_co_send_extents(NBDClient *client, uin= t64_t handle, /* Get block status from the exported device and send it to the client */ static int coroutine_fn nbd_co_send_block_status(NBDClient *client, uint64_t handle, - BlockDriverState *bs, uint64_t offse= t, + BlockBackend *blk, uint64_t offset, uint32_t length, bool dont_fragment, bool last, uint32_t context_id, Error **errp) @@ -2234,9 +2234,9 @@ coroutine_fn nbd_co_send_block_status(NBDClient *clie= nt, uint64_t handle, g_autoptr(NBDExtentArray) ea =3D nbd_extent_array_new(nb_extents); =20 if (context_id =3D=3D NBD_META_ID_BASE_ALLOCATION) { - ret =3D blockstatus_to_extents(bs, offset, length, ea); + ret =3D blockstatus_to_extents(blk, offset, length, ea); } else { - ret =3D blockalloc_to_extents(bs, offset, length, ea); + ret =3D blockalloc_to_extents(blk, offset, length, ea); } if (ret < 0) { return nbd_co_send_structured_error( @@ -2563,7 +2563,7 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, =20 if (client->export_meta.base_allocation) { ret =3D nbd_co_send_block_status(client, request->handle, - blk_bs(exp->common.blk), + exp->common.blk, request->from, request->len, dont_fragment, !--contexts_remaining, @@ -2576,7 +2576,7 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, =20 if (client->export_meta.allocation_depth) { ret =3D nbd_co_send_block_status(client, request->handle, - blk_bs(exp->common.blk), + exp->common.blk, request->from, request->len, dont_fragment, !--contexts_remaining, --=20 2.31.1 From nobody Mon May 6 00:41:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669383369; cv=none; d=zohomail.com; s=zohoarc; b=kKLMYcHd1XvyaQVilphAyBOhD4GLtg08uyc+3gwqRjeFZ5EnSQGnE+qL6Ouk8z3L6O+UQ2rILPJ+BscqvJpt86Cxli8I8hXcPK+AVM6ZZkJijKbrlSWR+gdbF5faVQ/HQtIidFA6zEWhfc2c3M1wWGQpr5ztcB3zzfTx7i/l2ew= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669383369; 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=BG3RABa1AnoYOZIUsX172/qsRfCCqnI9wQZdEtdFN7o=; b=bZpBfRK9W8Xz8kzZPaCUUNQQm/S8an9rUd5mJ0NSxLW/eQT2dB2UeMYiuOHyA1kGFyS0E16uWMxaHYfJAQCFrJE6w9zU1TGn2lIEvPOKsWQwrISljltG6oXcw8AmKqPXk0eMEka5uxtTmXothGqap0dRDDlytxXCEhEBphQV+28= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669383369033994.0949395468746; Fri, 25 Nov 2022 05:36:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyYs2-0006pX-6M; Fri, 25 Nov 2022 08:35: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 1oyYrk-0006W5-3T for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:43 -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 1oyYrc-0005Hw-E2 for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35: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-320-g5QM-DTbMbWowoIRFajnGg-1; Fri, 25 Nov 2022 08:35:25 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B1BA1C05155; Fri, 25 Nov 2022 13:35:23 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3C1992166B48; Fri, 25 Nov 2022 13:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669383331; 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=BG3RABa1AnoYOZIUsX172/qsRfCCqnI9wQZdEtdFN7o=; b=LfRyMGGrWfan+gb/+ANGl4z6q2ZcxhhtN94TMTZePp7LKmHv75Nnm2/aEP9Exj+smJrYkj a+5A9OWLLip/vauRXiaTnZft5XZY2dnb3Oo1ptH/EIlSGFkQnFwItSZQMfZLkM4uH5RLeZ tcgGLzLXFNjybwlZ+N8JMqMj3R5mczw= X-MC-Unique: g5QM-DTbMbWowoIRFajnGg-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v6 05/14] block/vmdk: add missing coroutine_fn annotations Date: Fri, 25 Nov 2022 08:35:09 -0500 Message-Id: <20221125133518.418328-6-eesposit@redhat.com> In-Reply-To: <20221125133518.418328-1-eesposit@redhat.com> References: <20221125133518.418328-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669383369480100003 Content-Type: text/plain; charset="utf-8" These functions end up calling bdrv_create() implemented as generated_co_wr= apper functions. In addition, they also happen to be always called in coroutine context, meaning all callers are coroutine_fn. This means that the g_c_w function will enter the qemu_in_coroutine() case and eventually suspend (or in other words call qemu_coroutine_yield()). Therefore we need to mark such functions coroutine_fn too. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Paolo Bonzini Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/vmdk.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/block/vmdk.c b/block/vmdk.c index 26376352b9..0c32bf2e83 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2285,10 +2285,11 @@ exit: return ret; } =20 -static int vmdk_create_extent(const char *filename, int64_t filesize, - bool flat, bool compress, bool zeroed_grain, - BlockBackend **pbb, - QemuOpts *opts, Error **errp) +static int coroutine_fn vmdk_create_extent(const char *filename, + int64_t filesize, bool flat, + bool compress, bool zeroed_grai= n, + BlockBackend **pbb, + QemuOpts *opts, Error **errp) { int ret; BlockBackend *blk =3D NULL; @@ -2366,14 +2367,14 @@ static int filename_decompose(const char *filename,= char *path, char *prefix, * non-split format. * idx >=3D 1: get the n-th extent if in a split subformat */ -typedef BlockBackend *(*vmdk_create_extent_fn)(int64_t size, - int idx, - bool flat, - bool split, - bool compress, - bool zeroed_grain, - void *opaque, - Error **errp); +typedef BlockBackend * coroutine_fn (*vmdk_create_extent_fn)(int64_t size, + int idx, + bool flat, + bool split, + bool compress, + bool zeroed_g= rain, + void *opaque, + Error **errp); =20 static void vmdk_desc_add_extent(GString *desc, const char *extent_line_fmt, @@ -2616,7 +2617,7 @@ typedef struct { QemuOpts *opts; } VMDKCreateOptsData; =20 -static BlockBackend *vmdk_co_create_opts_cb(int64_t size, int idx, +static BlockBackend * coroutine_fn vmdk_co_create_opts_cb(int64_t size, in= t idx, bool flat, bool split, bool co= mpress, bool zeroed_grain, void *opaqu= e, Error **errp) @@ -2768,10 +2769,11 @@ exit: return ret; } =20 -static BlockBackend *vmdk_co_create_cb(int64_t size, int idx, - bool flat, bool split, bool compres= s, - bool zeroed_grain, void *opaque, - Error **errp) +static BlockBackend * coroutine_fn vmdk_co_create_cb(int64_t size, int idx, + bool flat, bool split, + bool compress, + bool zeroed_grain, + void *opaque, Error *= *errp) { int ret; BlockDriverState *bs; --=20 2.31.1 From nobody Mon May 6 00:41:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669383736; cv=none; d=zohomail.com; s=zohoarc; b=QgY7qfSQEkOkzTFuq2DVv83DyFu5TTHUx69wh79oR9Xf9RkVnhc6QecjrKaFNFaVVD/5SK7aKUj2tXuP/JSC6VWJ936QPHDDpvYh0rgMCq0GfKUdYe4QhiSdRWxP6kWjby+rvI1T9PC7gaMy1ehgAfQAEAXLHBsIjPP5EzyJRuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669383736; 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=cp8UMOLDpzhXXN+dxF7xoRYj8evulEe3YE7MhoKJs10=; b=H7p0QXSawg/9/bM/6MTfa7mA53zX1mirtRTy7gSUiXpO8yNReF9/W1kZ09wJFxYFW38B/8PVQ5sUNBD8i9NveTijz00l7CA0KDWXSFcnztlPKz1nlFGcvD3CWJnKDRVmeqb1mhmrqwCVz/zA/tthScwH9GSxwBc0b/zo+Eg1LYU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669383736157474.96730822360246; Fri, 25 Nov 2022 05:42:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyYs5-0006rP-EZ; Fri, 25 Nov 2022 08:36:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oyYri-0006VW-Dc for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35: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 1oyYrb-0005Fm-ER for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:38 -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-564-ni3tMrmUOaKEe16W4vgzQA-1; Fri, 25 Nov 2022 08:35:24 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0F69C185A78B; Fri, 25 Nov 2022 13:35:24 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id A47CA2166B47; Fri, 25 Nov 2022 13:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669383330; 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=cp8UMOLDpzhXXN+dxF7xoRYj8evulEe3YE7MhoKJs10=; b=hOcZ6WWhd3fE6848jl5bNzxhXRgKS65EnREu9wU7SSgkxdMRasVWCfIsf5dcZlLOXoCseT 1gxIBzippk9/FaJswso8I/KfiaL7f6eIH1MJOX9ujwrQ90Pd8tugnyrT7aapZjFRy9KuTK cGrwrU2+OPYXbJ8nIUWfvziyz0kh4t0= X-MC-Unique: ni3tMrmUOaKEe16W4vgzQA-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v6 06/14] block: avoid duplicating filename string in bdrv_create Date: Fri, 25 Nov 2022 08:35:10 -0500 Message-Id: <20221125133518.418328-7-eesposit@redhat.com> In-Reply-To: <20221125133518.418328-1-eesposit@redhat.com> References: <20221125133518.418328-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669383737193100001 Content-Type: text/plain; charset="utf-8" We know that the string will stay around until the function returns, and the parameter of drv->bdrv_co_create_opts is const char*, so it must not be modified either. Suggested-by: Kevin Wolf Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/block.c b/block.c index 8c9f4ee37c..9d51e7b6e5 100644 --- a/block.c +++ b/block.c @@ -553,7 +553,7 @@ int bdrv_create(BlockDriver *drv, const char* filename, Coroutine *co; CreateCo cco =3D { .drv =3D drv, - .filename =3D g_strdup(filename), + .filename =3D filename, .opts =3D opts, .ret =3D NOT_DONE, .err =3D NULL, @@ -561,8 +561,7 @@ int bdrv_create(BlockDriver *drv, const char* filename, =20 if (!drv->bdrv_co_create_opts) { error_setg(errp, "Driver '%s' does not support image creation", dr= v->format_name); - ret =3D -ENOTSUP; - goto out; + return -ENOTSUP; } =20 if (qemu_in_coroutine()) { @@ -585,8 +584,6 @@ int bdrv_create(BlockDriver *drv, const char* filename, } } =20 -out: - g_free(cco.filename); return ret; } =20 --=20 2.31.1 From nobody Mon May 6 00:41:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669383455; cv=none; d=zohomail.com; s=zohoarc; b=mksfbwJMlAlBotjnVX7BxJleE0PSJ28VyaJ/rdx68p2n9yaFub6hjxF2+jDilruEnqBPefjR40vSMeXIi8EbO86sdOCYvBEDDKr2E8k0jeKsx9In10GjAdhV+/2V3pSQj/bn3W+rOVc5hw3Lme+Af/uxD2XL/paubPd4EDXX9hU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669383455; 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=B4GGvJzU1xDo9k0/o7coYHmaRBryfde1vvicjZyY9O4=; b=esSsRpMGF9hguJXpZauOuf0L4fUBl8UudJ/vXTm2GmDLb9d/wFNYI2rlnEX91fWaXN+TUvEq/r6PRmMhBl35TNBJzu2oX1LZRtSr/a/kkwgTIlXydkxteV+H4ucm4VsTMXH/26XyJ/Sioe6jUFFuwMNma+rO/UOxUT4cKa+3bfc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669383455903683.2404329006794; Fri, 25 Nov 2022 05:37:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyYry-0006eA-AC; Fri, 25 Nov 2022 08:35:54 -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 1oyYre-0006S4-AE for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:35 -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 1oyYrY-0005DM-PW for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:33 -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-350-Pv8lFmiZMDqYcugwxyWglQ-1; Fri, 25 Nov 2022 08:35:24 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 78B0D811E67; Fri, 25 Nov 2022 13:35:24 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 194382166B47; Fri, 25 Nov 2022 13:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669383328; 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=B4GGvJzU1xDo9k0/o7coYHmaRBryfde1vvicjZyY9O4=; b=TiE7jwQjGgxQjHGD0knM6amrz4SSSJfuh+LGZEaPcpPvqmbtItl6HdyNq2oaJdMhM85r0s EkP9BJo3WhW1MvRxxUZuo9pS2ZMyFZSt+Rm5BXqePlL6XWIkHeiGC7ifAtDylV9FYxRqFK enw/BY0fLFLx88zryBctUWSdn+XKeqk= X-MC-Unique: Pv8lFmiZMDqYcugwxyWglQ-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v6 07/14] block: distinguish between bdrv_create running in coroutine and not Date: Fri, 25 Nov 2022 08:35:11 -0500 Message-Id: <20221125133518.418328-8-eesposit@redhat.com> In-Reply-To: <20221125133518.418328-1-eesposit@redhat.com> References: <20221125133518.418328-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669383457842100001 Content-Type: text/plain; charset="utf-8" Call two different functions depending on whether bdrv_create is in coroutine or not, following the same pattern as generated_co_wrapper functions. This allows to also call the coroutine function directly, without using CreateCo or relying in bdrv_create(). Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 71 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/block.c b/block.c index 9d51e7b6e5..2cf50b37c4 100644 --- a/block.c +++ b/block.c @@ -528,63 +528,64 @@ typedef struct CreateCo { Error *err; } CreateCo; =20 -static void coroutine_fn bdrv_create_co_entry(void *opaque) +static int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filen= ame, + QemuOpts *opts, Error **errp) { - Error *local_err =3D NULL; int ret; + GLOBAL_STATE_CODE(); + ERRP_GUARD(); + assert(*errp =3D=3D NULL); + assert(drv); + + if (!drv->bdrv_co_create_opts) { + error_setg(errp, "Driver '%s' does not support image creation", + drv->format_name); + return -ENOTSUP; + } + + ret =3D drv->bdrv_co_create_opts(drv, filename, opts, errp); =20 + if (ret < 0 && !*errp) { + error_setg_errno(errp, -ret, "Could not create image"); + } + + return ret; +} + +static void coroutine_fn bdrv_create_co_entry(void *opaque) +{ CreateCo *cco =3D opaque; - assert(cco->drv); GLOBAL_STATE_CODE(); =20 - ret =3D cco->drv->bdrv_co_create_opts(cco->drv, - cco->filename, cco->opts, &local_e= rr); - error_propagate(&cco->err, local_err); - cco->ret =3D ret; + cco->ret =3D bdrv_co_create(cco->drv, cco->filename, cco->opts, &cco->= err); } =20 int bdrv_create(BlockDriver *drv, const char* filename, QemuOpts *opts, Error **errp) { - int ret; - GLOBAL_STATE_CODE(); =20 - Coroutine *co; - CreateCo cco =3D { - .drv =3D drv, - .filename =3D filename, - .opts =3D opts, - .ret =3D NOT_DONE, - .err =3D NULL, - }; - - if (!drv->bdrv_co_create_opts) { - error_setg(errp, "Driver '%s' does not support image creation", dr= v->format_name); - return -ENOTSUP; - } - if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ - bdrv_create_co_entry(&cco); + return bdrv_co_create(drv, filename, opts, errp); } else { + Coroutine *co; + CreateCo cco =3D { + .drv =3D drv, + .filename =3D filename, + .opts =3D opts, + .ret =3D NOT_DONE, + .err =3D NULL, + }; + co =3D qemu_coroutine_create(bdrv_create_co_entry, &cco); qemu_coroutine_enter(co); while (cco.ret =3D=3D NOT_DONE) { aio_poll(qemu_get_aio_context(), true); } + error_propagate(errp, cco.err); + return cco.ret; } - - ret =3D cco.ret; - if (ret < 0) { - if (cco.err) { - error_propagate(errp, cco.err); - } else { - error_setg_errno(errp, -ret, "Could not create image"); - } - } - - return ret; } =20 /** --=20 2.31.1 From nobody Mon May 6 00:41:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669383614; cv=none; d=zohomail.com; s=zohoarc; b=HCm+zmkFZG8i0R5u/uGdAGH2+QMRieOI6OPYcnCjVwqqbjwNwjZNLVUX/0j9rDk0Ser2mt65JfWdAsoFGFV5LD0htwzKgSRQzdi236UErTI0n4p9/TieGnu5hOwYMyf4+CujKuR90deqawGEe3YwQjw7wQi8Ahp5fKmr4KwFx08= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669383614; 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=1sQagkYbVmPaBXdgTv0JMV0TmZ1dqaNoTh9HX31Qpkw=; b=FgWQKO1M52GytkmV1seh01hRr4RnW6GtlQ8VNxyooOr6k0vy7c4cOjAuYPVI0F1j9BvR48zsW5SP6GyRWieYhRFV7iaia6C/ptlZLTXahTm8KC+HRRE4B8CLt4uhE5xpAp3Bpw50dtfz61PUIJyl2CeXR6zazrS+OOqCetX7Wys= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669383614981298.83254383941437; Fri, 25 Nov 2022 05:40:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyYry-0006dh-4m; Fri, 25 Nov 2022 08:35:54 -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 1oyYrf-0006Sm-Lg for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:35 -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 1oyYrZ-0005Du-A5 for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:34 -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-362-xz1BnDBtN6qIGTQD4UtzKw-1; Fri, 25 Nov 2022 08:35:25 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E27C085A588; Fri, 25 Nov 2022 13:35:24 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 82E2C2166B47; Fri, 25 Nov 2022 13:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669383328; 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=1sQagkYbVmPaBXdgTv0JMV0TmZ1dqaNoTh9HX31Qpkw=; b=WImuSzdOEP8Hiu7FMjaBeY0jIxtIihbXKhQJ5VZgSLRLLo0nLFeIwUgGVlM7XEOi8uzB4m eu1KsCxsK3dcbh+zYR7/sQ1urdEOwBaGGFopRrK505gkrukv8wpXl8j2krUqjBp9E/74L+ fQeEatlrr5jg5VgLzlNCOdThKnaUU/U= X-MC-Unique: xz1BnDBtN6qIGTQD4UtzKw-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v6 08/14] block: bdrv_create_file is a coroutine_fn Date: Fri, 25 Nov 2022 08:35:12 -0500 Message-Id: <20221125133518.418328-9-eesposit@redhat.com> In-Reply-To: <20221125133518.418328-1-eesposit@redhat.com> References: <20221125133518.418328-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669383616657100005 Content-Type: text/plain; charset="utf-8" It is always called in coroutine_fn callbacks, therefore it can directly call bdrv_co_create(). Rename it to bdrv_co_create_file too. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 5 +++-- block/crypto.c | 2 +- block/parallels.c | 2 +- block/qcow.c | 2 +- block/qcow2.c | 4 ++-- block/qed.c | 2 +- block/raw-format.c | 2 +- block/vdi.c | 2 +- block/vhdx.c | 2 +- block/vmdk.c | 2 +- block/vpc.c | 2 +- include/block/block-global-state.h | 3 ++- 12 files changed, 16 insertions(+), 14 deletions(-) diff --git a/block.c b/block.c index 2cf50b37c4..772df02d54 100644 --- a/block.c +++ b/block.c @@ -723,7 +723,8 @@ out: return ret; } =20 -int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp) +int coroutine_fn bdrv_co_create_file(const char *filename, QemuOpts *opts, + Error **errp) { QemuOpts *protocol_opts; BlockDriver *drv; @@ -764,7 +765,7 @@ int bdrv_create_file(const char *filename, QemuOpts *op= ts, Error **errp) goto out; } =20 - ret =3D bdrv_create(drv, filename, protocol_opts, errp); + ret =3D bdrv_co_create(drv, filename, protocol_opts, errp); out: qemu_opts_del(protocol_opts); qobject_unref(qdict); diff --git a/block/crypto.c b/block/crypto.c index 2fb8add458..bbeb9f437c 100644 --- a/block/crypto.c +++ b/block/crypto.c @@ -703,7 +703,7 @@ static int coroutine_fn block_crypto_co_create_opts_luk= s(BlockDriver *drv, } =20 /* Create protocol layer */ - ret =3D bdrv_create_file(filename, opts, errp); + ret =3D bdrv_co_create_file(filename, opts, errp); if (ret < 0) { goto fail; } diff --git a/block/parallels.c b/block/parallels.c index fa08c1104b..bbea2f2221 100644 --- a/block/parallels.c +++ b/block/parallels.c @@ -646,7 +646,7 @@ static int coroutine_fn parallels_co_create_opts(BlockD= river *drv, } =20 /* Create and open the file (protocol layer) */ - ret =3D bdrv_create_file(filename, opts, errp); + ret =3D bdrv_co_create_file(filename, opts, errp); if (ret < 0) { goto done; } diff --git a/block/qcow.c b/block/qcow.c index daa38839ab..18e17a5b12 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -973,7 +973,7 @@ static int coroutine_fn qcow_co_create_opts(BlockDriver= *drv, } =20 /* Create and open the file (protocol layer) */ - ret =3D bdrv_create_file(filename, opts, errp); + ret =3D bdrv_co_create_file(filename, opts, errp); if (ret < 0) { goto fail; } diff --git a/block/qcow2.c b/block/qcow2.c index 4d6666d3ff..7cc49a3a6c 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3871,7 +3871,7 @@ static int coroutine_fn qcow2_co_create_opts(BlockDri= ver *drv, } =20 /* Create and open the file (protocol layer) */ - ret =3D bdrv_create_file(filename, opts, errp); + ret =3D bdrv_co_create_file(filename, opts, errp); if (ret < 0) { goto finish; } @@ -3886,7 +3886,7 @@ static int coroutine_fn qcow2_co_create_opts(BlockDri= ver *drv, /* Create and open an external data file (protocol layer) */ val =3D qdict_get_try_str(qdict, BLOCK_OPT_DATA_FILE); if (val) { - ret =3D bdrv_create_file(val, opts, errp); + ret =3D bdrv_co_create_file(val, opts, errp); if (ret < 0) { goto finish; } diff --git a/block/qed.c b/block/qed.c index c2691a85b1..9d54c8eec5 100644 --- a/block/qed.c +++ b/block/qed.c @@ -778,7 +778,7 @@ static int coroutine_fn bdrv_qed_co_create_opts(BlockDr= iver *drv, } =20 /* Create and open the file (protocol layer) */ - ret =3D bdrv_create_file(filename, opts, errp); + ret =3D bdrv_co_create_file(filename, opts, errp); if (ret < 0) { goto fail; } diff --git a/block/raw-format.c b/block/raw-format.c index a68014ef0b..28905b09ee 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -433,7 +433,7 @@ static int coroutine_fn raw_co_create_opts(BlockDriver = *drv, QemuOpts *opts, Error **errp) { - return bdrv_create_file(filename, opts, errp); + return bdrv_co_create_file(filename, opts, errp); } =20 static int raw_open(BlockDriverState *bs, QDict *options, int flags, diff --git a/block/vdi.c b/block/vdi.c index c0c111c4b9..479bcfe820 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -934,7 +934,7 @@ static int coroutine_fn vdi_co_create_opts(BlockDriver = *drv, qdict =3D qemu_opts_to_qdict_filtered(opts, NULL, &vdi_create_opts, tr= ue); =20 /* Create and open the file (protocol layer) */ - ret =3D bdrv_create_file(filename, opts, errp); + ret =3D bdrv_co_create_file(filename, opts, errp); if (ret < 0) { goto done; } diff --git a/block/vhdx.c b/block/vhdx.c index bad9ca691b..4c929800fe 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -2084,7 +2084,7 @@ static int coroutine_fn vhdx_co_create_opts(BlockDriv= er *drv, } =20 /* Create and open the file (protocol layer) */ - ret =3D bdrv_create_file(filename, opts, errp); + ret =3D bdrv_co_create_file(filename, opts, errp); if (ret < 0) { goto fail; } diff --git a/block/vmdk.c b/block/vmdk.c index 0c32bf2e83..afd3471915 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -2294,7 +2294,7 @@ static int coroutine_fn vmdk_create_extent(const char= *filename, int ret; BlockBackend *blk =3D NULL; =20 - ret =3D bdrv_create_file(filename, opts, errp); + ret =3D bdrv_co_create_file(filename, opts, errp); if (ret < 0) { goto exit; } diff --git a/block/vpc.c b/block/vpc.c index 95841f259a..6ee95dcb96 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -1111,7 +1111,7 @@ static int coroutine_fn vpc_co_create_opts(BlockDrive= r *drv, } =20 /* Create and open the file (protocol layer) */ - ret =3D bdrv_create_file(filename, opts, errp); + ret =3D bdrv_co_create_file(filename, opts, errp); if (ret < 0) { goto fail; } diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 00e0cf8aea..387a7cbb2e 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -57,7 +57,8 @@ BlockDriver *bdrv_find_protocol(const char *filename, BlockDriver *bdrv_find_format(const char *format_name); int bdrv_create(BlockDriver *drv, const char* filename, QemuOpts *opts, Error **errp); -int bdrv_create_file(const char *filename, QemuOpts *opts, Error **errp); +int coroutine_fn bdrv_co_create_file(const char *filename, QemuOpts *opts, + Error **errp); =20 BlockDriverState *bdrv_new(void); int bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top, --=20 2.31.1 From nobody Mon May 6 00:41:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669383459; cv=none; d=zohomail.com; s=zohoarc; b=h//TwartKReCRhxtvNHg/zYu7YUYBeCLCe80T7sGKRqgYpYkTwP2/QPuYYc5QNYvP8yFi+hL6wKPE6vd0W43OYzPCzDDWoBJeH+CkSFItlbGaG/wQZPUCqtqVhsi/7f6i/hd+9ZQ+bjCITDur5Sg2LcUdlfFzX1R6w+mIPLAQRE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669383459; 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=GOMiXVaU6i+ne1L5P2GZwYqHepPDRC8JzGFpMGuOJ1c=; b=fnuyM12f7gd5oVaE7f2FGqHtGU6z5EehkKp8eN2zMszeLhirvjNtE4lPzJgxlS1BTq23k0tsppDt0iihU8760PCZUHzxCcdURIIiyiOzcBAF3foAjXs1bQM2PM4fiwK7JGY3Mk8q3XT9IxhZ8dddq8GK1Ldb7nxJtfsgL4yHFF8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669383459359607.7386138468954; Fri, 25 Nov 2022 05:37:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyYs1-0006nt-Ew; Fri, 25 Nov 2022 08:35: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 1oyYrh-0006Ul-4N for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:37 -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 1oyYra-0005Es-0y for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:36 -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-516-14pBv9gTNLeH-3ky3parxg-1; Fri, 25 Nov 2022 08:35:25 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5D0F13C0E219; Fri, 25 Nov 2022 13:35:25 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id EDC212166B46; Fri, 25 Nov 2022 13:35:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669383329; 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=GOMiXVaU6i+ne1L5P2GZwYqHepPDRC8JzGFpMGuOJ1c=; b=dGKO7+ixLSJEzeARSYoWkCFEXp5wtrkZXkwvdqy+EWetVaPBiewT+ntMt7BNwOTsvV54Ga 5Fdrjr/eOAkTo0GSxUb5w0iNZXzUbXUqAAOzXs4jAq3H4wfaw8XRPQd1D9Tfoh2G/NXLUb xeX+xLKyPJqQDGw0BhIXnPBscrgD/PU= X-MC-Unique: 14pBv9gTNLeH-3ky3parxg-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v6 09/14] block: rename generated_co_wrapper in co_wrapper_mixed Date: Fri, 25 Nov 2022 08:35:13 -0500 Message-Id: <20221125133518.418328-10-eesposit@redhat.com> In-Reply-To: <20221125133518.418328-1-eesposit@redhat.com> References: <20221125133518.418328-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669383459882100005 Content-Type: text/plain; charset="utf-8" In preparation to the incoming new function specifiers, rename g_c_w with a more meaningful name and document it. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/coroutines.h | 4 +- docs/devel/block-coroutine-wrapper.rst | 6 +-- include/block/block-common.h | 11 +++-- include/block/block-io.h | 44 ++++++++--------- include/sysemu/block-backend-io.h | 68 +++++++++++++------------- scripts/block-coroutine-wrapper.py | 6 +-- 6 files changed, 71 insertions(+), 68 deletions(-) diff --git a/block/coroutines.h b/block/coroutines.h index 3a2bad564f..17da4db963 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -71,7 +71,7 @@ nbd_co_do_establish_connection(BlockDriverState *bs, bool= blocking, * the "I/O or GS" API. */ =20 -int generated_co_wrapper +int co_wrapper_mixed bdrv_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, bool include_base, @@ -82,7 +82,7 @@ bdrv_common_block_status_above(BlockDriverState *bs, int64_t *map, BlockDriverState **file, int *depth); -int generated_co_wrapper +int co_wrapper_mixed nbd_do_establish_connection(BlockDriverState *bs, bool blocking, Error **e= rrp); =20 #endif /* BLOCK_COROUTINES_H */ diff --git a/docs/devel/block-coroutine-wrapper.rst b/docs/devel/block-coro= utine-wrapper.rst index 412851986b..64acc8d65d 100644 --- a/docs/devel/block-coroutine-wrapper.rst +++ b/docs/devel/block-coroutine-wrapper.rst @@ -26,12 +26,12 @@ called ``bdrv_foo()``. In this case the scri= pt can help. To trigger the generation: =20 1. You need ``bdrv_foo`` declaration somewhere (for example, in - ``block/coroutines.h``) with the ``generated_co_wrapper`` mark, + ``block/coroutines.h``) with the ``co_wrapper_mixed`` mark, like this: =20 .. code-block:: c =20 - int generated_co_wrapper bdrv_foo(); + int co_wrapper_mixed bdrv_foo(); =20 2. You need to feed this declaration to block-coroutine-wrapper script. For this, add the .h (or .c) file with the declaration to the @@ -46,7 +46,7 @@ Links =20 1. The script location is ``scripts/block-coroutine-wrapper.py``. =20 -2. Generic place for private ``generated_co_wrapper`` declarations is +2. Generic place for private ``co_wrapper_mixed`` declarations is ``block/coroutines.h``, for public declarations: ``include/block/block.h`` =20 diff --git a/include/block/block-common.h b/include/block/block-common.h index 297704c1e9..ec2309055b 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -35,14 +35,17 @@ #include "qemu/transactions.h" =20 /* - * generated_co_wrapper + * co_wrapper{*}: Function specifiers used by block-coroutine-wrapper.py * - * Function specifier, which does nothing but mark functions to be + * Function specifiers, which do nothing but mark functions to be * generated by scripts/block-coroutine-wrapper.py * - * Read more in docs/devel/block-coroutine-wrapper.rst + * Usage: read docs/devel/block-coroutine-wrapper.rst + * + * co_wrapper_mixed functions can be called by both coroutine and + * non-coroutine context. */ -#define generated_co_wrapper +#define co_wrapper_mixed =20 /* block.c */ typedef struct BlockDriver BlockDriver; diff --git a/include/block/block-io.h b/include/block/block-io.h index 72919254cd..72cf45975b 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -39,19 +39,19 @@ * to catch when they are accidentally called by the wrong API. */ =20 -int generated_co_wrapper bdrv_pwrite_zeroes(BdrvChild *child, int64_t offs= et, - int64_t bytes, - BdrvRequestFlags flags); +int co_wrapper_mixed bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, + int64_t bytes, + BdrvRequestFlags flags); int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags); -int generated_co_wrapper bdrv_pread(BdrvChild *child, int64_t offset, - int64_t bytes, void *buf, - BdrvRequestFlags flags); -int generated_co_wrapper bdrv_pwrite(BdrvChild *child, int64_t offset, - int64_t bytes, const void *buf, - BdrvRequestFlags flags); -int generated_co_wrapper bdrv_pwrite_sync(BdrvChild *child, int64_t offset, - int64_t bytes, const void *buf, - BdrvRequestFlags flags); +int co_wrapper_mixed bdrv_pread(BdrvChild *child, int64_t offset, + int64_t bytes, void *buf, + BdrvRequestFlags flags); +int co_wrapper_mixed bdrv_pwrite(BdrvChild *child, int64_t offset, + int64_t bytes, const void *buf, + BdrvRequestFlags flags); +int co_wrapper_mixed bdrv_pwrite_sync(BdrvChild *child, int64_t offset, + int64_t bytes, const void *buf, + BdrvRequestFlags flags); int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes, const void *buf, BdrvRequestFlags flags); @@ -281,22 +281,22 @@ int coroutine_fn bdrv_co_copy_range(BdrvChild *src, i= nt64_t src_offset, =20 void bdrv_drain(BlockDriverState *bs); =20 -int generated_co_wrapper +int co_wrapper_mixed bdrv_truncate(BdrvChild *child, int64_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **errp); =20 -int generated_co_wrapper bdrv_check(BlockDriverState *bs, BdrvCheckResult = *res, - BdrvCheckMode fix); +int co_wrapper_mixed bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, + BdrvCheckMode fix); =20 /* Invalidate any cached metadata used by image formats */ -int generated_co_wrapper bdrv_invalidate_cache(BlockDriverState *bs, - Error **errp); -int generated_co_wrapper bdrv_flush(BlockDriverState *bs); -int generated_co_wrapper bdrv_pdiscard(BdrvChild *child, int64_t offset, - int64_t bytes); -int generated_co_wrapper +int co_wrapper_mixed bdrv_invalidate_cache(BlockDriverState *bs, + Error **errp); +int co_wrapper_mixed bdrv_flush(BlockDriverState *bs); +int co_wrapper_mixed bdrv_pdiscard(BdrvChild *child, int64_t offset, + int64_t bytes); +int co_wrapper_mixed bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); -int generated_co_wrapper +int co_wrapper_mixed bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); =20 /** diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backe= nd-io.h index ee3eb12610..7ec6d978d4 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -110,77 +110,77 @@ int coroutine_fn blk_co_is_allocated_above(BlockBacke= nd *blk, * the "I/O or GS" API. */ =20 -int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset, - int64_t bytes, void *buf, - BdrvRequestFlags flags); +int co_wrapper_mixed blk_pread(BlockBackend *blk, int64_t offset, + int64_t bytes, void *buf, + BdrvRequestFlags flags); int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset, int64_t b= ytes, void *buf, BdrvRequestFlags flags); =20 -int generated_co_wrapper blk_preadv(BlockBackend *blk, int64_t offset, - int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags); +int co_wrapper_mixed blk_preadv(BlockBackend *blk, int64_t offset, + int64_t bytes, QEMUIOVector *qiov, + BdrvRequestFlags flags); int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); =20 -int generated_co_wrapper blk_preadv_part(BlockBackend *blk, int64_t offset, - int64_t bytes, QEMUIOVector *qiov, - size_t qiov_offset, - BdrvRequestFlags flags); +int co_wrapper_mixed blk_preadv_part(BlockBackend *blk, int64_t offset, + int64_t bytes, QEMUIOVector *qiov, + size_t qiov_offset, + BdrvRequestFlags flags); int coroutine_fn blk_co_preadv_part(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags f= lags); =20 -int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset, - int64_t bytes, const void *buf, - BdrvRequestFlags flags); +int co_wrapper_mixed blk_pwrite(BlockBackend *blk, int64_t offset, + int64_t bytes, const void *buf, + BdrvRequestFlags flags); int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, int64_t = bytes, const void *buf, BdrvRequestFlags flags); =20 -int generated_co_wrapper blk_pwritev(BlockBackend *blk, int64_t offset, - int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags); +int co_wrapper_mixed blk_pwritev(BlockBackend *blk, int64_t offset, + int64_t bytes, QEMUIOVector *qiov, + BdrvRequestFlags flags); int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); =20 -int generated_co_wrapper blk_pwritev_part(BlockBackend *blk, int64_t offse= t, - int64_t bytes, QEMUIOVector *qio= v, - size_t qiov_offset, - BdrvRequestFlags flags); +int co_wrapper_mixed blk_pwritev_part(BlockBackend *blk, int64_t offset, + int64_t bytes, QEMUIOVector *qiov, + size_t qiov_offset, + BdrvRequestFlags flags); int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offse= t, BdrvRequestFlags flags); =20 -int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk, - int64_t offset, int64_t byt= es, - const void *buf); +int co_wrapper_mixed blk_pwrite_compressed(BlockBackend *blk, + int64_t offset, int64_t bytes, + const void *buf); int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offse= t, int64_t bytes, const void *buf); =20 -int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offs= et, - int64_t bytes, - BdrvRequestFlags flags); +int co_wrapper_mixed blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, + int64_t bytes, + BdrvRequestFlags flags); int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, int64_t bytes, BdrvRequestFlags flag= s); =20 -int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset, - int64_t bytes); +int co_wrapper_mixed blk_pdiscard(BlockBackend *blk, int64_t offset, + int64_t bytes); int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); =20 -int generated_co_wrapper blk_flush(BlockBackend *blk); +int co_wrapper_mixed blk_flush(BlockBackend *blk); int coroutine_fn blk_co_flush(BlockBackend *blk); =20 -int generated_co_wrapper blk_ioctl(BlockBackend *blk, unsigned long int re= q, - void *buf); +int co_wrapper_mixed blk_ioctl(BlockBackend *blk, unsigned long int req, + void *buf); int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsigned long int req, void *buf); =20 -int generated_co_wrapper blk_truncate(BlockBackend *blk, int64_t offset, - bool exact, PreallocMode prealloc, - BdrvRequestFlags flags, Error **errp= ); +int co_wrapper_mixed blk_truncate(BlockBackend *blk, int64_t offset, + bool exact, PreallocMode prealloc, + BdrvRequestFlags flags, Error **errp); int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool e= xact, PreallocMode prealloc, BdrvRequestFlags f= lags, Error **errp); diff --git a/scripts/block-coroutine-wrapper.py b/scripts/block-coroutine-w= rapper.py index 08be813407..56e6425356 100644 --- a/scripts/block-coroutine-wrapper.py +++ b/scripts/block-coroutine-wrapper.py @@ -2,7 +2,7 @@ """Generate coroutine wrappers for block subsystem. =20 The program parses one or several concatenated c files from stdin, -searches for functions with the 'generated_co_wrapper' specifier +searches for functions with the 'co_wrapper_mixed' specifier and generates corresponding wrappers on stdout. =20 Usage: block-coroutine-wrapper.py generated-file.c FILE.[ch]... @@ -74,8 +74,8 @@ def gen_block(self, format: str) -> str: return '\n'.join(format.format_map(arg.__dict__) for arg in self.a= rgs) =20 =20 -# Match wrappers declared with a generated_co_wrapper mark -func_decl_re =3D re.compile(r'^int\s*generated_co_wrapper\s*' +# Match wrappers declared with a co_wrapper_mixed mark +func_decl_re =3D re.compile(r'^int\s*co_wrapper_mixed\s*' r'(?P[a-z][a-z0-9_]*)' r'\((?P[^)]*)\);$', re.MULTILINE) =20 --=20 2.31.1 From nobody Mon May 6 00:41:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669383581; cv=none; d=zohomail.com; s=zohoarc; b=lvWXX5ZAH8KSLMLsIMQei8f5Q++NzTlbcmYXeKLQqQsSCzkUMBtWOrncBs67asYQvDs5zZKiXMWfCAItbJ5y1+TVc3uADtEhU0StHB7W/aTSmGV3O3fiLZMWV0f4L7BAFZI9BegbhbS8kds0xgwcQcNjsoJt0D7ImKcXC9Q9LyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669383581; 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=fcnVOdUy4/t5jL683B7bA1LjMUE9GwGlOVYHLjlt9aU=; b=YGYTLF4kxldwMmXVHR9/SrUKLbHXZOwSm7LpV8Gr8Z1Jv0O8Kf2X7ihaI+FnYEOHctNnE4n9YPj2/4vBhlveP3+8oy9XKm1hArNwPrhOk44naWFbBqIbc4WkAp2D0yTr3Q1nwRL4HJI9C0qURrep+HRKIkCfpPeZ/7fAqkjACWU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669383581574507.8527178226111; Fri, 25 Nov 2022 05:39:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyYrv-0006ZK-Ko; Fri, 25 Nov 2022 08:35:51 -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 1oyYrf-0006So-MK for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:35 -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 1oyYrZ-0005Cw-9L for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:34 -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-528-refU2q7YPY2q4kqffkZoTg-1; Fri, 25 Nov 2022 08:35:26 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CACB93C0E21D; Fri, 25 Nov 2022 13:35:25 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 679412166B46; Fri, 25 Nov 2022 13:35:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669383327; 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=fcnVOdUy4/t5jL683B7bA1LjMUE9GwGlOVYHLjlt9aU=; b=CmB2+k3BGE1sWNdkJ+mVvnasKy1HLSfHz6CnP3FPRSG85+0N4OpkBmMNW/aTclYMhAnTRA 0IVEA9SiZ0twhpvChEM/Zbt1R+O1DnolN13LNoEyI6XzEQ6C7slFTgTgJ0clehe3m4ChsW 22yrO3Vtviw3ap5U93n0azSt6+AfWOA= X-MC-Unique: refU2q7YPY2q4kqffkZoTg-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v6 10/14] block-coroutine-wrapper.py: introduce co_wrapper Date: Fri, 25 Nov 2022 08:35:14 -0500 Message-Id: <20221125133518.418328-11-eesposit@redhat.com> In-Reply-To: <20221125133518.418328-1-eesposit@redhat.com> References: <20221125133518.418328-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669383582495100001 Content-Type: text/plain; charset="utf-8" This new annotation creates just a function wrapper that creates a new coroutine. It assumes the caller is not a coroutine. It will be the default annotation to be used in the future. This is much better as c_w_mixed, because it is clear if the caller is a coroutine or not, and provides the advantage of automating the code creation. In the future all c_w_mixed functions will be substituted by co_wrapper. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- docs/devel/block-coroutine-wrapper.rst | 6 +- include/block/block-common.h | 8 +- scripts/block-coroutine-wrapper.py | 109 +++++++++++++++++-------- 3 files changed, 85 insertions(+), 38 deletions(-) diff --git a/docs/devel/block-coroutine-wrapper.rst b/docs/devel/block-coro= utine-wrapper.rst index 64acc8d65d..6dd2cdcab3 100644 --- a/docs/devel/block-coroutine-wrapper.rst +++ b/docs/devel/block-coroutine-wrapper.rst @@ -26,12 +26,12 @@ called ``bdrv_foo()``. In this case the scri= pt can help. To trigger the generation: =20 1. You need ``bdrv_foo`` declaration somewhere (for example, in - ``block/coroutines.h``) with the ``co_wrapper_mixed`` mark, + ``block/coroutines.h``) with the ``co_wrapper`` mark, like this: =20 .. code-block:: c =20 - int co_wrapper_mixed bdrv_foo(); + int co_wrapper bdrv_foo(); =20 2. You need to feed this declaration to block-coroutine-wrapper script. For this, add the .h (or .c) file with the declaration to the @@ -46,7 +46,7 @@ Links =20 1. The script location is ``scripts/block-coroutine-wrapper.py``. =20 -2. Generic place for private ``co_wrapper_mixed`` declarations is +2. Generic place for private ``co_wrapper`` declarations is ``block/coroutines.h``, for public declarations: ``include/block/block.h`` =20 diff --git a/include/block/block-common.h b/include/block/block-common.h index ec2309055b..847e4d4626 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -42,9 +42,13 @@ * * Usage: read docs/devel/block-coroutine-wrapper.rst * - * co_wrapper_mixed functions can be called by both coroutine and - * non-coroutine context. + * There are 2 kind of specifiers: + * - co_wrapper functions can be called by only non-coroutine context, bec= ause + * they always generate a new coroutine. + * - co_wrapper_mixed functions can be called by both coroutine and + * non-coroutine context. */ +#define co_wrapper #define co_wrapper_mixed =20 /* block.c */ diff --git a/scripts/block-coroutine-wrapper.py b/scripts/block-coroutine-w= rapper.py index 56e6425356..7972d3fe01 100644 --- a/scripts/block-coroutine-wrapper.py +++ b/scripts/block-coroutine-wrapper.py @@ -2,7 +2,7 @@ """Generate coroutine wrappers for block subsystem. =20 The program parses one or several concatenated c files from stdin, -searches for functions with the 'co_wrapper_mixed' specifier +searches for functions with the 'co_wrapper' specifier and generates corresponding wrappers on stdout. =20 Usage: block-coroutine-wrapper.py generated-file.c FILE.[ch]... @@ -62,10 +62,28 @@ def __init__(self, param_decl: str) -> None: =20 =20 class FuncDecl: - def __init__(self, return_type: str, name: str, args: str) -> None: + def __init__(self, return_type: str, name: str, args: str, + variant: str) -> None: self.return_type =3D return_type.strip() self.name =3D name.strip() + self.struct_name =3D snake_to_camel(self.name) self.args =3D [ParamDecl(arg.strip()) for arg in args.split(',')] + self.create_only_co =3D True + + if 'mixed' in variant: + self.create_only_co =3D False + + subsystem, subname =3D self.name.split('_', 1) + self.co_name =3D f'{subsystem}_co_{subname}' + + t =3D self.args[0].type + if t =3D=3D 'BlockDriverState *': + bs =3D 'bs' + elif t =3D=3D 'BdrvChild *': + bs =3D 'child->bs' + else: + bs =3D 'blk_bs(blk)' + self.bs =3D bs =20 def gen_list(self, format: str) -> str: return ', '.join(format.format_map(arg.__dict__) for arg in self.a= rgs) @@ -74,8 +92,9 @@ def gen_block(self, format: str) -> str: return '\n'.join(format.format_map(arg.__dict__) for arg in self.a= rgs) =20 =20 -# Match wrappers declared with a co_wrapper_mixed mark -func_decl_re =3D re.compile(r'^int\s*co_wrapper_mixed\s*' +# Match wrappers declared with a co_wrapper mark +func_decl_re =3D re.compile(r'^int\s*co_wrapper' + r'(?P(_[a-z][a-z0-9_]*)?)\s*' r'(?P[a-z][a-z0-9_]*)' r'\((?P[^)]*)\);$', re.MULTILINE) =20 @@ -84,7 +103,8 @@ def func_decl_iter(text: str) -> Iterator: for m in func_decl_re.finditer(text): yield FuncDecl(return_type=3D'int', name=3Dm.group('wrapper_name'), - args=3Dm.group('args')) + args=3Dm.group('args'), + variant=3Dm.group('variant')) =20 =20 def snake_to_camel(func_name: str) -> str: @@ -97,24 +117,63 @@ def snake_to_camel(func_name: str) -> str: return ''.join(words) =20 =20 +# Checks if we are already in coroutine +def create_g_c_w(func: FuncDecl) -> str: + name =3D func.co_name + struct_name =3D func.struct_name + return f"""\ +int {func.name}({ func.gen_list('{decl}') }) +{{ + if (qemu_in_coroutine()) {{ + return {name}({ func.gen_list('{name}') }); + }} else {{ + {struct_name} s =3D {{ + .poll_state.bs =3D {func.bs}, + .poll_state.in_progress =3D true, + +{ func.gen_block(' .{name} =3D {name},') } + }}; + + s.poll_state.co =3D qemu_coroutine_create({name}_entry, &s); + + return bdrv_poll_co(&s.poll_state); + }} +}}""" + + +# Assumes we are not in coroutine, and creates one +def create_coroutine_only(func: FuncDecl) -> str: + name =3D func.co_name + struct_name =3D func.struct_name + return f"""\ +int {func.name}({ func.gen_list('{decl}') }) +{{ + {struct_name} s =3D {{ + .poll_state.bs =3D {func.bs}, + .poll_state.in_progress =3D true, + +{ func.gen_block(' .{name} =3D {name},') } + }}; + assert(!qemu_in_coroutine()); + + s.poll_state.co =3D qemu_coroutine_create({name}_entry, &s); + + return bdrv_poll_co(&s.poll_state); +}}""" + + def gen_wrapper(func: FuncDecl) -> str: assert not '_co_' in func.name assert func.return_type =3D=3D 'int' assert func.args[0].type in ['BlockDriverState *', 'BdrvChild *', 'BlockBackend *'] =20 - subsystem, subname =3D func.name.split('_', 1) - - name =3D f'{subsystem}_co_{subname}' + name =3D func.co_name + struct_name =3D func.struct_name =20 - t =3D func.args[0].type - if t =3D=3D 'BlockDriverState *': - bs =3D 'bs' - elif t =3D=3D 'BdrvChild *': - bs =3D 'child->bs' - else: - bs =3D 'blk_bs(blk)' - struct_name =3D snake_to_camel(name) + creation_function =3D create_g_c_w + if func.create_only_co: + creation_function =3D create_coroutine_only =20 return f"""\ /* @@ -136,23 +195,7 @@ def gen_wrapper(func: FuncDecl) -> str: aio_wait_kick(); }} =20 -int {func.name}({ func.gen_list('{decl}') }) -{{ - if (qemu_in_coroutine()) {{ - return {name}({ func.gen_list('{name}') }); - }} else {{ - {struct_name} s =3D {{ - .poll_state.bs =3D {bs}, - .poll_state.in_progress =3D true, - -{ func.gen_block(' .{name} =3D {name},') } - }}; - - s.poll_state.co =3D qemu_coroutine_create({name}_entry, &s); - - return bdrv_poll_co(&s.poll_state); - }} -}}""" +{creation_function(func)}""" =20 =20 def gen_wrappers(input_code: str) -> str: --=20 2.31.1 From nobody Mon May 6 00:41:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669383379; cv=none; d=zohomail.com; s=zohoarc; b=Q+NIcZVe6LmNMygAZFe6+DveFUDLC81zIx/otO/cb4ZFnMNQ/rZNutCY7DZPite80hGrxbF+D2hRgqYZ8nStUir5TSDdHkzUxiZeISQFUPyfY9vPyoTaroiuTsHd9alH2i6OoWo7CF0UYhqlG8xqWv/3DGst7uAJqr8aWxiJLak= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669383379; 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=t+hQkeuLxQUOF8Q06z5BuHlnGeJ/4tW/v4aWPQuK2i0=; b=LxOgVgrzWhRJSPZYhxlVnDvcj9U4hhJPv5dMsfynzTp5i/YQDFwISn52uj9LDVAOpFNi68WMD+AFZykEvJJWyR9Iw0TKjR5QuigR2bpFCjgX2C7pGIhHEAgT/tcQsVCa8vO7UCj8YKU7w/xI8UcFkhBv46QuZD3c58FTfG5XoHg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669383379581284.482118699357; Fri, 25 Nov 2022 05:36:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyYry-0006eE-Co; Fri, 25 Nov 2022 08:35:54 -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 1oyYrj-0006Vo-CL for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:41 -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 1oyYrb-0005Fv-GR for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:38 -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-193-gZtQnU7KPFmZX8rLMLAaYw-1; Fri, 25 Nov 2022 08:35:27 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 43FC51C0690A; Fri, 25 Nov 2022 13:35:26 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id D48772166B46; Fri, 25 Nov 2022 13:35:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669383330; 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=t+hQkeuLxQUOF8Q06z5BuHlnGeJ/4tW/v4aWPQuK2i0=; b=Pm0IaIDqponUH23hlsb8o35bA5MkwSweCHovDNRrMJ4MlyJgik36TjFXhfxj6eP5XuzQrw 81/YvuGdGEyQb/aozjbqwTiXkHCbpcxYFHX71O64arLQtjhUYwUKd7mnE73PD2AQ7Tn0Wm P0H9QsLVeyFAI9Lx0RNfzb1iaNsqsnk= X-MC-Unique: gZtQnU7KPFmZX8rLMLAaYw-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v6 11/14] block-coroutine-wrapper.py: default to main loop aiocontext if function does not have a BlockDriverState parameter Date: Fri, 25 Nov 2022 08:35:15 -0500 Message-Id: <20221125133518.418328-12-eesposit@redhat.com> In-Reply-To: <20221125133518.418328-1-eesposit@redhat.com> References: <20221125133518.418328-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669383381289100001 Content-Type: text/plain; charset="utf-8" Right now, we take the first parameter of the function to get the BlockDriverState to pass to bdrv_poll_co(), that internally calls functions that figure in which aiocontext the coroutine should run. However, it is useless to pass a bs just to get its own AioContext, so instead pass it directly, and default to the main loop if no BlockDriverState is passed as parameter. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/block-gen.h | 6 +++--- scripts/block-coroutine-wrapper.py | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/block/block-gen.h b/block/block-gen.h index f80cf4897d..08d977f493 100644 --- a/block/block-gen.h +++ b/block/block-gen.h @@ -30,7 +30,7 @@ =20 /* Base structure for argument packing structures */ typedef struct BdrvPollCo { - BlockDriverState *bs; + AioContext *ctx; bool in_progress; int ret; Coroutine *co; /* Keep pointer here for debugging */ @@ -40,8 +40,8 @@ static inline int bdrv_poll_co(BdrvPollCo *s) { assert(!qemu_in_coroutine()); =20 - bdrv_coroutine_enter(s->bs, s->co); - BDRV_POLL_WHILE(s->bs, s->in_progress); + aio_co_enter(s->ctx, s->co); + AIO_WAIT_WHILE(s->ctx, s->in_progress); =20 return s->ret; } diff --git a/scripts/block-coroutine-wrapper.py b/scripts/block-coroutine-w= rapper.py index 7972d3fe01..61a718ea2f 100644 --- a/scripts/block-coroutine-wrapper.py +++ b/scripts/block-coroutine-wrapper.py @@ -78,12 +78,14 @@ def __init__(self, return_type: str, name: str, args: s= tr, =20 t =3D self.args[0].type if t =3D=3D 'BlockDriverState *': - bs =3D 'bs' + ctx =3D 'bdrv_get_aio_context(bs)' elif t =3D=3D 'BdrvChild *': - bs =3D 'child->bs' + ctx =3D 'bdrv_get_aio_context(child->bs)' + elif t =3D=3D 'BlockBackend *': + ctx =3D 'blk_get_aio_context(blk)' else: - bs =3D 'blk_bs(blk)' - self.bs =3D bs + ctx =3D 'qemu_get_aio_context()' + self.ctx =3D ctx =20 def gen_list(self, format: str) -> str: return ', '.join(format.format_map(arg.__dict__) for arg in self.a= rgs) @@ -128,7 +130,7 @@ def create_g_c_w(func: FuncDecl) -> str: return {name}({ func.gen_list('{name}') }); }} else {{ {struct_name} s =3D {{ - .poll_state.bs =3D {func.bs}, + .poll_state.ctx =3D {func.ctx}, .poll_state.in_progress =3D true, =20 { func.gen_block(' .{name} =3D {name},') } @@ -149,7 +151,7 @@ def create_coroutine_only(func: FuncDecl) -> str: int {func.name}({ func.gen_list('{decl}') }) {{ {struct_name} s =3D {{ - .poll_state.bs =3D {func.bs}, + .poll_state.ctx =3D {func.ctx}, .poll_state.in_progress =3D true, =20 { func.gen_block(' .{name} =3D {name},') } @@ -165,8 +167,6 @@ def create_coroutine_only(func: FuncDecl) -> str: def gen_wrapper(func: FuncDecl) -> str: assert not '_co_' in func.name assert func.return_type =3D=3D 'int' - assert func.args[0].type in ['BlockDriverState *', 'BdrvChild *', - 'BlockBackend *'] =20 name =3D func.co_name struct_name =3D func.struct_name --=20 2.31.1 From nobody Mon May 6 00:41:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669383425; cv=none; d=zohomail.com; s=zohoarc; b=ktibVASF/NWLh7GKYAjjOzMKVKJGarGkfg9/0BjHyDiL82bqPYAJcL3+Bl7dVsw5GYUVWUzix5uk5EuRH8y9arj8ebwL7caW9CEUTIB8l89/NCDhVyEcx7l8a2M/p+HHCuThD0nKuRwOsWwURi8aT4oPRN7iFuaA9TyZxNruloY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669383425; 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=j1DQDqJyTtX9vawlSjo3gQtR9KvaODNFx+emVlpL+Vc=; b=PHDpva8/xEyVj2BhbrXWvO8XaPATRxPnp1lZ7RKWRB6nMm05hb7u4TsJzdKs4LqVMmRo6WOZt7CgNGWwzLKMZr3b+leudOgT+v0atk8yMwH25X04gsmXdo4GG0CviHPrG0olFBdPQrj2EXYyRl4CDNGgH8EYiQXi0cmBytwx/3c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669383425951468.5549065051532; Fri, 25 Nov 2022 05:37:05 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyYs2-0006qB-GS; Fri, 25 Nov 2022 08:36:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oyYri-0006Vl-HS for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:41 -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 1oyYrb-0005G4-En for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:38 -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-629-5R2E7ASFO7OyJ64gMx217Q-1; Fri, 25 Nov 2022 08:35:27 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AD4EF1C06902; Fri, 25 Nov 2022 13:35:26 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4DA7C2166B48; Fri, 25 Nov 2022 13:35:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669383330; 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=j1DQDqJyTtX9vawlSjo3gQtR9KvaODNFx+emVlpL+Vc=; b=cjHPnQajT3sun8+i8eq1Q7v0uekR7CwijpZxgV3ssRz45BoBEVHn+jkY6cEx91yn4nU15c VHcENBSerCxx6IuL7UzTxlCqens0M3UNmieN21aW47H9LZiKsZ1oCSO+zN2MOqJ3TSlfbY fMPLuzBrOBix6VrFRYJU9GcOYp4KoQw= X-MC-Unique: 5R2E7ASFO7OyJ64gMx217Q-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v6 12/14] block-coroutine-wrapper.py: support also basic return types Date: Fri, 25 Nov 2022 08:35:16 -0500 Message-Id: <20221125133518.418328-13-eesposit@redhat.com> In-Reply-To: <20221125133518.418328-1-eesposit@redhat.com> References: <20221125133518.418328-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_FILL_THIS_FORM_SHORT=0.01 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669383427521100003 Content-Type: text/plain; charset="utf-8" Extend the regex to cover also return type, pointers included. This implies that the value returned by the function cannot be a simple "int" anymore, but the custom return type. Therefore remove poll_state->ret and instead use a per-function custom "ret" field. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/block-gen.h | 5 +---- scripts/block-coroutine-wrapper.py | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/block/block-gen.h b/block/block-gen.h index 08d977f493..89b7daaa1f 100644 --- a/block/block-gen.h +++ b/block/block-gen.h @@ -32,18 +32,15 @@ typedef struct BdrvPollCo { AioContext *ctx; bool in_progress; - int ret; Coroutine *co; /* Keep pointer here for debugging */ } BdrvPollCo; =20 -static inline int bdrv_poll_co(BdrvPollCo *s) +static inline void bdrv_poll_co(BdrvPollCo *s) { assert(!qemu_in_coroutine()); =20 aio_co_enter(s->ctx, s->co); AIO_WAIT_WHILE(s->ctx, s->in_progress); - - return s->ret; } =20 #endif /* BLOCK_BLOCK_GEN_H */ diff --git a/scripts/block-coroutine-wrapper.py b/scripts/block-coroutine-w= rapper.py index 61a718ea2f..9d5d70a7dd 100644 --- a/scripts/block-coroutine-wrapper.py +++ b/scripts/block-coroutine-wrapper.py @@ -95,7 +95,8 @@ def gen_block(self, format: str) -> str: =20 =20 # Match wrappers declared with a co_wrapper mark -func_decl_re =3D re.compile(r'^int\s*co_wrapper' +func_decl_re =3D re.compile(r'^(?P[a-zA-Z][a-zA-Z0-9_]* [*]?)' + r'\s*co_wrapper' r'(?P(_[a-z][a-z0-9_]*)?)\s*' r'(?P[a-z][a-z0-9_]*)' r'\((?P[^)]*)\);$', re.MULTILINE) @@ -103,7 +104,7 @@ def gen_block(self, format: str) -> str: =20 def func_decl_iter(text: str) -> Iterator: for m in func_decl_re.finditer(text): - yield FuncDecl(return_type=3D'int', + yield FuncDecl(return_type=3Dm.group('return_type'), name=3Dm.group('wrapper_name'), args=3Dm.group('args'), variant=3Dm.group('variant')) @@ -124,7 +125,7 @@ def create_g_c_w(func: FuncDecl) -> str: name =3D func.co_name struct_name =3D func.struct_name return f"""\ -int {func.name}({ func.gen_list('{decl}') }) +{func.return_type} {func.name}({ func.gen_list('{decl}') }) {{ if (qemu_in_coroutine()) {{ return {name}({ func.gen_list('{name}') }); @@ -138,7 +139,8 @@ def create_g_c_w(func: FuncDecl) -> str: =20 s.poll_state.co =3D qemu_coroutine_create({name}_entry, &s); =20 - return bdrv_poll_co(&s.poll_state); + bdrv_poll_co(&s.poll_state); + return s.ret; }} }}""" =20 @@ -148,7 +150,7 @@ def create_coroutine_only(func: FuncDecl) -> str: name =3D func.co_name struct_name =3D func.struct_name return f"""\ -int {func.name}({ func.gen_list('{decl}') }) +{func.return_type} {func.name}({ func.gen_list('{decl}') }) {{ {struct_name} s =3D {{ .poll_state.ctx =3D {func.ctx}, @@ -160,13 +162,13 @@ def create_coroutine_only(func: FuncDecl) -> str: =20 s.poll_state.co =3D qemu_coroutine_create({name}_entry, &s); =20 - return bdrv_poll_co(&s.poll_state); + bdrv_poll_co(&s.poll_state); + return s.ret; }}""" =20 =20 def gen_wrapper(func: FuncDecl) -> str: assert not '_co_' in func.name - assert func.return_type =3D=3D 'int' =20 name =3D func.co_name struct_name =3D func.struct_name @@ -182,6 +184,7 @@ def gen_wrapper(func: FuncDecl) -> str: =20 typedef struct {struct_name} {{ BdrvPollCo poll_state; + {func.return_type} ret; { func.gen_block(' {decl};') } }} {struct_name}; =20 @@ -189,7 +192,7 @@ def gen_wrapper(func: FuncDecl) -> str: {{ {struct_name} *s =3D opaque; =20 - s->poll_state.ret =3D {name}({ func.gen_list('s->{name}') }); + s->ret =3D {name}({ func.gen_list('s->{name}') }); s->poll_state.in_progress =3D false; =20 aio_wait_kick(); --=20 2.31.1 From nobody Mon May 6 00:41:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669383586; cv=none; d=zohomail.com; s=zohoarc; b=P0prrtdahW16H/vIZrmpF9cfLdMSHl9mujjynz8Zc6LF86cAzmze3i4i8HgX5bz4LBuvLCrTfhXyz1rNo8ETOY4gHE1Z/ShF6V0P0C0MZJw4qt57vMywCIP0vmP4Ds5d8RnHPKl/z5Od1AP3b6GnP16loLhFJiB0m7MrULhkTV4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669383586; 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=wrZwmibtufJ2HXTilrk2NaR2PYv/x4SXjcdCbwlrG9Q=; b=Xgmzyx8WYlXhEDLRu2xRrBOiWXIWVe+t/d9toPOJx6mNgxi4ECsgbOwVDKMLYx8EF5tUYWcZeQLB+Mbf2uS6dbpNPY0HkcQFfu9Efr7ocirNgsyxPzPdUZQLBT+7r5dTtutc1hh9y0lXqXUWGnf97jLz1osOU/46jRherXuXYOs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669383586874887.5943592627629; Fri, 25 Nov 2022 05:39:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyYs6-0006u4-8v; Fri, 25 Nov 2022 08:36:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oyYrj-0006W2-LS for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35:41 -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 1oyYrb-0005G7-GV for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35: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-25-KsCgvPGQMk2hQAZTS4PEvQ-1; Fri, 25 Nov 2022 08:35:27 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 2389438164D5; Fri, 25 Nov 2022 13:35:27 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id B745A2166B47; Fri, 25 Nov 2022 13:35:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669383330; 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=wrZwmibtufJ2HXTilrk2NaR2PYv/x4SXjcdCbwlrG9Q=; b=aD+3DDgZNnAnyw7YK2VZItV07ZOCdKcX3J7UOle/Y8uIkCfmc6LuvtUJsMD/n9ouLgZZo/ zw+NkufWS6SN9fsGoR6y9k42jArE7YyNifOa5iEzT0UAqU3DYZ2MLW6b2z5iFAUMDNujuC 8x169FDXwzexVYfezu2Ms9BzrgfFoNo= X-MC-Unique: KsCgvPGQMk2hQAZTS4PEvQ-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v6 13/14] block: convert bdrv_create to co_wrapper Date: Fri, 25 Nov 2022 08:35:17 -0500 Message-Id: <20221125133518.418328-14-eesposit@redhat.com> In-Reply-To: <20221125133518.418328-1-eesposit@redhat.com> References: <20221125133518.418328-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669383588508100001 Content-Type: text/plain; charset="utf-8" This function is never called in coroutine context, therefore instead of manually creating a new coroutine, delegate it to the block-coroutine-wrapper script, defining it as co_wrapper. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- block.c | 40 ++---------------------------- include/block/block-global-state.h | 8 ++++-- 2 files changed, 8 insertions(+), 40 deletions(-) diff --git a/block.c b/block.c index 772df02d54..a6465bac74 100644 --- a/block.c +++ b/block.c @@ -528,8 +528,8 @@ typedef struct CreateCo { Error *err; } CreateCo; =20 -static int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filen= ame, - QemuOpts *opts, Error **errp) +int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp) { int ret; GLOBAL_STATE_CODE(); @@ -552,42 +552,6 @@ static int coroutine_fn bdrv_co_create(BlockDriver *dr= v, const char *filename, return ret; } =20 -static void coroutine_fn bdrv_create_co_entry(void *opaque) -{ - CreateCo *cco =3D opaque; - GLOBAL_STATE_CODE(); - - cco->ret =3D bdrv_co_create(cco->drv, cco->filename, cco->opts, &cco->= err); -} - -int bdrv_create(BlockDriver *drv, const char* filename, - QemuOpts *opts, Error **errp) -{ - GLOBAL_STATE_CODE(); - - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - return bdrv_co_create(drv, filename, opts, errp); - } else { - Coroutine *co; - CreateCo cco =3D { - .drv =3D drv, - .filename =3D filename, - .opts =3D opts, - .ret =3D NOT_DONE, - .err =3D NULL, - }; - - co =3D qemu_coroutine_create(bdrv_create_co_entry, &cco); - qemu_coroutine_enter(co); - while (cco.ret =3D=3D NOT_DONE) { - aio_poll(qemu_get_aio_context(), true); - } - error_propagate(errp, cco.err); - return cco.ret; - } -} - /** * Helper function for bdrv_create_file_fallback(): Resize @blk to at * least the given @minimum_size. diff --git a/include/block/block-global-state.h b/include/block/block-globa= l-state.h index 387a7cbb2e..1f8b54f2df 100644 --- a/include/block/block-global-state.h +++ b/include/block/block-global-state.h @@ -55,8 +55,12 @@ BlockDriver *bdrv_find_protocol(const char *filename, bool allow_protocol_prefix, Error **errp); BlockDriver *bdrv_find_format(const char *format_name); -int bdrv_create(BlockDriver *drv, const char* filename, - QemuOpts *opts, Error **errp); + +int coroutine_fn bdrv_co_create(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp); +int co_wrapper bdrv_create(BlockDriver *drv, const char *filename, + QemuOpts *opts, Error **errp); + int coroutine_fn bdrv_co_create_file(const char *filename, QemuOpts *opts, Error **errp); =20 --=20 2.31.1 From nobody Mon May 6 00:41:11 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1669383681; cv=none; d=zohomail.com; s=zohoarc; b=KdAni6CFBI+ggmU8JK1ZimpjMVZF8y/X8KkXylqaXb4wXS+tF5QWIVnl+xWxYez0v8Gwp4Y9ojTPIkadLBS314U5TJBjnU1ifP410mTjt1Hyw0ZUfa7Sm9H1eG9TeePSrlFeYTv7eEjp58Qpw2p3jAKV0Zx6FFxXuHtUrzGB88M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1669383681; 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=Fpb2xG+QzbZjY9RbyYvWPOQyMk5SFaHyNUYglIPMznY=; b=fI3tOJiJqGoCIF+Ea0KRrPKlp49j0cBn3mmdBB5475xcwM114qDYS1DZLmqJenL4dOt6GyHZTx9XjoEngHs4hy8DGW9DOoeRYulDlh2QB84v+B8PyQDH69jqZsJsXdp/f3HgwEA4GzEAGjf8X+CdG/As7bK9oaGG4buLhNE46qg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1669383681070336.43084896538494; Fri, 25 Nov 2022 05:41:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyYs5-0006sw-Q7; Fri, 25 Nov 2022 08:36:01 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oyYrk-0006W3-34 for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35: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 1oyYrc-0005GP-2h for qemu-devel@nongnu.org; Fri, 25 Nov 2022 08:35: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-37-EjRPU6QtOLq4Kv-k3fZg7g-1; Fri, 25 Nov 2022 08:35:28 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 91CAC2932494; Fri, 25 Nov 2022 13:35:27 +0000 (UTC) Received: from virtlab701.virt.lab.eng.bos.redhat.com (virtlab701.virt.lab.eng.bos.redhat.com [10.19.152.228]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2DB882166B47; Fri, 25 Nov 2022 13:35:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669383331; 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=Fpb2xG+QzbZjY9RbyYvWPOQyMk5SFaHyNUYglIPMznY=; b=f/RjB5g6WCWwh+wXkbKubdXs1RviaOx/0tDVzW/tZd2bkEJNkjtpsi6XoqUbof5xxH5dey ghxdKw5TsTGSk49Ag85SVzfpzldd9ktJwIcTZl4QlkUlqa85JiUUHVuM2vWbfFL2StuWHv NdZwRzCN/jOCUYMcMM7gWSZQ2G9R4Uk= X-MC-Unique: EjRPU6QtOLq4Kv-k3fZg7g-1 From: Emanuele Giuseppe Esposito To: qemu-block@nongnu.org Cc: Kevin Wolf , Paolo Bonzini , Hanna Reitz , John Snow , Vladimir Sementsov-Ogievskiy , Eric Blake , Fam Zheng , Stefan Hajnoczi , "Denis V. Lunev" , Stefan Weil , Jeff Cody , Cleber Rosa , qemu-devel@nongnu.org, Emanuele Giuseppe Esposito Subject: [PATCH v6 14/14] block/dirty-bitmap: convert coroutine-only functions to co_wrapper Date: Fri, 25 Nov 2022 08:35:18 -0500 Message-Id: <20221125133518.418328-15-eesposit@redhat.com> In-Reply-To: <20221125133518.418328-1-eesposit@redhat.com> References: <20221125133518.418328-1-eesposit@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=eesposit@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1669383683299100002 Content-Type: text/plain; charset="utf-8" bdrv_can_store_new_dirty_bitmap and bdrv_remove_persistent_dirty_bitmap check if they are running in a coroutine, directly calling the coroutine callback if it's the case. Except that no coroutine calls such functions, therefore that check can be removed, and function creation can be offloaded to c_w. Signed-off-by: Emanuele Giuseppe Esposito Reviewed-by: Kevin Wolf Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/dirty-bitmap.c | 88 +----------------------------------- block/meson.build | 1 + include/block/block-common.h | 5 +- include/block/block-io.h | 10 +++- include/block/dirty-bitmap.h | 10 +++- 5 files changed, 22 insertions(+), 92 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index bf3dc0512a..21cf592889 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -388,7 +388,7 @@ void bdrv_release_named_dirty_bitmaps(BlockDriverState = *bs) * not fail. * This function doesn't release corresponding BdrvDirtyBitmap. */ -static int coroutine_fn +int coroutine_fn bdrv_co_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *n= ame, Error **errp) { @@ -399,45 +399,6 @@ bdrv_co_remove_persistent_dirty_bitmap(BlockDriverStat= e *bs, const char *name, return 0; } =20 -typedef struct BdrvRemovePersistentDirtyBitmapCo { - BlockDriverState *bs; - const char *name; - Error **errp; - int ret; -} BdrvRemovePersistentDirtyBitmapCo; - -static void coroutine_fn -bdrv_co_remove_persistent_dirty_bitmap_entry(void *opaque) -{ - BdrvRemovePersistentDirtyBitmapCo *s =3D opaque; - - s->ret =3D bdrv_co_remove_persistent_dirty_bitmap(s->bs, s->name, s->e= rrp); - aio_wait_kick(); -} - -int bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *= name, - Error **errp) -{ - if (qemu_in_coroutine()) { - return bdrv_co_remove_persistent_dirty_bitmap(bs, name, errp); - } else { - Coroutine *co; - BdrvRemovePersistentDirtyBitmapCo s =3D { - .bs =3D bs, - .name =3D name, - .errp =3D errp, - .ret =3D -EINPROGRESS, - }; - - co =3D qemu_coroutine_create(bdrv_co_remove_persistent_dirty_bitma= p_entry, - &s); - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, s.ret =3D=3D -EINPROGRESS); - - return s.ret; - } -} - bool bdrv_supports_persistent_dirty_bitmap(BlockDriverState *bs) { @@ -447,7 +408,7 @@ bdrv_supports_persistent_dirty_bitmap(BlockDriverState = *bs) return false; } =20 -static bool coroutine_fn +bool coroutine_fn bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *name, uint32_t granularity, Error **errp) { @@ -470,51 +431,6 @@ bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *b= s, const char *name, return drv->bdrv_co_can_store_new_dirty_bitmap(bs, name, granularity, = errp); } =20 -typedef struct BdrvCanStoreNewDirtyBitmapCo { - BlockDriverState *bs; - const char *name; - uint32_t granularity; - Error **errp; - bool ret; - - bool in_progress; -} BdrvCanStoreNewDirtyBitmapCo; - -static void coroutine_fn bdrv_co_can_store_new_dirty_bitmap_entry(void *op= aque) -{ - BdrvCanStoreNewDirtyBitmapCo *s =3D opaque; - - s->ret =3D bdrv_co_can_store_new_dirty_bitmap(s->bs, s->name, s->granu= larity, - s->errp); - s->in_progress =3D false; - aio_wait_kick(); -} - -bool bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *nam= e, - uint32_t granularity, Error **errp) -{ - IO_CODE(); - if (qemu_in_coroutine()) { - return bdrv_co_can_store_new_dirty_bitmap(bs, name, granularity, e= rrp); - } else { - Coroutine *co; - BdrvCanStoreNewDirtyBitmapCo s =3D { - .bs =3D bs, - .name =3D name, - .granularity =3D granularity, - .errp =3D errp, - .in_progress =3D true, - }; - - co =3D qemu_coroutine_create(bdrv_co_can_store_new_dirty_bitmap_en= try, - &s); - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, s.in_progress); - - return s.ret; - } -} - void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap) { bdrv_dirty_bitmaps_lock(bitmap->bs); diff --git a/block/meson.build b/block/meson.build index b7c68b83a3..c48a59571e 100644 --- a/block/meson.build +++ b/block/meson.build @@ -137,6 +137,7 @@ block_gen_c =3D custom_target('block-gen.c', output: 'block-gen.c', input: files( '../include/block/block-io.h', + '../include/block/dirty-bitmap.h', '../include/block/block-global-state= .h', '../include/sysemu/block-backend-io.= h', 'coroutines.h' diff --git a/include/block/block-common.h b/include/block/block-common.h index 847e4d4626..6cf603ab06 100644 --- a/include/block/block-common.h +++ b/include/block/block-common.h @@ -29,8 +29,6 @@ #include "qemu/iov.h" #include "qemu/coroutine.h" #include "block/accounting.h" -#include "block/dirty-bitmap.h" -#include "block/blockjob.h" #include "qemu/hbitmap.h" #include "qemu/transactions.h" =20 @@ -51,6 +49,9 @@ #define co_wrapper #define co_wrapper_mixed =20 +#include "block/dirty-bitmap.h" +#include "block/blockjob.h" + /* block.c */ typedef struct BlockDriver BlockDriver; typedef struct BdrvChild BdrvChild; diff --git a/include/block/block-io.h b/include/block/block-io.h index 72cf45975b..52869ea08e 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -215,8 +215,14 @@ AioContext *child_of_bds_get_parent_aio_context(BdrvCh= ild *c); void bdrv_io_plug(BlockDriverState *bs); void bdrv_io_unplug(BlockDriverState *bs); =20 -bool bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, const char *nam= e, - uint32_t granularity, Error **errp); +bool coroutine_fn bdrv_co_can_store_new_dirty_bitmap(BlockDriverState *bs, + const char *name, + uint32_t granularity, + Error **errp); +bool co_wrapper bdrv_can_store_new_dirty_bitmap(BlockDriverState *bs, + const char *name, + uint32_t granularity, + Error **errp); =20 /** * diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 6528336c4c..c3700cec76 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -34,8 +34,14 @@ int bdrv_dirty_bitmap_check(const BdrvDirtyBitmap *bitma= p, uint32_t flags, Error **errp); void bdrv_release_dirty_bitmap(BdrvDirtyBitmap *bitmap); void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs); -int bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *= name, - Error **errp); + +int coroutine_fn bdrv_co_remove_persistent_dirty_bitmap(BlockDriverState *= bs, + const char *name, + Error **errp); +int co_wrapper bdrv_remove_persistent_dirty_bitmap(BlockDriverState *bs, + const char *name, + Error **errp); + void bdrv_disable_dirty_bitmap(BdrvDirtyBitmap *bitmap); void bdrv_enable_dirty_bitmap(BdrvDirtyBitmap *bitmap); void bdrv_enable_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap); --=20 2.31.1