firecracker icon indicating copy to clipboard operation
firecracker copied to clipboard

feat(virtio-block): Add support for VIRTIO_BLK_T_DISCARD request type

Open LDagnachew opened this issue 7 months ago • 1 comments

(Reupload) Opening this as a Draft PR, as I am still working on fully integrating unmap/fstrim/discard. Right now I'm currently working on the functionality.

Changes

Expose discard feature bit

  • Added VIRTIO_BLK_F_DISCARD to the device’s advertised avail_features so guests can negotiate discard support

Extend RequestType enum

  • Introduced a new Discard variant and mapped VIRTIO_BLK_T_DISCARDRequestType::Discard in the request conversion

Update request parsing (Request::parse) in request.rs

  • Allowed Discard (alongside Flush) to skip the data descriptor
  • Enforced sector‑aligned length and bounds checks for Discard requests

Implement handle_discard backend

  • Created handle_discard(offset, len) to call fallocate() on the host file descriptor

Reason

Attempting to resolve Issue #2708

Next Steps

  • Checking for VIRTIO_BLK_F_DISCARD support (need suggestions for this, not sure of an efficient way to check for Discard Support within a given VirtIO block).
  • Writing Unit & Integration Tests.

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

  • [x] I have read and understand CONTRIBUTING.md.
  • [ ] 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.

LDagnachew avatar Apr 24 '25 17:04 LDagnachew