From patchwork Wed Jan 16 15:47:52 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: 213017 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 C62C82C0090 for ; Thu, 17 Jan 2013 06:28:58 +1100 (EST) Received: from localhost ([::1]:54697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvYfQ-0005jd-Ux for incoming@patchwork.ozlabs.org; Wed, 16 Jan 2013 14:28:56 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59488) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvVFP-0005Bx-H3 for qemu-devel@nongnu.org; Wed, 16 Jan 2013 10:49:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvVFM-00055U-PM for qemu-devel@nongnu.org; Wed, 16 Jan 2013 10:49:51 -0500 Received: from nodalink.pck.nerim.net ([62.212.105.220]:42851 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvVFM-00055J-Gq for qemu-devel@nongnu.org; Wed, 16 Jan 2013 10:49:48 -0500 Received: by paradis.irqsave.net (Postfix, from userid 1002) id 62EB1874309; Wed, 16 Jan 2013 17:21:24 +0100 (CET) Received: from localhost.localdomain (unknown [192.168.77.1]) by paradis.irqsave.net (Postfix) with ESMTP id E743E874326; Wed, 16 Jan 2013 17:19:46 +0100 (CET) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Wed, 16 Jan 2013 16:47:52 +0100 Message-Id: <1358351321-4891-14-git-send-email-benoit@irqsave.net> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1358351321-4891-1-git-send-email-benoit@irqsave.net> References: <1358351321-4891-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 13/62] qcow2: Create qcow2_is_cluster_to_dedup. 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 | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ block/qcow2.h | 4 ++++ 2 files changed, 56 insertions(+) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 5b1d20d..fedcf57 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -514,6 +514,58 @@ out: return ret; } +/* Check if a cluster is to deduplicate given it's index + * + * @index: The logical index of the cluster starting from 0 + * @physical_sect: The physical sector of the cluster as return value + * @err: 0 on success, negative on error + * @ret: True if the cluster is to deduplicate else false + */ +bool qcow2_is_cluster_to_dedup(BlockDriverState *bs, + uint64_t index, + uint64_t *physical_sect, + int *err) +{ + BDRVQcowState *s = bs->opaque; + unsigned int l1_index, l2_index; + uint64_t offset; + uint64_t l2_offset; + uint64_t *l2_table = NULL; + + *physical_sect = 0; + *err = 0; + + l1_index = index >> s->l2_bits; + + if (l1_index >= s->l1_size) { + return false; + } + + /* no l1 entry */ + if (!(s->l1_table[l1_index] & QCOW_OFLAG_COPIED)) { + return false; + } + + l2_offset = s->l1_table[l1_index] & L1E_OFFSET_MASK; + + *err = l2_load(bs, l2_offset, &l2_table); + if (*err < 0) { + return false; + } + + l2_index = index & (s->l2_size - 1); + + offset = be64_to_cpu(l2_table[l2_index]); + *physical_sect = (offset & L2E_OFFSET_MASK) >> 9; + + *err = qcow2_cache_put(bs, s->l2_table_cache, (void **) &l2_table); + if (*err < 0) { + return false; + } + + return offset & QCOW_OFLAG_TO_DEDUP; +} + /* * get_cluster_table * diff --git a/block/qcow2.h b/block/qcow2.h index bc1ba33..0232088 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -440,6 +440,10 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m); int qcow2_discard_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors); int qcow2_zero_clusters(BlockDriverState *bs, uint64_t offset, int nb_sectors); +bool qcow2_is_cluster_to_dedup(BlockDriverState *bs, + uint64_t index, + uint64_t *physical_sect, + int *ret); /* qcow2-snapshot.c functions */ int qcow2_snapshot_create(BlockDriverState *bs, QEMUSnapshotInfo *sn_info);