From patchwork Fri May 19 09:34:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 9736805 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 0365D6034C for ; Fri, 19 May 2017 09:43:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0457C288F4 for ; Fri, 19 May 2017 09:43:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED01D28904; Fri, 19 May 2017 09:43:39 +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 3A9D9288F4 for ; Fri, 19 May 2017 09:43:39 +0000 (UTC) Received: from localhost ([::1]:57504 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBeRe-0004Xw-8l for patchwork-qemu-devel@patchwork.kernel.org; Fri, 19 May 2017 05:43:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48266) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dBeJb-0006m0-QZ for qemu-devel@nongnu.org; Fri, 19 May 2017 05:35:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dBeJX-0006nX-UA for qemu-devel@nongnu.org; Fri, 19 May 2017 05:35:19 -0400 Received: from mail-db5eur01on0122.outbound.protection.outlook.com ([104.47.2.122]:23424 helo=EUR01-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 1dBeJX-0006nH-K8 for qemu-devel@nongnu.org; Fri, 19 May 2017 05:35:15 -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=Ejcp/D2hSy4fWOcrEB88V3g2492GWdWvWbFxdxkINI0=; b=Cf7mXBBprfWPq5t3MIzca4Dt9hVNdOJGniRUVeaDUTNaeBaIpNsLl+x/CKWSxCL2N++wWpMN9YDJeBoWKIGYcUv7SHULSyICExFxc05RebyqsrOI8GWnCL0ho53BhjzZxCPDppYZDXn6EpmAtWD8kW2aG1P3tqR2LAreYLXS1wk= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from xantnef-ws.sw.ru (195.214.232.6) by AM5PR0801MB1988.eurprd08.prod.outlook.com (2603:10a6:203:4b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1101.14; Fri, 19 May 2017 09:35:12 +0000 From: Anton Nefedov To: Date: Fri, 19 May 2017 12:34:33 +0300 Message-ID: <1495186480-114192-7-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1495186480-114192-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1495186480-114192-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR09CA0073.eurprd09.prod.outlook.com (2603:10a6:7:3d::17) To AM5PR0801MB1988.eurprd08.prod.outlook.com (2603:10a6:203:4b::15) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM5PR0801MB1988: X-MS-Office365-Filtering-Correlation-Id: 98c35884-044b-490e-c541-08d49e9a599c X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:AM5PR0801MB1988; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1988; 3:94jCip6m7pjwLbAL6J+XSXf600SID1FnDrDf8qrYlcfTZeSn56o/APN3avO3psiT5lpPPr0v5x/ZOSQkiF5vlmOzpbFD4DzagODT3BQTyRi9Tcr/Kx5jlDB0DECpn6pmeeXxAMy21pTWODKYJ2+mRpuiseiNcq++GAimGlhUJvqQ/gp6l0BTufB0HQw/dRUdUTY4SDGOhF7EBEoR8HwjK1Fx6kV9AJqDSUw4TgJNUXuceE0UQCDe+SiSFZIbP2X/lZ7P9DltCv/DB6um9tpqUzjsGosJkggms0XUvnvUc004VvH2m7fBP0P6c2PqFoon4Ej85Bt+XQHBm2NOSpbNyA==; 25:fiCCaKhc9K+eiL8FQUBtmVlzqfse8vIm6J2cE5DGUs2Q9/t9PRnGWCcMWJHXSE8xVfRB1j8vcO/SA7NrCNzXxFpbec2GmKMG2SXDhIwVjYJUE0bBSuSZSmLHLkToY9sbGfxA2B9Wa83AC4GswYiz6m73R4OpDpA997GtXWIy1x5v/Hg+rX0tDi9jpapFxSRdgqw8gmkzTNYCDeGrgNd1OTgJ3fkrvR7lZ1D9gt0iLIiFPi9RPkMfLg1BWlluocifHyW8dNqeUauNkoyAh3+9FZIMUK4tAjllVoUg9ytvEKrXm9jBl/5fwmktgXG9Lxqd+rHQimyTmT5J3e+iuZS70bRh9k2QL0SXsoVaRbNZIFoNCP29hM3KWulk1dkh1n8EgX7DMAvlY17RMJ+tR6VuCW1eYz6E55P3At5cjUtsOJurKVh9s/IjtxdiyOWHANPXWlJL1va4+i9zd9jPhdSrYXxwBARL2eBD8Z2tB26AT9I= X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1988; 31:GdiOCqvYG3WRphuVJjucH33TfytwJhIZVzEEeuFx95pA1IH2n7fjxS4eqc4tEiBfZZzEMzZmSQyIsEcJBp17qi39TM6xDADqRPnh0ubQFS+I5NAV0rSToH32m6wN3sBJ4q+axFnb8hdQ2tGu+tGbcw94JgavLekXymwFF+K63gzCtLxlq3DzPPyFq+4iAoLRtiJ8AAgI4ETRFVgO6B+YFBprtiosQEHqJTYd9bTrKL0=; 20:IPBl1sG7O07LC2etqb0Kb6kjNQgHjPuVCzBHIbKui31ln3S2zU9r9dxvfg2wtAYw4yTIsTN+1D5Tu+ka1h5h+P9v8mk7RJBmaZPZGTRrjB224zpBo6HKmg3jLoKSdxBbyAE593iFFiREfMzMk6v22Lei3h3xWL61zTPASNCMEbdAnlo/HTMYqDtG0vcklSZyh4hTSDZqoR1ZlmQ1nsJ6mlzC+MmwN4rZYXuv7e8DMXRQmd5q2DCOPV6Y3SBjkcjDOC79HxH1LV6oVODfOnmTxE+51SHo1SBDlW84hs8Q/ce+V54R8RGgwu2ywnZvsOuL8q69AyYysRzIX3aiTYoo/UfHYCcfVzFaGpCFTM3+9NS4OqhGx+FJTWwKYiwNtSmluFEKpSpnSweLh4YufsK9iJp8NkEDk0404xYVIGLbfkY= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(601004)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(10201501046)(6041248)(20161123555025)(20161123558100)(20161123562025)(20161123564025)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148); SRVR:AM5PR0801MB1988; BCL:0; PCL:0; RULEID:; SRVR:AM5PR0801MB1988; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1988; 4:amq/VmC6s67emi3njYC4jG1guCW7ZpPcyw55qqVXZu0sMhkY6vMuW06rpeu5gnc0OCKUJY9dIFnc9liKXk1vp3wqp4gwAIALvBLCUhGVcginENHntfEvbIDOc3vF43qqwEalWlDxSE5Xuj3T2A0iVu6VHNRUTNmzn9I0Zmw5FyOiQxy+pBAmdJVg8dGNnduKdtVh9weQJoxj4JFOY462BIYUMF9CAOuiljSGhgEV76VaXwF9LjoCEB5HP71wjomKpZAakfn/uIpEExFy6zsQzYJmVg2fejRRpcxvawbPjZv5x1HMrhKJwUaJElbEbTV/yW8zN3xw2DcUZgu9SMw5l5hlzSwC0Gnz83ZjeGkWo2NVcRNdlS55C0Y5XZZ5EeD2W7LtqA7myRa5SC9gffP9qgoc0KbYHFST7Iw9uaJXAVXY+HGF9aa0UeMvS1IL5LlbZOPxL54vB8bKDIm+siuTrFAk6/cnv9m6MMH33eYStlZNYuRAqrztVt0wRZvbHMmoiucwWKh4APgjExLL8K4ap2MNsJMZQ2t/g6Zc1LY4Q+MiCXFzzvjMXAvCX4xiutZF/pT3zxxhxodbtTbA6QCbtErbPF8TToybw+iKnY620/TTIu6dXDcnJxme8hquVXiWWPeN2qbtE9wt1fx2ITQ8p+RUUW1ixgnYDPstTZwJQYDsc4UqAOwDVNT6wSeGLgVLjeVj5PT5q43MX0QghODcMyUySJvGpEzkx73z8v+if3kxJVQ5sfLopN1DEkFQa9jO2svpzRY0XoQmM8uhlkfNdA== X-Forefront-PRVS: 031257FE13 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39450400003)(39840400002)(39410400002)(39400400002)(48376002)(8676002)(7736002)(81166006)(53416004)(305945005)(50226002)(33646002)(5003940100001)(42186005)(3846002)(4326008)(25786009)(66066001)(189998001)(50466002)(2351001)(2906002)(478600001)(6486002)(6506006)(50986999)(575784001)(6512007)(54906002)(36756003)(5660300001)(86362001)(53936002)(2950100002)(110136004)(6666003)(6916009)(107886003)(38730400002)(76176999); DIR:OUT; SFP:1102; SCL:1; SRVR:AM5PR0801MB1988; H:xantnef-ws.sw.ru; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-asc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A6fX6rfHB1WkOBHPgHORl0FAiBrXU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1988; 7:RSozqZsImOQlxDE/1x5hF6tgHt8BixA9Jqc9s37G4kSMymRnMPMLB42TuvGi8tDNHCHzmt13bhGLYlCvouVfPdmES4CPrU+5nfGfljOx416jHy1JdxOZh1qHZ0td7itjrIE5tn68a6qcElD2qUoaOAeo1gKikdvQpeD4Q2zqKFQGgl0tyAkcgPzFzg04iK5LQCY2E5cRCjB+mYkReza0BD0N51e1y5NSrjKxY8s3h5nMxZfw3qFC6A1G12zcI58UGzLFVh7LbbfeMxNJ94pH/PxxAO1JucoEEdPQCmWACwNFN2r/yE5C64DD7uJ644Q49rPUyIDqHGomn8sbQzcCTQ==; 20:qJG0U6VYbZh61IHqEXImiBE670f13xXXeAHgLSIq8Yl4QEd9w15pXFDS/y8xAqOz5IL4nQDF8JifqYGz2RRdRroo/gU83u341F5HBTpL3a79lXjigEBvP0fgxGSOfTIJ7u0TdDE1ByFRIfxcvUNGJcrJUjuVvg6AYxNjQu8XjFk= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2017 09:35:12.4785 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM5PR0801MB1988 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.2.122 Subject: [Qemu-devel] [PATCH v1 06/13] qcow2: truncate preallocated space 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, "Denis V. Lunev" , Anton Nefedov , den@virtuozzo.com, 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 From: "Denis V. Lunev" This could be done after calculation of the end of data and metadata in the qcow2 image. Signed-off-by: Denis V. Lunev Signed-off-by: Anton Nefedov --- block/qcow2-cluster.c | 9 +++++++++ block/qcow2-refcount.c | 7 +++++++ block/qcow2.c | 8 ++++++++ block/qcow2.h | 3 +++ 4 files changed, 27 insertions(+) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index a4b6d40..b2879b9 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1957,3 +1957,12 @@ fail: g_free(l1_table); return ret; } + +void qcow2_update_data_end(BlockDriverState *bs, uint64_t off) +{ + BDRVQcow2State *s = bs->opaque; + + if (s->data_end < off) { + s->data_end = off; + } +} diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 873a1d2..8156466 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -744,6 +744,9 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, ret = alloc_refcount_block(bs, cluster_index, &refcount_block); if (ret < 0) { goto fail; + } else { + qcow2_update_data_end(bs, s->refcount_table_offset + + s->refcount_table_size * sizeof(uint64_t)); } } old_table_index = table_index; @@ -865,6 +868,8 @@ retry: s->free_cluster_index - 1 > (INT64_MAX >> s->cluster_bits)) { return -EFBIG; + } else { + qcow2_update_data_end(bs, s->free_cluster_index << s->cluster_bits); } #ifdef DEBUG_ALLOC2 @@ -929,6 +934,8 @@ int64_t qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset, if (ret < 0) { return ret; + } else { + qcow2_update_data_end(bs, offset + (nb_clusters << s->cluster_bits)); } return i; diff --git a/block/qcow2.c b/block/qcow2.c index 07c1706..7b4359b 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1192,6 +1192,8 @@ static int qcow2_do_open(BlockDriverState *bs, QDict *options, int flags, } } + s->data_end = bdrv_getlength(bs->file->bs); + #ifdef DEBUG_ALLOC { BdrvCheckResult result = {0}; @@ -1948,12 +1950,18 @@ static int qcow2_inactivate(BlockDriverState *bs) static void qcow2_close(BlockDriverState *bs) { BDRVQcow2State *s = bs->opaque; + qemu_vfree(s->l1_table); /* else pre-write overlap checks in cache_destroy may crash */ s->l1_table = NULL; if (!(s->flags & BDRV_O_INACTIVE)) { qcow2_inactivate(bs); + + /* truncate preallocated space */ + if (!bs->read_only && s->data_end < bdrv_getlength(bs->file->bs)) { + bdrv_truncate(bs->file, s->data_end, NULL); + } } cache_clean_timer_del(bs); diff --git a/block/qcow2.h b/block/qcow2.h index a0d222d..e28c54a 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -297,6 +297,7 @@ typedef struct BDRVQcow2State { char *image_backing_format; uint64_t prealloc_size; + uint64_t data_end; } BDRVQcow2State; typedef struct Qcow2COWRegion { @@ -607,4 +608,6 @@ int qcow2_cache_get_empty(BlockDriverState *bs, Qcow2Cache *c, uint64_t offset, void **table); void qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table); +void qcow2_update_data_end(BlockDriverState *bs, uint64_t off); + #endif