Patchwork [RFC,V1,07/12] qcow2: Add qcow2_pause_dedup.

login
register
mail settings
Submitter Benoît Canet
Date Jan. 16, 2013, 4:25 p.m.
Message ID <1358353518-5421-8-git-send-email-benoit@irqsave.net>
Download mbox | patch
Permalink /patch/212819/
State New
Headers show

Comments

Benoît Canet - Jan. 16, 2013, 4:25 p.m.
---
 block/qcow2-dedup.c |   19 +++++++++++++++++++
 block/qcow2.c       |    2 ++
 block/qcow2.h       |    1 +
 3 files changed, 22 insertions(+)

Patch

diff --git a/block/qcow2-dedup.c b/block/qcow2-dedup.c
index dd320bf..e007387 100644
--- a/block/qcow2-dedup.c
+++ b/block/qcow2-dedup.c
@@ -1278,15 +1278,20 @@  static void qcow2_deduplicate_after_resuming(BlockDriverState *bs)
     BDRVQcowState *s = bs->opaque;
     uint64_t i;
     bool processed;
+    bool exit;
 
     /* for each l2 entry */
     for (i = 0; i < s->l2_size * s->l1_size; i++) {
         qemu_co_mutex_lock(&s->lock);
         processed = qcow2_process_to_dedup_cluster(bs, i);
+        exit = s->dedup_status == QCOW_DEDUP_STOPPING;
         qemu_co_mutex_unlock(&s->lock);
         if (processed || !(i % s->l2_size)) {
             co_sleep_ns(rt_clock, s->dedup_co_delay);
         }
+        if (exit) {
+            return;
+        }
     }
 }
 
@@ -1450,3 +1455,17 @@  void qcow2_dedup_update_metrics(BlockDriverState *bs)
     s->dedup_metrics.ram_usage = nb_hashs * GTREE_NODE_SIZE * 2;
     s->dedup_metrics.ram_usage += nb_hashs * sizeof(QCowHashNode);
 }
+
+void qcow2_pause_dedup(BlockDriverState *bs)
+{
+    BDRVQcowState *s = bs->opaque;
+
+    if (s->dedup_status != QCOW_DEDUP_STARTED) {
+        return;
+    }
+
+    s->dedup_status = QCOW_DEDUP_STOPPING;
+    /* 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 e442268..c17ab63 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2011,6 +2011,8 @@  static BlockDriver bdrv_qcow2 = {
 
     .bdrv_invalidate_cache      = qcow2_invalidate_cache,
 
+    .bdrv_pause_dedup           = qcow2_pause_dedup,
+
     .create_options = qcow2_create_options,
     .bdrv_check = qcow2_check,
 };
diff --git a/block/qcow2.h b/block/qcow2.h
index d8e8539..5940c89 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -511,5 +511,6 @@  bool qcow2_dedup_is_running(BlockDriverState *bs);
 int qcow2_dedup_init(BlockDriverState *bs);
 void qcow2_dedup_close(BlockDriverState *bs);
 void qcow2_dedup_update_metrics(BlockDriverState *bs);
+void qcow2_pause_dedup(BlockDriverState *bs);
 
 #endif