From patchwork Wed May 27 20:37:27 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: 281808 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 9B09EC433E2 for ; Wed, 27 May 2020 20:39:00 +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 64ED920835 for ; Wed, 27 May 2020 20:39:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="eEX+rCTx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 64ED920835 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]:42306 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1je2pH-00067p-In for qemu-devel@archiver.kernel.org; Wed, 27 May 2020 16:38:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35220) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1je2oF-0004Rj-Th; Wed, 27 May 2020 16:37:55 -0400 Received: from mail-am6eur05on2112.outbound.protection.outlook.com ([40.107.22.112]:57342 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 1je2oE-0007uz-Ot; Wed, 27 May 2020 16:37:55 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KqKaaoPqqCaUiuFWQX7FdFljpUPu2jrlxTiv8UWv4USXYVg7j3mF4Qfw0hs5MNUmswBwNerO+OHIjVVWux4kiy2Ed4K+0FPLexvW9H/2owy6DRHS+aiBZFzu3aQB0WtzxlCqvWSUdSHQbRLT+ddJZtEUdr7NNHQAfHz5+FT8z0bOoQwkQcBiDUKp6lQKTjn75E34AgYiLN3VyFlXRa6Wt8SJEzvFjnAb88mMj9xijKgBda6x86K3VwymAOtBesH8Gtgxsd9QF+fHSrM83gMmogpL/pvZgDZa88HJ56BAGtTMzeXQHwnb7JS3Ck7z5PvEnYbgrCGGRKAo/XukYcKCYw== 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=tfPufP/IZK8kRWDGxlOJVFuyZsiyXUFfZaqTGzDh6NM=; b=mYlz32ZqgOyqw9UkS0tvDTblLx3FayQmiyyOsNxqXej14fDQGKa3+jrT4JaQDhrnjxpIpsD4PeSVG7aeFBTMbm8+AxguyjBl4YqT3HbGdiqXay2ae6Wk8ukKvBr7YiQmwKGmT+LejB/Qwz1Sz7kU/5mdgoqBUVhzZ2CLo4BzoH4rGxwpTGycMaoxRh5HOUsoLh/7AMPY/hwY+8owMeE/7NyD4BBqXDDkTv2Vt2LyD7hPSZZ1ws9zFd5NMbQ2typlipkXcoj9zy24MkFAQs+xbd0lN4StXB1I5moHj7/l1Cd7uiL6fSGqoECPeFSvt95WkyPoJuAtj9QcIywZXXnFCw== 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=tfPufP/IZK8kRWDGxlOJVFuyZsiyXUFfZaqTGzDh6NM=; b=eEX+rCTxt09igMHo7TDiizeVo7OJJa4OQq7awxTL2FNNuT/h8fv7yip7561Cemw9W0neSDgF9t8rP6FcitoTWy6Pp+LzmVa/T0+w+jGSAQi7aOUygdIuFD8l3dEl0SwIdu6DlI4S0azkWXLhzgU/vGf7UgNkYWLzazyPB9/3Ft4= 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 AM7PR08MB5336.eurprd08.prod.outlook.com (2603:10a6:20b:105::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.24; Wed, 27 May 2020 20:37:50 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%4]) with mapi id 15.20.3045.018; Wed, 27 May 2020 20:37:50 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v5 1/7] block: return error-code from bdrv_invalidate_cache Date: Wed, 27 May 2020 23:37:27 +0300 Message-Id: <20200527203733.16129-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200527203733.16129-1-vsementsov@virtuozzo.com> References: <20200527203733.16129-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM0PR10CA0101.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::18) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kvm.sw.ru (185.215.60.148) by AM0PR10CA0101.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.17 via Frontend Transport; Wed, 27 May 2020 20:37:49 +0000 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.148] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5039558f-8c68-482d-1a5f-08d8027dd263 X-MS-TrafficTypeDiagnostic: AM7PR08MB5336: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:489; X-Forefront-PRVS: 04163EF38A X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RJgZTqUR+h6bbSxcnQzbqhaK1oucTCJM6YYY0FB0p9ycUhMYyArVicbahZXk2Fo+Yk9LdUwTMKPjg4VmqptAgAvGKvBa7siaS7db747pLIgzCCh9JtFi801Dxtqkxyowe89/HRB1iWuDkzPVZcb0ZX6nsXf6G0AIxW3hlWogj6dfy0L66HpWTRTzNsAI03IyJWfnbBI/sTi8N1f3WhQjFqX4/pK19eLjbQA9qYTJaHiqGMnVA1P7R0Q4OKQnFbBuPqNkThVtRa3iBJFlYqNe3R7/sBERefqLspWr+UaVW1GBXlzF+QBXd8sgHkDOaUiR 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)(346002)(366004)(396003)(39850400004)(376002)(136003)(956004)(66556008)(66946007)(66476007)(8676002)(6486002)(6512007)(1076003)(478600001)(186003)(316002)(5660300002)(6916009)(2616005)(6506007)(8936002)(16526019)(26005)(2906002)(6666004)(83380400001)(36756003)(4326008)(52116002)(86362001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 8/msihvap/dfpggpLPhVW9B4fuFxOBf8obm7H3mZFzJoBGpkwP8hvUEhyoLvU9Yzpg5vWvho0rtj+UHUGTuKHX5zW+rsyfS8QQCZNsRwuS3yC2InLc1vfuNy2A+p6TwKujJX22jvexooWj/XO9DwofH9X/bPreKYsXWRt4L9id3dfw6JvLA9lqm+bzexg4qzVsNVviieqBog8T8mrRE+VSoMaWkpmpU4fQoo2I8ZDFSaaMCFbScAfT3jJ5KqeNkx62HkCPREtNbckPumyaDKi2psXoMGCALqFPWyvNUymLP50IVwhLw+jjbPK5cowQC0523jAhBeBhXsVv3CBDjYmncHKy0pV2q3Rza3wP3fF5A0YvPMbjCEiZvxEiQG4hwJ96PBkLbwGdH4IFtCZjkd89kGexsYOiwlJ3il6ldMqv2joI5H+yImK4ZGfwBw6kDjFHGuMSkL2+1WYynwDl1J6qhpbO6I2gbXujhMgIdTmmoLiogcpXl2eIicpzrtNM8G X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5039558f-8c68-482d-1a5f-08d8027dd263 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2020 20:37:49.8779 (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: Q8jYznJxCmaZAiAE/MeVn/Xhm/gedUh6DMkR6t/wWYe+Z+JeSvkNo/sR6nWDzaRwP+s2hUHD4TVeeenJxoQVBgNNFt3AFGJ2PA2JeKXeWS8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5336 Received-SPF: pass client-ip=40.107.22.112; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/27 16:37:50 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: kwolf@redhat.com, fam@euphon.net, 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" This is the only coroutine wrapper from block.c and block/io.c which doesn't return value, so let's convert it to the common behavior, to simplify moving to generated coroutine wrappers in further commit. Also, bdrv_invalidate_cache is a void function, returning error only through **errp parameter, which considered to be bad practice, as it forces callers to define and propagate local_err variable, so conversion is good anyway. This patch leaves convertion of .bdrv_co_invalidate_cache() driver callbacks and bdrv_invalidate_cache_all() for another-day refactoring. Signed-off-by: Vladimir Sementsov-Ogievskiy --- 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 25e299605e..46965a7780 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -464,7 +464,7 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb); int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); /* 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); diff --git a/block.c b/block.c index 8416376c9b..b01551f21c 100644 --- a/block.c +++ b/block.c @@ -5643,8 +5643,8 @@ void bdrv_init_with_whitelist(void) bdrv_init(); } -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; @@ -5653,14 +5653,14 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, BdrvDirtyBitmap *bm; if (!bs->drv) { - return; + return -ENOMEDIUM; } 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; } } @@ -5684,7 +5684,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, if (ret < 0) { bs->open_flags |= BDRV_O_INACTIVE; error_propagate(errp, local_err); - return; + return ret; } bdrv_set_perm(bs, perm, shared_perm); @@ -5693,7 +5693,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, if (local_err) { bs->open_flags |= BDRV_O_INACTIVE; error_propagate(errp, local_err); - return; + return -EINVAL; } } @@ -5705,7 +5705,7 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, if (ret < 0) { bs->open_flags |= BDRV_O_INACTIVE; error_setg_errno(errp, -ret, "Could not refresh total sector count"); - return; + return ret; } } @@ -5715,27 +5715,30 @@ static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, if (local_err) { bs->open_flags |= BDRV_O_INACTIVE; error_propagate(errp, local_err); - return; + return -EINVAL; } } } + + return 0; } 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 = opaque; - bdrv_co_invalidate_cache(ico->bs, ico->errp); + ico->ret = bdrv_co_invalidate_cache(ico->bs, ico->errp); ico->done = true; aio_wait_kick(); } -void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) +int bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) { Coroutine *co; InvalidateCacheCo ico = { @@ -5752,22 +5755,23 @@ void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) bdrv_coroutine_enter(bs, co); BDRV_POLL_WHILE(bs, !ico.done); } + + return ico.ret; } void bdrv_invalidate_cache_all(Error **errp) { BlockDriverState *bs; - Error *local_err = NULL; BdrvNextIterator it; for (bs = bdrv_first(&it); bs; bs = bdrv_next(&it)) { AioContext *aio_context = bdrv_get_aio_context(bs); + int ret; aio_context_acquire(aio_context); - bdrv_invalidate_cache(bs, &local_err); + ret = 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; } From patchwork Wed May 27 20:37:30 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: 281807 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 BA163C433E0 for ; Wed, 27 May 2020 20:40:01 +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 6B3D9207BC for ; Wed, 27 May 2020 20:40:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="lc1Pm6aV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6B3D9207BC 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]:46532 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1je2qG-0008NE-KF for qemu-devel@archiver.kernel.org; Wed, 27 May 2020 16:40:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35238) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1je2oJ-0004Xz-5U; Wed, 27 May 2020 16:37:59 -0400 Received: from mail-am6eur05on2112.outbound.protection.outlook.com ([40.107.22.112]:57342 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 1je2oH-0007uz-N0; Wed, 27 May 2020 16:37:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f4U3oKjMsSK1uFMbvifwIuoH9jqDbn28W/7d8IPLz36O93FgBiCzt97/P8BWGeTLTYG8kkUoTB3J3E/WHKRadAmaS9IDShT9JFYKhDIsrCufpyaCQYd4NsUE3ERGgJkAi6q0lyQIvI8g8hjsRIgLsi6fwo0/eoeWn0lyo2+NFt9koxiKFOyELNjZ+7OlpDf8LTcTwrvW8mHAU66hOkmbw+K5cisqBFn2M4AGmDSK6grhRbrlqldxS8PE9t+UB3/kCIiCv5vZnCi56SiNgbAFYiqDj14C40mkAnq/qQ5zYSX7SI8oOK6Mdq6TI1NG/sCB3YbiOU54dfJeecHZnQBzuw== 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=PVviC0rvEF+n1VWK35SpxyytVAGnfYxn43crSy0MDog=; b=jhJT6Eyq2HpaeKZoODyHCGLe7nJUTk1j8xXsrN0I1XPe9RDV0/g1tFBAP7oFiRUpcYbenYiu1C2rV3kY371pUX5cgQVPb7nROLKhGFey/B8pMdGTUNDCM6frILiVMnfGrO5h1gMrQyjSGoSPzipdq15VM1eUMQ5f6YJkOEqEEu+vWcbGulwqoiwgjfzxsuGbRG6BB1c1HrDzckvzk5qs6n/JKTbxQSjQWpo8aXuIbE5zFBo+UmXMjdaL7OxjE3NFNn7kHvZiUo5RocCHohDc1HXa1OoN+5RxQpynAplr/AZMKMKg0I2pkMwAGzUektHaeahU1tn/M5Dp9hgCFCZ6TQ== 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=PVviC0rvEF+n1VWK35SpxyytVAGnfYxn43crSy0MDog=; b=lc1Pm6aV/ukrPW8czsmy7ziJ4CWLB75g3Wcyoj9SaZtMcS2AAsgTr6RwOno0A0X0K6mQNZzWoHQr6pwd7k/aVzC78An0YW4+uRTv21MUi9Lo/JXk/+dvCxKVM4ygI+yS390dgbGFOJb7FxHKhQpX50e0JWAxtpaxu5g7AVZOngg= 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 AM7PR08MB5336.eurprd08.prod.outlook.com (2603:10a6:20b:105::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.24; Wed, 27 May 2020 20:37:52 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%4]) with mapi id 15.20.3045.018; Wed, 27 May 2020 20:37:52 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v5 4/7] scripts: add coroutine-wrapper.py Date: Wed, 27 May 2020 23:37:30 +0300 Message-Id: <20200527203733.16129-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200527203733.16129-1-vsementsov@virtuozzo.com> References: <20200527203733.16129-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM0PR10CA0101.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::18) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kvm.sw.ru (185.215.60.148) by AM0PR10CA0101.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.17 via Frontend Transport; Wed, 27 May 2020 20:37:51 +0000 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.148] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f840a922-db8d-4c03-8ee2-08d8027dd419 X-MS-TrafficTypeDiagnostic: AM7PR08MB5336: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:651; X-Forefront-PRVS: 04163EF38A X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DkiSPhPIftkzBWmVHb1yGip+CTfT5QxooW+EccI1joHTtkcPgTf4Wcw7CrQRQXidEcR8XNdD27DCdtuHTfGSSRzsLWj4SyMio1tjXJFGXCWAroWMcJCrQsaTkm9T4hrtJWpansZYfcrIY5tWRIK2+n2Slado1cXiCJ/JtAmUEl9sHAoImYV5CW81AL/poNUGHKg8wkLf8P3nGqhGAHVU3QhdwbEUZh9cnWX5WO88XfApLj+NQ/Ds6I3beB8U/YG7ly3Jk1Mg/R72RNHiXI2C+F0aBDQdHmYl9vpqcVXmHxj3ZsLSCNEj25D9pK8JdmBpaBxo1WNEP8olK9eFmZcbErOChDBhLxz1LYSQqgQpTCTXNIr3KCQN3rQ5gEA++W6aISkcp6Cu5lToVn4uv+FMwX+HiFzua/uqGNhce5a6JulYxoxNdw/QJF+Pr7CWEfSi 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)(346002)(366004)(396003)(39850400004)(376002)(136003)(956004)(66556008)(66946007)(66476007)(8676002)(6486002)(6512007)(1076003)(478600001)(186003)(316002)(5660300002)(6916009)(30864003)(2616005)(6506007)(8936002)(16526019)(26005)(2906002)(6666004)(83380400001)(36756003)(4326008)(52116002)(86362001)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: jpKtaUPgKzIiVGtgd2CImY03zZWtfk2OEYFVrvj5rVOzS/HrVNSBFbrjHZd0hJmNsjTMhq4pI6rb3OAUWYPciELJHQaCIqJ/bo3rasFnKMWxm2ZqfVgJx+5pceYDoJ5g/HCrqFioIocioCXpa0YM8ilG1a27BVdOb6SFMkIXll1ndBfOFoCfmTfoaLj+tidPuQ6cYh+SrLIp/OgNTZVzPAh9yPwK8/jZcJMWDoA/d7Wblp/DpqHPDTkM7AYdahr+XnHloBK0LVvW/Rg2ySQXpdvcj2w64ORbArM3nAKCaPEcQ2l8+eoaXUwUoDlaN+lXbirh2C2azjrB3vgUY1iaV8xhAou6U+Yv2GcakO1JUrUtgUC+ngQeCxm2iNn/ld8I3ENxKdCb0dmzh8oTKKlmbhlcny/7Y1ozfFi4coHUJ1oDF7LJ5ixL7ZWrK3nkZn0h1rA3BD/9w7mMDx63O8XPitbqo0xHlvdmmYLvEvsr5i0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: f840a922-db8d-4c03-8ee2-08d8027dd419 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2020 20:37:52.7464 (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: mD7Vmf7+XUCbI6myORIS5nfCE4G1i+/IUXxHIWVXEXkLxrc9YwPO9cmGPw5QHxzHFtx+baHYCUczcr2QXO/678SwATUwz9GtYDAnlFaQtzA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5336 Received-SPF: pass client-ip=40.107.22.112; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/27 16:37:50 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: kwolf@redhat.com, fam@euphon.net, 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, use separate bool for void functions - 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 | 55 +++++++++ include/block/generated-co-wrapper.h | 35 ++++++ block/Makefile.objs | 1 + scripts/coroutine-wrapper.py | 173 +++++++++++++++++++++++++++ 5 files changed, 272 insertions(+) create mode 100644 block/block-gen.h create mode 100644 include/block/generated-co-wrapper.h create mode 100755 scripts/coroutine-wrapper.py diff --git a/Makefile b/Makefile index 40e4f7677b..09e9b1875c 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..482d06737d --- /dev/null +++ b/block/block-gen.h @@ -0,0 +1,55 @@ +/* + * 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" + +/* This function is called at the end of generated coroutine entries. */ +static inline void bdrv_poll_co__on_exit(void) +{ + aio_wait_kick(); +} + +/* 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/generated-co-wrapper.h b/include/block/generated-co-wrapper.h new file mode 100644 index 0000000000..62c6e053ba --- /dev/null +++ b/include/block/generated-co-wrapper.h @@ -0,0 +1,35 @@ +/* + * Block layer I/O functions + * + * 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_GENERATED_CO_WRAPPER_H +#define BLOCK_GENERATED_CO_WRAPPER_H + +/* + * generated_co_wrapper + * Function specifier, which does nothing but marking functions to be + * generated by scripts/coroutine-wrapper.py + */ +#define generated_co_wrapper + +#endif /* BLOCK_GENERATED_CO_WRAPPER_H */ 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..c579d40946 --- /dev/null +++ b/scripts/coroutine-wrapper.py @@ -0,0 +1,173 @@ +#!/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 +from typing import Iterator + + +def prettify(code: str) -> str: + """Prettify code using clang-format if available""" + + try: + style = '{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, capture_output=True) + 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"\ +""" + + +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; + + bdrv_poll_co__on_exit(); +}} + +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 May 27 20:37: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: 281806 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 936D3C433DF for ; Wed, 27 May 2020 20:41:54 +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 4B6A3207BC for ; Wed, 27 May 2020 20:41:54 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="uxm8KK7M" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4B6A3207BC 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]:52268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1je2s5-0002fu-Gn for qemu-devel@archiver.kernel.org; Wed, 27 May 2020 16:41:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35252) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1je2oL-0004eL-A2; Wed, 27 May 2020 16:38:01 -0400 Received: from mail-am6eur05on2109.outbound.protection.outlook.com ([40.107.22.109]:23104 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 1je2oK-00080U-EF; Wed, 27 May 2020 16:38:00 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QjnYhiXqWjqztP1BP+u53e5c6i/QF+k8wGy7KbXrrTXOdLqqFkEWFODMNW5EOc/2zpGp3yBrZPIPWszVFJ1+MjG5gSdrCWd8vowitAxjYnYVOZokObT7oAbbrQUWlhbEoTa2IK5uQlM2CMAHcu+MChjywXUYwcvNkNdPdgVBd+T5rMLb2wKbgybLDMwdAoUEjDtyN8jmfXU4kiGyBkOBJe6VA1McBTyg097accBRaMP20ZGL5XCsm4pytWzuJxukbincRbDUXo8G0aAQv7lT7E5hHsGcxXCaH3kfvfmVXv3YKQwSn+MYDrbnHyqOPwzw9E6mIyb68RCs8orQktiIkQ== 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=Kk7/nXOXuMkO+z4xRJpFixMZOBdXmAi/XfA0tdLd9ig=; b=UygcD6QvTSrnhXLIgxz7owK14Untnl025Q+grGJ22P9l03g+b8mepfAZdr5AKrCEoKzBti2h9ucU1aPoI+1VFq4Sdv8hCsbgHOdH+3MFtTxf+eLt7+PqTlBXK66iY5os19TpEmb9O2LH6QYYiPz3L3ZhYQBKeIAFFcJLEbTVBBhXyiLGUZeejO9Mo+PlfTzw8YjUtZmeEPWtT5r4iIJU685HWXVolbghpB6av61Aq6H6i6K3z6sSBNZj3wV0vTNXaj9tRy/DsZFSA5Ik/7HBgg/paUOPxnf7IJRIPGEzYT3PkHWIufqBwxPHvsS4Pmgq8nOOcV5DecLtrxyD6DRdug== 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=Kk7/nXOXuMkO+z4xRJpFixMZOBdXmAi/XfA0tdLd9ig=; b=uxm8KK7MUoi4bFNCEfNsMdlLh9PwKia1+9Ryw/GADjMom8o/UwLoKR1Bk7SLnvmSZnHGBErVBvS2xgf8ZqwstRi2Nt9368oGk/GkS2rfOE+McJ5rYalcZDnEeg0ptlVeyBCeJgzPsogO2jozjbFkCt2mMBtbdhCVDLXPBZjxX7U= 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 AM7PR08MB5336.eurprd08.prod.outlook.com (2603:10a6:20b:105::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.24; Wed, 27 May 2020 20:37:54 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%4]) with mapi id 15.20.3045.018; Wed, 27 May 2020 20:37:54 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v5 6/7] block: drop bdrv_prwv Date: Wed, 27 May 2020 23:37:32 +0300 Message-Id: <20200527203733.16129-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200527203733.16129-1-vsementsov@virtuozzo.com> References: <20200527203733.16129-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM0PR10CA0101.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::18) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kvm.sw.ru (185.215.60.148) by AM0PR10CA0101.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.17 via Frontend Transport; Wed, 27 May 2020 20:37:53 +0000 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.148] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3f4058f9-7010-411f-b893-08d8027dd536 X-MS-TrafficTypeDiagnostic: AM7PR08MB5336: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1051; X-Forefront-PRVS: 04163EF38A X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2RMQx5+Y4RRai6x38TadlyC/5Gv7EH7JF6ofiOpfDf05lQZe24NzSavwhByy8oyqLOHtUgQVKXxrWQMrpREfRmwo+HKGCbyBba50scDi61Th1bA2a3EK2AewnBoGpkSo19yB52jotjQSV0OHqKuoxxJg8uIGuPjd2vw+r49bRHbdYfj1EU0oYgBok81/5OMKm8EpmT/+AM0260rqzB1JHIrEIi/QKejCwM6K3/UsC1/14oFbTIWty9s6dmj9Lhv2SCjsU4rS9faQs6cKWwYYDEJW5vUYBrTWQRUcK1OpxuRCPOhMX7BblymtJT1zyZ4C 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)(346002)(366004)(396003)(39850400004)(376002)(136003)(956004)(66556008)(66946007)(66476007)(8676002)(6486002)(6512007)(1076003)(478600001)(186003)(316002)(5660300002)(6916009)(2616005)(6506007)(8936002)(16526019)(26005)(2906002)(6666004)(83380400001)(36756003)(4326008)(52116002)(86362001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: tKYIWf0/n9nz4Yw/F1BMfodeENkB7/Pxp2DiWHFn/TWZF4SsJVNWwbWsda/Zxj/yn+jeGxAXGjBnyIsbIoSUbUvJ88SWfnU3bcVZD+OE+GYRNdSrc4rzzbbaOxaw0vmxkIYZdD0DB6q2X3pGntviMfsF2pfo081IUKsEamlMlWyCLrGIFURHFdL7byKuWpFaU7fsxYOkB/aY5TsOJKqNoEhyoJaH50FkJX0uCQKXCKyUzmvJTtFncmeoyoQ2CdQUcwOtfsjZYeJBXI9UtZB/XDQih/9EEvhRqxwu4tlO1Wfh9Zc2RFY7rfr2Q/oF3qlOVhrAXxMwUKoqPlTX4H6nc/Zm+n2CAk7d+vL5+TouRO6FHJ0uL5nsFTcshi+iEazsxT9uzpYSxXxs84ByCtHVWdyOYx96r6xwo1TmforFvjet54/1D69SOKhxt4NoBgVmI+0Ku5VEKisB2nUZvAMbN7ADZVw8Ulx+SAaR9MakxTc= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3f4058f9-7010-411f-b893-08d8027dd536 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2020 20:37:54.5933 (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: BllbVv/l8FqL5rRxW3ZlPrNMfdYaoyOqV5KCpu/SlS/oRG1WGeSXA78xDHMIPAIOF7aA9/0BAz1en+aH3/si+GIs/sAahCDRAA5NgYw8oDU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5336 Received-SPF: pass client-ip=40.107.22.109; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/27 16:37:56 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: kwolf@redhat.com, fam@euphon.net, 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 145a2d2645..56c0be6f8f 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -32,12 +32,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 46c8b7816e..dadb6e796f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -379,9 +379,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 f9700cc897..305ee7219a 100644 --- a/block/io.c +++ b/block/io.c @@ -892,23 +892,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); } /* @@ -952,41 +940,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: @@ -997,13 +963,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 */ From patchwork Wed May 27 20:37: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: 281805 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 08D3DC433DF for ; Wed, 27 May 2020 20:44:37 +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 C64FF20835 for ; Wed, 27 May 2020 20:44:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=virtuozzo.com header.i=@virtuozzo.com header.b="DLJ9rCI2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C64FF20835 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]:58434 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1je2uh-00065a-RK for qemu-devel@archiver.kernel.org; Wed, 27 May 2020 16:44:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35256) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1je2oM-0004hW-Fx; Wed, 27 May 2020 16:38:02 -0400 Received: from mail-am6eur05on2112.outbound.protection.outlook.com ([40.107.22.112]:57342 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 1je2oL-0007uz-JK; Wed, 27 May 2020 16:38:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=buc6J1SAiJowE9/OxwdoNgrkUK9EYikD4oHdwJHjUrdXikCc3JLajux/EgrgJ4IOFjSbgurdjlM9T9A4u/8lsrfDAOS07PUAiVg1Qg+wpO3iPtlzI+cSUDhElg1H854MJFMQc14MxOVjpe0IGz4IkjltGco1PP4PeVhfiM+998QUS6ZOxLRgOp/vS1p4EyoUIAtZCflEKMKrzJC9S1uu4ruIeDTFeOhwljDVoezg18K89r8XdHB/eN3ntJYkDe0q0RtuwGp/B6cNYPnuXz1h22dVTtw+0Dj8AjtNjurww17hMjDEK5stgGg1wUr91NL5UtiUgoOqGhWQiYML9qYzHg== 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=pr+GJNdchyYPHs5RK2uBet6LwgwPvfZ+Xutgzg2P2MA=; b=nlZ/KQ/iGzjLWbuRNcyLIbsmgCNOcfpVQ6wAfklgE9TgIUveaIZHMUtr8zbHQ88sx9YaIPcoU5kh3rGpfw2S3zQGMXj9LeaoxYvBZ+xNxTcsWKO5pPJbXAYV51EWsnhbKvXbtmBHCS3MivCoXbSefOwFkHVadkC94v/qEIssWZvGDrKgzOVcUpBt1/uNUUDaS/EpcCBasS/Po/A3L3T0zAxlN4gGP/xuUTczQX0/JifPsS9O1c3rhVxnWbfHHmhhJTQCIBRfJeLcHn9CUkis3JSP1SIqI8oASyc7jpWc4ApZGwrYQLMX15U7hraOoVIq4xT9K2apwUrxKNkn9BzLrg== 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=pr+GJNdchyYPHs5RK2uBet6LwgwPvfZ+Xutgzg2P2MA=; b=DLJ9rCI2oKrIryWjRfuLDVr4m4rTGb1T11ZLDUfElVbsnPN144JfvMo+6BBaFM12KyIKmjmwlyWWUuUyFGP9PggwwufP3fVovONpHgAt9VdkIPuLF62LswwDEYuFRKWW0W7+DUEexF4nPtdH0+NTlPGRcEuIkj65orW5Rs2n37k= 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 AM7PR08MB5336.eurprd08.prod.outlook.com (2603:10a6:20b:105::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.24; Wed, 27 May 2020 20:37:55 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::a408:2f0f:bc6c:d312%4]) with mapi id 15.20.3045.018; Wed, 27 May 2020 20:37:55 +0000 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v5 7/7] block/io: refactor save/load vmstate Date: Wed, 27 May 2020 23:37:33 +0300 Message-Id: <20200527203733.16129-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200527203733.16129-1-vsementsov@virtuozzo.com> References: <20200527203733.16129-1-vsementsov@virtuozzo.com> X-ClientProxiedBy: AM0PR10CA0101.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::18) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from kvm.sw.ru (185.215.60.148) by AM0PR10CA0101.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:208:e6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3045.17 via Frontend Transport; Wed, 27 May 2020 20:37:54 +0000 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.148] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3f17480e-e023-46a1-9af2-08d8027dd5bf X-MS-TrafficTypeDiagnostic: AM7PR08MB5336: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:153; X-Forefront-PRVS: 04163EF38A X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pKYWbF68LmdTIdGCV4aqpumMWSvcEnkWfw47nzPCspQuAK0e5BBQl/uJUZ4JupbtBbXPP7QmraNVYV7Hf4Mqf/Vfs+yr7CQFkWqeC5qcbFw/ws/gHw0Gmo7M71n+xkRMvG4XEjaus0/QxLGC/7Mr9mJDGwULKIW5rFTrOWTB1NQTI0425bLx1T+6Tt+oQFZAf2uAFS9wsZ3Rc70rth0RrGVuAt/1UVDojTtGXtSpSViySUIAbyczP1mnIqImx2BB8W36EEGDOon6rvzeD8SfO+QCqs7acVJe7qd1L+1WGh2eq8pSt2GG2cTK1wfXTRpYNpqDkDjvRmtbN2ZLa+cjLg== 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)(346002)(366004)(396003)(39850400004)(376002)(136003)(956004)(66556008)(66946007)(66476007)(8676002)(6486002)(6512007)(1076003)(478600001)(186003)(316002)(5660300002)(6916009)(2616005)(6506007)(8936002)(16526019)(26005)(2906002)(6666004)(83380400001)(36756003)(4326008)(52116002)(86362001); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: 5ca44NcNtDHYtFScqJVyCNAtjfwZw/TUdQZEiaM8GCAjfg5B62yt51luPogJlfxQDguW9Gya1GJp4VpVDINtbfeTWvvvdodIWW19Wk851nbOW7eYedvfh9Opb91bxUnMAGsNCHEyTTHZXqPNjp0YLA7tp8sW7tfie2K4ib0+Xf2Iw6pMTj6Nu07HHdh5Eo2eVM6XzoV7pp3gVPOJl9kJesO68dH0E1fuHYhGyTNmDvSMOBedEZpMaRj+KHipRQ4tgwkPxnfKAXGlaq/FIN9kO9mBoldQ3JYo8exhwPUm0BzIf56kQlg6O2LIK0RAXclHaJR9lzKfeEn4HD+UDXUsxQLOWDfb/sw1t9FBKzuK8U8feF+VnMziYomFo+jW05NuDwqCMb/PXhvcvpJNu1h4KwbFV4PJ7f1D+SgaGOCoa7mhwgwSwZRPjJnFgBw/Y3X9SVmUEkHwUhhbIQG/eGKGthfsnzrw6QYo6RBdSveq8nQ= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3f17480e-e023-46a1-9af2-08d8027dd5bf X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 May 2020 20:37:55.4804 (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: BaPlm/vXdv9N5xPN6+uuttNs2BmUS4pIcYz46W+8Vj2NBKLbpe4Eu8cZn35aVrJlBXGtRO1CEhi4Dg90kzjZ0qKcrJOXTJAfc4s5mbxyafA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5336 Received-SPF: pass client-ip=40.107.22.112; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/27 16:37:50 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: 5 X-Spam_score: 0.5 X-Spam_bar: / X-Spam_report: (0.5 / 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, RCVD_IN_SBL_CSS=3.335, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, URIBL_BLOCKED=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: kwolf@redhat.com, fam@euphon.net, 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" 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 --- 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 56c0be6f8f..7e14fdeccf 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -58,11 +58,9 @@ bdrv_common_block_status_above(BlockDriverState *bs, int64_t *map, BlockDriverState **file); -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); #endif /* BLOCK_COROUTINES_INT_H */ diff --git a/include/block/block.h b/include/block/block.h index dadb6e796f..cc2edbeb65 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -568,8 +568,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); -int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); -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); diff --git a/block/io.c b/block/io.c index 305ee7219a..8c1da3c335 100644 --- a/block/io.c +++ b/block/io.c @@ -2491,66 +2491,67 @@ int bdrv_is_allocated_above(BlockDriverState *top, } 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 pos) { BlockDriver *drv = bs->drv; int ret = -ENOTSUP; + if (!drv) { + return -ENOMEDIUM; + } + bdrv_inc_in_flight(bs); - if (!drv) { - ret = -ENOMEDIUM; - } else if (drv->bdrv_load_vmstate) { - if (is_read) { - ret = drv->bdrv_load_vmstate(bs, qiov, pos); - } else { - ret = drv->bdrv_save_vmstate(bs, qiov, pos); - } + if (drv->bdrv_load_vmstate) { + ret = drv->bdrv_load_vmstate(bs, qiov, pos); } else if (bs->file) { - ret = bdrv_co_rw_vmstate(bs->file->bs, qiov, pos, is_read); + ret = bdrv_co_readv_vmstate(bs->file->bs, qiov, pos); } bdrv_dec_in_flight(bs); + return ret; } -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 pos) { - QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, size); - int ret; + BlockDriver *drv = bs->drv; + int ret = -ENOTSUP; - ret = bdrv_writev_vmstate(bs, &qiov, pos); - if (ret < 0) { - return ret; + if (!drv) { + return -ENOMEDIUM; } - return size; -} + bdrv_inc_in_flight(bs); -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 = drv->bdrv_save_vmstate(bs, qiov, pos); + } else if (bs->file) { + ret = bdrv_co_writev_vmstate(bs->file->bs, qiov, pos); + } + + bdrv_dec_in_flight(bs); + + return ret; } -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 = QEMU_IOVEC_INIT_BUF(qiov, buf, size); - int ret; - - ret = bdrv_readv_vmstate(bs, &qiov, pos); - if (ret < 0) { - return ret; - } + int ret = bdrv_writev_vmstate(bs, &qiov, pos); - return size; + return ret < 0 ? ret : size; } -int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos) +int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf, + int64_t pos, int size) { - return bdrv_rw_vmstate(bs, qiov, pos, true); + QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, size); + int ret = bdrv_readv_vmstate(bs, &qiov, pos); + + return ret < 0 ? ret : size; } /**************************************************************/