Skip to content

virtio-blk: add async discard support#5935

Open
bacarrdy wants to merge 5 commits into
firecracker-microvm:mainfrom
bacarrdy:virtio-blk-discard-async-followup
Open

virtio-blk: add async discard support#5935
bacarrdy wants to merge 5 commits into
firecracker-microvm:mainfrom
bacarrdy:virtio-blk-discard-async-followup

Conversation

@bacarrdy

@bacarrdy bacarrdy commented Jun 4, 2026

Copy link
Copy Markdown

Changes

  • Build on top of virtio-blk: add discard request support #5908 to add discard=true support for writable Async IO engine virtio-block drives.
  • Use IORING_OP_FALLOCATE for regular backing files.
  • Use BLOCK_URING_CMD_DISCARD for block-device backing stores on host kernels that support it.
  • Reject async discard for block-device backends on host kernels older than Linux 6.12.
  • Include the required io_uring opcode probing so unsupported hosts fail during configuration instead of later at request execution time.
  • Keep discard gated by negotiated VIRTIO_BLK_F_DISCARD, so guests that did not negotiate the feature receive an unsupported status.
  • Update API schema, block discard docs, block IO engine docs, changelog, and tests for the async support matrix.

This PR intentionally depends on #5908. If #5908 is merged first, this branch should be rebased so the final diff only contains the async follow-up.

Reason

#5908 keeps the initial discard implementation focused on the Sync IO engine. This follow-up adds the io_uring path so deployments using the Async IO engine can still expose guest fstrim/discard where the host kernel and backing storage support it.

Validation

  • Ran tools/devtool checkstyle locally after the latest update: passed (20 passed, 4 skipped).
  • Earlier local validation covered tools/devtool checkbuild --all while resolving the libc::Ioctl review thread.
  • Added/kept unit and integration coverage for discard feature negotiation, unsupported requests, API configuration, and functional discard behavior inherited from virtio-blk: add discard request support #5908.

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.

Copilot AI review requested due to automatic review settings June 4, 2026 19:32

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds opt-in virtio-blk discard/TRIM support, wiring it through drive configuration into virtio request handling and the file I/O backends (sync + io_uring), plus updating docs and seccomp to permit the needed syscalls.

Changes:

  • Add discard to drive/block configs and propagate it through virtio-blk feature negotiation and persistence.
  • Implement discard request parsing/execution and backend support (sync via BLKDISCARD/fallocate, async via io_uring FALLOCATE or URING_CMD).
  • Extend io_uring opcode support/probing and update docs + seccomp filters accordingly.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/vmm/tests/integration_tests.rs Update test drive configs to include new discard field.
src/vmm/src/vmm_config/drive.rs Add discard to BlockDeviceConfig and update related tests/helpers.
src/vmm/src/resources.rs Update resource tests to include new discard field.
src/vmm/src/io_uring/operation/mod.rs Add io_uring opcodes + SQE layout support for fallocate / uring cmd.
src/vmm/src/io_uring/mod.rs Allow callers to specify required opcodes when creating rings.
src/vmm/src/devices/virtio/block/virtio/test_utils.rs Extend default block test config with discard.
src/vmm/src/devices/virtio/block/virtio/request.rs Add VIRTIO_BLK_T_DISCARD parsing/validation + execution path.
src/vmm/src/devices/virtio/block/virtio/persist.rs Persist/restore discard feature bit and config space changes.
src/vmm/src/devices/virtio/block/virtio/mod.rs Define discard-related limits/alignment constants.
src/vmm/src/devices/virtio/block/virtio/io/sync_io.rs Implement sync discard via BLKDISCARD or fallocate(PUNCH_HOLE).
src/vmm/src/devices/virtio/block/virtio/io/mod.rs Add discard API to FileEngine and plumb discard flag into async engine creation.
src/vmm/src/devices/virtio/block/virtio/io/async_io.rs Add async discard selection and submission via io_uring (fallocate / uring cmd).
src/vmm/src/devices/virtio/block/virtio/device.rs Add discard to virtio-blk config, feature bits, config space, and tests.
src/vmm/src/devices/virtio/block/vhost_user/device.rs Ensure vhost-user block configs reject/omit discard.
src/vmm/src/device_manager/mod.rs Update device manager tests for new discard field.
src/vmm/src/builder.rs Update builder tests for new discard field.
src/firecracker/swagger/firecracker.yaml Document new discard API field for drives.
resources/seccomp/x86_64-unknown-linux-musl.json Allow fallocate and ioctl(BLKDISCARD) for discard support.
resources/seccomp/aarch64-unknown-linux-musl.json Allow fallocate and ioctl(BLKDISCARD) for discard support.
docs/api_requests/block-io-engine.md Document async discard behavior/requirements.
docs/api_requests/block-discard.md Add API usage documentation for discard.
CHANGELOG.md Note new discard feature in changelog.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/vmm/src/devices/virtio/block/virtio/io/async_io.rs Outdated
Comment thread src/vmm/src/devices/virtio/block/virtio/request.rs Outdated
Comment thread src/vmm/src/devices/virtio/block/virtio/io/sync_io.rs
Comment thread src/firecracker/swagger/firecracker.yaml
Comment thread docs/api_requests/block-discard.md Outdated
@bacarrdy bacarrdy force-pushed the virtio-blk-discard-async-followup branch 3 times, most recently from cd7b1df to 67e39aa Compare June 4, 2026 19:56
bacarrdy added 4 commits June 5, 2026 08:45
Extend the virtio-blk config space through the discard limit fields so
the device can report discard capability details when the feature is
enabled.

Signed-off-by: Jonas Savulionis <jonas@esnet.lt>
Add an opt-in discard drive flag and parse a single validated discard
range without re-reading guest memory after validation.

Execute discard with hole punching for regular files and BLKDISCARD for
block devices on the sync engine. Reject discard with the async engine
until an async implementation can be added.

Signed-off-by: Jonas Savulionis <jonas@esnet.lt>
Allow fallocate hole punching and BLKDISCARD ioctl calls needed by the
sync virtio-blk discard implementation.

Signed-off-by: Jonas Savulionis <jonas@esnet.lt>
Add async discard execution for virtio-blk drives when the discard
feature is enabled.

Regular file backends use IORING_OP_FALLOCATE with hole punching.
Block-device backends use BLOCK_URING_CMD_DISCARD through
IORING_OP_URING_CMD when the host kernel supports it.

Require async fsync support during io_uring initialization, document the
async discard support matrix, and return VIRTIO_BLK_S_UNSUPP for guest
DISCARD requests when the discard feature was not negotiated.

Signed-off-by: Jonas Savulionis <jonas@esnet.lt>
@bacarrdy bacarrdy force-pushed the virtio-blk-discard-async-followup branch 3 times, most recently from d373e02 to 3007b1e Compare June 7, 2026 19:42
Store the validated discard byte offset and length in the existing
Request fields instead of carrying a separate discard range.

Signed-off-by: Jonas Savulionis <jonas@esnet.lt>
@bacarrdy bacarrdy force-pushed the virtio-blk-discard-async-followup branch from 3007b1e to 465d79d Compare June 12, 2026 16:50
@bacarrdy bacarrdy changed the title Virtio blk discard async followup virtio-blk: add async discard support Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants