From patchwork Mon Aug 8 15:05:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 9268615 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 C0C5760871 for ; Mon, 8 Aug 2016 15:50:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B284E283F6 for ; Mon, 8 Aug 2016 15:50:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A6D50283FE; Mon, 8 Aug 2016 15:50:16 +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.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 EECB7283F6 for ; Mon, 8 Aug 2016 15:50:15 +0000 (UTC) Received: from localhost ([::1]:58238 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWmog-0001dv-DU for patchwork-qemu-devel@patchwork.kernel.org; Mon, 08 Aug 2016 11:50:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42737) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWm7d-00075g-DB for qemu-devel@nongnu.org; Mon, 08 Aug 2016 11:05:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bWm7X-0004Zx-1d for qemu-devel@nongnu.org; Mon, 08 Aug 2016 11:05:44 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:43709 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bWm7W-0004Yx-7v for qemu-devel@nongnu.org; Mon, 08 Aug 2016 11:05:38 -0400 Received: from kvm.qa.sw.ru. ([10.28.8.145]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id u77NfZcf001857; Mon, 8 Aug 2016 02:41:39 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Mon, 8 Aug 2016 18:05:20 +0300 Message-Id: <1470668720-211300-30-git-send-email-vsementsov@virtuozzo.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1470668720-211300-1-git-send-email-vsementsov@virtuozzo.com> References: <1470668720-211300-1-git-send-email-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH 29/29] qcow2-dirty-bitmap: refcounts 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, vsementsov@virtuozzo.com, famz@redhat.com, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Calculate refcounts for dirty bitmaps. Signed-off-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Denis V. Lunev --- block/qcow2-bitmap.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++-- block/qcow2-refcount.c | 14 +++++++----- block/qcow2.h | 5 +++++ 3 files changed, 70 insertions(+), 7 deletions(-) diff --git a/block/qcow2-bitmap.c b/block/qcow2-bitmap.c index def2005..b24fa27 100644 --- a/block/qcow2-bitmap.c +++ b/block/qcow2-bitmap.c @@ -253,6 +253,62 @@ static int load_autoload_bitmaps(BlockDriverState *bs, Error **errp) return 0; } +static int bitmap_table_load(BlockDriverState *bs, QCow2BitmapHeader *bmh, + uint64_t **table); +int qcow2_dirty_bitmaps_refcounts(BlockDriverState *bs, + BdrvCheckResult *res, + void **refcount_table, + int64_t *refcount_table_size) +{ + BDRVQcow2State *s = bs->opaque; + QCow2BitmapHeader *h, + *begin = (QCow2BitmapHeader *)s->bitmap_directory, + *end = (QCow2BitmapHeader *) + (s->bitmap_directory + s->bitmap_directory_size); + + int i; + int ret = inc_refcounts(bs, res, refcount_table, refcount_table_size, + s->bitmap_directory_offset, + s->bitmap_directory_size); + if (ret < 0) { + return ret; + } + + for (h = begin; h < end; h = next_dir_entry(h)) { + uint64_t *bitmap_table = NULL; + + ret = inc_refcounts(bs, res, refcount_table, refcount_table_size, + h->bitmap_table_offset, + h->bitmap_table_size); + if (ret < 0) { + return ret; + } + + ret = bitmap_table_load(bs, h, &bitmap_table); + if (ret < 0) { + return ret; + } + + for (i = 0; i < h->bitmap_table_size; ++i) { + uint64_t off = be64_to_cpu(bitmap_table[i]); + if (off <= 1) { + continue; + } + + ret = inc_refcounts(bs, res, refcount_table, refcount_table_size, + off, s->cluster_size); + if (ret < 0) { + g_free(bitmap_table); + return ret; + } + } + + g_free(bitmap_table); + } + + return 0; +} + static int handle_in_use_bitmaps(BlockDriverState *bs); int qcow2_read_bitmaps(BlockDriverState *bs, Error **errp) { @@ -351,8 +407,6 @@ static void do_free_bitmap_clusters(BlockDriverState *bs, QCOW2_DISCARD_ALWAYS); } -static int bitmap_table_load(BlockDriverState *bs, QCow2BitmapHeader *bmh, - uint64_t **table); static int free_bitmap_clusters(BlockDriverState *bs, QCow2BitmapHeader *bmh) { int ret; diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index cbfb3fe..05bcc57 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -1309,11 +1309,9 @@ static int realloc_refcount_array(BDRVQcow2State *s, void **array, * * Modifies the number of errors in res. */ -static int inc_refcounts(BlockDriverState *bs, - BdrvCheckResult *res, - void **refcount_table, - int64_t *refcount_table_size, - int64_t offset, int64_t size) +int inc_refcounts(BlockDriverState *bs, BdrvCheckResult *res, + void **refcount_table, int64_t *refcount_table_size, + int64_t offset, int64_t size) { BDRVQcow2State *s = bs->opaque; uint64_t start, last, cluster_offset, k, refcount; @@ -1843,6 +1841,12 @@ static int calculate_refcounts(BlockDriverState *bs, BdrvCheckResult *res, return ret; } + /* dirty bitmaps */ + ret = qcow2_dirty_bitmaps_refcounts(bs, res, refcount_table, nb_clusters); + if (ret < 0) { + return ret; + } + return check_refblocks(bs, res, fix, rebuild, refcount_table, nb_clusters); } diff --git a/block/qcow2.h b/block/qcow2.h index 74d395b..3359c14 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -564,6 +564,9 @@ int qcow2_check_metadata_overlap(BlockDriverState *bs, int ign, int64_t offset, int64_t size); int qcow2_pre_write_overlap_check(BlockDriverState *bs, int ign, int64_t offset, int64_t size); +int inc_refcounts(BlockDriverState *bs, BdrvCheckResult *res, + void **refcount_table, int64_t *refcount_table_size, + int64_t offset, int64_t size); int qcow2_change_refcount_order(BlockDriverState *bs, int refcount_order, BlockDriverAmendStatusCB *status_cb, @@ -623,6 +626,8 @@ BdrvDirtyBitmap *qcow2_bitmap_load(BlockDriverState *bs, const char *name, void qcow2_bitmap_store(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, Error **errp); int qcow2_delete_bitmaps(BlockDriverState *bs); +int qcow2_dirty_bitmaps_refcounts(BlockDriverState *bs, BdrvCheckResult *res, + void **refcount_table, int64_t *refcount_table_size); /* qcow2-cache.c functions */ Qcow2Cache *qcow2_cache_create(BlockDriverState *bs, int num_tables);