mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
The write zeroes segment descriptor (struct virtio_blk_discard_write_zeroes, virtio spec v1.2 section 5.2.6) includes a flags field with an unmap bit. Per section 5.2.6.2, if unmap is set, the device MAY deallocate the specified range of sectors in the device backend storage, as if the discard command had been sent. Read the flags field and when the unmap bit is set, use punch_hole to deallocate the range. Otherwise continue using write_zeroes via ZERO_RANGE which preserves allocation. This allows the guest to reclaim host disk space through write zeroes requests on thin provisioned images. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>