From nobody Fri Apr 26 06:49:39 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; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1600188414; cv=pass; d=zohomail.com; s=zohoarc; b=ifkgxU98mmUgL2+cgr76Y7OS22GEu+4RPkYaOzn8o2VE/7tt6xEz7wyRqAGL6rykA1nle0uXpCcH0Z/X/LIQ1UURMJWkw++4dkTNMpGdtuEwbyMXTLaf40quA4xuXyhaBJsbGFx9X7qMpjj1PhkjVqvyK040tt5tdXjj2yeyLPk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600188414; h=Content-Type: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=GTWy7sTjuGz74Kif+Hn35/zOvFhq4MPHkYxT2852UhQ=; b=nQdm/U2m7Fy8/gqyjxeVbNUbpQqpnwAUzPReSZOuLdk+NQ3sIE2rV8GAfp/bN0ixo3u0NT9rNT6mrsrJSeLQ2cIlHlkgq+JZmILolC7o8IW+9ojkCC91GcyGmPt+p//xSpYDbN4hB9grFY7xH2LTkAX8T9WWkMgxsFDaBZ6naUc= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16001884145361014.2105702683801; Tue, 15 Sep 2020 09:46:54 -0700 (PDT) Received: from localhost ([::1]:56332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIE6X-00028l-6v for importer@patchew.org; Tue, 15 Sep 2020 12:46:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4I-0000Cc-Up; Tue, 15 Sep 2020 12:44:34 -0400 Received: from mail-eopbgr70092.outbound.protection.outlook.com ([40.107.7.92]:52206 helo=EUR04-HE1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4G-0007gp-Rx; Tue, 15 Sep 2020 12:44:34 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.17; Tue, 15 Sep 2020 16:44:24 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692%8]) with mapi id 15.20.3370.019; Tue, 15 Sep 2020 16:44:24 +0000 Received: from kvm.sw.ru (185.215.60.75) by AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.5 via Frontend Transport; Tue, 15 Sep 2020 16:44:23 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S3Y+U+RslvonHKxPWrc5gMlaNdAr51pf8/cMvVjPVgdSCKmDWB3vI+H0mRoCbc26c84epiIRdqeySB7JY6VM+9nKDa3Tgy99uYb/yZP+/bW5yfQ3ijW7R2woCoi/VMPr9KN6h4QwyfCIeFoUQHe5bLUXdlGc69nd9j8SYc2DamGbzticRzlBHX5dj7SFgRdCCKk0xo/y+ikAOpaNwLnY6aK1j7ZkKoLv4QQ+2qETJzdhXg12lRU3vBjvCFiKRUrviphZFvdVKktTVImzO93U7bLrXt1U/3DvvoH4uURBHOtB2FDHvIO/Pj8AXQQJ9U0Jjy1VpLxBbBkTaEiCDBE6ZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GTWy7sTjuGz74Kif+Hn35/zOvFhq4MPHkYxT2852UhQ=; b=RPvtXqqdPY7phiXW6QQoZxj3EAiBscD7YeGTkN8LaVE5Xn9QEgSS7pG4OxQpsk1m6OPXB+A/B+rJjyZBKWgCKm5HG9gE2M8O+6+BzJ2DFFbT7bRqy0HmLTmy4BI9KyD9EzcyAJz1P2TbEdZP+taov1jijfP4W5dxFM004Tng6/WNZAgD1ois4YhWGdsvNITNMXwIGltB+7Yg3se99hJ5GxXBKkUHrMXUnWii90GFBuPBm82xpLgmOO6bnylt0bEfiaOV5AnasnArYEkaAgYVqHyDQak1HdyniEykD8RsTe/g9u4U+OLFYuUcq1KgTP5MCan48o1R9IUd7g6KHMMdhQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GTWy7sTjuGz74Kif+Hn35/zOvFhq4MPHkYxT2852UhQ=; b=l49PZVE/hMugfaZA24BwG0nzNM90hzS3+iuQ8yTKo1PezG7K8F6ueWeK91+8mfRIfgUHX8pDixI29Jnea1wTLuDCCJADivao5z00r/MA1Rx8nvHIa2esezJJT2c4RjM8mnkhcIgGcMOIG6wqLY8yDCy+ckgQZ2ve+KyLQAgUGbo= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, crosa@redhat.com, ehabkost@redhat.com, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, eblake@redhat.com Subject: [PATCH v8 1/7] block: return error-code from bdrv_invalidate_cache Date: Tue, 15 Sep 2020 19:44:05 +0300 Message-Id: <20200915164411.20590-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200915164411.20590-1-vsementsov@virtuozzo.com> References: <20200915164411.20590-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.3 X-Originating-IP: [185.215.60.75] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 60365c0e-2964-4c94-573b-08d859969a12 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:489; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RH74FFdGqI87n1evAShi273OpPS6GZ9MCBHsthKPcChWFAXNXclSlB5knfT9X9QZzJiioRZLlY+81dTDwh4kZjLpgxkh/mDbKUOtAKtdrL8IcI/XhboccEsNsqCAkUadhtPAAsnwFr5jdrIosSD67IyxOEJ+iwOimwRy3AxkQtQ7mipUlFgbVdDTQMRPFjnYK9I2oroZTfj5ad64VdyyaC30z/jImaIgxbij8QM4vmy6aInE9GplZxvvNyN2vcNhwjG8dPvRYRBAzBm58AgEohAuBTcIbfLlANpa6zYmSYWXvRUXD0XsMmQHcEHjiXDA1ICmrLZdd6HLtoPGXStguNKGaBklMqN0ZgGXhREf0wZnq9refxNJmRqdma/ZYr6S X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(366004)(396003)(136003)(39840400004)(6916009)(6512007)(2906002)(83380400001)(36756003)(478600001)(1076003)(6486002)(86362001)(2616005)(956004)(8676002)(316002)(186003)(16526019)(5660300002)(66946007)(6666004)(52116002)(66476007)(8936002)(26005)(66556008)(6506007)(4326008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: dpTSTwGwtd3ywRfmnFDdZiML0z39Y9jUaRSv7+tCVVP5f7fEqlsofSismwn2gGgkpd1At84YkpkVY3nWgVA3Pc7lJ3K+3jPLNRDjyd79vTf9nygMOhBkkNAy3C5SIa4xp2+sbBRPlY4zWyWk3XZMrmHqsY8wZOZhRQwoeo53xH9X6k2INavhWzy2aM7dr0RXTR1p/th62qtZPjRaxHzcpX5L2w4APVKp93BXe+wypfRz9+8LO3XzVNetKulgBu3eagtGbc5O7py2Vry5qxg2muZWbMi8IkvuqMAH8BzyLeV7NzDd6+mE851SRt+JP9k1lPgTkhjJ0GME2hhTaXtg0+8X85EjSeiByl5PeukBf6xvWG3I14JIfmvzHqgk+OktFaNmejSZQu6LxqpmGWHsMNjpJzbTKnnt04FIHgg6lngwe37foYWw+uY76on7TV+z0vXGGF8ZXBDS1ZbNzQT5D2rN6uA85izbbcqYKeOnGqu+KtZIUKp+xrqjCLomGgnqFMdNH2nJs5VdWish2a5YQkJ5WrnymhugJ+6r+nThJDrgO0i6RgzpGWsvbHCRXMMe2aMMSbx34IDZhcnUtueKnFagOgtIQpSlElrnODyPKaiwRRPTboNxzHxoyoWRnxbXjwYml+l4CKXFT81ULppIyA== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 60365c0e-2964-4c94-573b-08d859969a12 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2020 16:44:24.1050 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: o/a9T/qs61pD7xx0R4IbxxVgDD30V2vfz/DR9ozk3ZOpust3GJccwS6QVoFnThgAiISLoq3tSzQL9CYT2lBF7RK5JEBzcjlG1I8x61PnVCY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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=40.107.7.92; envelope-from=vsementsov@virtuozzo.com; helo=EUR04-HE1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 12:44:24 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-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.23 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" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" This is the only coroutine wrapper from block.c and block/io.c which doesn't return a value, so let's convert it to the common behavior, to simplify moving to generated coroutine wrappers in a further commit. Also, bdrv_invalidate_cache is a void function, returning error only through **errp parameter, which is considered to be bad practice, as it forces callers to define and propagate local_err variable, so conversion is good anyway. This patch leaves the conversion of .bdrv_co_invalidate_cache() driver callbacks and bdrv_invalidate_cache_all() for another day. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- include/block/block.h | 2 +- block.c | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/include/block/block.h b/include/block/block.h index 6e36154061..8aef849a75 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -460,7 +460,7 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb); int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); =20 /* Invalidate any cached metadata used by image formats */ -void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp); +int bdrv_invalidate_cache(BlockDriverState *bs, Error **errp); void bdrv_invalidate_cache_all(Error **errp); int bdrv_inactivate_all(void); =20 diff --git a/block.c b/block.c index 2ba76b2c36..ccfe1d851b 100644 --- a/block.c +++ b/block.c @@ -5649,8 +5649,8 @@ void bdrv_init_with_whitelist(void) bdrv_init(); } =20 -static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, - Error **errp) +static int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, + Error **errp) { BdrvChild *child, *parent; uint64_t perm, shared_perm; @@ -5659,14 +5659,14 @@ static void coroutine_fn bdrv_co_invalidate_cache(B= lockDriverState *bs, BdrvDirtyBitmap *bm; =20 if (!bs->drv) { - return; + return -ENOMEDIUM; } =20 QLIST_FOREACH(child, &bs->children, next) { bdrv_co_invalidate_cache(child->bs, &local_err); if (local_err) { error_propagate(errp, local_err); - return; + return -EINVAL; } } =20 @@ -5689,7 +5689,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(Blo= ckDriverState *bs, ret =3D bdrv_check_perm(bs, NULL, perm, shared_perm, NULL, NULL, e= rrp); if (ret < 0) { bs->open_flags |=3D BDRV_O_INACTIVE; - return; + return ret; } bdrv_set_perm(bs, perm, shared_perm); =20 @@ -5698,7 +5698,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(Blo= ckDriverState *bs, if (local_err) { bs->open_flags |=3D BDRV_O_INACTIVE; error_propagate(errp, local_err); - return; + return -EINVAL; } } =20 @@ -5710,7 +5710,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(Blo= ckDriverState *bs, if (ret < 0) { bs->open_flags |=3D BDRV_O_INACTIVE; error_setg_errno(errp, -ret, "Could not refresh total sector c= ount"); - return; + return ret; } } =20 @@ -5720,27 +5720,30 @@ static void coroutine_fn bdrv_co_invalidate_cache(B= lockDriverState *bs, if (local_err) { bs->open_flags |=3D BDRV_O_INACTIVE; error_propagate(errp, local_err); - return; + return -EINVAL; } } } + + return 0; } =20 typedef struct InvalidateCacheCo { BlockDriverState *bs; Error **errp; bool done; + int ret; } InvalidateCacheCo; =20 static void coroutine_fn bdrv_invalidate_cache_co_entry(void *opaque) { InvalidateCacheCo *ico =3D opaque; - bdrv_co_invalidate_cache(ico->bs, ico->errp); + ico->ret =3D bdrv_co_invalidate_cache(ico->bs, ico->errp); ico->done =3D true; aio_wait_kick(); } =20 -void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) +int bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) { Coroutine *co; InvalidateCacheCo ico =3D { @@ -5757,22 +5760,23 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Er= ror **errp) bdrv_coroutine_enter(bs, co); BDRV_POLL_WHILE(bs, !ico.done); } + + return ico.ret; } =20 void bdrv_invalidate_cache_all(Error **errp) { BlockDriverState *bs; - Error *local_err =3D NULL; BdrvNextIterator it; =20 for (bs =3D bdrv_first(&it); bs; bs =3D bdrv_next(&it)) { AioContext *aio_context =3D bdrv_get_aio_context(bs); + int ret; =20 aio_context_acquire(aio_context); - bdrv_invalidate_cache(bs, &local_err); + ret =3D bdrv_invalidate_cache(bs, errp); aio_context_release(aio_context); - if (local_err) { - error_propagate(errp, local_err); + if (ret < 0) { bdrv_next_cleanup(&it); return; } --=20 2.21.3 From nobody Fri Apr 26 06:49:39 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; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1600188561; cv=pass; d=zohomail.com; s=zohoarc; b=itxjtzJERvuRLrZWL7VEKYxysjZfdDE0DCAdp5i2qnGVjme2T9aToC+3T/1HBNrYuGSN27lv+kY/MYi14MZWSHX3ZyFCgDwMNO35TEyzPzl7a/oJrRsfBM9wMTnx0obUUBoHHj3mJu9SRQDYzMtqF+wq0eZNfjIxbK2AG/FLCwM= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600188561; h=Content-Type: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=MEvaQ+4moyf7BJ81ZgScnoOoGx05Ry4V4/CfXm04VFg=; b=m+U7eJB5hHeTBx1LiOeTDJ8yO68SzJ9T4v19gapx1fT7/2X2JVC8aA/kelRkSBKXssPoJ5jjjSJzrmpdY7kyJmqAmNVuH866sqIa+EJQhcNBp+Jv34d32XR4NejtrOFucjvEOk6WMrRIrlJoxC5EUFP9tZyphiLnJ1tUWErl8F8= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600188561249529.2941211482796; Tue, 15 Sep 2020 09:49:21 -0700 (PDT) Received: from localhost ([::1]:37162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIE8u-0005wa-23 for importer@patchew.org; Tue, 15 Sep 2020 12:49:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38354) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4P-0000Fw-Af; Tue, 15 Sep 2020 12:44:41 -0400 Received: from mail-eopbgr00099.outbound.protection.outlook.com ([40.107.0.99]:58470 helo=EUR02-AM5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4N-0007hn-FG; Tue, 15 Sep 2020 12:44:41 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.17; Tue, 15 Sep 2020 16:44:25 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692%8]) with mapi id 15.20.3370.019; Tue, 15 Sep 2020 16:44:25 +0000 Received: from kvm.sw.ru (185.215.60.75) by AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.5 via Frontend Transport; Tue, 15 Sep 2020 16:44:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OgN6sIdoP2MSzPkZxg8kgvqQMPWMWe7l4ZoG67y5NKSCh/4u5JstHmD4E4XDs1rnp72UQnY2bxizzd8Vbxd6Bi9zLVWw1vfeOCUt14clZQSIWXncBP4axwvVQ34b+GvX0NZSg+VGYpcUzpsn5nUfFBwk1NpeTRe23mitDUQdBFIsxLJEfjsCa1rwYHDQFSMwHjn0+rxPtkmax0Psen/KnVGxUkfqQ3imMGUFOHJC3YXONMwOVNCuZEajjgB8RQY3tbBrLmVXyGqnYGynJDHLlxlBS+pmqyYaFw5OB3hJ3cNqUXAphYfVfxctzb918b/83ZaUbB5x8w2raf5bDc5U/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MEvaQ+4moyf7BJ81ZgScnoOoGx05Ry4V4/CfXm04VFg=; b=Loi/SxD/6KWVbBiFxJW9BMEDTCEph8R9c4RhR168w5v7lSy2WqSfW0GiV9bYhkK20Us8utm5v9bhJvcAthUqSbu04nZYF//bWofQ/gP8PRkxyu/6q1YnptQ8dI01daNlOnkyMiFRd5S5ItU3SWRASwGNA0mV2/nFzHVcFcMnxZGXU6T7Q1gBEgB3Fyo/uuWgopUbdPgrDkSFfSYn+lehHGRTlRlqVBOWWBQzrd/lP4yxM1lOlYrl6fSh7Fad0kmtJ+xqWKGpMsUHWU9NfyOCIX/IiA0StUULliQ+pczjYtzGca02x4M8Pgg0G1zmz8qTutOjlOGxLNAt2HBF46LncQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MEvaQ+4moyf7BJ81ZgScnoOoGx05Ry4V4/CfXm04VFg=; b=EyCByyNmNOQBqxStHswDCBzAwV3Mw7M43/OWTeOuOOwkO9npYnqGwN213WGwY9PSDuDC6Q/GyvB1BiSYa9Pc9HBMstKaUELn3qC1jISU46BQj0ShNZBPMaXCtqtJOvbVYdaaLVsrY06WIAL2uLJ9fdrezghvINQiooCygnZWy+0= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, crosa@redhat.com, ehabkost@redhat.com, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, eblake@redhat.com Subject: [PATCH v8 2/7] block/io: refactor coroutine wrappers Date: Tue, 15 Sep 2020 19:44:06 +0300 Message-Id: <20200915164411.20590-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200915164411.20590-1-vsementsov@virtuozzo.com> References: <20200915164411.20590-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.3 X-Originating-IP: [185.215.60.75] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: df40fd52-4054-4eb2-05e0-08d859969ac3 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:189; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nTfm8IOrKk228fNaa4EebWzRP9VNHJGOkvAiVrI6eppem/Na9c4rHdwoovJybrol7VaGmLzpXA5PPevFnk2RGW9bu02JQ7Ja4eioPKhjcAJmDjpzADw/oi0guETPMaPIx3nMvt6Z/rW7eSDKLpBcvVZdg5ySoZ/MLvRGOhWPNh5Fu3NLgVZ8SIIVZ+ity5omgJQQGLorUUXazw+O5VRNi8G5Ccfxwp5bWY+LML1MLT1dTmD1fMjrMoULXyf9p3YNJh1gApVxfRnFktTW1FCbutlUMi9tkCJzGFLfOeuRzhY383vXLB++IcZ+B6Fw2r2rpIj9wGo/oIGaz5uHVncyicN78AtUOcDpfyJtg8XpveYojFQeodC7WeohszTFc3yw X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(366004)(396003)(136003)(39840400004)(6916009)(6512007)(2906002)(83380400001)(36756003)(478600001)(1076003)(6486002)(86362001)(2616005)(956004)(8676002)(316002)(186003)(16526019)(5660300002)(66946007)(6666004)(52116002)(66476007)(8936002)(26005)(66556008)(6506007)(4326008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: K5zzFIC2KfOEwT8CWNBt6PvM5wQUtPi1ybzoTpulVsBlYwXE0YH0eH+D/CSKGj8i8DCGkhjolqCHWBTmZrvZ/wRNl4MbVLUZbfcVewnlMXwcesQMtM20oVeF/fgOl1S7KLTLZqPgycIlwJBDF0lea5XqEb5V88Tw9A7TWsZGblUFHt66yqAyx/MAXK5reRiNyhTt5aT7ioGFHaWNwjUcl29G1L4ZtjScHUgzM3n2MrJawLt1J3OPFcK99+0q3Mis16pKbzIGp0FcduMrbfQ3bzZ7R0wgoUC+FXwcSSxbNDqutO3vXnvL3vFAErxPqUkKmkEgWO2tiBqGG+JxKszAd1I/5NVp1vnb3MpD607r/QaN/O2BrW4IPEhRbu/kCa+VSWfnTpXRF9IR2Y2Yc4x3BeHd/dl/6RLGkVWCVWL3lrtuUVI8RbutoYPtq3cP3FLZfYPsBG6/AFDp9W0zrjqlwpjXGeCc81oIY6WsVFb+NnrvLPoYRuNFNPp/t90lcapAMs/8JTM4+3B4rLDZGIRhejtHHurfpL6TXYdGA1MQBd+OyrtyNoLMzzzSkLIBciAAunrxgDHmP3J8tJB6fawBW6VqfKW2y9KUGy3RU5IR0hjkaFT4qI6XwJ3afz6H6xIR4NDa7jk3HLhMBeLTQ1NucA== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: df40fd52-4054-4eb2-05e0-08d859969ac3 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2020 16:44:25.1424 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Y6w7dI5BlL859ruftAkoO9hiCKLWhhOeyuW4x4c1V6L+iPds4ucjY0dE1oKM94sHv5esvolpWc4OHo90Rz7o6vibQ6HscLRCx2LbNyS+Ptg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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=40.107.0.99; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 12:44:37 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-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.23 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" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Most of our coroutine wrappers already follow this convention: We have 'coroutine_fn bdrv_co_()' as the core function, and a wrapper 'bdrv_()' which does parameters packing and call bdrv_run_co(). The only outsiders are the bdrv_prwv_co and bdrv_common_block_status_above wrappers. Let's refactor them to behave as the others, it simplifies further conversion of coroutine wrappers. This patch adds indirection layer, but it will be compensated by further commit, which will drop bdrv_co_prwv together with is_write logic, to keep read and write path separate. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- block/io.c | 60 +++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/block/io.c b/block/io.c index ad3a51ed53..2e2c89ce31 100644 --- a/block/io.c +++ b/block/io.c @@ -933,27 +933,31 @@ typedef struct RwCo { BdrvRequestFlags flags; } RwCo; =20 +static int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, + QEMUIOVector *qiov, bool is_write, + BdrvRequestFlags flags) +{ + if (is_write) { + return bdrv_co_pwritev(child, offset, qiov->size, qiov, flags); + } else { + return bdrv_co_preadv(child, offset, qiov->size, qiov, flags); + } +} + static int coroutine_fn bdrv_rw_co_entry(void *opaque) { RwCo *rwco =3D opaque; =20 - if (!rwco->is_write) { - return bdrv_co_preadv(rwco->child, rwco->offset, - rwco->qiov->size, rwco->qiov, - rwco->flags); - } else { - return bdrv_co_pwritev(rwco->child, rwco->offset, - rwco->qiov->size, rwco->qiov, - rwco->flags); - } + return bdrv_co_prwv(rwco->child, rwco->offset, rwco->qiov, + rwco->is_write, rwco->flags); } =20 /* * Process a vectored synchronous request using coroutines */ -static int bdrv_prwv_co(BdrvChild *child, int64_t offset, - QEMUIOVector *qiov, bool is_write, - BdrvRequestFlags flags) +static int bdrv_prwv(BdrvChild *child, int64_t offset, + QEMUIOVector *qiov, bool is_write, + BdrvRequestFlags flags) { RwCo rwco =3D { .child =3D child, @@ -971,8 +975,7 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, { QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes); =20 - return bdrv_prwv_co(child, offset, &qiov, true, - BDRV_REQ_ZERO_WRITE | flags); + return bdrv_prwv(child, offset, &qiov, true, BDRV_REQ_ZERO_WRITE | fla= gs); } =20 /* @@ -1021,7 +1024,7 @@ int bdrv_preadv(BdrvChild *child, int64_t offset, QEM= UIOVector *qiov) { int ret; =20 - ret =3D bdrv_prwv_co(child, offset, qiov, false, 0); + ret =3D bdrv_prwv(child, offset, qiov, false, 0); if (ret < 0) { return ret; } @@ -1045,7 +1048,7 @@ int bdrv_pwritev(BdrvChild *child, int64_t offset, QE= MUIOVector *qiov) { int ret; =20 - ret =3D bdrv_prwv_co(child, offset, qiov, true, 0); + ret =3D bdrv_prwv(child, offset, qiov, true, 0); if (ret < 0) { return ret; } @@ -2465,14 +2468,15 @@ early_out: return ret; } =20 -static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - bool want_zero, - int64_t offset, - int64_t bytes, - int64_t *pnum, - int64_t *map, - BlockDriverState **file) +static int coroutine_fn +bdrv_co_common_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + BlockDriverState **file) { BlockDriverState *p; int ret =3D 0; @@ -2510,10 +2514,10 @@ static int coroutine_fn bdrv_block_status_above_co_= entry(void *opaque) { BdrvCoBlockStatusData *data =3D opaque; =20 - return bdrv_co_block_status_above(data->bs, data->base, - data->want_zero, - data->offset, data->bytes, - data->pnum, data->map, data->file); + return bdrv_co_common_block_status_above(data->bs, data->base, + data->want_zero, + data->offset, data->bytes, + data->pnum, data->map, data->= file); } =20 /* --=20 2.21.3 From nobody Fri Apr 26 06:49:39 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; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1600188414; cv=pass; d=zohomail.com; s=zohoarc; b=JNBFJwewwd73Eo+XMgoGRD4yJhi/1c4WwTQ6sjY5f4JRiOiR876lbSiml0/65NvkvZlfNPN1431Zf7bJslhrckBXQsNYOcHTd3Xfl1INxgSDHsSxR6UOEdRQmDQUUj7uinolTZQIaibg1q66FhW8+VD1GHd0T6BJg6axaRnVueI= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600188414; h=Content-Type: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=UXTc2vOBQaJj9s8IJxi73NFh1IaXpQ18epG4EPbK03A=; b=hhSvfDste2Vc3t9dQFzXc3ObkD6JbIgYGHVbQSuhLMYFtsvIdcjbh4d0jQuGi4hgnXKpzp/VUXoQLf/1Er3rb3sQRf9BpG3LYG5b2+1qWoCXtc/4uCdKlZwuc/ObGz/uv7sw6GiwoTqi56ICIcRJAn1C51lF0HD80cqH1RONnfk= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160018841461710.765702308245636; Tue, 15 Sep 2020 09:46:54 -0700 (PDT) Received: from localhost ([::1]:56370 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIE6X-00029i-FJ for importer@patchew.org; Tue, 15 Sep 2020 12:46:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38332) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4N-0000Ef-6G; Tue, 15 Sep 2020 12:44:39 -0400 Received: from mail-eopbgr00131.outbound.protection.outlook.com ([40.107.0.131]:27107 helo=EUR02-AM5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4L-0007he-56; Tue, 15 Sep 2020 12:44:38 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.17; Tue, 15 Sep 2020 16:44:26 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692%8]) with mapi id 15.20.3370.019; Tue, 15 Sep 2020 16:44:26 +0000 Received: from kvm.sw.ru (185.215.60.75) by AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.5 via Frontend Transport; Tue, 15 Sep 2020 16:44:25 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d3E3BfpNbSuzA8KOLlkE6FxGYTiBr9oCRO914bW5oRpjXbzLGoxMFYrrZaqAshCSctw8Ac6U9fGFMr/me9ns+HNfZbtP08L/RckYL0tuuI7zGslcuGpTRQzeeU10wFj26b14qxAfY1XYfmnkvl3+q1j7B/5bVWU8Dxm8A+WYJsak54dM1erkHRUm0fYviD2DFTPW4GmpVcyOLqnK4z3XngX6U6idb7Lvi5PIgE2/Qub8WhQW1KV3j1LZ5ktFeZwKrnTTNI2pxNJerle1BWgGl7i/9emPH4mGMAe+WVNNtbAnBrjPwgqeIbIbNeTj1qurFvJ5g50mX7R4hY492qVUAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UXTc2vOBQaJj9s8IJxi73NFh1IaXpQ18epG4EPbK03A=; b=CejFbMnxr/wzknJ/pD0xCPHpX/NESiCevPTkRx+nj2r/kilxFSFPi+EMnsrcQwHDHNos6YWaSADXOi0L+gBsSYi2y5c+slx5sol6qWrKWnK41sxXAEbE8RF805UEykXXrc7vgbE6UWGicEVXVx4lZBUofJPHP1aZfsww2Kytj8qVecVAjb5W3g4o0xgtyj3d4JkxpT1cMnnDjMnv4COD7zfRhSzXM4j8bCY79JFkYR+DZc5Xdp/Y6j99qejJj4rB+T9KMQZXjdQ40WzzFYgaFiGCrm9oQYJMQM6Y40XWdeQHgfU9zXQRNifiRjCmGNhMlhY0bwxzz8bXSFZizoeJ5Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UXTc2vOBQaJj9s8IJxi73NFh1IaXpQ18epG4EPbK03A=; b=bwQBtzEjb5VXd1yAIenb3p0zLquMNQMFJhMgtNB111NczhPAdQAu8MMSEpWPALmFLy6Svz1aNTL5yG4UlG2rCUf6uoVOU6ztAv90Yx+UBGgP05gkw4iCJ4Slzwb3q7zGFGWD2M0/7EHsaSbrPhRaUCoozbpi21CyJpyH2YIpqkk= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, crosa@redhat.com, ehabkost@redhat.com, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, eblake@redhat.com Subject: [PATCH v8 3/7] block: declare some coroutine functions in block/coroutines.h Date: Tue, 15 Sep 2020 19:44:07 +0300 Message-Id: <20200915164411.20590-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200915164411.20590-1-vsementsov@virtuozzo.com> References: <20200915164411.20590-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.3 X-Originating-IP: [185.215.60.75] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 74a19726-ccdf-4d03-e3fb-08d859969b52 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ybnpzw3g8i9hBTr5/bukS6h4MiuqfCv4MTKu8tnWeZu3IlGrL5KmIVajZohXkRg5tmJEcr68BwaToy7jipYBNtf4tfDWgjaovCjtoO5mvi5vIiJygScIa5baHmK2cpThjuna4JpI8yj5MCURUzv+oaDAwjciF1fd9DS5bTM2umMxFKF6YOgJAVvAyCKZG0C+D344SYNBSEqi38li+roDNfTOY7mI/u6kk0xqFOyp1kfa1iHfijJ0x4XgIu45sLcrXWahLBVFW0P8WCrN9nL3h4yOmbJdHpHwDYVrHo32tCiCEKS+/5CaZZQn6IrBPywUmnoooSpcaLFkquUe5KPySBZbY0IrY4qY/HWWV2WU9xgNfpLIKlhXKpHy2zOjlNZ1 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(366004)(396003)(136003)(39840400004)(6916009)(6512007)(2906002)(83380400001)(36756003)(478600001)(1076003)(6486002)(86362001)(2616005)(956004)(8676002)(316002)(186003)(16526019)(5660300002)(66946007)(6666004)(52116002)(66476007)(8936002)(26005)(66556008)(6506007)(4326008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: wfJg3ePy4ZQ3FWpRARRc1NhFRIQ3KbL8N1HLZlnVkHklDDU2OoxEEGeyLqjs8bJiuKbdJM9Z/pj5x7BW6wJhpknWLR1OTVqezQ6Krh5ROplxY+PEKLT4dmn1p54o2AalP5V3eEmID15pLOd6RA0qyOsy9boQ0eacosMQwTdtXnowVJvJ/L8ZY1Xvv/HrMPAS08lodeH6Lt/W7spX73Pvp/qBuyZYZKkCLTbar2bztMyo5PlEJzZOSm5PzpfAT0RlFK9eXCL42Pz+/VGN6PlorKBe4fy6yXjQZUEY89z44BcqrVuGvo1RanEwUPYizQQmAGCD0/iIkD0zcqqCs17bW6RTTl/q+EekVmwJK1e9k+pWb5BWYlEYbDGFVXgsWJkAYl34mssSABqVIrJqLzI+2MeaGqEaUSoGae9lNfx8KgCIoADKdEpRBzBkhnWL7Is55pkQAAMJOPGO0KRE3ekD19EyMtKAI//q+6fn1AnqOUl6hC6rx/Zajs/KBKaAN9UK1J5EJO5QEttxeaSe7qOrQa+feiVLslgiK0nKuQbJSc+/0+08oaqudDuWA9uyLjWPTOEg9mSDRGT9ehGp72DfPThx943sI+eoXZCEK+iCOCuAhrfQBmo5o+Ia7IUl10B/uf/4qPU5ib4zzC26Lm/ikw== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74a19726-ccdf-4d03-e3fb-08d859969b52 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2020 16:44:26.0972 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ndVXZgkq6nv8+EDpdEqyBBB8aemSqFXuLg73JjeGtJKDBu503ZBvJb0jMgvsgnmIAnGpI2as84VJvsha252uN/eZYhC/4SM1JhFsmbw8SQo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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=40.107.0.131; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 12:44:35 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-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.23 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" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" We are going to keep coroutine-wrappers code (structure-packing parameters, BDRV_POLL wrapper functions) in separate auto-generated files. So, we'll need a header with declaration of original _co_ functions, for those which are static now. As well, we'll need declarations for wrapper functions. Do these declarations now, as a preparation step. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- block/coroutines.h | 67 ++++++++++++++++++++++++++++++++++++++++++++++ block.c | 8 +++--- block/io.c | 34 +++++++++++------------ 3 files changed, 88 insertions(+), 21 deletions(-) create mode 100644 block/coroutines.h diff --git a/block/coroutines.h b/block/coroutines.h new file mode 100644 index 0000000000..9ce1730a09 --- /dev/null +++ b/block/coroutines.h @@ -0,0 +1,67 @@ +/* + * Block layer I/O functions + * + * Copyright (c) 2003 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef BLOCK_COROUTINES_INT_H +#define BLOCK_COROUTINES_INT_H + +#include "block/block_int.h" + +int coroutine_fn bdrv_co_check(BlockDriverState *bs, + BdrvCheckResult *res, BdrvCheckMode fix); +int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **er= rp); + +int coroutine_fn +bdrv_co_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, + bool is_write, BdrvRequestFlags flags); +int +bdrv_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, + bool is_write, BdrvRequestFlags flags); + +int coroutine_fn +bdrv_co_common_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + BlockDriverState **file); +int +bdrv_common_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + BlockDriverState **file); + +int coroutine_fn +bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, + bool is_read); +int +bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, + bool is_read); + +#endif /* BLOCK_COROUTINES_INT_H */ diff --git a/block.c b/block.c index ccfe1d851b..ec5a8cbd7b 100644 --- a/block.c +++ b/block.c @@ -48,6 +48,7 @@ #include "qemu/timer.h" #include "qemu/cutils.h" #include "qemu/id.h" +#include "block/coroutines.h" =20 #ifdef CONFIG_BSD #include @@ -4640,8 +4641,8 @@ static void bdrv_delete(BlockDriverState *bs) * free of errors) or -errno when an internal error occurred. The results = of the * check are stored in res. */ -static int coroutine_fn bdrv_co_check(BlockDriverState *bs, - BdrvCheckResult *res, BdrvCheckMode = fix) +int coroutine_fn bdrv_co_check(BlockDriverState *bs, + BdrvCheckResult *res, BdrvCheckMode fix) { if (bs->drv =3D=3D NULL) { return -ENOMEDIUM; @@ -5649,8 +5650,7 @@ void bdrv_init_with_whitelist(void) bdrv_init(); } =20 -static int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, - Error **errp) +int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **er= rp) { BdrvChild *child, *parent; uint64_t perm, shared_perm; diff --git a/block/io.c b/block/io.c index 2e2c89ce31..676c932caf 100644 --- a/block/io.c +++ b/block/io.c @@ -29,6 +29,7 @@ #include "block/blockjob.h" #include "block/blockjob_int.h" #include "block/block_int.h" +#include "block/coroutines.h" #include "qemu/cutils.h" #include "qapi/error.h" #include "qemu/error-report.h" @@ -933,9 +934,9 @@ typedef struct RwCo { BdrvRequestFlags flags; } RwCo; =20 -static int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, - QEMUIOVector *qiov, bool is_write, - BdrvRequestFlags flags) +int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, + QEMUIOVector *qiov, bool is_write, + BdrvRequestFlags flags) { if (is_write) { return bdrv_co_pwritev(child, offset, qiov->size, qiov, flags); @@ -955,9 +956,9 @@ static int coroutine_fn bdrv_rw_co_entry(void *opaque) /* * Process a vectored synchronous request using coroutines */ -static int bdrv_prwv(BdrvChild *child, int64_t offset, - QEMUIOVector *qiov, bool is_write, - BdrvRequestFlags flags) +int bdrv_prwv(BdrvChild *child, int64_t offset, + QEMUIOVector *qiov, bool is_write, + BdrvRequestFlags flags) { RwCo rwco =3D { .child =3D child, @@ -2468,7 +2469,7 @@ early_out: return ret; } =20 -static int coroutine_fn +int coroutine_fn bdrv_co_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, bool want_zero, @@ -2525,12 +2526,12 @@ static int coroutine_fn bdrv_block_status_above_co_= entry(void *opaque) * * See bdrv_co_block_status_above() for details. */ -static int bdrv_common_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - bool want_zero, int64_t offset, - int64_t bytes, int64_t *pnum, - int64_t *map, - BlockDriverState **file) +int bdrv_common_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + bool want_zero, int64_t offset, + int64_t bytes, int64_t *pnum, + int64_t *map, + BlockDriverState **file) { BdrvCoBlockStatusData data =3D { .bs =3D bs, @@ -2646,7 +2647,7 @@ typedef struct BdrvVmstateCo { bool is_read; } BdrvVmstateCo; =20 -static int coroutine_fn +int coroutine_fn bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read) { @@ -2678,9 +2679,8 @@ static int coroutine_fn bdrv_co_rw_vmstate_entry(void= *opaque) return bdrv_co_rw_vmstate(co->bs, co->qiov, co->pos, co->is_read); } =20 -static inline int -bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read) +int bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, + bool is_read) { BdrvVmstateCo data =3D { .bs =3D bs, --=20 2.21.3 From nobody Fri Apr 26 06:49:39 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; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1600188546; cv=pass; d=zohomail.com; s=zohoarc; b=ZVQpDo0n29Pj03ZxxIDElexz0OKtKRfT9BLoCgiwIDQG2kf4UJjfJBGw3is0i/EF8QTll4404juc38Q2nOveU8/vOUlQwt6hg1WnMyL2IML8hfmzv7uxN2g1rHXmhDMrtnAwW1IMK0HeBP+HFb9uCV4JdmYqy62ilZe3YjprOWk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600188546; h=Content-Type: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=unNBHlAe+kvtIF5BIgGOFmx9QPiUaLHMbnEElQNDjHY=; b=DpzQAh9XQ02y6aFwXUQgSAfAQGgcoIFwtBjsaooroDOYsm2io02nmL+nLUJcsJ2EKorvpcTO4+rRoJ13/WmKDyC7YyVO++knIkR6fRu/Ed1wiok6W7LINx6/JWtaQ8+AhbBB6g2g4a8DvboNOi7huLpd1mMsGWbcPsLyT/ulDoY= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160018854599275.36847058452656; Tue, 15 Sep 2020 09:49:05 -0700 (PDT) Received: from localhost ([::1]:36650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIE8e-0005ia-OB for importer@patchew.org; Tue, 15 Sep 2020 12:49:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38360) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4Q-0000Gs-Bi; Tue, 15 Sep 2020 12:44:42 -0400 Received: from mail-eopbgr00131.outbound.protection.outlook.com ([40.107.0.131]:27107 helo=EUR02-AM5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4N-0007he-Mt; Tue, 15 Sep 2020 12:44:42 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.17; Tue, 15 Sep 2020 16:44:27 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692%8]) with mapi id 15.20.3370.019; Tue, 15 Sep 2020 16:44:27 +0000 Received: from kvm.sw.ru (185.215.60.75) by AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.5 via Frontend Transport; Tue, 15 Sep 2020 16:44:26 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PmaW1FBmNCz7Uh/YtghHX1gWW4VojhEhyVxIQYS2FkVU7KjwUsCMdY5oR6vcXeMTu29NYaqe9MiL7sapejuftDBweJQgoqZ3KDQRUu/t53QDuRb4wgQ1KOlyiqh6kXBKz/WaICnpiP1M1Z1eDuodC4UzMWsW6rmpcB3py2w0IRLsx7YqJTjgvStyDZ6axQkjY+qTjYtEQE82ClU5wvl8ZQJZyKzxvtTMKXXyjzz3R72h9/187UzVY6OhadNkZ1GUnXhw/Jx/tuF1H/ygIjWA9WBZ0uplCP9tvFovA/z4aqV+fjNxet3uPab4um1nQpB74CuIeQxHif6P7ErLJgZw+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=unNBHlAe+kvtIF5BIgGOFmx9QPiUaLHMbnEElQNDjHY=; b=Yf007BcSVhmpD4jhwaH8i+oqYxuBxlkzBW02oM35jFHo2EtIPzT34X+FC6X5c6urkhJE+SGQR8diqFhM8ILhJ4KEMJETV+PpFimFdqsViPBI4zhZ/xBIoDJcKo6cL8CamV/bxwHxsrdlPLEmu7No+QHWrWov14ljW4xwVVILjuvF68L+q1ZOjXkGtdNPWOdMpIkJ4Bu9dOa98lrOezoMjpCVgZjJGGs3VrbG3qjoNB6ghta5w++qtu4Li7scii143MELUXypsyRCI7HW2TGSHCiwif8ylxTmsaO79IO5Pz7vhtYX/6OUPAn932Zz6BjnEh5bo9Z80Gki2tqHupl44A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=unNBHlAe+kvtIF5BIgGOFmx9QPiUaLHMbnEElQNDjHY=; b=gwIlLeCt1ts2QOj9nsipzZ0Gu8GwptoD4inBvn8aCf1VzypMvs+6r5eWVYg6aEMZVtdc4qgiO0ki4/wTcO+Uplkl7m0l7oYKzKtVr84lZSk8wpJGlA7cfejJhTD1JtFuUFfBpNBFbW35+aDhKiyYNwnmzMflcNFC8VZSDIwNclI= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, crosa@redhat.com, ehabkost@redhat.com, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, eblake@redhat.com Subject: [PATCH v8 4/7] scripts: add block-coroutine-wrapper.py Date: Tue, 15 Sep 2020 19:44:08 +0300 Message-Id: <20200915164411.20590-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200915164411.20590-1-vsementsov@virtuozzo.com> References: <20200915164411.20590-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.3 X-Originating-IP: [185.215.60.75] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fddb59d2-27b4-44ef-476f-08d859969bf0 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:478; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KoLyegdtXVcskPnBIWN6E3siAXmi3H0nO+TaLirKEC6Ct+FRIqbtmZa+2xvxQtpqkvdAPL3oi/F/ebasq2rYtzk72uDpi3WR8Wd7u4r+cVYK7ZzkyUVnzJzFfrhObo6LsHKFVep/zWjEdNYpS2xyDs2sqaYwsfJX2NOsE9OFkodro2Ju+RFYUlkRqd2JX3pz5EULWlSVOyTvnKZkJ63isMWyNHo73LC7JEEyQifUzjyhHBJl8/fbwUdBk7eXm+2BuwnjRkaC9NXcqDXRddwCD1QVH0DB9/M8Gy8p5/1HZ4T+XSUFxbuhnIjYq2ocrVT//48j9DdCbyQpxR5WO/6FFj6iHUCEqWa4ypeyBJSEltuShNT+PxoNkVzlJ25H4ADvZYHqqYI9eVbKQAkc6VyRHfD8CCYj7UVg33My1Oh4zGNX6Cp/v41oEEAITP7VUaLX2sZq6IhVDrxckXLF2OtfOtBmDYqkeaiZBnxaSUrdexFxQpwGgV/oL9NoY1xgP/Wq X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(366004)(396003)(136003)(39840400004)(6916009)(6512007)(2906002)(83380400001)(36756003)(478600001)(30864003)(1076003)(6486002)(86362001)(2616005)(956004)(8676002)(316002)(186003)(16526019)(5660300002)(66946007)(6666004)(52116002)(66476007)(8936002)(26005)(66556008)(6506007)(4326008)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 8KgAi5M1HGAptQbESIohHDU0ryO2BY9qA5i0cpEX3ycq1ir51Bx/7FUuUNuJgsAEPl27h90qgBp/X8PuijRBSwl0uGlcfv9XNTb9zoM1qBoC1V/C+d5nIbNsXxJwbmNuyPUwECKKdBy1MCQtIA99y6asGV0bDpTIfw3bHKoP7fNQ5hudO9OBUrm3+Jwro8dd9pTHFIUeamANWQgWiXlXM7HaK4V/oOCpJA4uWNGyA1oK5bQfrtrLqOLbXDc9hjRB8JU28A/skimIMZmFz74EfiqDHm3dOxqkP4+InXCCcNakTJR7E24eC49Nb+4PMWeiansSBiZE0Kogh/O3NxumRZAkvRpoOcP/A/9JHRA74Al1BXnx8P42H2GYV0u17oKnVVPyD7KuAtL0G563yDyQ1LQr2+XDtT+l/RJaZCp/hAEp2HOKMs0v1Tc+EOLMZJEDIRJkkQLdkQdX/IaR9SUp0ueAKlUwqd8BqVvKfXspOiukjciuT4VgY3E4MvuHgG1zL2w9rNWOubTJ1A8H1zPmx7lDIh+z7wFqlPR1qsEAC9VH9DVXsgI7XiJaGJJ3mATWycQbcWfKiW+vyWoooRHnHX49crKiBQ0KcC7PoRx+m2OGG3goHUp2aRWax+W9fMuu2CnxUHkA5WJ54hG6tMN0kQ== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: fddb59d2-27b4-44ef-476f-08d859969bf0 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2020 16:44:27.2034 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: RZHzmNQFWn+maKR8gH8T8eL+NwS/+lrxaMmL4XOPNg4DpHXzVFUeUEg5yVLEZN1oREFNXDNS567V1v3hkq7ZOAZHxdMvONAamXC8T67ueuI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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=40.107.0.131; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 12:44:35 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-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.23 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" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" We have a very frequent pattern of creating coroutine from function with several arguments: - create structure to pack parameters - create _entry function to call original function taking parameters from struct - do different magic to handle completion: set ret to NOT_DONE or EINPROGRESS or use separate bool field - fill the struct and create coroutine from _entry function and this struct as a parameter - do coroutine enter and BDRV_POLL_WHILE loop Let's reduce code duplication by generating coroutine wrappers. This patch adds scripts/block-coroutine-wrapper.py together with some friends, which will generate functions with declared prototypes marked by 'generated_co_wrapper' specifier. The usage of new code generation is as follows: 1. define somewhere int coroutine_fn bdrv_co_NAME(...) {...} function 2. declare in some header file int generated_co_wrapper bdrv_NAME(...); function with same list of parameters. (you'll need to include "block/generated-co-wrapper.h" to get the specifier) 3. both declarations should be available through block/coroutines.h header. 4. add header with generated_co_wrapper declaration into COROUTINE_HEADERS list in Makefile Still, no function is now marked, this work is for the following commit. Signed-off-by: Vladimir Sementsov-Ogievskiy Tested-by: Eric Blake --- docs/devel/block-coroutine-wrapper.rst | 54 +++++++ block/block-gen.h | 49 +++++++ include/block/block.h | 10 ++ block/meson.build | 8 ++ scripts/block-coroutine-wrapper.py | 187 +++++++++++++++++++++++++ 5 files changed, 308 insertions(+) create mode 100644 docs/devel/block-coroutine-wrapper.rst create mode 100644 block/block-gen.h create mode 100755 scripts/block-coroutine-wrapper.py diff --git a/docs/devel/block-coroutine-wrapper.rst b/docs/devel/block-coro= utine-wrapper.rst new file mode 100644 index 0000000000..f7050bbc8f --- /dev/null +++ b/docs/devel/block-coroutine-wrapper.rst @@ -0,0 +1,54 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +block-coroutine-wrapper +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +A lot of functions in QEMJ block layer (see ``block/*``) can by called +only in coroutine context. Such functions are normally marked by +coroutine_fn specifier. Still, sometimes we need to call them from +non-coroutine context, for this we need to start a coroutine, run the +needed function from it and wait for coroutine finish in +BDRV_POLL_WHILE() loop. To run a coroutine we need a function with one +void* argument. So for each coroutine_fn function, which needs +non-coroutine interface, we should define a structure to pack the +parameters, define a separate function to unpack the parameters and +call the original function and finally define a new interface function +with same list of arguments as original one, which will pack the +parameters into a struct, create a coroutine, run it and wait in +BDRV_POLL_WHILE() loop. It's boring to create such wrappers by hand, so +we have a script to generate them. + +Usage +=3D=3D=3D=3D=3D + +Assume we have defined ``coroutine_fn`` function +``bdrv_co_foo()`` and need a non-coroutine interface for it, +called ``bdrv_foo()``. In this case the script can help. To +trigger the generation: + +1. You need ``bdrv_foo`` declaration somewhere (for example in + ``block/coroutines.h`` with ``generated_co_wrapper`` mark, + like this: + +.. code-block:: c + + int generated_co_wrapper bdrv_foor(); + +2. You need to feed this declaration to block-coroutine-wrapper script. + For this, add .h (or .c) file with the declaration to + ``input: files(...)`` list of ``block_gen_c`` target declaration in + ``block/meson.build`` + +You are done. On build, coroutine wrappers will be generated in +``/block/block-gen.c``. + +Links +=3D=3D=3D=3D=3D + +1. The script location is ``scripts/block-coroutine-wrapper.py``. + +2. Generic place for private ``generated_co_wrapper`` declarations is + ``block/coroutines.h``, for public declarations: + ``include/block/block.h`` + +3. The core API of generated coroutine wrappers is placed in + (not generated) ``block/block-gen.h`` diff --git a/block/block-gen.h b/block/block-gen.h new file mode 100644 index 0000000000..f80cf4897d --- /dev/null +++ b/block/block-gen.h @@ -0,0 +1,49 @@ +/* + * Block coroutine wrapping core, used by auto-generated block/block-gen.c + * + * Copyright (c) 2003 Fabrice Bellard + * Copyright (c) 2020 Virtuozzo International GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef BLOCK_BLOCK_GEN_H +#define BLOCK_BLOCK_GEN_H + +#include "block/block_int.h" + +/* Base structure for argument packing structures */ +typedef struct BdrvPollCo { + BlockDriverState *bs; + bool in_progress; + int ret; + Coroutine *co; /* Keep pointer here for debugging */ +} BdrvPollCo; + +static inline int bdrv_poll_co(BdrvPollCo *s) +{ + assert(!qemu_in_coroutine()); + + bdrv_coroutine_enter(s->bs, s->co); + BDRV_POLL_WHILE(s->bs, s->in_progress); + + return s->ret; +} + +#endif /* BLOCK_BLOCK_GEN_H */ diff --git a/include/block/block.h b/include/block/block.h index 8aef849a75..a0655b84d6 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -10,6 +10,16 @@ #include "block/blockjob.h" #include "qemu/hbitmap.h" =20 +/* + * generated_co_wrapper + * + * Function specifier, which does nothing but marking functions to be + * generated by scripts/block-coroutine-wrapper.py + * + * Read more in docs/devel/block-coroutine-wrapper.rst + */ +#define generated_co_wrapper + /* block.c */ typedef struct BlockDriver BlockDriver; typedef struct BdrvChild BdrvChild; diff --git a/block/meson.build b/block/meson.build index a3e56b7cd1..88ad73583a 100644 --- a/block/meson.build +++ b/block/meson.build @@ -107,6 +107,14 @@ module_block_h =3D custom_target('module_block.h', command: [module_block_py, '@OUTPUT0@', mod= src]) block_ss.add(module_block_h) =20 +wrapper_py =3D find_program('../scripts/block-coroutine-wrapper.py') +block_gen_c =3D custom_target('block-gen.c', + output: 'block-gen.c', + input: files('../include/block/block.h', + 'coroutines.h'), + command: [wrapper_py, '@OUTPUT@', '@INPUT@']) +block_ss.add(block_gen_c) + block_ss.add(files('stream.c')) =20 softmmu_ss.add(files('qapi-sysemu.c')) diff --git a/scripts/block-coroutine-wrapper.py b/scripts/block-coroutine-w= rapper.py new file mode 100755 index 0000000000..d859c07a5f --- /dev/null +++ b/scripts/block-coroutine-wrapper.py @@ -0,0 +1,187 @@ +#!/usr/bin/env python3 +"""Generate coroutine wrappers for block subsystem. + +The program parses one or several concatenated c files from stdin, +searches for functions with 'generated_co_wrapper' specifier +and generates corresponding wrappers on stdout. + +Usage: block-coroutine-wrapper.py generated-file.c FILE.[ch]... + +Copyright (c) 2020 Virtuozzo International GmbH. + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +""" + +import sys +import re +import subprocess +import json +from typing import Iterator + + +def prettify(code: str) -> str: + """Prettify code using clang-format if available""" + + try: + style =3D json.dumps({ + 'IndentWidth': 4, + 'BraceWrapping': {'AfterFunction': True}, + 'BreakBeforeBraces': 'Custom', + 'SortIncludes': False, + 'MaxEmptyLinesToKeep': 2 + }) + p =3D subprocess.run(['clang-format', f'-style=3D{style}'], check= =3DTrue, + encoding=3D'utf-8', input=3Dcode, + stdout=3Dsubprocess.PIPE) + return p.stdout + except FileNotFoundError: + return code + + +def gen_header(): + copyright =3D re.sub('^.*Copyright', 'Copyright', __doc__, flags=3Dre.= DOTALL) + copyright =3D re.sub('^(?=3D.)', ' * ', copyright.strip(), flags=3Dre.= MULTILINE) + copyright =3D re.sub('^$', ' *', copyright, flags=3Dre.MULTILINE) + return f"""\ +/* + * File is generated by scripts/block-coroutine-wrapper.py + * +{copyright} + */ + +#include "qemu/osdep.h" +#include "block/coroutines.h" +#include "block/block-gen.h" +#include "block/block_int.h"\ +""" + + +class ParamDecl: + param_re =3D re.compile(r'(?P' + r'(?P.*[ *])' + r'(?P[a-z][a-z0-9_]*)' + r')') + + def __init__(self, param_decl: str) -> None: + m =3D self.param_re.match(param_decl.strip()) + if m is None: + raise ValueError(f'Wrong parameter declaration: "{param_decl}"= ') + self.decl =3D m.group('decl') + self.type =3D m.group('type') + self.name =3D m.group('name') + + +class FuncDecl: + def __init__(self, return_type: str, name: str, args: str) -> None: + self.return_type =3D return_type.strip() + self.name =3D name.strip() + self.args =3D [ParamDecl(arg.strip()) for arg in args.split(',')] + + def gen_list(self, format: str) -> str: + return ', '.join(format.format_map(arg.__dict__) for arg in self.a= rgs) + + def gen_block(self, format: str) -> str: + return '\n'.join(format.format_map(arg.__dict__) for arg in self.a= rgs) + + +# Match wrappers declared with a generated_co_wrapper mark +func_decl_re =3D re.compile(r'^int\s*generated_co_wrapper\s*' + r'(?P[a-z][a-z0-9_]*)' + r'\((?P[^)]*)\);$', re.MULTILINE) + + +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')) + + +def snake_to_camel(func_name: str) -> str: + """ + Convert underscore names like 'some_function_name' to camel-case like + 'SomeFunctionName' + """ + words =3D func_name.split('_') + words =3D [w[0].upper() + w[1:] for w in words] + return ''.join(words) + + +def gen_wrapper(func: FuncDecl) -> str: + assert func.name.startswith('bdrv_') + assert not func.name.startswith('bdrv_co_') + assert func.return_type =3D=3D 'int' + assert func.args[0].type in ['BlockDriverState *', 'BdrvChild *'] + + name =3D 'bdrv_co_' + func.name[5:] + bs =3D 'bs' if func.args[0].type =3D=3D 'BlockDriverState *' else 'chi= ld->bs' + struct_name =3D snake_to_camel(name) + + return f"""\ +/* + * Wrappers for {name} + */ + +typedef struct {struct_name} {{ + BdrvPollCo poll_state; +{ func.gen_block(' {decl};') } +}} {struct_name}; + +static void coroutine_fn {name}_entry(void *opaque) +{{ + {struct_name} *s =3D opaque; + + s->poll_state.ret =3D {name}({ func.gen_list('s->{name}') }); + s->poll_state.in_progress =3D false; + + aio_wait_kick(); +}} + +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); + }} +}}""" + + +def gen_wrappers_file(input_code: str) -> str: + res =3D gen_header() + for func in func_decl_iter(input_code): + res +=3D '\n\n\n' + res +=3D gen_wrapper(func) + + return prettify(res) # prettify to wrap long lines + + +if __name__ =3D=3D '__main__': + if len(sys.argv) < 3: + exit(f'Usage: {sys.argv[0]} OUT_FILE.c IN_FILE.[ch]...') + + with open(sys.argv[1], 'w') as f_out: + for fname in sys.argv[2:]: + with open(fname) as f_in: + f_out.write(gen_wrappers_file(f_in.read())) + f_out.write('\n') --=20 2.21.3 From nobody Fri Apr 26 06:49:39 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; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1600188451; cv=pass; d=zohomail.com; s=zohoarc; b=gu86rs8ZNS+edKZfq4+nQt/Hf/gxUGRDnO0J2DVupESuqwHdWgzEstaZRo4FKtTeyFPiS3jGRxFzVaTjbWSOq3K8aupDoUd2W1nxdie/jkrvBJ84vf4YRbWcHQlBXSMQFT3u8Hx115I5atKTStkdG03tBq+51k/l46mRGoQHRSA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600188451; h=Content-Type: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=ybkMlJS9wo8XwsHbWVSe2rUXC0IFtUXHQUnkuc3Mmbs=; b=XXemSNDiYEtNC/vdfotYkNRGXhA19Srrxvp57uuGf+qyneBdCvdUaM26jgvzi7TBQGJltlxv1B+quVpKkhYjWI9Sq2As29T0ZAJsAQZWbHE/9nNo5XVABRovrdka9jJpmvwWk9vnYMB1JibZMBIrBn5jFgeFR+k7JhGD30zruMs= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600188451332484.4402223081386; Tue, 15 Sep 2020 09:47:31 -0700 (PDT) Received: from localhost ([::1]:57598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIE76-0002eT-23 for importer@patchew.org; Tue, 15 Sep 2020 12:47:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38382) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4S-0000IM-Il; Tue, 15 Sep 2020 12:44:44 -0400 Received: from mail-eopbgr00099.outbound.protection.outlook.com ([40.107.0.99]:58470 helo=EUR02-AM5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4P-0007hn-S7; Tue, 15 Sep 2020 12:44:44 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.17; Tue, 15 Sep 2020 16:44:28 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692%8]) with mapi id 15.20.3370.019; Tue, 15 Sep 2020 16:44:28 +0000 Received: from kvm.sw.ru (185.215.60.75) by AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.5 via Frontend Transport; Tue, 15 Sep 2020 16:44:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jMT38+Ov9jmc6q/Qchuf1G5A++akEj7/JYqzE6MmZQ8TKqYaoUBlUisCjyQqB7Y+YMx9DkrUn9Ep1COHjp4zM7vJoIDDS1gSYo9wCiCKUSm9peVsgLHYGffP7WwljAU/JtM9ZUgMHL4Gtbi8IXwK4QGYZlNykKpTI/C9L6Sd9wkF+j/pbOk/VgQpBxGXNxELZGcomn9RzoJgk2lfYZXWve+QSnMURX1m/IoVpSpr1KGmyLsk4Lo/gFxoZczHxc74GQPlViCQwuvFVncBhhbz3zY7bpcHxDUBtBh8YRZnGCbXabw6wyM4h3+8fcNQOE1aTDnh03gTyKdfefzx6FkUew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ybkMlJS9wo8XwsHbWVSe2rUXC0IFtUXHQUnkuc3Mmbs=; b=CEKUEX+nctDNPYBsyxKceB2TX671YxC+vkHLLwAX2WxhMBqZBai6q5WMjB1TwsGAY4CvBT69UdTiUo3/IpE78IKASgvBJhB5FRAY8lBkAyV7Uxcs5oxUzzoEjCh0YyP5JQBt21XSD66iojwcu5yI1H2rs/aTKgDAcE4hdzKjgqHPQn30o9fpvmLkQ3K2ln0DPyhTdok36/KwoWTUByDtfs7QJiZxJxZif39VmPOFLEtEmQ5+NgUihWYcIW+PBaZcuCe+3Sssn7jaIfC9hE371wAhAq9ZY9K9qOosJY/aec1SIO7UxWOBexIr5h3rc/qD3OtiHMUZXzYoTmkahcyUxA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ybkMlJS9wo8XwsHbWVSe2rUXC0IFtUXHQUnkuc3Mmbs=; b=PeXaCiOXWkUNAou/RfhBJTyQH1d3UgJqFDksH3UI/75BnKY2nM0FzMpTNh50niuwsnHUrOgmZmNEvuzAvHGoUrK9VJBsFesP39/HzO9Bhrwl6p3kp4jv/plUgRrENwohpeiFFcTj85wXagOehoNX/UZxSVnHsVtLrntzpzPahNo= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, crosa@redhat.com, ehabkost@redhat.com, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, eblake@redhat.com Subject: [PATCH v8 5/7] block: generate coroutine-wrapper code Date: Tue, 15 Sep 2020 19:44:09 +0300 Message-Id: <20200915164411.20590-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200915164411.20590-1-vsementsov@virtuozzo.com> References: <20200915164411.20590-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.3 X-Originating-IP: [185.215.60.75] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7de0d6c5-4a07-4be7-b4b5-08d859969c90 X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:158; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cRNgYAeFIkOlTnPrf5E/kcBULE2kBnWsRJrLmAjGbBkH9H5F1gRIqMEfqzdznUU0+tIsUi2boyGmn4j/kb/UzcldURm7ytCG9KVM/Ma9DXpqGCulIqBTteJVp1fb5YBtHsAWjh4KGNs2qCJk7QR5BnjARvz7rOPLTWjy3oC120bq+jFHG+HG5HuLinrzAvj6LZf5DyMm/e6oO54X7t5fDDgo96DUBOgPYDOTf+z5P7u9DYm0eHR4oUeJNPcBevw9cEi70qS2l1uEHFOdxUW88HvVUgw6wA6SgTlJDKB6qroyw/et3AgqPztBQZtLpcL8RIYo9wouuR/QRQ/02r+/5E/wz2JEztl+pfRDCsFKypzH3BeRJ/LXboNsk3zHn+EP X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(366004)(396003)(136003)(39840400004)(6916009)(6512007)(2906002)(83380400001)(36756003)(478600001)(30864003)(1076003)(6486002)(86362001)(2616005)(956004)(8676002)(316002)(186003)(16526019)(5660300002)(66946007)(6666004)(52116002)(66476007)(8936002)(26005)(66556008)(6506007)(4326008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 9NC92UAUG2kZcipYKcPVTgV2yhaRKXzUrdIbXJERLihb5H5r/5KvvrqgbYngOcOW8CYtNekltd0dL2ThDVzFCAL1Di//LbSZ9fAh9iWYDQMioWibl2H+fZMU9ISYuhhbO1CSkCyqMPpZt4IsrrrDC2Ij8yGrErExwNL4wd4KO4SLbN52y9zxj3KfU4C9bEg7XI/e0AiBi/9phUOldzivuQaIOwfZjkbpMFfbLuzMLepElebVslxj2ePfwUXN4bTKgeKvSVVJN48kNeDmP2aye2QAOuhcUN9ZtJi1TeRVAFczd2CvVai1z2/iYsiLt2XSk0ZKrwX14S9nZEomc7f32/y+cIqU/ZzQQkF+WrVFLDm5bsgwVeFxWkeCtPsNQXhtSJsP6NgePye/f+h37I1qL5+6L6sRhHeZiLV1Y1XpmxwCTUwoN7Vj4i550uPSbtguXY1uohzDvZceMr9bM2OXvD5+0HhTbXH0kXJkykHKsAWfdSvNHfN1YF2N7neLoyn5Lwz7pxvEq+H8vYdBCTWC7T1xpt9ArDjd90MIYv6fZ16GitsPawJxyodO4EnkGyPcY6JosReyeJtsbJeuOgiJprleUgxWXQ+W4xPUgm+AGGpLizgMNJBiXTybpIOGl/CFZ1godUBQs7c2LdiromutbQ== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7de0d6c5-4a07-4be7-b4b5-08d859969c90 X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2020 16:44:28.1721 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: vqav1WebTYVooN51lRPBIoGs4eQuozy0ttGCL7tlXRj69rLc6Ze6o0px3Ufki18Du7wsSenvHwspD52CVnNwvdOIhRwQ53fmaoWih6KBLbw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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=40.107.0.99; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 12:44:37 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-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.23 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" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Use code generation implemented in previous commit to generated coroutine wrappers in block.c and block/io.c Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/coroutines.h | 6 +- include/block/block.h | 16 ++-- block.c | 73 --------------- block/io.c | 212 ------------------------------------------ 4 files changed, 13 insertions(+), 294 deletions(-) diff --git a/block/coroutines.h b/block/coroutines.h index 9ce1730a09..c62b3a2697 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -34,7 +34,7 @@ int coroutine_fn bdrv_co_invalidate_cache(BlockDriverStat= e *bs, Error **errp); int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, bool is_write, BdrvRequestFlags flags); -int +int generated_co_wrapper bdrv_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, bool is_write, BdrvRequestFlags flags); =20 @@ -47,7 +47,7 @@ bdrv_co_common_block_status_above(BlockDriverState *bs, int64_t *pnum, int64_t *map, BlockDriverState **file); -int +int generated_co_wrapper bdrv_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, bool want_zero, @@ -60,7 +60,7 @@ bdrv_common_block_status_above(BlockDriverState *bs, int coroutine_fn bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read); -int +int generated_co_wrapper bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read); =20 diff --git a/include/block/block.h b/include/block/block.h index a0655b84d6..d8fb02fa2a 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -403,8 +403,9 @@ void bdrv_refresh_filename(BlockDriverState *bs); int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool e= xact, PreallocMode prealloc, BdrvRequestFlags = flags, Error **errp); -int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact, - PreallocMode prealloc, BdrvRequestFlags flags, Error **e= rrp); +int generated_co_wrapper +bdrv_truncate(BdrvChild *child, int64_t offset, bool exact, + PreallocMode prealloc, BdrvRequestFlags flags, Error **errp); =20 int64_t bdrv_nb_sectors(BlockDriverState *bs); int64_t bdrv_getlength(BlockDriverState *bs); @@ -446,7 +447,8 @@ typedef enum { BDRV_FIX_ERRORS =3D 2, } BdrvCheckMode; =20 -int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode f= ix); +int generated_co_wrapper bdrv_check(BlockDriverState *bs, BdrvCheckResult = *res, + BdrvCheckMode fix); =20 /* The units of offset and total_work_size may be chosen arbitrarily by the * block driver; total_work_size may change during the course of the amend= ment @@ -470,12 +472,13 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb); int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); =20 /* Invalidate any cached metadata used by image formats */ -int bdrv_invalidate_cache(BlockDriverState *bs, Error **errp); +int generated_co_wrapper bdrv_invalidate_cache(BlockDriverState *bs, + Error **errp); void bdrv_invalidate_cache_all(Error **errp); int bdrv_inactivate_all(void); =20 /* Ensure contents are flushed to disk. */ -int bdrv_flush(BlockDriverState *bs); +int generated_co_wrapper bdrv_flush(BlockDriverState *bs); int coroutine_fn bdrv_co_flush(BlockDriverState *bs); int bdrv_flush_all(void); void bdrv_close_all(void); @@ -490,7 +493,8 @@ void bdrv_drain_all(void); AIO_WAIT_WHILE(bdrv_get_aio_context(bs_), \ cond); }) =20 -int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); +int generated_co_wrapper bdrv_pdiscard(BdrvChild *child, int64_t offset, + int64_t bytes); int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs); diff --git a/block.c b/block.c index ec5a8cbd7b..d49d591917 100644 --- a/block.c +++ b/block.c @@ -4655,43 +4655,6 @@ int coroutine_fn bdrv_co_check(BlockDriverState *bs, return bs->drv->bdrv_co_check(bs, res, fix); } =20 -typedef struct CheckCo { - BlockDriverState *bs; - BdrvCheckResult *res; - BdrvCheckMode fix; - int ret; -} CheckCo; - -static void coroutine_fn bdrv_check_co_entry(void *opaque) -{ - CheckCo *cco =3D opaque; - cco->ret =3D bdrv_co_check(cco->bs, cco->res, cco->fix); - aio_wait_kick(); -} - -int bdrv_check(BlockDriverState *bs, - BdrvCheckResult *res, BdrvCheckMode fix) -{ - Coroutine *co; - CheckCo cco =3D { - .bs =3D bs, - .res =3D res, - .ret =3D -EINPROGRESS, - .fix =3D fix, - }; - - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - bdrv_check_co_entry(&cco); - } else { - co =3D qemu_coroutine_create(bdrv_check_co_entry, &cco); - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, cco.ret =3D=3D -EINPROGRESS); - } - - return cco.ret; -} - /* * Return values: * 0 - success @@ -5728,42 +5691,6 @@ int coroutine_fn bdrv_co_invalidate_cache(BlockDrive= rState *bs, Error **errp) return 0; } =20 -typedef struct InvalidateCacheCo { - BlockDriverState *bs; - Error **errp; - bool done; - int ret; -} InvalidateCacheCo; - -static void coroutine_fn bdrv_invalidate_cache_co_entry(void *opaque) -{ - InvalidateCacheCo *ico =3D opaque; - ico->ret =3D bdrv_co_invalidate_cache(ico->bs, ico->errp); - ico->done =3D true; - aio_wait_kick(); -} - -int bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) -{ - Coroutine *co; - InvalidateCacheCo ico =3D { - .bs =3D bs, - .done =3D false, - .errp =3D errp - }; - - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - bdrv_invalidate_cache_co_entry(&ico); - } else { - co =3D qemu_coroutine_create(bdrv_invalidate_cache_co_entry, &ico); - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, !ico.done); - } - - return ico.ret; -} - void bdrv_invalidate_cache_all(Error **errp) { BlockDriverState *bs; diff --git a/block/io.c b/block/io.c index 676c932caf..5270d68d72 100644 --- a/block/io.c +++ b/block/io.c @@ -890,50 +890,6 @@ static int bdrv_check_byte_request(BlockDriverState *b= s, int64_t offset, return 0; } =20 -typedef int coroutine_fn BdrvRequestEntry(void *opaque); -typedef struct BdrvRunCo { - BdrvRequestEntry *entry; - void *opaque; - int ret; - bool done; - Coroutine *co; /* Coroutine, running bdrv_run_co_entry, for debugging = */ -} BdrvRunCo; - -static void coroutine_fn bdrv_run_co_entry(void *opaque) -{ - BdrvRunCo *arg =3D opaque; - - arg->ret =3D arg->entry(arg->opaque); - arg->done =3D true; - aio_wait_kick(); -} - -static int bdrv_run_co(BlockDriverState *bs, BdrvRequestEntry *entry, - void *opaque) -{ - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - return entry(opaque); - } else { - BdrvRunCo s =3D { .entry =3D entry, .opaque =3D opaque }; - - s.co =3D qemu_coroutine_create(bdrv_run_co_entry, &s); - bdrv_coroutine_enter(bs, s.co); - - BDRV_POLL_WHILE(bs, !s.done); - - return s.ret; - } -} - -typedef struct RwCo { - BdrvChild *child; - int64_t offset; - QEMUIOVector *qiov; - bool is_write; - BdrvRequestFlags flags; -} RwCo; - int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, bool is_write, BdrvRequestFlags flags) @@ -945,32 +901,6 @@ int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_= t offset, } } =20 -static int coroutine_fn bdrv_rw_co_entry(void *opaque) -{ - RwCo *rwco =3D opaque; - - return bdrv_co_prwv(rwco->child, rwco->offset, rwco->qiov, - rwco->is_write, rwco->flags); -} - -/* - * Process a vectored synchronous request using coroutines - */ -int bdrv_prwv(BdrvChild *child, int64_t offset, - QEMUIOVector *qiov, bool is_write, - BdrvRequestFlags flags) -{ - RwCo rwco =3D { - .child =3D child, - .offset =3D offset, - .qiov =3D qiov, - .is_write =3D is_write, - .flags =3D flags, - }; - - return bdrv_run_co(child->bs, bdrv_rw_co_entry, &rwco); -} - int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, BdrvRequestFlags flags) { @@ -2247,18 +2177,6 @@ int bdrv_flush_all(void) return result; } =20 - -typedef struct BdrvCoBlockStatusData { - BlockDriverState *bs; - BlockDriverState *base; - bool want_zero; - int64_t offset; - int64_t bytes; - int64_t *pnum; - int64_t *map; - BlockDriverState **file; -} BdrvCoBlockStatusData; - int coroutine_fn bdrv_co_block_status_from_file(BlockDriverState *bs, bool want_zero, int64_t offset, @@ -2510,43 +2428,6 @@ bdrv_co_common_block_status_above(BlockDriverState *= bs, return ret; } =20 -/* Coroutine wrapper for bdrv_block_status_above() */ -static int coroutine_fn bdrv_block_status_above_co_entry(void *opaque) -{ - BdrvCoBlockStatusData *data =3D opaque; - - return bdrv_co_common_block_status_above(data->bs, data->base, - data->want_zero, - data->offset, data->bytes, - data->pnum, data->map, data->= file); -} - -/* - * Synchronous wrapper around bdrv_co_block_status_above(). - * - * See bdrv_co_block_status_above() for details. - */ -int bdrv_common_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - bool want_zero, int64_t offset, - int64_t bytes, int64_t *pnum, - int64_t *map, - BlockDriverState **file) -{ - BdrvCoBlockStatusData data =3D { - .bs =3D bs, - .base =3D base, - .want_zero =3D want_zero, - .offset =3D offset, - .bytes =3D bytes, - .pnum =3D pnum, - .map =3D map, - .file =3D file, - }; - - return bdrv_run_co(bs, bdrv_block_status_above_co_entry, &data); -} - int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file) @@ -2640,13 +2521,6 @@ int bdrv_is_allocated_above(BlockDriverState *top, return 0; } =20 -typedef struct BdrvVmstateCo { - BlockDriverState *bs; - QEMUIOVector *qiov; - int64_t pos; - bool is_read; -} BdrvVmstateCo; - int coroutine_fn bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read) @@ -2672,26 +2546,6 @@ bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVecto= r *qiov, int64_t pos, return ret; } =20 -static int coroutine_fn bdrv_co_rw_vmstate_entry(void *opaque) -{ - BdrvVmstateCo *co =3D opaque; - - return bdrv_co_rw_vmstate(co->bs, co->qiov, co->pos, co->is_read); -} - -int bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read) -{ - BdrvVmstateCo data =3D { - .bs =3D bs, - .qiov =3D qiov, - .pos =3D pos, - .is_read =3D is_read, - }; - - return bdrv_run_co(bs, bdrv_co_rw_vmstate_entry, &data); -} - int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, int64_t pos, int size) { @@ -2767,11 +2621,6 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb) /**************************************************************/ /* Coroutine block device emulation */ =20 -static int coroutine_fn bdrv_flush_co_entry(void *opaque) -{ - return bdrv_co_flush(opaque); -} - int coroutine_fn bdrv_co_flush(BlockDriverState *bs) { int current_gen; @@ -2884,24 +2733,6 @@ early_exit: return ret; } =20 -int bdrv_flush(BlockDriverState *bs) -{ - return bdrv_run_co(bs, bdrv_flush_co_entry, bs); -} - -typedef struct DiscardCo { - BdrvChild *child; - int64_t offset; - int64_t bytes; -} DiscardCo; - -static int coroutine_fn bdrv_pdiscard_co_entry(void *opaque) -{ - DiscardCo *rwco =3D opaque; - - return bdrv_co_pdiscard(rwco->child, rwco->offset, rwco->bytes); -} - int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes) { @@ -3016,17 +2847,6 @@ out: return ret; } =20 -int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes) -{ - DiscardCo rwco =3D { - .child =3D child, - .offset =3D offset, - .bytes =3D bytes, - }; - - return bdrv_run_co(child->bs, bdrv_pdiscard_co_entry, &rwco); -} - int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf) { BlockDriver *drv =3D bs->drv; @@ -3424,35 +3244,3 @@ out: =20 return ret; } - -typedef struct TruncateCo { - BdrvChild *child; - int64_t offset; - bool exact; - PreallocMode prealloc; - BdrvRequestFlags flags; - Error **errp; -} TruncateCo; - -static int coroutine_fn bdrv_truncate_co_entry(void *opaque) -{ - TruncateCo *tco =3D opaque; - - return bdrv_co_truncate(tco->child, tco->offset, tco->exact, - tco->prealloc, tco->flags, tco->errp); -} - -int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact, - PreallocMode prealloc, BdrvRequestFlags flags, Error **e= rrp) -{ - TruncateCo tco =3D { - .child =3D child, - .offset =3D offset, - .exact =3D exact, - .prealloc =3D prealloc, - .flags =3D flags, - .errp =3D errp, - }; - - return bdrv_run_co(child->bs, bdrv_truncate_co_entry, &tco); -} --=20 2.21.3 From nobody Fri Apr 26 06:49:39 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; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1600188703; cv=pass; d=zohomail.com; s=zohoarc; b=OwGiuUbbJoZwIV4rHTReZ4b/zs4sVUPre6OjjQ0oRhMxNUvbBobtwpxjLq5kOffnj4oExFpmuHSNwiLozc/csf6OQ0tcvbBsVib6ggGnF6f073hLBK/XxPABv/5N4Hlj6SWYz+p+48grt3SjN8/4aTtUxCRhJCtnIpygVCnB0UY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600188703; h=Content-Type: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=m3Mfjs6F23/Apaan2wyhFR9NH3ancKVhc8mxe6uHokQ=; b=QDu1/Yb6jjYyFZ4r88mfQlFhTk5llne8iohg5ikMLmRfmhEwmK9RMcWVtO5xjgGFbQ32/SVhIj7hZwY4bWLAKUMUSol1SID1H54ahhiPh5oYuv3C1KHSZHSxWvujb1qxfUuh7QdtXGJFKwzrAIPq6pM9xKATVd7az+4cKL+/Ki4= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600188703369808.789603706817; Tue, 15 Sep 2020 09:51:43 -0700 (PDT) Received: from localhost ([::1]:45962 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIEBB-0001Dx-Ru for importer@patchew.org; Tue, 15 Sep 2020 12:51:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4U-0000LR-HD; Tue, 15 Sep 2020 12:44:46 -0400 Received: from mail-eopbgr00131.outbound.protection.outlook.com ([40.107.0.131]:27107 helo=EUR02-AM5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4Q-0007he-T7; Tue, 15 Sep 2020 12:44:46 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.17; Tue, 15 Sep 2020 16:44:29 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692%8]) with mapi id 15.20.3370.019; Tue, 15 Sep 2020 16:44:29 +0000 Received: from kvm.sw.ru (185.215.60.75) by AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.5 via Frontend Transport; Tue, 15 Sep 2020 16:44:28 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k2UdzEKdil8twx5D4EGQKa3yjoVDZhEvg3EWBsnwiuodFxWulmG3VJRceLlK2zcgUecS0ZrXIRREXLjuBSkRzimq3iymgaiJzNS+fVOizIxW5mmRHz7dPxxUTM1vWEnOWOdXp0PrweLMMJg1CHLuT8J1AUes3ViYg4d4OVFayr1KQ8QDLEap/pE85jqW7Eo3ANHUHVPeUqrLWYbslse3kuYQ4QRo1ZtkxjZVXAhCItwTmzQYETNy2dUzDJc+gtN2Ke63P2wJ3iZHlCmRGru4yRoH7puVU9Nkc4TihIeAMesbZzJn7zVei98oHNM7CDvdIukir/1EA5vPQ+EJ0aSDmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m3Mfjs6F23/Apaan2wyhFR9NH3ancKVhc8mxe6uHokQ=; b=Rt8w+GUD/oqtKzX88VyUXzcYNySoD95MB4sW3xeG9ROAO0WG2Rf1dcfbKlZ6RMPab/AGwNS4AciPTJyX6d0noXV23PQti34OdiY8gwxpEs0qm68zUTW36SAH9DJuKaDMS3ipg/x6go1SNsaYpNyJkwdn+tnL6rePPoaxEfadMz8EOQW4NFTL0EH8X50sdOlO59WhDGwCwJXWXcIImyOzAhXYOAkYJStIAe8472/xuq0BooDGtHRBFNqCajzpgA9yBxzw1P08V+ORkDlBptNdCkwIdGBFPyw5NAoncaij6UPQZ+FbNgwkCukMPV5sfjo/e+8XWP0qnt+dfSO1mmbAFA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m3Mfjs6F23/Apaan2wyhFR9NH3ancKVhc8mxe6uHokQ=; b=S6hJvgfIh//SE3IB4tO1lBaSod5WQ3jlyUsDzn+FogiqR57Y7fUyK+1CRMijN85tlg+Se62ZZyzjWcijirQW4LbydtoWZNFszx/kttDT0LFgrTSV9l39nNe2+wkzm07oXZf0MEAnAFhKg4gtxy0kZ2AWXn5we0Y417Y6V7qw6OY= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, crosa@redhat.com, ehabkost@redhat.com, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, eblake@redhat.com Subject: [PATCH v8 6/7] block: drop bdrv_prwv Date: Tue, 15 Sep 2020 19:44:10 +0300 Message-Id: <20200915164411.20590-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200915164411.20590-1-vsementsov@virtuozzo.com> References: <20200915164411.20590-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.3 X-Originating-IP: [185.215.60.75] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ff160562-6e63-49a4-4f5b-08d859969d2f X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1051; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V0q4UdXYE3oPvibPknG4ZNNDVFv9esasRcKtsNMoUPt3SIw1bl+j8Z5T+aw6IvmwmVVR1Wkh7SGCUdiav4knXRJUb1w5fgD1qrG2MSbAjroXS0V2HtH9vZ3wws5fM85UB/v6ha7Tr3NE+x1Wf+0ZcOZJ+QRTHeWTyWTwdRsugArZEYV6HfkA86k5TJeRMh3sd8OloXGTwIyCPe5YjT/myXROZpHr/WmnO7brTgB9d6Qk1QZc3i8dshU7Ke2VMqeqJ7PGIGfDrH9aRyRExAfB5My1qlRepN2SNFVv4+MD3aFinbPIxwy4jb3eyKTd72kqzfTl8wrdDi2sQAfi85JI/soqC7wUZoCqjRMOEm8H54E= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(366004)(396003)(136003)(39840400004)(6916009)(6512007)(2906002)(83380400001)(36756003)(478600001)(1076003)(6486002)(86362001)(2616005)(956004)(8676002)(316002)(186003)(16526019)(5660300002)(66946007)(6666004)(52116002)(66476007)(8936002)(26005)(66556008)(6506007)(4326008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 9dO+RLJDlVlEpCBco0edIt9QyCiWehCJFPgLiD1dxXXKwfwYuvhAnLQgaZTT11WAUsPqNIDj4xFrwHk7NHuZeJ7hc7jkFUc4mZya3xQuxAil1pPm1oLAKePDPh5GyvRoT4pRj3VvnMHmIsEC5gP+zW+CdChDnPAknlq8k5dkVP5takpd3bmFMRoxiNrMqKIxAgwc3qOwv9m8CQ87IlaiZEyIGfqwgoxpvr6Q8EdqXa3QBxFvYoqHfpq/BCctF0vbG/Kyuxhy5m8ipykkW4W6NsGTOtyXU7LeN9GSCz4i9uio+Hvf9j4eE7pHuyZT3KEW3wGuR/E4c0Qm7OA3SwDLcw5X9pDiGOp/IEvJAgEXswTJtMV43tXatV3uqPOM78I4jh6mA5smDNIY+BBK2ROj92lT7PKlW09eyMaorDiHh4c3Z13kgRPl1rDy2KEsl12fyS2wKucRUfiOsSMWKA+Klbntquxm23tuHMjPxGRrE1t1x2aCTz5+AXfTCp43L80v5PTfjqdOqITmlpCwspsjvVYEGR+DtD1wL3o7ZHN11DXzAxlxcfGxTCSyFMdK5O7KjRgfpnRWIZ5hooKRyqkbSYny+SnlBQAGIqCUzM7S0nRtfcVDugSZ3cVNpDuom9rgcFoOHuDVBfKuUV/pHy+x2Q== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff160562-6e63-49a4-4f5b-08d859969d2f X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2020 16:44:29.1707 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: S63iejeq6VLKDea5kKjYbs6nCiPeZ21dMh7bIh85fCckRmRHFBZk6I1VDyE3xl3yQYwpphnUwabVIfdduWNl0nImCBR8T59xgifw0E4gpXA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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=40.107.0.131; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 12:44:35 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-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.23 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" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Now that we are not maintaining boilerplate code for coroutine wrappers, there is no more sense in keeping the extra indirection layer of bdrv_prwv(). Let's drop it and instead generate pure bdrv_preadv() and bdrv_pwritev(). Currently, bdrv_pwritev() and bdrv_preadv() are returning bytes on success, auto generated functions will instead return zero, as their _co_ prototype. Still, it's simple to make the conversion safe: the only external user of bdrv_pwritev() is test-bdrv-drain, and it is comfortable enough with bdrv_co_pwritev() instead. So prototypes are moved to local block/coroutines.h. Next, the only internal use is bdrv_pread() and bdrv_pwrite(), which are modified to return bytes on success. Of course, it would be great to convert bdrv_pread() and bdrv_pwrite() to return 0 on success. But this requires audit (and probably conversion) of all their users, let's leave it for another day refactoring. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Stefan Hajnoczi --- block/coroutines.h | 10 ++++----- include/block/block.h | 2 -- block/io.c | 49 ++++++++--------------------------------- tests/test-bdrv-drain.c | 2 +- 4 files changed, 15 insertions(+), 48 deletions(-) diff --git a/block/coroutines.h b/block/coroutines.h index c62b3a2697..6c63a819c9 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -31,12 +31,12 @@ int coroutine_fn bdrv_co_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix); int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **er= rp); =20 -int coroutine_fn -bdrv_co_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, - bool is_write, BdrvRequestFlags flags); int generated_co_wrapper -bdrv_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, - bool is_write, BdrvRequestFlags flags); +bdrv_preadv(BdrvChild *child, int64_t offset, unsigned int bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags); +int generated_co_wrapper +bdrv_pwritev(BdrvChild *child, int64_t offset, unsigned int bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags); =20 int coroutine_fn bdrv_co_common_block_status_above(BlockDriverState *bs, diff --git a/include/block/block.h b/include/block/block.h index d8fb02fa2a..b8b4c177de 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -383,9 +383,7 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, BdrvRequestFlags flags); int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags); int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes); -int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov); int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int byt= es); -int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov); int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, const void *buf, int count); /* diff --git a/block/io.c b/block/io.c index 5270d68d72..68d7d9cf80 100644 --- a/block/io.c +++ b/block/io.c @@ -890,23 +890,11 @@ static int bdrv_check_byte_request(BlockDriverState *= bs, int64_t offset, return 0; } =20 -int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, - QEMUIOVector *qiov, bool is_write, - BdrvRequestFlags flags) -{ - if (is_write) { - return bdrv_co_pwritev(child, offset, qiov->size, qiov, flags); - } else { - return bdrv_co_preadv(child, offset, qiov->size, qiov, flags); - } -} - int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, BdrvRequestFlags flags) { - QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes); - - return bdrv_prwv(child, offset, &qiov, true, BDRV_REQ_ZERO_WRITE | fla= gs); + return bdrv_pwritev(child, offset, bytes, NULL, + BDRV_REQ_ZERO_WRITE | flags); } =20 /* @@ -950,41 +938,19 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags= flags) } } =20 -/* return < 0 if error. See bdrv_pwrite() for the return codes */ -int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) -{ - int ret; - - ret =3D bdrv_prwv(child, offset, qiov, false, 0); - if (ret < 0) { - return ret; - } - - return qiov->size; -} - /* See bdrv_pwrite() for the return codes */ int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes) { + int ret; QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); =20 if (bytes < 0) { return -EINVAL; } =20 - return bdrv_preadv(child, offset, &qiov); -} - -int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) -{ - int ret; + ret =3D bdrv_preadv(child, offset, bytes, &qiov, 0); =20 - ret =3D bdrv_prwv(child, offset, qiov, true, 0); - if (ret < 0) { - return ret; - } - - return qiov->size; + return ret < 0 ? ret : bytes; } =20 /* Return no. of bytes on success or < 0 on error. Important errors are: @@ -995,13 +961,16 @@ int bdrv_pwritev(BdrvChild *child, int64_t offset, QE= MUIOVector *qiov) */ int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int byt= es) { + int ret; QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); =20 if (bytes < 0) { return -EINVAL; } =20 - return bdrv_pwritev(child, offset, &qiov); + ret =3D bdrv_pwritev(child, offset, bytes, &qiov, 0); + + return ret < 0 ? ret : bytes; } =20 /* diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 1107271840..1595bbc92e 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -1872,7 +1872,7 @@ static int coroutine_fn bdrv_replace_test_co_preadv(B= lockDriverState *bs, } s->io_co =3D NULL; =20 - ret =3D bdrv_preadv(bs->backing, offset, qiov); + ret =3D bdrv_co_preadv(bs->backing, offset, bytes, qiov, 0); s->has_read =3D true; =20 /* Wake up drain_co if it runs */ --=20 2.21.3 From nobody Fri Apr 26 06:49:39 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; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=quarantine dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1600188691; cv=pass; d=zohomail.com; s=zohoarc; b=L4E2sOikEQ4AxGCOH0nf+4qjDAetj4sFZp+kjjADTdDmXpmQ+DqzSCA94LaRlyohldmNxlYaVlYVhOy9jHSrueT6ua+0ZpksVrnHS8+lmmNJqIa0ts8WIYU/KaQqelYXBQ0+9ZhbeggztLLJ64Yk2QfiZbhBDH0BSiVtaGCOld4= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600188691; h=Content-Type: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=OSnVLhzq5WN5xeH2xNaNt7J24Fm2sh2hE7kfHigSJVA=; b=lucHVvyNftRVzthAXisGtNv1rmMKl+Ye18rNKJc68yroK2dlKZ9zKfoaQE8vXJ57jn5+3n0ZXrsIx9YItP3lYAZ5LdldBp4RRb/JSQGO5hfKHLyAtmkEXtmN6kROdyfJZi5c3iS2c96fWW44GD1PJrj3m0ziK6cwRE8gzji9j3U= ARC-Authentication-Results: i=2; 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; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=quarantine dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1600188691817634.7831447294003; Tue, 15 Sep 2020 09:51:31 -0700 (PDT) Received: from localhost ([::1]:45168 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kIEB0-0000uB-H8 for importer@patchew.org; Tue, 15 Sep 2020 12:51:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4U-0000LS-VT; Tue, 15 Sep 2020 12:44:47 -0400 Received: from mail-eopbgr00099.outbound.protection.outlook.com ([40.107.0.99]:58470 helo=EUR02-AM5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kIE4T-0007hn-2v; Tue, 15 Sep 2020 12:44:46 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM5PR0801MB1652.eurprd08.prod.outlook.com (2603:10a6:203:3c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3370.17; Tue, 15 Sep 2020 16:44:30 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::b179:9641:7589:d692%8]) with mapi id 15.20.3370.019; Tue, 15 Sep 2020 16:44:30 +0000 Received: from kvm.sw.ru (185.215.60.75) by AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.5 via Frontend Transport; Tue, 15 Sep 2020 16:44:29 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H1brkcUFG2JLKglFrOWPHos0R+V8T0KGmIgeG+vqM4Ok5Jsa1L1YK7Kx/3CLcFraboumVR1/YUcU6PSbjjjCG9WA37rhWxC1wy5ZFsLWZm4tMOQfLu18/F61QOdw5bSKeqmfuqsh6hchoM0GgmmqiLKFxjn+STq55aAMZY2+zGyYqD6/yuksSLPXvMMtp77FVxKdzfcVOacuFyjCUuroJ5S2/Bw5Nev6hde0FSlGX8ey+CP5dE9MlgJgPA7p/EUK01ZxP0bM+DtUShVTQVOT0C6hN0EheZUeJ/+THIVKhyREd/aQcA6HY8vu8IUgL/SA08niLSw5TAQrmPX3iU4JAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OSnVLhzq5WN5xeH2xNaNt7J24Fm2sh2hE7kfHigSJVA=; b=PgAOj17+MDZ/W8bXX4vcmTDlKRzJR2RtHRJAdxvDzEUBpw4v6VAToIQmDfv/xzXUgTLCRaK7L3iAE22smZG3gPCp1Qug79rjdH6eEo99jnh0PZGbaV0ZY18wM6Zst/xpQ5w8pWqqpv08zMbFBmCC6VQ4imybDo5YPP14Xa9E9TAnSAU92a5fg4RDakgUjcfgDkQNkFtWpqlZRnsYbnJtSe0dzaGNTNNhPi7XI07w7iRRpI711JI43u8G605l3AcEDI1u/ppp97SXFC43Y6RMZA/PpmDmAbE5o6nQ+N+oVQb8pZd7sKwu9VypiIQJQdpB19uxsM5wUnH77Is/t+5XQg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=virtuozzo.com; dmarc=pass action=none header.from=virtuozzo.com; dkim=pass header.d=virtuozzo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OSnVLhzq5WN5xeH2xNaNt7J24Fm2sh2hE7kfHigSJVA=; b=I1+cFFpaZ0V3S0s0DGcBhaHh+Y0teSr+BjJ9OYl7NlxQv5ErFWVY9X0oMxoGZAqf0wcpUfrzGctkMMIs5ekzpEd35vEQDBwk3p/2wXkiXto/us8fB5S9NiptXPVFTqWVO0EaPLdzYNrjd19hpe/pHR6YTX/nyqg/tijdnDHhESM= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Cc: qemu-devel@nongnu.org, crosa@redhat.com, ehabkost@redhat.com, fam@euphon.net, stefanha@redhat.com, mreitz@redhat.com, kwolf@redhat.com, vsementsov@virtuozzo.com, den@openvz.org, eblake@redhat.com Subject: [PATCH v8 7/7] block/io: refactor save/load vmstate Date: Tue, 15 Sep 2020 19:44:11 +0300 Message-Id: <20200915164411.20590-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20200915164411.20590-1-vsementsov@virtuozzo.com> References: <20200915164411.20590-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM0PR07CA0025.eurprd07.prod.outlook.com (2603:10a6:208:ac::38) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.3 X-Originating-IP: [185.215.60.75] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 08bfc6d1-271e-49da-77d8-08d859969dba X-MS-TrafficTypeDiagnostic: AM5PR0801MB1652: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:153; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ECLOZ5IOthkpuErqzL/g/K+srYCm490p7iOBF87O0denR31IMypD3TvYcxWon5OpOhzEdS8PcZ+/GwiBhijDN4RmNSR7IYZrYEtuKl/EeT6rv/26zqjWpqvi9O8/AhySTOL+jwgBl9OPthoLAcRFXA9H9Nf4WRlWMZGufwtpsMnd8NzF0/mlbzCuGQ4SunlHQ4k+NVOziyrWPtoTYYtSvTpkUb8rm25MGOutAya15JhycEPQZ/91D3rc5y+2Hix7GsxcbUDuCDxf0FWS8dwNR/TVJ+pcRrw37nRK7gL7vkyUBd6stGchLo2aGCf6IG/v3jAqP+XPfOvA0orV+kSzwymdpKc6NMpEdgxtzbEciGaxI0LlAloByMBUhwEJlusn X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM7PR08MB5494.eurprd08.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(366004)(396003)(136003)(39840400004)(6916009)(6512007)(2906002)(83380400001)(36756003)(478600001)(1076003)(6486002)(86362001)(2616005)(956004)(8676002)(316002)(186003)(16526019)(5660300002)(66946007)(6666004)(52116002)(66476007)(8936002)(26005)(66556008)(6506007)(4326008); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: WGsrgVZETWIxV0Xk1i//7fnONp7lQJwHmtPS0NAjyVDKQmDOx7Tlv6DlqJP4EamWx0cdsKr766vu+YB6qSF2AvGrKtBqZEpqzLn4WshU8xfvDXu75xLRqnqH/zHu5UOBYcUTVAc/yjA65QiaXQXBZmA3FDLuPVwXFak0ZHasNDmBR0sAgiQiV+WGsXfRpP7XAyNFLRizhWEMuFeph+FyPegzNk3/XOjWsvVimDkr/fqKUJmOLodVI6sPImXbhARMMfv6c14lmBtTYGhYry5CwBjKg1dzgYo6RBMxLy6VJrL+loSoHMNOvo/CvD+0XwKQenp6AoVUxLZ6Fry0TpjJr0UaPdQkQEkjFrlgafGt1KVGRzHLlzs0fJe9WEkX8YkUi2zemtJFMQJtDLxqv1Rh3lSjjpCfUkdyu+KWKi46+Zgp9XgRZ5riIxOy4M6PT7eEE6vlz9D0wjpdPgi3zH2VsDUzD98r5AguCaXkhm+VNHwNLRCR12KnR+TZ+g4G6fsgyiewoy7A5/YD4NzrriwZAzf4AHYdUhhOtukIF32C62zm+e2fJmZuLzY3NxAuPRcwoog95miV/3lngg0+KwxDhGMicoONtMoGOhMxTj9wizAtTpi9PgDhKMR3m2GL7eGDoa/f6MCHcIkDDE5pyETHIA== X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 08bfc6d1-271e-49da-77d8-08d859969dba X-MS-Exchange-CrossTenant-AuthSource: AM7PR08MB5494.eurprd08.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Sep 2020 16:44:30.2161 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: aMROoGa5OJFLlH7Yk/gpjJHSIquUGeVUq9CzubilXsONGtcK4gseoxbOivIWk3KpLZjc3OyJW4qcAD1vvel/GWv5FkckOTWuX9b1PdeCxdw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1652 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=40.107.0.99; envelope-from=vsementsov@virtuozzo.com; helo=EUR02-AM5-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/15 12:44:37 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-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.23 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" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Like for read/write in a previous commit, drop extra indirection layer, generate directly bdrv_readv_vmstate() and bdrv_writev_vmstate(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi --- block/coroutines.h | 10 +++---- include/block/block.h | 6 ++-- block/io.c | 67 ++++++++++++++++++++++--------------------- 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/block/coroutines.h b/block/coroutines.h index 6c63a819c9..f69179f5ef 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -57,11 +57,9 @@ bdrv_common_block_status_above(BlockDriverState *bs, int64_t *map, BlockDriverState **file); =20 -int coroutine_fn -bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read); -int generated_co_wrapper -bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read); +int coroutine_fn bdrv_co_readv_vmstate(BlockDriverState *bs, + QEMUIOVector *qiov, int64_t pos); +int coroutine_fn bdrv_co_writev_vmstate(BlockDriverState *bs, + QEMUIOVector *qiov, int64_t pos); =20 #endif /* BLOCK_COROUTINES_INT_H */ diff --git a/include/block/block.h b/include/block/block.h index b8b4c177de..6cd789724b 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -572,8 +572,10 @@ int path_has_protocol(const char *path); int path_is_absolute(const char *path); char *path_combine(const char *base_path, const char *filename); =20 -int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t p= os); -int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t = pos); +int generated_co_wrapper +bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); +int generated_co_wrapper +bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, int64_t pos, int size); =20 diff --git a/block/io.c b/block/io.c index 68d7d9cf80..84f82bc069 100644 --- a/block/io.c +++ b/block/io.c @@ -2491,66 +2491,67 @@ int bdrv_is_allocated_above(BlockDriverState *top, } =20 int coroutine_fn -bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read) +bdrv_co_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t po= s) { BlockDriver *drv =3D bs->drv; int ret =3D -ENOTSUP; =20 + if (!drv) { + return -ENOMEDIUM; + } + bdrv_inc_in_flight(bs); =20 - if (!drv) { - ret =3D -ENOMEDIUM; - } else if (drv->bdrv_load_vmstate) { - if (is_read) { - ret =3D drv->bdrv_load_vmstate(bs, qiov, pos); - } else { - ret =3D drv->bdrv_save_vmstate(bs, qiov, pos); - } + if (drv->bdrv_load_vmstate) { + ret =3D drv->bdrv_load_vmstate(bs, qiov, pos); } else if (bs->file) { - ret =3D bdrv_co_rw_vmstate(bs->file->bs, qiov, pos, is_read); + ret =3D bdrv_co_readv_vmstate(bs->file->bs, qiov, pos); } =20 bdrv_dec_in_flight(bs); + return ret; } =20 -int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, - int64_t pos, int size) +int coroutine_fn +bdrv_co_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t p= os) { - QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, size); - int ret; + BlockDriver *drv =3D bs->drv; + int ret =3D -ENOTSUP; =20 - ret =3D bdrv_writev_vmstate(bs, &qiov, pos); - if (ret < 0) { - return ret; + if (!drv) { + return -ENOMEDIUM; } =20 - return size; -} + bdrv_inc_in_flight(bs); =20 -int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t = pos) -{ - return bdrv_rw_vmstate(bs, qiov, pos, false); + if (drv->bdrv_load_vmstate) { + ret =3D drv->bdrv_save_vmstate(bs, qiov, pos); + } else if (bs->file) { + ret =3D bdrv_co_writev_vmstate(bs->file->bs, qiov, pos); + } + + bdrv_dec_in_flight(bs); + + return ret; } =20 -int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf, +int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, int64_t pos, int size) { QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, size); - int ret; - - ret =3D bdrv_readv_vmstate(bs, &qiov, pos); - if (ret < 0) { - return ret; - } + int ret =3D bdrv_writev_vmstate(bs, &qiov, pos); =20 - return size; + return ret < 0 ? ret : size; } =20 -int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t p= os) +int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf, + int64_t pos, int size) { - return bdrv_rw_vmstate(bs, qiov, pos, true); + QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, size); + int ret =3D bdrv_readv_vmstate(bs, &qiov, pos); + + return ret < 0 ? ret : size; } =20 /**************************************************************/ --=20 2.21.3