Skip to content
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

[RFC] Block device proposal #32

Closed
wants to merge 4 commits into from

Conversation

alexandruag
Copy link
Collaborator

This PR proposes a block device implementation based on abstraction from upstream (merged or under review) and some local logic as well (parts of which can become reusable at some point themselves). The block device is not properly tied to the command line yet; for now it's just hardcoded in the Vmm, which tries to open a file named "disk.ext4" from the current working directory when being run. There are some comments in the last commit regarding the order in which we create the irqchip relative to the devices; would be great to see what kind of restriction we're dealing with there (if any).

The request parsing and execution part is taken from Firecracker, until we can reuse something from rust-vmm. The next steps here are to see what kind of user interface changes we want to add to the application for block devices, and to start creating more tests if things look reasonable.

Use [patch] sections in the workspace Cargo.toml file to redirect
dependencies to custom repos/branches that are not upstream yet. Also
switched to abort on panic for both debug and release builds. Enabled
lto and codegen-unit = 1 for release builds (and they take longer now).

Signed-off-by: Alexandru Agache <[email protected]>
The virtio device implementations are going to be added to a local
devices crate, so renaming the module with the same name within vmm
to serial (because there's only a serial device there for the time
being). Going foward, we should move the serial console to the devices
crate as well.

Signed-off-by: Alexandru Agache <[email protected]>
Signed-off-by: Alexandru Agache <[email protected]>
Applied some changes to the vmm to support the creation of block
devices. There's not cmdline support to configure them yet so
there's one hardcoded block device for demo purposes for now. It
will always attempt to open a file named 'disk.ext4` from the
current working directory when running the VMM.

Signed-off-by: Alexandru Agache <[email protected]>

let irqfd = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFd)?;
args.vm_fd
.register_irqfd(&irqfd, args.mmio_cfg.gsi)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the spirit of #14 I'd like to see this done elsewhere (run()?). The empty Block can hang around inert without a VmFd until it really needs to become a live device.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really like to try out this approach because it helps delegate all the setup logic to the device, as long as the necessary "resources" (such as the VmFd for this particular implementation) are provided by the environment.

Unsupported(u32),
}

impl From<u32> for RequestType {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd make more sense to couple this RFC with the other block device-related RFC rust-vmm/vm-virtio#29 and use the abstractions from there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be a good moment to do this, indeed. Do we plan to do this in the same PR or another one?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done this (by pulling the changes from your PR in the vm-virtio branch used as a depenency right now) in #41.

Copy link
Collaborator

@lauralt lauralt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

High level looks good, left a few comments for now.

// will be ignored.
let num_sectors = file_size >> SECTOR_SHIFT;
// This has to be in little endian btw.
Ok(num_sectors.to_be_bytes().to_vec())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to_le_bytes()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely! my bad

src/devices/src/virtio/block/mod.rs Show resolved Hide resolved
}

// Arguments required when building a block device.
// TODO: Add read-only operation support as a quick next step.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future we might want to have some sort of array for the supported operations since there are a few more other than read-only.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense; we should def keep it in mind when adding all that stuff.

Unsupported(u32),
}

impl From<u32> for RequestType {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be a good moment to do this, indeed. Do we plan to do this in the same PR or another one?

match Request::parse(&mut chain) {
Ok(request) => {
let len;
// TODO: The executor could actually write the status itself, right?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should, still trying to figure out how to do this in a nice way :D.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's cool; we can def live with this as is for the time being.

@andreeaflorescu andreeaflorescu mentioned this pull request Nov 24, 2020
2 tasks
Copy link
Collaborator Author

@alexandruag alexandruag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comments! I've added answers here, and addressed them as part of #41 (which is meant to supersede this RFC PR). We can close this after that gets resolved/merged.


let irqfd = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFd)?;
args.vm_fd
.register_irqfd(&irqfd, args.mmio_cfg.gsi)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would really like to try out this approach because it helps delegate all the setup logic to the device, as long as the necessary "resources" (such as the VmFd for this particular implementation) are provided by the environment.

// will be ignored.
let num_sectors = file_size >> SECTOR_SHIFT;
// This has to be in little endian btw.
Ok(num_sectors.to_be_bytes().to_vec())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely! my bad

}

// Arguments required when building a block device.
// TODO: Add read-only operation support as a quick next step.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense; we should def keep it in mind when adding all that stuff.

src/devices/src/virtio/block/mod.rs Show resolved Hide resolved
Unsupported(u32),
}

impl From<u32> for RequestType {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done this (by pulling the changes from your PR in the vm-virtio branch used as a depenency right now) in #41.

match Request::parse(&mut chain) {
Ok(request) => {
let len;
// TODO: The executor could actually write the status itself, right?
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's cool; we can def live with this as is for the time being.

src/vmm/src/lib.rs Show resolved Hide resolved
@alexandruag
Copy link
Collaborator Author

Closing as the discussion moved over to #41.

@alexandruag alexandruag closed this Dec 2, 2020
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.

4 participants