SIGN IN SIGN UP

virtio-blk: add discard request support

Add opt-in virtio-blk discard support for sync file-backed drives.
The device advertises VIRTIO_BLK_F_DISCARD only when enabled,
validates guest discard ranges once during request parsing, and
executes discard through BLKDISCARD for block devices or fallocate
hole punching for regular files.

Derive discard alignment from the logical block size advertised to the
guest and persist that alignment across snapshot restore. Disk image
updates retain the original value.

Reject discard for read-only drives and the async IO engine for now,
and return UNSUPP if a guest submits discard without negotiating the
feature.

[jackabt@amazon.com: rebased onto main and updated the config round-trip
expectations for the normalised discard field in test_block_config,
resources, and the two device manager persistence tests]

Signed-off-by: Jonas Savulionis <jonas@esnet.lt>
Signed-off-by: Rekas <aure369@gmail.com>
Signed-off-by: Jack Thomson <jackabt@amazon.com>
Signed-off-by: Pierre Bertholom <pbertho@amazon.com>
R
Rekas committed
80aa8e23b451cb2e8d1924726f7bdbe0b08ae237
Parent: 0867682
Committed by Pierre Bertholom <149312528+PierreBertholom@users.noreply.github.com> on 9/3/2026, 2:31:37 PM