From patchwork Wed Jan 16 16:24:40 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Beno=C3=AEt_Canet?= X-Patchwork-Id: 213001 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1AE232C0084 for ; Thu, 17 Jan 2013 06:15:55 +1100 (EST) Received: from localhost ([::1]:35221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvVpP-0002yb-3r for incoming@patchwork.ozlabs.org; Wed, 16 Jan 2013 11:27:03 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41354) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvVpC-0002bu-IS for qemu-devel@nongnu.org; Wed, 16 Jan 2013 11:26:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvVp8-0007BU-Ht for qemu-devel@nongnu.org; Wed, 16 Jan 2013 11:26:50 -0500 Received: from nodalink.pck.nerim.net ([62.212.105.220]:43243 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvVp8-0007BC-5X for qemu-devel@nongnu.org; Wed, 16 Jan 2013 11:26:46 -0500 Received: by paradis.irqsave.net (Postfix, from userid 1002) id B0F33874323; Wed, 16 Jan 2013 17:58:22 +0100 (CET) Received: from localhost.localdomain (unknown [192.168.77.1]) by paradis.irqsave.net (Postfix) with ESMTP id A582287432C; Wed, 16 Jan 2013 17:56:04 +0100 (CET) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Wed, 16 Jan 2013 17:24:40 +0100 Message-Id: <1358353497-5292-20-git-send-email-benoit@irqsave.net> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1358353497-5292-1-git-send-email-benoit@irqsave.net> References: <1358353497-5292-1-git-send-email-benoit@irqsave.net> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 62.212.105.220 Cc: kwolf@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com Subject: [Qemu-devel] [RFC V5 19/36] qcow2: Add a deduplication boolean to update_refcount. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This is needed for next commit which handle the deduplication refcount overflow case. Signed-off-by: Benoit Canet --- block/qcow2-dedup.c | 2 +- block/qcow2-refcount.c | 20 +++++++++++--------- block/qcow2.h | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/block/qcow2-dedup.c b/block/qcow2-dedup.c index 7049bd8..25ecefa 100644 --- a/block/qcow2-dedup.c +++ b/block/qcow2-dedup.c @@ -386,7 +386,7 @@ static int qcow2_deduplicate_cluster(BlockDriverState *bs, return update_refcount(bs, (hash_node->physical_sect / s->cluster_sectors) << s->cluster_bits, - 1, 1); + 1, 1, true); } /* This function tries to deduplicate a given cluster. diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 75c2bde..b1ad112 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -245,7 +245,7 @@ static int alloc_refcount_block(BlockDriverState *bs, } else { /* Described somewhere else. This can recurse at most twice before we * arrive at a block that describes itself. */ - ret = update_refcount(bs, new_block, s->cluster_size, 1); + ret = update_refcount(bs, new_block, s->cluster_size, 1, false); if (ret < 0) { goto fail_block; } @@ -427,7 +427,7 @@ fail_block: /* XXX: cache several refcount block clusters ? */ int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, - int64_t offset, int64_t length, int addend) + int64_t offset, int64_t length, int addend, bool deduplication) { BDRVQcowState *s = bs->opaque; int64_t start, last, cluster_offset; @@ -513,7 +513,8 @@ fail: */ if (ret < 0) { int dummy; - dummy = update_refcount(bs, offset, cluster_offset - offset, -addend); + dummy = update_refcount(bs, offset, cluster_offset - offset, -addend, + deduplication); (void)dummy; } @@ -534,7 +535,8 @@ static int update_cluster_refcount(BlockDriverState *bs, BDRVQcowState *s = bs->opaque; int ret; - ret = update_refcount(bs, cluster_index << s->cluster_bits, 1, addend); + ret = update_refcount(bs, cluster_index << s->cluster_bits, 1, addend, + false); if (ret < 0) { return ret; } @@ -588,7 +590,7 @@ int64_t qcow2_alloc_clusters(BlockDriverState *bs, int64_t size) return offset; } - ret = update_refcount(bs, offset, size, 1); + ret = update_refcount(bs, offset, size, 1, false); if (ret < 0) { return ret; } @@ -620,7 +622,7 @@ int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset, old_free_cluster_index = s->free_cluster_index; s->free_cluster_index = cluster_index + i; - ret = update_refcount(bs, offset, i << s->cluster_bits, 1); + ret = update_refcount(bs, offset, i << s->cluster_bits, 1, false); if (ret < 0) { return ret; } @@ -686,7 +688,7 @@ void qcow2_free_clusters(BlockDriverState *bs, int ret; BLKDBG_EVENT(bs->file, BLKDBG_CLUSTER_FREE); - ret = update_refcount(bs, offset, size, -1); + ret = update_refcount(bs, offset, size, -1, false); if (ret < 0) { fprintf(stderr, "qcow2_free_clusters failed: %s\n", strerror(-ret)); /* TODO Remember the clusters to free them later and avoid leaking */ @@ -795,7 +797,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, int ret; ret = update_refcount(bs, (offset & s->cluster_offset_mask) & ~511, - nb_csectors * 512, addend); + nb_csectors * 512, addend, false); if (ret < 0) { goto fail; } @@ -1228,7 +1230,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res, if (num_fixed) { ret = update_refcount(bs, i << s->cluster_bits, 1, - refcount2 - refcount1); + refcount2 - refcount1, false); if (ret >= 0) { (*num_fixed)++; continue; diff --git a/block/qcow2.h b/block/qcow2.h index f987328..5c126be 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -418,7 +418,7 @@ int qcow2_update_snapshot_refcount(BlockDriverState *bs, int qcow2_check_refcounts(BlockDriverState *bs, BdrvCheckResult *res, BdrvCheckMode fix); int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, - int64_t offset, int64_t length, int addend); + int64_t offset, int64_t length, int addend, bool deduplication); /* qcow2-cluster.c functions */ typedef int (*qcow2_save_table)(BlockDriverState *bs,