From patchwork Wed Jan 2 16:16:08 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: 209076 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 531512C0086 for ; Thu, 3 Jan 2013 03:20:11 +1100 (EST) Received: from localhost ([::1]:55529 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TqR0D-0000ua-E5 for incoming@patchwork.ozlabs.org; Wed, 02 Jan 2013 11:17:13 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TqQzs-0000Mx-23 for qemu-devel@nongnu.org; Wed, 02 Jan 2013 11:16:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TqQzp-0005zh-38 for qemu-devel@nongnu.org; Wed, 02 Jan 2013 11:16:51 -0500 Received: from nodalink.pck.nerim.net ([62.212.105.220]:56184 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TqQzo-0005za-QL for qemu-devel@nongnu.org; Wed, 02 Jan 2013 11:16:49 -0500 Received: by paradis.irqsave.net (Postfix, from userid 1002) id 6490E874307; Wed, 2 Jan 2013 17:43:17 +0100 (CET) Received: from localhost.localdomain (unknown [192.168.77.1]) by paradis.irqsave.net (Postfix) with ESMTP id D2D5D874310; Wed, 2 Jan 2013 17:42:38 +0100 (CET) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Wed, 2 Jan 2013 17:16:08 +0100 Message-Id: <1357143393-29832-6-git-send-email-benoit@irqsave.net> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1357143393-29832-1-git-send-email-benoit@irqsave.net> References: <1357143393-29832-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 V4 05/30] qcow2: Create a way to link to l2 tables when deduplicating. 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 | 8 ++++++-- block/qcow2.h | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 56fccf9..63a7241 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -693,7 +693,8 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m) old_cluster[j++] = l2_table[l2_index + i]; l2_table[l2_index + i] = cpu_to_be64((cluster_offset + - (i << s->cluster_bits)) | QCOW_OFLAG_COPIED); + (i << s->cluster_bits)) | + (m->oflag_copied ? QCOW_OFLAG_COPIED : 0)); } @@ -706,7 +707,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs, QCowL2Meta *m) * If this was a COW, we need to decrease the refcount of the old cluster. * Also flush bs->file to get the right order for L2 and refcount update. */ - if (j != 0) { + if (!m->overwrite && j != 0) { for (i = 0; i < j; i++) { qcow2_free_any_clusters(bs, be64_to_cpu(old_cluster[i]), 1); } @@ -1006,6 +1007,9 @@ again: .offset = nb_sectors * BDRV_SECTOR_SIZE, .nb_sectors = avail_sectors - nb_sectors, }, + + .oflag_copied = true, + .overwrite = false, }; qemu_co_queue_init(&(*m)->dependent_requests); QLIST_INSERT_HEAD(&s->cluster_allocs, *m, next_in_flight); diff --git a/block/qcow2.h b/block/qcow2.h index 3307481..9403431 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -59,6 +59,10 @@ #define DEFAULT_CLUSTER_SIZE 65536 #define HASH_LENGTH 32 +/* indicate that the hash structure is empty and miss offset */ +#define QCOW_FLAG_EMPTY (1LL << 62) +/* indicate that the cluster for this hash has QCOW_OFLAG_COPIED on disk */ +#define QCOW_FLAG_FIRST (1LL << 63) typedef enum { QCOW_HASH_SHA256 = 0, @@ -289,6 +293,11 @@ typedef struct QCowL2Meta */ CoQueue dependent_requests; + /* set to true if QCOW_OFLAG_COPIED must be set in the L2 table entry */ + bool oflag_copied; + /* set to true if we are overwriting an L2 table entry */ + bool overwrite; + /** * The COW Region between the start of the first allocated cluster and the * area the guest actually writes to.