From patchwork Thu Jun 1 15:14:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Nefedov X-Patchwork-Id: 9759871 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 2111D60375 for ; Thu, 1 Jun 2017 15:24:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FA6F284F1 for ; Thu, 1 Jun 2017 15:24:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 02638284FF; Thu, 1 Jun 2017 15:24:44 +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 6703C284F1 for ; Thu, 1 Jun 2017 15:24:44 +0000 (UTC) Received: from localhost ([::1]:45217 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRxr-0007Vy-Eq for patchwork-qemu-devel@patchwork.kernel.org; Thu, 01 Jun 2017 11:24:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51609) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRod-0000Gj-5N for qemu-devel@nongnu.org; Thu, 01 Jun 2017 11:15:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGRoa-0004ht-HW for qemu-devel@nongnu.org; Thu, 01 Jun 2017 11:15:11 -0400 Received: from mail-eopbgr40094.outbound.protection.outlook.com ([40.107.4.94]:49888 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 1dGRoa-0004fj-9z for qemu-devel@nongnu.org; Thu, 01 Jun 2017 11:15:08 -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=BA2XgkapURGBsoGBENcXnDa/0F1LhYFKh3F/WYHE9uc=; b=HcOTycO7OAMp3DqSJdBe6q1PsxHUT+5UWbKEGvPCRGjvzkSwj/berZZahuKfdaFyFakmWV/qeflj+0flOqVczkLKpNeZVwMwF8lKjx//bMy8UrtSCcxheHM/OCkQzCxhkh+wuBp/N0sxYwdWxP4XnrshHNVuGkV2OPs5SjAqyGM= 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 VI1PR0801MB1999.eurprd08.prod.outlook.com (2603:10a6:800:8a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1124.9; Thu, 1 Jun 2017 15:15:06 +0000 From: Anton Nefedov To: Date: Thu, 1 Jun 2017 18:14:26 +0300 Message-ID: <1496330073-51338-9-git-send-email-anton.nefedov@virtuozzo.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1496330073-51338-1-git-send-email-anton.nefedov@virtuozzo.com> References: <1496330073-51338-1-git-send-email-anton.nefedov@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: DB6PR1001CA0005.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:4:b7::15) To VI1PR0801MB1999.eurprd08.prod.outlook.com (2603:10a6:800:8a::20) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0801MB1999: X-MS-Office365-Filtering-Correlation-Id: 577d35c8-7cc2-426e-68e7-08d4a900fcaf X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:VI1PR0801MB1999; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1999; 3:g69exEB5p1oZrqDoPBKdg3HP13kgLIq+s4IKTeLh9OGFL28agCM+BrVE7t3B3mjWwOki3AFQTq0fbP1UshLD5LrS/iG+rzq+EAhZA8wU2xwINJ2qCMqe5vTotJ4n+sqbOWBnjWi/g61cwMGUJNSVG23Rbw9sdp4bBrEDyiJgj5/2fYa79pzLmc4z0Fxp9lIr+BVjopos1EFUPVtcmA1oMaIbXomRjpGII9ugeBn8sljNW0wgxKKnC2GGAld8R6PxcACJ0+ThUG0mmDqfjo3YbRTCkzGGZY60sh05EoLEU3ccB791Bm7E0w0If5hzld6RP0BS0zFnLLcuyKRrjeM9Zg==; 25:QsNstodDzan/UijNbbIKRYR8wVITTyDO2xADAW0UhLZB2TfohuMcks4t65nkJHj64jf+nrnXTNtmSZVO1Za1WBNSf4Avtop/3qA+mjb5i3bYnVX7klftXUuvPcb0Apzy0EIDanT6QwMUpSys4WnbupJCl2FHh+va8rqVnwgyInCiun3WfZLjtOXj/4md46+BXxHsMPkZ1bYPt9JemTT0gp0/3nclRl3FhsOobUW4CQYKpmb+hAHglOJGry+PNFnv6sZqfzTui1MKzYKdShB6/QifVS6NMGjatdHgaUdcCDMKYIieOQ/rPS1pFXzrzZhXejTyyjj6WUh5Nb58XYj2sTEs5DWYdJxeuMI9vg71KeNlzScxIzigMNPTS6HpjUngIU9VSvvSmgcE/Eg5TMRkFfAZWRoqyBcMpatb2ZARwXIjsTF8DSwfB6VBozq++qOSfEUE+Rf9vL2B+UNkf8z/pQ2Uy/6UmU2fbeMvLhC3bZI= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1999; 31:lSRNk7/C3LrA5PcawqaOSA5YPFYX2hWVnZN6UYfF6xORJ0I584MZhzchZut/TkddmhzUU+D4Bqh3VX74UAaSyNjZzc0+3ERBxvCVuoqPvDIKS1RrUtnlq99edywlLosG5Lce01PSXyKyOuUzpkbzdre/qnSQmgCAuiumx2j18WuDng2NaM7fwlHgCDatsY/D2WzyrRFUBI5n80Izp9mjIHDgVa83GmK5sNi+5jUssrw=; 20:WZhTQHNjhuAL67fKMgoPowUhFwmlhh9DsZZAUcgFRIYPw0iM9YiRZrdOmUEpqlALkkvHgiuwVNvwBPYKjj8T8wWcK1Zi/A3coZvKIJcQBjPQ4t9e/lsL30kXT+FiBVxNjo8eoF42N0p6QWx+E+2Tlk6t6XsI52PgzUW7ZmLjYUHvmXHQ8k99A5VjHTXGI/SX1a7WQNRqONqMZqXmB4Pm9F6WMHewwJCStBiJTlvtsOoQVcNM7iPZmfeTpjcpWWc1dnR818XoVt+Lx/ePgKk/cuCNJh7X+zIxwsJrJhmdr31CapnrYcObsWIIteS2SRMRbQDQ01aQe+47sURj5Z3N+p6LfovAaGiwauybZs5Ev95Q6pt89JRNvnTn9QZF3qqArzi0rl16tM/T6TWSoUYZXhgpu2aJdD5Cq94+bKz3iG4= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(10201501046)(100000703101)(100105400095)(3002001)(6041248)(20161123560025)(20161123558100)(20161123555025)(20161123562025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123564025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:VI1PR0801MB1999; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VI1PR0801MB1999; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0801MB1999; 4:naJxMw7KiJ3ub+JtxGSOfFcqJ8YRjyNb5sqPbezf?= =?us-ascii?Q?mUXJqnerTmjf26RiQ8Vw1BsVmdCry7XxDCPVCiT1dsYVnEjNylOyeQ/L5zGB?= =?us-ascii?Q?rpbHmxPgEp3WaEFshoj/Ud1E+ARV5LflN5YtM7J3VE72NkkFBPMMATzoW2Vb?= =?us-ascii?Q?minWmPMsd1NYXgJ8MtTv2ZrXEjgsslflYptyb9tGLqBG+jGnRYWorm7ZK4yj?= =?us-ascii?Q?TDrZnZLaQ+BVfMrDmSMFv766PzqcbskDONJJoKNH9o0Amta8xDe+UwO9eBan?= =?us-ascii?Q?d+WGfvucvoJHIhZ4A7ILXsa6QPDCoxcqPfcPl7XkbbDENTj9G91l6dTqb9sF?= =?us-ascii?Q?6pbXnWUy9BsGcfNqnuiB+RSCyQsKQd6BUMujK4bUNLDbZxt5p+XwDDMI46qU?= =?us-ascii?Q?gIGtOioFuFRbcN7auE4o268b4VerSLCum+O1WQcTNi6B4CjTRotsRz5IYr3+?= =?us-ascii?Q?y11pwlynq1vw9uvlAdEp8SqYhX+cD45rNcy26lDTbhujsfp4GIwUvMpmK42o?= =?us-ascii?Q?hJLWOwHm3nvn8bNGF1xNkBz81+guxmpOeD+3Bh6H7U3PiRMYEqJdxvYnyE3i?= =?us-ascii?Q?8wbXT6oQgQDkW2ZWjg79LM0RY1J6RCIF2Q3vDb0kWLwQ6OlraOZ51Vn+4lt3?= =?us-ascii?Q?U/loD48pMAGaFGTpDxk3WgiQMlP8/zsK5kBJY/VcvRtq6E+r2wIiKHY1x7ZB?= =?us-ascii?Q?urtZFmiDYUNx6NcJ60wYcg55EAAhcdu/mu6XnVMeWm/KanzHZlXOy1A+OTew?= =?us-ascii?Q?lRH8Wgns853Wi7PiqRbigVLBu1XyMedE2sCCJz8WXIEgTRAw01CeIFKZTLXR?= =?us-ascii?Q?9HZCh7A9uKvGKkMtB7B0tSURTul1HyYLy23VR+c0wNQWZUv+I2rfg1bjwC1I?= =?us-ascii?Q?1jlfNf9tOPlFaoxihxraLDQU0U85EPa64NOgT7KgXJ5ypsm6rDEGXfqMcMtE?= =?us-ascii?Q?Q4XdQI02STqrIBRgzJoBoJj+ozoHz7VpbyY2fc33zy4liwx2+Kkc4pEMlaE2?= =?us-ascii?Q?fpmi6V2BJA2HBF74e3dJRGTXqaWZAlCzEnvrRKSihp3iY6STI5t8kaMDRNqU?= =?us-ascii?Q?a0pX8+gvXtA1r79RqvPQ9NEGgL2z9Ddr3I25RKF6BSP5vvYT/hPrscE9GnKN?= =?us-ascii?Q?3wYfSmkGv8Asa4ywcQHOWngIYXQ0rvxP?= X-Forefront-PRVS: 0325F6C77B X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39830400002)(39450400003)(39400400002)(6916009)(6666003)(6486002)(7736002)(478600001)(5660300001)(305945005)(54906002)(53936002)(4326008)(6512007)(6506006)(2950100002)(110136004)(107886003)(3846002)(50226002)(8676002)(66066001)(42186005)(81166006)(38730400002)(25786009)(6116002)(76176999)(50986999)(47776003)(86362001)(5003940100001)(2906002)(2351001)(36756003)(48376002)(50466002)(33646002)(575784001)(53416004)(189998001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0801MB1999; H:xantnef-ws.sw.ru; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0801MB1999; 23:zVpslw1xRQveRoURl1GnN7SnEeF1izK2iW4Bpz0?= =?us-ascii?Q?smG492GSsaeWjHAZ+f+9Wb/G2Sf2gZD0K45+9zwJJbQGzzj/eMcKaCI/4bPp?= =?us-ascii?Q?XFvtPNOMf029ZlCZ2U8d3+Su8kOhFTYfw6dW1fls0zzFAc+57cFRLMyyOhxN?= =?us-ascii?Q?vIVeT5BhgZUte+JZhzJMG4A5WGTQ5l4FO/JpGbC29nHFJ/coeZ6VZD8sfj6R?= =?us-ascii?Q?dUzjoRo2S6anhHKN55QATRA8swWoSHG1nIKfx8iCohK+WFpULCbXGUiUk4Kh?= =?us-ascii?Q?iFyY7B1cFmACjP56iI22RPQSOLn/pKKRsWfBcbQAklxdcZ4QjyT8tsYnVtFw?= =?us-ascii?Q?UvY0ZCfycbAn+dP8xbqWsCEdlM3lgby+k+ODj6dJCb8UAILdF0nA04E7oXik?= =?us-ascii?Q?E+Ck0UAUvcRhUMEndOr7d305s1karTmvZqQek58sVKQbMsz/Idn2uK8PDXyl?= =?us-ascii?Q?6wOIrXL/WMRBapC/0t+4KX/9iciUgJTnHpqVpKe/5sNn09xdMep28VT4gqIf?= =?us-ascii?Q?PhcDR2XCJS7IUh5DsCXXWITh6W+dmqJLGw0Rii2wlSaUhWsnB4MM5I1ImT8s?= =?us-ascii?Q?a/Xy3I7g9eGlEpbz5v3o16Td6AHTmSgMF0wJc7zyk57a/VjbwddtY8BZfm7y?= =?us-ascii?Q?lXipeWAuSH6Pi1ppxvPqyAJTARZeQDRPGWWxcCQPmqK7ieHJyx/daBFpLZIA?= =?us-ascii?Q?tvHqhJNddOBUiG8HDgbuHR1OZBlkU54BZXLDZ50azIygOCVJ0CqFfoW1vBcK?= =?us-ascii?Q?tITy703wfeODD8XWh2QiKMJ7blHgDT1QIWVTM23Nvs5unDNO/7gQeEj32l/V?= =?us-ascii?Q?lurUDzirY9yyb9RUIZL2rtQ9AiWBDMXqU3kY7RbeG0is3wKUezJw/nNSKyEw?= =?us-ascii?Q?wrv7aScrOEleiaBHM/onlDT0FIOGKup++w7a03ha0nPDuA7AvcEdfChWiS8F?= =?us-ascii?Q?gTBmmbETG/9mg6ZFRaEzn8Zj4YdK9oZVgPwWRPE3maMVUg5T+9xOLqLHUO7v?= =?us-ascii?Q?jjNcOe0TuYZ7pT9/mljvNCc7nbCV1PQF20bwBU1a4qbaZmmknmnHNGqPHStl?= =?us-ascii?Q?CNKFyMLVmtF88renXA7QC1psflinq?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1999; 6:asamXk+ptof1S3Z7gmACoOB5XRQWvLmO1Zc0D4SDoeSs1VMtXqCEm9hLeyxEHwtTeMSF8tPnu0MjUAG3dCEE1Au5kxb4fWOPBlX+X1j/o/n+YenCqSZfUV82bWUc94gJ8bUiB6PJvuDe7oDwBFJXSO4F0avcubaalsjA6KJ8kbt3i8fMEf1xgd9OYI5bUFuil0pyZoPCX6fpgbAofEz4iysiVkhKBmE8gw8IMjreupJfeRnxj7/SfmFXjHJvmh+AB6rXm5LjcKaiGorQHjRsMlbe3AcydLnI569GWqeAzFi5UGWXneJe9O+z5BTIWqd44cw9HVcGxAQrGSoT4Ec+SAnh68EJ+poR1XjuO1xgPz237MmM42YVsdw7iLvFOTsxYKVQXTZwtGYOiOYDeowu54InFRURBddN8SQERKJtA72xZnB3eHl1RAjnGWDQtBBhk9NC0SPuuCXPTPk1BFoiPpd+R1SbPxscwkU/VuuczUiLLrjB8snATLJAcVpwbK4N/WUYVNM05apAxYzcJOqV4g== X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1999; 5:9lXGl1+URP8709WaH4XdGnDOpE2COc/2Fh5CXUYGtLt9FdP0roOiyKs5bhv6ex+9wjfhhd5FmMOSqwNC1aeUFZwiEM2GWOtpKHl9oRepaRJqWrN994zwbs/b79bVV/SLoNLgGZDtcrak5/6SBoG0UiXK8tKhjN0XknCqRD2X4WTX+mVAF8DhbFbNhyVvCEl6vY3ExbjA5mN1TzzJMB0dStKzhy9U80dmGR9u9CiH/0HN29ipbdC9R9ckZA1ChmxezpMxR3nRl5+aYiOaHH7bnNmaJMUp9rBedd9K0IbeMUu3XrieEQwpM70oRBT7jJa5oZid6Aj/9Psgql1zvhrLUGez7vySWAU2B63pEYx313LwvcF08pm9lSv9jpdGOnujd4TQXeV4meXBwyu+Cun4gQFqcuMBT4YpRTQXWUyDUiJ95U71YTBv8llIrTVqsWC0EnCyzwJFM6+bcEWfPwhKnxpZ97ThCi88LpikvxwsS/dgG35/ooXM/i8b3ZL2mhtL; 24:iMlbFEEdaMjM0Nq3Q+Hoea2u7EcmCA5uvtYNyBZBDy/7h++mvP2skB/k0MFSe6pGl1s9TuzK3/ihyFqTudXyA3zil3v0rikgLYWJgBKPSLU= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1999; 7:ipckjSx2uQUyiG0D+RRvR/dQwAbcvSWc4zAHYSiRsrp7Vd2zvk1MsCkgjHYN/v00499DYQ8X8n30ll3uQ3q0ZlJNg38ruF/jgZOyxoidaBoAAfuhHPJaQFzNpjLv5EtsJ5l8nLKYNSlgnWmqOtCm3HKeFdWv+bZ5nWnlDm49CDmEdexeWVWzc7a6tkwdi23QStYSQvCGS9oNyDiwPxo0CAq1NFFF61b4IGz8GX0M0rLTlU6Ki1jIzdU+7XyKI6sCNmfr5c2RTe/DGzDoZMjnWW4Odcq9d+HTnVpcy4SBcqV5T/wgvQVJ11hlhPOP2waUQor7REJ4Ll74O3HizdJS9g==; 20:dyElEVi/UOE3T33j5CoweVBybGEtGGiMp9oSAZIMGkfVXhwJtVk79ICK3nIT04zNAERp6zRMsPHno3Px4ucO1PuKYhqm0zy2gXaFW6DNzJ/UQxMJ5T2C3ICXxcF+ykYe3Ck/8+xN7y1v3O3kzOmH7+/tq7OMEYljCWH6T4DJUDQ= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Jun 2017 15:15:06.1780 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1999 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.4.94 Subject: [Qemu-devel] [PATCH v2 08/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 , den@virtuozzo.com, 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-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 88dd555..c39e825 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1958,3 +1958,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 b090833..33e5455 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1194,6 +1194,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}; @@ -1941,12 +1943,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