Thanks to visit codestin.com
Credit goes to github.com

Skip to content

block: Assume sparse support for block devices - #7757

Merged
rbradford merged 5 commits into
cloud-hypervisor:mainfrom
weltling:sparse-probe
Feb 26, 2026
Merged

rbradford merged 5 commits into
cloud-hypervisor:mainfrom
weltling:sparse-probe

Conversation

@weltling

Copy link
Copy Markdown
Member

Block devices fail the sparse support probe because there is no non-destructive readonly ioctl to query discard/write-zeroes capabilities, so VIRTIO_BLK_F_DISCARD and VIRTIO_BLK_F_WRITE_ZEROES are never negotiated.

Unconditionally assume sparse support for block devices. This matches QEMU, where in hw/block/virtio-blk.c set these features in host_features without probing

  • DEFINE_PROP_BIT64("discard", ..., true)
  • DEFINE_PROP_BIT64("write-zeroes", ..., true)

Runtime failures return VIRTIO_BLK_S_IOERR. Well behaved guests handle this gracefully.

It is unclear whether QEMU has test coverage for topologies like DM snapshot where BLKDISCARD is unsupported.

Integration tests verify discard on a loop device and graceful IOERR handling on a DM snapshot topology. Windows tests disable sparse to avoid viostor.sys BSOD on unsupported discard. This also includes a small refactoring on the integration test side.

Ref: #7750

Extend run_qemu_img() with an optional trailing_args parameter
for arguments that follow the image path, such as the size in
'qemu-img create -f raw <path> 128M'.

Signed-off-by: Anatol Belski <[email protected]>
Verify that a loopback block device advertises
VIRTIO_BLK_F_DISCARD to the guest and that blkdiscard succeeds.

Signed-off-by: Anatol Belski <[email protected]>
Verify that the guest remains stable when BLKDISCARD fails on the
host backend.  DM snapshot targets do not support discard, so the
VMM returns VIRTIO_BLK_S_IOERR.  The test retries blkdiscard several
times, checking guest responsiveness after each attempt, then
confirms normal I/O still works.

The DM topology follows the same pattern used by WindowsDiskConfig.

Signed-off-by: Anatol Belski <[email protected]>
The Windows tests use a DM snapshot device for the OS disk.
DM snapshot targets do not support BLKDISCARD, so the VMM returns
IOERR for every TRIM attempt. viostor.sys may BSOD when the host
returns an error for negotiated discard/write-zeroes operations.

Add a default_disks_sparse_off() helper to GuestCommand and use it
in all Windows tests.

Signed-off-by: Anatol Belski <[email protected]>
There is no non destructive readonly ioctl to query block device
discard or write zeroes capabilities. BLKZEROOUT is guaranteed to
succeed via kernel software fallback. BLKDISCARD may fail at runtime
with EOPNOTSUPP on devices that lack trim support, but the error
propagates to the guest as VIRTIO_BLK_S_IOERR and well behaved
guests handle it gracefully.

Signed-off-by: Anatol Belski <[email protected]>
@xyjixyjixyji

Copy link
Copy Markdown

Thanks for raising this, the code lgtm! do we want write_zeroes in the test cases too? i saw there is only discard

@rbradford
rbradford enabled auto-merge February 25, 2026 23:46
@weltling

weltling commented Feb 26, 2026

Copy link
Copy Markdown
Member Author

I've been double checking - BLKZEROOUT is guaranteed to succeed by the kernel - blkdev_issue_zeroout() in block/blk-lib.c tries hardware write zeroes first, and if that returns EOPNOTSUPP, falls back to blkdev_issue_zero_pages() which explicitly writes zero filled pages.

It can fail with I/O errors, but that's another situation. So there there seems to be no failure edge case to cover for write zeroes. The discard path is the one that can actually fail (EOPNOTSUPP on dm-snapshot, etc.), which is what the tests focus on.

Thanks

@xyjixyjixyji xyjixyjixyji left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the digging!

@rbradford
rbradford added this pull request to the merge queue Feb 26, 2026
Merged via the queue into cloud-hypervisor:main with commit 6404d2d Feb 26, 2026
40 of 46 checks passed
@weltling
weltling deleted the sparse-probe branch February 26, 2026 13:25
@xyjixyjixyji

xyjixyjixyji commented Mar 5, 2026

Copy link
Copy Markdown

Hi, quick question, are we going to have a release with this fix? If so, may i know what is the planned release schedule? Seems i didn't find it in the repo, maybe i missed something

@rbradford

Copy link
Copy Markdown
Member

Hi, quick question, are we going to have a release with this fix? If so, may i know what is the planned release schedule? Seems i didn't find it in the repo, maybe i missed something

This will be included in the next release - v52 - scheduled for April 23rd.

@xyjixyjixyji

Copy link
Copy Markdown

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants