Patchwork [RFC,V6,06/33] qcow2: Create a way to link to l2 tables when deduplicating.

login
register
mail settings
Submitter Benoît Canet
Date Feb. 6, 2013, 12:31 p.m.
Message ID <1360153926-9492-7-git-send-email-benoit@irqsave.net>
Download mbox | patch
Permalink /patch/218646/
State New
Headers show

Comments

Benoît Canet - Feb. 6, 2013, 12:31 p.m.
Signed-off-by: Benoit Canet <benoit@irqsave.net>
---
 block/qcow2-cluster.c |    8 ++++++--
 block/qcow2.h         |    9 +++++++++
 2 files changed, 15 insertions(+), 2 deletions(-)
Stefan Hajnoczi - Feb. 6, 2013, 4:59 p.m.
On Wed, Feb 06, 2013 at 01:31:39PM +0100, Benoît Canet wrote:
> diff --git a/block/qcow2.h b/block/qcow2.h
> index 8867091..95bf848 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)

QCOW_FLAG_ is too general, I'm not sure what these flags relate to.
Maybe QCOW_DEDUP_FLAG_*?

> +/* indicate that the cluster for this hash has QCOW_OFLAG_COPIED on disk */
> +#define QCOW_FLAG_FIRST   (1LL << 63)

It's easier to understand if "OFLAG_COPIED" is part of the name instead
of picking a new word ("FIRST").

Also, does this hunk belong in another patch?

Patch

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 8867091..95bf848 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)
 
 #define QCOW_STRATEGY_RAM     1
 #define QCOW_STRATEGY_DISK    (1 << 1)
@@ -301,6 +305,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.