From patchwork Wed Nov 1 15:44:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10036687 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7CCAF602B5 for ; Wed, 1 Nov 2017 15:56:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 42F0B28C92 for ; Wed, 1 Nov 2017 15:56:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3771728C88; Wed, 1 Nov 2017 15:56:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9E36F28C99 for ; Wed, 1 Nov 2017 15:56:45 +0000 (UTC) Received: from localhost ([::1]:56434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9vNk-0000sS-Ci for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 Nov 2017 11:56:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9vCE-0008An-8J for qemu-devel@nongnu.org; Wed, 01 Nov 2017 11:44:52 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9vC9-0006fa-Ez for qemu-devel@nongnu.org; Wed, 01 Nov 2017 11:44:50 -0400 Received: from mail-eopbgr40133.outbound.protection.outlook.com ([40.107.4.133]:45238 helo=EUR03-DB5-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e9vC9-0006ec-5I; Wed, 01 Nov 2017 11:44:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=c5SgFoSUEyWVv6kYDhU/zrcJakgDN4L/NHCKe93+L+0=; b=cAFR9ymAi8Pck18Rt5j1stwUM87Qm78LNBSTHzsvFbUkpw+AS/sXxvuQen0lExLSzVplB0wqvJVyCU0p/DPzMFlIzmYlyEsoecEYzb6Pru6to15qK6aEC6EGv4k/bZXS4Pp9hOtTswrWRaQc76yuXiFZddbWKa4X61zG61RptuQ= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by AM5PR0801MB1987.eurprd08.prod.outlook.com (2603:10a6:203:4b::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.178.6; Wed, 1 Nov 2017 15:44:42 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Wed, 1 Nov 2017 18:44:00 +0300 Message-Id: <1509551048-129830-8-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1509551048-129830-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1509551048-129830-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: VI1PR0501CA0017.eurprd05.prod.outlook.com (2603:10a6:800:92::27) To AM5PR0801MB1987.eurprd08.prod.outlook.com (2603:10a6:203:4b::14) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8e58ae10-7fe4-4097-6c0a-08d5213f787c X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(2017052603199); SRVR:AM5PR0801MB1987; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1987; 3:qxccBL4T0pcJRYBnYDAp0W9ldShMNbjjxhrXlY3SXgn2zTXorqhOufHpOBGbm9kyWOUUDOLAYnzAQir2bz7THJ16WB0Bc+3vo0RsbHYeW5ORKOG/Kffy1WuRYWi6Rvr7DEQe3+k1DKbimHYwgVoI6ZaCUdpVAtXkpfldjjJFo5ZJvWDAnH62HBad+YoA25l9M4gtVZM3wN1XdeNUOuX2KBDZ++ihm7SN+2XkrVrqb+yGR1EQI3g2OwFaC1MprVqy; 25:1RmTQ5puaRmaH+qGl50og+KRwwoX912Gm/5JVPLy7AIfdKyJmNLD+2CkrviMYMBzYX0j14rgCM8LsBX3muKjuw/LnNXVqIeGnA3+/oWsMzJe6wWjrEld+EycDy7qW63O0JsACFyuh12J/MNv4PzLoNHXa8IKmNbS8QTpx++iGQH78SXhHFz68tKG5Y0CNnS7LswT79yYP7VNwquDTgzKqxLRaUwyWGpePnIZLIfWZlZZ82MlK56tlNdxqnT0nkZcAkQC4p0ZjEtxjgCtOjaqfgssT0NVOdE0qpNofHofoSPZjBxE6VAZbq9+7Ml3coOQZrun59FbFFhBUAeHZCEHhg==; 31:eg3u6JU/WYS1fg/rLg8Ve4C8GXJAaedf4qmVGmRHen83eieFffAdIz1YRpOb1/H8PFfojhLhMD0NaOCG6xPJOw3Kq5A2qmpGxn8CfXg1Bhd06BTIyXOOdF1cd754t1am+0ZTtaUl79TZQFZorVMFm7EAz3w3dj+aC0hx4U5tLc8MijOCx20Xg6Znx100kBzEpixEpSwc7Ily0zoAgAH4KlHFKWZ4z6YcTfVH+IYxNBI= X-MS-TrafficTypeDiagnostic: AM5PR0801MB1987: X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1987; 20:V+NTxW2Cf3bhroAzxYuBoLvv+PbxBvlK/oslLPoKIZcNN+Cu/t6HQWi/iGjJvw9WqMU0rSpU059mQfHqe4uH75mZTOEVSiJJEKB6idK15CyHqKhEWBr7FPqKJXzJPDokx5hWAgtrCpCDPPif6qW/B8lCMff/mZfQAw5ZJVNnzt9J+NhetXqqiO7VEcgtEWhRxNJDy0MmMts90qNIY9HucQ+qDXMZYz0s6+DaWbmq/+uzhcrQ+0ad9LfH/qezeCevOqQA+m8ELke7TpX/2dzbXfRAO2fhTUdJtkevGVQyIKCXiJlFRHqF38MDG/3wCV/s41dbFRICKCCh+jFUVV89rB8+KEgHQ7t0hD8xiU2yECLyZpuyBfanIkdhQnsOirMXYoVSmg2Gtz/PtuiO58nY7zdkBns8kdeUUGw9ynsVk8k=; 4:pMvoxULWwR4GWStqKKhECPdfdUUwRvw20ur7DeDGZlgkuTMlXo6JumEE3ZxhEbbaLOJswoydiNkRfvCoi+Enha6QVa6JQGYmJlYG/tOTvJ0w2w5cRQ670xjlPVbVQ0AzX88oYDRU6wtrGiO5x2tFtlT9Etumr3IiZWEJUB1A2bGkv5TWBrdAIXcugihcp4A5nUqhL1AaT/ncyqSvCmIc8XdMMqfCNagFLxGUp6OTO5gPFrNHuFrBFDakrSCziFloK/9973ftRVV7+SDvo7EWtA== X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(10201501046)(93006095)(93001095)(3231020)(100000703101)(100105400095)(3002001)(6041248)(20161123555025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123562025)(20161123564025)(20161123558100)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:AM5PR0801MB1987; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:AM5PR0801MB1987; X-Forefront-PRVS: 0478C23FE0 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(376002)(346002)(189002)(199003)(6666003)(16526018)(53936002)(107886003)(48376002)(86362001)(6916009)(2950100002)(3846002)(6116002)(101416001)(50986999)(76176999)(106356001)(69596002)(5660300001)(25786009)(105586002)(316002)(53416004)(2351001)(16586007)(2361001)(33646002)(4326008)(5003940100001)(478600001)(66066001)(36756003)(50226002)(6512007)(47776003)(2906002)(8936002)(6506006)(97736004)(6486002)(68736007)(305945005)(50466002)(81166006)(81156014)(8676002)(189998001)(7736002); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0801MB1987; H:xantnef-ws.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM5PR0801MB1987; 23:aNF1rEknseLYXTkoUkY3Qd0v+SpE/cueRJMuOmt?= =?us-ascii?Q?geLsD+lvLsiFiYBILNHLdMYrhJscHRIQotAOt09NSME+Y3DlZeSHzoVOR59f?= =?us-ascii?Q?9Ocm7UNN/TELhcLi6lQ/ldOJ5jsjz7v+3bG55nWRgxw3UitWT8LAerxGlc1N?= =?us-ascii?Q?4YZ5JaHtdAOdXdhxhlRKn7gHK48KZaYNmzMGbL6+mfkNwBwbr4h0PzUgfYmL?= =?us-ascii?Q?nckS1u8eS80eiJAKvAHDRGwIHBPibtsvvr4YZZM4IUFrxoybPYZsDc/zpgL9?= =?us-ascii?Q?av8O1sF4hxZxh7QIZXR6Gh/AqRWJwtZJ6ybFipxmLG5wpHSRXJj8w1B2lU0h?= =?us-ascii?Q?B1mVcYk+mW+IKfxdk9fO0fyxkfvZXXL763PoGZK3adwFEfcXlhTVynvjBFns?= =?us-ascii?Q?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pIMX4hI1kM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2017 15:44:42.2588 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8e58ae10-7fe4-4097-6c0a-08d5213f787c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1987 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.4.133 Subject: [Qemu-devel] [PATCH v5 07/15] qcow2: move is_zero() up X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Anton Nefedov , berto@igalia.com, den@virtuozzo.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP To be used in the following commit without a forward declaration. Signed-off-by: Anton Nefedov Reviewed-by: Alberto Garcia --- block/qcow2.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 92cb9f9..db759ce 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1881,6 +1881,23 @@ static bool merge_cow(uint64_t offset, unsigned bytes, return false; } +static bool is_zero(BlockDriverState *bs, int64_t offset, int64_t bytes) +{ + int64_t nr; + int res; + + /* Clamp to image length, before checking status of underlying sectors */ + if (offset + bytes > bs->total_sectors * BDRV_SECTOR_SIZE) { + bytes = bs->total_sectors * BDRV_SECTOR_SIZE - offset; + } + + if (!bytes) { + return true; + } + res = bdrv_block_status_above(bs, NULL, offset, bytes, &nr, NULL, NULL); + return res >= 0 && (res & BDRV_BLOCK_ZERO) && nr == bytes; +} + static coroutine_fn int qcow2_co_pwritev(BlockDriverState *bs, uint64_t offset, uint64_t bytes, QEMUIOVector *qiov, int flags) @@ -2998,24 +3015,6 @@ finish: return ret; } - -static bool is_zero(BlockDriverState *bs, int64_t offset, int64_t bytes) -{ - int64_t nr; - int res; - - /* Clamp to image length, before checking status of underlying sectors */ - if (offset + bytes > bs->total_sectors * BDRV_SECTOR_SIZE) { - bytes = bs->total_sectors * BDRV_SECTOR_SIZE - offset; - } - - if (!bytes) { - return true; - } - res = bdrv_block_status_above(bs, NULL, offset, bytes, &nr, NULL, NULL); - return res >= 0 && (res & BDRV_BLOCK_ZERO) && nr == bytes; -} - static coroutine_fn int qcow2_co_pwrite_zeroes(BlockDriverState *bs, int64_t offset, int bytes, BdrvRequestFlags flags) {