From patchwork Thu Jan 18 17:49:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10173771 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 56493602DC for ; Thu, 18 Jan 2018 17:56:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4381928382 for ; Thu, 18 Jan 2018 17:56:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 38566283C3; Thu, 18 Jan 2018 17:56:19 +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 A261828382 for ; Thu, 18 Jan 2018 17:56:18 +0000 (UTC) Received: from localhost ([::1]:44620 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecEQE-00021a-0i for patchwork-qemu-devel@patchwork.kernel.org; Thu, 18 Jan 2018 12:56:18 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52273) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ecEJg-0004Ml-Hy for qemu-devel@nongnu.org; Thu, 18 Jan 2018 12:49:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ecEJe-0004JM-Ns for qemu-devel@nongnu.org; Thu, 18 Jan 2018 12:49:32 -0500 Received: from mail-am5eur03on0716.outbound.protection.outlook.com ([2a01:111:f400:fe08::716]:42208 helo=EUR03-AM5-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 1ecEJe-0004Ce-Gc; Thu, 18 Jan 2018 12:49:30 -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=FrURudwleB2MOUYPla+1rid+Tvrxdnr8W1ScDtmkwz5PgurOWOiNIN3A4VfLtmJyiIen2nIXgcgvUDuQRHRHGCDiZPLKXiOQIBttYgxMa5k0kI5HdAw4IgFPj0ltMBGAQW4KDNy42j4nzJuzJtX8GgskTrtbtUUpocmrOQr28mM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=anton.nefedov@virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by HE1PR0801MB1995.eurprd08.prod.outlook.com (2603:10a6:3:50::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.7; Thu, 18 Jan 2018 17:49:26 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Thu, 18 Jan 2018 20:49:05 +0300 Message-Id: <1516297747-107232-8-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516297747-107232-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1516297747-107232-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR05CA0132.eurprd05.prod.outlook.com (2603:10a6:7:28::19) To HE1PR0801MB1995.eurprd08.prod.outlook.com (2603:10a6:3:50::8) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7fd6824c-96b4-4bcc-01ce-08d55e9bd15e X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:HE1PR0801MB1995; X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1995; 3:3mKIH736mtmmVRwHYLLP03zNkGBWl0cqTFuzMyXIuCodAnxl3Iwd8KGNi0Wb23Wo8XCG4JM1WYWyY+ln7FoILrnBh8CfpRLaL1zMUaSWGpNSjizlZVy3kUHcXxErE8/JOBmCyIH9HFPtXeLYWTe8HmQQX3HA04+bxibth97zl/xWmDkpyvyBXrLTKzsjXiD8j52/RJo2KhRv3zSJ3C7HvvWtvcCB0ynN7AjSkaEWgTtstf6WONa14kNOxYE52rxn; 25:yTdfzCJOJr/SGbQlo8As1bvYeabNAisfELTddtOhxxoMNH2gyjXYcmwF1B3fYsb6AkG5v4jS0v1bpQXCFYd0DEKPLvxGrrMjfye9VTkth2WP6onf8F8J10gJHFfaiq97fr9Qru7gvFKEWmRuiwSUh3/FO9bbMoPPWwA9GWs0ai/ExQwIi3firS7IziSIirGOtP8cIIpzeR+29hmklW+lwM9f3QU9d4BMAvbev5oBkTiNQVqlumY3AgI2v0+iY5ZXHs4rfxwTFxmp8ZnM4CuyEB26PFxTcVfcC8XeRue4kEMFg6h7aX7rPamyCgzFuclsPwOIU13ek1v1x1477n2k2g==; 31:3CVciJ4cQiwvlNrURQ4uyiYg6DhBs8waAWyaSqmWABiQanVLy20RziuvrscG127aBtH7jxLp3HWWvuzKmQKMVrexAHZt5VezWo3oEMU/56ZF4/Z8t/4FQj56JMz+yOI/1ooaeLPNRWgbSSbGm5NV6/938Xy1iVGAk5twyJ/cROjUzG96hiFwHK2G5VhyNwv44e2K/D+t484d5fdv9nwzO1jcdkXTUm9rjo7SRKY0/Ts= X-MS-TrafficTypeDiagnostic: HE1PR0801MB1995: X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1995; 20:DWhskCoOhkkyZ1VouWB4zI80E50OBDTndTliEn3vnkZxiGUd48pCEwntybGSefy1sXO9forn8JrelAa+YKI3bH61AD+GYmX9liY7cbBHflwtRI4cr4EzvgUWrTp+lh/7fjWpVnhRTcMeCeUzLqjGPGvSGwa3g68/zZ/iqdImr6+xqnS/Q1eO5nDgxtPqH6P1pmDnl6o+SZxGU0Z0g8F6k5N4f+CJxlaGP+HA5UKaqtdMlNVfO+96xDGw6FBgRuW2uy3jCItZG2Sqrv91UT4NFil4ZHCSeNYzCHH8TBMgrIeqAfgbB+S0UJA568WMDmxE475tZvrrGehvGFtEtgUB/llTamAfXY5Z1cHLJsNkWEq76bnJpbpU537STpXGM10swr7IKLkAVOmfikidsvfKdf1ao5y3pPpGCkPa416NO/w=; 4:bwj6jQZ1fYRXNpIvIeQifRD3tGkRf1Xh25v2wDeEpNPqbkcxk4m/3bqaIrT3gQ4RWSrUAG1DCLnLICWXjJzxUnDJiFInJqYV5v9gLuxHFoLPyleLOAtBe7RRQfELy4IZVkKxkCrZA1gcJUB855UwM23SuPWxUxA1TvUdUJSLGzN34TL25+SsA08LgDMPn62x++jAtL7tK+A1pvyc8Vie3I55794+ga/UXap1GcPdeAiR6hsEcCIb/0eMDrM0aqlS3NdwkeEW7y7CRRx4USUwJg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040495)(2401047)(8121501046)(5005006)(10201501046)(3231023)(2400065)(944501161)(3002001)(93006095)(93001095)(6041282)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123558120)(20161123560045)(20161123562045)(6072148)(201708071742011); SRVR:HE1PR0801MB1995; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:HE1PR0801MB1995; X-Forefront-PRVS: 05568D1FF7 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(39850400004)(376002)(396003)(39380400002)(366004)(199004)(189003)(50226002)(6512007)(16586007)(316002)(2906002)(16526018)(53936002)(2351001)(6666003)(5660300001)(66066001)(51416003)(6916009)(69596002)(7736002)(2950100002)(86362001)(2361001)(76176011)(478600001)(97736004)(107886003)(105586002)(50466002)(6116002)(47776003)(68736007)(52116002)(26005)(8676002)(6506007)(305945005)(3846002)(386003)(36756003)(81166006)(81156014)(53416004)(6486002)(8936002)(25786009)(106356001)(4326008)(48376002); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1PR0801MB1995; H:xantnef-ws.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; HE1PR0801MB1995; 23:+FLbRwtwWnKBACY4Q/5g2UDkVMyIaWKqS81EqBO?= =?us-ascii?Q?JaZtil5N8DSU00XMzbDS7B00Tkr6XCg9LH9p07L1EIp65byTk6JorzJAeCv2?= =?us-ascii?Q?Feqg00XF969jx41JCn1ES4k46dPustDzHddHaQrxANrLwo1H1Vh45yW1SjNR?= =?us-ascii?Q?u7Hnw0SQoUS1fb7SJ91UgZ4xPEGUT1WKgoiiHZRkdgrr/kgGYvxwFh4Xi3Ju?= =?us-ascii?Q?q/6pmNqry6Fe+QvyghulP4Wy8Y0LqhvpvGGMJR1DnyYtT430gby6oOs2jFUh?= =?us-ascii?Q?j5OfpDuGGSHXzJsBqqDGyMjqPEcBqarhiQZ/vS2fqvkK8UTJsSv2A6cU7ZaD?= =?us-ascii?Q?PtG/bJ0QH9HD4bq4TEbEBP0lPcx9ZxsC3NZurEsBkZ4AP2eFqAWcigHFHomK?= =?us-ascii?Q?cIRRStazFvLkNSLSShxXKW/nRajPkhviNdlwBu/yk+cW7GTXVP06yGAsynrI?= =?us-ascii?Q?BZwr8qB4q0dcHTcifQL3a6BockaGoYPO4XwScnG009iNKfwzOqKvXQoiana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X0bkGu+Q7tw/hSh41HCKo2GYYL9IkUj/KX0FQSawtbMrJRTE8hhzPOgO8jDd3qVre9QE5kkk4CV8MVu4ED63vZwwH4PBo2I+mMdDQEo8b9z4FX1aBVEesi8dGVRp3Iu2JFF4ioWs/bOQybOzM5Kz7mzpR3OlAODKarlQx7/k/ZRsLlRkG2U=; 5:9Y7yLFEzSkcxtKb8CMqjyUqZY6sHv3JMnjMyoGtMWKPidrz9u6af+hc4IWTdu2OGERMiTFobsif7rb0xcBDyYleHA2OlLcxz9dzQt6nJy2A9orSaYR9B/Y2vFG7RyKf1ajOVU3yGTCWFDROouQ1ydKAVasBkvnw1DYSBXpvYprw=; 24:RQ0CwCBSE6/7zoJ+FVV2pfwFc8lfoz9WR4B6JKFJzHaDqbxyr+kuT/mfzJCLVvag90fsM5cSt4T2L/5qzsGOVX9UGkms4U1sK4kJGSaj/KA=; 7:Q0dBEs0NMrcp7ngLmyl6g0ToTYY5k5a/OD1hycb1nFd0HE4NVsZ46risyK/ST7BdHsP62Lym+QO1c9OwbOliFCVmBGA2lQaqbR7J2cJclJ3DQClOOukpyoJSKfPPLxAUN3uUuiawR/5dwClzPsVBMCBrodk0fqFd1pvIUOciNyoSAVKLJecSbqm9rUt7fRSsQkhqUXtJ1wmyFqEe+sDry0h0FQqRl1tNsky+KdlQD+oxu4Y7OYJGDGdJu+b4uzet SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; HE1PR0801MB1995; 20:LeUDQAqSrLQ4HnuBM1xhGj3EE4+mTWnqAA2UcITXbUFGGgVHjYfpLbvs3E5KxxX5dSFhf1IfXK7Z0I3k5ZzCUV7EfihdgfMUQFLm3yW6EpT6lgIs0D5B6DjmvUz1W3jp3EnrXK2TuC3WuO9lkaqYAk6cD+yyAVqw7NN9mlY4ozg= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2018 17:49:26.5521 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7fd6824c-96b4-4bcc-01ce-08d55e9bd15e X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB1995 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 2a01:111:f400:fe08::716 Subject: [Qemu-devel] [PATCH v7 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 Reviewed-by: Max Reitz --- 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) {