From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Upfpf-0000z6-Vl for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:27:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpfpZ-0000zf-Sd for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:27:27 -0400 Received: from nodalink.pck.nerim.net ([62.212.105.220]:37555 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpfpZ-0000zB-Iv for qemu-devel@nongnu.org; Thu, 20 Jun 2013 10:27:21 -0400 From: =?UTF-8?q?Beno=C3=AEt=20Canet?= Date: Thu, 20 Jun 2013 16:26:16 +0200 Message-Id: <1371738392-9594-9-git-send-email-benoit@irqsave.net> In-Reply-To: <1371738392-9594-1-git-send-email-benoit@irqsave.net> References: <1371738392-9594-1-git-send-email-benoit@irqsave.net> Subject: [Qemu-devel] [RFC V8 08/24] qcow2: Create a way to link to l2 tables when deduplicating. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, =?UTF-8?q?Beno=C3=AEt=20Canet?= , stefanha@redhat.com Signed-off-by: Benoit Canet --- block/qcow2-cluster.c | 6 ++++-- block/qcow2.h | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index c71470a..d6db0b9 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -696,7 +696,7 @@ 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->l2_entry_flags); } @@ -709,7 +709,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); } @@ -1098,6 +1098,8 @@ static int handle_alloc(BlockDriverState *bs, uint64_t guest_offset, .offset = nb_sectors * BDRV_SECTOR_SIZE, .nb_sectors = avail_sectors - nb_sectors, }, + .l2_entry_flags = QCOW_OFLAG_COPIED, + .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 9a9abd3..7754065 100644 --- a/block/qcow2.h +++ b/block/qcow2.h @@ -438,6 +438,12 @@ typedef struct QCowL2Meta */ CoQueue dependent_requests; + /* contains the flags to apply to the l2 entry */ + uint64_t l2_entry_flags; + + /* 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. -- 1.7.10.4