From patchwork Wed Jun 10 10:03:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 280927 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A52F3C433E2 for ; Wed, 10 Jun 2020 10:05:44 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 7321120734 for ; Wed, 10 Jun 2020 10:05:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="u2I8E6cW" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7321120734 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:54730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jixc7-0001QY-Mm for qemu-devel@archiver.kernel.org; Wed, 10 Jun 2020 06:05:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jixaY-00085j-JA; Wed, 10 Jun 2020 06:04:06 -0400 Received: from mail-eopbgr130098.outbound.protection.outlook.com ([40.107.13.98]:48772 helo=EUR01-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 1jixaX-0005xX-Fb; Wed, 10 Jun 2020 06:04:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KpbIWWwjGTXXIyGy/W9D6F844WMRymfjdyW/jCIZ7KM39wahDsxqiyPbQCDOcumwVJ0chcKc2u4Je4G59gtKbWMuEk3Jw7IFTtgndOKVsynerD3kzukHtVye2gBdTvqAWtjggwY1un58ynnG8S+icGwmrepGzia2WjkgUjpgFy7YzHKHJWpJeCW6/KPsiyiVWWpKQHfHpJ2XSSy1ndNl1t1mjbm7INY13suNpjfegDLafirTcrffc52abm8/uaRoNXAgAIc3gkz0tUiuLV1e0Ln9UucS8kaV3DP6tiu2VYMN/ML31ZIKrT8Njzw3mfyOK+IsDx1wjaJnCOm7SP+XJA== 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=oyuElqbl1dwKIMPBQiLQGPB4rKWdUC711HR1FYlCycQ=; b=N5Su/Jj0gL2lzPlWfcUs6XHWpMnSiM2XeTfs2XMCDxBr/n2Iv+RGD6oFyXWgCD4aqOkIBbEDBd5c9dVPIvKZe9WH51VtHrBzusYTlnQ61+2YUWPff5WSbi7eodyB8KXawsTKxG53ssv/egYAzLZu2bvQT322UXYC39P2ei5KNrWT86EMgnite9/yd27GReS7blcx0lX2ZF1pTGa2ErKqx9UmhcQOwdn/lAR9XgddmmZs8pTki7QRujUuCfnyAKsU0CoFXMjbzaNXJtIZHgrQXrl8AnLzFnbnZLKNY4iI7R9+Ns/sDv0lnezYzXKMBuUSDZqiFWx90UGFxdvNxxJ/GA== 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=oyuElqbl1dwKIMPBQiLQGPB4rKWdUC711HR1FYlCycQ=; b=u2I8E6cWqvuAV5rf+z74dRFpLLXCmOPoiLOy8PUU3jpqrCw6fmNUCpgeGTPn5AKsBF6UeNciDEJ4cZvp9Jf0PgGOSS17WT4xpdH6q/u3T5W81bUXfXnMspqQ2J/+H2o47u+W/IwIKXBHl7KaZuxKD1L1X3tIdn6UY67oBLSzyPo= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5525.eurprd08.prod.outlook.com (2603:10a6:20b:107::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Wed, 10 Jun 2020 10:03:58 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%3]) with mapi id 15.20.3066.023; Wed, 10 Jun 2020 10:03:58 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v7 2/7] block/io: refactor coroutine wrappers Date: Wed, 10 Jun 2020 13:03:31 +0300 Message-Id: <20200610100336.23451-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200610100336.23451-1-vsementsov@virtuozzo.com> References: <20200610100336.23451-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM0PR03CA0005.eurprd03.prod.outlook.com (2603:10a6:208:14::18) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (185.215.60.166) by AM0PR03CA0005.eurprd03.prod.outlook.com (2603:10a6:208:14::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.19 via Frontend Transport; Wed, 10 Jun 2020 10:03:57 +0000 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.166] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 04747811-8ac3-47cd-7ac9-08d80d259765 X-MS-TrafficTypeDiagnostic: AM7PR08MB5525: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:189; X-Forefront-PRVS: 0430FA5CB7 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mrLUj3mf/mxIIckA7Zw+kd1q9kdbrUV/80/edQI6gl98DV8rkwnvModETE8uvKKCAPQx/hHhz0orLG/rLpCupZHxlh1WxjyPMZKBPnsKDzczZHBxeWB9V2zbXq960D7AgCaMtcPkimJnP1gydz6nfn5ni6Ly5EQ9pp75bFQMw55z4CDwt8UVldfDBzQte3PS3JmT0kTTvPqkYQy91fQFO2Vw8pOnC/hL0A+qndBQtGawp0jFwZKijkt8PT9tp8TbeB4rWCLJ3S/wxhtHx+8szdIB9KMxO02NyeC2EcylvhqluQ9vEXjkcknnk6cN0V/xGyrwaCNCCpSGnpkl7w+meapWjpfBRv25q8kimf7pUPqhfWR4smwnOUZkbLMOmaX+ 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; SFTY:; SFS:(4636009)(39850400004)(346002)(136003)(366004)(376002)(396003)(478600001)(83380400001)(66556008)(66476007)(956004)(6666004)(316002)(5660300002)(6512007)(2616005)(36756003)(8936002)(107886003)(69590400007)(6916009)(6486002)(26005)(4326008)(66946007)(186003)(8676002)(6506007)(52116002)(1076003)(2906002)(86362001)(16526019); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: as1jDgAWU12iOS+qtDJk2pleApQnMxMcreckCAB1E9aaW6uihSLtvhtZaPGPK+meI1i83yyb4CceYl50CC2xIzINTQJb6lqsLW8ePgzt1jO3dYyZtf/r3qWaqSwQ279z4KMOl48BUrt9qTH+l1PK6/89BhT5vKKMpvHieJaz/tgLPnZZQ8BOdhxhCHBWEjdf1ZGr6EHChiePm5xlW/GmRuyAl8Cx60anUShiew3jCZbvWkRIW25fYgie/U0X6GA+n82zNUDhkk9Q6aRA6Q0Baa8CR62Urq9tjFAYpaDQtKB3zbpeRAGjthQBDGVXWp98EBs687aXwxz3tZAMtAMUY2tTNDo2mVt0Zfpp/hpGR1Q2oCaPoiqsx0mkX/gn/oujY4BDkiWruCZC+od8aEFZhsKwqHBWylFqyto9uiXXcS79HJWSwN0IdDlZ0ICmTSmjYXMPcC9WNRnHqI/NLkubJjq2EAf5XiL8v1zrXUebo1iYbBKm6soQl508jxHMVOse X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 04747811-8ac3-47cd-7ac9-08d80d259765 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2020 10:03:57.9449 (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: Y1hfhXx80CRQA2jGrcgsjq9G5zV2jI98RncaBFPlsgCtPgcyXq0ibmgEKWgl+USvziOICqoevUEyAKzND0U8e0VzK6EkAIzqcdLrV3eJfC0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5525 Received-SPF: pass client-ip=40.107.13.98; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-HE1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/10 06:04:01 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -37 X-Spam_score: -3.8 X-Spam_bar: --- X-Spam_report: (-3.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=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: , Cc: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, ehabkost@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, crosa@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- block/io.c | 60 +++++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 28 deletions(-) diff --git a/block/io.c b/block/io.c index df8f2a98d4..af6cb839bf 100644 --- a/block/io.c +++ b/block/io.c @@ -933,27 +933,31 @@ typedef struct RwCo { BdrvRequestFlags flags; } RwCo; +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 = opaque; - 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); } /* * 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 = { .child = child, @@ -971,8 +975,7 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, { QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes); - return bdrv_prwv_co(child, offset, &qiov, true, - BDRV_REQ_ZERO_WRITE | flags); + return bdrv_prwv(child, offset, &qiov, true, BDRV_REQ_ZERO_WRITE | flags); } /* @@ -1021,7 +1024,7 @@ int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) { int ret; - ret = bdrv_prwv_co(child, offset, qiov, false, 0); + ret = bdrv_prwv(child, offset, qiov, false, 0); if (ret < 0) { return ret; } @@ -1045,7 +1048,7 @@ int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) { int ret; - ret = bdrv_prwv_co(child, offset, qiov, true, 0); + ret = bdrv_prwv(child, offset, qiov, true, 0); if (ret < 0) { return ret; } @@ -2463,14 +2466,15 @@ early_out: return ret; } -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 = 0; @@ -2508,10 +2512,10 @@ static int coroutine_fn bdrv_block_status_above_co_entry(void *opaque) { BdrvCoBlockStatusData *data = opaque; - 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); } /* From patchwork Wed Jun 10 10:03:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 280925 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D437C433DF for ; Wed, 10 Jun 2020 10:09:08 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1AE832072F for ; Wed, 10 Jun 2020 10:09:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="BYCWXca7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1AE832072F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:37750 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jixfP-0006D1-9y for qemu-devel@archiver.kernel.org; Wed, 10 Jun 2020 06:09:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jixaa-00089g-Fu; Wed, 10 Jun 2020 06:04:08 -0400 Received: from mail-eopbgr130098.outbound.protection.outlook.com ([40.107.13.98]:48772 helo=EUR01-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 1jixaZ-0005xX-8L; Wed, 10 Jun 2020 06:04:08 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hqhtUIu2V+9aQaI1OWoFjrSDN6uIiCTF5T/pfIy20IWykQtg5yWYthT0SN/M1A3ZEZZTynZHXx6wpL0pYS6fGiFjsrFXvdy1HIeJlsZHr7UqqSCgoEU4lB1TVSiyzUvAdOpBBc4sAb0nmJ3AGI+2DTMoWLwepfTv/FzSABxrx8XuqMPURwB3W6FeEJd+CF9Na5JOLyS0o/Wz64i92QISJFxzRWZsq2q7MXBT94c/6PJ3T1XsVvzmMvmfCRKN790S+TduuFQ0s0d0mzglQoyjGqjAxWivMqw0HptJJ8Ximbj56gXWYHswoEED/x3MLz+71/LwxMp1DluKCZSLwdtY5A== 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=CdkEciUCSDw7LDQzG+bxUvcxlwX6Xi7xdsPRAuiFRuU=; b=UiLqUxe1ttJ0jo2fVvPvHV5SHT4tIc8sg9Yh5+4puszllkI2m68fbpJR2mNHyk/H1kbnvnjI6/YxKZL3FTZ3IbhtAxfqfiabdk5ECIYYy64PNBbDL/yMyuX0gNfEJPiofykkd5BjNVu3Qrc7Gg19cq6QLd9U24kN3I/Ql5quEy9ZG5Kg65OTQq3vLjYV6CCbEzyQxAH9+r0qfLAgAEgSds3UByYz9gVsjYwJxGQ7oNXOcXPmRJwGxk7qagV40EngPi9XOGLF1pdBcfxKO3fr9WqHiK/TzNeG2W7e2uv8zfHJxkWFYYrAiZMpMaRTTC/BicDeG5++HSoE1T0uyDFtDw== 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=CdkEciUCSDw7LDQzG+bxUvcxlwX6Xi7xdsPRAuiFRuU=; b=BYCWXca7ssVAEHp6TIuVEJnP+8I6sUBDm2tsC6fQB8XItjW4BIDBKvDFB/7aM22Ri6Zuxz/XG39bxayWIfoOqcfWdLAcCJYBMA6lTY4OVSGbHBem0oZgnCg3P/CJmzVJ4HBpH1M8495zWbKpy8AG/cbxqRNxajdelvrLiSdRNE0= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5525.eurprd08.prod.outlook.com (2603:10a6:20b:107::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Wed, 10 Jun 2020 10:03:59 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%3]) with mapi id 15.20.3066.023; Wed, 10 Jun 2020 10:03:59 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v7 3/7] block: declare some coroutine functions in block/coroutines.h Date: Wed, 10 Jun 2020 13:03:32 +0300 Message-Id: <20200610100336.23451-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200610100336.23451-1-vsementsov@virtuozzo.com> References: <20200610100336.23451-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM0PR03CA0005.eurprd03.prod.outlook.com (2603:10a6:208:14::18) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (185.215.60.166) by AM0PR03CA0005.eurprd03.prod.outlook.com (2603:10a6:208:14::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.19 via Frontend Transport; Wed, 10 Jun 2020 10:03:58 +0000 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.166] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3b27796e-f88c-4b5d-79d0-08d80d2597f7 X-MS-TrafficTypeDiagnostic: AM7PR08MB5525: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-Forefront-PRVS: 0430FA5CB7 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: q+zyqzikOiRj/HpeGOIt+Gb1VnmjwQYwXPnQhW48nhnJz4jtMeFHlp0BfzCnzHnR4/OCwsHNQeVFqDX/EXTocrSt5XtwNdRBYvJXxW301QvdMlOhDqabTkjaa3wM5t5cwV3oMmv7ofm8+oGVKMcbX6ts4M/LUpEGFcNw2LodqiS/gwp0sarR7cf44wNoSMP7DofGZNqXPt0RW493wdciUR0/692A0V2fOU9lk4U8uwbl3NTjPrGtGXYNlFqg0pA/wo0c9mVwRPeWVrhtNCtTnE+HXLmzNoMUVlSlSYUdJrltmCelR6pwHn0gc8G6I7jz4X3ZWzw5SDBDnd1+XGtQkZ5a2cPbNd01dwjx2+M3tOasFpPQlaj2OyKaqUl6bJxl 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; SFTY:; SFS:(4636009)(39850400004)(346002)(136003)(366004)(376002)(396003)(478600001)(83380400001)(66556008)(66476007)(956004)(6666004)(316002)(5660300002)(6512007)(2616005)(36756003)(8936002)(107886003)(69590400007)(6916009)(6486002)(26005)(4326008)(66946007)(186003)(8676002)(6506007)(52116002)(1076003)(2906002)(86362001)(16526019); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: r/4Ti6GAl6u28hWlXqa5tkN46TpJHaZq8xdGWZY0AlW0IogV8UwqIALWt/7a6Yc4nZ8rTz4WVG/uD6YO+QFM4wmeqBtnVsp27ZPiJnsxkvZZhctsaBC0rKKSLNeqYerj6oYS4kpO+Xc6xhQxYP9hqevCKSKKIuqTeCMK1OKLkifsqxfvsS5SLvz4vdoEKD/QEHS8FoSz04O3J6iH7Tt8bekDxzet0oH9j5Y27daEc7mnzbbWQaaSNK6Z3nza4UVaFcfBr5+xw/cJozPH9fC/7UosmhBJLxx26KzhjPjP5xo+VQuhbR/vI8c4xoMSR8OzZC5I38icKLggeFLKC28k5W75lWtoZq0MQgyBRBc802qMXQj4R5pxR6NahsSB8rso2Gzrjzg/LkUDdyT/tN3up79NELjyomuLeUeaHsgDqQrhikWYVYsTkfXrcmRt/m+8mUttyN3xvtYNb1szSqXiqb4mwe6auyesVqlOd8itG4w= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3b27796e-f88c-4b5d-79d0-08d80d2597f7 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2020 10:03:59.0112 (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: EsMdEyarpbtHJqnFlUsCsSYaw/HeNFg1OpJT6udXnlUZ+ye6xmyreSfIA4aVISpFkfTMo/4cj9brFJY4M7qglcSehTpwLGqcx1u4KTXf4a8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5525 Received-SPF: pass client-ip=40.107.13.98; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-HE1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/10 06:04:01 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -37 X-Spam_score: -3.8 X-Spam_bar: --- X-Spam_report: (-3.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=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: , Cc: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, ehabkost@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, crosa@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 OTHER + * 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 **errp); + +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 b01551f21c..2ca9267729 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" #ifdef CONFIG_BSD #include @@ -4625,8 +4626,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 == NULL) { return -ENOMEDIUM; @@ -5643,8 +5644,7 @@ void bdrv_init_with_whitelist(void) bdrv_init(); } -static int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, - Error **errp) +int coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **errp) { BdrvChild *child, *parent; uint64_t perm, shared_perm; diff --git a/block/io.c b/block/io.c index af6cb839bf..deb9ca8d82 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; -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 = { .child = child, @@ -2466,7 +2467,7 @@ early_out: return ret; } -static int coroutine_fn +int coroutine_fn bdrv_co_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, bool want_zero, @@ -2523,12 +2524,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 = { .bs = bs, @@ -2644,7 +2645,7 @@ typedef struct BdrvVmstateCo { bool is_read; } BdrvVmstateCo; -static int coroutine_fn +int coroutine_fn bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read) { @@ -2676,9 +2677,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); } -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 = { .bs = bs, From patchwork Wed Jun 10 10:03:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 280924 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC7BDC433DF for ; Wed, 10 Jun 2020 10:10:28 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8AF9920734 for ; Wed, 10 Jun 2020 10:10:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="MhY+2Ftf" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8AF9920734 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:42288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jixgh-00081o-Ng for qemu-devel@archiver.kernel.org; Wed, 10 Jun 2020 06:10:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54236) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jixad-0008GS-2n; Wed, 10 Jun 2020 06:04:11 -0400 Received: from mail-eopbgr130098.outbound.protection.outlook.com ([40.107.13.98]:48772 helo=EUR01-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 1jixab-0005xX-6h; Wed, 10 Jun 2020 06:04:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l4fSmejt9s/z7Go00cWWQrE7xQfjzDi1StdPp6YhgXEtivAVH14pJiXH0OmMDix8cF5TpHC8N4OmJDN/opv6dri+13d3pJQw6NwWooszxGDdev6SCORjlXv4LOuwFcQluGpjDpZ0hr7vnWARzlFSxt9466LdzQHaj1tRHNwND3sI7b05nteN31DpDeKyLpG2GQ10Q6/UYF2aAbXtWDpkj4h3+3pepy4KNJWKt7eatV13eIYmk60UKuYfJ/r/U3YmGmYUD5dsyLJF1UO2OWXxrTt9+Y0kFfXJ7wTsC0Tz+EOmiwaVeaPyMXoiyhRyKwAsycJutuEheho5K98MkyCWjg== 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=XJJi2loRZgPaPIorUhGFO4frr4iSoysFAZrh0Vbw1ro=; b=cBWIRgL3GMBwBupAzetFERZH+hQWt8TI1yWIfdwrVgtNU3QqIbV1HiXboRuXuG5sQ0eidhpPa0CFmrzuHhAe2F/nSN+1WbnCxtfGYukaZXhL/CYMmi1UiU3dJhZiITGla4x6FqKva6vsZQDAoXzkuKumH0hW0XfNAFzsyd1W6m36YOu0QbcckW8JjjIoBwstpK1qdY5Cc6zaO0dPUN8b8LEfwmqw986YvSdfevcPo3n0Kknr1sxo7IMYqLPZSzh4EFnfMgeST0mBkZn9uJmRK7OEDhrN6yrkSfmC3KHtovGwXqmW8dwbNfSf6TwaqS6/rZP+YMB9BpAEu6PdEWGH9A== 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=XJJi2loRZgPaPIorUhGFO4frr4iSoysFAZrh0Vbw1ro=; b=MhY+2FtfjtzVTUZdtskQjnaJRwQyXwp9nOGQmY1dp74Oz301EUmrfrO7SqtavFHzdtvOUyy2mSXJV0zHYWQi+kDvUSulImpeUdO32BPSLV9APmmyN2hxhMyfJWd0FLOTUsGiGuL8caOpAZydnxQf7o/3+yGG3FEdaEWED14lj7U= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5525.eurprd08.prod.outlook.com (2603:10a6:20b:107::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Wed, 10 Jun 2020 10:04:00 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%3]) with mapi id 15.20.3066.023; Wed, 10 Jun 2020 10:04:00 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v7 4/7] scripts: add coroutine-wrapper.py Date: Wed, 10 Jun 2020 13:03:33 +0300 Message-Id: <20200610100336.23451-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200610100336.23451-1-vsementsov@virtuozzo.com> References: <20200610100336.23451-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM0PR03CA0005.eurprd03.prod.outlook.com (2603:10a6:208:14::18) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (185.215.60.166) by AM0PR03CA0005.eurprd03.prod.outlook.com (2603:10a6:208:14::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.19 via Frontend Transport; Wed, 10 Jun 2020 10:03:59 +0000 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.166] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 36cb3ada-c893-446e-1ea8-08d80d259899 X-MS-TrafficTypeDiagnostic: AM7PR08MB5525: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:651; X-Forefront-PRVS: 0430FA5CB7 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: y7mHr5kjuIEtv4EF/+WQdSc6rym59MirBxbgEDDYt8Bs46sYyesZnBWjGDJj+kK9XbCpF89QpPCCgLdLzxfeb+aBNDbYlM+uiOtPZtPbP4NTqKhkc3CMf4aQbnLEBHUp5TQ9czzF9EXpuwFoukTtE5vZX2wXXgnZWLEBeh7XQ12McRJ1D39cb70Szwbum0iWsiTsD2CsPC88ut6T/ofQEY54hlZhGWgUqK1xa9Xe/rFwYAQCCn+YotzvGj+6B0v1rlN6K1Dqp25cRw9zKV/3K2+mf7IEtRJpjDAS07rVxN0RiqjzeZKBQe97XZE10PPMfUHscL2LGkA7HM1OzCElla+OPbkUwV/mjIJp7njd6tLM17aiXPag7y2+m2PMQWjI2C5JUmzYUIXEbHfuDq5PAz/VjpfklqUnDwXGrWsCufJovk92bKVnok9TS8oVT/dtxGObpivnXCztV52oxCGa0wjRvUep4jEzvtmUdu3jgqg= 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; SFTY:; SFS:(4636009)(39850400004)(346002)(136003)(366004)(376002)(396003)(478600001)(83380400001)(66556008)(66476007)(956004)(6666004)(316002)(5660300002)(6512007)(2616005)(36756003)(8936002)(107886003)(69590400007)(6916009)(6486002)(26005)(4326008)(66946007)(186003)(8676002)(6506007)(30864003)(52116002)(1076003)(2906002)(86362001)(16526019)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: cgVsW83kNch4BBmogti01uozCkV/AMQmsZIcOE6OdEE+pXOfCtTVZxiitcxkLczWytVRWC2wqg5J3Bha9L1n3VYAWOQdSORrNIsanuWF/SM5WVaBGp8pEnsLlPseQ7yn3/Kblcgt4AG/BX1HPp/GTlYnNboYDoWKiG2LL4jGcrxPH5W2+xV5M6y2YDruaxR2UIDDlXaSwhk9tmdrQpYQON6YvgrdIsHSkUen8j+1tuvUyP2RJacgW7L8TjfoboHLK2EUgJ43zujEYM2seeAYk2IPaBJ3XjJkRRamiNacPBRfqXTsgXIcsCp/P5CwcMSyYww6puKwdTkd6s39n5iRFzXH2UUHBjsrZip8B4Si3Cgl66MFRCLgRjDhP3gIicDM76MDFhTy2A6+TnGHHzTimnW3i+IPR7U6lE7Yn64wmGvDzaa4UiAxEjTNCU4bKdLzfy3twYiOz7pNnt+/0yfrG035bDNAGvcm49oEekJV4tg= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36cb3ada-c893-446e-1ea8-08d80d259899 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2020 10:04:00.0965 (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: 4jbKL4qBkkwGqykyfZGKKoOAImwzYKgNMxtYqWr1dFODfTE9HSv0iikl9YFnfJN4n8aWCax5MNY8WxG5N3NaWU9V4XMR+oKl8KuuTFc1ihk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5525 Received-SPF: pass client-ip=40.107.13.98; envelope-from=vsementsov@virtuozzo.com; helo=EUR01-HE1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/10 06:04:01 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -37 X-Spam_score: -3.8 X-Spam_bar: --- X-Spam_report: (-3.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=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: , Cc: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, ehabkost@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, crosa@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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/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 --- Makefile | 8 ++ block/block-gen.h | 49 ++++++++++ include/block/block.h | 7 ++ block/Makefile.objs | 1 + scripts/coroutine-wrapper.py | 180 +++++++++++++++++++++++++++++++++++ 5 files changed, 245 insertions(+) create mode 100644 block/block-gen.h create mode 100755 scripts/coroutine-wrapper.py diff --git a/Makefile b/Makefile index d1af126ea1..517a29810f 100644 --- a/Makefile +++ b/Makefile @@ -175,6 +175,14 @@ generated-files-y += $(TRACE_SOURCES) generated-files-y += $(BUILD_DIR)/trace-events-all generated-files-y += .git-submodule-status +generated-files-y += block/block-gen.c + +COROUTINE_HEADERS = include/block/block.h block/coroutines.h +block/block-gen.c: $(COROUTINE_HEADERS) scripts/coroutine-wrapper.py + $(call quiet-command, \ + cat $(addprefix $(SRC_PATH)/,$(COROUTINE_HEADERS)) | \ + $(SRC_PATH)/scripts/coroutine-wrapper.py > $@,"GEN","$(TARGET_DIR)$@") + trace-group-name = $(shell dirname $1 | sed -e 's/[^a-zA-Z0-9]/_/g') tracetool-y = $(SRC_PATH)/scripts/tracetool.py 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"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * 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 OTHER + * 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 46965a7780..59a002e06f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -10,6 +10,13 @@ #include "block/blockjob.h" #include "qemu/hbitmap.h" +/* + * generated_co_wrapper + * Function specifier, which does nothing but marking functions to be + * generated by scripts/coroutine-wrapper.py + */ +#define generated_co_wrapper + /* block.c */ typedef struct BlockDriver BlockDriver; typedef struct BdrvChild BdrvChild; diff --git a/block/Makefile.objs b/block/Makefile.objs index 3635b6b4c1..05e4d033c1 100644 --- a/block/Makefile.objs +++ b/block/Makefile.objs @@ -45,6 +45,7 @@ block-obj-y += crypto.o block-obj-y += aio_task.o block-obj-y += backup-top.o block-obj-y += filter-compress.o +block-obj-y += block-gen.o common-obj-y += monitor/ block-obj-y += stream.o diff --git a/scripts/coroutine-wrapper.py b/scripts/coroutine-wrapper.py new file mode 100755 index 0000000000..57ae6aed20 --- /dev/null +++ b/scripts/coroutine-wrapper.py @@ -0,0 +1,180 @@ +#!/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: cat FILE.[ch]... | coroutine-wrapper.py > generated-file.c + +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 = json.dumps({ + 'IndentWidth': 4, + 'BraceWrapping': {'AfterFunction': True}, + 'BreakBeforeBraces': 'Custom', + 'SortIncludes': False, + 'MaxEmptyLinesToKeep': 2 + }) + p = subprocess.run(['clang-format', f'-style={style}'], check=True, + encoding='utf-8', input=code, + stdout=subprocess.PIPE) + return p.stdout + except FileNotFoundError: + return code + + +def gen_header(): + copyright = re.sub('^.*Copyright', 'Copyright', __doc__, flags=re.DOTALL) + copyright = re.sub('^(?=.)', ' * ', copyright.strip(), flags=re.MULTILINE) + copyright = re.sub('^$', ' *', copyright, flags=re.MULTILINE) + return f"""\ +/* + * File is generated by scripts/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 = re.compile(r'(?P' + r'(?P.*[ *])' + r'(?P[a-z][a-z0-9_]*)' + r')') + + def __init__(self, param_decl: str) -> None: + m = self.param_re.match(param_decl.strip()) + if m is None: + raise ValueError(f'Wrong parameter declaration: "{param_decl}"') + self.decl = m.group('decl') + self.type = m.group('type') + self.name = m.group('name') + + +class FuncDecl: + def __init__(self, return_type: str, name: str, args: str) -> None: + self.return_type = return_type.strip() + self.name = name.strip() + self.args = [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.args) + + def gen_block(self, format: str) -> str: + return '\n'.join(format.format_map(arg.__dict__) for arg in self.args) + + +# Match wrappers declared with a generated_co_wrapper mark +func_decl_re = 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='int', + name=m.group('wrapper_name'), + args=m.group('args')) + + +def snake_to_camel(func_name: str) -> str: + """ + Convert underscore names like 'some_function_name' to camel-case like + 'SomeFunctionName' + """ + words = func_name.split('_') + words = [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 == 'int' + assert func.args[0].type in ['BlockDriverState *', 'BdrvChild *'] + + name = 'bdrv_co_' + func.name[5:] + bs = 'bs' if func.args[0].type == 'BlockDriverState *' else 'child->bs' + struct_name = 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 = opaque; + + s->poll_state.ret = {name}({ func.gen_list('s->{name}') }); + s->poll_state.in_progress = 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 = {{ + .poll_state.bs = {bs}, + .poll_state.in_progress = true, + +{ func.gen_block(' .{name} = {name},') } + }}; + + s.poll_state.co = qemu_coroutine_create({name}_entry, &s); + + return bdrv_poll_co(&s.poll_state); + }} +}}""" + + +def gen_wrappers_file(input_code: str) -> str: + res = gen_header() + for func in func_decl_iter(input_code): + res += '\n\n\n' + res += gen_wrapper(func) + + return prettify(res) # prettify to wrap long lines + + +if __name__ == '__main__': + print(gen_wrappers_file(sys.stdin.read())) From patchwork Wed Jun 10 10:03:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 280926 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AADBC433DF for ; Wed, 10 Jun 2020 10:07:32 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 141632072F for ; Wed, 10 Jun 2020 10:07:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="I8+Cj2Uu" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 141632072F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:33012 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jixdr-00044I-B6 for qemu-devel@archiver.kernel.org; Wed, 10 Jun 2020 06:07:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jixaZ-00088E-Ds; Wed, 10 Jun 2020 06:04:07 -0400 Received: from mail-am6eur05on2106.outbound.protection.outlook.com ([40.107.22.106]:48963 helo=EUR05-AM6-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 1jixaY-0005xb-9k; Wed, 10 Jun 2020 06:04:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=STXvjjBe2oJ1kVMfF2i2kopxRwKvG1rWiRjPx9HIVSa4DQ4wIM35puSU0XawaUV2vAjtsUx7Q3pG9aHQMxYvlaldOOBGB3Za6bq0KNGaQAMeRXcyQV6/Cd0IsxyFjYrS+sDI8v56mxyhtdCpl+024YWY3Kc+kYU8aK38Y9pP00AKeR3FQkg/+vg6MYjdv7Wg2eFMZrOfNo1nn+ynE8NaQIBaDun9rtt2jPYHBy3qei9+QCBKsr8UPijlWIe12Mhwa9aJHWAALy4QQUgN5jXBG5T0JedSe1tHaO4BPz9uO8dTvzWPR2FIBzKoxbg6OYq4ftRY09EBb7LDCci8rfLx1Q== 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=UjvoL2TpYskDQLKlnYqUmcA1MmhlqZWY29eYVJaKHN0=; b=I/OFFsioZt1wAz7RcHyEJ33tYL7TDAiw4PxA7OxQ1DMPmH/7BLTUxYznKhYPdydWVKDkmWhVgPwqWHn8WzjIMfNsE9HfqVgZQIYz7b82EPJWeYQpj0Qos5XyFPgvL5fEqHfB/iQoTOfqQNqGZlyFxeI6uvbEuk2lP6798e/AnklzutAd53fJWuA6EdHt9m7u8ynIdD79ORr2XUj98BqAV0ZsbFxxDmMuXSRq8Ht2/HqxSzdi7KG6iRn41Kmueyxvi/wOqHjvMFeZ74L/QyZFUA46VijnnYsdmb/FMGVApQt6RN2fqO3aV/ChJxE7REirfcyYll11vptYn4mJ0a86Zw== 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=UjvoL2TpYskDQLKlnYqUmcA1MmhlqZWY29eYVJaKHN0=; b=I8+Cj2UutJoPTLup2b24X38gcCf2h+xAgdyuhksOOnwZGCZ4/L/LXHbFjpk7pEUaYx63TXKTy0s1+PHcDx50sVV7okCDgm7Moexd9ELoellNxaKDVgCRroYeIo6GS0GEacFl3b94Tk9OL9QRscAhpkx+zYztifdHTSzHtSD1eqI= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5496.eurprd08.prod.outlook.com (2603:10a6:20b:de::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3066.18; Wed, 10 Jun 2020 10:04:02 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%3]) with mapi id 15.20.3066.023; Wed, 10 Jun 2020 10:04:02 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v7 6/7] block: drop bdrv_prwv Date: Wed, 10 Jun 2020 13:03:35 +0300 Message-Id: <20200610100336.23451-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200610100336.23451-1-vsementsov@virtuozzo.com> References: <20200610100336.23451-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM0PR03CA0005.eurprd03.prod.outlook.com (2603:10a6:208:14::18) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (185.215.60.166) by AM0PR03CA0005.eurprd03.prod.outlook.com (2603:10a6:208:14::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3088.19 via Frontend Transport; Wed, 10 Jun 2020 10:04:01 +0000 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.166] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c4cfacf1-2086-496c-aa99-08d80d259a04 X-MS-TrafficTypeDiagnostic: AM7PR08MB5496: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1051; X-Forefront-PRVS: 0430FA5CB7 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IcB9Nqoyn4UEG0gHEQRjsNxhvcxVxyZp/Y8o+yl1iss0AF8p/l2mStY2TGXSdALwHNeaquiHyLIuCS4J65+152kPJtMfeNlSx+9EOMr3Bekwdo/rAS2EqHzSc8JBnXOBYRd2xMeGnDcLp5rV7Q28qDgDnkCkhXnphfk30fkOtr4+Aip9GytvUtr+1VtUrXqEF1zRn/bhUdiPTPH9feza9yE+YWXWDCgvDcLQJhI7K7hF+7FsumdJcCcU9BCrB7sxkzCqirg9Edd5PaARGk488kSXE3sAG7yEfMXeQoG0NK4BPR+G/m1fFqL4oX2kuRh7k09HdIvPVHiEIjL56n0gZBMENcogxAfcraP7XhDFQZ5yvks2bu9W5oeYLyjwUf9T 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; SFTY:; SFS:(4636009)(136003)(396003)(376002)(366004)(346002)(39850400004)(6486002)(316002)(8676002)(107886003)(8936002)(86362001)(52116002)(6916009)(478600001)(6512007)(6666004)(1076003)(4326008)(66556008)(83380400001)(5660300002)(66946007)(66476007)(16526019)(36756003)(69590400007)(26005)(2906002)(956004)(6506007)(2616005)(186003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: k8ya13tVxUgHORJ0vX4p0yNc3gGD3f1dh6FPgdxuCI2h5+MP9KkmB1K7sZfI+swlGMkn5IWMhImzaALKGfHDlmwIDdfIUVLdUDA/DY846V/5TSLemfxSm1bEbYf6n0LHx3DCOXiChdpYgqOurW8UjsGcpGCjlm6h1q4vu4TNkKSHv7bgxPjJEpU/RztiTVtTbkJpZIrVA3sJmdl0mZ759YA/gXP9NbtQ/hygMiszNEMHxt8hgP5bkMb2bahtnCJHpNlYmF1ZKW0yTomuW+ElSKxKvOc9Jy4X/Lb9EYQmvOFIRY+ipMFrqB7cFumhzuawqNhTLyf8EAOycln3ZsOJ6Ka8u7iynJe6Lc4mCPBIfJ5lcNBPzVYYpgVxSza/IwLG22shNzLHLDQ2aPz6pO2tj4MLmGGkmQgmXzaP7UKIfnnixpexUIJJ0gWQ3wLQX1En7Pe3/OS18HrTfdIgJcjHDC4VOr84RnUUTLZO18qxPHU= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: c4cfacf1-2086-496c-aa99-08d80d259a04 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jun 2020 10:04:02.5417 (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: /2myC0GeI+BrzClvMT1XN2SQwH6fV/0Zm5KF8nxEx7pVGbBi5006qGNKT6htM5XIzI3ekWkC6eM4JXaCKi7Ubo9l/c58WxnJem6inRKZUDo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5496 Received-SPF: pass client-ip=40.107.22.106; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/10 06:04:02 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -37 X-Spam_score: -3.8 X-Spam_bar: --- X-Spam_report: (-3.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=-1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN 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: , Cc: fam@euphon.net, kwolf@redhat.com, vsementsov@virtuozzo.com, ehabkost@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, crosa@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" 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 --- 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 **errp); -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); int coroutine_fn bdrv_co_common_block_status_above(BlockDriverState *bs, diff --git a/include/block/block.h b/include/block/block.h index 9f94c59057..280cf2a7d5 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -385,9 +385,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 bytes); -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 36fbf9e1fa..3060c7e6ed 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; } -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 = QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes); - - return bdrv_prwv(child, offset, &qiov, true, BDRV_REQ_ZERO_WRITE | flags); + return bdrv_pwritev(child, offset, bytes, NULL, + BDRV_REQ_ZERO_WRITE | flags); } /* @@ -950,41 +938,19 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) } } -/* return < 0 if error. See bdrv_pwrite() for the return codes */ -int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) -{ - int ret; - - ret = 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 = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); if (bytes < 0) { return -EINVAL; } - return bdrv_preadv(child, offset, &qiov); -} - -int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) -{ - int ret; + ret = bdrv_preadv(child, offset, bytes, &qiov, 0); - ret = bdrv_prwv(child, offset, qiov, true, 0); - if (ret < 0) { - return ret; - } - - return qiov->size; + return ret < 0 ? ret : bytes; } /* 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, QEMUIOVector *qiov) */ int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int bytes) { + int ret; QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); if (bytes < 0) { return -EINVAL; } - return bdrv_pwritev(child, offset, &qiov); + ret = bdrv_pwritev(child, offset, bytes, &qiov, 0); + + return ret < 0 ? ret : bytes; } /* 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(BlockDriverState *bs, } s->io_co = NULL; - ret = bdrv_preadv(bs->backing, offset, qiov); + ret = bdrv_co_preadv(bs->backing, offset, bytes, qiov, 0); s->has_read = true; /* Wake up drain_co if it runs */