From patchwork Tue Feb 12 12:35:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Shinkevich X-Patchwork-Id: 1040549 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 43zMly6VCzz9sMx for ; Tue, 12 Feb 2019 23:43:58 +1100 (AEDT) Received: from localhost ([127.0.0.1]:38579 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtXPo-0002qL-Qb for incoming@patchwork.ozlabs.org; Tue, 12 Feb 2019 07:43:56 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43781) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtXIE-00065d-Sz for qemu-devel@nongnu.org; Tue, 12 Feb 2019 07:36:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gtXIB-0002IF-Ue for qemu-devel@nongnu.org; Tue, 12 Feb 2019 07:36:06 -0500 Received: from relay.sw.ru ([185.231.240.75]:51018) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gtXIA-00029N-Uq; Tue, 12 Feb 2019 07:36:03 -0500 Received: from [172.16.25.136] (helo=localhost.sw.ru) by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1gtXHz-0000H2-VB; Tue, 12 Feb 2019 15:35:52 +0300 From: Andrey Shinkevich To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Tue, 12 Feb 2019 15:35:51 +0300 Message-Id: <1549974951-731285-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] Discard old bitmap directories in QCOW2 image 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" Clean QCOW2 image from bitmap obsolete directory when a new one is allocated and stored. It slows down the image growth a little bit. The flag QCOW2_DISCARD_ALWAYS allows a call to raw_co_pdiscard() that does the actual cleaning of the image on disk. 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 --- block/qcow2-bitmap.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index b946301..682cb09 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; } } @@ -257,7 +257,7 @@ static int free_bitmap_clusters(BlockDriverState *bs, Qcow2BitmapTable *tb) clear_bitmap_table(bs, bitmap_table, tb->size); qcow2_free_clusters(bs, tb->offset, tb->size * sizeof(uint64_t), - QCOW2_DISCARD_OTHER); + QCOW2_DISCARD_ALWAYS); g_free(bitmap_table); tb->offset = 0; @@ -801,7 +801,7 @@ fail: g_free(dir); if (!in_place && dir_offset > 0) { - qcow2_free_clusters(bs, dir_offset, dir_size, QCOW2_DISCARD_OTHER); + qcow2_free_clusters(bs, dir_offset, dir_size, QCOW2_DISCARD_ALWAYS); } return ret; @@ -904,14 +904,14 @@ static int update_ext_header_and_dir(BlockDriverState *bs, } if (old_size > 0) { - qcow2_free_clusters(bs, old_offset, old_size, QCOW2_DISCARD_OTHER); + qcow2_free_clusters(bs, old_offset, old_size, QCOW2_DISCARD_ALWAYS); } return 0; fail: if (new_offset > 0) { - qcow2_free_clusters(bs, new_offset, new_size, QCOW2_DISCARD_OTHER); + qcow2_free_clusters(bs, new_offset, new_size, QCOW2_DISCARD_ALWAYS); } s->bitmap_directory_offset = old_offset; @@ -1242,7 +1242,7 @@ fail: if (tb_offset > 0) { qcow2_free_clusters(bs, tb_offset, tb_size * sizeof(tb[0]), - QCOW2_DISCARD_OTHER); + QCOW2_DISCARD_ALWAYS); } g_free(tb);