From nobody Sun Nov 9 14:48:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551346093715692.1611754965536; Thu, 28 Feb 2019 01:28:13 -0800 (PST) Received: from localhost ([127.0.0.1]:34984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzHz5-0001jA-KG for importer@patchew.org; Thu, 28 Feb 2019 04:28:07 -0500 Received: from eggs.gnu.org ([209.51.188.92]:44376) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzHy5-0001ND-S0 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 04:27:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzHy4-00022s-TB for qemu-devel@nongnu.org; Thu, 28 Feb 2019 04:27:05 -0500 Received: from relay.sw.ru ([185.231.240.75]:48128) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gzHy4-00021J-GN; Thu, 28 Feb 2019 04:27:04 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gzHxz-0001z7-NU; Thu, 28 Feb 2019 12:26:59 +0300 From: Andrey Shinkevich To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Thu, 28 Feb 2019 12:26:59 +0300 Message-Id: <1551346019-293202-1-git-send-email-andrey.shinkevich@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH v2] qcow2: discard bitmap when removed 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, den@openvz.org, vsementsov@virtuozzo.com, andrey.shinkevich@virtuozzo.com, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" When a bitmap is removed, we can clean some space on the disk. The size of a cluster may be larger, so is the size of the bitmap that includes many clusters. Some bitmaps can be as large as tens of megabytes. The flag QCOW2_DISCARD_ALWAYS allows a call to the raw_co_pdiscard() that does the actual cleaning of the image on disk, while with the flag QCOW2_DISCARD_OTHER, a reference count of the cluster is updated only. Signed-off-by: Andrey Shinkevich Reviewed-by: Vladimir Sementsov-Ogievskiy --- v1: Discard old bitmap directories in QCOW2 image In the first version of the patch, any call to qcow2_free_clusters() in block/qcow2-bitmap.c was with the flag QCOW2_DISCARD_ALWAYS, even in the cases when the cleaned space is insignificant, particularly, in case of bitmap directories. Discussed in the email thread with the message ID <1549974951-731285-1-git-send-email-andrey.shinkevich@virtuozzo.com> block/qcow2-bitmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index 3ee524d..162744e 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -202,7 +202,7 @@ static void clear_bitmap_table(BlockDriverState *bs, ui= nt64_t *bitmap_table, continue; } =20 - qcow2_free_clusters(bs, addr, s->cluster_size, QCOW2_DISCARD_OTHER= ); + qcow2_free_clusters(bs, addr, s->cluster_size, QCOW2_DISCARD_ALWAY= S); bitmap_table[i] =3D 0; } } --=20 1.8.3.1