From patchwork Wed Nov 1 15:44:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 10036675 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 A074D602B5 for ; Wed, 1 Nov 2017 15:52:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A087E28C77 for ; Wed, 1 Nov 2017 15:52:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9452928CA0; Wed, 1 Nov 2017 15:52:07 +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 1842A28C77 for ; Wed, 1 Nov 2017 15:52:07 +0000 (UTC) Received: from localhost ([::1]:56403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9vJG-0004sQ-5u for patchwork-qemu-devel@patchwork.kernel.org; Wed, 01 Nov 2017 11:52:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60761) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e9vCK-0008Gs-5Q for qemu-devel@nongnu.org; Wed, 01 Nov 2017 11:44:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e9vCE-0006ka-78 for qemu-devel@nongnu.org; Wed, 01 Nov 2017 11:44:56 -0400 Received: from mail-eopbgr40130.outbound.protection.outlook.com ([40.107.4.130]:62701 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 1e9vCD-0006iU-T1; Wed, 01 Nov 2017 11:44:50 -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=3HKwSreg02OWAswte85yQNL+d8jUeGjkv/3MNwOzP1Q=; b=eaJEBP6vx4JUd2dYBcGCo+eX0G5n0QtARg9Mkl39srwSDGrlxegrV/AsaEKOkZ4FD0x965sImeO+8l+qs6zpQOskIYjgcjTSNaQ43bBNO115yunGsyAvwTlEqMowpQmsG9B4YDoUeZapBUTGC8POjVxor1Ss0cufG7KRRXFitw0= 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:47 +0000 From: Anton Nefedov To: qemu-devel@nongnu.org Date: Wed, 1 Nov 2017 18:44:04 +0300 Message-Id: <1509551048-129830-12-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: 7f25db02-22e9-4cc2-2407-08d5213f7b5d X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(4534020)(4602075)(2017052603199); SRVR:AM5PR0801MB1987; X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1987; 3:d56jQXsO4oGY1sKgxx+5axJUxCoFQHA7DKKSvONSS+8mIOrFRVB9ZFcojwfoLpV0W14pgZFOSwZnKSp7JZSEjuYZARNicv6OwIK3ApJOIYekcd3wddkMuEb0pI5YLYDQ7MR0vc/QA1x5yvyfPgEUsEePgDvCbJQz02vQfqvjyGbCIPQ6eE90UXezBhuiUAPXZRJJso4rQSS/iznfqg4wY3RO44IfP7EKU8qL+YgB2iJZXbAnB+PI9/P/VrjkSIFK; 25:VNUJnQA9ZoaWI17O959xPM7Az0nk4FgFAMOPsZ59J+PYJ3hly66dJNvMOfJNk/GKjReYzbqp8REVQaFiUMg44w2JZFiqschdUTF8OfDLdrS+VH/V1KSgX/Ga40P2/wgGGC6IvDtJPt2dl10T8dhcK83RenHhF3cjeshVMFA80CcC3xnZUkHZgiFcq1rdByzd4sLg9i5V6QUqYcIBKvk3fuAj3FBbIjLmscHofIrCj7pI6Rvdlx4Y6RuGVokXubMhsr4Fx1SIM0dzFu4/C5ZXy9UkJIoOkEM4ZyaAbeyciKzUXLmi8/fvnyPY54RHj7EugIhhbgO62mDhdQio6dqocg==; 31:MZG0m5NWI06A9bYZEqVX2+H36vEpH7yg0tg0qg56AYxygZEG1W6uHPj3oKCWsfaEuO0X4hr4YVPBN216xQbJwv4UrxuhvHIY+lGrZUBUxWd6q5duzdTN5gQaJbS5zRJymK7ZCYRbl+ObUutYlYyFF6SIe2/eE6jFHIq21GF+mVc9gZ8pa1c+clUEi/ns15obXW6S47GV7iKdG/QPsy/uhbSztxwTHs+UkGg+KTv3Dwg= X-MS-TrafficTypeDiagnostic: AM5PR0801MB1987: X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1987; 20:gJPH9waLbQrAb0QTQiXSeLvBHS1sOBsOfnpik3do8jseAvH456gjh2yrnKeCl45+g5GtuluH/L7cId1w6ACH5mj3hfowr6xxBImsAxXSQpsOFzQcwHldZehfpS76ecfTWXUepS0YPg3k6XAVRw29++oBojoR9vXHRKOJxLGL9Y8LG9NhI8NobcXBeNl6WrPYr3avfs6stRoquBmKCLrjc+SJaXeW69dTt9rJ9pP784tJmFObFTFlhEnqH6vfDAFTjurmkzcS451K5aUKKEtMiS6qa/4IgtGo116EwwB5gbJTFMRV7XumEzTaZFOfWVgNL7Y3xV67WCOj+2Z8pwS6yrnqa34sVVTCMJN32BrGMOeMjlJPwwE8Zz6JHyJURdATsQYYciGu8tvJlLdfQvMEpHjm9Y75jewimFisjljZ9eQ=; 4:Lwm4dRpYvN32bWXfGJg9I7itzE74F0xTT8eRRgHcvs+oha5m9h+eKPv9fxIOtE9ydMV4gRWfEtlf8mTyH9hgxeqD9eRPoeH716+Xsi6uZXtT4jnI5G0E1PL4LUz6DKaZjxaRHSZTwt/mT/4OIM9V7dGTRLc1wW+RHEJe1//qTrcvAQndf9cEARaHLdgBjGXudl2ar67djjDu2w6N3QdfBtGRHfw000oqnrTbz9vqoTCgvDiDZYGtTLnxEjD/1Ej2a2VufY/pCRikpvxrtjRcGA== 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)(54906003)(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:hzG5h5US55fsI4DuV2nVvMZkQq+FrWNUYxrqv2c?= =?us-ascii?Q?KnZaSZCOo4k+5Fi5u8pkbMrV4Jx0k0fCD34lJ0jjUNGovy26gnN2bS+vd/wZ?= =?us-ascii?Q?2xHwLp2pBBLUStPPrDJg3Pi6HLvOx7xxNlbsVBjtpFb0PqQlfl8a/NzKb+LZ?= =?us-ascii?Q?vuDMcdlI710W1CdtGGq80uPqZhpMODePUbTLve1umUdfd5NcIp4z5wO5WeXL?= =?us-ascii?Q?STLvcf5iyxuc0yJmeCiZwDGS9GnWR17POfGnnCukYrCJC6UdrjyoyEdSnXJ6?= =?us-ascii?Q?P9VbBG+6rNYVzIGP12SdlnBF2+HFHQJnyXB5mj3UEe3eCncX61OijpY4srcS?= =?us-ascii?Q?ZIQ4d09bKZKThn8N35E7rQulcQkEtgKOLV7xKlr3wH7/Hb+j21myOqweoNBB?= =?us-ascii?Q?g+tY3AmPTRadRVRtkqLf6SFLR61eH5GeOtt/DCBE+i5ma5hNe8zNNI70CkUO?= =?us-ascii?Q?q60gTC9oKXZTHyhS88acea4Y9fb2tY4+5DhsZ6XbAk5pYE7FVY8+91SIndxz?= =?us-ascii?Q?ksKVK5leiU56uiTYJVLAW8iSnOl/uC/D7HJlCHu2pVTCeYsEer0WTnOTRJ3d?= =?us-ascii?Q?OnavARKzV9aRbMwR/QQk+QyQCjkRepkCZACMvCSuZkpiPV/wV3zdILi04Ahs?= =?us-ascii?Q?60dgzXmvda1qUcXKC8iMUa1yb/rb2oFPBiv1OyqyEl7QenNocqaqb7dlQRW7?= =?us-ascii?Q?0ltJhUy+Z8LOWZJlot14g0MckEgFHPM1S4C/7PSH2ZdVo+06t7ZItXOZxojR?= =?us-ascii?Q?pZM494I++va7c6Ixe1ZmcBYerMKa6/YMXEmWT28jd776Ciobz+H/NUrleidz?= =?us-ascii?Q?DlajdoL3FrTME95E7U8lFD4kEgFVtFLKjG8UbsN8xHPh9BI62j0mUMwM8w3V?= =?us-ascii?Q?OzLcpwmSvJgFsjdu+XpgP7KRM1jaumYFa1BhIaPA2/0wBR+KmvGbntBMF+J9?= =?us-ascii?Q?hhS/nDN1yDUaL2UqxKmMlfPfnOMGS21x4dupnLyRYDwE4em9tAcy+/zJd2xU?= =?us-ascii?Q?VbrsR+60VWFdKgnpWZU0adx3V7mpqQTZewt/jZ4szrL6HF379jX5Qwdsc7d0?= =?us-ascii?Q?dpNLBpoKSQNye7gfU+iTk3LfHMw4zmRj1EfFROpyy1GekzbNPMxMGKox7uYV?= =?us-ascii?Q?pBGfZ+B46PGos34shr+FNMRrPqXYY9eIrCIY9FJ7DFZBqBEq4e9J8gJBcn4z?= =?us-ascii?Q?5sP2uy7lbiFKKf8E=3D?= X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1987; 6:4FKCEN88jqqg4MvPmo/WNmw+mwBuHl0UAoPx7Xcg3dPHe5AbW2+l3/UNYxOkiZHpj5JMansGJSPP6bflAA8xcZ4IRQ6PX0uBklpf9lH45K0f51nlvR+2FFahLSA95oHAbeLyHs6S3VZdfpLOp5neLRyPGlnuYrLr2xncRbTwlM/JC4k0BeNOWU13LgqHv36QqIN2UfYWvMhik9vkeS94w4rsUbpYPmyQv4amwQosoRkPq4YkuMxxobmfIudmOk45q37TgeyguWknF34st/psqRE6gEXlbCvvWgktgjuLTzvOyZmCKrZ7TW62nIdxxy6FLOD5cn13LhQIFj+Ag0wcDLJNrVJ2JmkXwjOkWHGKW6k=; 5:1TVuLvEDHjqNyEqmYe+hT/+1jEchWu4ILbgDoDblL+MzDVXsxSSFKJInfCRSOT8OMlhkR64GtpqmAFKxvjYDhpQIAJaBhQrfEcZ5JiVuUoob5/ejtTvXd58QBX/tVBf+AxepCYKwU/FJPstLpP+oCYPwVSqPAlW26MLnmEWiNz4=; 24:fsMARDX2sILQB90wtv4jteXMqFU8/s9JI1l90KU/WZ8X8AhQR9sILUmLnnJ1u4Orr4PPI+MoliihqxA9xIoPHAttweuBCH2bU/GR8cDbIlk=; 7:zUwnrwsjp3TmMVjs55Riu/ciQ/b29nim6t56YKjlFUkxV4M4D39zpP3hSjK3uAl6MclmwvfZx8Ka50BHEhmVifguu4T1l7KEug9/D00zHEPRkwOIepMSXv7dXPkXsIT7+E0BMhXuU/519FNEUhkXwY5h7htFAwC+suHEn9nOc25xMpnnCmXnuiEarJ3ZvN5MDiN1ZGQVK/I9AU6duXF8N+61IjYM+cH9CyI+K/vJLNL7dk2UMKljEFsB+Pc+vv0x SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM5PR0801MB1987; 20:cQXFRk+iwvUTMA2VMCt9nH1RQHPuwvg5sYbzMToj6xENz3+txWl66N2JD7xFSC3DEUhGVxGFW0RKRxm4jEXIOdvvtH9HELcwT9R5scH1Mbb+XmibghvPiJkMcCoaiEbMj+gewyE+cLZI2lAHIkgzGhV2jMD4LSDwvUvE5PBNqsA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2017 15:44:47.0088 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7f25db02-22e9-4cc2-2407-08d5213f7b5d 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.130 Subject: [Qemu-devel] [PATCH v5 11/15] 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, Anton Nefedov , berto@igalia.com, den@virtuozzo.com, qemu-block@nongnu.org, mreitz@redhat.com, "Denis V. Lunev" 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.h | 3 +++ block/qcow2-cluster.c | 9 +++++++++ block/qcow2-refcount.c | 7 +++++++ block/qcow2.c | 7 +++++++ 4 files changed, 26 insertions(+) diff --git a/block/qcow2.h b/block/qcow2.h index 9a2711e..579838d 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -330,6 +330,7 @@ typedef struct BDRVQcow2State { char *image_backing_format; uint64_t prealloc_size; + uint64_t data_end; } BDRVQcow2State; typedef struct Qcow2COWRegion { @@ -693,4 +694,6 @@ void qcow2_remove_persistent_dirty_bitmap(BlockDriverState *bs, const char *name, Error **errp); +void qcow2_update_data_end(BlockDriverState *bs, uint64_t off); + #endif diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index e364116..9b24cab 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -2080,3 +2080,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 aa3fd6c..5797666 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -834,6 +834,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; @@ -971,6 +974,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 @@ -1035,6 +1040,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 f41aaac..5e2b543 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1488,6 +1488,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}; @@ -2184,6 +2186,11 @@ static int qcow2_inactivate(BlockDriverState *bs) if (result == 0) { qcow2_mark_clean(bs); + + /* truncate preallocated space */ + if (!bs->read_only && s->data_end < bdrv_getlength(bs->file->bs)) { + bdrv_truncate(bs->file, s->data_end, PREALLOC_MODE_OFF, NULL); + } s->flags |= BDRV_O_INACTIVE; }