[Devel] [PATCH hci-8.1 v5 3/3] dm-qcow2: truncate unused tail of image on suspend
no-reply at sashiko.virtuozzo.com
no-reply at sashiko.virtuozzo.com
Sat Oct 10 15:53:19 MSK 2026
> On postsuspend we truncate the image file only down to
> file_preallocated_area_start, i.e. we drop preallocations only.
> Clusters at the end of the file freed by discard (refcount dropped
> to zero) are never given back, so the file size never shrinks.
>
> Add qcow2_calc_used_end(), which scans refcount blocks backward from
> file_preallocated_area_start and returns the end of the last cluster
> with non-zero refcount. Refcount ranges with no allocated refblock
> are skipped at once. Metadata pages are taken from md cache or read
> synchronously. This is called on suspended device after md writeback,
> so R1 and R2 can't change under us.
>
> Truncate the file to the 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.
>
> Close and reload to RO go through postsuspend too: on remove,
> __dm_destroy() suspends the live table if it isn't suspended yet,
> and on table swap do_resume() suspends the old (RW) table before
> dm_swap_table(). So the tail is given back in these cases as well.
>
> https://virtuozzo.atlassian.net/browse/VSTOR-148171
> Feature: dm-qcow2: block device over QCOW2 files driver
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov at virtuozzo.com>
Sashiko has reviewed this patch and found no issues. It looks great!
--
Sashiko AI review · https://sashiko.vzint.dev/#/patchset/20261010124642.927044-1-alexander.ivanov@virtuozzo.com?part=3
More information about the Devel
mailing list