From patchwork Thu Jun 20 14:26:26 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: 253014 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 702DF2C0182 for ; Fri, 21 Jun 2013 01:41:28 +1000 (EST) Received: from localhost ([::1]:46002 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpgzF-0007si-TJ for incoming@patchwork.ozlabs.org; Thu, 20 Jun 2013 11:41:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60515) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpfrC-0003wB-S5 for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:29:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Upfr2-0001Tf-Re for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:29:02 -0400 Received: from nodalink.pck.nerim.net ([62.212.105.220]:37609 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upfr2-0001Sx-GU for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:28:52 -0400 Received: by paradis.irqsave.net (Postfix, from userid 1002) id DB91C874673; Thu, 20 Jun 2013 16:28:51 +0200 (CEST) Received: from localhost.localdomain (unknown [192.168.77.1]) by paradis.irqsave.net (Postfix) with ESMTP id 9AE1C87467D; Thu, 20 Jun 2013 16:25:01 +0200 (CEST) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Thu, 20 Jun 2013 16:26:26 +0200 Message-Id: <1371738392-9594-19-git-send-email-benoit@irqsave.net> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1371738392-9594-1-git-send-email-benoit@irqsave.net> References: <1371738392-9594-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, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com Subject: [Qemu-devel] [RFC V8 18/24] qcow2: Remove hash when cluster is deleted. 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-dedup.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ block/qcow2-refcount.c | 3 +++ block/qcow2.h | 2 ++ 3 files changed, 50 insertions(+) diff --git a/block/qcow2-dedup.c b/block/qcow2-dedup.c index da4ad5c..599cb2e 100644 --- a/block/qcow2-dedup.c +++ b/block/qcow2-dedup.c @@ -656,3 +656,48 @@ int qcow2_dedup_store_new_hashes(BlockDriverState *bs, return ret; } + +/* Clean the last reference to a given cluster when its refcount is zero + * + * @cluster_index: the index of the physical cluster + */ +void qcow2_dedup_destroy_hash(BlockDriverState *bs, + uint64_t cluster_index) +{ + BDRVQcowState *s = bs->opaque; + uint64_t offset = cluster_index * s->cluster_size; + QCowHashInfo hash_info; + uint8_t *buf; + int ret = 0; + + /* allocate buffer */ + buf = qemu_blockalign(bs, s->cluster_size); + + /* read cluster from disk */ + ret = bdrv_pread(bs->file, offset, buf, s->cluster_size); + + /* error */ + if (ret < 0) { + goto free_exit; + } + + /* clear hash info */ + memset(&hash_info, 0, sizeof(QCowHashInfo)); + + /* compute hash for the cluster */ + ret = qcow2_compute_cluster_hash(bs, + &hash_info.hash, + buf); + + + /* error */ + if (ret < 0) { + goto free_exit; + } + + /* delete hash from key value store. It will not be deduplicated anymore */ + qcow2_store_delete(bs, &s->key_value_store, &hash_info); + +free_exit: + qemu_vfree(buf); +} diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 3bd8f37..2734cd9 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -482,6 +482,9 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(BlockDriverState *bs, ret = -EINVAL; goto fail; } + if (s->has_dedup && refcount == 0) { + qcow2_dedup_destroy_hash(bs, cluster_index); + } if (refcount == 0 && cluster_index < s->free_cluster_index) { s->free_cluster_index = cluster_index; } diff --git a/block/qcow2.h b/block/qcow2.h index 720131d..6f85e03 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -748,5 +748,7 @@ int qcow2_dedup_store_new_hashes(BlockDriverState *bs, int count, uint64_t logical_sect, uint64_t physical_sect); +void qcow2_dedup_destroy_hash(BlockDriverState *bs, + uint64_t cluster_index); #endif