From nobody Fri Sep 20 22:16:19 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=1587998491; cv=pass; d=zohomail.com; s=zohoarc; b=EIPMD/4uGmnmNtgLFjv3r5VfRG+WntyBuCbqJwfl+TAAttFk2KPzbRkc3HyHUaekByNO5ZLClfWIVhSn3tTvtlqH6HdurBAD7z2CqMlrEgJ12U4GCvGje+QlWPU5D2yZGO7uvJrcr5iyVLuQRvRX4QdYmuZitPdEzQUBuUx3uIs= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587998491; 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=ErVBdh1cF9BloFlIPWQR4KJ9no3velI5wxrkcsnsz10=; b=lbe0AuEh+mZqDAcRLqoQcIJHC46DaJiGFwAbap/AIa9d4s7l5SA59qVXCTe8VU2Uk83e2hspABVheoaT/8AscxiYSmqKt1BB/cBU6j9bG/X8IMSLbmI6wCveKjuA+15C5phD+stM9TOc3DRHfI3q06GVU7CNsF5r9V6555BhH+k= 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 1587998491166337.9006616718847; Mon, 27 Apr 2020 07:41:31 -0700 (PDT) Received: from localhost ([::1]:48600 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4wp-0001zM-8K for importer@patchew.org; Mon, 27 Apr 2020 10:41:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56830) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4v3-00088d-T5 for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jT4v3-0007kC-7L for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:37 -0400 Received: from mail-am6eur05on2133.outbound.protection.outlook.com ([40.107.22.133]:24288 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 1jT4v1-0007iF-6c; Mon, 27 Apr 2020 10:39:35 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5527.eurprd08.prod.outlook.com (2603:10a6:20b:de::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Mon, 27 Apr 2020 14:39:31 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.020; Mon, 27 Apr 2020 14:39:31 +0000 Received: from localhost.localdomain (185.215.60.182) by FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Mon, 27 Apr 2020 14:39:30 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gtmSjwNeZY64L81+1zGxMwdXM60mQLbndKaCAXNcltdIyu4u5OJrtHOaD0YOgUaNg9pciqDcN71/rCcD2qn/pIRA3poZ3MVBtQQEdSD21R1t5plHj1up4mQHUBDnqnpIbziw6d+xAD0cMsVnnlw971+8laZdDEwtrZ01aIOct4wl8W4W8OogWK3Ye5ZhZCoovxwvmKtOp3iLMP9k4w/QwTbpdMCUnY9RTVJdn4YFUU1ruJbC9AKXKGfZVWNzXcMmy16KnxGrmyZy54Y4NJTtnbZ5Z2AV4V2wdHV2FYaNRe5o9Hwt9Po6o3QHPhxw7agFpj3N+SZM/ZHxTD+aeLADqg== 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=ErVBdh1cF9BloFlIPWQR4KJ9no3velI5wxrkcsnsz10=; b=gPfssuudhts8JQZe8K+LqW//JSxB3UuiUNfbAaK2On2hHE7bxhh6UfQ9WKIimRqguEw28AfA/CfRwgu/rrGIbkIqliQtlRIp1xen/uDMRI7n9KyQsJRddAT4WgsodVYWCyDaVdqtkv3VoCWfN3CsmMqrzSdmaFIUTe7YtcI8/x5BK1ss0paYYgISnZXhda4DxHFKyVzSfzyfbl0LVU7XYJHhFAAKUnNzIewwlI9VhqxBbkvReks3trV32wQ134kS0ftWz8nhV2Fo3svaigvynKXipomJl7Qdu8GEfZQLp3R5Sbjo/dCCzJYIE38oTbdcOOj1iTE8F+eNek+jSFM1sg== 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=ErVBdh1cF9BloFlIPWQR4KJ9no3velI5wxrkcsnsz10=; b=PwBQnxwi03Nge20My+bDPshC448qiPpMC7ayEUWMTwYNZ+E8YwqS2IvwrSe3YLqojJU87wW54dCrJSYpBGCmpbi7/LT+3+v29m5Y+u9EY4ith5oXSn9SvCLElXJYEGruFJYQOPNRQMo/jESSn9KJgpElQ2F8bp5dd4f7qyTLaMk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vsementsov@virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 1/9] block/io: refactor bdrv_is_allocated_above to run only one coroutine Date: Mon, 27 Apr 2020 17:38:59 +0300 Message-Id: <20200427143907.5710-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200427143907.5710-1-vsementsov@virtuozzo.com> References: <20200427143907.5710-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) 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.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a5f691e0-cb14-4127-3321-08d7eab8cbf5 X-MS-TrafficTypeDiagnostic: AM7PR08MB5527: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-Forefront-PRVS: 0386B406AA 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)(39840400004)(376002)(396003)(366004)(136003)(346002)(5660300002)(107886003)(316002)(2906002)(6512007)(478600001)(6486002)(66946007)(66476007)(66556008)(69590400007)(1076003)(2616005)(956004)(81156014)(16526019)(86362001)(6506007)(52116002)(186003)(36756003)(8676002)(8936002)(6666004)(26005)(6916009)(4326008); DIR:OUT; SFP:1102; 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: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Vr875pw0KFLFfNWddvBO0qpCI++kCvRvdgj293M0gsoygzPrtih9h/XbMyTBPnpO+heylPoYYDO0nGMBeYbzIA25YnT/Tka+RTunUPN7r9vMdUpcBG20QpdwGciOV1EIa3yu85dHmcbTlKCmbZIIaARc7kUjHATNpEfICaGcB4zPqb2g/quRng7nfSzQNXjTse8e4kO7+/uXzShhwddBrdu9FOnhtggedSdOC/bYqZPaf7OFXIm/S2P6QiX2R0N/sG5AH+HVZtabFsM+eztZAOX9QumRzeG7lnPpA1aFzo+Or2HYgmlw5WIoVpAS9D5ckUikXYTkalndYldEZUgTtKOfwkvzDDZBNCwrlMlwV1Bs8xD7eAEXwpJJxUotwMID6quryqZIvmPLqSereP/UXqivI09nBHIaATnyI3QCKnPkKfUPoPEsxa7c1BuWPkkmbQ7x0uB2QrHOXMf7sfOW+AbUVjeXQOcDzLCf/XyH1WK0PAyyOya+H82dtu8YmlFV X-MS-Exchange-AntiSpam-MessageData: Pay+4kQ4H0fJK1e5JriQyZVh6lxRQhMNhMiDEDzliHEpBT3gEHQQEq/i24OhJ0zCvz+CXOhA+0QDXaoOtQBASvDvDW65Oi7s17NIlrJZCShdiFjmkBPpbsG/g9a5t8TqLav3foFotkT/pwQRrtU1GkPwn14T+f82wLSx4zXvlmieXm2eqolhvQJ2y9AeBiCaPIbUZwkTM8u5+EQGtfPEt8PcGL2ubKrGqVwJqxEQoQnI6hn20qaEjrqlL/UIWhhfGkUMjoyiwABY3VEQWgB9CFQaGr9hQz4Ag1IxUxFN6b6GiVTgvGXPxWmzNk7RbN6Oc1F6gr9l57mSeX+jM4ExQs+khbcIVH1OPE16mwVcuGpC5GNkW8tYKG1WKitrM3RrHf/wAcqdoAdL3T1RKe4eHwgAX4OPyqKZPBpvIgKKhpNFhWAOtAM3OqRxBzDXiv1Y64AdcNTuE3MfdRE9iWZ0NQgZB783/Mif2oO4Y2US2cDytsdITmn7yL6t2DjzJnxg5bxwss61EFFD3cGFAjxdCppz3fEViPvIOm8o1xYLKOIpXyBzsRUdig7dkN5/ztrR1sOx8f0rDouG0ekqzdP/uAjfF18M0YXcScNzPbWfzb7KPvTEJZJkcKGAapJ4wJzEGC16gQ5dOR7l/gv+Z0jp/ZwXgG1OQbxPfpyzvKHBgDXSffVC/qniZ/K5EPDuMZ8/KB/qJPOyBvtiVpf4fpoVTE+Xyv88lEa/xQrMGTjcW8A3ZkD5hTvPiUnzMPfmznZLMjxtrXAotYY3cnqMIyjBxDxVQPHOf2euDsSSnqv2eLs= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: a5f691e0-cb14-4127-3321-08d7eab8cbf5 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2020 14:39:31.4404 (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: krA8otFK1fQlwC6ubbvbQE6aV94iffzoLCogxvNQQtMk1Z5xJ5Dwtcwf0BxfQfBY83hr6eFoAJGWvJxjlWDLzeOzZUnxtaGdb+36SiGu1W0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5527 Received-SPF: pass client-ip=40.107.22.133; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/27 10:39:31 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.22.133 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, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@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" bdrv_is_allocated_above creates new coroutine on each iteration if called from non-coroutine context. To simplify expansion of in_flight inc/dec sections in further patch let's refactor it. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/io.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 71 insertions(+), 5 deletions(-) diff --git a/block/io.c b/block/io.c index aba67f66b9..94ab8eaa0f 100644 --- a/block/io.c +++ b/block/io.c @@ -2482,6 +2482,22 @@ static int coroutine_fn bdrv_co_block_status_above(B= lockDriverState *bs, return ret; } =20 +static int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, + int64_t offset, int64_t bytes, + int64_t *pnum) +{ + int ret; + int64_t dummy; + + ret =3D bdrv_co_block_status_above(bs, backing_bs(bs), false, offset, + bytes, pnum ? pnum : &dummy, NULL, + NULL); + if (ret < 0) { + return ret; + } + return !!(ret & BDRV_BLOCK_ALLOCATED); +} + /* Coroutine wrapper for bdrv_block_status_above() */ static void coroutine_fn bdrv_block_status_above_co_entry(void *opaque) { @@ -2578,10 +2594,10 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState= *bs, int64_t offset, * but 'pnum' will only be 0 when end of file is reached. * */ -int bdrv_is_allocated_above(BlockDriverState *top, - BlockDriverState *base, - bool include_base, int64_t offset, - int64_t bytes, int64_t *pnum) +static int coroutine_fn +bdrv_co_is_allocated_above(BlockDriverState *top, BlockDriverState *base, + bool include_base, int64_t offset, int64_t byte= s, + int64_t *pnum) { BlockDriverState *intermediate; int ret; @@ -2595,7 +2611,7 @@ int bdrv_is_allocated_above(BlockDriverState *top, int64_t size_inter; =20 assert(intermediate); - ret =3D bdrv_is_allocated(intermediate, offset, bytes, &pnum_inter= ); + ret =3D bdrv_co_is_allocated(intermediate, offset, bytes, &pnum_in= ter); if (ret < 0) { return ret; } @@ -2624,6 +2640,56 @@ int bdrv_is_allocated_above(BlockDriverState *top, return 0; } =20 +typedef struct BdrvCoIsAllocatedAboveData { + BlockDriverState *top; + BlockDriverState *base; + bool include_base; + int64_t offset; + int64_t bytes; + int64_t *pnum; + int ret; + bool done; +} BdrvCoIsAllocatedAboveData; + +static void coroutine_fn bdrv_is_allocated_above_co_entry(void *opaque) +{ + BdrvCoIsAllocatedAboveData *data =3D opaque; + + data->ret =3D bdrv_co_is_allocated_above(data->top, data->base, + data->include_base, + data->offset, data->bytes, + data->pnum); + data->done =3D true; + aio_wait_kick(); +} + +int bdrv_is_allocated_above(BlockDriverState *top, BlockDriverState *base, + bool include_base, int64_t offset, int64_t byt= es, + int64_t *pnum) +{ + Coroutine *co; + BdrvCoIsAllocatedAboveData data =3D { + .top =3D top, + .base =3D base, + .include_base =3D include_base, + .offset =3D offset, + .bytes =3D bytes, + .pnum =3D pnum, + .done =3D false, + }; + + if (qemu_in_coroutine()) { + /* Fast-path if already in coroutine context */ + bdrv_is_allocated_above_co_entry(&data); + } else { + co =3D qemu_coroutine_create(bdrv_is_allocated_above_co_entry, &da= ta); + bdrv_coroutine_enter(top, co); + BDRV_POLL_WHILE(top, !data.done); + } + + return data.ret; +} + typedef struct BdrvVmstateCo { BlockDriverState *bs; QEMUIOVector *qiov; --=20 2.21.0 From nobody Fri Sep 20 22:16:19 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=1587999149; cv=pass; d=zohomail.com; s=zohoarc; b=d+KqaySjSlCoDFdBuu2GOogSTel0x5iBpqxedEcl5UhWDtn8CFTMKOGOUCYBwFQSazgeCwT8jVnjOjh46x6c/nXIZa8jF9hwviQxEvA8UaFUhv4NofeeDcKkjqV8hOwR1YxoFT5vNvMIJO6ulkrSSedYUW9jVWPYUrtqgPOsSxY= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587999149; 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=QQ35i0r1Bi+qYtXHM5DJG/eYdtQ4haVjHbJ4RnHcvlo=; b=KO2xXWxwTkGGz4rwSTRgoTmP1Z3yMdL0aKpCHS1NHYn09mbDTrUmjtH6neQMbI5N4907vXegGP4EFWRuHJS1gRibBjP01o8JKS0oGEVyMUggI0As+9ro9ooqRlIQU4t58xCTvF/a2duuu8Sw8mSAK87C0kjQVf6/2M4mTK33nN8= 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 158799914939815.966940067917562; Mon, 27 Apr 2020 07:52:29 -0700 (PDT) Received: from localhost ([::1]:49406 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT57T-0003zX-5e for importer@patchew.org; Mon, 27 Apr 2020 10:52:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56908) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4v9-0008IB-Ex for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jT4v9-0007n6-2Y for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:43 -0400 Received: from mail-am6eur05on2133.outbound.protection.outlook.com ([40.107.22.133]:24288 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 1jT4v2-0007iF-Ga; Mon, 27 Apr 2020 10:39:36 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5527.eurprd08.prod.outlook.com (2603:10a6:20b:de::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Mon, 27 Apr 2020 14:39:32 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.020; Mon, 27 Apr 2020 14:39:32 +0000 Received: from localhost.localdomain (185.215.60.182) by FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Mon, 27 Apr 2020 14:39:31 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bqgw13YjOu3tePzk6vc8BcghVTz2TLPkSYDa7AkDos8914VRUS1VczuIfABZq4sJkLblbz5WcO24Uu7J3DcINzBgyN6J/xgryawbgcZ+UeYexebAQMxpfUgXjb7j8HhsDBlWQbgkojzI/dyTS7bG7M4ixioLlj5shiIIVH6fkbUlUGypMlOPRJR0gtwsa2TR/tsl9EzaHFF6R9leX7CqFuDVpbrRinEQillYEJWJDWHPqLV6QF1B0zIBI+pbhkVnNokdETezKlWYJ5nLaivwsufZJJlIR3EmdZ/u/j6cY8OtqftCoHFjCXZ6MzAau4NVKywEf6Po1nBgGaLz+Xi5uQ== 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=QQ35i0r1Bi+qYtXHM5DJG/eYdtQ4haVjHbJ4RnHcvlo=; b=BNTDa6JHMhu1E4zdwrsCZAILP44Zj3TO5Tp1CenhjikOCDlAh8xgThDzvmZEpDd8i0QlPJr17eOFYadbMy0dHZ40+c0rw2ubRgpF7HTUuQ/a1NcWzZf3B3eZrHV7jxZZicfuEvK5+Lq4+tKccbMPlrlsQmsNYuMu5MbxkHXiBQWCWXBZMK8aNBG3H/jJ639EFZVbHL/bz2R0aRZ2c1W2DrfSL7yJd4Z++JStjkkpPW5owD6eqq0JmxIwAthyMRZFDXlizu4p28r5dW2noNn0lhZ0O0pgvdqJBgz+nnRpc9q/ReYQbaSiLfPGLgQIKROcVeYEhAbvew/9shZIZccsSA== 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=QQ35i0r1Bi+qYtXHM5DJG/eYdtQ4haVjHbJ4RnHcvlo=; b=rHFIcAJyLLqVT0I1jC7DYj6We0J/CoQAqhnDU8+lfkxuamMjrQATmgzW1I5Z3LcnzIXwlWbu+Xqp88zYU2zTjlZiEQTXpRLEvHJgZsMxGL7ToN2UORQ/KN3aGydc+qNdanEmJyiy2tFPPFaA8sKjFek/1QxScO+MOQVWN8zrHCI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vsementsov@virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 2/9] block/io: refactor bdrv_co_ioctl: move aio stuff to corresponding block Date: Mon, 27 Apr 2020 17:39:00 +0300 Message-Id: <20200427143907.5710-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200427143907.5710-1-vsementsov@virtuozzo.com> References: <20200427143907.5710-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) 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.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ea764120-0a4d-4542-4abd-08d7eab8cc67 X-MS-TrafficTypeDiagnostic: AM7PR08MB5527: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:901; X-Forefront-PRVS: 0386B406AA 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)(39840400004)(376002)(396003)(366004)(136003)(346002)(5660300002)(107886003)(316002)(2906002)(6512007)(478600001)(6486002)(66946007)(66476007)(66556008)(69590400007)(1076003)(2616005)(956004)(81156014)(16526019)(86362001)(6506007)(52116002)(186003)(36756003)(8676002)(8936002)(6666004)(26005)(6916009)(4326008); DIR:OUT; SFP:1102; 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: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SlGGn+8trawMJ1j1+ECWfuyuE6a0Y/Obd9gx5PmLfsQfEwRm9zwAhxhp0C/MRoth3tCk8+E2or8CFRRLq027TsaPruTKdTJNXhvWXmTrmkSkTaQMyiX2QC8ioO2FtjeLvJ3K/i/B0IqyFz/owdBIGVHQSvwZPcK6rvGaIgHPAR51w82lT3OW3lOt4nPwqyPqt0QNnK5wd844GNgUNYp4IPcjRQMkMrjMEO/NlfDAENYDK796OhFc6+DI24Ghiq93RnHvkaBY+tPZfa2J5Qy/8oJr5NPAU6Hb3Mipo+DzZvDUgitz1UPyLRLExISNG9yOgwWEoV0K84Ez/hjsDhDdAZh2pxKMsaccUChNaz/m993vI8ThL5HrHaTJKC9ozoQkMnFr6lsw5gETHNuXtIgUnCDLkDcQ+TxS2VwERISxXsV2Ti4Hhp+cEl/OE7nfREku1XK7ev597atb41AOx39p5r28xPhDgEunf1aTSOIwqzcBbAw1rOuEahU7uTyWn6Vw X-MS-Exchange-AntiSpam-MessageData: Vc/ZRYpeKUTae1FRA1A8vThd2awi/AEUaQZP4tqEuKxgpGbmj3EMdDLxzibOcTt0q7vCpJDQ9MjkVX7cabp42DJSCoz0xNLViaxhAzW9d9XpIjbTkJY20SHeZg+gevdXIrn9eIhPdIG4fftD3hReeGhFju43jYNKmFMN25Re5oITEpUvIAFAPjv3yF/trNtWLmLh4ECE1xB9dK9PrmIfASLbnlk5M8yikVetZAIIt9YdBXL2Yfkrd4sS6C4+3qaTjpldgwbKprsORUOGbnmbKOo66R7pmEYrZ/XH2utGCvM9Hf1ubYynji6ftpbpBtGfjvQu/1F6WYjFQ3ZIJaGsdeozzbpsZ2MALRfdkEYgKLhRGaTF8oibbDjhADSPqPVnUSA8SEHGlQCnmjNSpOC3nB7vMsBF3AckYhNmxSI7v0457lcW2KEfs37BXloleSjCk2Z7g0apB0yBuw8ST2vOshxjy/OWtSNQY8jKLH/gCgrNNRooc9laQUqstyWvrLiT2qndiM+epyyGjzozZFQM08pJL9bfcFYqVQ3phSSKxuIZv6u9nGFVDRqAABIHW/orXRG+L/EL8tCkGG+CyCCmxhKccJN36/BQSjPIFSGAL/dF8vjDOqIF39xBtqnV6KiwibEYkpWUZcs7A371mKh+ojB56KThUy5k1p5oxng+8zTiPXCTc0fardgdd0VN7NAV9K7MfeeE1qmEsCpBaNL2IOouF4ohgO2GmQFhNCxAL6/MDI2aPvG/lVqTn74jiw4aq6QA9LkU4fT8fUyCZh3tw0eqiLNuEv/gnAewU/wmUmA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ea764120-0a4d-4542-4abd-08d7eab8cc67 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2020 14:39:32.1652 (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: Q78Zrt3HWueWGKHxSns/u8IBMrlSFgb0anKAMXLEHViIMRT9uBz4Gw5hW9QHm17j53/9oEKdh9ILgK5Kd1AxbVUiOKrUHDt9OL9xVRPOBkY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5527 Received-SPF: pass client-ip=40.107.22.133; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/27 10:39:31 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.22.133 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, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@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" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Stefan Hajnoczi --- block/io.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/block/io.c b/block/io.c index 94ab8eaa0f..880871e691 100644 --- a/block/io.c +++ b/block/io.c @@ -3125,31 +3125,38 @@ int bdrv_pdiscard(BdrvChild *child, int64_t offset,= int64_t bytes) =20 int bdrv_co_ioctl(BlockDriverState *bs, int req, void *buf) { + int ret; BlockDriver *drv =3D bs->drv; - CoroutineIOCompletion co =3D { - .coroutine =3D qemu_coroutine_self(), - }; - BlockAIOCB *acb; =20 bdrv_inc_in_flight(bs); + if (!drv || (!drv->bdrv_aio_ioctl && !drv->bdrv_co_ioctl)) { - co.ret =3D -ENOTSUP; + ret =3D -ENOTSUP; goto out; } =20 if (drv->bdrv_co_ioctl) { - co.ret =3D drv->bdrv_co_ioctl(bs, req, buf); + ret =3D drv->bdrv_co_ioctl(bs, req, buf); } else { + CoroutineIOCompletion co =3D { + .coroutine =3D qemu_coroutine_self(), + }; + BlockAIOCB *acb; + acb =3D drv->bdrv_aio_ioctl(bs, req, buf, bdrv_co_io_em_complete, = &co); if (!acb) { - co.ret =3D -ENOTSUP; + ret =3D -ENOTSUP; goto out; } + qemu_coroutine_yield(); + ret =3D co.ret; } + out: bdrv_dec_in_flight(bs); - return co.ret; + + return ret; } =20 void *qemu_blockalign(BlockDriverState *bs, size_t size) --=20 2.21.0 From nobody Fri Sep 20 22:16:19 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=1587998484; cv=pass; d=zohomail.com; s=zohoarc; b=F25mfdWAOAXf234g3R8YcOz/Ae/FsXSGDhM84BQUC3cRRmRcaEPKVerkQN/0VQOC1tBKfgeekZhbXWhtfcr32Xyxwo3/D/nUlnrWXgNOMjPTZWa+Cs+8I10Mvc42Z2EMiWYH4GhypJ5O6w3HXMjBwGlYz/fXgFAstWa/eBqgMgc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587998484; 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=+Tp/lNrp4pa6NXDHRAe0wN6lAiaVRIBuOBnYuWH7cs4=; b=KHdI5G3y5JSroI0YqhREhWXIV/j3y4HPQoLgzlwjSvnOp/JmOZ6y3x262oo8DjdYCj/TCRQgxK/+6mVJNaZh/CgHO40Pm45fMTk/ibOZbYlgcxGWiqf3YuMx2oBLLSVG281duC2+RbGasuvOhc5yN1n3rVHAVSBR3dHTswj0l8w= 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 1587998484681681.2632995488877; Mon, 27 Apr 2020 07:41:24 -0700 (PDT) Received: from localhost ([::1]:48591 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4wj-0001ph-5E for importer@patchew.org; Mon, 27 Apr 2020 10:41:21 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56842) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4v4-00089L-AM for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jT4v3-0007kR-Ri for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:38 -0400 Received: from mail-eopbgr40124.outbound.protection.outlook.com ([40.107.4.124]:49833 helo=EUR03-DB5-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 1jT4v1-0007iT-9D; Mon, 27 Apr 2020 10:39:35 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5336.eurprd08.prod.outlook.com (2603:10a6:20b:105::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Mon, 27 Apr 2020 14:39:33 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.020; Mon, 27 Apr 2020 14:39:33 +0000 Received: from localhost.localdomain (185.215.60.182) by FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Mon, 27 Apr 2020 14:39:32 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Yx2DnubE9R6Rlt7g/9roIxuOhmC/icVy7glRoD9KcFZrqtb/nNz9DZK9hLQSJvNkDtzHuhg04pqsmvwY899cKCFSr0148PcSVeCbyDKCvN6a+Be3zTyNv2LoEsww4hWA4mWVvZN/os8NVg76NSaqIkC/RE73DJ3bVuA0PjuCindWlJmbGq9WYvC3r8wf6SNQkdNEpYbI+RLlE2quicNp8q7gOt24q6Bp9j/3+wqAjcLn1n0wYCvZ2jfoJxkd9mXyUz6rR04Qxc5UoBL4+5ahMaLIjChekLf1PIEzJ46ii4HquQu1/2LTVawssTSCsS1UROh0dNhrz7GtOi5boVDVGA== 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=+Tp/lNrp4pa6NXDHRAe0wN6lAiaVRIBuOBnYuWH7cs4=; b=nu1zKfZUlnNlt0euh6np8R/gTH0+yUbz8zN/tNw10qyd6WvshOliscp0jww8VxD17zuuEOzfOS1GCItN5OKnRrPqM81ClNl/LqTkuSNyHsTzrgPPuuzZDzRp9enJV+q26aL0JoHo8wciSluzw2rf+IoX6DsxuzyM7oFPdWOKjCzJDMZRK/V+xHD2UCpwbPHmwAybu6DRvVdo29NGfQFjNU3eqYfU/7mou8LG13L3ciztwzDQ5njWvcsgX3fwy0tBt0CNIhxq+invelz10oj5//SKIEa+MFohAMVLnraqWS1I5NrWHYlH51R0PTFVXnyHSiJZefXHUplwjz3HXJ3dZw== 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=+Tp/lNrp4pa6NXDHRAe0wN6lAiaVRIBuOBnYuWH7cs4=; b=YS9ow0G/RtWp+W7QANmuBdRvVm61I0G+rkbVGv9yUfoRXsje+QChu7y5NDm+HJ/urpxU4lI9HWK0Eazhx0nTYsRKNJnE5CIAOz80VTxxs37uzx34O8vhNiQgXu4AMeZDT9OVj9js36nOfOJj+oOXb24Viivopgq7zK7Y+JJfaKk= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vsementsov@virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 3/9] block/io: move flush and pdiscard stuff down Date: Mon, 27 Apr 2020 17:39:01 +0300 Message-Id: <20200427143907.5710-4-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200427143907.5710-1-vsementsov@virtuozzo.com> References: <20200427143907.5710-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) 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.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 47d9a031-ffe9-41a5-1196-08d7eab8cce0 X-MS-TrafficTypeDiagnostic: AM7PR08MB5336: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:248; X-Forefront-PRVS: 0386B406AA 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)(376002)(136003)(346002)(366004)(39840400004)(478600001)(52116002)(6916009)(2616005)(956004)(4326008)(8676002)(36756003)(107886003)(6666004)(5660300002)(2906002)(316002)(66476007)(6486002)(66946007)(6512007)(8936002)(69590400007)(186003)(6506007)(66556008)(16526019)(26005)(86362001)(1076003)(81156014); DIR:OUT; SFP:1102; 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: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Zz7KO/VoX7ZtrOij+B5VMurGtIXXRzIFDeqmkWwedfoUpqoMB7gDGylA2BHU3mn+p9evtNUz0qphe8Hpj9mjDEtpWZUsUWEKBLuryr8wsTxHC2we3a9nH23p1Gj9uW1sh2pHf+CDkccVJ7U2llQu9KWVJHXc12SqLEYniQrWSTQ8XY2wQ4/TtnR0y4kH+r4qYlJCFovj3wQxDhgwlM/QgZ8A9r4GuCgoVqe+9UPD/RE1fSG7+5UrJ4qMqkrw8tK9ruMnuYfiUyddGSoG4Fys5kBw+lTX/evpUDESWp1oajo9eIJlKlMHicGrPpWm6Lu0R6++DVwiGLbuRkRlkGKbDN2i8fSGiKmZ0aeST3x2iTS+YSx50lrVq2Asp1uKx2EcKqOgcwiVtK2TZw1pJsruXd02tZYcYXUSj3KXPHcJ34yNGAoU/GvmPAU3yczvxX/ycm1f5i5JDJLxHJATqcy2UrqrS5IoQvS2yJm4Cb7MT9PidLKEifp9oTO6B1cfdXQN X-MS-Exchange-AntiSpam-MessageData: hJNu7Muxmr5Ihve8CMMcUuZZxbEpNJsFLOXWFrMuH43gZFlztc/CCwLUIoA2itsev7HgR+1Za4zqGWvB2cwcvb1tYyyVmv9HzmrZLized5oRfLXi59/FdTZvCZ+BzRkMQ4lCtsDbs1Y3mQJgZF1+vPQxknI3KtO6NjkoU7WpJrufXZsvJr14TzyAx+wBVoXfb/tx9BH1lppRzxBIDt69KhWtLnjZbrpmbPwgBN9179Fsj6daAPZmfS2hph18m/k1WAiolWA44EPU9Gjee3DlOGdrpXuEIzZjr2bUZw96quIYx0sr+9S23Fs7lfcJtSvMKtRMiF7umfjdc1bSue98/HXCP5nbtxbqNNfpkrPzqyoT14cYkQiU5YrUKaYk4hueD82dC8HlkyeDTVdL8A2w9rpxrbrw+gH2BmttDXol8DGRWZTbJ64uD4agFNxtUUf4xkq7yXzWzvrDSPHzE3FYqlgdteroel3t0adzsDllu6XhQgAJG4HE8Dyv9RUciWksCSj+qFu2ikUx6620FyEXnFIEazERkF5wftCB0b4WylfZzpSNgtMhR60nu9VsATfY//moWXJ65bxwwKo5JvZLwLRcmrsIv3itrd75/wRayfT/ZmoOCLB01kvq8toLPrd+RlhisaJUpDeZGJG7M3teYnIdN6pR4X1YvMGZ2Wm2OFtwEnNkR8tUn2aw5ir5JcEDoxbnyIaUUMcJOYyc6W0Te5TFzXQgEH7wy7OU1oRu+DX4s9CixXlIbaJwmIM47INShFo6+6sZnboG2DYvvWkentSw+Sk8Y9YxeCE3oP1P1LM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 47d9a031-ffe9-41a5-1196-08d7eab8cce0 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2020 14:39:32.9667 (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: BCoDqRyiPGSE9CVzxTXuZsK2s+ce7FRkzaBGfhHZ5cijP4RRa+ejQ9/Khor/2Vmq74+3kl83cEL4edci31m4VvTzTjwaMUKOg3iyyjSRFaw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5336 Received-SPF: pass client-ip=40.107.4.124; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-DB5-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/27 10:39:33 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.4.124 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, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@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" bdrv_co_flush and bdrv_co_pdiscard will become static in further patch, move their usage down. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Stefan Hajnoczi --- block/io.c | 56 +++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/block/io.c b/block/io.c index 880871e691..1134f8144a 100644 --- a/block/io.c +++ b/block/io.c @@ -2827,20 +2827,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; @@ -2953,6 +2939,19 @@ early_exit: return ret; } =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 bdrv_flush(BlockDriverState *bs) { Coroutine *co; @@ -2973,20 +2972,6 @@ int bdrv_flush(BlockDriverState *bs) return flush_co.ret; } =20 -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) { @@ -3101,6 +3086,21 @@ out: return ret; } =20 +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 bdrv_pdiscard(BdrvChild *child, int64_t offset, int64_t bytes) { Coroutine *co; --=20 2.21.0 From nobody Fri Sep 20 22:16:19 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=1587998942; cv=pass; d=zohomail.com; s=zohoarc; b=IB/ZtQ9r/VIMiujiKFsy5YrijBaz/WqM5767FMrfbXma+tmxMtAJ+ZkuVMkbCt4K2ZjzsvXlHaulp6ooUOiohZkFCz7MTNTSiO3J3X/+ierIy9fKdroUOjPxpN3K4O5tcmONQqQVXVW3LAJIMWCUUsDEUyev1eYo+n4V1ZPkHwA= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587998942; 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=9ihRWiLKIJVJgQeWrd0GmjsDZuY3P9UqMYNUt5RqTKw=; b=ZZI5M/kZ2oj2lAHmVbbWISab5u9VjX4t5RWSqXfNHB6fJFKTh/1m4tpMxhwTPlyf9DfG2YJh14YzCEXJ46BEr2azTHRE0QTPH0l7vkLefENlCAWDth4WzPIe7lRMYQ4xSY+6vJjbwlLcSf8IRNadAl15BTR2f+h29WMfon1Nd1o= 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 1587998942747415.9627479013824; Mon, 27 Apr 2020 07:49:02 -0700 (PDT) Received: from localhost ([::1]:49128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT549-00071D-B2 for importer@patchew.org; Mon, 27 Apr 2020 10:49:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56890) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4v8-0008GE-EJ for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jT4v5-0007lY-N0 for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:42 -0400 Received: from mail-eopbgr40124.outbound.protection.outlook.com ([40.107.4.124]:49833 helo=EUR03-DB5-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 1jT4v2-0007iT-IO; Mon, 27 Apr 2020 10:39:36 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5336.eurprd08.prod.outlook.com (2603:10a6:20b:105::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Mon, 27 Apr 2020 14:39:33 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.020; Mon, 27 Apr 2020 14:39:33 +0000 Received: from localhost.localdomain (185.215.60.182) by FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Mon, 27 Apr 2020 14:39:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DaGiq1hvFR483fjKru53lCl9xT3zDWwx5HyuPT20YZ4xrwHs5jjlLuapOKqX2ond2BcJtWU6VdxU7BrpKlU/lfgtLekEbUmQEJYpV7wVqh2QqeSqtu+TPnD0kUxY61oCrrUWyq8DIXTgX3vggbVwM7gE8SUJY3lbtgVkMIIXAEjEZIlLoQDutP887qhVUsdwzGFuntNpjaeQIw9PhL8b5RckyDhMBv4CS9fsDIwtgJzWF0/D6i/VhuWZn7h2P0bN7ZkVbJsNzO10PEEVB/K1BSbW7Cj0Je4UIXx7zJWm3JuXYkXlTt7edIi5C79PRfQRqx0obiD4X/HdXvNjcEyj7Q== 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=9ihRWiLKIJVJgQeWrd0GmjsDZuY3P9UqMYNUt5RqTKw=; b=ZJLrWjRXrwTh1pVFNosHmV41yqboxPpQvIaqOGWttyF58Z84g/jUKAwDVorSJJyi1/UG/wEwt9PvtA2ZOaBvKEJZJMdaMK1ZgDQjtCxNgTa07W1Zq/nawZLvYRTe26QJ4s4QN8rbp3eMnImonAOZntY1n4BAs2H6L4JltrqAYTSwv7dsOrnmeH3GVpoq7INk6NEihxeQQKz1n59GNslt4b+8Tmh7czsPFFkfJT2j17DrBKR2vsSVPVqfJMQPXH7I+gvd3gKg/1/cSbc1UaFjcmtBTUvp/EzDJtwuzODBCTeecqlZs38ErGx3aOKWjZ+Rmd8MSMTwh2TekejsF8UBkw== 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=9ihRWiLKIJVJgQeWrd0GmjsDZuY3P9UqMYNUt5RqTKw=; b=iahpMOvMVPG4FxTyCbmsvck9AD6ydIbQaOn+OwythTPnjiGDDBDwUeYqg1IgoZDwgyIsct/Sr4J+35OtvtMCz+b8sfmEw7T1rS9uyx6jxeoxv9M4w6C9YRzsVzpyrOGDX7CDP11/mFL5UmMhyi+S0G9vt/JGm2BZ2sYpFYlAr3E= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vsementsov@virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 4/9] block/io: move bdrv_rw_co_entry and friends down Date: Mon, 27 Apr 2020 17:39:02 +0300 Message-Id: <20200427143907.5710-5-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200427143907.5710-1-vsementsov@virtuozzo.com> References: <20200427143907.5710-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) 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.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3ec3f310-36f2-459f-b11a-08d7eab8cd4c X-MS-TrafficTypeDiagnostic: AM7PR08MB5336: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-Forefront-PRVS: 0386B406AA 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)(376002)(136003)(346002)(366004)(39840400004)(478600001)(52116002)(6916009)(2616005)(956004)(4326008)(8676002)(36756003)(107886003)(6666004)(5660300002)(2906002)(316002)(66476007)(6486002)(66946007)(6512007)(8936002)(69590400007)(186003)(6506007)(66556008)(16526019)(26005)(86362001)(1076003)(81156014); DIR:OUT; SFP:1102; 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: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: cz3wntPHU6kNhlmNTUKfofIA0jh7LM55vkKeNQQMKXlm5ZptByKcE9FjripJLyBLxJpttZbIyljaagiwsNIjZMtEoN1dU+3MRhtkqOVuuQpf0eL1RiXVpgtpOnfSzV0PE09Puizg1w2RRZ345fwwnBIy2i8oR5JkXjRnxEsOdgPclZBZCQIlveK+Az6wzqyFDVuYaSXYia/xkuHQvYi6avjXs+Tq0N5ue4ENW/7+bF6RSJW/qOY//HxUvNMy84NqNhCrYwnz5q6CtPzdpS1JOI/I2BkjQo+TH++CqdxnQp7e0a0xGcvyPYEZPT0EADTJm3Rfw99tkYQM8FjGr7XewbsuVzjWnSjikTKQRS7E3NYi5RleoU/V7e9ln9lAqUeYQuEV6+FWvAyCcKNPxUkgp4DhR9UYX23SqgD4GpT3LYBKdYI2ktjPwd4tcCF/oJyXQCChfvypsbeWkcfF+49MiDWQq/C4ABm/CfW1216/vip47nPznhzXey52MKYFHxT8 X-MS-Exchange-AntiSpam-MessageData: RVueGdoIEr5xfkTqq5L2IV6Ll2uHqj0kZxEbJoe7Qemn+f9cQsLl2sSRGmlJGQrhssPPzthHQ55NO87oy8S5Laps9Ftd8uqQgoshnIBtEetY99pUGWazpiB6hzQjzKS461oetuwJz+z26piPN5CAQe7JFJiiJQt4HASWWRWN616QOaNzu0wiaVt5aa8X5xg6g3vPV79KUOYM0bZ2oBzat6ctYgf/TReMGrLIrbnjNE38W0vtVFOHpgfY+atcjEbbK3LgiFDtF0TRi6VPkQ0lRO9K/xfXpFq0Q8LBrF0ZLyiXk12w/dafX5z5CsfDjDwvBwoowYl0vTOG/pkAKgy/ycpXS2Zenk+ZQiijRrvgmzbkescd6XAfgRuu43ZmhwCG502IokhgYSbJd1rTNpyjTUsIuYSHBsd7t5YxMe1tgoO8pN3Pfn7zrDopMSiBNiONiMOCxlEkY5sV/+wQB+acs5POft+ReQJY98oZ8b5KIN8c3qwAVdwRp0g1TIlUM4XJbxEeR65RDBfz16N2sk+eNkqL32PilspMC+NFxayY/cYGhBHsNuxFvLGTjYUQ1I9ZvyOOtCUxwXVlCFNGBU+kum8LOnhPuO5jIXPTWwHkMnXR+IEFQK4rBrltZlnCmOYOg8BMGMj7EBuwMt7lR/zuksyMLolNyJSB5mAkTmKWSH1r0KsArTWiKQTjqfTbkB6vy7yPe7r0U89EQ1y6nC5Njz260JiwB3vWa0UlTXXQQPS0TyuFfzjQ8dwmuveP1WDJY9eN5mK6jI+yozJV2biuCbf9ZQn8Nk04i4KjMSZCL9I= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ec3f310-36f2-459f-b11a-08d7eab8cd4c X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2020 14:39:33.7721 (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: aweXqm4nqMIOtj9JvRcs2VkvAWv3mWeDZP55MxGEJA0osL4L3CVQgeiGOyL+69a+NS/gWmkFENkPtEW19qpehxFmHb7/K/wXmh5HIU/NmEw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5336 Received-SPF: pass client-ip=40.107.4.124; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-DB5-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/27 10:39:33 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.4.124 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, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@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 use bdrv_co_pwritev_part and bdrv_co_preadv_part in bdrv_rw_co_entry, so move it down. Note: Comment formatting was changed to conform to coding style and function order was changed. Otherwise the code is unmodified. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Stefan Hajnoczi --- block/io.c | 361 +++++++++++++++++++++++++++-------------------------- 1 file changed, 181 insertions(+), 180 deletions(-) diff --git a/block/io.c b/block/io.c index 1134f8144a..061f3f2590 100644 --- a/block/io.c +++ b/block/io.c @@ -891,186 +891,6 @@ static int bdrv_check_byte_request(BlockDriverState *= bs, int64_t offset, return 0; } =20 -typedef struct RwCo { - BdrvChild *child; - int64_t offset; - QEMUIOVector *qiov; - bool is_write; - int ret; - BdrvRequestFlags flags; -} RwCo; - -static void coroutine_fn bdrv_rw_co_entry(void *opaque) -{ - RwCo *rwco =3D opaque; - - 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); - } - aio_wait_kick(); -} - -/* - * Process a vectored synchronous request using coroutines - */ -static int bdrv_prwv_co(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) -{ - QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes); - - return bdrv_prwv_co(child, offset, &qiov, true, - BDRV_REQ_ZERO_WRITE | flags); -} - -/* - * Completely zero out a block device with the help of bdrv_pwrite_zeroes. - * The operation is sped up by checking the block status and only writing - * zeroes to the device if they currently do not return zeroes. Optional - * flags are passed through to bdrv_pwrite_zeroes (e.g. BDRV_REQ_MAY_UNMAP, - * BDRV_REQ_FUA). - * - * Returns < 0 on error, 0 on success. For error codes see bdrv_write(). - */ -int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) -{ - int ret; - int64_t target_size, bytes, offset =3D 0; - BlockDriverState *bs =3D child->bs; - - target_size =3D bdrv_getlength(bs); - if (target_size < 0) { - return target_size; - } - - for (;;) { - bytes =3D MIN(target_size - offset, BDRV_REQUEST_MAX_BYTES); - if (bytes <=3D 0) { - return 0; - } - ret =3D bdrv_block_status(bs, offset, bytes, &bytes, NULL, NULL); - if (ret < 0) { - return ret; - } - if (ret & BDRV_BLOCK_ZERO) { - offset +=3D bytes; - continue; - } - ret =3D bdrv_pwrite_zeroes(child, offset, bytes, flags); - if (ret < 0) { - return ret; - } - offset +=3D bytes; - } -} - -int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) -{ - int ret; - - ret =3D bdrv_prwv_co(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) -{ - QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); - - if (bytes < 0) { - return -EINVAL; - } - - return bdrv_preadv(child, offset, &qiov); -} - -int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) -{ - int ret; - - ret =3D bdrv_prwv_co(child, offset, qiov, true, 0); - if (ret < 0) { - return ret; - } - - return qiov->size; -} - -/* Return no. of bytes on success or < 0 on error. Important errors are: - -EIO generic I/O error (may happen for all errors) - -ENOMEDIUM No media inserted. - -EINVAL Invalid offset or number of bytes - -EACCES Trying to write a read-only device -*/ -int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int byt= es) -{ - QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); - - if (bytes < 0) { - return -EINVAL; - } - - return bdrv_pwritev(child, offset, &qiov); -} - -/* - * Writes to the file and ensures that no writes are reordered across this - * request (acts as a barrier) - * - * Returns 0 on success, -errno in error cases. - */ -int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, - const void *buf, int count) -{ - int ret; - - ret =3D bdrv_pwrite(child, offset, buf, count); - if (ret < 0) { - return ret; - } - - ret =3D bdrv_flush(child->bs); - if (ret < 0) { - return ret; - } - - return 0; -} - typedef struct CoroutineIOCompletion { Coroutine *coroutine; int ret; @@ -2185,6 +2005,187 @@ int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *c= hild, int64_t offset, BDRV_REQ_ZERO_WRITE | flags); } =20 +typedef struct RwCo { + BdrvChild *child; + int64_t offset; + QEMUIOVector *qiov; + bool is_write; + int ret; + BdrvRequestFlags flags; +} RwCo; + +static void coroutine_fn bdrv_rw_co_entry(void *opaque) +{ + RwCo *rwco =3D opaque; + + 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); + } + aio_wait_kick(); +} + +/* + * Process a vectored synchronous request using coroutines + */ +static int bdrv_prwv_co(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) +{ + QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, NULL, bytes); + + return bdrv_prwv_co(child, offset, &qiov, true, + BDRV_REQ_ZERO_WRITE | flags); +} + +/* See bdrv_pwrite() for the return codes */ +int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int bytes) +{ + QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); + + if (bytes < 0) { + return -EINVAL; + } + + return bdrv_preadv(child, offset, &qiov); +} + +int bdrv_pwritev(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) +{ + int ret; + + ret =3D bdrv_prwv_co(child, offset, qiov, true, 0); + if (ret < 0) { + return ret; + } + + return qiov->size; +} + +/* + * Return no. of bytes on success or < 0 on error. Important errors are: + * -EIO generic I/O error (may happen for all errors) + * -ENOMEDIUM No media inserted. + * -EINVAL Invalid offset or number of bytes + * -EACCES Trying to write a read-only device + */ +int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, int byt= es) +{ + QEMUIOVector qiov =3D QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); + + if (bytes < 0) { + return -EINVAL; + } + + return bdrv_pwritev(child, offset, &qiov); +} + +/* + * Writes to the file and ensures that no writes are reordered across this + * request (acts as a barrier) + * + * Returns 0 on success, -errno in error cases. + */ +int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, + const void *buf, int count) +{ + int ret; + + ret =3D bdrv_pwrite(child, offset, buf, count); + if (ret < 0) { + return ret; + } + + ret =3D bdrv_flush(child->bs); + if (ret < 0) { + return ret; + } + + return 0; +} + +/* + * Completely zero out a block device with the help of bdrv_pwrite_zeroes. + * The operation is sped up by checking the block status and only writing + * zeroes to the device if they currently do not return zeroes. Optional + * flags are passed through to bdrv_pwrite_zeroes (e.g. BDRV_REQ_MAY_UNMAP, + * BDRV_REQ_FUA). + * + * Returns < 0 on error, 0 on success. For error codes see bdrv_write(). + */ +int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) +{ + int ret; + int64_t target_size, bytes, offset =3D 0; + BlockDriverState *bs =3D child->bs; + + target_size =3D bdrv_getlength(bs); + if (target_size < 0) { + return target_size; + } + + for (;;) { + bytes =3D MIN(target_size - offset, BDRV_REQUEST_MAX_BYTES); + if (bytes <=3D 0) { + return 0; + } + ret =3D bdrv_block_status(bs, offset, bytes, &bytes, NULL, NULL); + if (ret < 0) { + return ret; + } + if (ret & BDRV_BLOCK_ZERO) { + offset +=3D bytes; + continue; + } + ret =3D bdrv_pwrite_zeroes(child, offset, bytes, flags); + if (ret < 0) { + return ret; + } + offset +=3D bytes; + } +} + +int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) +{ + int ret; + + ret =3D bdrv_prwv_co(child, offset, qiov, false, 0); + if (ret < 0) { + return ret; + } + + return qiov->size; +} + /* * Flush ALL BDSes regardless of if they are reachable via a BlkBackend or= not. */ --=20 2.21.0 From nobody Fri Sep 20 22:16:19 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=1587998519; cv=pass; d=zohomail.com; s=zohoarc; b=oCfVcGZosdVU0TDrBVTfxSORgmV7RxMQ7ZZ1joznycMof7lDRjmaAoZxWR2yUkM8Z04jkanRRwOKW1bQRG8y86Hlw3OqQJFEFE7h+zE3rHjAFGgZ4d9Cn0rBITDpOCoz2KCSGA3C6vUt4WuUK009ZoiD94HH9hWASDpt8jzA/Rg= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587998519; 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=pBsTKOfdeaYxD8YTy5iDd2s7PklFJjA0Pe3Rsu7nlJk=; b=Hvo2JaQC4/mtU5RjdZd4SzHI9r7VlZeVrD/w5XrnCWkjq0hz/7zeSth9kHRQjhrF4dIdCt85WlGhCvP3al1u8aoaBUbcud3zBecr1Jsl+OsjjPOcFVg0pU+bS6+aOKzBXU1VlMB6UwjxEiE/zlAdyo9bCRFgx4HWLn1hEkA2OCU= 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 1587998519847633.282254135558; Mon, 27 Apr 2020 07:41:59 -0700 (PDT) Received: from localhost ([::1]:48626 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4xH-0002wo-9R for importer@patchew.org; Mon, 27 Apr 2020 10:41:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56920) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4vA-0008JW-Sd for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jT4vA-0007nQ-0l for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:44 -0400 Received: from mail-eopbgr40124.outbound.protection.outlook.com ([40.107.4.124]:49833 helo=EUR03-DB5-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 1jT4v3-0007iT-Hr; Mon, 27 Apr 2020 10:39:37 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5336.eurprd08.prod.outlook.com (2603:10a6:20b:105::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Mon, 27 Apr 2020 14:39:34 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.020; Mon, 27 Apr 2020 14:39:34 +0000 Received: from localhost.localdomain (185.215.60.182) by FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Mon, 27 Apr 2020 14:39:33 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eF0WTSh5le4p4snOOvR039P4MEcwy/gQhIKx+2IeRovTjBh2Olro6sjLv83Yk6AqQhxF6T856Zk5kmY25X6g8Mk/F32wO5HL0udLT+SPKslnjlnPabZU1xibBGuj41Z/Tn5SEv6rxZGeudIOBN+H781YQZATzK/S0CU7zxUEWR0HJJP+bQaJs0KisrZ7hE3rT31ZugXuNXXZDcBBpgawFDcVJljHGqFMdOHrTyaNlXlg/OFVtmhoArxivKqak607499OQrqcaLIYNOr0DgGL1BGvVUm+ITaAwnXj9ZKeTQr4qOsXLMKGmngRsPIUfOIm6K/QpP6ufQlXtTdUr/DPAw== 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=pBsTKOfdeaYxD8YTy5iDd2s7PklFJjA0Pe3Rsu7nlJk=; b=Jf8nDalLazGFEx6LZMzltdZe2dpkWP1cQ59Ky7uOUwno52/LPVxnxvAmIIz2j0+ncYMNMo+dNjngafed3jXbFzPTXvlkTjIpOc8rMVrXknCIss9SOfrhsrcWwtbiHu/EdIQCMJZuLkAYrkmU4nkSN/1rFdeUzgTi2wKWH4dv1FO8JWk3AqFF8jnyvrKkzpy/TTmt5/EAihWQ+k54rOrrVNfYESAbyXtDnXZ/3oiyYSBGooWYlyPMCbFdses9zUXABYhBCw1Wib0u+P9e3QfTPvBuiGlURM2gqTx3hIc7eWB8bLwnNPg1HZe6lcy9WAvfeyOG1dZCy2p2C+KyjziFLQ== 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=pBsTKOfdeaYxD8YTy5iDd2s7PklFJjA0Pe3Rsu7nlJk=; b=iwZg8jsl/JZxz9P6Znnu0bWasUiGbstZKZBlD2FFfPCHGiDE06loK7k9N4Z38KEscQp/JQiAs7/OsjzEGEcLZZ5W098T8hq/ld41XrdzsOCgKy4JnbNlD7DiERc9Vy50BRPk0WTesmKoBqbLdURWrx8t09f0GPWHXcW04IEo9lc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vsementsov@virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 5/9] block/io: expand in_flight inc/dec section: simple cases Date: Mon, 27 Apr 2020 17:39:03 +0300 Message-Id: <20200427143907.5710-6-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200427143907.5710-1-vsementsov@virtuozzo.com> References: <20200427143907.5710-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) 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.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 311b4f26-27be-4f44-81b9-08d7eab8cdc8 X-MS-TrafficTypeDiagnostic: AM7PR08MB5336: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-Forefront-PRVS: 0386B406AA 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)(376002)(136003)(346002)(366004)(39840400004)(478600001)(52116002)(6916009)(2616005)(956004)(4326008)(8676002)(36756003)(107886003)(6666004)(5660300002)(2906002)(316002)(30864003)(66476007)(6486002)(66946007)(6512007)(8936002)(69590400007)(186003)(6506007)(66556008)(16526019)(26005)(86362001)(1076003)(81156014); DIR:OUT; SFP:1102; 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: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JjaVV/SafuzwFn2gtupZj/LT4+DtMT4iiBSn6R19hoFbUG27wO5cfqyoa5xcoMZrjkX2K/J1ZmPbfcCUdwPavwzBi/UVJ/h21EoMcYSyUBzF2rZzNgM5bYGXqJh18nOA2AW0WrBGev4r1paIRUGEYJpZDq2AFohFjSuAJxJHZ0U1h8i9RiRKjbxBo2nhjGdqybJDUPi4ip9JYwkBLQPV4nA4JN3kVnDW5n68gnI+bGuuj84u6BojqTbUMqbXBfHgfEP3DqlHxr/3ljLwu98SVE5KrV9BzBvRP78u2891GTPl53q1+pIsPf6qiGWV9L5j8qqzjbcbXdbO0lW9sLXje/6AMHR81VcgzbcIGuNok6ZZTe4jOrZm7Oei/lLk83Tv9G58qiYcnBtDKhI3kE0ktUmLXj8F9E00pZOKpXKOdu3xr9psU/2VglMk2j6tKWXf3E/TwD1XoKEpQlLyPFDvdMZURgVPz6inQC4t+d4Y+Xisou+TN+cVhsGICgZ10LzG X-MS-Exchange-AntiSpam-MessageData: gqdDZolIetGbHUpXdWKugFEWJRNn3uVFkowRC6FUmMiyrAC7swyuE0dxKnN7zdFTuzEZcv1xW/ZmKO5pC4aGvP8b3lkaOK4mc3UJWjhjMWd/SYiMaVSpEJMz3CPwV/yzu/w+/8q1CHorRe8P0xkS/Dumz0u1/xC8N/gCX0PxTK5nD1KQIjSUcM26Mzn/wLbs6EURPvPJVPpKsJaq0K58rgxTgrX2AanHEUSMTQ36BYPtp0816HtJ7GJFWSR/GU9iGORUwstGwGZJrra4x7AaGodROLPOjTC2D+YqNNNjaLSZQ18rh3a1YfsKhDRjZLONZy6IAtuUGQbfLk9wuAiz9fJLDCZ+Cn2UExclqNur3XTXdgarWOoMEhZk0aaXN39fs00wY55THHis3efGGC/oquarH27LOF7OvBps/fk8TsZ89cO1yOROnXiQsxlPww2NP94aOexsiuTy/58rC3tntq6hJmx51lIqauTocPD+2YvjThgCSJrZel6NKZDXUIC9RhCzVUXgjWc6tpPHe9cPWg+Nnqc9TNk++/duLEitD0ydFu8b2xOC+3CmG3oNIBhMFhpkMmb8wQptrQNukQD3phHIRHHJF5CcdNMkqXKHQejS+Tork+uKE/+ylzVBjDpMLENUtandSIUiv6F0OwvQ3dPsJ7teQupQExXY54z5Jco2+OdqKIdRy+OIJkxvrF87rzjeroDaQ+/Hsd84nA44Rp484QuzLjAtxgZn+0A73t1gyiYapIAM9nrTdWFavvLSpVwDdyd+JCl9I5MVFS7JjrsuDLSZfs24xTOhBgqetWw= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 311b4f26-27be-4f44-81b9-08d7eab8cdc8 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2020 14:39:34.5448 (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: nuLgl6vuN0VdaDA0Xqx10JSOktALFDyaFvHR/3OC8pF6SjuE3rjY7uG0KJyoAopcX+JazrrJ+FDnHt/KhjqXrj3xI79x8ZAA6ic+dyalB80= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5336 Received-SPF: pass client-ip=40.107.4.124; envelope-from=vsementsov@virtuozzo.com; helo=EUR03-DB5-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/27 10:39:33 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.4.124 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, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@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" It's safer to expand in_flight request to start before enter to coroutine in synchronous wrappers, due to the following (theoretical) problem: Consider write. It's possible, that qemu_coroutine_enter only schedules execution, assume such case. Then we may possibly have the following: 1. Somehow check that we are not in drained section in outer code. 2. Call bdrv_pwritev(), assuming that it will increase in_flight, which will protect us from starting drained section. 3. It calls bdrv_prwv_co() -> bdrv_coroutine_enter() (not yet increased in_flight). 4. Assume coroutine not yet actually entered, only scheduled, and we go to some code, which starts drained section (as in_flight is zero). 5. Scheduled coroutine starts, and blindly increases in_flight, and we are in drained section with in_flight request. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/io.c | 161 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 124 insertions(+), 37 deletions(-) diff --git a/block/io.c b/block/io.c index 061f3f2590..a91d8c1e21 100644 --- a/block/io.c +++ b/block/io.c @@ -1511,7 +1511,8 @@ int coroutine_fn bdrv_co_preadv(BdrvChild *child, return bdrv_co_preadv_part(child, offset, bytes, qiov, 0, flags); } =20 -int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ +static int coroutine_fn bdrv_do_preadv_part(BdrvChild *child, int64_t offset, unsigned int bytes, QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags) @@ -1540,8 +1541,6 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, return 0; } =20 - bdrv_inc_in_flight(bs); - /* Don't do copy-on-read if we read data before write operation */ if (atomic_read(&bs->copy_on_read)) { flags |=3D BDRV_REQ_COPY_ON_READ; @@ -1554,13 +1553,26 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *chi= ld, bs->bl.request_alignment, qiov, qiov_offset, flags); tracked_request_end(&req); - bdrv_dec_in_flight(bs); =20 bdrv_padding_destroy(&pad); =20 return ret; } =20 +int coroutine_fn bdrv_co_preadv_part(BdrvChild *child, + int64_t offset, unsigned int bytes, + QEMUIOVector *qiov, size_t qiov_offset, + BdrvRequestFlags flags) +{ + int ret; + + bdrv_inc_in_flight(child->bs); + ret =3D bdrv_do_preadv_part(child, offset, bytes, qiov, qiov_offset, f= lags); + bdrv_dec_in_flight(child->bs); + + return ret; +} + static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags) { @@ -1922,7 +1934,8 @@ int coroutine_fn bdrv_co_pwritev(BdrvChild *child, return bdrv_co_pwritev_part(child, offset, bytes, qiov, 0, flags); } =20 -int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child, +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ +static int coroutine_fn bdrv_do_pwritev_part(BdrvChild *child, int64_t offset, unsigned int bytes, QEMUIOVector *qiov, size_t qiov_of= fset, BdrvRequestFlags flags) { @@ -1962,7 +1975,6 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *chil= d, return 0; } =20 - bdrv_inc_in_flight(bs); /* * Align write if necessary by performing a read-modify-write cycle. * Pad qiov with the read parts and be sure to have a tracked request = not @@ -1987,7 +1999,19 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *chi= ld, =20 out: tracked_request_end(&req); - bdrv_dec_in_flight(bs); + + return ret; +} + +int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child, + int64_t offset, unsigned int bytes, QEMUIOVector *qiov, size_t qiov_of= fset, + BdrvRequestFlags flags) +{ + int ret; + + bdrv_inc_in_flight(child->bs); + ret =3D bdrv_do_pwritev_part(child, offset, bytes, qiov, qiov_offset, = flags); + bdrv_dec_in_flight(child->bs); =20 return ret; } @@ -2014,17 +2038,18 @@ typedef struct RwCo { BdrvRequestFlags flags; } RwCo; =20 +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ 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->ret =3D bdrv_do_preadv_part(rwco->child, rwco->offset, + rwco->qiov->size, rwco->qiov, 0, rwco->flags); } else { - rwco->ret =3D bdrv_co_pwritev(rwco->child, rwco->offset, - rwco->qiov->size, rwco->qiov, + rwco->ret =3D bdrv_do_pwritev_part(rwco->child, rwco->offset, + rwco->qiov->size, rwco->qiov, 0, rwco->flags); } aio_wait_kick(); @@ -2047,6 +2072,8 @@ static int bdrv_prwv_co(BdrvChild *child, int64_t off= set, .flags =3D flags, }; =20 + bdrv_inc_in_flight(child->bs); + if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_rw_co_entry(&rwco); @@ -2055,6 +2082,9 @@ static int bdrv_prwv_co(BdrvChild *child, int64_t off= set, bdrv_coroutine_enter(child->bs, co); BDRV_POLL_WHILE(child->bs, rwco.ret =3D=3D NOT_DONE); } + + bdrv_dec_in_flight(child->bs); + return rwco.ret; } =20 @@ -2699,15 +2729,14 @@ typedef struct BdrvVmstateCo { int ret; } BdrvVmstateCo; =20 +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ static int coroutine_fn -bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, +bdrv_do_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read) { BlockDriver *drv =3D bs->drv; int ret =3D -ENOTSUP; =20 - bdrv_inc_in_flight(bs); - if (!drv) { ret =3D -ENOMEDIUM; } else if (drv->bdrv_load_vmstate) { @@ -2717,17 +2746,19 @@ bdrv_co_rw_vmstate(BlockDriverState *bs, QEMUIOVect= or *qiov, int64_t pos, ret =3D drv->bdrv_save_vmstate(bs, qiov, pos); } } else if (bs->file) { - ret =3D bdrv_co_rw_vmstate(bs->file->bs, qiov, pos, is_read); + bdrv_inc_in_flight(bs->file->bs); + ret =3D bdrv_do_rw_vmstate(bs->file->bs, qiov, pos, is_read); + bdrv_dec_in_flight(bs->file->bs); } =20 - bdrv_dec_in_flight(bs); return ret; } =20 +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ 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); + co->ret =3D bdrv_do_rw_vmstate(co->bs, co->qiov, co->pos, co->is_read); aio_wait_kick(); } =20 @@ -2735,8 +2766,12 @@ static inline int bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos, bool is_read) { + int ret; + + bdrv_inc_in_flight(bs); + if (qemu_in_coroutine()) { - return bdrv_co_rw_vmstate(bs, qiov, pos, is_read); + ret =3D bdrv_do_rw_vmstate(bs, qiov, pos, is_read); } else { BdrvVmstateCo data =3D { .bs =3D bs, @@ -2749,8 +2784,12 @@ bdrv_rw_vmstate(BlockDriverState *bs, QEMUIOVector *= qiov, int64_t pos, =20 bdrv_coroutine_enter(bs, co); BDRV_POLL_WHILE(bs, data.ret =3D=3D -EINPROGRESS); - return data.ret; + ret =3D data.ret; } + + bdrv_dec_in_flight(bs); + + return ret; } =20 int bdrv_save_vmstate(BlockDriverState *bs, const uint8_t *buf, @@ -2828,16 +2867,14 @@ void bdrv_aio_cancel_async(BlockAIOCB *acb) /**************************************************************/ /* Coroutine block device emulation */ =20 -int coroutine_fn bdrv_co_flush(BlockDriverState *bs) +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ +static int coroutine_fn bdrv_do_flush(BlockDriverState *bs) { int current_gen; - int ret =3D 0; - - bdrv_inc_in_flight(bs); + int ret; =20 - if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs) || - bdrv_is_sg(bs)) { - goto early_exit; + if (!bdrv_is_inserted(bs) || bdrv_is_read_only(bs) || bdrv_is_sg(bs)) { + return 0; } =20 qemu_co_mutex_lock(&bs->reqs_lock); @@ -2935,8 +2972,17 @@ out: qemu_co_queue_next(&bs->flush_queue); qemu_co_mutex_unlock(&bs->reqs_lock); =20 -early_exit: + return ret; +} + +int coroutine_fn bdrv_co_flush(BlockDriverState *bs) +{ + int ret; + + bdrv_inc_in_flight(bs); + ret =3D bdrv_do_flush(bs); bdrv_dec_in_flight(bs); + return ret; } =20 @@ -2945,11 +2991,12 @@ typedef struct FlushCo { int ret; } FlushCo; =20 +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ static void coroutine_fn bdrv_flush_co_entry(void *opaque) { FlushCo *rwco =3D opaque; =20 - rwco->ret =3D bdrv_co_flush(rwco->bs); + rwco->ret =3D bdrv_do_flush(rwco->bs); aio_wait_kick(); } =20 @@ -2961,6 +3008,8 @@ int bdrv_flush(BlockDriverState *bs) .ret =3D NOT_DONE, }; =20 + bdrv_inc_in_flight(bs); + if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_flush_co_entry(&flush_co); @@ -2970,11 +3019,14 @@ int bdrv_flush(BlockDriverState *bs) BDRV_POLL_WHILE(bs, flush_co.ret =3D=3D NOT_DONE); } =20 + bdrv_dec_in_flight(bs); + return flush_co.ret; } =20 -int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, int64_t offset, - int64_t bytes) +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ +static int coroutine_fn bdrv_do_pdiscard(BdrvChild *child, int64_t offset, + int64_t bytes) { BdrvTrackedRequest req; int max_pdiscard, ret; @@ -3012,7 +3064,6 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, i= nt64_t offset, head =3D offset % align; tail =3D (offset + bytes) % align; =20 - bdrv_inc_in_flight(bs); tracked_request_begin(&req, bs, offset, bytes, BDRV_TRACKED_DISCARD); =20 ret =3D bdrv_co_write_req_prepare(child, offset, bytes, &req, 0); @@ -3083,7 +3134,18 @@ int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, = int64_t offset, out: bdrv_co_write_req_finish(child, req.offset, req.bytes, &req, ret); tracked_request_end(&req); - bdrv_dec_in_flight(bs); + return ret; +} + +int coroutine_fn bdrv_co_pdiscard(BdrvChild *child, + int64_t offset, int64_t bytes) +{ + int ret; + + bdrv_inc_in_flight(child->bs); + ret =3D bdrv_do_pdiscard(child, offset, bytes); + bdrv_dec_in_flight(child->bs); + return ret; } =20 @@ -3094,11 +3156,12 @@ typedef struct DiscardCo { int ret; } DiscardCo; =20 +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ static void coroutine_fn bdrv_pdiscard_co_entry(void *opaque) { DiscardCo *rwco =3D opaque; =20 - rwco->ret =3D bdrv_co_pdiscard(rwco->child, rwco->offset, rwco->bytes); + rwco->ret =3D bdrv_do_pdiscard(rwco->child, rwco->offset, rwco->bytes); aio_wait_kick(); } =20 @@ -3112,6 +3175,8 @@ int bdrv_pdiscard(BdrvChild *child, int64_t offset, i= nt64_t bytes) .ret =3D NOT_DONE, }; =20 + bdrv_inc_in_flight(child->bs); + if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_pdiscard_co_entry(&rwco); @@ -3121,6 +3186,8 @@ int bdrv_pdiscard(BdrvChild *child, int64_t offset, i= nt64_t bytes) BDRV_POLL_WHILE(child->bs, rwco.ret =3D=3D NOT_DONE); } =20 + bdrv_dec_in_flight(child->bs); + return rwco.ret; } =20 @@ -3411,9 +3478,12 @@ static void bdrv_parent_cb_resize(BlockDriverState *= bs) * If 'exact' is true, the file must be resized to exactly the given * 'offset'. Otherwise, it is sufficient for the node to be at least * 'offset' bytes in length. + * + * To be called between exactly one pair of bdrv_inc/dec_in_flight() */ -int coroutine_fn bdrv_co_truncate(BdrvChild *child, int64_t offset, bool e= xact, - PreallocMode prealloc, Error **errp) +static int coroutine_fn bdrv_do_truncate(BdrvChild *child, + int64_t offset, bool exact, + PreallocMode prealloc, Error **er= rp) { BlockDriverState *bs =3D child->bs; BlockDriver *drv =3D bs->drv; @@ -3444,7 +3514,6 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, i= nt64_t offset, bool exact, new_bytes =3D 0; } =20 - bdrv_inc_in_flight(bs); tracked_request_begin(&req, bs, offset - new_bytes, new_bytes, BDRV_TRACKED_TRUNCATE); =20 @@ -3493,6 +3562,19 @@ int coroutine_fn bdrv_co_truncate(BdrvChild *child, = int64_t offset, bool exact, =20 out: tracked_request_end(&req); + + return ret; +} + +int coroutine_fn bdrv_co_truncate(BdrvChild *child, + int64_t offset, bool exact, + PreallocMode prealloc, Error **errp) +{ + int ret; + BlockDriverState *bs =3D child->bs; + + bdrv_inc_in_flight(bs); + ret =3D bdrv_do_truncate(child, offset, exact, prealloc, errp); bdrv_dec_in_flight(bs); =20 return ret; @@ -3507,10 +3589,11 @@ typedef struct TruncateCo { int ret; } TruncateCo; =20 +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ 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->ret =3D bdrv_do_truncate(tco->child, tco->offset, tco->exact, tco->prealloc, tco->errp); aio_wait_kick(); } @@ -3528,6 +3611,8 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, b= ool exact, .ret =3D NOT_DONE, }; =20 + bdrv_inc_in_flight(child->bs); + if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_truncate_co_entry(&tco); @@ -3537,5 +3622,7 @@ int bdrv_truncate(BdrvChild *child, int64_t offset, b= ool exact, BDRV_POLL_WHILE(child->bs, tco.ret =3D=3D NOT_DONE); } =20 + bdrv_dec_in_flight(child->bs); + return tco.ret; } --=20 2.21.0 From nobody Fri Sep 20 22:16:19 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=1587998818; cv=pass; d=zohomail.com; s=zohoarc; b=NATZ/74pQut7f2zzP+s0cRaHSjuDsybVLuGQBG6R8HlebcZtixvtTe69BNdRU6L+Pzd5KSDRzDt4SxPNmHd6m6bxwb9a0+aJNog+L2x5fq4fD0vvlRoAwH6nLfknmsvLh16fXBW2oZEjRkEBusIlhpzjvdCoIPRhr9pi0053VPk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587998818; 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=2E/AKrIBiKr9k6kN+BLGLW0KAf8ZeXORIcK0XuhwXnI=; b=hViEIlY9UPIyVfxIiejWWgV6KOxmQUnWzgTqU9PAnR/UFCXuX0Q3h3nn1dJTOVKacqUqCGP3dolDjlD0vfmrP93EmWK1+fvNh9kQfCW1roaXi71CWFK2gXMFexc2UuVirsyXzw73I3hMQ4ka7LwV2jJ3FpD0Y73yC7APSxoGd+E= 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 1587998818236833.5300502318672; Mon, 27 Apr 2020 07:46:58 -0700 (PDT) Received: from localhost ([::1]:48980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT528-00031P-Lp for importer@patchew.org; Mon, 27 Apr 2020 10:46:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56876) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4v7-0008Dx-DJ for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jT4v6-0007lm-EN for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:41 -0400 Received: from mail-am6eur05on2133.outbound.protection.outlook.com ([40.107.22.133]:24288 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 1jT4v3-0007iF-EP; Mon, 27 Apr 2020 10:39:37 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5527.eurprd08.prod.outlook.com (2603:10a6:20b:de::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Mon, 27 Apr 2020 14:39:35 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.020; Mon, 27 Apr 2020 14:39:35 +0000 Received: from localhost.localdomain (185.215.60.182) by FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Mon, 27 Apr 2020 14:39:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c3Mg+VK/fp530GohjU5Bcy1tkbig6K/YzXgulzljCX4EGjKXWdLcxl4kaFKwfec3E7HUFlU+Mwc0OzxBY43tQd8u7RwL2Y25CSepP3SYPSlRAhKB26PtQeT1ZYlhDlNqDbAqHY0Pg8OC3GRqAXztZ3TtEcNLz7nVuZwnUU+Tcsxa1184BFifyqMLbs9RTFDnnLshOYcZoCDOnXppoptPX9A8hl1wMv5l0rDSi9QVHzMu1FzdGZIalxLE1hwocg+Szs+E5vHlM5I4WqGtdKBpbMFRv42OVmley8ytkJd9zD5Yw95nZ6FyrlbsGDL0QeEr7T8/kbKa+hdZ28Lw0FB59g== 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=2E/AKrIBiKr9k6kN+BLGLW0KAf8ZeXORIcK0XuhwXnI=; b=mMTabXL8VdTZeMb2sfKASfq5h+/g5ycrEMkeGJPM51Pn91y07PEKqT0RvGCg64Tv6hI3tD6zfYzXuuYFnUrAVSrOtN8V1ytzrEyRUbAgZIr/tdN69B0k8DrF69Ti2tyRm2qfihn9NsoanQ48Bzs7H/be+huT75lnBs6xXAOWoJIG6fXpG3gLwtuvL6c3GULMMV7LdqjT+3gVrjgtz7JwNzGp4EPkEgZVFwfWkZlQT0qsyOtxFyMBzKtYAlfnlKQzN/a4EP67YqScwuyjFwoXXvvJo3EqmHy0xnH9eFofT5jzWP9K8U1+qg4WCtTpqP5GxGwEcjuOQ4hFwffeFxEfAA== 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=2E/AKrIBiKr9k6kN+BLGLW0KAf8ZeXORIcK0XuhwXnI=; b=wHGhMZgLZZ9Oh3P4v8SGTl7z79q7IBrQ3uXg4q90nq8QL6to98ckiBFrEyfPiSQTg+HAoenyTnBXsIRlk6ZVlT21tBmB0OLleZhqG4MpxMzabPPHF1x/+ZvYLzX9sALicJ3uLWGyTSXr7TQJdhhazOrXHWKi2bjX9feXul0asNc= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vsementsov@virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 6/9] block/io: expand in_flight inc/dec section: block-status Date: Mon, 27 Apr 2020 17:39:04 +0300 Message-Id: <20200427143907.5710-7-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200427143907.5710-1-vsementsov@virtuozzo.com> References: <20200427143907.5710-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) 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.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ddfd52da-46bc-4a48-f7d3-08d7eab8ce47 X-MS-TrafficTypeDiagnostic: AM7PR08MB5527: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-Forefront-PRVS: 0386B406AA 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)(39840400004)(376002)(396003)(366004)(136003)(346002)(5660300002)(107886003)(316002)(2906002)(6512007)(478600001)(6486002)(66946007)(66476007)(66556008)(69590400007)(1076003)(2616005)(956004)(81156014)(16526019)(86362001)(6506007)(52116002)(186003)(36756003)(8676002)(8936002)(6666004)(26005)(6916009)(4326008); DIR:OUT; SFP:1102; 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: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TG951CHFtukKpezkK8HOduUm8JyXTCU5eu2QX+267++6otR2+CY94bjlOWQgBZjsWu11ER/ZO8CMDSGPNPQJv5dTuOFMrSp59zxUPZ3FOYKusXFVUutJf/Wf8V9lJb1dwRIsfJqQIFZw0OQJRYfuyOUyE8f4j7CM4/XLBHrtr92m5NCcYhfquuK/MvbGU524VQnZIyRZDSUeeLJSDvyQcGglosKXJLwhwnrh1QuSDpmpnoakbq7CJN9nwUyuYqAp17oW2FvwkgVhjmCtEQUpbj7/J8nxDKDIgEG20uOe+5MsrzIN/nxeVOOMO2xcrCoYQPaw6mvpI3n4qLeE9npEcxo2//s9e9EntFtUH9lUqdqWDj4WmMz1rMDDgXbHQJwVNWkCNCtqLE8BblhSLtKHXYy1yqwIg4hpJ7O0IeRZlsK8N1FMpEp8gc+/hPXirZfdY4FgmhyzvYo4WfZDjAhYUUYDHhe7pNzzwcaSdHAuUohveHXCc6Lz/MxsToS2UGcE X-MS-Exchange-AntiSpam-MessageData: FitGfqN9LndXtl+ca+KM90gUAelAYjFp8J/wgEybB/FKackUFjM2naGfy3iH4Wq/cK4Ims6ey+Rbp/VWXhw745syh7FcizO1NSU9Wc+CpkdoGk+f7s7LgvXHWOh7eEheGktSO/cssJd6sljxczcRbzhfWDp/mDigmPFIPVW03pglo2lYnRWu39oauIj83dDDZKHdVkQGUWTbZokzbJfY0vpfDw2bcwY4hddUgz4r8peXZ6qpnsK4PLUyziRB2OHnBn72zms+VClMLtaJKy962XCFoPTx72/cPNLwiaN3kzaXhWiFBQXXlwXkt5bGHRWc8IVfofLdsDLad1N5Os2LGPyaWsiBsAZHB1959ylODeA/Auo5cByxOqFBwcgXXsGKaymUSs8TGFe6JR2BfsgqsYSSslHzydswwNfZPguSt1fZ/RXtyqGlj7QW0Wp8ZdGQUgwPqSOzPOh0x8/ZgI2y5ZH3E5/U+6WX7ngPRNMXCF8TSlWjwSlvl3xfakj9Ku+cWK/H8EkU7wTbUN+0m8Sn5dzhi4+kG163zLvvACYrvtqM7Dj8U0WDqUR3yrX/3TWPlRG+Ay20SrrSEz95hABZZgPAhFaicQA8LqtJX07sg6R9dbZiT0sPOYaFstcfSoD+T87MtkG5ef+kynA9yLY4LgNEA17DoKWAz63QAcGDHcDVsM7n4uTxxf7zAu3se22fqAQprjjZb1h3SmJv/pWbYFIDQGPvEYtGBeknUZ5zl2vZAMRpJDu0gj2V0TpFVu7HmmZ0ty3hvJRDNuOWroJuwkjHr1J3OKyj8SrYqg+k3ck= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ddfd52da-46bc-4a48-f7d3-08d7eab8ce47 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2020 14:39:35.3054 (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: 1kh7Tz59AofkKUf50MQz1XtXM6dUB5xuUeg2WudRF8p4oTBHMLArGXyAc7MDMPjriRAAacgdoKAHabzJ3LB4syj3isBmGIKMufkJObskFEA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5527 Received-SPF: pass client-ip=40.107.22.133; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/27 10:39:31 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.22.133 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, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@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" It's safer to expand in_flight request to start before enter to coroutine in synchronous wrappers and end after BDRV_POLL_WHILE loop. Note that qemu_coroutine_enter may only schedule the coroutine in some circumstances. block-status requests are complex, they involve querying different block driver states across backing chain. Let's expand only in_flight section for the top bs, keeping other sections as is. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/io.c | 65 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 14 deletions(-) diff --git a/block/io.c b/block/io.c index a91d8c1e21..1cb6f433e5 100644 --- a/block/io.c +++ b/block/io.c @@ -2303,6 +2303,10 @@ int coroutine_fn bdrv_co_block_status_from_backing(B= lockDriverState *bs, * _ZERO where possible; otherwise, the result favors larger 'pnum', * with a focus on accurate BDRV_BLOCK_ALLOCATED. * + * If 'inc_in_flight' is true, in_flight counter will be increased for bs = during + * the operation. All nested block_status calls will increase the counter = for + * corresponding bs anyway. + * * If 'offset' is beyond the end of the disk image the return value is * BDRV_BLOCK_EOF and 'pnum' is set to 0. * @@ -2321,7 +2325,7 @@ int coroutine_fn bdrv_co_block_status_from_backing(Bl= ockDriverState *bs, * set to the host mapping and BDS corresponding to the guest offset. */ static int coroutine_fn bdrv_co_block_status(BlockDriverState *bs, - bool want_zero, + bool want_zero, bool inc_in_f= light, int64_t offset, int64_t bytes, int64_t *pnum, int64_t *map, BlockDriverState **file) @@ -2372,7 +2376,9 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, goto early_out; } =20 - bdrv_inc_in_flight(bs); + if (inc_in_flight) { + bdrv_inc_in_flight(bs); + } =20 /* Round out to request_alignment boundaries */ align =3D bs->bl.request_alignment; @@ -2409,7 +2415,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, =20 if (ret & BDRV_BLOCK_RAW) { assert(ret & BDRV_BLOCK_OFFSET_VALID && local_file); - ret =3D bdrv_co_block_status(local_file, want_zero, local_map, + ret =3D bdrv_co_block_status(local_file, want_zero, true, local_ma= p, *pnum, pnum, &local_map, &local_file); goto out; } @@ -2436,7 +2442,7 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, int64_t file_pnum; int ret2; =20 - ret2 =3D bdrv_co_block_status(local_file, want_zero, local_map, + ret2 =3D bdrv_co_block_status(local_file, want_zero, true, local_m= ap, *pnum, &file_pnum, NULL, NULL); if (ret2 >=3D 0) { /* Ignore errors. This is just providing extra information, it @@ -2459,7 +2465,9 @@ static int coroutine_fn bdrv_co_block_status(BlockDri= verState *bs, } =20 out: - bdrv_dec_in_flight(bs); + if (inc_in_flight) { + bdrv_dec_in_flight(bs); + } if (ret >=3D 0 && offset + *pnum =3D=3D total_size) { ret |=3D BDRV_BLOCK_EOF; } @@ -2473,9 +2481,15 @@ early_out: return ret; } =20 +/* + * If 'inc_in_flight' is true, in_flight counter will be increased for bs = during + * the operation. All block_status calls to the backing chain of bs will + * increase the counter for corresponding bs anyway. + */ static int coroutine_fn bdrv_co_block_status_above(BlockDriverState *bs, BlockDriverState *base, bool want_zero, + bool inc_in_flight, int64_t offset, int64_t bytes, int64_t *pnum, @@ -2488,11 +2502,13 @@ static int coroutine_fn bdrv_co_block_status_above(= BlockDriverState *bs, =20 assert(bs !=3D base); for (p =3D bs; p !=3D base; p =3D backing_bs(p)) { - ret =3D bdrv_co_block_status(p, want_zero, offset, bytes, pnum, ma= p, - file); + ret =3D bdrv_co_block_status(p, want_zero, inc_in_flight, + offset, bytes, pnum, map, file); if (ret < 0) { break; } + inc_in_flight =3D true; + if (ret & BDRV_BLOCK_ZERO && ret & BDRV_BLOCK_EOF && !first) { /* * Reading beyond the end of the file continues to read @@ -2514,15 +2530,16 @@ static int coroutine_fn bdrv_co_block_status_above(= BlockDriverState *bs, } =20 static int coroutine_fn bdrv_co_is_allocated(BlockDriverState *bs, + bool inc_in_flight, int64_t offset, int64_t bytes, int64_t *pnum) { int ret; int64_t dummy; =20 - ret =3D bdrv_co_block_status_above(bs, backing_bs(bs), false, offset, - bytes, pnum ? pnum : &dummy, NULL, - NULL); + ret =3D bdrv_co_block_status_above(bs, backing_bs(bs), false, inc_in_f= light, + offset, bytes, pnum ? pnum : &dummy, + NULL, NULL); if (ret < 0) { return ret; } @@ -2535,7 +2552,7 @@ static void coroutine_fn bdrv_block_status_above_co_e= ntry(void *opaque) BdrvCoBlockStatusData *data =3D opaque; =20 data->ret =3D bdrv_co_block_status_above(data->bs, data->base, - data->want_zero, + data->want_zero, false, data->offset, data->bytes, data->pnum, data->map, data->fi= le); data->done =3D true; @@ -2567,6 +2584,8 @@ static int bdrv_common_block_status_above(BlockDriver= State *bs, .done =3D false, }; =20 + bdrv_inc_in_flight(bs); + if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_block_status_above_co_entry(&data); @@ -2575,6 +2594,9 @@ static int bdrv_common_block_status_above(BlockDriver= State *bs, bdrv_coroutine_enter(bs, co); BDRV_POLL_WHILE(bs, !data.done); } + + bdrv_dec_in_flight(bs); + return data.ret; } =20 @@ -2624,15 +2646,19 @@ int coroutine_fn bdrv_is_allocated(BlockDriverState= *bs, int64_t offset, * words, the result is not necessarily the maximum possible range); * but 'pnum' will only be 0 when end of file is reached. * + * To be called between exactly one pair of bdrv_inc/dec_in_flight() for t= op bs. + * bdrv_do_is_allocated_above takes care of increasing in_fligth for other= block + * driver states from bs backing chain. */ static int coroutine_fn -bdrv_co_is_allocated_above(BlockDriverState *top, BlockDriverState *base, +bdrv_do_is_allocated_above(BlockDriverState *top, BlockDriverState *base, bool include_base, int64_t offset, int64_t byte= s, int64_t *pnum) { BlockDriverState *intermediate; int ret; int64_t n =3D bytes; + bool inc_in_flight =3D false; =20 assert(base || !include_base); =20 @@ -2642,10 +2668,12 @@ bdrv_co_is_allocated_above(BlockDriverState *top, B= lockDriverState *base, int64_t size_inter; =20 assert(intermediate); - ret =3D bdrv_co_is_allocated(intermediate, offset, bytes, &pnum_in= ter); + ret =3D bdrv_co_is_allocated(intermediate, inc_in_flight, offset, = bytes, + &pnum_inter); if (ret < 0) { return ret; } + inc_in_flight =3D true; if (ret) { *pnum =3D pnum_inter; return 1; @@ -2682,11 +2710,16 @@ typedef struct BdrvCoIsAllocatedAboveData { bool done; } BdrvCoIsAllocatedAboveData; =20 +/* + * To be called between exactly one pair of bdrv_inc/dec_in_flight() for t= op bs. + * bdrv_do_is_allocated_above takes care of increasing in_fligth for other= block + * driver states from the backing chain. + */ static void coroutine_fn bdrv_is_allocated_above_co_entry(void *opaque) { BdrvCoIsAllocatedAboveData *data =3D opaque; =20 - data->ret =3D bdrv_co_is_allocated_above(data->top, data->base, + data->ret =3D bdrv_do_is_allocated_above(data->top, data->base, data->include_base, data->offset, data->bytes, data->pnum); @@ -2709,6 +2742,8 @@ int bdrv_is_allocated_above(BlockDriverState *top, Bl= ockDriverState *base, .done =3D false, }; =20 + bdrv_inc_in_flight(top); + if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ bdrv_is_allocated_above_co_entry(&data); @@ -2718,6 +2753,8 @@ int bdrv_is_allocated_above(BlockDriverState *top, Bl= ockDriverState *base, BDRV_POLL_WHILE(top, !data.done); } =20 + bdrv_inc_in_flight(top); + return data.ret; } =20 --=20 2.21.0 From nobody Fri Sep 20 22:16:19 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=1587998964; cv=pass; d=zohomail.com; s=zohoarc; b=CqP49WhTBotYpPPQLpNfprqzJKRNPkXZAPNsGDHk70ABVGecMM/yxM0YCARTDuGvxDIIn+S3ZNBBPut+2tssNja6FB+KkvwLofP6O3X0vu7tAhyFM5kDV+fwoENorGym6Adf7EbEJPmf5b+Xif9Ess/hXMz/xPVViuj08qAO/Lo= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587998964; 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=R/KHxXjLZZosLyhmJd8gaGFYJpbqdCga15U3mqAzN+o=; b=fIj1KcC8XeBbGbE9HW6uFRkVCrpbbk+kcVdAs0n+PvM2uQzSsRH0H+rf2I7xZ6nQGqoHyz4/ET93c7tlXDj1DbCLn3J7wEiWwKQikuiG9L7xUvQ2eLPl9rFnFI8jNklfXBFtJFJKpOkr83fj3yzAIJYdxY2Vv033hiftBvHJLQs= 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 158799896494679.25016190137751; Mon, 27 Apr 2020 07:49:24 -0700 (PDT) Received: from localhost ([::1]:49164 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT54V-0007ZA-Kr for importer@patchew.org; Mon, 27 Apr 2020 10:49:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56902) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4v9-0008HO-1O for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jT4v8-0007ml-7O for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:42 -0400 Received: from mail-am6eur05on2133.outbound.protection.outlook.com ([40.107.22.133]:24288 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 1jT4v4-0007iF-Da; Mon, 27 Apr 2020 10:39:38 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5527.eurprd08.prod.outlook.com (2603:10a6:20b:de::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Mon, 27 Apr 2020 14:39:36 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.020; Mon, 27 Apr 2020 14:39:36 +0000 Received: from localhost.localdomain (185.215.60.182) by FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Mon, 27 Apr 2020 14:39:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CYvxb3xT8AbUoMmigwZ4YXcUdJJgWLnpqNu0A7EqP/IEKlLOaz1m7kFfKl5FGTQhhpT+sPu4kKXZYwfZNSbk51b1M6AzzkzKpNB9sKSXTecNBHj4F0LXo1JQE4vRA5F79eR5KwoFrvKZasb++J0VpLvFrDtvQGyPDFi/Rr3xw8dmiENQBSAgbUnXctkP6ImbTtUMrXCBoM7LvWQFW25Jq1ZJ/T1yyNLKOMZ1zfn7lcroyoMu0fAlW19KuGUVQ0T/+lZ900Au207qJR0y5T5jsjMbDZgk436QBz8OcEdUsCKWwIjUVPaBpnU3UicUbskrSRFCik5g5EBWzZs3qtU9BQ== 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=R/KHxXjLZZosLyhmJd8gaGFYJpbqdCga15U3mqAzN+o=; b=Vvu/Gs01zER1/uli+ongeCTLXTeTJsstA3oVH2cUqiVqkv4dE5Vjc5Pu/01k1xSbefvLTTX6daEmcjEK2TdUSYZ3PKp2zZLjXyNmrqWZ1hPdLEYJDdLH75O1nqJJRWBiyh1ebkx4qJiPUVMvDAEZ/adF++DDFQJkse6Wnwz5LZtwaFKy1W/mpesRC3HTM9o7yDt7nncx99sunhJUQz/WZiaf+2yndJSdxF95VOlGpXhtOMJ0fcWgag5VjiabwduLn1k0clIAijk3KP94gHR2HzhcjavU45vqhf0zttgS5lkPPaX8E4ZhhnAhpTeoqXiw7VvoMhm2sExolSRfr75RQw== 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=R/KHxXjLZZosLyhmJd8gaGFYJpbqdCga15U3mqAzN+o=; b=S7XbetRUj3YLAklZk6toOH1HeWDbvoVF9xtxDCLg7v+Dp3pcpvLJHfTbIFKVk0QZvddI2hLJhySL7LNKsOFhwCrYZZ/bPbhjbFJklIOy0/U6FR86A+y70ilPbh5JDmrjzSciUSSLnUEkd3E4zZJ8/vRoSnbq6te6JigIPqpiJDg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vsementsov@virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 7/9] block/io: add bdrv_do_pwrite_zeroes Date: Mon, 27 Apr 2020 17:39:05 +0300 Message-Id: <20200427143907.5710-8-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200427143907.5710-1-vsementsov@virtuozzo.com> References: <20200427143907.5710-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) 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.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7eb6aeec-3804-4a4e-8719-08d7eab8ceb3 X-MS-TrafficTypeDiagnostic: AM7PR08MB5527: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3826; X-Forefront-PRVS: 0386B406AA 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)(39840400004)(376002)(396003)(366004)(136003)(346002)(5660300002)(107886003)(316002)(2906002)(6512007)(478600001)(6486002)(66946007)(66476007)(66556008)(69590400007)(1076003)(2616005)(956004)(81156014)(16526019)(86362001)(6506007)(52116002)(186003)(36756003)(8676002)(8936002)(6666004)(26005)(6916009)(4326008); DIR:OUT; SFP:1102; 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: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u8FZb1i8zi50jL9zXrxZP4bUsmruYJSewcNOtLVDKVPbBa9WeYqs24kk4PGlazbwr1pxu9xvaRN49SOyrUMm/MMYA+ApBkHW48glbx8szulFp3iKMwvpU8lLB+4KPy//5pCj16JTy70tp6dR3RVEeUBHbmsUfWWRcIm7Q6UAu2RU/mQJ6pB3fWcv3hRF1yVZscLoiyVUcg53kBhlQ+dslaBR8xkqYNHyztif6hyDsSwE99UgnlypAAszaZLGRG/lpffuMw6hHtHltmVEAoHpDlmYDXRJxV11t5Vhl+M5h2eLq5pkWlcxMILHgkH48ayrdxKOazWmdeiC7ircfYkOEBGvGKikCgd0m2WVAiYZxZSKeYOF8fnXlv9qhO5H4z0VxjsbFxkJd2Pvc81+db4v6k3sy6Z3AKbyG5wLfKldI4BA1UNxoXpp7e1BvSJN/hqFZWb6kMo5DGl6z19w4sJTM/UsKMT0ocbP/uHSd8nuCtNE7LCcmkVszVwNWpkJAPm9 X-MS-Exchange-AntiSpam-MessageData: Os+RFQWs6a6HWHyucP5wmfxKpPhlMjtCaXdQac6g0PC4GBb178RlzsHbDQXTCHdKyL7PvZNLYeG/MNAl4FUnYsoCAFvmJCdhDMbEsTidw6PHKqqyENAR4GbYmzZ8SUrlboyAtij6Zv25TN80GavH18cxlUW3dZuKu/3A9mk2h84oh7IwC2wZukKPD/H/iJ7nUKotL5SZILhtVX9RSbzP4sqAxNLCl9oa1i2gxPNOJM+CQB8w7zm4ZaMjinMbsN1KLHxHjqhKXcG+wWAXqIi+myzC2HFsxBeLyC3+GJxDqshspLjq+SXkxzkrkBVHlWk5O/+jRtOrwFginTQj9kULsa02umNbKpbvZ1WIASmbCYFxGiZ+sijCyBr4BdVRIR392tWlKMvX9mrnF55OenXc9Q+FhIQdA/MvjxbhEuk5l7ONMsXhe71PBUeMgbeOOg3JkEC9UYcwuwu3zLXC75VAoLSpg/uhx7+G1j7Z5zeGgl6oZBQ2ImdEOrXPBNkFat+E4o8ox8qMd3gORWCCrLhsyTwQYLzJ9HmTzjrCds+cRVV655NFGJFDddy2j7leTV7P3T0cpMaDe0abA3KRVj9YVpzOjYbcBhJEq/vWsFHbLjbMth1aWM99p3b0NE6/OFD1+NnfS1P8RBRRr9QP24vFtKKQgCdrdsg1c3R/64RxUL23Vn4k6QHmQYeWDHTKk6pMXLQitMxAapNtD0r2Tb/EmmkkbXa2SamHjWNsQcU7oVpMaw2tW0VMJMF5BOPcP2gZIPr2JDKA9MQnBRtJe7+D5dPByXQQhqHlozBOD4SlE+U= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7eb6aeec-3804-4a4e-8719-08d7eab8ceb3 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2020 14:39:36.0233 (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: yr45yQ912mG2mc991l6oMhT9QzIuSMh+oo4EGp0JvAbDtiLyKFkp5eYvXYRNgRzi+7ArNtF5KcL/s7KQYBOWVOx5abdddAnXZIGdFHhXqP8= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5527 Received-SPF: pass client-ip=40.107.22.133; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/27 10:39:31 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.22.133 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, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@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'll need a bdrv_co_pwrite_zeroes version without inc/dec in_flight to be used in further implementation of bdrv_make_zero. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Stefan Hajnoczi Reviewed-by: Eric Blake --- block/io.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/block/io.c b/block/io.c index 1cb6f433e5..e6a8ead46c 100644 --- a/block/io.c +++ b/block/io.c @@ -2016,8 +2016,10 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *chi= ld, return ret; } =20 -int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, - int bytes, BdrvRequestFlags flags) +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ +static int coroutine_fn +bdrv_do_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, + BdrvRequestFlags flags) { trace_bdrv_co_pwrite_zeroes(child->bs, offset, bytes, flags); =20 @@ -2025,8 +2027,21 @@ int coroutine_fn bdrv_co_pwrite_zeroes(BdrvChild *ch= ild, int64_t offset, flags &=3D ~BDRV_REQ_MAY_UNMAP; } =20 - return bdrv_co_pwritev(child, offset, bytes, NULL, - BDRV_REQ_ZERO_WRITE | flags); + return bdrv_do_pwritev_part(child, offset, bytes, NULL, 0, + BDRV_REQ_ZERO_WRITE | flags); +} + +int coroutine_fn +bdrv_co_pwrite_zeroes(BdrvChild *child, int64_t offset, int bytes, + BdrvRequestFlags flags) +{ + int ret; + + bdrv_inc_in_flight(child->bs); + ret =3D bdrv_do_pwrite_zeroes(child, offset, bytes, flags); + bdrv_dec_in_flight(child->bs); + + return ret; } =20 typedef struct RwCo { --=20 2.21.0 From nobody Fri Sep 20 22:16:19 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=1587998626; cv=pass; d=zohomail.com; s=zohoarc; b=AGHOIhcVQg3WjTKTVJfZg+4Lhe6zwAFqi2xPjib+lmwK8+HvqHJyKO4XArXHbR3QsqvpRWiZ4bA7gXt85f1wBjaFn0yMtjErGnpdD4mUnQ1ypv35+kaLeCsoXfX6OzIJoqaTnX9n2Imv4UEUqKkvbp1va8vROPY+lkKA6mK/FLw= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587998626; 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=ZWf3gkufmonKz+QtUw5YgibQn493tksGtYBwyWswqGs=; b=LaHtf4OfFQpdeYk/mvB0Z60XBNLD+Yh0OmwvVUNtDOU065d3BAiEgyw94N1+q1s9I/fJvGzjL9Fco+XBkKdumaWfmcOM05FTpk2/jAW2JxsaFHD3hqj+U27Z1RlUyc+loW9byys8UwXsJwRbC2brK0MOUYqPrCMnlQLZkkk3HRg= 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 158799862653419.949193006185624; Mon, 27 Apr 2020 07:43:46 -0700 (PDT) Received: from localhost ([::1]:48800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4z3-0006z3-76 for importer@patchew.org; Mon, 27 Apr 2020 10:43:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56916) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4vA-0008J8-Il for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jT4vA-0007nW-3p for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:44 -0400 Received: from mail-am6eur05on2133.outbound.protection.outlook.com ([40.107.22.133]:24288 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 1jT4v6-0007iF-4f; Mon, 27 Apr 2020 10:39:40 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5527.eurprd08.prod.outlook.com (2603:10a6:20b:de::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Mon, 27 Apr 2020 14:39:36 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.020; Mon, 27 Apr 2020 14:39:36 +0000 Received: from localhost.localdomain (185.215.60.182) by FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Mon, 27 Apr 2020 14:39:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JfMZFv4rJKVixS9BlPVd0R8+vtqJpWsfr+qtfF3Y/s9cu6Ke3oPgVT/y4UWnEHiCAJXKdTxU0vhiQ6I4L2jJv2Wn4Pnar2l/aCFMOW1/XNf1qoynhB8niu4HpWLvbaAIQUd7CImwzcKTNOkAPZpFNvPBLtqmdlhj//Xmt0XBmqatAd/p4ZIOJL4i57hoGTQ8HysUQ46Opd6SQ1LNXwawwWV7j4lx2x7SgHmQfDXEOya2J5M/5L5spd1WcNse1/ifU5cyFiY9nxIjrrvj4VGD3v/zzw8SGnZ+33QljImrEACbL0DeIy2PM38rXLVW0PAhJfvdxvuUb3d4t/EIeJoJAQ== 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=ZWf3gkufmonKz+QtUw5YgibQn493tksGtYBwyWswqGs=; b=ZzShixzUpyfLPgNVubDNaNbxEQ7Wzmj8fIlAeMeV96hkFCAHulaMUPbUFA6NbpAAMylc4ZQktUR3n9geXR6Hw6irxqu9fYKYPPzYlUOBrrIDL9mwWPM31gIyk7ulpGWjxKT70nSuPV7W7s2cQ6eOhvemfCBvHUfaUXI9tsDkCx3f+xC0uPY7XdhWldCMXn7h92L5xyshdiysu3esorAqxZ5bRgLwPe4yLlofEf9Bp+vdAQpUP2+w09ejD4N88Xdj7fptj7E1WVpizYrg9S2UrDV5SQQuiMDf7lpcSiZ9vpqO5uBJwnJxL6wioLb53PKXstRsXQwywjtmLSzc+GXJ+Q== 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=ZWf3gkufmonKz+QtUw5YgibQn493tksGtYBwyWswqGs=; b=IxS9LWvqVhLrrLihDwnv1NYj6dkRH3ZGvVMRhObig6L6uHzYFgwEykx1xCB5rVM0bG61Pi0r/1f1YD20hLEXA8Pl4s1hzSxYRgZxvWpUFioXn3kYc12dDi3/TUDFS7E//vydgI4sUhSQSCnSWKuUOFUbf1+IVe7U0fw0216rmIo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vsementsov@virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 8/9] block/io: move bdrv_make_zero under block-status Date: Mon, 27 Apr 2020 17:39:06 +0300 Message-Id: <20200427143907.5710-9-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200427143907.5710-1-vsementsov@virtuozzo.com> References: <20200427143907.5710-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) 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.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ca1149bb-bdda-4fa0-3d38-08d7eab8cf1f X-MS-TrafficTypeDiagnostic: AM7PR08MB5527: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-Forefront-PRVS: 0386B406AA 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)(39840400004)(376002)(396003)(366004)(136003)(346002)(5660300002)(107886003)(316002)(2906002)(6512007)(478600001)(6486002)(66946007)(66476007)(66556008)(69590400007)(1076003)(2616005)(956004)(81156014)(16526019)(86362001)(6506007)(52116002)(186003)(36756003)(8676002)(8936002)(6666004)(26005)(6916009)(4326008); DIR:OUT; SFP:1102; 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: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8pKkRoSviTLu7TvSZn4ewKAaQTtaxuxQO6IkBqeDug3KUvU8k6gxA5yqXSHpkXulLz+q4/01QlY5mzsdWMs0rvLMzwpslKCDQ+yuRbcGOPIuIMLMFqn1YFSe2eqkUm292xsVJENWoYrSWoJMCfaZyVwvXIqPx0LQDAud3/ZcUkSY0r6ucWh67sFpbksd/Vyu5h+Oj+B7gYtKzuKgrlWFSGWKvR0dTnmTDLn/JpvnDhZBbU730TE6RlWPpj5o81iAclYcv7Ht2tq0PqmMxzmf/xc5XejL287iRgtGtPC26PLHGMWprtg5S8HBOTypVOr8l8wAuwyT+pJ0td/zb4b6evsBF9VGZEU0XIEZ3H+NY7jA5qwSioAqMr19ACjq3/EndVmLQEZ+LSkDiC2Q4PvV+/hLeYYBXL68Mx6N0B14NJL0r7iWOyF7S75vqu0cCORxBYwCUKgk8JPhOUjkx3eurNUtOglLLN68Z0yk58hFDP0e/a8/rZUxQ3OV2k03jEZe X-MS-Exchange-AntiSpam-MessageData: 7SEJHIcN8JIWbaqbdO/faTTZ9BnIS1+Ndf9rSnhr3b9VlmfZFd1lO3NFrKDz6Naq+o9bCVBrZbC4fmCSz4Io+kXvG3Ax0WBXe54/t2ZyjpVYRpD/pSuwjMdOI8+s++uta0qfypYVXPdDo7OkdMCV3IIdzS3B+wP0smO+1rKvIupOxVfquYvqkGkkOfiGHSF7B/HSwUAO/Xysj343TDBvJYtwfmHOkE0o32lfdh3hTyNNLKYyyyzrzjoFjkGNEZqhP6KPS23J8bYPGhMlPeZZlOHS3xjVQrVwr9x1LBKWNaOxrN2QnaWRu0LF9HT7G+nQuG1lGmqnNYMW8smEvhztmHQtakj/Q1rGdngAFX6icn5WpNmdW3oHeeVrrRhqD99kFmXvPnqgq0NmgFBRuskPV9X7T8lrhiMv8l5+qLvChKFhgvIgq6SzAXaencizovNHdR+qFuxh/E6kcV7NYZG/1ikekKUwECEUm3y5GJKHelc4DwXSD8It1TfPqXqyGYbr90sarkL2CdHnVSxlwN+TT4B4oekazBf322d4GOmk8tL1FxYJol8YTOPIsj6xAvsBdqn7G7G4r7eIpvmitAH5k5RGti1ilhkmN454RjAhqrkXSAcrTRwddyp6sAzn4EvuZiUDWzfmcodAmaF7T/89odZ6ZHR4ttSJatkYZE/CeatfjR4umOlx3I8x01vXPSeYggPH2RDOVWYkmf0ey9cd/ufIsi+jf9DRJ5/r5CYefWFDK9FuzVfCDbgZ4TOzxdN6N4HK164C3JBIOHx03qoaCpIxV6q7MD8CLGR1nULobg0= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: ca1149bb-bdda-4fa0-3d38-08d7eab8cf1f X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2020 14:39:36.7710 (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: WPM2fMFi0XiRwEWqjl8m8lloZ224qo+VoN16COzuBuBtJ822RMHnZr8Mh4pwTXv2KOzhVJhuQv9cHxQLEt43+y7GM9jT6zcSVdW+fHbnB54= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5527 Received-SPF: pass client-ip=40.107.22.133; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/27 10:39:31 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.22.133 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, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@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 use bdrv_co_block_status in bdrv_make_zero, so move it now down. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Stefan Hajnoczi --- block/io.c | 82 +++++++++++++++++++++++++++--------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/block/io.c b/block/io.c index e6a8ead46c..3bc0daec33 100644 --- a/block/io.c +++ b/block/io.c @@ -2178,47 +2178,6 @@ int bdrv_pwrite_sync(BdrvChild *child, int64_t offse= t, return 0; } =20 -/* - * Completely zero out a block device with the help of bdrv_pwrite_zeroes. - * The operation is sped up by checking the block status and only writing - * zeroes to the device if they currently do not return zeroes. Optional - * flags are passed through to bdrv_pwrite_zeroes (e.g. BDRV_REQ_MAY_UNMAP, - * BDRV_REQ_FUA). - * - * Returns < 0 on error, 0 on success. For error codes see bdrv_write(). - */ -int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) -{ - int ret; - int64_t target_size, bytes, offset =3D 0; - BlockDriverState *bs =3D child->bs; - - target_size =3D bdrv_getlength(bs); - if (target_size < 0) { - return target_size; - } - - for (;;) { - bytes =3D MIN(target_size - offset, BDRV_REQUEST_MAX_BYTES); - if (bytes <=3D 0) { - return 0; - } - ret =3D bdrv_block_status(bs, offset, bytes, &bytes, NULL, NULL); - if (ret < 0) { - return ret; - } - if (ret & BDRV_BLOCK_ZERO) { - offset +=3D bytes; - continue; - } - ret =3D bdrv_pwrite_zeroes(child, offset, bytes, flags); - if (ret < 0) { - return ret; - } - offset +=3D bytes; - } -} - int bdrv_preadv(BdrvChild *child, int64_t offset, QEMUIOVector *qiov) { int ret; @@ -2773,6 +2732,47 @@ int bdrv_is_allocated_above(BlockDriverState *top, B= lockDriverState *base, return data.ret; } =20 +/* + * Completely zero out a block device with the help of bdrv_pwrite_zeroes. + * The operation is sped up by checking the block status and only writing + * zeroes to the device if they currently do not return zeroes. Optional + * flags are passed through to bdrv_pwrite_zeroes (e.g. BDRV_REQ_MAY_UNMAP, + * BDRV_REQ_FUA). + * + * Returns < 0 on error, 0 on success. For error codes see bdrv_write(). + */ +int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) +{ + int ret; + int64_t target_size, bytes, offset =3D 0; + BlockDriverState *bs =3D child->bs; + + target_size =3D bdrv_getlength(bs); + if (target_size < 0) { + return target_size; + } + + for (;;) { + bytes =3D MIN(target_size - offset, BDRV_REQUEST_MAX_BYTES); + if (bytes <=3D 0) { + return 0; + } + ret =3D bdrv_block_status(bs, offset, bytes, &bytes, NULL, NULL); + if (ret < 0) { + return ret; + } + if (ret & BDRV_BLOCK_ZERO) { + offset +=3D bytes; + continue; + } + ret =3D bdrv_pwrite_zeroes(child, offset, bytes, flags); + if (ret < 0) { + return ret; + } + offset +=3D bytes; + } +} + typedef struct BdrvVmstateCo { BlockDriverState *bs; QEMUIOVector *qiov; --=20 2.21.0 From nobody Fri Sep 20 22:16:19 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=1587998849; cv=pass; d=zohomail.com; s=zohoarc; b=IDNAL2u3NQM8gcGWcF+LhtIKbzM19vRjfjTiRk+Vs2pyG6E/javrMWbbLu7BqJno3aMriALz6rLZRTbAZxvyF89AqMfPZEHI04ezpBx2SHlTQ8wUr2DmAcp4A4AW0LyLM0H25Ek7m/hCJ7OZ8SM1Qb3976ttVKCc9diPD5MGLyk= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1587998849; 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=qhCI3mR5pgL/iYViE4V7hx6uZsZTQBrSjdHTZOX0Z4A=; b=UR0FV6PDGV5o7AiRZKuueHRavUiSmS8ZF+qTJM41ci7RS3l/10azi6bYo5Jm/0nUiOKiuRrxV59Mf6fgCuA5vlnHjb9lgmzbu9Vf5SdQxWMhWM13SEL02b8GKnusFn+8sG8LUsrNjfjcOhkqorOECx5+ewrWUhV26mEvq66/148= 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 1587998849536191.67031762193574; Mon, 27 Apr 2020 07:47:29 -0700 (PDT) Received: from localhost ([::1]:49018 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT52e-0004Xf-86 for importer@patchew.org; Mon, 27 Apr 2020 10:47:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56930) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jT4vH-0008Ux-5z for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.90_1) (envelope-from ) id 1jT4vG-0007o8-Ow for qemu-devel@nongnu.org; Mon, 27 Apr 2020 10:39:50 -0400 Received: from mail-am6eur05on2133.outbound.protection.outlook.com ([40.107.22.133]:24288 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 1jT4v7-0007iF-7A; Mon, 27 Apr 2020 10:39:41 -0400 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com (2603:10a6:20b:dc::15) by AM7PR08MB5527.eurprd08.prod.outlook.com (2603:10a6:20b:de::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.22; Mon, 27 Apr 2020 14:39:37 +0000 Received: from AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9]) by AM7PR08MB5494.eurprd08.prod.outlook.com ([fe80::acfa:5:88c8:b7b9%3]) with mapi id 15.20.2937.020; Mon, 27 Apr 2020 14:39:37 +0000 Received: from localhost.localdomain (185.215.60.182) by FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2937.13 via Frontend Transport; Mon, 27 Apr 2020 14:39:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CX060VwXV9NUZgzkd9ARvUT1XOMgkOcRwtwW6gbSOIm9wJ/QBczxx4nqJ+tTwXbC5a6IzniVx1JWp8R5mjpTKRVXTvnEwKnu9q19Lz+wi4yZ32XDOE2sPc1SJrvWqC2FjOisfuiFR5uX8PI7iprTX8PR1MFh6mlkYEY4OHq3e5Bo5lgIOkOF1RsIriLUQSoIV7nPa9On12+5aJdLoAA0VlekPPBJVZsyS2ZdTRn4nxoLAUpldAer4FUt59XVJYPyFXQr8ry51ogHXfCGaOEMBMCbkqJBtCAFTGZVwQVST9K9gpVd3aPwCoDjJC5ZydOIMbvPKFM6wCbHoxEW28WQTQ== 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=qhCI3mR5pgL/iYViE4V7hx6uZsZTQBrSjdHTZOX0Z4A=; b=YQT+AnsX8VGWVvRS1NqYiBQZaDJulWyVYwluM+tdNQjclrjkW+iEcpUmuDpCLSRGp6yIpIFI0m/flSk46h+T1Az+o8xTr62x7y0iMm03IXEScn0ZCcVs6OMJjzJzYZw8dqUC8A/4ej6fCpQlSYUmWgm2jrJ/Jk8iOg+npYjCi01eyIKW/nsw02YciltKAgs6o9hJaIAE1QGCn92Nrmnhv0BSdPW6M9RrJkkPatYTP6SaDaAPAi6n1WMwYlzF4UhdjdDDbcIx9pSMSh7G4oikxP0ufJy62ENT5a6Nj90vehKXodiM3W83+wmEB7JGsPCQkwLVICjw1xYCXrXiQQnxJQ== 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=qhCI3mR5pgL/iYViE4V7hx6uZsZTQBrSjdHTZOX0Z4A=; b=ZHj8Sg0Dnv4B4qN8LiLeNPRVisbFqUSb2h/z/t9yo6LiyxOLtR3xvlREnz6dMshkPKk/zfXmxcTm/cUPBawQyqKV+HfLE/t+pIxs8iz312IQu+azTieajqA+Cqxnsn9l0v9QjONSX41qNChvsFRJZA2MjFLuGSNRtKl/4jdkiAI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=vsementsov@virtuozzo.com; From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 9/9] block/io: expand in_flight inc/dec section: bdrv_make_zero Date: Mon, 27 Apr 2020 17:39:07 +0300 Message-Id: <20200427143907.5710-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20200427143907.5710-1-vsementsov@virtuozzo.com> References: <20200427143907.5710-1-vsementsov@virtuozzo.com> Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: FRYP281CA0010.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::20) 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.182] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6b1b9897-6afe-48c7-449d-08d7eab8cf90 X-MS-TrafficTypeDiagnostic: AM7PR08MB5527: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-Forefront-PRVS: 0386B406AA 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)(39840400004)(376002)(396003)(366004)(136003)(346002)(5660300002)(107886003)(316002)(2906002)(6512007)(478600001)(6486002)(66946007)(66476007)(66556008)(69590400007)(1076003)(2616005)(956004)(81156014)(16526019)(86362001)(6506007)(52116002)(186003)(36756003)(8676002)(8936002)(6666004)(26005)(6916009)(4326008); DIR:OUT; SFP:1102; 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: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GfUIeXB7MPLq/l6bYP1esF1UvzDwbKMUP1sIu73zk0W4SQTLbHujYK8mPBDDs/n7MgtCWE8kuRPz5eeBL4Lv71pzW7yFWqycpn1PVGZuhzuDIbAPLlzbpUKvPkTlzbRRjckZISCjxTh1AupX/DqnWB3C1i2Ng3UjIVPBNZkM3ktSUIBqKaZUfFe+9s0+7yw09n3uNIYoZU6xWFbNYOfQMgW0vE8GhUqcwHSx4Fuh18h8otthCMB483yb+zMG7E3e1jqz40tNvEmGB2fyQ+OhL7lkjYyiGckaik8yiVO2u0EYRrKJjVSEUmRFfSkQA+3PI5V9GRHm6yr61t151h7qiCttLk8tI4H+lrS0WJkqD6lZdYV6HXnOa4vnDsrUUHY2AtcMDxl7T5vaIplvrCFOA7P4Md0sFBW96bfvSykN8YA7pNl8Uh5wZGUZZcP9Tdq2vUXG6AdcaqxR0pC7nKtfC9fUxgUo3Sj4x8EWhfs+0Z6ne7c52lgoR/5ZUqSKMmlz X-MS-Exchange-AntiSpam-MessageData: /bq9qBvTjGt8cgaZpRk2MmKrx5dUa0qYqnqVFB7M+nX7axKJB+bHh1+XkZ8evEMB3Ueh9hnesol7uUxNiwOIie2ovZYg2jKgHG77hJ1obob2wgPGkGTnw9KtTg34pSSFcuLMedQoXf0Ks1yhZYtMH14Hajg+5SlKyyiLbp7BYBVMQWvcz0IPOEjTvi16IPB822E/xqFLxKVLdlx9gTiIyujfbMfzV5kUI2684tXfUTt31gl8PgCig4lXse1620y15WQEGR6c43WtlwuM20FjTiBtpc4hDxFWkn7MAWbBJA1TMQ3ow/RfyfQNltT2XuuWbTag+IXWki+utsDMqMFHrmzUbyGcJ15xMm2E3iZGuTA2nnrcROtQw8TXo2EYMAAbn2iFHLAi97nUiJ2/TmDEHvt1We3pNhe41eVn6WyUXgNk1sLBfHkBvTb1xKpUwgMYVGUK8l0w8kwg09ueah9JuX5kXviEjvFdoMhy1XIePfoX+/4JLi6YOjLBCZrur6bOAsPCM3HvyzPd20D3y666nDzVFPTQEZbc3tl2kCCWs7C+OuNN2ES8vTHUT9DvxSNt5rNfAsSWc3TgwuZLJF95Ytc7haemXiTgr97OQImKqYmC/77xwZ8U3EoIeOCWaX70vvQJHAeVdi3mRG6CeQb9v2mz5tXINKquAnp9wjrI3nQAYZn7AEeGW9PVip6nfi5+oM3JFiI8CUVTD/nqvw5BQ65zHscxEwi+2JKHHHH/U19tu0n6mp3uWVBOdYCr77WF5HwUEJ3jhKA8YOvvk7I/1OE14Y8EvBkEWQXFmUMyj2o= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b1b9897-6afe-48c7-449d-08d7eab8cf90 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Apr 2020 14:39:37.5436 (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: Gj9UX7klU47bQ9As2zCq1K29MHjf3FtlSkd6QrMsKgwGpe2Ase4pF1OtB9Y0JmMPmflW5uhE4K9am4kDnNFuzKOFYgdzpdlICWeS5749qFg= X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM7PR08MB5527 Received-SPF: pass client-ip=40.107.22.133; envelope-from=vsementsov@virtuozzo.com; helo=EUR05-AM6-obe.outbound.protection.outlook.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/04/27 10:39:31 X-ACL-Warn: Detected OS = Windows NT kernel [generic] [fuzzy] X-Received-From: 40.107.22.133 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, qemu-devel@nongnu.org, mreitz@redhat.com, stefanha@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" It's safer to expand in_flight request to start before enter to coroutine in synchronous wrappers and end after BDRV_POLL_WHILE loop. Note that qemu_coroutine_enter may only schedule the coroutine in some circumstances. bdrv_make_zero update includes refactoring: move the whole loop into coroutine, which has additional benefit of not create/enter new coroutine on each iteration. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- block/io.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/block/io.c b/block/io.c index 3bc0daec33..cd5374e6c7 100644 --- a/block/io.c +++ b/block/io.c @@ -2740,8 +2740,11 @@ int bdrv_is_allocated_above(BlockDriverState *top, B= lockDriverState *base, * BDRV_REQ_FUA). * * Returns < 0 on error, 0 on success. For error codes see bdrv_write(). + * + * To be called between exactly one pair of bdrv_inc/dec_in_flight() */ -int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) +static int coroutine_fn +bdrv_do_make_zero(BdrvChild *child, BdrvRequestFlags flags) { int ret; int64_t target_size, bytes, offset =3D 0; @@ -2757,7 +2760,8 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags= flags) if (bytes <=3D 0) { return 0; } - ret =3D bdrv_block_status(bs, offset, bytes, &bytes, NULL, NULL); + ret =3D bdrv_co_block_status(bs, true, false, + offset, bytes, &bytes, NULL, NULL); if (ret < 0) { return ret; } @@ -2765,7 +2769,7 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags= flags) offset +=3D bytes; continue; } - ret =3D bdrv_pwrite_zeroes(child, offset, bytes, flags); + ret =3D bdrv_do_pwrite_zeroes(child, offset, bytes, flags); if (ret < 0) { return ret; } @@ -2773,6 +2777,50 @@ int bdrv_make_zero(BdrvChild *child, BdrvRequestFlag= s flags) } } =20 +typedef struct BdrvDoMakeZeroData { + BdrvChild *child; + BdrvRequestFlags flags; + int ret; + bool done; +} BdrvDoMakeZeroData; + +/* To be called between exactly one pair of bdrv_inc/dec_in_flight() */ +static void coroutine_fn bdrv_make_zero_co_entry(void *opaque) +{ + BdrvDoMakeZeroData *data =3D opaque; + + data->ret =3D bdrv_do_make_zero(data->child, data->flags); + data->done =3D true; + aio_wait_kick(); +} + +int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags) +{ + int ret; + + bdrv_inc_in_flight(child->bs); + + if (qemu_in_coroutine()) { + /* Fast-path if already in coroutine context */ + ret =3D bdrv_do_make_zero(child, flags); + } else { + BdrvDoMakeZeroData data =3D { + .child =3D child, + .flags =3D flags, + .done =3D false, + }; + Coroutine *co =3D qemu_coroutine_create(bdrv_make_zero_co_entry, &= data); + + bdrv_coroutine_enter(child->bs, co); + BDRV_POLL_WHILE(child->bs, !data.done); + ret =3D data.ret; + } + + bdrv_dec_in_flight(child->bs); + + return ret; +} + typedef struct BdrvVmstateCo { BlockDriverState *bs; QEMUIOVector *qiov; --=20 2.21.0