[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC V7 13/32] qcow2: make the deduplication forget a clust
From: |
Benoît Canet |
Subject: |
[Qemu-devel] [RFC V7 13/32] qcow2: make the deduplication forget a cluster hash when a cluster is to dedupe |
Date: |
Fri, 15 Mar 2013 15:49:27 +0100 |
Signed-off-by: Benoit Canet <address@hidden>
---
block/qcow2-cluster.c | 11 +++++++++--
block/qcow2-dedup.c | 40 ++++++++++++++++++++++++++++++++++++++++
block/qcow2.h | 2 ++
3 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c
index 0d11ef0..3cbb64f 100644
--- a/block/qcow2-cluster.c
+++ b/block/qcow2-cluster.c
@@ -683,6 +683,7 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs,
QCowL2Meta *m)
qcow2_cache_entry_mark_dirty(s->l2_table_cache, l2_table);
for (i = 0; i < m->nb_clusters; i++) {
+ uint64_t offset = cluster_offset + (i << s->cluster_bits);
/* if two concurrent writes happen to the same unallocated cluster
* each write allocates separate cluster and writes data concurrently.
* The first one to complete updates l2 table with pointer to its
@@ -692,8 +693,14 @@ int qcow2_alloc_cluster_link_l2(BlockDriverState *bs,
QCowL2Meta *m)
if(l2_table[l2_index + i] != 0)
old_cluster[j++] = l2_table[l2_index + i];
- l2_table[l2_index + i] = cpu_to_be64((cluster_offset +
- (i << s->cluster_bits)) | m->l2_entry_flags);
+ l2_table[l2_index + i] = cpu_to_be64(offset | m->l2_entry_flags);
+
+ /* make the deduplication forget the cluster to avoid making
+ * the dedup pointing to a cluster that has changed on it's back.
+ */
+ if (m->to_deduplicate) {
+ qcow2_dedup_forget_cluster_by_sector(bs, offset >> 9);
+ }
}
diff --git a/block/qcow2-dedup.c b/block/qcow2-dedup.c
index c106bd5..2aca01a 100644
--- a/block/qcow2-dedup.c
+++ b/block/qcow2-dedup.c
@@ -869,6 +869,46 @@ static inline bool is_hash_node_empty(QCowHashNode
*hash_node)
return hash_node->physical_sect & QCOW_DEDUP_FLAG_EMPTY;
}
+/* This function removes a hash_node from the trees given a physical sector
+ *
+ * @physical_sect: The physical sector of the cluster corresponding to the hash
+ */
+static void qcow2_remove_hash_node_by_sector(BlockDriverState *bs,
+ uint64_t physical_sect)
+{
+ BDRVQcowState *s = bs->opaque;
+ QCowHash hash;
+ int ret = 0;
+ uint8_t *data = qemu_blockalign(bs, s->cluster_sectors * BDRV_SECTOR_SIZE);
+
+
+ /* read the cluster data */
+ ret = bdrv_pread(bs->file, physical_sect << 9, data, s->cluster_size);
+
+ if (ret < 0) {
+ goto free_exit;
+ }
+
+ ret = qcow2_compute_cluster_hash(bs,
+ &hash,
+ data);
+
+ if (ret < 0) {
+ goto free_exit;
+ }
+
+ g_tree_remove(s->dedup_tree_by_hash, &hash);
+
+free_exit:
+ qemu_vfree(data);
+}
+
+void qcow2_dedup_forget_cluster_by_sector(BlockDriverState *bs,
+ uint64_t physical_sect)
+{
+ qcow2_remove_hash_node_by_sector(bs, physical_sect);
+}
+
/* This function store a hash information to disk and RAM
*
* @hash: the QCowHash to process
diff --git a/block/qcow2.h b/block/qcow2.h
index 9f24b4c..2eab1a4 100644
--- a/block/qcow2.h
+++ b/block/qcow2.h
@@ -467,6 +467,8 @@ int qcow2_cache_put(BlockDriverState *bs, Qcow2Cache *c,
void **table);
/* qcow2-dedup.c functions */
bool qcow2_must_deduplicate(BlockDriverState *bs);
+void qcow2_dedup_forget_cluster_by_sector(BlockDriverState *bs,
+ uint64_t physical_sect);
int qcow2_dedup_read_missing_and_concatenate(BlockDriverState *bs,
QEMUIOVector *qiov,
uint64_t sector,
--
1.7.10.4
- [Qemu-devel] [RFC V7 03/32] qcow2: Add deduplication structures and fields., (continued)
- [Qemu-devel] [RFC V7 03/32] qcow2: Add deduplication structures and fields., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 04/32] qcow2: Add qcow2_de dup_read_missing_and_concatenate, Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 05/32] qcow2: Create a way to link to l2 tables when deduplicating., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 06/32] qcow2: Make qcow2_update_cluster_refcount public., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 09/32] qcow2: Do allocate on rewrite on the dedup case., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 07/32] qcow2: Add qcow2_dedup and related functions, Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 08/32] qcow2: Add qcow2_dedup_store_new_hashes., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 10/32] qcow2: Implement qcow2_compute_cluster_hash., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 12/32] qcow2: Makes qcow2_alloc_cluster_link_l2 mark to deduplicate clusters., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 11/32] qcow2: Add qcow2_dedup_grow_table and use it., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 13/32] qcow2: make the deduplication forget a cluster hash when a cluster is to dedupe,
Benoît Canet <=
- [Qemu-devel] [RFC V7 14/32] qcow2: Create qcow2_is_cluster_to_dedup., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 16/32] qcow2: Extract qcow2_do_table_init., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 15/32] qcow2: Load and save deduplication table header extension., Benoît Canet, 2013/03/15
- [Qemu-devel] [RFC V7 17/32] qcow2-cache: Allow to choose table size at creation., Benoît Canet, 2013/03/15
- [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