Patchwork [RFC,V2,6/7] qcow2: Make dedup status persists.

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

Comments

Benoît Canet - Feb. 6, 2013, 12:32 p.m.
---
 block/qcow2-dedup.c |    7 +++++++
 block/qcow2.c       |    6 +++++-
 block/qcow2.h       |    1 +
 3 files changed, 13 insertions(+), 1 deletion(-)

Patch

diff --git a/block/qcow2-dedup.c b/block/qcow2-dedup.c
index 66fb415..165aae9 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 = DEDUP_STATUS_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 = DEDUP_STATUS_STARTING;
 
     /* resume deduplication */
@@ -1474,6 +1480,7 @@  void qcow2_dedup_control(BlockDriverState *bs, const bool enable)
         qemu_coroutine_enter(s->dedup_resume_co, bs);
     } else {
         s->dedup_status = DEDUP_STATUS_STOPPING;
+        qcow2_update_header(bs);
         /* must handle half processed write requests */
         qcow2_dedup_reset(bs);
         s->dedup_status = DEDUP_STATUS_STOPPED;
diff --git a/block/qcow2.c b/block/qcow2.c
index 3549e87..8319fe4 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -169,6 +169,8 @@  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 &
+                                 QCOW_STRATEGY_RUNNING;
             break;
 
         default:
@@ -1219,7 +1221,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 |= QCOW_STRATEGY_RAM;
-        dedup_table_extension.strategies |= QCOW_STRATEGY_RUNNING;
+        if (s->has_dedup && s->dedup_status == DEDUP_STATUS_STARTED) {
+            dedup_table_extension.strategies |= QCOW_STRATEGY_RUNNING;
+        }
         ret = header_ext_add(buf,
                              QCOW2_EXT_MAGIC_DEDUP_TABLE,
                              &dedup_table_extension,
diff --git a/block/qcow2.h b/block/qcow2.h
index 316b0d3..dd6190b 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -242,6 +242,7 @@  typedef struct BDRVQcowState {
     int64_t free_byte_offset;
 
     bool has_dedup;
+    bool start_dedup;
     DedupStatus dedup_status;
     QCowHashAlgo dedup_hash_algo;
     Coroutine *dedup_resume_co;