From patchwork Thu Feb 28 09:26:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Shinkevich X-Patchwork-Id: 1049347 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4496f51L1gz9s4Z for ; Thu, 28 Feb 2019 20:27:37 +1100 (AEDT) Received: from localhost ([127.0.0.1]:34980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzHyY-0001NP-Cs for incoming@patchwork.ozlabs.org; Thu, 28 Feb 2019 04:27:34 -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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, uint64_t *bitmap_table, continue; } - qcow2_free_clusters(bs, addr, s->cluster_size, QCOW2_DISCARD_OTHER); + qcow2_free_clusters(bs, addr, s->cluster_size, QCOW2_DISCARD_ALWAYS); bitmap_table[i] = 0; } }