From nobody Mon May 6 21:52:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1590401466; cv=pass; d=zohomail.com; s=zohoarc; b=cSHhLxjRZFSIoi60tvjrZzcE8vZlzOF30a3H3SKTHZOesBbH1gCXh6YZANV2b+7Lt5aa3Ec6ND9FWLxeBgp5GrAJIi3GLn7r0sEkCWadmSUsIKZekKMaR3gNkB4FlPDP+uxK0QhsENFpQ4dcXfG00IxKpI+mc6S70QiZetu3clw= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590401466; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=MngoYbInMWIY4ehHMSgf3rM/wNm2DvQ45ruocibDZzE=; b=C/kl8b/lSWxqqbhyGWUTGQUAMcmN1p9l6T8FhocGFAqxoABnEzrtubTvBx4T/2GVwRrsJZuG2s7IhNnuhFnIgGJexd5wF5w/atEqQuJ+fgIu1G8gNb18iCsqO8FQ+WnG0jbhv2dgboMza9BSSGBH0llEvPH9DQe2l/D3KOD4QGA= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159040146616351.911130539363285; Mon, 25 May 2020 03:11:06 -0700 (PDT) Received: from localhost ([::1]:44290 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdA4W-0004Fm-Qp for importer@patchew.org; Mon, 25 May 2020 06:11:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49594) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdA2o-0001j4-IZ; Mon, 25 May 2020 06:09:18 -0400 Received: from mail-am6eur05on2108.outbound.protection.outlook.com ([40.107.22.108]:58945 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 1jdA2n-0003zD-A3; Mon, 25 May 2020 06:09:18 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5464.eurprd08.prod.outlook.com (2603:10a6:20b:10a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.27; Mon, 25 May 2020 10:09:11 +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.3021.029; Mon, 25 May 2020 10:09:11 +0000 Received: from localhost.localdomain (185.215.60.147) by AM3PR04CA0143.eurprd04.prod.outlook.com (2603:10a6:207::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Mon, 25 May 2020 10:09:10 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HONP2ErLclXNtBx7mvxEshSYw1A/SHVg9VPp6r1+o23SoS9XLDCxw2/DeZFESOvDmzbPQNtZeJ4rfiBw0sRaZ2IKnCwXFvbmcVQQ0UYW9bvTWdudy6PlD/TB7tQHvQ1rdcIGcagzoGqfHcTF4uBJPH01piQrvVLs8pQZRmHRTQQMYzzyH74tFpy1iw0v9Ml/XlOESMLruL6Q/jldB1ddhGG8gyMAcmULeq0vCnZWMxPW6lNlGN1bxB2rKMpd7klu/UAPCLj+WUBO8VwQwEWxvVeZ1eAcaItD2jT0CmDfkgqHPVtFUw8Af7Gm//hvqV1G0XvdV9lOdiv4e7XNSxA5SA== 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=MngoYbInMWIY4ehHMSgf3rM/wNm2DvQ45ruocibDZzE=; b=haTxIaypAwKVZGAMOtWQBiByxgnwa1N3es5IiV90zLX9Uv8eaIVFb1QHDkkoLV5o0t5J64JUO3p5Glk+CLXQY2F/CTO6Verv3Eub8PNDmiBFAGvjd6bCoOo9uA8+KDYj1kiJaIe1+3vElO51qgENVIPsekMsk6SFry8BH09d2vwVoRQF9UdglonkS1ByrJaI7skjVsBv2P1x/+qms90t6dMD0Tg6wpmybNDaKQUKNlpBJeF2eBqaiLeQG3u9qiH77nFczJOlkuThJUs8njP1uJa2F5JwEV91DWHq7FLnp5ZDxLt4wFuTApbmWX9PXyScKRik0KyDRg6j1blVSyeDeg== 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=MngoYbInMWIY4ehHMSgf3rM/wNm2DvQ45ruocibDZzE=; b=k/PkExUZnPUGrZkxYxfr0gfUj244A6E2Lu1cllrzc/wFqGeCgnIHP4sacRE+t1zfB5YEY1C5OrPvjfO/c+KHK1xGUQf3BIsUPwwHBtz9GryiEmJc8bh32ez+V1Hex+5C48YNnqgh7Lc91zSPVHMzubR33jWXbtuu5MGEjzENX88= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 1/5] block/io: refactor coroutine wrappers Date: Mon, 25 May 2020 13:07:57 +0300 Message-Id: <20200525100801.13859-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200525100801.13859-1-vsementsov@virtuozzo.com> References: <20200525100801.13859-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM3PR04CA0143.eurprd04.prod.outlook.com (2603:10a6:207::27) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.147] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4042a46e-f747-4e90-3419-08d80093ab82 X-MS-TrafficTypeDiagnostic: AM7PR08MB5464: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:644; X-Forefront-PRVS: 0414DF926F X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rLMBeK8Hq3ibYj0/34rROeldoRjpQCWgJvNnniN1TOEirbxkph4aoAwTsVDeHeqN7M6ErbYrUKsmnrilEL+zy53ocuZx9t4uvXX9ZhSqCW+ppYRYwoHYEIEdxLfMJJvxdTGvGrtmjTN6uTBIxTvwJ6D9XgSUqqVP2V4TJ4g3sFN/4YcQgzotDaARbElysKon8rkjmXgGn3v5CLI/Ce/iULpmpJapaaFVHeKDnOOXoeZzWzj+QBK/mq5uIuN5JPpK1GmHMv1Ur5MGLmxBBIauzWbvlg5ElsVi6/SBcVfW6xZ8mc6ZGgrd4crFlan9pIm3P/CDeJ0yHNW7noU14XiAqiZjAkCv9Pb6vkuX1upWgM2d2WOI7ZJyz3zYKElmeukS 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)(396003)(39840400004)(376002)(366004)(136003)(6666004)(6486002)(1076003)(316002)(52116002)(26005)(69590400007)(6916009)(6512007)(478600001)(107886003)(8676002)(6506007)(2616005)(8936002)(86362001)(16526019)(186003)(36756003)(2906002)(66556008)(66946007)(4326008)(5660300002)(66476007)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: e4huy5aPChsyX8v7vgE9O5rHQc7OihapPcXOzTq7nI1/NkeY6CFk6/WXG1zhdvwnzHnFuhdSL2Y6xT8TLh8qyhlC+PtJLJBgS6aMmhMS5U8SpaXUguMp2y97lJA2MrRW/VZ6MJS5t/5JpGaWUJEUL3voHJ8OpQg0sQOUyIDp+ewnYuZwn5sqjtI+naFoe+m8UZOLL6ujQYGQGSHv7QYcuZc0z3hf4ZONtGsybGntx9j4yg9gG1cmC1h6RG9oihrpA1dHmOTn8XYpCca34VUgPiHGZYMXzlPIyCr8LbS20dqWzGngTUifDcnbr9kDFh//G4a4O6uGt8tJh3VYP1rwmlU2GJAubY/bRLebnC2PIc8V7pSDm6WcPXdseXFuHajndo0RzqVqUnj2zjU31rcQscGnaWUM3ld0a8tY8KSnmWwHn4NHoRb4zY6JXN8XstUMqEcYEn4sz8CeB+M38i3Iz44jjtn+ZiGBbyPeYBFvpL7Do7LwWTjd1b3cKuRH+DK4 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4042a46e-f747-4e90-3419-08d80093ab82 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2020 10:09:11.2944 (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: 7LNx39syzZ1/KJ5B9241I8Rn32JBhsz5ZOWuFBvQutrpMn+UadZYq9lnG57HZBLeea8P050C+d7MuDbOqMyiYGlR3Qif40UW5+gIb7nAfQ0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5464 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.22.108; 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/25 06:09:15 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Most of our coroutine wrappers already follow this convention: We have 'coroutine_fn bdrv_co_()' as the core function, and a wrapper 'bdrv_()' which does a polling loop. 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. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/io.c | 61 +++++++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 28 deletions(-) diff --git a/block/io.c b/block/io.c index 121ce17a49..bd00a70b47 100644 --- a/block/io.c +++ b/block/io.c @@ -900,28 +900,32 @@ typedef struct RwCo { BdrvRequestFlags flags; } RwCo; =20 +static int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, + QEMUIOVector *qiov, bool is_write, + BdrvRequestFlags flags) +{ + if (is_write) { + return bdrv_co_pwritev(child, offset, qiov->size, qiov, flags); + } else { + return bdrv_co_preadv(child, offset, qiov->size, qiov, flags); + } +} + static void coroutine_fn bdrv_rw_co_entry(void *opaque) { RwCo *rwco =3D opaque; =20 - if (!rwco->is_write) { - rwco->ret =3D bdrv_co_preadv(rwco->child, rwco->offset, - rwco->qiov->size, rwco->qiov, - rwco->flags); - } else { - rwco->ret =3D bdrv_co_pwritev(rwco->child, rwco->offset, - rwco->qiov->size, rwco->qiov, - rwco->flags); - } + rwco->ret =3D bdrv_co_prwv(rwco->child, rwco->offset, rwco->qiov, + rwco->is_write, rwco->flags); aio_wait_kick(); } =20 /* * Process a vectored synchronous request using coroutines */ -static int bdrv_prwv_co(BdrvChild *child, int64_t offset, - QEMUIOVector *qiov, bool is_write, - BdrvRequestFlags flags) +static int bdrv_prwv(BdrvChild *child, int64_t offset, + QEMUIOVector *qiov, bool is_write, + BdrvRequestFlags flags) { Coroutine *co; RwCo rwco =3D { @@ -949,8 +953,7 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, { QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes); =20 - return bdrv_prwv_co(child, offset, &qiov, true, - BDRV_REQ_ZERO_WRITE | flags); + return bdrv_prwv(child, offset, &qiov, true, BDRV_REQ_ZERO_WRITE | fla= gs); } =20 /* @@ -999,7 +1002,7 @@ int bdrv_preadv(BdrvChild *child, int64_t offset, QEMU= IOVector *qiov) { int ret; =20 - ret =3D bdrv_prwv_co(child, offset, qiov, false, 0); + ret =3D bdrv_prwv(child, offset, qiov, false, 0); if (ret < 0) { return ret; } @@ -1023,7 +1026,7 @@ int bdrv_pwritev(BdrvChild *child, int64_t offset, QE= MUIOVector *qiov) { int ret; =20 - ret =3D bdrv_prwv_co(child, offset, qiov, true, 0); + ret =3D bdrv_prwv(child, offset, qiov, true, 0); if (ret < 0) { return ret; } @@ -2443,14 +2446,15 @@ early_out: return ret; } =20 -static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - bool want_zero, - int64_t offset, - int64_t bytes, - int64_t *pnum, - int64_t *map, - BlockDriverState **file) +static int coroutine_fn +bdrv_co_common_block_status_above(BlockDriverState *bs, + BlockDriverState *base, + bool want_zero, + int64_t offset, + int64_t bytes, + int64_t *pnum, + int64_t *map, + BlockDriverState **file) { BlockDriverState *p; int ret =3D 0; @@ -2488,10 +2492,11 @@ static void coroutine_fn bdrv_block_status_above_co= _entry(void *opaque) { BdrvCoBlockStatusData *data =3D opaque; =20 - data->ret =3D bdrv_co_block_status_above(data->bs, data->base, - data->want_zero, - data->offset, data->bytes, - data->pnum, data->map, data->fi= le); + data->ret =3D bdrv_co_common_block_status_above(data->bs, data->base, + data->want_zero, + data->offset, data->byte= s, + data->pnum, data->map, + data->file); data->done =3D true; aio_wait_kick(); } --=20 2.21.0 From nobody Mon May 6 21:52:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1590401457; cv=pass; d=zohomail.com; s=zohoarc; b=e7qAAazisVWJHpIUl16xh79BXdIOzbinr0izVv2NbwZtksWYDbzf8zAknDnpBsf8FQ470l+LC3KfUiUHhWlRmDJY2OOok0NkhxC/mDEOjhrtw229EfGjKUo1CtGGB8y+ukw4qfhuGZXoNjK56Zjiil1S2d3OvQPn17NHBhQA+m8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590401457; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=GJo3Tdxyi8ASO50sVAm1KefW3miTRmTfyvdfJfHwxWM=; b=P7+fgHMIcJzitiDGFL5hg+QDdNdqvbvM3akhbq3lIzwQ4AfFN4SWeNp1ZZ/gqnX2oYF3iXHX0KSmLkku1TR+qsugGrceuWHd8COmMBv/gISQYIcFXIOCl7JhM8T9uaJcmJ7k02rOL0Y5lxzhvDON23Zfm1t/xwT+0lOBs7UsaSk= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590401457741398.0705835835912; Mon, 25 May 2020 03:10:57 -0700 (PDT) Received: from localhost ([::1]:43410 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdA4O-0003uE-CW for importer@patchew.org; Mon, 25 May 2020 06:10:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49602) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdA2q-0001nP-70; Mon, 25 May 2020 06:09:20 -0400 Received: from mail-am6eur05on2108.outbound.protection.outlook.com ([40.107.22.108]:58945 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 1jdA2p-0003zD-2G; Mon, 25 May 2020 06:09:19 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5464.eurprd08.prod.outlook.com (2603:10a6:20b:10a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.27; Mon, 25 May 2020 10:09:12 +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.3021.029; Mon, 25 May 2020 10:09:12 +0000 Received: from localhost.localdomain (185.215.60.147) by AM3PR04CA0143.eurprd04.prod.outlook.com (2603:10a6:207::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Mon, 25 May 2020 10:09:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l7dp+WiphCt0p/b6E8EiHkfHs/4zoFjfMZlMF65lrDK2VdBe2vr7yQg3iuQpvtJlyN62YWE0bpPLpsJlrnqNGp37AGsb9yuanSYddgYzPj8H8/8BQ0les67wxpeS74N+Gi6PH+SxDF9Gl0z1YRS36lIxpvS4+mXXal3738Yuztu1DFGT0V+/2EHLzr7dph8Ew0Y7q5tI0EDe/vVqHcH5pJjtyW84w6SO40MeDosjgoU/dac7bdVKSe+AOef7siKvt5vCIA/mMQ4xPJG+FQpTiWzCvuWnLQQ2SUdwAqpIe5tAHyDoQ3TuMjSV0F24/a8mwoRtVa+bOeetdSGYFHp3rg== 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=GJo3Tdxyi8ASO50sVAm1KefW3miTRmTfyvdfJfHwxWM=; b=bOP9J2XtxRPB8VxBR+/Jkues1iVQJuCxVVYbB6qd1dhFe/B7G+M19nStRXBtZ5/JsbQrZCoycNuhYpNeaSrZwET4G62nr6wUlz2y9BtoMpd/MMgYeRZAIi0NIP32acz2yVO97EHhvlARoMwsgyLCj2+6Z3JGnzXsjWDuChtJBylWN+leJtK1efCjD6T+1FpH8Wio1a7BpAt77jJ/7mBfVscttrs71gVM6CMwCaFE3fRg0jcoqVum58BoHBzja+DzODwwyJPmudfSmvgIi1H98ajqjHzh/7jaEuzZwT8wrKwkNprsHJLAa3T0oziYEaA1z8UZBNYRjctU+fziTfp/eQ== 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=GJo3Tdxyi8ASO50sVAm1KefW3miTRmTfyvdfJfHwxWM=; b=YKGkzXZFQ9DOU213g8CPlTdbvvfVbgG+DdA9Q0dkdeGIabfzPF1GGcLv6Yj4oWMdOMAwZb9HAnwE9XX2uSPoG+DuVo47kRE78J5qavLzYHKU6USF7/H1wBwAQTqVIvKNMvoqnbYSVslgKjVR0alXUm5cdX22NcTHajfL2uQC2TA= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 2/5] block: declare some coroutine functions in block/coroutines.h Date: Mon, 25 May 2020 13:07:58 +0300 Message-Id: <20200525100801.13859-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200525100801.13859-1-vsementsov@virtuozzo.com> References: <20200525100801.13859-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM3PR04CA0143.eurprd04.prod.outlook.com (2603:10a6:207::27) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.147] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 523f5596-048c-4ac8-dbed-08d80093ac28 X-MS-TrafficTypeDiagnostic: AM7PR08MB5464: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-Forefront-PRVS: 0414DF926F X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iXm83N0DSLrBQVkbaV/FfQHY9RwikT4lSa8Msa+PmP09Z191Y9IiS3jXCrpvf8mh/OoImQmjX71uPA3DqyTm/24xPERXQGiS3lF3bGBmk2VNdW/waZkjsIbYFNGYPpodWVOu3106dUEq4WCkp9DwpGtOfvwH+D0/SDT775bI9CDDlGZJeSImIBiKj6FOcE20X2rajrRr0AmN/QnqtcpB5dcUg6BAE6rdKhkqGjCHXI8loR65kCIwMU/qu8wGz3sTDEtNWi6ktuUIZ3cHoA0gMBgCoWav8JY8hWfPEzGUil3sB0UyLUHQIokYLVJxJ9U6cV8mH0RygscRZ9nimlYxD7+G3DinUDpBzjn/D9I5VSW8SCvzWDYTj5orUFasjFoH 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)(396003)(39840400004)(376002)(366004)(136003)(6666004)(6486002)(1076003)(316002)(52116002)(26005)(69590400007)(6916009)(6512007)(478600001)(107886003)(8676002)(6506007)(2616005)(8936002)(86362001)(16526019)(186003)(36756003)(2906002)(66556008)(66946007)(4326008)(5660300002)(66476007)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: cqXBAQrjR6egkPmaBCTFdLk9wXTCz49w/kd/vMHP3DyAyslUNgN9Kl+pXMy0laiSs1RNu6YM0ZJYjbRzJ0nyo8xBybe4QVJsflqwPw45M6Vbv0IU/3fvAwRe6Vb4oibuYsEvHoGvnmQvZkCmfrOH5OUAjrn17+0gtAuwDgYAVn3HSlZQ3a01ejsseE3wM17pQMArJRE8VWfbVKBzhj6dkX8Y46X0OXA49pQOR3ZNHxCJ0i/GvTqFxaqchDw5rwCwzNxLYGtY7L+BEUG1RgqGZCBZZcOD19ttEclvXTwLAUZTKM5w4Rnu7ZuSXBVqjJYIRFWDodZCAnHhQrRXkWQIxpsINS6vE1P0QQilnsjMjd0WKQ0YIqB891hBIDYLHBgzkDE++gR7wvsSaEL2BZ6hrDS93pCE2DV1+fJI7qlevlR+ih3lNMozHVazdNBEVHHuJb5RjGfs6go4cPrTYvDcJperQF03WsuCRuIInlrq9eA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 523f5596-048c-4ac8-dbed-08d80093ac28 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2020 10:09:12.3119 (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: vytboaSxcKvUSfw/5eEFdTOMvVO8zlxhTj1BNemWJg+/LloeIgQL5V3gR6qYMNm7rIOvGYM4f8lHSNuGkSREUMbjAmehSDgUS8xMk/3dwqI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5464 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.22.108; 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/25 06:09:15 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" We are going to keep coroutine-wrappers code (structure-packing parameters, BDRV_POLL wrapper functions) in a 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..74278cfef2 --- /dev/null +++ b/block/coroutines.h @@ -0,0 +1,67 @@ +/* + * Block layer I/O functions + * + * Copyright (c) 2003 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef BLOCK_COROUTINES_INT_H +#define BLOCK_COROUTINES_INT_H + +#include "block/block_int.h" + +int coroutine_fn bdrv_co_check(BlockDriverState *bs, + BdrvCheckResult *res, BdrvCheckMode fix); +void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **e= rrp); + +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 8416376c9b..7f06e82880 100644 --- a/block.c +++ b/block.c @@ -48,6 +48,7 @@ #include "qemu/timer.h" #include "qemu/cutils.h" #include "qemu/id.h" +#include "block/coroutines.h" =20 #ifdef CONFIG_BSD #include @@ -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 =3D=3D NULL) { return -ENOMEDIUM; @@ -5643,8 +5644,7 @@ void bdrv_init_with_whitelist(void) bdrv_init(); } =20 -static void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, - Error **errp) +void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **e= rrp) { BdrvChild *child, *parent; uint64_t perm, shared_perm; diff --git a/block/io.c b/block/io.c index bd00a70b47..f5b6ce3bf6 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" @@ -900,9 +901,9 @@ typedef struct RwCo { BdrvRequestFlags flags; } RwCo; =20 -static int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, - QEMUIOVector *qiov, bool is_write, - BdrvRequestFlags flags) +int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, + QEMUIOVector *qiov, bool is_write, + BdrvRequestFlags flags) { if (is_write) { return bdrv_co_pwritev(child, offset, qiov->size, qiov, flags); @@ -923,9 +924,9 @@ static void 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) { Coroutine *co; RwCo rwco =3D { @@ -2446,7 +2447,7 @@ early_out: return ret; } =20 -static int coroutine_fn +int coroutine_fn bdrv_co_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, bool want_zero, @@ -2506,12 +2507,12 @@ static void 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) { Coroutine *co; BdrvCoBlockStatusData data =3D { @@ -2638,7 +2639,7 @@ typedef struct BdrvVmstateCo { int ret; } BdrvVmstateCo; =20 -static int coroutine_fn +int coroutine_fn bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read) { @@ -2670,9 +2671,8 @@ static void coroutine_fn bdrv_co_rw_vmstate_entry(voi= d *opaque) aio_wait_kick(); } =20 -static inline int -bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read) +int bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, + bool is_read) { if (qemu_in_coroutine()) { return bdrv_co_rw_vmstate(bs, qiov, pos, is_read); --=20 2.21.0 From nobody Mon May 6 21:52:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1590401557; cv=pass; d=zohomail.com; s=zohoarc; b=TfLowSa3JP6Xo8vCFtXOb4OWacFdEJLOnxGm39iCf2CCCgMnpNRuslEq5BNHOpCpw1w2ACLwwxJT/VGiq5WnRVGizOWCkcpDDlM/v7aLRzx8AMOe54o4F8No2Q1Q6pIDQx+r+1NCQIXD58fPf5gexaL+PRe16vJyNLtmAUmck+M= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590401557; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ipfpRMpr+2IP+VFEVHCUdDjNAzMpc1C2taSBuzNlLeM=; b=M52fWrF/p+wDIkY1J3BMX7VFZJolNWwwncUz/AWDmouuhUXKQclNZRkJVKtKFfUxDsXJ5WGAuxwot+9dvICBMmuuZz3hStqGphVNZD25XN0CxS3wthAuoMR4aMjnTJ1wGTEohyOaTWrwALRIr3vOa6KBKmTWlp/W7qaY1ny9FT8= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1590401557525147.53945368011478; Mon, 25 May 2020 03:12:37 -0700 (PDT) Received: from localhost ([::1]:52020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdA5z-0007O4-NL for importer@patchew.org; Mon, 25 May 2020 06:12:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49612) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdA2t-0001uh-0C; Mon, 25 May 2020 06:09:23 -0400 Received: from mail-am6eur05on2108.outbound.protection.outlook.com ([40.107.22.108]:58945 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 1jdA2q-0003zD-OP; Mon, 25 May 2020 06:09:22 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5464.eurprd08.prod.outlook.com (2603:10a6:20b:10a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.27; Mon, 25 May 2020 10:09:13 +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.3021.029; Mon, 25 May 2020 10:09:13 +0000 Received: from localhost.localdomain (185.215.60.147) by AM3PR04CA0143.eurprd04.prod.outlook.com (2603:10a6:207::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Mon, 25 May 2020 10:09:12 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JRr2IKr5qc/zO81Sv2fEN89LCs+4SvE0iGGBOzBZyOi0ZQTCInXGIFMwf0HCn/bFR40e19uANQ5ikiTX4vYYEjNywU3/XbaxeuUKJsKgsQagT59Sue/FqBsO5VvXFyFhQABVRRhto4WhFef3kJKHqwsRgIOCYew1R38lGf8/QZhHMLj/zaKQoNcUer9kuhIDXl65hSqMpaWxaoSYVeEdjy7GC91dWOHxvHNomTAFQfscUFiqonWnwWRYGk92K1GLcNpcMnBq68dvRZilBx0RkHSGEqsCPCP9KDdpL+FfjadtO8CutTxiPncMPx+oCsLUUxaDYCxiw3+LzF3AaV3lgg== 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=ipfpRMpr+2IP+VFEVHCUdDjNAzMpc1C2taSBuzNlLeM=; b=nroyzDJsJms5mKrX1snxaFIlW00DXKAkLQ9YFlaGiyK84wQvamwYiQ0MxIhnOT2PLDHnfdVHL7Syzr21drSXwglu9wW0O1/MuCbvkX/T+3ltEpxpnyMjzS9Or1SpgD7FL1X55etVqjW9poErHJF4Eb5hu3/gNA3W+kYHDAN3UmQFFmgvXkhvzA4kT1G4o5EoDElKgNGBztjUIlL+pIylmv2Q72NO5pmuDCF1Qtyhr8i1E1vTJwdB6diuH1zuz6kt/PUIBA6egy4DGuyCWSOLODt0G3TRdTVYU5JVDp4KCVSPMcugZ8nTuUwJi1L09jR+b8KmPnHTm2B3aD/AJMLRDg== 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=ipfpRMpr+2IP+VFEVHCUdDjNAzMpc1C2taSBuzNlLeM=; b=c4BS2Nb5Zz+11/sRJfEOu8eF7XXZ8EuXkLayyNO5kRgClVsbSH/hqH75Py4NmPCsS4cszyMK75OyVGRvzGDwzcDwPK6rF834gXQBa9sQ+7vZwDN3hgt4417a20xRUaJKFWh9wEtWUxM5XwPTXGfYc72HAcsb+TGTi37l13oa9Lk= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 3/5] block: generate coroutine-wrapper code Date: Mon, 25 May 2020 13:07:59 +0300 Message-Id: <20200525100801.13859-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200525100801.13859-1-vsementsov@virtuozzo.com> References: <20200525100801.13859-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM3PR04CA0143.eurprd04.prod.outlook.com (2603:10a6:207::27) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.147] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d752cd47-9a4c-408a-5528-08d80093acad X-MS-TrafficTypeDiagnostic: AM7PR08MB5464: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3631; X-Forefront-PRVS: 0414DF926F X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ASwQyyS5cjShT5fLwEtcV6UNC59m0IgK17/igFuDnO4jx2Ieu6prSTiVlCjRQQp8Og+k6Wx/gm7B8Sp3Srvha4/UAyFwnL+6aDmH5gtSgVbOzHNOAs9GiKAmUgWQv2jUxfM+4FFW6Ib1kphkxSHYMtBPpUZdT1phnlYgGNz4aGE5vnruWQVmG88qRuNVp2GbHs2ZOFED+Ht+Z9FxD+JwOK8Bmzis2DPial3ewwsB8VAnyWNyWcvIcJEnVE3kt6vZwlnJbaOFeG52YqUHUYukINbeg2TRICsOg34ZZeiB2Lz7dchWbRmVYFuD8zp8ZgJK+9AYJP3SWH4CynraUG87t0ya139R3IeZ/RfsBq2+9alAocmg9SvOIAdKt9cdFU+Mooy4/iYc5aDU8eNh96M6bCDiDTd7bTmvmyf1iGv/3IkjPYmQQeIz3tgfhtsSytiZVYPLm1rI5WuTUQ6Y6DrmMd1/N7JlS9CgDCxmgKoa5hI= 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)(396003)(39840400004)(376002)(366004)(136003)(6666004)(6486002)(1076003)(316002)(52116002)(26005)(69590400007)(6916009)(6512007)(478600001)(107886003)(8676002)(6506007)(2616005)(8936002)(86362001)(16526019)(186003)(36756003)(2906002)(66556008)(66946007)(4326008)(5660300002)(66476007)(30864003)(956004)(2004002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: zHAUh2IO2ETruTmEVr64b++rY9pdfgIA2Bpq0pAImIwR5ZmkniogpAs/srEjxrKD8j3iZibEVQxwFj3OCe4rehByiQ/RcHkvlz9vVwVlGtY3Hn7QDwEjMy2dy3U+YYATYz1NMBEa1yAdkWp/nqJdQ/4CTU3VuwUxk6l3le5OfwQzwsj+htSEUMxWAOoyIektuONU2V3YwKl5egu+bqvz0P9zO5jEP7xK4sb71UISC1Qqb9KbRHdfjOKyDBd5pYaTAt6xLdozDV2agvLTpORhePhPeC39jYWMnsNl19Tq2VsSWpfjzUQU05Ur5Fd92Ok1kHEM79KEPMvBOswRdjbJb37gz0yLNoyCW955ChHVt8D80KW7hVIB5d0TqPHTvi+TC4s2MiNyMflbYxxkWJU9sh1kJT3WUt8yH2c6E548W83X3+3JDNM/2lUNp7HKwr3HAyc2KYJtbuYyn+WbpCJwHrAeU1i8iLCauUdchDcZL+E= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: d752cd47-9a4c-408a-5528-08d80093acad X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2020 10:09:13.3075 (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: YwLMA2PmwIK1foI9YU5UvRC1Uej7nKYH/mWFvC8GoYiIPlSkD1XZOnGyPmOn/+F0ZxjUK4WChJHHZV2ffRzKelk3WSXGsHThTnyMwCTVecY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5464 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.22.108; 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/25 06:09:15 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" We have a very frequent pattern of creating coroutine from function with several arguments: - create structure to pack parameters - create _entry function to call original function taking parameters from struct - do different magic to handle completion: set ret to NOT_DONE or EINPROGRESS, 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. Here: Functional part (BDRV_POLL_WHILE loop, aio_wait_kick()) moved to (non-generated) block/block-gen.h Mechanical part (arguments packing, different kind of needed wrappers) are generated from template by scripts/coroutine-wrapper.py to resulting file block/block-gen.c Signed-off-by: Vladimir Sementsov-Ogievskiy --- Makefile | 6 + Makefile.objs | 2 +- block/block-gen.h | 55 ++++++ block/coroutines.h | 7 +- include/block/block.h | 17 +- include/block/generated-co-wrapper.h | 35 ++++ block.c | 70 -------- block/io.c | 260 --------------------------- block/Makefile.objs | 1 + scripts/coroutine-wrapper.py | 168 +++++++++++++++++ 10 files changed, 281 insertions(+), 340 deletions(-) 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..ec15b8ea89 100644 --- a/Makefile +++ b/Makefile @@ -159,6 +159,8 @@ generated-files-$(CONFIG_TRACE_UST) +=3D trace-ust-all.c =20 generated-files-y +=3D module_block.h =20 +generated-files-y +=3D block/block-gen.c + TRACE_HEADERS =3D trace-root.h $(trace-events-subdirs:%=3D%/trace.h) TRACE_SOURCES =3D trace-root.c $(trace-events-subdirs:%=3D%/trace.c) TRACE_DTRACE =3D @@ -175,6 +177,10 @@ generated-files-y +=3D $(TRACE_SOURCES) generated-files-y +=3D $(BUILD_DIR)/trace-events-all generated-files-y +=3D .git-submodule-status =20 +COROUTINE_HEADERS =3D include/block/block.h block/coroutines.h +block/block-gen.c: $(COROUTINE_HEADERS) $(SRC_PATH)/scripts/coroutine-wrap= per.py + $(call quiet-command, cat $(COROUTINE_HEADERS) | $(SRC_PATH)/scripts/coro= utine-wrapper.py > $@,"GEN","$(TARGET_DIR)$@") + trace-group-name =3D $(shell dirname $1 | sed -e 's/[^a-zA-Z0-9]/_/g') =20 tracetool-y =3D $(SRC_PATH)/scripts/tracetool.py diff --git a/Makefile.objs b/Makefile.objs index 99774cfd25..8cb20f94c3 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -14,7 +14,7 @@ chardev-obj-y =3D chardev/ authz-obj-y =3D authz/ =20 block-obj-y =3D block/ block/monitor/ nbd/ scsi/ -block-obj-y +=3D block.o blockjob.o job.o +block-obj-y +=3D block.o blockjob.o job.o block/block-gen.o block-obj-y +=3D qemu-io-cmds.o block-obj-$(CONFIG_REPLICATION) +=3D replication.o =20 diff --git a/block/block-gen.h b/block/block-gen.h new file mode 100644 index 0000000000..11a44247b7 --- /dev/null +++ b/block/block-gen.h @@ -0,0 +1,55 @@ +/* + * Block layer I/O functions + * + * Copyright (c) 2003 Fabrice Bellard + * Copyright (c) 2020 Virtuozzo International GmbH + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef BLOCK_BLOCK_GEN_H +#define BLOCK_BLOCK_GEN_H + +#include "block/block_int.h" + +/* 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/block/coroutines.h b/block/coroutines.h index 74278cfef2..e2047697d6 100644 --- a/block/coroutines.h +++ b/block/coroutines.h @@ -26,6 +26,7 @@ #define BLOCK_COROUTINES_INT_H =20 #include "block/block_int.h" +#include "block/generated-co-wrapper.h" =20 int coroutine_fn bdrv_co_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix); @@ -34,7 +35,7 @@ void coroutine_fn bdrv_co_invalidate_cache(BlockDriverSta= te *bs, Error **errp); int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, bool is_write, BdrvRequestFlags flags); -int +int generated_co_wrapper bdrv_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, bool is_write, BdrvRequestFlags flags); =20 @@ -47,7 +48,7 @@ bdrv_co_common_block_status_above(BlockDriverState *bs, int64_t *pnum, int64_t *map, BlockDriverState **file); -int +int generated_co_wrapper bdrv_common_block_status_above(BlockDriverState *bs, BlockDriverState *base, bool want_zero, @@ -60,7 +61,7 @@ bdrv_common_block_status_above(BlockDriverState *bs, int coroutine_fn bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read); -int +int generated_co_wrapper bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read); =20 diff --git a/include/block/block.h b/include/block/block.h index 25e299605e..aed6ffcc4f 100644 --- a/include/block/block.h +++ b/include/block/block.h @@ -9,6 +9,7 @@ #include "block/dirty-bitmap.h" #include "block/blockjob.h" #include "qemu/hbitmap.h" +#include "block/generated-co-wrapper.h" =20 /* block.c */ typedef struct BlockDriver BlockDriver; @@ -398,8 +399,9 @@ void bdrv_refresh_filename(BlockDriverState *bs); int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool e= xact, PreallocMode prealloc, BdrvRequestFlags = flags, Error **errp); -int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact, - PreallocMode prealloc, BdrvRequestFlags flags, Error **e= rrp); +int generated_co_wrapper +bdrv_truncate(BdrvChild *child, int64_t offset, bool exact, + PreallocMode prealloc, BdrvRequestFlags flags, Error **errp); =20 int64_t bdrv_nb_sectors(BlockDriverState *bs); int64_t bdrv_getlength(BlockDriverState *bs); @@ -441,7 +443,8 @@ typedef enum { BDRV_FIX_ERRORS =3D 2, } BdrvCheckMode; =20 -int bdrv_check(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode f= ix); +int generated_co_wrapper bdrv_check(BlockDriverState *bs, BdrvCheckResult = *res, + BdrvCheckMode fix); =20 /* The units of offset and total_work_size may be chosen arbitrarily by the * block driver; total_work_size may change during the course of the amend= ment @@ -464,12 +467,13 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb); int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf); =20 /* Invalidate any cached metadata used by image formats */ -void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp); +void generated_co_wrapper bdrv_invalidate_cache(BlockDriverState *bs, + Error **errp); void bdrv_invalidate_cache_all(Error **errp); int bdrv_inactivate_all(void); =20 /* Ensure contents are flushed to disk. */ -int bdrv_flush(BlockDriverState *bs); +int generated_co_wrapper bdrv_flush(BlockDriverState *bs); int coroutine_fn bdrv_co_flush(BlockDriverState *bs); int bdrv_flush_all(void); void bdrv_close_all(void); @@ -484,7 +488,8 @@ void bdrv_drain_all(void); AIO_WAIT_WHILE(bdrv_get_aio_context(bs_), \ cond); }) =20 -int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); +int generated_co_wrapper bdrv_pdiscard(BdrvChild *child, int64_t offset, + int64_t bytes); int bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes); int bdrv_has_zero_init_1(BlockDriverState *bs); int bdrv_has_zero_init(BlockDriverState *bs); diff --git a/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"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#ifndef BLOCK_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.c b/block.c index 7f06e82880..c1132ab323 100644 --- a/block.c +++ b/block.c @@ -4640,43 +4640,6 @@ int coroutine_fn bdrv_co_check(BlockDriverState *bs, return bs->drv->bdrv_co_check(bs, res, fix); } =20 -typedef struct CheckCo { - BlockDriverState *bs; - BdrvCheckResult *res; - BdrvCheckMode fix; - int ret; -} CheckCo; - -static void coroutine_fn bdrv_check_co_entry(void *opaque) -{ - CheckCo *cco =3D opaque; - cco->ret =3D bdrv_co_check(cco->bs, cco->res, cco->fix); - aio_wait_kick(); -} - -int bdrv_check(BlockDriverState *bs, - BdrvCheckResult *res, BdrvCheckMode fix) -{ - Coroutine *co; - CheckCo cco =3D { - .bs =3D bs, - .res =3D res, - .ret =3D -EINPROGRESS, - .fix =3D fix, - }; - - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - bdrv_check_co_entry(&cco); - } else { - co =3D qemu_coroutine_create(bdrv_check_co_entry, &cco); - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, cco.ret =3D=3D -EINPROGRESS); - } - - return cco.ret; -} - /* * Return values: * 0 - success @@ -5721,39 +5684,6 @@ void coroutine_fn bdrv_co_invalidate_cache(BlockDriv= erState *bs, Error **errp) } } =20 -typedef struct InvalidateCacheCo { - BlockDriverState *bs; - Error **errp; - bool done; -} InvalidateCacheCo; - -static void coroutine_fn bdrv_invalidate_cache_co_entry(void *opaque) -{ - InvalidateCacheCo *ico =3D opaque; - bdrv_co_invalidate_cache(ico->bs, ico->errp); - ico->done =3D true; - aio_wait_kick(); -} - -void bdrv_invalidate_cache(BlockDriverState *bs, Error **errp) -{ - Coroutine *co; - InvalidateCacheCo ico =3D { - .bs =3D bs, - .done =3D false, - .errp =3D errp - }; - - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - bdrv_invalidate_cache_co_entry(&ico); - } else { - co =3D qemu_coroutine_create(bdrv_invalidate_cache_co_entry, &ico); - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, !ico.done); - } -} - void bdrv_invalidate_cache_all(Error **errp) { BlockDriverState *bs; diff --git a/block/io.c b/block/io.c index f5b6ce3bf6..f9700cc897 100644 --- a/block/io.c +++ b/block/io.c @@ -892,15 +892,6 @@ static int bdrv_check_byte_request(BlockDriverState *b= s, int64_t offset, return 0; } =20 -typedef struct RwCo { - BdrvChild *child; - int64_t offset; - QEMUIOVector *qiov; - bool is_write; - int ret; - BdrvRequestFlags flags; -} RwCo; - int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, bool is_write, BdrvRequestFlags flags) @@ -912,43 +903,6 @@ int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_= t offset, } } =20 -static void coroutine_fn bdrv_rw_co_entry(void *opaque) -{ - RwCo *rwco =3D opaque; - - rwco->ret =3D bdrv_co_prwv(rwco->child, rwco->offset, rwco->qiov, - rwco->is_write, rwco->flags); - aio_wait_kick(); -} - -/* - * Process a vectored synchronous request using coroutines - */ -int bdrv_prwv(BdrvChild *child, int64_t offset, - QEMUIOVector *qiov, bool is_write, - BdrvRequestFlags flags) -{ - Coroutine *co; - RwCo rwco =3D { - .child =3D child, - .offset =3D offset, - .qiov =3D qiov, - .is_write =3D is_write, - .ret =3D NOT_DONE, - .flags =3D flags, - }; - - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - bdrv_rw_co_entry(&rwco); - } else { - co =3D qemu_coroutine_create(bdrv_rw_co_entry, &rwco); - bdrv_coroutine_enter(child->bs, co); - BDRV_POLL_WHILE(child->bs, rwco.ret =3D=3D NOT_DONE); - } - return rwco.ret; -} - int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, BdrvRequestFlags flags) { @@ -2223,20 +2177,6 @@ int bdrv_flush_all(void) return result; } =20 - -typedef struct BdrvCoBlockStatusData { - BlockDriverState *bs; - BlockDriverState *base; - bool want_zero; - int64_t offset; - int64_t bytes; - int64_t *pnum; - int64_t *map; - BlockDriverState **file; - int ret; - bool done; -} BdrvCoBlockStatusData; - int coroutine_fn bdrv_co_block_status_from_file(BlockDriverState *bs, bool want_zero, int64_t offset, @@ -2488,56 +2428,6 @@ bdrv_co_common_block_status_above(BlockDriverState *= bs, return ret; } =20 -/* Coroutine wrapper for bdrv_block_status_above() */ -static void coroutine_fn bdrv_block_status_above_co_entry(void *opaque) -{ - BdrvCoBlockStatusData *data =3D opaque; - - data->ret =3D bdrv_co_common_block_status_above(data->bs, data->base, - data->want_zero, - data->offset, data->byte= s, - data->pnum, data->map, - data->file); - data->done =3D true; - aio_wait_kick(); -} - -/* - * Synchronous wrapper around bdrv_co_block_status_above(). - * - * See bdrv_co_block_status_above() for details. - */ -int bdrv_common_block_status_above(BlockDriverState *bs, - BlockDriverState *base, - bool want_zero, int64_t offset, - int64_t bytes, int64_t *pnum, - int64_t *map, - BlockDriverState **file) -{ - Coroutine *co; - BdrvCoBlockStatusData data =3D { - .bs =3D bs, - .base =3D base, - .want_zero =3D want_zero, - .offset =3D offset, - .bytes =3D bytes, - .pnum =3D pnum, - .map =3D map, - .file =3D file, - .done =3D false, - }; - - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - bdrv_block_status_above_co_entry(&data); - } else { - co =3D qemu_coroutine_create(bdrv_block_status_above_co_entry, &da= ta); - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, !data.done); - } - return data.ret; -} - int bdrv_block_status_above(BlockDriverState *bs, BlockDriverState *base, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file) @@ -2631,14 +2521,6 @@ int bdrv_is_allocated_above(BlockDriverState *top, return 0; } =20 -typedef struct BdrvVmstateCo { - BlockDriverState *bs; - QEMUIOVector *qiov; - int64_t pos; - bool is_read; - int ret; -} BdrvVmstateCo; - int coroutine_fn bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read) @@ -2664,34 +2546,6 @@ bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVecto= r *qiov, int64_t pos, return ret; } =20 -static void coroutine_fn bdrv_co_rw_vmstate_entry(void *opaque) -{ - BdrvVmstateCo *co =3D opaque; - co->ret =3D bdrv_co_rw_vmstate(co->bs, co->qiov, co->pos, co->is_read); - aio_wait_kick(); -} - -int bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read) -{ - if (qemu_in_coroutine()) { - return bdrv_co_rw_vmstate(bs, qiov, pos, is_read); - } else { - BdrvVmstateCo data =3D { - .bs =3D bs, - .qiov =3D qiov, - .pos =3D pos, - .is_read =3D is_read, - .ret =3D -EINPROGRESS, - }; - Coroutine *co =3D qemu_coroutine_create(bdrv_co_rw_vmstate_entry, = &data); - - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, data.ret =3D=3D -EINPROGRESS); - return data.ret; - } -} - int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, int64_t pos, int size) { @@ -2767,20 +2621,6 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb) /**************************************************************/ /* Coroutine block device emulation */ =20 -typedef struct FlushCo { - BlockDriverState *bs; - int ret; -} FlushCo; - - -static void coroutine_fn bdrv_flush_co_entry(void *opaque) -{ - FlushCo *rwco =3D opaque; - - rwco->ret =3D bdrv_co_flush(rwco->bs); - aio_wait_kick(); -} - int coroutine_fn bdrv_co_flush(BlockDriverState *bs) { int current_gen; @@ -2893,40 +2733,6 @@ early_exit: return ret; } =20 -int bdrv_flush(BlockDriverState *bs) -{ - Coroutine *co; - FlushCo flush_co =3D { - .bs =3D bs, - .ret =3D NOT_DONE, - }; - - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - bdrv_flush_co_entry(&flush_co); - } else { - co =3D qemu_coroutine_create(bdrv_flush_co_entry, &flush_co); - bdrv_coroutine_enter(bs, co); - BDRV_POLL_WHILE(bs, flush_co.ret =3D=3D NOT_DONE); - } - - return flush_co.ret; -} - -typedef struct DiscardCo { - BdrvChild *child; - int64_t offset; - int64_t bytes; - int ret; -} DiscardCo; -static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque) -{ - DiscardCo *rwco =3D opaque; - - rwco->ret =3D bdrv_co_pdiscard(rwco->child, rwco->offset, rwco->bytes); - aio_wait_kick(); -} - int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes) { @@ -3041,28 +2847,6 @@ out: return ret; } =20 -int bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes) -{ - Coroutine *co; - DiscardCo rwco =3D { - .child =3D child, - .offset =3D offset, - .bytes =3D bytes, - .ret =3D NOT_DONE, - }; - - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - bdrv_pdiscard_co_entry(&rwco); - } else { - co =3D qemu_coroutine_create(bdrv_pdiscard_co_entry, &rwco); - bdrv_coroutine_enter(child->bs, co); - BDRV_POLL_WHILE(child->bs, rwco.ret =3D=3D NOT_DONE); - } - - return rwco.ret; -} - int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf) { BlockDriver *drv =3D bs->drv; @@ -3460,47 +3244,3 @@ out: =20 return ret; } - -typedef struct TruncateCo { - BdrvChild *child; - int64_t offset; - bool exact; - PreallocMode prealloc; - BdrvRequestFlags flags; - Error **errp; - int ret; -} TruncateCo; - -static void coroutine_fn bdrv_truncate_co_entry(void *opaque) -{ - TruncateCo *tco =3D opaque; - tco->ret =3D bdrv_co_truncate(tco->child, tco->offset, tco->exact, - tco->prealloc, tco->flags, tco->errp); - aio_wait_kick(); -} - -int bdrv_truncate(BdrvChild *child, int64_t offset, bool exact, - PreallocMode prealloc, BdrvRequestFlags flags, Error **e= rrp) -{ - Coroutine *co; - TruncateCo tco =3D { - .child =3D child, - .offset =3D offset, - .exact =3D exact, - .prealloc =3D prealloc, - .flags =3D flags, - .errp =3D errp, - .ret =3D NOT_DONE, - }; - - if (qemu_in_coroutine()) { - /* Fast-path if already in coroutine context */ - bdrv_truncate_co_entry(&tco); - } else { - co =3D qemu_coroutine_create(bdrv_truncate_co_entry, &tco); - bdrv_coroutine_enter(child->bs, co); - BDRV_POLL_WHILE(child->bs, tco.ret =3D=3D NOT_DONE); - } - - return tco.ret; -} 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 +=3D crypto.o block-obj-y +=3D aio_task.o block-obj-y +=3D backup-top.o block-obj-y +=3D filter-compress.o +block-obj-y +=3D block-gen.o common-obj-y +=3D monitor/ =20 block-obj-y +=3D stream.o diff --git a/scripts/coroutine-wrapper.py b/scripts/coroutine-wrapper.py new file mode 100755 index 0000000000..72115f7dd8 --- /dev/null +++ b/scripts/coroutine-wrapper.py @@ -0,0 +1,168 @@ +#!/usr/bin/env python3 +# +# Generate coroutine wrappers for block subsystem. +# +# 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 re +from typing import List, Iterator + +header =3D '''/* + * File is generated by scripts/coroutine-wrapper.py + */ + +#include "qemu/osdep.h" +#include "block/coroutines.h" +#include "block/block-gen.h"''' + +template =3D """ + +/* + * Wrappers for $name$ + */ + +typedef struct $struct_name$ { + BdrvPollCo poll_state; + $fields$ +} $struct_name$; + +static void coroutine_fn $name$_entry(void *opaque) +{ + $struct_name$ *s =3D opaque; + + $assign_ret$$name$($args_from_s$); + + s->poll_state.in_progress =3D false; + + bdrv_poll_co__on_exit(); +} + +$ret_type$ $wrapper_name$($args_def$) +{ + if (qemu_in_coroutine()) { + $do_return$$name$($arg_names$); + } else { + $struct_name$ s =3D { + .poll_state.bs =3D $bs$, + .poll_state.in_progress =3D true, + + $initializers$ + }; + + s.poll_state.co =3D qemu_coroutine_create($name$_entry, &s); + + $do_return$bdrv_poll_co(&s.poll_state); + } +}""" + +# We want to use python string.format() formatter, which uses curly bracke= ts +# as separators. But it's not comfortable with C. So, we used dollars inst= ead, +# and now is the time to escape curly brackets and convert dollars. +template =3D template.replace('{', '{{').replace('}', '}}') +template =3D re.sub(r'\$(\w+)\$', r'{\1}', template) + + +class ParamDecl: + param_re =3D re.compile(r'(?P' + r'(?P.*[ *])' + r'(?P[a-z][a-z0-9_]*)' + r')') + + def __init__(self, param_decl: str) -> None: + m =3D self.param_re.match(param_decl.strip()) + self.decl =3D m.group('decl') + self.type =3D m.group('type') + self.name =3D m.group('name') + + +class FuncDecl: + def __init__(self, return_type: str, name: str, args: str) -> None: + self.return_type =3D return_type.strip() + self.name =3D name.strip() + self.args: List[ParamDecl] =3D [] + self.args =3D [ParamDecl(arg) for arg in args.split(',')] + + def get_args_decl(self) -> str: + return ', '.join(arg.decl for arg in self.args) + + def get_arg_names(self) -> str: + return ', '.join(arg.name for arg in self.args) + + def gen_struct_fields(self) -> str: + return '\n '.join(f'{arg.decl};' for arg in self.args) + + def gen_struct_initializers(self, indent: int) -> str: + sep =3D '\n' + ' ' * indent + return sep.join(f'.{a.name} =3D {a.name},' for a in self.args) + + +# Match wrappers declaration, with generated_co_wrapper mark +func_decl_re =3D re.compile(r'^(?P(int|void))' + r'\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=3Dm.group('return_type'), + name=3Dm.group('wrapper_name'), + args=3Dm.group('args')) + + +def struct_name(func_name: str) -> str: + """some_function_name -> SomeFunctionName""" + words =3D func_name.split('_') + words =3D [w[0].upper() + w[1:] for w in words] + return ''.join(words) + + +def make_wrapper(func: FuncDecl) -> str: + assert func.name.startswith('bdrv_') + co_name =3D 'bdrv_co_' + func.name[5:] + + has_ret =3D func.return_type !=3D 'void' + + params =3D { + 'name': co_name, + 'do_return': 'return ' if has_ret else '', + 'assign_ret': 's->poll_state.ret =3D ' if has_ret else '', + 'struct_name': struct_name(co_name), + 'wrapper_name': func.name, + 'ret_type': func.return_type, + 'args_def': func.get_args_decl(), + 'arg_names': func.get_arg_names(), + 'fields': func.gen_struct_fields(), + 'initializers': func.gen_struct_initializers(12), + 'args_from_s': ', '.join(f's->{a.name}' for a in func.args), + } + + if func.args[0].type =3D=3D 'BlockDriverState *': + params['bs'] =3D 'bs' + else: + assert func.args[0].type =3D=3D 'BdrvChild *' + params['bs'] =3D 'child->bs' + + return template.format(**params) + + +if __name__ =3D=3D '__main__': + import sys + + print(header) + for func in func_decl_iter(sys.stdin.read()): + print(make_wrapper(func)) --=20 2.21.0 From nobody Mon May 6 21:52:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1590401647; cv=pass; d=zohomail.com; s=zohoarc; b=QfJ6pkhJJ2RWq0LI0IZFHCHlLhloxOmKU6UxQ/0TY43lmd2KlKImEIkyte5pcndmCxWs41V0+TPT29Xrjx1lpV5Ec83GxoGXl78nkmVQMr4afrkWSUpIRlqCbYlENxse67WgOsBUhv2oamp5SKQ4asrQTYm8SQObD5D2uFr99wg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590401647; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=TIDXlTC6oJx92z3YcqpOVAhp6raRtWpa5HXBjbU3lZw=; b=U2538db4h24EIz1B4U0k0lsV0hPg0DKq//G/m2ujwndELR5Fn/YJyowFvPc6iLpeP8kC+ZIZMItgyI3R9P2hVvcVwkyBbz4N/RRyznjwX1O+K9YY+8aHkRyYwLP+kQmey3+pmGf3WBoQr0H7cnzl2AQhD4Bz2mHNl1zFwVy8shw= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159040164773315.756595775442406; Mon, 25 May 2020 03:14:07 -0700 (PDT) Received: from localhost ([::1]:58214 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdA7S-0001g7-Eo for importer@patchew.org; Mon, 25 May 2020 06:14:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49618) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdA2u-0001zI-I8; Mon, 25 May 2020 06:09:24 -0400 Received: from mail-am6eur05on2108.outbound.protection.outlook.com ([40.107.22.108]:58945 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 1jdA2t-0003zD-H6; Mon, 25 May 2020 06:09:24 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5464.eurprd08.prod.outlook.com (2603:10a6:20b:10a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.27; Mon, 25 May 2020 10:09:14 +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.3021.029; Mon, 25 May 2020 10:09:14 +0000 Received: from localhost.localdomain (185.215.60.147) by AM3PR04CA0143.eurprd04.prod.outlook.com (2603:10a6:207::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Mon, 25 May 2020 10:09:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nIBuLyTAuBPuCptGfEUhX8Y+MvfvBurDg31qvIWMKRfFSGET4vAnX4fbuRBXO1GDjVScDNDJ2A5LU3M+iPDaviIAAoUWN5uRhTdQWrhGE6rdMG7mMFcicg7Ooo1HVqXAfRHDvS44u5crN0KFevZ2JOpbUcjs+5f4/YMXtnkIu1ivl+7EN4yp5aw2z9KPmMOii+o1IgsvI8HZuWQpg6dSRtHaGYty9iGVBHHSoK0FKnGHvUkob8TEyaOEfcFAGtlTJQvS4YJUIsLJOnTqZZkgcFfJvHWlYS+kP4yBGRFTBhfrFaf0Jsbb+I3jjkfobMQxINiYtnODB/E7AA+nMJN/bQ== 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=TIDXlTC6oJx92z3YcqpOVAhp6raRtWpa5HXBjbU3lZw=; b=J4AyQrzPgQBWJJmrKnKDrqtr1pCYR9UzbXRgcTPo66W5XdTY8RLPz+Pus9eGo6XJt7y9X5ZkPd/WnjWgO7tKlNyJJqXoYq0YiwvOIHNJ9rn/aPjgboOOE7h0u8RImeuYCQljCpHH5R5Om5kelRr2q9S3DhddXDZuKGjNa0saEjYr8ItaqQ2RCIrJ1rvUeldSk5mFcrUn5lVF3+O5uHRiJp4MOO01cbXUqE41fZO8X0f672Zim3W/R4ncDJRHt0sxWAaLLNxtMaX2mEuDMRRatg3TJhUeDXxL/e8v1TqwwthE5yqsmAi7Sh7Zloj5Ok12zGsJGd7zbTnlFR8NYCbvDg== 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=TIDXlTC6oJx92z3YcqpOVAhp6raRtWpa5HXBjbU3lZw=; b=I+cdnQaXJZmLzkF4L6CE8RkCkxYpaA7jMgxpMwKaUyZDIP+RQPP+oTcV1gE25M6wWVvYbRSlZdhj+7qVEstUyxjwdaZ9F7MeVW2jOtERR6+A9gFQXQ1r5P44RnARNOh2HxDxjh5kQ6imwqr5BKPXefsZRn701nQbUq28rLvWl+w= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 4/5] block: drop bdrv_prwv Date: Mon, 25 May 2020 13:08:00 +0300 Message-Id: <20200525100801.13859-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200525100801.13859-1-vsementsov@virtuozzo.com> References: <20200525100801.13859-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM3PR04CA0143.eurprd04.prod.outlook.com (2603:10a6:207::27) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.147] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2ed49427-ae83-4599-5731-08d80093ad44 X-MS-TrafficTypeDiagnostic: AM7PR08MB5464: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:530; X-Forefront-PRVS: 0414DF926F X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rA7MkSd4JSSo1VlCFavZPl7aGN5GelQbWeafESMHPgyB4vlrou+MHjj4A1QoTNG3IZNFn4AvNn0u88ayoFLLgbOmJJdpZ/RzfEtdc4mx0CCUaZ1N8Cta/3GweEXcQgI4rKNQr5PxMKTtw3mlht3mr05x6PIz4g9KFuqCz0xnSVRqqdgkCh3jyHcSvfI5nRvsG7sFwbIetGsLTaTQ6rl2ZFP6KiffkqC9DZJ0IhgK6BpHLx7oc1ivfoBs9Xb9pttQiwHRta7s6xbLFNmk91DoaBt3W9/G+NXMht/ThoA9lDZXwT3R3M70jI9VG5FxNp03AirUPvBt6P5FqOYHc/pLBM23X03LSJW8aFE+BTi9FhOnBDU6TqHC14R25K8kjSQj 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)(396003)(39840400004)(376002)(366004)(136003)(6666004)(6486002)(1076003)(316002)(52116002)(26005)(69590400007)(6916009)(6512007)(478600001)(107886003)(8676002)(6506007)(2616005)(8936002)(86362001)(16526019)(186003)(36756003)(2906002)(66556008)(66946007)(4326008)(5660300002)(66476007)(956004); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: clP2xFiaZdeDd58ZVgP6a5PTr49QfTFdsgBxTA9acNBxhHhaBu6QJkyHjWpL0jOz4ZNikRpUxHnjM3g3zvRbAILwroFCveKIQlWFiYkXWaSFEXJBBy27DBk/dvE828ato7U+7DvND62V+0Q2MPKj9pTO05dI2PFpCr3nXEzDygJQChJ/MM2Fn5wi2UV+H85a+a8R1bgl/Q5a861dT04iilqwTBTmNXAR4xAJA03ZHH6tFtKXtcophCP3Tc4ppStFLmHEO+FMGwXpGhebGE380v+epTUFEevTFvJ4YMXjuRnkdBu/cPmWBHQMTe2RY6ppzXpme4cBGH2AlYyI41hHrMvK42BTwoBVXNfm1o6WoEujIS0bd1OLWMTjVbfGZCnqCPkPpBBaD2OGFG2qWiuLKcwR47RbBWCVaF/WXxvnmTxX2T1498ifHMld7XlSA1LeL76o9YwrdvMopAiVN0uc5fOn1ChFgveAJoKrKfsRToE= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2ed49427-ae83-4599-5731-08d80093ad44 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2020 10:09:14.1767 (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: GdcIdIzFAH7sjpqRvwTVe/95QGpAQi8Z30oq6dV6GQn5G25kP7JEeXjmV84XpddxhnHE09ScwuJZxmyv1QVgH2FKDtDbfb7Mi5uO5Cijxfs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5464 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.22.108; 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/25 06:09:15 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Now, when we are not more paying extra code for coroutine wrappers, there no more sence in extra indirection layer: bdrv_prwv(). Let's drop it and instead genereate 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. 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 e2047697d6..233b8b3694 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); void coroutine_fn bdrv_co_invalidate_cache(BlockDriverState *bs, Error **e= rrp); =20 -int coroutine_fn -bdrv_co_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, - bool is_write, BdrvRequestFlags flags); int generated_co_wrapper -bdrv_prwv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov, - bool is_write, BdrvRequestFlags flags); +bdrv_preadv(BdrvChild *child, int64_t offset, unsigned int bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags); +int generated_co_wrapper +bdrv_pwritev(BdrvChild *child, int64_t offset, unsigned int bytes, + QEMUIOVector *qiov, BdrvRequestFlags flags); =20 int coroutine_fn bdrv_co_common_block_status_above(BlockDriverState *bs, diff --git a/include/block/block.h b/include/block/block.h index aed6ffcc4f..dce99f8453 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 byt= es); -int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov); int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, const void *buf, int count); /* diff --git a/block/io.c b/block/io.c index 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; } =20 -int coroutine_fn bdrv_co_prwv(BdrvChild *child, int64_t offset, - QEMUIOVector *qiov, bool is_write, - BdrvRequestFlags flags) -{ - if (is_write) { - return bdrv_co_pwritev(child, offset, qiov->size, qiov, flags); - } else { - return bdrv_co_preadv(child, offset, qiov->size, qiov, flags); - } -} - int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, BdrvRequestFlags flags) { - QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes); - - return bdrv_prwv(child, offset, &qiov, true, BDRV_REQ_ZERO_WRITE | fla= gs); + return bdrv_pwritev(child, offset, bytes, NULL, + BDRV_REQ_ZERO_WRITE | flags); } =20 /* @@ -952,41 +940,19 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags= flags) } } =20 -/* return < 0 if error. See bdrv_pwrite() for the return codes */ -int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) -{ - int ret; - - ret =3D bdrv_prwv(child, offset, qiov, false, 0); - if (ret < 0) { - return ret; - } - - return qiov->size; -} - /* See bdrv_pwrite() for the return codes */ int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes) { + int ret; QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); =20 if (bytes < 0) { return -EINVAL; } =20 - return bdrv_preadv(child, offset, &qiov); -} - -int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) -{ - int ret; + ret =3D bdrv_preadv(child, offset, bytes, &qiov, 0); =20 - ret =3D bdrv_prwv(child, offset, qiov, true, 0); - if (ret < 0) { - return ret; - } - - return qiov->size; + return ret < 0 ? ret : bytes; } =20 /* Return no. of bytes on success or < 0 on error. Important errors are: @@ -997,13 +963,16 @@ int bdrv_pwritev(BdrvChild *child, int64_t offset, QE= MUIOVector *qiov) */ int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int byt= es) { + int ret; QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); =20 if (bytes < 0) { return -EINVAL; } =20 - return bdrv_pwritev(child, offset, &qiov); + ret =3D bdrv_pwritev(child, offset, bytes, &qiov, 0); + + return ret < 0 ? ret : bytes; } =20 /* diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c index 1107271840..1595bbc92e 100644 --- a/tests/test-bdrv-drain.c +++ b/tests/test-bdrv-drain.c @@ -1872,7 +1872,7 @@ static int coroutine_fn bdrv_replace_test_co_preadv(B= lockDriverState *bs, } s->io_co =3D NULL; =20 - ret =3D bdrv_preadv(bs->backing, offset, qiov); + ret =3D bdrv_co_preadv(bs->backing, offset, bytes, qiov, 0); s->has_read =3D true; =20 /* Wake up drain_co if it runs */ --=20 2.21.0 From nobody Mon May 6 21:52:46 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass(p=none dis=none) header.from=virtuozzo.com ARC-Seal: i=2; a=rsa-sha256; t=1590401450; cv=pass; d=zohomail.com; s=zohoarc; b=P08mjjCQuP6GHzG3uq+bEP6XhlzH8bdl+jhGZctvdB4E4VsWb2vtnPhsAV4V9PPDv5RMKEQXEQp3vaO1x8Gn2OtUEVg7p52qVcpwRX5oUq5ZkB3OjQcqyNh7HV8GyaQEM6GAeLSPHnRqHCHYSOZ73zeacTBcIH10eKTxoEiXs3Y= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590401450; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Ft2bnljl6qaPO1d7df0oPlVI+hNCPWKxsLlPln/hrQA=; b=Fsx2o33Y0Sov2qZRoY1pqs4+BSZqmQpzRPwKkg9jcvfykVcsE8U8kDRHIn8EGzf7m25nzntplcG8hu/TyDqt9hKKkatpRwJ12q0LPu8P/gDHXcuURCTniBBh4vDJkCP88L/vPEA04CW/KVahOkMH5KQAFqzrvwyneDcZwV7UF1c= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; arc=pass (i=1dmarc=pass fromdomain=virtuozzo.com); dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15904014507018.383262166266945; Mon, 25 May 2020 03:10:50 -0700 (PDT) Received: from localhost ([::1]:42630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jdA4H-0003VS-7P for importer@patchew.org; Mon, 25 May 2020 06:10:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jdA2o-0001is-8q; Mon, 25 May 2020 06:09:18 -0400 Received: from mail-vi1eur05on2099.outbound.protection.outlook.com ([40.107.21.99]:63329 helo=EUR05-VI1-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 1jdA2n-0003zE-CT; Mon, 25 May 2020 06:09:17 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5447.eurprd08.prod.outlook.com (2603:10a6:20b:10b::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.27; Mon, 25 May 2020 10:09:15 +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.3021.029; Mon, 25 May 2020 10:09:15 +0000 Received: from localhost.localdomain (185.215.60.147) by AM3PR04CA0143.eurprd04.prod.outlook.com (2603:10a6:207::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3021.23 via Frontend Transport; Mon, 25 May 2020 10:09:14 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iUxcRLHY5xdmwm4JeojFXRv2acgYGy+fyjwugOhSx0OFW7nrhYIkAgoMSSur/1Iige7vpKWLXVuPskir4rvxB0kFG6zTcoCGsOGr9EayOLjw5XEOSaGuD1cXbyFt1puGRj3WTswVo8hx4attXBYIj85/9UUSNgrMkCxcGUF4NhjB9khHJSRs1BM2IgUOxNX8CF9OCcZue6T7BZtDxom3ne0Ag87lNVkiyXZkOg6zZQiEWfzhU8X9USV831SPgB2vgkCgWkkrSNsMnpjPplwTLDLymD8KjWy2ENrhUA/gs7nyvQl8ixo7LRYGvBB5pRJD18tZRbPBQAa/la1m69owtg== 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=Ft2bnljl6qaPO1d7df0oPlVI+hNCPWKxsLlPln/hrQA=; b=gv/r+hD6WC4CBN/W5YnVflf6w73BRAKlcIpPDSZk7ivJL3bqr5BO0ONFOfp2XBAsdmhjLOSZS80jFJZEEBipBzfL32eWeOqFiI3WbeDB2uUBmGK7wGzm3I3fBwhoaZdPjnbC5Lbv4uIRhsiTEYivfmmQF5q+8DagJ83SsXfUoFo6klJJm86tis6ONbJ3KkoMHExbSaReieRdmUfDbqcXZJMWjYRKs6kLHBlHKzgc9aKoTf6dyFtcLYkn2dSiv2QOt9M00l9zisjfqAGeZAFwLeAfVOJOISYIjgNsw0Jy94ACO+A8yto+wPjxP5lTXy9wawvrwI6ThTubdz5H2O8fhw== 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=Ft2bnljl6qaPO1d7df0oPlVI+hNCPWKxsLlPln/hrQA=; b=nI3FThldO5GCtleJ2m6ogSJCMSl+G2B+oq3xLx6quc+zWcAe9r7ybe3sD0RuFE5Yd1or0wBDoaFQ3kO7SQw28czGZcfpLy3flXLUqc6G6m/eaYo5TRzWUdXbtvlxtOiRTlA7PGajU4NR577axXJVLH1BDSDw9uJOtB1bd/cezl4= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none;nongnu.org; dmarc=none action=none header.from=virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v4 5/5] block/io: refactor save/load vmstate Date: Mon, 25 May 2020 13:08:01 +0300 Message-Id: <20200525100801.13859-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200525100801.13859-1-vsementsov@virtuozzo.com> References: <20200525100801.13859-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: AM3PR04CA0143.eurprd04.prod.outlook.com (2603:10a6:207::27) To AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-Mailer: git-send-email 2.21.0 X-Originating-IP: [185.215.60.147] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e38bac9d-353f-4754-7c43-08d80093adca X-MS-TrafficTypeDiagnostic: AM7PR08MB5447: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:153; X-Forefront-PRVS: 0414DF926F X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: B6+dKYmvDT9RL0hjCSMI9cLojNitA/e5r0jxp9GmV7dCJQexEgcmZRQ3FzcC536MkFlSzN+LCJcXsnUh8E5Y3NyGppDGGQJ/FtEkNp9z0DXseN4+MZ9V6DyYexyZg3lnY7XQTWKFQhIZi77SPq0z7dpH9zJiNEsUFExi4sSw/3X+fkXkUVS5mxYXDFbYawa58sBy0KAJdNP3qZyMNcAV8pNC6yjRAk0FBaJ+sljHqf8zO+8mihlzaKYHvz0pngIjQ4jWq1FfXwQYSuoTWht6YLdKVZWhYV4ExmJLCo58FjN7t/YFmht3nIpGG7P0Y1KSXV5aHZioDU2/IRKOyOY7nTyc4DtcZWeeEGwIe+KYvNNspJB907R1A4kPx2WcbkBk 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)(396003)(39840400004)(376002)(136003)(346002)(366004)(69590400007)(26005)(16526019)(186003)(107886003)(6506007)(66946007)(66556008)(66476007)(956004)(2906002)(2616005)(52116002)(478600001)(6916009)(5660300002)(316002)(6512007)(6486002)(1076003)(6666004)(8936002)(36756003)(86362001)(4326008)(8676002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData: i3wOzbIBLTGWp9fDSX9xdmD+U1Pw3ZTt1SClchG2jntQVuY/I9bTN0N3m1c2zuvU6SNyqIeDKLJKhXyKlTBFMcAuz1Gsf1+kzxd7UuaJ6HqZj86lbA1H1qPLdC9dr9z5FmgAr2/8myeMgP/xkAskl/3GSPJH86OKq4crfEKPc0+aMfzR94q8L5upopuZ88jmQCYqhyg5piu19CZb7DAI3XUSprPr1z9Ul2Uhbu4bioemkjmMJx/jg8Fyv9Ib3+LDN5z+VvJesaw5cqNGdx6rM3cigrOxBoyzrD4s9Q2A+GZOhPCyhdX3MW0WEvPb4AJIlrdESBe37G7lbCokbVipY67xcfcEB3BPQuDi0Pu8J1u2yvwbkahdmY5b4Xrn+XDTa226M+8c0qba9lN2giietRVL2tjzISFbJf9jrn6ufz+41rLLxgAbnMWbQqqSqJgEsLPTM4GKLsD0z3HkX8M6y3PsUW3v6nA/+JG8O/PfNpk= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: e38bac9d-353f-4754-7c43-08d80093adca X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 May 2020 10:09:15.0598 (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: XJV7YwVnAmPyIgqQIp+lWm8ziYAp+BTJDxe4vdwy4MuF38UVR4rMgEKtZ/Yb8VihtnWV5yg4tQEiOG1cmU1sDRdHrFKtdxWwYWE2VPBAX84= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5447 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=40.107.21.99; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-VI1-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/25 06:09:15 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @virtuozzo.com) Content-Type: text/plain; charset="utf-8" Like for read/write in a previous commit, drop extra indirection layer, generate directly bdrv_readv_vmstate() and bdrv_writev_vmstate(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- 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 233b8b3694..fd0dd6a5e6 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); =20 -int coroutine_fn -bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read); -int generated_co_wrapper -bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read); +int coroutine_fn bdrv_co_readv_vmstate(BlockDriverState *bs, + QEMUIOVector *qiov, int64_t pos); +int coroutine_fn bdrv_co_writev_vmstate(BlockDriverState *bs, + QEMUIOVector *qiov, int64_t pos); =20 #endif /* BLOCK_COROUTINES_INT_H */ diff --git a/include/block/block.h b/include/block/block.h index dce99f8453..618c0b76b5 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); =20 -int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t p= os); -int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t = pos); +int generated_co_wrapper +bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); +int generated_co_wrapper +bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos); int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, int64_t pos, int size); =20 diff --git a/block/io.c b/block/io.c index 305ee7219a..8c1da3c335 100644 --- a/block/io.c +++ b/block/io.c @@ -2491,66 +2491,67 @@ int bdrv_is_allocated_above(BlockDriverState *top, } =20 int coroutine_fn -bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, - bool is_read) +bdrv_co_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t po= s) { BlockDriver *drv =3D bs->drv; int ret =3D -ENOTSUP; =20 + if (!drv) { + return -ENOMEDIUM; + } + bdrv_inc_in_flight(bs); =20 - if (!drv) { - ret =3D -ENOMEDIUM; - } else if (drv->bdrv_load_vmstate) { - if (is_read) { - ret =3D drv->bdrv_load_vmstate(bs, qiov, pos); - } else { - ret =3D drv->bdrv_save_vmstate(bs, qiov, pos); - } + if (drv->bdrv_load_vmstate) { + ret =3D drv->bdrv_load_vmstate(bs, qiov, pos); } else if (bs->file) { - ret =3D bdrv_co_rw_vmstate(bs->file->bs, qiov, pos, is_read); + ret =3D bdrv_co_readv_vmstate(bs->file->bs, qiov, pos); } =20 bdrv_dec_in_flight(bs); + return ret; } =20 -int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, - int64_t pos, int size) +int coroutine_fn +bdrv_co_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t p= os) { - QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, size); - int ret; + BlockDriver *drv =3D bs->drv; + int ret =3D -ENOTSUP; =20 - ret =3D bdrv_writev_vmstate(bs, &qiov, pos); - if (ret < 0) { - return ret; + if (!drv) { + return -ENOMEDIUM; } =20 - return size; -} + bdrv_inc_in_flight(bs); =20 -int bdrv_writev_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t = pos) -{ - return bdrv_rw_vmstate(bs, qiov, pos, false); + if (drv->bdrv_load_vmstate) { + ret =3D drv->bdrv_save_vmstate(bs, qiov, pos); + } else if (bs->file) { + ret =3D bdrv_co_writev_vmstate(bs->file->bs, qiov, pos); + } + + bdrv_dec_in_flight(bs); + + return ret; } =20 -int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf, +int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, int64_t pos, int size) { QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, size); - int ret; - - ret =3D bdrv_readv_vmstate(bs, &qiov, pos); - if (ret < 0) { - return ret; - } + int ret =3D bdrv_writev_vmstate(bs, &qiov, pos); =20 - return size; + return ret < 0 ? ret : size; } =20 -int bdrv_readv_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t p= os) +int bdrv_load_vmstate(BlockDriverState *bs, uint8_t *buf, + int64_t pos, int size) { - return bdrv_rw_vmstate(bs, qiov, pos, true); + QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, size); + int ret =3D bdrv_readv_vmstate(bs, &qiov, pos); + + return ret < 0 ? ret : size; } =20 /**************************************************************/ --=20 2.21.0