From patchwork Wed Jan 16 16:24:33 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: 212858 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 7C7562C0091 for ; Thu, 17 Jan 2013 04:31:31 +1100 (EST) Received: from localhost ([::1]:60602 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvVoc-0001Qw-Ib for incoming@patchwork.ozlabs.org; Wed, 16 Jan 2013 11:26:14 -0500 Received: from eggs.gnu.org ([208.118.235.92]:41013) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvVoN-0001Fc-1i for qemu-devel@nongnu.org; Wed, 16 Jan 2013 11:26:06 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvVoK-00070L-49 for qemu-devel@nongnu.org; Wed, 16 Jan 2013 11:25:58 -0500 Received: from nodalink.pck.nerim.net ([62.212.105.220]:43189 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvVoJ-00070A-Jl for qemu-devel@nongnu.org; Wed, 16 Jan 2013 11:25:56 -0500 Received: by paradis.irqsave.net (Postfix, from userid 1002) id 22BD587435B; Wed, 16 Jan 2013 17:57:32 +0100 (CET) Received: from localhost.localdomain (unknown [192.168.77.1]) by paradis.irqsave.net (Postfix) with ESMTP id 15BD3874325; 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:33 +0100 Message-Id: <1358353497-5292-13-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 12/36] qcow2: make the deduplication forget a cluster hash when a cluster is to dedupe 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 Signed-off-by: Benoit Canet --- block/qcow2-cluster.c | 11 +++++++++-- block/qcow2-dedup.c | 8 +++++++- block/qcow2.h | 2 ++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index ef91216..5b1d20d 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -710,6 +710,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m) for (i = 0; i < m->nb_clusters; i++) { uint64_t flags = 0; + uint64_t offset = cluster_offset + (i << s->cluster_bits); /* if two concurrent writes happen to the same unallocated cluster * each write allocates separate cluster and writes data concurrently. * The first one to complete updates l2 table with pointer to its @@ -722,8 +723,14 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m) flags = m->oflag_copied ? QCOW_OFLAG_COPIED : 0; flags |= m->to_deduplicate ? QCOW_OFLAG_TO_DEDUP : 0; - l2_table[l2_index + i] = cpu_to_be64((cluster_offset + - (i << s->cluster_bits)) | flags); + l2_table[l2_index + i] = cpu_to_be64(offset | flags); + + /* make the deduplication forget the cluster to avoid making + * the dedup pointing to a cluster that has changed on it's back. + */ + if (m->to_deduplicate) { + qcow2_dedup_forget_cluster_by_sector(bs, offset >> 9); + } } diff --git a/block/qcow2-dedup.c b/block/qcow2-dedup.c index 3d512e5..7049bd8 100644 --- a/block/qcow2-dedup.c +++ b/block/qcow2-dedup.c @@ -824,7 +824,7 @@ static void qcow2_remove_hash_node(BlockDriverState *bs, * @physical_sect: The physical sector of the cluster corresponding to the hash */ static void qcow2_remove_hash_node_by_sector(BlockDriverState *bs, - uint64_t physical_sect) + uint64_t physical_sect) { BDRVQcowState *s = bs->opaque; QCowHashNode *hash_node; @@ -838,6 +838,12 @@ static void qcow2_remove_hash_node_by_sector(BlockDriverState *bs, qcow2_remove_hash_node(bs, hash_node); } +void qcow2_dedup_forget_cluster_by_sector(BlockDriverState *bs, + uint64_t physical_sect) +{ + qcow2_remove_hash_node_by_sector(bs, physical_sect); +} + /* This function store a hash information to disk and RAM * * @hash: the QCowHash to process diff --git a/block/qcow2.h b/block/qcow2.h index da7e57e..bc1ba33 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -469,6 +469,8 @@ int qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c, void **table); /* qcow2-dedup.c functions */ bool qcow2_must_deduplicate(BlockDriverState *bs); +void qcow2_dedup_forget_cluster_by_sector(BlockDriverState *bs, + uint64_t physical_sect); int qcow2_dedup_read_missing_and_concatenate(BlockDriverState *bs, QEMUIOVector *qiov, uint64_t sector,