[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC V7 30/32] qcow2: Add qcow2_dedup_init and qcow2_dedup_
From: |
Benoît Canet |
Subject: |
[Qemu-devel] [RFC V7 30/32] qcow2: Add qcow2_dedup_init and qcow2_dedup_close. |
Date: |
Fri, 15 Mar 2013 15:49:44 +0100 |
Signed-off-by: Benoit Canet <address@hidden>
---
block/qcow2-dedup.c | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++
block/qcow2.h | 2 ++
2 files changed, 80 insertions(+)
diff --git a/block/qcow2-dedup.c b/block/qcow2-dedup.c
index 6ad9d0c..c2dd145 100644
--- a/block/qcow2-dedup.c
+++ b/block/qcow2-dedup.c
@@ -1091,3 +1091,81 @@ bool qcow2_dedup_is_running(BlockDriverState *bs)
BDRVQcowState *s = bs->opaque;
return s->has_dedup && s->dedup_status == DEDUP_STATUS_STARTED;
}
+
+static gint qcow2_dedup_compare_by_hash(gconstpointer a,
+ gconstpointer b,
+ gpointer data)
+{
+ QCowHash *hash_a = (QCowHash *) a;
+ QCowHash *hash_b = (QCowHash *) b;
+ return memcmp(hash_a->data, hash_b->data, HASH_LENGTH);
+}
+
+static void qcow2_dedup_destroy_qcow_hash_node(gpointer p)
+{
+ QCowHashNode *hash_node = (QCowHashNode *) p;
+ g_free(hash_node);
+}
+
+static int qcow2_dedup_alloc(BlockDriverState *bs)
+{
+ BDRVQcowState *s = bs->opaque;
+ int ret;
+
+ ret = qcow2_do_table_init(bs,
+ &s->dedup_table,
+ s->dedup_table_offset,
+ s->dedup_table_size,
+ false);
+
+ if (ret < 0) {
+ return ret;
+ }
+
+ s->dedup_tree_by_hash = g_tree_new_full(qcow2_dedup_compare_by_hash, NULL,
+ NULL,
+
qcow2_dedup_destroy_qcow_hash_node);
+
+ s->dedup_cluster_cache = qcow2_cache_create(bs, DEDUP_CACHE_SIZE,
+ s->hash_block_size);
+
+ return 0;
+}
+
+static void qcow2_dedup_free(BlockDriverState *bs)
+{
+ BDRVQcowState *s = bs->opaque;
+ g_free(s->dedup_table);
+
+ qcow2_cache_flush(bs, s->dedup_cluster_cache);
+ qcow2_cache_destroy(bs, s->dedup_cluster_cache);
+ g_tree_destroy(s->dedup_tree_by_hash);
+}
+
+int qcow2_dedup_init(BlockDriverState *bs)
+{
+ BDRVQcowState *s = bs->opaque;
+ int ret = 0;
+
+ s->has_dedup = true;
+
+ ret = qcow2_dedup_alloc(bs);
+
+ if (ret < 0) {
+ return ret;
+ }
+
+ /* if we are read-only we don't load the deduplication table */
+ if (bs->read_only) {
+ return 0;
+ }
+
+ s->dedup_status = DEDUP_STATUS_STARTING;
+
+ return 0;
+}
+
+void qcow2_dedup_close(BlockDriverState *bs)
+{
+ qcow2_dedup_free(bs);
+}
diff --git a/block/qcow2.h b/block/qcow2.h
index a430fe1..9275be1 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -500,5 +500,7 @@ int qcow2_dedup_store_new_hashes(BlockDriverState *bs,
void qcow2_dedup_destroy_hash(BlockDriverState *bs,
uint64_t cluster_index);
bool qcow2_dedup_is_running(BlockDriverState *bs);
+int qcow2_dedup_init(BlockDriverState *bs);
+void qcow2_dedup_close(BlockDriverState *bs);
#endif
--
1.7.10.4
- [Qemu-devel] [RFC V7 18/32] qcow2: Extract qcow2_set_incompat_feature and qcow2_clear_incompat_feature., (continued)
- [Qemu-devel] [RFC V7 18/32] qcow2: Extract qcow2_set_incompat_feature and qcow2_clear_incompat_feature., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 21/32] qcow2: Remove hash when cluster is deleted., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 22/32] qcow2: Add qcow2_dedup_is_running to probe if dedup is running., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 20/32] qcow2: Drop hash for a given cluster when dedup makes refcount > 2^16/2., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 24/32] qcow2: Serialize write requests when deduplication is activated., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 23/32] qcow2: Integrate deduplication in qcow2_co_writev loop., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 19/32] block: Add qcow2_dedup format and image creation code., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 25/32] qcow2: Adapt checking of QCOW_OFLAG_COPIED for dedup., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 26/32] qcow2: Add check_dedup_l2 in order to check l2 of dedup table., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 27/32] qcow2: Add verification of dedup table., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 30/32] qcow2: Add qcow2_dedup_init and qcow2_dedup_close.,
Benoît Canet <=
- [Qemu-devel] [RFC V7 28/32] qcow2: Integrate SKEIN hash algorithm in deduplication., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 29/32] qcow: Set large dedup hash block size., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 32/32] qcow2: Enable the deduplication feature., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 31/32] qcow2: Add qcow2_co_dedup_resume to restart deduplication., Benoît Canet, 2013/03/15