Prepare for refactoring the create_sockaddr() function by adding a test
for the existing version.
BUG=b:365852007
TEST=cargo test -p net_util sockaddr
Change-Id: Ibe2d910df93f46702ce96615220a7e8e60cc6dc9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5760285
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
For ioctl numbers that do not require any parameters, make ioctl_io_nr
and related macros generate a constant rather than a function with no
parameters. This makes the code that uses these constants more idiomatic
and also allows using the constants in match statements (see an example
in virtio/fs/passthrough.rs).
BUG=None
TEST=tools/dev_container tools/presubmit
Change-Id: Id52817528d770c5dbbe2ce7928c9f31a15c83d83
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5648647
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Ensure that every Cargo.toml dependency on a third-party crates.io crate
specifies at least a major version, or a minor version for 0.x crates,
to ensure that if a new major version is published, it cannot cause API
breaks.
The versions are selected to match the ones already in Cargo.lock, so
this should have no functional change, but it will help prevent new "*"
versions from being introduced via copy-and-paste.
For rationale, see the Cargo FAQ:
<https://doc.rust-lang.org/cargo/faq.html#can-libraries-use--as-a-version-for-their-dependencies>
`minijail`, `audio_streams`, and `cras` are left as "*" for now, since
they have unusual situations (imported from a submodule and/or replaced
at build time with ebuild magic).
BUG=None
TEST=tools/dev_container tools/presubmit
TEST=verify Cargo.lock is unchanged
Change-Id: Ifa18199f812f01d2d10bfb4146b3353c1a76527c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5555656
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
See prior comment thread:
https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5454793/6..9//COMMIT_MSG#b12
`TimerTrait::reset` offers a very similar API to the `timerfd_settime`
system call, but in practice is almost used to set either a one-shot
timer, or a repeating timer with an initial timeout the same as the
repeating timeout.
`kqueue`'s timer functionality only supports the cases that are actually
used in practice. This change aligns the API with the way it is used,
and makes the distinction between the behavior of the arguments more
obvious.
Test: tools/presubmit
Test: cargo test -p base timer -- --ignored
Bug: 335486579
Change-Id: I1873ab9cccaf7a4b988431839964b1c253f76a34
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5463100
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
The validate_and_configure_tap() and virtio_features_to_tap_offload()
functions already effectively did nothing on Windows, since the
implementations of these for Slirp were not provided. These functions
are moved to sys so the Linux-specific TAP interfaces are no longer
needed in TapTCommon.
The get_ifreq() function is only called internally inside the
implementation of the Linux Tap struct; it does not need to be part of
the TapT trait at all.
The MacAddress <-> sockaddr interop is only needed on Linux, and the
conversion can be moved into the get_mac_address and set_mac_address
implementations for Linux.
With these changes, net_sys is used only on Linux, so it can be
conditionally compiled and not included in non-Linux builds at all.
BUG=None
TEST=tools/dev_container tools/presubmit
Change-Id: I3419a3bdb1470c4d72588fe19e43fabcdfe4e451
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5046598
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Updates are made to source and documentation.
This more accurately represents the currently supported platforms of
Android/Linux and Windows, without unexpectedly including other
unix-like operating systems.
Command to reproduce:
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -i 's/cfg(unix)/cfg(any(target_os = "android", target_os = "linux"))/g' {}
$ cargo fmt
md files manually updated to fix line lengths.
Renaming `unix` modules to `linux` will be done in a later CL.
Test: ./tools/dev_container ./tools/presubmit
Bug: b/298269162
Change-Id: I42c1bf0abf80b9a0df25551613910293217c7295
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4909059
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
zerocopy 0.7.x has finally released as a stable version, uprev it
to allow some remaining structs to be derivable.
TEST=CQ
BUG=b:300969352
FIXED=b:300969352
Change-Id: I90f0dfb09494f875fef1cd11bfcbd48030846092
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4878761
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zihan Chen <zihanchen@google.com>
Previously all of the zerocopy imports just used "*", but there are
API changes in zerocopy 0.7, so ensure we get a compatible version by
depending on 0.6 everywhere.
This is a no-op since Cargo.lock already specifies a 0.6.x version, but
it will prevent accidentally upgrading to 0.7.x without updating to the
new API.
BUG=b:301283548
TEST=cargo build
Change-Id: Ifd702d982a09b5083dddd666dc6f3052cba22214
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4878502
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Allows to make a prod build capable of capturing if the argument is
passed. But, behaves the same as before if the CLI is not passed.
BUG=b:294419893
TEST=downstream emulator
Change-Id: Iab1dddd30537c6ea61e9d32b240fabdfddd13e22
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4752604
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Idan Raiter <idanr@google.com>
Introduce a TimerTrait that is implemented by both Timer and FakeTimer.
This trait can be used to write testable code without needing to
condition use statements on cfg(test).
BUG=None
TEST=CQ
Change-Id: I874ffe19fafe73e5c17fd5bb689e5b571e9f5b12
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4664188
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: David Stevens <stevensd@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
This test will spin up block and net vhost user device processes. This
test will be used as a smoke test and won't run during presubmits
Also refactor functions that can be shared into the fixture crate.
BUG=b:281115884
TEST=ran test. Also verified messages get sent to vhost user devices
Change-Id: Ic7e78a8ed71290fd3c42f9e15bf59a238623c49e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4519650
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Richard Zhang <rizhang@google.com>
The build.rs file will be compiled for the host platform and cfg()
flags will reflect those of the host platform and not of the build
target.
Use CARGO_CFG_ environment variables instead.
BUG=b:240593511
TEST=CQ
Change-Id: Ib8b6c8e8bfb44ad83212bb2aa40a17a4e16a4adf
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4518569
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
The overlapped wrappers on PipeConnection are unsafe, but they were
marked as safe. There are no actual unsafe production uses of them
because the conventions for overlapped IO generally make that hard to
do. That being said, these wrappers MUST be marked unsafe. This CL does
so and updates the callers with safety statements.
BUG=b:272812234
TEST=presubmit
Change-Id: I0def7056431d5b3b70eb4ce7c6ac8b44aef0a4cc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4330490
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Noah Gold <nkgold@google.com>
- Rust toolchain is updated to 1.65.0
- Catapult dashboard upload tool is added to dev_container
- Bindgen is updated to latest version to support custom derive
- Derive Eq when PartialEq is derived as required by new Clippy
TEST=CQ, bindgen-all-the-things
FIXED=b:260784028
BUG=b:257303497
Change-Id: I2034cd09e0aed84d4e9b30f2e85d84d94a442ea4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4228427
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Zihan Chen <zihanchen@google.com>
A few more needless_borrow and needless_return warnings slipped in since
the last round of Rust 1.65 clippy fixes.
BUG=b:260784028
TEST=tools/clippy # with Rust 1.65
Change-Id: Iefceab6f1ec1c460e92b49f9cd21cfb79569f04a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4133516
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
These should be written as ChromeOS and ChromiumOS (without the space)
to match the updated branding. The copyright headers were already
migrated to the new style (https://crrev.com/c/3894243), but there were
some more instances left over.
BUG=None
TEST=tools/cargo-doc
Change-Id: I8c76aea2eb33b2e370ab71ee9b5cc0a4cfd00585
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4129934
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
These tests require root privileges to run. Check if we can do
a passwordless sudo and run the test process as a child process
with sudo.
This will work in CI or dev_container. For developer workflows,
the test_runner will already ask for sudo credentials before
running tests.
BUG=b:261600801
TEST=Fails: cargo test -p net_util
Passes: sudo true && cargo test -p net_util
Change-Id: I7c18057f7cfb91d5d389f9d9d1bb2d886d7f0149
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4086904
Auto-Submit: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Testing tap functionality requires root privileges. The crosvmdev
user of our dev_container is set up for passwordless sudo, so we can
seamlessly execute these tests via sudo.
For running on the developer workstation directly, this will prompt
for a password, which is disruptive to workflows. The --no-root
option can be used to prevent this and skip the tests in question.
BUG=None
TEST=tools/run_tests [--no-root]
Change-Id: I731887837affceb76152466f0006c4ee51a19234
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4063237
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Currently, we ignore clippy::needless_return, with many violations in
the code base. This CL fixes trivial, safe-to-fix violations of
needless_return. These were found by removing the needless_return
suppression in .cargo/config.toml and then fixing needless returns.
These are not all needless returns in the code base; it is only the
trivial fixes. This CL is a part of a chain of CLs to fix the
needless_returns in the code base.
BUG=chromium:908640, b:157245930
TEST=cargo clippy + cargo build
Change-Id: I6f8f3a0bed25d774fba7ae4b6e4c021af439ec22
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4014832
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Clarissa Garvey <clarissagarvey@chromium.org>
The tests require root privileges and have been silently
failing in CI because of that.
We will need a mechanism to run tests as root to enable these.
See b/256221093
BUG=b:244623459
TEST=presubmit
Change-Id: If812c219f44221275eabb2892891fd05b432d2fb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3990012
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
CrosVM must ensure that the tap file it uses is O_NONBLOCK, otherwise
the networking is very slow. Currently CrosVM uses O_NONBLOCK when
opening the tap file directly in create_tap_with_ifreq, and it must
ensure the same behavior if the tap file is created from a raw
descriptor.
BUG=b:257304931
Change-Id: I32ce42085ba312993dce32c457a8e5376b94c46b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4003798
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Peter Oskolkov <posk@google.com>
Use the off64_t versions of libc file functions.
There is no Rust libc crate equivalent of the C _FILE_OFFSET_BITS and
related defines, so we have to use the Linux-specific *64 variants
explicitly.
This extends the size of file offsets to 64 bits instead of 32 on
platforms with 32-bit userspace.
(It also fixes the recently introduced check for non-LFS functions in
ChromeOS - see b/201531268 for details.)
BUG=b:201531268
TEST=emerge-kevin crosvm
TEST=start Crostini on kevin
Change-Id: Ife42917c8896d4fa1ccd78051c2a0b7dd565b2b3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3979975
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Trying to reconcile the difference between the linux and windows
implementations.
Code relying on the eventfd count must now use the linux specific
`EventExt` interface.
BUG=b:231344063
TEST=presubmits
Change-Id: I14eb50f7a02d766a00f27aca388823309633e193
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3864030
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Currently, --tap-name, --tap-name, --host-ip...etc commands are all used
to create a vhost-user net device. This CL unifies the command line arguments.
BUG=b:246224081
TEST=run the following tests:
- `cargo test -p devices virtio::net::tests`
- `cargo test -p net_util`
Change-Id: Ie1342f23f0951e5a81e54547bf725c0d9be19f97
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3893869
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Koki Ryu <kokiryu@chromium.org>
Fix a few stray references to "CrosVM" and "CrosVm" so that we refer to
the crosvm project with consistent capitalization.
BUG=None
TEST=None
Change-Id: If5c3c131774d6e5da1d27466810642aec3cb42ac
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3938640
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
While we are tweaking all of the copyright headers, let's take the
opportunity to ensure there is always a blank line after the copyright
header for consistency. (Almost all files already follow this style.)
This includes a slightly ugly regex to allow the end of a C-style
comment block after the end of the copyright:
/*
* Example comment block
*/ <-- this line
Change-Id: Idfd0855861e5ecb3d33afae942fdba908af0dcff
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3892521
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
This search/replace updates all copyright notices to drop the
"All rights reserved", Use "ChromiumOS" instead of "Chromium OS"
and drops the trailing dots.
This fulfills the request from legal and unifies our notices.
./tools/health-check has been updated to only accept this style.
BUG=b:246579983
TEST=./tools/health-check
Change-Id: I87a80701dc651f1baf4820e5cc42469d7c5f5bf7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3894243
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
When debugging, we've repeatedly run into issues where we don't know how
far in the initialization process various devices or the main process
managed to get before it ran into trouble. As a first step, we're
introducing some informational logs at various critical points so we can
tell the difference between a true startup failure and other failure
modes.
BUG=b:242103548
TEST=tested downstream
Change-Id: Ia76c7de3c98ea76943853588f2b9c0e89de056d6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3833643
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Noah Gold <nkgold@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
- Remove trailing ::{self} on all use statements
- Remove any resulting single-level use statements (e.g. use libc;)
- Reformat with `tools/fmt --nightly`
BUG=b:239937122
TEST=tools/dev_container tools/presubmit --all
Change-Id: I8afd1b0458ca6d08d9b41a24583f7d4148597ccb
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3798973
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Ran clippy with features that are enabled downstream. Those features
will be enabled upstream in later cls when crosvm starts building.
BUG=b:213146388
TEST=presubmit
Change-Id: I67cb74127a349b572e573c350d69d1611533d961
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3793690
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Tested-by: Vikram Auradkar <auradkar@google.com>
crosvm is switching the import style to use one import per line.
While more verbose, this will greatly reduce the occurence of merge
conflicts going forward.
Note: This is using a nightly feature of rustfmt. So it's a one-off
re-format only. We are considering adding a nightly toolchain to
enable the feature permanently.
BUG=b:239937122
TEST=CQ
Change-Id: Id2dd4dbdc0adfc4f8f3dd1d09da1daafa2a39992
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3784345
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
A few of the cfg_if blocks got misaligned somewhere along the line, and
cargo fmt won't rewrite code inside macro invocations, so we have to fix
them manually.
BUG=None
TEST=stare at whitespace
Change-Id: I1ccf7aff7c7827a2687ab5fa50cc192c79d6400b
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3691968
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Pull the declaration of the `EventToken` enum up to the top level of the
base crate, replacing the identical implementations inside sys/windows
and sys/unix.
Use the `EventToken` name consistently throughout the tree to remove the
unix-flavored "poll" nomenclature.
BUG=b:213153157
TEST=tools/dev_container tools/presubmit --all
Change-Id: I0ba42037b533b796797a7a3f6d8d7e71a5592aba
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3642673
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
This provides at least a minimal one-line description to show what each
crate is about.
BUG=None
TEST=tools/cargo-doc
Change-Id: I26732e8c29062e622d5be09bdc120a49d564b9fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3630422
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>