-
Notifications
You must be signed in to change notification settings - Fork 48
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
Add vhost-device-template crate #559
Conversation
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, I left some suggestions but they are trivial
828b9ad
to
4d386a6
Compare
I think I have taken care of most of the comments. Please review again :) |
4d386a6
to
267a288
Compare
I suggest splitting the code in a |
@vireshk nice, thanks for working on this! What about also adding a paragraph in the main readme about the template? |
This can be okay only if we do the same for all existing crates first. Not sure if we really want that. Also I am not sure if it should be moved to lib.rs or something like i2c.rs which we already do. |
I assume that if we move anything to libs it should probably be moved to vm-virtio so that others can also benefit from it? 🤔 Or is there a major benefit from having tests under tests/ instead of under the source tree? |
Why not? By the way that's how I structured |
No reason. I am okay with lib.rs or something like i2c.rs, but I think that should be followed throughout. That's all.
I haven't reviewed it yet :) |
The library crate does give an incorrect picture of the binary crate I feel. The APIs there aren't supposed to be exported but putting them in lib.rs might indicate that. |
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.
Only nit-picking comments that probably applies to some of our existing daemons as well...
Sure. What I meant was that some abstractions may be helpful for non vhost-user virtio implementations. vsock already has some stuff in vm-virtio. So if we find stuff that is useful to share, moving that there maybe makes more sense. But I agree that lib.rs under vhost-device is a bit confusing. And test code probably won't be useful in vm-virtio. |
Hm... But if we publish that to crates.io, that will allow people to use the bits in there, right? Do we want that? It might give the idea that we support using the lib directly. |
It's a really common Rust pattern to allow for integration tests. The fact there is a lib.rs/main.rs split is not visible in crates.io. There's no different treatment on the registry (may change in the future, the plan is to distinguish binary crates. Right now all crates are shown as libraries) And we're not mentioning APIs in READMEs either. See https://crates.io/crates/vhost-device-vsock:
yet, vhost-device-vsock has no lib.rs. If it's too confusing for you, I have no strong feelings about this. It's just good practice to design your API cleanly and then consume it; even if you're the only user of it. |
That is the intention although it seems we are accumulating device logic quite quickly in this repo. That said it's not a major issue if there isn't the demand for the downstream VMM's who want to do in-VMM handling for VirtIO. virtio-sound is probably leading in this complexity considering the interaction between the VirtIO device and the various audio backends. |
267a288
to
12fbf98
Compare
Done. |
Yep. But you need export a lot more stuff as public like that. Since your main.rs is living in a separate crate, the libs needs to export all the functionality as
Full ACK on that. I am not against making stuff reusable. I am just worried that we make vhost-device conflicting with the idea of vm-virtio :) |
And we already kind of do that without a lib.rs, like gpio/i2c.rs, etc.. |
Okay, we are ready for review again.. Updated few more bits. |
"the libs needs to export all the functionality as The point is: a lib.rs allows you to do integration tests. All the visibility/crates.io/vm-virtio are irrelevant.
Separation of concerns. Unit tests are testing a single thing at a time. Integration tests test for more complex interactions. Also, you don't have to recompile the crate everytime you change the tests. These are official rust guidelines, it makes sense for rustvmm to be as Rust-like as possible. |
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.
One typo, otherwise LGTM
This adds a basic template crate, which will be useful for new developers to understand how things work and layout all basic stuff they are expected to write to make it work. The current implementation just parses all the requests from the virtqueue and prints the number of descriptor chains and size of each descriptor buffer in there. This adds basic sanity tests as well for the same, which can be run to test the working of the crate. Signed-off-by: Viresh Kumar <[email protected]>
12fbf98
to
d7b685d
Compare
I was going to click the merge button, but now I just have a copyright question. I think in the second case we should put a generic copyright and a TODO for who will use the template. I'm in favor of both, I think we just need to be clear on whether this code has a copyright or not. |
Copyright as in at the top of the source files ? I have already added them here. |
Yes, maybe I explained myself wrongly. Exactly because we added it, this is going to force anybody using this template to use these copyrights that might be incompatible with others that they would like to use. Do we want that? (I'm okay with that, I just want to understand whether or not one is allowed to change the copyright or this code is explicitly released with this copyright.) |
There is copyright information here: My name + Linaro and then there is SPDX License thing.. The License thing should be used by everyone, that's fine. For the copyright part, I am not sure why it would be confusing to anyone to just update the same with their name / comapny or in some other way ?
I think one should be allowed to add their own for their own crate. |
Okay, but maybe the copyright they want to use is incompatible with these (I'm thinking of GPL for example) and so they can't use this template. Is this okay with us? (I don't have a strong opinion, I just want to see if it's okay for you too) |
Hmm.. We decided a while back on what licenses we should be using for crates in vhost-device and we settled with: "Apache-2.0 or BSD-3-Clause". I think we should promote the same going forward too ? I do see some GPL bits in SCMI, but then I am not sure what the right thing to do here is.
I will still allow them to use the template and let them provide a reason why they don't want to go with "Apache-2.0 or BSD-3-Clause". Will that work ? |
Not a lawyer, but I'm sure they can use the BSD-3 parts of this template and relicense their work as gpl; BSD-3 allows this. Of course the BSD-3 parts of the template remain BSD-3. |
Yeah, perhaps we should clarify this (obviously not in this PR)
You own the copyright, so I think you can do it, but only you, I think, unless we explicitly specify it by adding it in the copyright. |
Maybe we should use WTFPL (just kidding, just a game because it's Friday ;-P). |
Copyright re-assignment afaik is only necessary for re-licensing the code; since we use permissing licenses this would only allow people to use it for proprietary forks/releases. I don't know if I'm 100% correct but this isn't something we want, right? With Apache and BSD-3 everyone can use it in whatever FOSS way they want as long as they retain the copyright notices etc. |
Okay, so I think for now we merge as is, if there are problems in the future we'll see. But I hope not. |
This is an example code modified from Linux kernel, i.e. documentation not related to the vhost-device code license. |
This adds a basic template crate, which will be useful for new developers to understand how things work and layout all basic stuff they are expected to write to make it work.
The current implementation just parses all the requests from the virtqueue and prints the number of descriptor chains and size of each descriptor buffer in there.
This adds basic sanity tests as well for the same, which can be run to test the working of the crate.