[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC V2 5/7] qcow2: Add qcow2_dedup_control.
From: |
Benoît Canet |
Subject: |
[Qemu-devel] [RFC V2 5/7] qcow2: Add qcow2_dedup_control. |
Date: |
Wed, 6 Feb 2013 13:32:24 +0100 |
---
block/qcow2-dedup.c | 31 +++++++++++++++++++++++++++++++
block/qcow2.c | 2 ++
block/qcow2.h | 1 +
3 files changed, 34 insertions(+)
diff --git a/block/qcow2-dedup.c b/block/qcow2-dedup.c
index bbbb1ac..66fb415 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 == DEDUP_STATUS_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;
+ }
}
}
@@ -1448,3 +1453,29 @@ void qcow2_dedup_update_metrics(BlockDriverState *bs)
s->dedup_metrics.ram_usage = nb_hashs * sizeof(GTreeNode_Copy) * 2;
s->dedup_metrics.ram_usage += nb_hashs * sizeof(QCowHashNode);
}
+
+void qcow2_dedup_control(BlockDriverState *bs, const bool enable)
+{
+ BDRVQcowState *s = bs->opaque;
+
+ /* must stop and not STARTED -> pass */
+ if (!enable && s->dedup_status != DEDUP_STATUS_STARTED) {
+ return;
+ }
+
+ /* must start and not stopped -> pass */
+ if (enable && s->dedup_status != DEDUP_STATUS_STOPPED) {
+ return;
+ }
+
+ if (enable) {
+ s->dedup_status = DEDUP_STATUS_STARTING;
+ s->dedup_resume_co = qemu_coroutine_create(qcow2_co_dedup_resume);
+ qemu_coroutine_enter(s->dedup_resume_co, bs);
+ } else {
+ s->dedup_status = DEDUP_STATUS_STOPPING;
+ /* 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 0ee5f4b..3549e87 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -2052,6 +2052,8 @@ static BlockDriver bdrv_qcow2 = {
.bdrv_invalidate_cache = qcow2_invalidate_cache,
+ .bdrv_dedup_control = qcow2_dedup_control,
+
.create_options = qcow2_create_options,
.bdrv_check = qcow2_check,
};
diff --git a/block/qcow2.h b/block/qcow2.h
index 191b272..316b0d3 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -525,5 +525,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_dedup_control(BlockDriverState *bs, const bool enable);
#endif
--
1.7.10.4
- [Qemu-devel] [RFC V2 0/7] QCOW2 asynchronous deduplication, Benoît Canet, 2013/02/06
- [Qemu-devel] [RFC V2 2/7] qcow2: Add code to deduplicate cluster flagged with QCOW_OFLAG_TO_DEDUP., Benoît Canet, 2013/02/06
- [Qemu-devel] [RFC V2 6/7] qcow2: Make dedup status persists., Benoît Canet, 2013/02/06
- [Qemu-devel] [RFC V2 5/7] qcow2: Add qcow2_dedup_control.,
Benoît Canet <=
- [Qemu-devel] [RFC V2 7/7] qmp: Add block-dedup-control., Benoît Canet, 2013/02/06
- [Qemu-devel] [RFC V2 4/7] block: Add bdrv_dedup_control to start and stop deduplication., Benoît Canet, 2013/02/06
- [Qemu-devel] [RFC V2 3/7] block: Add bdrv_has_dedup., Benoît Canet, 2013/02/06
- [Qemu-devel] [RFC V2 1/7] block: Add BlockDriver function prototype to pause and resume deduplication., Benoît Canet, 2013/02/06