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: 10807845 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 70777746 for ; Tue, 12 Feb 2019 12:44:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60B132975D for ; Tue, 12 Feb 2019 12:44:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 54C382A6E0; Tue, 12 Feb 2019 12:44:17 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A7ECA2975D for ; Tue, 12 Feb 2019 12:44:11 +0000 (UTC) Received: from localhost ([127.0.0.1]:38581 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gtXQ2-0003B2-Hh for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Feb 2019 07:44:10 -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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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);