From: Max Reitz Date: Wed, 3 May 2017 23:11:19 +0000 (+0200) Subject: qcow2: Discard preallocated zero clusters X-Git-Tag: v2.10.0-rc0~200^2~11 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=293073a56c6c921c9902da17711914a0042f29ba;p=thirdparty%2Fqemu.git qcow2: Discard preallocated zero clusters In discard_single_l2(), we completely discard normal clusters instead of simply turning them into preallocated zero clusters. That means we should probably do the same with such preallocated zero clusters: Discard them instead of keeping them allocated. Reported-by: Eric Blake Signed-off-by: Max Reitz Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index fb91fd8979e..31077d81021 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -1511,7 +1511,8 @@ static int discard_single_l2(BlockDriverState *bs, uint64_t offset, break; case QCOW2_CLUSTER_ZERO: - if (!full_discard) { + /* Preallocated zero clusters should be discarded in any case */ + if (!full_discard && (old_l2_entry & L2E_OFFSET_MASK) == 0) { continue; } break;