Skip to content

virtio-blk: add discard request support - #6142

Open
JackThomson2 wants to merge 4 commits into
firecracker-microvm:mainfrom
JackThomson2:pr-5908-rebase
Open

virtio-blk: add discard request support#6142
JackThomson2 wants to merge 4 commits into
firecracker-microvm:mainfrom
JackThomson2:pr-5908-rebase

Conversation

@JackThomson2

Copy link
Copy Markdown
Contributor

Changes

Update of the PR: #5908

To fix a few warning and update against main

Also fixed a bug in which the config space was no longer calling .to_le()

Reason

...

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache 2.0 license. For more information on following Developer
Certificate of Origin and signing off your commits, please check
CONTRIBUTING.md.

PR Checklist

  • I have read and understand CONTRIBUTING.md.
  • I have run tools/devtool checkbuild --all to verify that the PR passes
    build checks on all supported architectures.
  • I have run tools/devtool checkstyle to verify that the PR passes the
    automated style checks.
  • I have described what is done in these changes, why they are needed, and
    how they are solving the problem in a clear and encompassing way.
  • I have updated any relevant documentation (both in code and in the docs)
    in the PR.
  • I have mentioned all user-facing changes in CHANGELOG.md.
  • If a specific issue led to this PR, this PR closes the issue.
  • When making API changes, I have followed the
    Runbook for Firecracker API changes.
  • I have tested all new and changed functionalities in unit tests and/or
    integration tests.
  • I have linked an issue to every new TODO.

  • This functionality cannot be added in rust-vmm.

Extend the virtio-blk config space through the discard limit fields so
the device can report discard capability details when the feature is
enabled.

[jackabt@amazon.com: rebased onto main and reconciled with the
read-only config space test]

Signed-off-by: Jonas Savulionis <jonas@esnet.lt>
Signed-off-by: Jack Thomson <jackabt@amazon.com>
@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.14815% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.91%. Comparing base (f90fa86) to head (09dd359).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/vmm/src/devices/virtio/block/virtio/io/mod.rs 0.00% 19 Missing ⚠️
.../vmm/src/devices/virtio/block/virtio/io/sync_io.rs 58.82% 14 Missing ⚠️
src/vmm/src/devices/virtio/block/virtio/request.rs 88.46% 6 Missing ⚠️
...vmm/src/devices/virtio/block/virtio/io/async_io.rs 0.00% 3 Missing ⚠️
.../vmm/src/devices/virtio/block/vhost_user/device.rs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6142      +/-   ##
==========================================
- Coverage   82.98%   82.91%   -0.07%     
==========================================
  Files         277      277              
  Lines       30885    31010     +125     
==========================================
+ Hits        25630    25713      +83     
- Misses       5255     5297      +42     
Flag Coverage Δ
5.10-m5n.metal 83.17% <68.14%> (-0.09%) ⬇️
5.10-m6a.metal 82.53% <68.14%> (-0.09%) ⬇️
5.10-m6g.metal 79.98% <68.14%> (-0.08%) ⬇️
5.10-m6i.metal 83.17% <68.14%> (-0.09%) ⬇️
5.10-m7a.metal-48xl 82.52% <68.14%> (-0.09%) ⬇️
5.10-m7g.metal 79.99% <68.14%> (-0.07%) ⬇️
5.10-m7i.metal-24xl 83.14% <68.14%> (-0.09%) ⬇️
5.10-m7i.metal-48xl 83.14% <68.14%> (-0.09%) ⬇️
5.10-m8g.metal-24xl 79.98% <68.14%> (-0.08%) ⬇️
5.10-m8g.metal-48xl 79.99% <68.14%> (-0.07%) ⬇️
5.10-m8i.metal-48xl 83.15% <68.14%> (-0.09%) ⬇️
5.10-m8i.metal-96xl 83.14% <68.14%> (-0.08%) ⬇️
6.18-m5n.metal 83.20% <68.14%> (-0.08%) ⬇️
6.18-m6a.metal 82.56% <68.14%> (-0.08%) ⬇️
6.18-m6g.metal 79.99% <68.14%> (-0.07%) ⬇️
6.18-m6i.metal 83.19% <68.14%> (-0.09%) ⬇️
6.18-m7a.metal-48xl 82.55% <68.14%> (-0.09%) ⬇️
6.18-m7g.metal 79.99% <68.14%> (-0.07%) ⬇️
6.18-m7i.metal-24xl 83.20% <68.14%> (-0.09%) ⬇️
6.18-m7i.metal-48xl 83.20% <68.14%> (-0.09%) ⬇️
6.18-m8g.metal-24xl 79.98% <68.14%> (-0.08%) ⬇️
6.18-m8g.metal-48xl 79.98% <68.14%> (-0.08%) ⬇️
6.18-m8i.metal-48xl 83.21% <68.14%> (-0.09%) ⬇️
6.18-m8i.metal-96xl 83.21% <68.14%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

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, updated the config round-trip
expectations for the normalised discard field in test_block_config,
resources, and the two device manager persistence tests, and moved the
changelog entry to the unreleased section]

Signed-off-by: Jonas Savulionis <jonas@esnet.lt>
Signed-off-by: Rekas <aure369@gmail.com>
Signed-off-by: Jack Thomson <jackabt@amazon.com>
Allow the sync virtio-blk discard path to punch holes in regular
files and issue BLKDISCARD for block-device backed drives.

[jackabt@amazon.com: rebased onto main]

Signed-off-by: Jonas Savulionis <jonas@esnet.lt>
Signed-off-by: Rekas <aure369@gmail.com>
Signed-off-by: Jack Thomson <jackabt@amazon.com>
Cover the discard drive API by validating successful configuration,
guest-visible discard granularity, and rejection of unsupported
read-only or async combinations.

Add a guest functional test that writes data to a file-backed drive,
issues blkdiscard, and verifies host block allocation decreases.

[jackabt@amazon.com: rebased onto main]

Signed-off-by: Jonas Savulionis <jonas@esnet.lt>
Signed-off-by: Rekas <aure369@gmail.com>
Signed-off-by: Jack Thomson <jackabt@amazon.com>
@JackThomson2 JackThomson2 added the Status: Awaiting review Indicates that a pull request is ready to be reviewed label Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Status: Awaiting review Indicates that a pull request is ready to be reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants