-
Notifications
You must be signed in to change notification settings - Fork 64
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
vmm-sys-util #1
vmm-sys-util #1
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.
Pass 1, will do another pass soonish.
src/errno.rs
Outdated
// Copyright 2019 Intel Corporation. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
// TODO: This module is not used now. Avoid the warning. |
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.
I believe it shouldn't throw a warning if you are not using this module in the vmm-sys-util
crate. All modules from this crate should be re-exported with pub mod in src/lib.rs
.
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.
Thank you for the quick reviewing! I'll fix the comments in codes.
src/lib.rs
Outdated
#[macro_use] | ||
pub mod ioctl; | ||
|
||
mod errno; |
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.
I think the modules here should be re-exported with pub. These modules are not for internal use in the vmm-sys-util
crate but they're going to be used by other crates.
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.
Fixed.
@@ -0,0 +1,86 @@ | |||
// Copyright 2019 Intel Corporation. All Rights Reserved. |
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.
Any reason why we need this module instead of using std::io::Error
?
In Firecracker we replaced it with std::io::Error
because it wasn't producing human readable errors.
For example, let's say you do not have enough permissions to open /dev/kvm
.
- the error message with errno.rs:
Cannot open /dev/kvm. errno: 13
- the error message with std::io::Error:
Cannot open /dev/kvm. Error: permission denied.
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.
The nice part about this error type is that it is fully compatible with os error code thrown off by system calls. If one were to put an os error code into an io::Error
, it might be hard to get the os error back out in upper parts of the call stack. Using io::Error::raw_os_error
returns an Option
that either requires unwrap
or an extra match
just to extract the code. Using io::Error::kind
is tricky because it has variants which are not possible to get from a syscall (UnexpectedEof
), or are mismatched by the std implementation that converts error numbers to ErrorKind
variants. Additionally, some error codes have no correspondence with an ErrorKind
variant other than Other
.
If human error messaging is all that is needed to make this module acceptable, I suggest using what we have in crosvm today for Error
:
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
io::Error::from_raw_os_error(self.0).fmt(f)
}
}
README.md
Outdated
# vmm-sys-util | ||
This crate is a collection of modules that essentially provide helpers and utilities. |
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.
nit: essentially is just a filler word, can you remove it?
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.
Yes. Will do it.
src/eventfd.rs
Outdated
|
||
//TODO: Firecracker uses io::Error instead of sys_util::Error for Result<T, E>. Need discussion here. | ||
|
||
#![allow(unused)] |
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.
This should not be necessary once we export the module as public in src/lib.rs.
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.
Right! Will remove it
src/eventfd.rs
Outdated
/// A safe wrapper around a Linux eventfd (man 2 eventfd). | ||
/// | ||
/// An eventfd is useful because it is sendable across processes and can be used for signaling in | ||
/// and out of the KVM API. They can also be polled like any other file descriptor. |
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.
nit-ish: I would remove the reference to the KVM API here. It is not super relevant in the context of rust-vmm where we will also have other hypervisors. I believe the comment is a bit outdated.
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.
Removed.
src/eventfd.rs
Outdated
} | ||
|
||
impl EventFd { | ||
/// Creates a new blocking EventFd with an initial value of 0. |
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.
I don't think this comment is accurate. We are creating the eventfd with EFD_NONBLOCK.
I noticed that in CrosVM they are opening it without the flag so maybe it would make sense to pass the additional flags as parameters.
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.
Yep. Let me change the flag to be a parameter for new() and test the new(EFD_NONBLOCK) in #[test]. Do you think we need double test the new(0) for each #[test]?
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.
Hmm, I'll look at the code. It is always nice to test all the usecases, now it depends whether it adds any value.
@liujing2 please also add the Travis configuration file. Here is the one from the vm-memory crate: https://github.com/rust-vmm/vm-memory/blob/master/.travis.yml |
Cargo.toml
Outdated
@@ -0,0 +1,9 @@ | |||
[package] | |||
name = "libc-utils" |
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.
Name should probably be vmm-sys-utils
/// A safe wrapper around a Linux timerfd (man 2 timerfd_create). | ||
pub struct TimerFd(File); | ||
|
||
impl TimerFd { |
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.
I haven't check the other docs, but I think it is a good idea to have the documentation split in summary and description.
For new() it would look something like this:
/// Create a new `TimerFd`.
///
/// The timer is initially disarmed and must be armed by calling `reset()`.
Then we could also add links to the structures and methods, but I guess it is optional because it does make the code comments harder to read with the advantage of making the html docs prettier:
/// Create a new [`TimerFd`](struct.TimerFd.html).
///
/// The timer is initially disarmed and must be armed by calling [`reset`](struct.TimerFd.html#method.reset).
P.S. I haven't checked that the documentation links are correct.
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.
Let me split the summary and description. The link might be optional and I found not all of the linux man is appended in original codes.
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.
Hmm, I don't think I understand, I meant inside links to structures and functions that you are referring to in the comments.
https://rust-lang-nursery.github.io/api-guidelines/documentation.html#prose-contains-hyperlinks-to-relevant-things-c-link
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.
@andreeaflorescu Thanks for the guide. I misunderstood. I'll update a new version today.
} | ||
|
||
#[cfg(test)] | ||
mod tests { |
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.
Please prefix tests with test_
(test_one_shot
). This is a good way to visually separate tests from helper methods.
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, I will add the prefix for every tests in these files.
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.
Could you please be more verbose in each commit message? We should be able to quickly understand what was introduced by each commit only looking at the commit messages IMO.
Cargo.lock
Outdated
] | ||
|
||
[metadata] | ||
"checksum libc 0.2.49 (registry+https://github.com/rust-lang/crates.io-index)" = "413f3dfc802c5dc91dc570b05125b6cda9855edfaa9825c9849807876376e70e" |
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.
There was a discussion about whether Cargo.lock should be committed. I remember the conclusion is not to commit for library crate and only commit for binary crate.
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.
Thanks for the reviewing. Will ignore it in next update.
Cargo.toml
Outdated
name = "libc-utils" | ||
version = "0.1.0" | ||
authors = ["Jing Liu <jing2.liu@linux.intel.com>"] | ||
edition = "2018" |
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.
Seems a little risky to force 2018 edition.
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.
Got it. Remove it and add license BTW.
@@ -0,0 +1,86 @@ | |||
// Copyright 2019 Intel Corporation. All Rights Reserved. | |||
// SPDX-License-Identifier: Apache-2.0 |
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.
Now it's suggested to dual license for Apache-2.0 and MIT. Please help to add support of MIT.
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.
Now it's suggested to dual license for Apache-2.0 and MIT. Please help to add support of MIT.
@jiangliu I just updated the codes regarding to the license and other review comments.
BTW, for the vhost utility, could you explain your request in details so I can help?
src/errno.rs
Outdated
/// Returns the last `errno` as a [`Result`] that is always an error. | ||
/// | ||
/// [`Result`]: type.Result.html | ||
/// |
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.
Should we remove the blank lines?
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.
I think blank line is no need here. The same as others.
Sure. Let me append more. |
Currently the vhost crate makes use of the EventFd and ioctl macros from the sys_util crate, seems they are available in the vmm-sys-util already.
… On Apr 16, 2019, at 5:40 PM, liujing2 ***@***.*** ***@***.***>> wrote:
@liujing2 commented on this pull request.
In src/errno.rs <#1 (comment)>:
> @@ -0,0 +1,86 @@
+// Copyright 2019 Intel Corporation. All Rights Reserved.
+// SPDX-License-Identifier: Apache-2.0
Now it's suggested to dual license for Apache-2.0 and MIT. Please help to add support of MIT.
@jiangliu <https://github.com/jiangliu> I just updated the codes regarding to the license and other review comments.
BTW, for the vhost utility, could you explain your request in details so I can help?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub <#1 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AB14_A3AoZQL225N9B1pkL2iTCEtjfwOks5vhZp-gaJpZM4b-wo4>.
|
a651f7a
to
8663f2e
Compare
Codes updated with license MIT and review comments. Thanks! |
.travis.yml
Outdated
script: | ||
- cargo build -- release | ||
- cargo test | ||
- cargo fmt --all -- --check |
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.
Do we need to check clippy result here ?
- cargo clippy --all-targets --all-features -- -D warnings
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.
Yep, I just updated PR with a separate commit on top, about solving the clippy issue. Thanks.
src/errno.rs
Outdated
// | ||
// Portions Copyright 2017 The Chromium OS Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the THIRD-PARTY file. |
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.
Seems the BSD license file is missing from the crate.
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.
BSD license file is added.
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, thank you @liujing2!
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
LICENSE.MIT
Outdated
@@ -0,0 +1,21 @@ | |||
MIT License |
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.
What code is coming under MIT vs BSD or Apache 2.0?
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.
It seems currently dual license for Apache-2.0 and MIT are supported for rust-vmm. See the comments BSD is copied from crosvm.
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.
@liujing2 I think it would be wiser to remove the MIT license for now and only keep the Apache 2.0 and the 3 clause BSD one.
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.
Will remove MIT license.
@liujing2 I sent you a PR for adding a few more utilities to that crate, mostly for supporting disk image format crates like e.g. QCOW. |
LICENSE.BSD
Outdated
@@ -0,0 +1,27 @@ | |||
// Copyright 2017 The Chromium OS Authors. All rights reserved. |
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.
Could we please rename that file LICENSE-BSD-3-Clause and the Apache one LICENSE-APACHE? Just to be consistent with the already existing crates?
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.
Will do that.
LICENSE.MIT
Outdated
@@ -0,0 +1,21 @@ | |||
MIT License |
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.
@liujing2 I think it would be wiser to remove the MIT license for now and only keep the Apache 2.0 and the 3 clause BSD one.
Add and correct basic support files for the vmm-sys-util crate including: - files generated by Cargo - license files - gitignore Signed-off-by: Jing Liu <jing2.liu@linux.intel.com>
The errno module wraps an interface to the error codes. The eventfd module is a wraper around the Linux eventfd. Use result::Result<EventFd, io::Error> instead of result::Result<EventFd, errno::Errno> as return type. The terminal module is for configuring pseudo-terminals in raw mode. The signal module is for registering signal handlers and for signalling threads. The ioctl module is factoring out common ioctl wrappers and macros. This is derived from crosvm code base e4ece32798ba436fbfa88466c571f46dab99e2be and firecracker code base 1fdde1997fc763601f8a88399bc426bd5d4097cd. Signed-off-by: Jing Liu <jing2.liu@linux.intel.com> --- Change Log Add license. Append prefix test_ for each test. Add verbose commit messages.
To use different init flag(e.g. SA_RESTART, SA_SIGINFO) for sigaction, add a parameter to register_signal_handler and a function to set this flag. Signed-off-by: Jing Liu <jing2.liu@linux.intel.com>
Wrapping the libc timerfd for the usage of setting timer, waiting expiring, disarm timer. This is derived from crosvm code base e4ece32798ba436fbfa88466c571f46dab99e2be. Signed-off-by: Jing Liu <jing2.liu@linux.intel.com> --- Change Log: Add license. Split the summary and description for method. Add link for structures and functions. Append prefix test_ for tests.
The poll module addis the Poller object for waiting on mutliple file descriptors at once. Add macro handle_eintr_errno! to check the epoll_wait return value. The syslog module is for logging, temporarily defining the SYS_getpid syscall value. This is derived from crosvm code base e4ece32798ba436fbfa88466c571f46dab99e2be. Signed-off-by: Jing Liu <jing2.liu@linux.intel.com> --- Change Log Append prefix test_ for tests.
This is needed for disk image format support like e.g. QCOW2. Copied verbatim from crosvm 107edb3e. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Several places are improved to suppress the clippy warnings. The changes of type casting in timerfd module are based on crosvm latest code base b1de6323ab8c96c52a60e0ff735e4bbb8a8464c9. The write_zeroes and seek_hole clippy warnings are only on test code, we can safely allow them. Signed-off-by: Jing Liu <jing2.liu@linux.intel.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Seems file_traits, wrtite_zeros, seek_hole and fallocate are related to each other, how about combine them into one file? |
It fails to compile with "cargo build --target x86_64-unknown-linux-musl" as below. GNU library is ok. error: aborting due to previous error For more information about this error, try |
@jiangliu According to the MUSL libc which is used by rust musl build, we can find that MUSL libc doesn't have SEEK_HOLE and SEEK_DATA support. |
musl does not define the SEEK_HOLE and SEEK_DATA constants. We use the libc one when using glibc and we define them when building for musl. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
@zachreizner @dgreid PTAL |
Could we also reexport libc::{EFD_SEMAPHORE, EFD_SEMAPHORE, EFD_CLOEXEC} in the eventfd.rs, so it get a little easier for use. |
Testing a potential fix... |
Using the File wrappers leads to poisoned pointers when running under a tmpfs based /dev mount. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
The vmm-sys-util test make heavy use of temporary dirs and files. Running that under a container overlay leads to erratic behaviours and this is fixed by using a real tmpfs mount into the container's /tmp. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Seems to be working. |
@jiangliu Do you mind if we merge that one first and then send that as a follow up PR? |
sure, actually I have three patches upon this patch set:) |
Excellent :) Could you please give this PR another review? Adding new commits dismissed the previous reviews... |
Looks like this PR is ready to be merged :) |
Great, the vhost crate could move on once this has been merged:) |
This includes the utilities that directly use libc from crosvm and firecracker.