[Devel] [PATCH hci-8.1] drivers/md/dm-qcow2: truncate unused tail of image on suspend

Konstantin Khorenko khorenko at virtuozzo.com
Tue Oct 6 20:39:56 MSK 2026


On 10/6/26 17:56, Denis V. Lunev wrote:
> On 10/6/26 17:52, Konstantin Khorenko wrote:
>>> drivers/md/dm-qcow2: truncate unused tail of image on suspend
>> ...
>>> Truncate the file to min(file_preallocated_area_start, used end).
>>> Skip the scan if md writeback failed, as refcounts on disk are stale
>>> then, and fall back to the old behaviour on scan error.
>> There is one more case of stale refcounts on disk: an image with
>> INCOMPATIBLE_FEATURES_DIRTY_BIT set. qcow2_check_convert_hdr() accepts it
>> (the check is commented out), and with qemu lazy refcounts that bit means
>> refcounts were not written for the last allocations, so they are too low.
>>
>> Today such an image loses data only when the allocator hands out a
>> cluster whose refcount is zero but which L2 still references. After this
>> patch the first suspend truncates live clusters at the tail without a
>> single write to the device. The image is already invalid per spec, so
>> this is not a regression in the strict sense, but either the commit
>> message should say that a dirty image is not supported, or the dirty-bit
>> check in qcow2_check_convert_hdr() should come back.
> 
> Image should go clean into the kernel on first pass.

Well, i agree here, so please disregard my comment about dirty bit handling.

On the other hand i would like to note that the current design does not allow kernel to distinguish 2 situations:

1. the image is CLEAN (it might be checked / fixed after the crash, does not matter),
ploop utility marks it as DIRTY when sending to the kernel - intended behavior.

2. the image had DIRTY bit because the Node crashed, so the image was NOT fixed, but
someone issued "dmsetup create" manually, not via ploop util.




More information about the Devel mailing list