Skip to contentSkip to conversation

qcow2: Free preallocated zero clusters

PATCH Applied Max Reitz 2 participants 3 messages Oct 9, 2013 Block layer

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

PATCH 1/1 qcow2: Free preallocated zero clusters

In qcow2_free_any_clusters, preallocated zero clusters should be freed just as normal clusters are.

---
 block/qcow2-refcount.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
block/qcow2-refcount.c +5 -3
index 2d67885..9dd5e44 100644
@@ -796,11 +796,13 @@ void qcow2_free_any_clusters(BlockDriverState *bs, uint64_t l2_entry,
         }
         break;
     case QCOW2_CLUSTER_NORMAL:
-        qcow2_free_clusters(bs, l2_entry & L2E_OFFSET_MASK,
-                            nb_clusters << s->cluster_bits, type);
+    case QCOW2_CLUSTER_ZERO:
+        if (l2_entry & L2E_OFFSET_MASK) {
+            qcow2_free_clusters(bs, l2_entry & L2E_OFFSET_MASK,
+                                nb_clusters << s->cluster_bits, type);
+        }
         break;
     case QCOW2_CLUSTER_UNALLOCATED:
-    case QCOW2_CLUSTER_ZERO:
         break;
     default:
         abort();
Signature · 1 line
1.8.3.1
Applied
#1 lore raw

Am 09.10.2013 um 10:44 hat Max Reitz geschrieben:

Quoted 4 lines

In qcow2_free_any_clusters, preallocated zero clusters should be freed just as normal clusters are.

Thanks, applied to the block branch.

Do you have a test case that would cause a leak previously?

Kevin

author
#2 lore raw
Quoted 10 lines · Kevin Wolf

Am 09.10.2013 um 10:44 hat Max Reitz geschrieben:

Quoted 4 lines

In qcow2_free_any_clusters, preallocated zero clusters should be freed just as normal clusters are.

Thanks, applied to the block branch.

Do you have a test case that would cause a leak previously?

Kevin

Oh, right.

qemu-img create -f qcow2 f.qcow2 64M
qemu-io -c 'write 0 64M' -c 'write -z 0 64M' -c 'discard 0 64M' f.qcow2 qemu-img check f.qcow2

seems enough, I'll send that test case as a follow-up.

Max