-
Notifications
You must be signed in to change notification settings - Fork 2.1k
refactor: Simplify VMM code to perform API action on device #5387
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: Simplify VMM code to perform API action on device #5387
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #5387 +/- ##
==========================================
+ Coverage 82.25% 82.41% +0.15%
==========================================
Files 266 266
Lines 30619 30571 -48
==========================================
+ Hits 25185 25194 +9
+ Misses 5434 5377 -57
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
10458b5
to
5142dd1
Compare
Currently, the device ids (TYPE_*) are hardcoded in various places. With this change, they are generated from linux headers. Signed-off-by: Riccardo Mancini <[email protected]>
Make the with_virtio_device_with_id function more generic and introduce its variant with error handling try_with_virtio_device_with_id. Then use these new functions in vmm.rs whenever we need to perform an action on a device. To simplify the code, I also moved some balloon device error handling back to the balloon device code and refactored it a little bit. Signed-off-by: Riccardo Mancini <[email protected]>
Remove some error variants that were not used in the code. Signed-off-by: Riccardo Mancini <[email protected]>
The balloon device always returns "Amount of pages requested cannot fit in u32" even if it fails due to the guest memory check. Reword the error to make it more clear. Signed-off-by: Riccardo Mancini <[email protected]>
As the caller of latest_stats() always clones the object, just derive Copy on it and return the copy rather than a reference. Signed-off-by: Riccardo Mancini <[email protected]>
By defining an associated function to the trait, we can simplify the logic to execute code on a specific device from the VMM, while also statically guaranteeing we are passing the right constant. The downside is that we need both a sized and a dyn implementation for the function. To ensure devices implement them correctly, a utility macro is provided. We cannot do it as a default trait impl as the const_ variant is only defined on Sized. Signed-off-by: Riccardo Mancini <[email protected]>
9c1c89a
to
f272086
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Cool stuff
Changes
becomes
by extending the existing
with_virtio_device_with_id
implementation (now all accesses are using this pattern).Reason
I will be adding a bunch of these
with_virtio_device_with_id
for thevirtio-mem
device and this makes it simpler rather than writing the old longif
branches.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
tools/devtool checkbuild --all
to verify that the PR passesbuild checks on all supported architectures.
tools/devtool checkstyle
to verify that the PR passes theautomated style checks.
how they are solving the problem in a clear and encompassing way.
in the PR.
CHANGELOG.md
.Runbook for Firecracker API changes.
integration tests.
TODO
.rust-vmm
.