Patchwork [RFC,V8,17/24] qcow2: Drop hash for a given cluster when dedup makes refcount > 2^16/2.

login
register
mail settings
Submitter Benoît Canet
Date June 20, 2013, 2:26 p.m.
Message ID <1371738392-9594-18-git-send-email-benoit@irqsave.net>
Download mbox | patch
Permalink /patch/252959/
State New
Headers show

Comments

Benoît Canet - June 20, 2013, 2:26 p.m.
A new physical cluster with the same hash value will be used for further
occurrence of this hash.

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

Patch

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;