From patchwork Wed Jan 16 16:24: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: 212977 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 727252C0090 for ; Thu, 17 Jan 2013 05:56:53 +1100 (EST) Received: from localhost ([::1]:59459 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvVoB-0000pq-CI for incoming@patchwork.ozlabs.org; Wed, 16 Jan 2013 11:25:47 -0500 Received: from eggs.gnu.org ([208.118.235.92]:40759) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvVnd-0007yz-1Q for qemu-devel@nongnu.org; Wed, 16 Jan 2013 11:25:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TvVnZ-0006qy-LX for qemu-devel@nongnu.org; Wed, 16 Jan 2013 11:25:12 -0500 Received: from nodalink.pck.nerim.net ([62.212.105.220]:43139 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvVnZ-0006qn-DU for qemu-devel@nongnu.org; Wed, 16 Jan 2013 11:25:09 -0500 Received: by paradis.irqsave.net (Postfix, from userid 1002) id D9BEB874306; Wed, 16 Jan 2013 17:56:45 +0100 (CET) Received: from localhost.localdomain (unknown [192.168.77.1]) by paradis.irqsave.net (Postfix) with ESMTP id 723DC874315; Wed, 16 Jan 2013 17:56:03 +0100 (CET) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Wed, 16 Jan 2013 17:24:26 +0100 Message-Id: <1358353497-5292-6-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 05/36] 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 803aeda..4273e7c 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -63,6 +63,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_DEDUP_STOPPED, @@ -304,6 +308,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.