firecracker
firecracker copied to clipboard
feat(virtio-block): Add support for VIRTIO_BLK_T_DISCARD request type
(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_DISCARDto 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_DISCARD→RequestType::Discardin 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 callfallocate()on the host file descriptor
Reason
Attempting to resolve Issue #2708
Next Steps
- Checking for
VIRTIO_BLK_F_DISCARDsupport (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 checkstyleto 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.