-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Block refactor #4285
Block refactor #4285
Conversation
57509e6
to
fde8989
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #4285 +/- ##
==========================================
- Coverage 81.52% 81.39% -0.13%
==========================================
Files 241 243 +2
Lines 29296 29430 +134
==========================================
+ Hits 23883 23955 +72
- Misses 5413 5475 +62
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
3b8429f
to
9d6e94c
Compare
f992f1e
to
6af3360
Compare
684930f
to
2803a6d
Compare
2803a6d
to
c7d3961
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.
Left a second round of comments. In general, I think I would prefer the flow of the commits to be the following:
- Create the module structure under
vmm::devices::virtio::block
as you do now. - Create the new
Block
type that encapsulates the Virtio and Vhost devices- Maybe you need to mark this as
#[allow(unused)]
- Maybe you need to mark this as
- Switch everything to use the new type.
My main motivation for this flow is that it makes reviewing a lot easier IMHO and it makes easier the process of following the git history of the code base as well.
edit: If I am the only one that thinks this is important I will not block the PR. So, I'd like the feedback of @kalyazin on this as well.
946d97c
to
a3b1b8c
Compare
Move `virtio_block` and `vhost_user_block` under `devices/block`. Move `block_common.rs` to `block/mod.rs`. Signed-off-by: Egor Lazarchuk <[email protected]>
Temporary remove ability to create vhost-user-block devices. This is done to simplify transition to the single `block` type with different backends. vhost-user-block backends will be enabled again in later commits. Signed-off-by: Egor Lazarchuk <[email protected]>
Temporary remove vhost-user-block from the device_manager. This is done as a part of a transition to the single `block` device. Signed-off-by: Egor Lazarchuk <[email protected]>
This is done as a part of a transition to the single `block` type. This will be enabled again later. Signed-off-by: Egor Lazarchuk <[email protected]>
Create files for future `Block` related types to live in. Signed-off-by: Egor Lazarchuk <[email protected]>
Replaced `Virtio` types with aliases to make it easier to transition to singe `Block` type. Signed-off-by: Egor Lazarchuk <[email protected]>
New `Block` enum wraps around `VirtioBlock`. This helps to understand what methods/traits are needed to be implemented for `Block`. Signed-off-by: Egor Lazarchuk <[email protected]>
Replace type aliases for `BlockState` and `BlockConstructorArgs` with actual types. For now `BlockState` enum only contains `Virtio` variant but will have `Vhost` variant added in later commits. Because `VirtioBlockConstructorArgs` and `VhostUserBlockConstructorArgs` are same, `BlockConstructorArgs` is replacing them both. Signed-off-by: Egor Lazarchuk <[email protected]>
Add new `BlockError` error enum with `VirtioBackend` variant for virtio-block errors. Signed-off-by: Egor Lazarchuk <[email protected]>
Now `Block` is constructed from `BlockDeviceConfig`. This simplifies the creation of new block devices as both variants of block device are created from same config type. Signed-off-by: Egor Lazarchuk <[email protected]>
Add back ability to create vhost-user-block devices. Signed-off-by: Egor Lazarchuk <[email protected]>
Re enabled vhost-user-block `config_update` method. Signed-off-by: Egor Lazarchuk <[email protected]>
Vhost-user-block devices still do not support snapshots, so the functionality is disabled for now. Signed-off-by: Egor Lazarchuk <[email protected]>
Error formatting has been updated to use `Display`. Signed-off-by: Egor Lazarchuk <[email protected]>
a3b1b8c
to
963e2c5
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.
Ok LGTM now, so I'm fine to approve it. I will just try to clarify my previous comment regarding the PR structure in terms of commits, mainly for future reference:
The way the PR was structured made it difficult for me to review, because:
- It was difficult to follow the purpose of the changes.
- There was a big re-direction in the PR with removing vhost-user-block and re-introducing it.
What the PR wanted to do (and did in the end) was to introduce a new type for block devices which encapsulates the two variants we support today (virtio and vhost-user). So, in my eyes it would be easier to:
- create the new type without breaking the rest of the code. To ease review this could be done in 2 steps:
- make the necessary changes in the file structure, moving existing types around as a preparatory step. Personally, I would group changes in fewer commits. I don't mind big commits as long as they do the same thing and having everything in one commit makes it easier to follow the purpose of a change.
- add the new type as effectively dead code.
- Plug the new type in the rest of the system.
I know that adding dead-code is counter intuitive and that's probably why my first thought would have been to do the change the way Egor did it here, as well. However, I think that doing it like that helps reviewing and, in reality, it doesn't have any issues. If the dead code of the first part is wrong, we will catch it in the second part where we plug in everything, so we can go back and amend the first part.
In any case, thanks a lot for the PR. I think this is a great improvement in our code structure and "cleaniness".
As I mentioned earlier I just wanted to write down my thoughts so we have data points in the future when we discuss PRs and git organization.
Changes
Refactoring of the block devices architecture. Return of a single
Block
type which now will have virtio or vhost-userimplementation inside itself.
Reason
Lowers code complexity.
Currently Firecracker is designed with only
virtio
devices types in mind (i.e. net, block, vsock...). When Firecracker introduced second 'type' of block device (vhost-user-block
) it created inconsistency and boilerplate code to distinguish between 2 block types. In order to reduce this newly introduced complexity we move back to a singleBlock
type which plays nice with the rest of the system.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
CHANGELOG.md
.TODO
s link to an issue.rust-vmm
.