A new physical cluster with the same hash value will be used for further
occurrence of this hash.

Signed-off-by: Benoit Canet <ben...@irqsave.net>
---
 block/qcow2-dedup.c |   20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/block/qcow2-dedup.c b/block/qcow2-dedup.c
index 2d2c15c..da4ad5c 100644
--- a/block/qcow2-dedup.c
+++ b/block/qcow2-dedup.c
@@ -305,12 +305,24 @@ static int qcow2_deduplicate_cluster(BlockDriverState *bs,
 {
     BDRVQcowState *s = bs->opaque;
     uint64_t cluster_index = hash_info->physical_sect / s->cluster_sectors;
-    int ret = 0;
+    int refcount, ret = 0;
 
     /* Increment the refcount of the cluster */
-    ret = qcow2_update_cluster_refcount(bs,
-                                        cluster_index,
-                                        1);
+    refcount = qcow2_update_cluster_refcount(bs,
+                                             cluster_index,
+                                             1);
+
+    if (refcount < 0) {
+        return refcount;
+    }
+
+    /* if we reached half the max refcount delete the QCowHashInfo from the
+     * store so the next time this cluster will be seen it will be handled as
+     * new
+     */
+    if (refcount >= 0xFFFF/2) {
+        ret = qcow2_store_delete(bs, &s->key_value_store, hash_info);
+    }
 
     if (ret < 0) {
         return ret;
-- 
1.7.10.4


Reply via email to