From patchwork Tue Jan 16 13:04:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10166817 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 2637C60325 for ; Tue, 16 Jan 2018 13:09:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1806F28470 for ; Tue, 16 Jan 2018 13:09:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0BA6B28488; Tue, 16 Jan 2018 13:09:54 +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 60C1D28470 for ; Tue, 16 Jan 2018 13:09:53 +0000 (UTC) Received: from localhost ([::1]:35189 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebQzw-0006cR-KN for patchwork-qemu-devel@patchwork.kernel.org; Tue, 16 Jan 2018 08:09:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55748) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ebQvU-0002op-O8 for qemu-devel@nongnu.org; Tue, 16 Jan 2018 08:05:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ebQvL-0006WQ-8P for qemu-devel@nongnu.org; Tue, 16 Jan 2018 08:05:16 -0500 Received: from mail-ve1eur01on0091.outbound.protection.outlook.com ([104.47.1.91]:25568 helo=EUR01-VE1-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 1ebQvK-0006Va-VO; Tue, 16 Jan 2018 08:05:07 -0500 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=dzrJ6E1TLwhjhu9GHNeyMFsPVECKfM46zlwMqw6O/t8=; b=Dy6X/EJFbXkHkW/H7PB1J4mmM2w9LBKD5Ppf1TzOHuhHzdCyBilulO8MvrjuhrOmycfJanfqpU7l35ko4HCNVyeCnUR54XEffOZid7D+FNCKzN1bhqcUDHRf4WRvFuM6de+H2E3Vgm6Zwkqbre7E6f+Mej6K7R53G8TV7Ut2KhU= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by VI1PR0801MB2000.eurprd08.prod.outlook.com (2603:10a6:800:8a::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.7; Tue, 16 Jan 2018 13:05:04 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Tue, 16 Jan 2018 16:04:28 +0300 Message-Id: <1516107870-8110-8-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516107870-8110-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1516107870-8110-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1P190CA0006.EURP190.PROD.OUTLOOK.COM (2603:10a6:3:bc::16) To VI1PR0801MB2000.eurprd08.prod.outlook.com (2603:10a6:800:8a::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ed9f0730-9358-410b-9f11-08d55ce1c2fc X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:VI1PR0801MB2000; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB2000; 3:ODNDX+DRyaTXupFuWbW5He5rJ0Mkh0dIjE7HrdVsFq9Gov+ARjisjDMW9vou4quCGx8+Jv0ORq06xGqLW4ZuNHMvCcvvKEnMqtDC14EdCsEzE2erdvs5LzGnizXjPx5Vh+icl6QAgliZB2yJF7baa9ndei2W6dcEHw481wAUJ4HthBVsQ/zgg+yD2vkH3EHcJoK+PaxNxseeljFwhm55F3lvM8APVwMfqFwtoxW6gktV8h/8YUxA/qha7BePzDKO; 25:HgsERoD/XPXgXh1Rbfo04EarShcy//8cA4g9ybAIci7ar2e3TKNvoFnq+c5x37N56eeLOyxhApyWQst0Qf9GsyOqKrrvCYSQRz9PpeZBrfVSMPW2hNSIE/RUw+GcbiMspQ1LizxIi2X0YiNytyaTNaAAKWKrBW4A1vBBzSFpT/qb5P5SbctCnFHICnjzVgprsQB2jkFainK9oc0PIJd65rw/lnJPqYB57JoLSIH9WIxl7dSWzunE1OXj3ma5vm6yRZrRREmAeC66pFlan9SiMsfK1FCS+TWjdQsBAUqDTbHMQAVhrF8RVsV50B+TjtDcN/gHlY8BT1Jp6uaxasbGNQ==; 31:dsqwz9JgLlJhIkE6sp7fro34RrvXVI3QXm6Wbgd4YfYGBSy16iivFg8JY70tbLau2zmOrpxd4hprjXtBkslKBZb/nUsaZkF0K1bSDhlxMBe9KXURoC2rcG/FvbL42ehgvmqk4nt56OaX+F2xgowvP7Odj7CYBG3TUiRfUCUdfUaqtrvGxZp9LAJ+gndBuHs4mQtZ+smndRMtfmhmXkNzVivlTrLZ3lCICGdlS0Y51I4= X-MS-TrafficTypeDiagnostic: VI1PR0801MB2000: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB2000; 20:GKEJV28OwWzKLB/aLixYHmZZ9NVcx/f9TtWaHbI2b4t1zifQeIWdXX/WcrKXLHl0owQ4KbFJP8LR5h9AlvX/ZN4kiKTmi5f4oBeNpQKNnA5aziXeXSzxO7WmSQ+GJ3Re/szDKnN9+ULnEPHxbwxlcblLKiEFCH/CD86JY2vklgTsQApUhf3wE+jctWtq10R0bTi7Bh2q3dzo1PwrkublW2WWNOHJBjVFuDump+6Lefl5ZrRp8XPDcJteeukrMD4r9+Zuqy4LoHjCNsrD0GHjsGGtqcjcGYi6rH7y3mfGHTAm91/q7wfNEb/M3zIEOdXl807e/UPHYv8bcpXU8QBKj2BQrFutWZ0tUN7yT8PpliIyCg9IFF5EIi24to+lEXjNIKOOmHkuxnyeTqrM8MljwiSnggBpYZx64zrnIztV+t0=; 4:1JBagjHN7xjhJqUetWxOFYfAZJx6nUIJCQOK7IIsch1VgvUMNC/+QvuKWdqd8THFxSs9JrdbTVIF1ceDV9R9VusV5gClAcas6Enx++ZAygW/Q4FR2xU2R7QAn5z8sVw5CsG2g3NIfPEq6ysiq+7cTl0c5cPG6/UpIBQvaxDyq8259pPny8LzhHtJK+XSFQmtfTc5bqeNbzKHbxwp1idlXwQSsxn5aBgOSakNgWUK9wphC4Tqo+01KmiXf1zMPxVIYFxkNA8xwW4xxbkuddruUQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040470)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(3231023)(944501161)(10201501046)(6041268)(20161123564045)(20161123558120)(20161123560045)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:VI1PR0801MB2000; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:VI1PR0801MB2000; X-Forefront-PRVS: 0554B1F54F X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(396003)(366004)(39380400002)(376002)(39840400004)(189003)(199004)(105586002)(2906002)(48376002)(6916009)(2950100002)(5660300001)(53416004)(66066001)(6512007)(53936002)(26005)(50466002)(47776003)(16526018)(6666003)(2351001)(478600001)(36756003)(106356001)(2361001)(69596002)(51416003)(305945005)(68736007)(4326008)(8936002)(81166006)(386003)(52116002)(3846002)(25786009)(8676002)(81156014)(6486002)(50226002)(76176011)(6116002)(6506007)(97736004)(316002)(16586007)(86362001)(107886003)(7736002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0801MB2000; 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; VI1PR0801MB2000; 23:NBtzYD/FTobbayLlvANeDMVc3JctCOVhZx57Kds?= =?us-ascii?Q?IM+BTbBjpebrsaGBfJJcTdfCnswBPHTm+t+gAvAMm2BncMU4zxVOeG+ukXJj?= =?us-ascii?Q?8u/SAl8y28fuTuUCItmzYJuHNreJJmCK3zUQOc1fHoAOR439FFgiV3haRd9n?= =?us-ascii?Q?90/VQ95telR+AYBqNnIQJa3lM+h+56qhWgZrFuhsUgyylGdO4DPyCwAy390x?= =?us-ascii?Q?kBa9zPg2kL3VWzkZNA6HK3lVinsXEkW+Xx70tXW83HnOi/kB3+9Xph3GBVFe?= =?us-ascii?Q?y/kt1cDd9DZ6LHlH0COjmG6X2mntZti6bat+jY0XpY/YKnpfNDanqPqluTCL?= =?us-ascii?Q?gU1Q7pEqloJHLPIjEI+h1ySdMdL2dJYV6/dj2CKBBFOnh8BfFQ0C4NucYZCN?= =?us-ascii?Q?3jMocBjdMHeIqHPsJPFegvxx6SVFCvFNt5P1rW3FjFAKOlLCcIilhoCDUTm/?= =?us-ascii?Q?L55yLniIDH3zyPB4/qO1FcrMBZhFgw0OX3udDyz8VdBSzTim/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cQDo0JPhK5IQ703s0LZwUN2VJSdIVl3hW+iYbgsoawhuGZu9icB5TYZue5/0aaBDFnSLTpWTwgI4IfKDk4kiDqRktd2JxJHXtPoQXFfXYU+QA2EigQw75O6d6gDkrKUSShcdHck/2dfFlQrCLoPy+msYIJedA6qYFA6teXW3XnsIzBE2g5oG+gR5PM=; 5:0cMB1VLkJZ+ZDhrCKIuDoXClaBQ8wl2YTtl2syYs2cQ3zkM3tox3hPS/Yb2BuIuCfG+4fABmfliJSQGysmoKtIQCzFB1XO3Y8TghYprhbe1HcYBxv47DsC2WZYuoalv4yCRk0xVNXl/FXuSMdklYlFefctKrWkigZwmiOojce5Y=; 24:xDqhNP7mVBEbD0b5LablUh2IHu5yLRx3k8xeS+r7IYVhXsZbX66I445gB9ENFcuFoGG0EKFTiWiXECQl167J/Dc54AeM09o77BhsTzkZiok=; 7:Djx0RD9fB9FFBN1d9eK7A1EqhczsPquSMdgCMEUYf2VEjBHKTgx34z7k8M0HGbmxUZW+nh1lL+vuNSBPSqD38DZINNf06FZMK605fhpM8brF7wKTHUIO1VoUtFfM/wlCUkMZdWMVO7zuT8dVulrBpiba9VrPfsX15mJrpjBB73/Di0+19wDbvdmXSm0SNV71LNO6n8NqHyB2cw/FqZNsUBsRWvnd77pxjh4CbE9uPf2CcVxN8kUhAkpYdVsfXxIE SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB2000; 20:Dl/YJ57OlTITTh2VA2BQX/CWyky2tJlEbzbITrheKl1oF4Rz+KMlS8lCDynSnbbZSnd9vk609SfZzlpZ3mrdSAwba1wrghjR9m1Uk/SzRn+ziwBL3YFd5xC+SO9nox3exGX+QyzEW8M8Koiw5vBU1b+UxWR1cn+4Z20L1qulQrU= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Jan 2018 13:05:04.4494 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ed9f0730-9358-410b-9f11-08d55ce1c2fc X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB2000 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.1.91 Subject: [Qemu-devel] [PATCH v6 7/9] 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 4348b2c..2ed21ff 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1858,6 +1858,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) @@ -2975,24 +2992,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) {