[Devel] [PATCH hci-8.2 v2] dm-qcow2: fix stale host data showing in a zero cluster after a write
Konstantin Khorenko
khorenko at virtuozzo.com
Tue Nov 24 16:16:29 MSK 2026
I won't apply this version, please send v3 with the changes below.
On Tue, 24 Nov 2026 13:46:13 +0100, Denis V. Lunev wrote:
> dm-qcow2: fix stale host data showing in a zero cluster after a write
- Keep the unallocated subcluster case, but do not pay for it on
clusters dm-qcow2 allocated itself: their unused subclusters are
zero on disk already.
- Commit message: split the last sentence of the first paragraph, and
the subject should cover unallocated subclusters too.
All four v1 asks are done, and the code is correct. The problem is the
price of my first v1 ask as it is done here.
> + if (!maybe_mapped_in_lower_delta(qcow2, qio))
> + mask |= ~((u32)map->ext_l2 | zeroes);
prepare_l1l2_allocation() sets the alloc bits of the written
subclusters only, so every cluster dm-qcow2 allocates has unallocated
subclusters, and without backing data each of them now takes this
path. ploop creates images with 1M clusters and extended L2 entries,
so this is the default CT disk without snapshots. A 4K write into a
fresh subcluster used to set the bit and go out at once, with the L2
writeback in parallel. Now it waits for a dirty L2, locks the L2 entry
so all I/O to the 1M cluster waits, writes 32K of which 28K are
zeroes, and completes only after its own L2 writeback. That is up to
31 times per cluster, and host holes become allocated blocks.
Those zeroes buy nothing: prepare_unused_cluster() punches a reused
area below file_preallocated_area_start and the area past it is fresh,
and our own discard punches too. Stale data can come only from
clusters qemu wrote. One way: when dm-qcow2 allocates a cluster that
has no backing data, set all its alloc bits at once (the check must
look at the cluster, not at the write start); then only qemu-written
clusters take the COW. If you see a cheaper way, fine too, but please
show fio numbers for 4K random and sequential writes on a fresh 1M
extended L2 image without backing, before and after.
> unit reads back the stale data instead of zeroes:
> prepare_l1l2_allocation() reuses the host cluster as it is, and the
> backing file COW of a write with one border in an unallocated
> subcluster and the other in a zero subcluster copies only the
> unallocated one.
This sentence runs eight lines and joins two mechanisms with a colon;
please split it. The subject still says "zero cluster" while the patch
now fixes unallocated subclusters as well.
--
Konstantin Khorenko,
Virtuozzo Linux Kernel Team
More information about the Devel
mailing list