[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC V4 11/30] qcow2: create function to load deduplication
From: |
Benoît Canet |
Subject: |
[Qemu-devel] [RFC V4 11/30] qcow2: create function to load deduplication hashes at startup. |
Date: |
Wed, 2 Jan 2013 17:16:14 +0100 |
Signed-off-by: Benoit Canet <address@hidden>
---
block/qcow2-dedup.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++
block/qcow2.h | 1 +
2 files changed, 69 insertions(+)
diff --git a/block/qcow2-dedup.c b/block/qcow2-dedup.c
index b998a2d..4c391e5 100644
--- a/block/qcow2-dedup.c
+++ b/block/qcow2-dedup.c
@@ -918,3 +918,71 @@ int qcow2_dedup_store_new_hashes(BlockDriverState *bs,
return ret;
}
+
+static void qcow2_dedup_insert_hash_and_preserve_newer(BlockDriverState *bs,
+ QCowHashNode *hash_node)
+{
+ BDRVQcowState *s = bs->opaque;
+ QCowHashNode *newer_hash_node;
+
+ newer_hash_node = g_tree_lookup(s->dedup_tree_by_sect,
+ &hash_node->physical_sect);
+
+ if (!newer_hash_node) {
+ g_tree_insert(s->dedup_tree_by_hash, &hash_node->hash, hash_node);
+ g_tree_insert(s->dedup_tree_by_sect, &hash_node->physical_sect,
+ hash_node);
+ } else {
+ g_free(hash_node);
+ }
+}
+
+/*
+ * This coroutine load the deduplication hashes in the tree
+ *
+ * @data: the given BlockDriverState
+ * @ret: NULL
+ */
+void coroutine_fn qcow2_co_load_dedup_hashes(void *opaque)
+{
+ BlockDriverState *bs = opaque;
+ BDRVQcowState *s = bs->opaque;
+ int ret;
+ QCowHash hash, null_hash;
+ uint64_t max_clusters, i;
+ uint64_t first_logical_sect;
+ int nb_hash_in_hash_block = s->hash_block_size / (HASH_LENGTH + 8);
+ QCowHashNode *hash_node;
+
+ /* prepare the null hash */
+ memset(&null_hash, 0, sizeof(null_hash));
+
+ max_clusters = s->dedup_table_size * nb_hash_in_hash_block;
+
+ for (i = 0; i < max_clusters; i++) {
+ /* get the hash */
+ qemu_co_mutex_lock(&s->lock);
+ ret = qcow2_dedup_read_write_hash(bs, &hash,
+ &first_logical_sect,
+ i * s->cluster_sectors,
+ false);
+
+ if (ret < 0) {
+ qemu_co_mutex_unlock(&s->lock);
+ error_report("Failed to load deduplication hash.");
+ continue;
+ }
+
+ /* if the hash is null don't load it */
+ if (!memcmp(hash.data, null_hash.data, HASH_LENGTH)) {
+ qemu_co_mutex_unlock(&s->lock);
+ continue;
+ }
+
+ hash_node = qcow2_dedup_build_qcow_hash_node(&hash,
+ i * s->cluster_sectors,
+ first_logical_sect);
+ qcow2_dedup_insert_hash_and_preserve_newer(bs, hash_node);
+ qemu_co_mutex_unlock(&s->lock);
+ }
+}
diff --git a/block/qcow2.h b/block/qcow2.h
index afa730e..5cbfc82 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -467,5 +467,6 @@ int qcow2_dedup_store_new_hashes(BlockDriverState *bs,
int count,
uint64_t logical_sect,
uint64_t physical_sect);
+void coroutine_fn qcow2_co_load_dedup_hashes(void *opaque);
#endif
--
1.7.10.4
- [Qemu-devel] [RFC V4 20/30] qcow2: Serialize write requests when deduplication is activated., (continued)
- [Qemu-devel] [RFC V4 20/30] qcow2: Serialize write requests when deduplication is activated., Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 22/30] qcow2: Adapt checking of QCOW_OFLAG_COPIED for dedup., Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 28/30] qcow: Set dedup cluster block size to 64KB., Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 27/30] qcow2: Use large L2 table for deduplication., Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 12/30] qcow2: Load and save deduplication table header extension., Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 16/30] qcow2: Extract qcow2_add_feature and qcow2_remove_feature., Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 06/30] qcow2: Add qcow2_dedup and related functions, Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 26/30] qcow2: Add lazy refcounts to deduplication to prevent qcow2_cache_set_dependency loops, Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 18/30] qcow2: Behave correctly when refcount reach 0 or 2^16., Benoît Canet, 2013/01/02
- [Qemu-devel] [RFC V4 11/30] qcow2: create function to load deduplication hashes at startup.,
Benoît Canet <=
- [Qemu-devel] [RFC V4 13/30] qcow2: Extract qcow2_do_table_init., Benoît Canet, 2013/01/02
- Re: [Qemu-devel] [RFC V4 00/30] QCOW2 deduplication, Troy Benjegerdes, 2013/01/02
- Re: [Qemu-devel] [RFC V4 00/30] QCOW2 deduplication, Benoît Canet, 2013/01/02
- Re: [Qemu-devel] [RFC V4 00/30] QCOW2 deduplication, Troy Benjegerdes, 2013/01/02
- Re: [Qemu-devel] [RFC V4 00/30] QCOW2 deduplication, Benoît Canet, 2013/01/02
- Re: [Qemu-devel] [RFC V4 00/30] QCOW2 deduplication, ronnie sahlberg, 2013/01/02
- Re: [Qemu-devel] [RFC V4 00/30] QCOW2 deduplication, Benoît Canet, 2013/01/02
- Re: [Qemu-devel] [RFC V4 00/30] QCOW2 deduplication, Troy Benjegerdes, 2013/01/02