Patchwork [RFC,V5,59/62] qcow2: Make dedup status persists.

login
register
mail settings
Submitter Benoît Canet
Date Jan. 16, 2013, 3:48 p.m.
Message ID <1358351321-4891-60-git-send-email-benoit@irqsave.net>
Download mbox | patch
Permalink /patch/212816/
State New
Headers show

Comments

Benoît Canet - Jan. 16, 2013, 3:48 p.m.
---
 block/qcow2-dedup.c |    7 +++++++
 block/qcow2.c       |    5 ++++-
 block/qcow2.h       |    1 +
 3 files changed, 12 insertions(+), 1 deletion(-)

Patch

diff --git a/block/qcow2-dedup.c b/block/qcow2-dedup.c
index 93545af..85ef66f 100644
--- a/block/qcow2-dedup.c
+++ b/block/qcow2-dedup.c
@@ -1323,6 +1323,8 @@  static void coroutine_fn qcow2_co_dedup_resume(void *opaque)
     s->dedup_status = QCOW_DEDUP_STARTED;
     qemu_co_mutex_unlock(&s->lock);
 
+    qcow2_update_header(bs);
+
     qcow2_deduplicate_after_resuming(bs);
 
     return;
@@ -1429,6 +1431,10 @@  int qcow2_dedup_init(BlockDriverState *bs)
         return 0;
     }
 
+    if (!s->start_dedup) {
+        return 0;
+    }
+
     s->dedup_status = QCOW_DEDUP_STARTING;
 
     /* resume deduplication */
@@ -1465,6 +1471,7 @@  void qcow2_pause_dedup(BlockDriverState *bs)
     }
 
     s->dedup_status = QCOW_DEDUP_STOPPING;
+    qcow2_update_header(bs);
     /* must handle half processed write requests */
     qcow2_dedup_reset(bs);
     s->dedup_status = QCOW_DEDUP_STOPPED;
diff --git a/block/qcow2.c b/block/qcow2.c
index d5681ad..1e61050 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -168,6 +168,7 @@  static int qcow2_read_extensions(BlockDriverState *bs, uint64_t start_offset,
                 s->dedup_table_size =
                     be32_to_cpu(dedup_table_extension.size);
                 s->dedup_hash_algo = dedup_table_extension.hash_algo;
+                s->start_dedup = dedup_table_extension.strategies & (1 << 2);
             break;
 
         default:
@@ -1221,7 +1222,9 @@  int qcow2_update_header(BlockDriverState *bs)
         dedup_table_extension.size = cpu_to_be32(s->dedup_table_size);
         dedup_table_extension.hash_algo = s->dedup_hash_algo;
         dedup_table_extension.strategies |= 1; /* RAM based lookup */
-        dedup_table_extension.strategies |= 1 << 2; /* deduplication running */
+        if (s->has_dedup && s->dedup_status == QCOW_DEDUP_STARTED) {
+            dedup_table_extension.strategies |= 1 << 2;
+        }
         ret = header_ext_add(buf,
                              QCOW2_EXT_MAGIC_DEDUP_TABLE,
                              &dedup_table_extension,
diff --git a/block/qcow2.h b/block/qcow2.h
index 2b5a7d4..3fdfe14 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -228,6 +228,7 @@  typedef struct BDRVQcowState {
     int64_t free_byte_offset;
 
     bool has_dedup;
+    bool start_dedup;
     QCowDedupStatus dedup_status;
     QCowHashAlgo dedup_hash_algo;
     Coroutine *dedup_resume_co;