qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC V7 05/32] qcow2: Create a way to link to l2 tables whe


From: Benoît Canet
Subject: [Qemu-devel] [RFC V7 05/32] qcow2: Create a way to link to l2 tables when deduplicating.
Date: Fri, 15 Mar 2013 15:49:19 +0100

Signed-off-by: Benoit Canet <address@hidden>
---
 block/qcow2-cluster.c |    7 +++++--
 block/qcow2.h         |    6 ++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 56fccf9..3354f39 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -693,7 +693,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);
      }
 
 
@@ -706,7 +706,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 +1006,9 @@ again:
                     .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 83c90b6..6c45520 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -309,6 +309,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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]