Commit graph

120 commits

Author SHA1 Message Date
Daniel Verkamp
a360baa819 Cargo.toml: upgrade protobuf 2.x -> 3.x
system_api bindings have been regenerated with protobuf 3.2; this should
be okay to land before the full ChromeOS system_api migration, since
crosvm always uses its own copy of the bindings rather than the ones
provided by the dev-rust/system_api package.

The protoc-rust crate is replaced with protobuf_codegen in 3.x.

BUG=b:277243607
BUG=b:279834784
TEST=tools/dev_container tools/presubmit

Change-Id: I6aad45ded2639d7506a7238800584bebab196455
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4405309
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-04-28 19:32:01 +00:00
Daniel Verkamp
2c1d17fe41 tree-wide: remove unnecessary casts
Fixes clippy lint in Rust 1.68

BUG=b:276487055
TEST=tools/clippy # with rust 1.68

Change-Id: Ib9d83b8dc15a93e815600391e93b8bb1788f7dc4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4391107
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-04-17 23:43:59 +00:00
Daniel Verkamp
27d1a90062 disk: use Seek::stream_position() convenience function
Replace seek(SeekFrom::Current(0)) with the stream_position() helper
function, which has been stable since Rust 1.51.

BUG=b:276487055
TEST=tools/clippy # with rust 1.68

Change-Id: I21e9af65f6ad5ad8443dd1d2b95c08d3be91f174
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4390741
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-04-11 20:44:34 +00:00
Junichi Uekawa
d03c99fc0c crosvm: Uprev uuid > 1
Uprev to version available in Debian.

This seem to end up doing uprev to 1.3 now.

BUG=b:265082456
BUG=b:229895468
TEST=build

Change-Id: I550778acb675c9034b9cfcea77f4ae847e2d2ea1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4364559
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2023-04-04 23:56:13 +00:00
Frederick Mayle
6245e630b8 cros_async: introduce concrete type IoSource for async IO
This removes two layers of boxing and trait objects. One for the IO
source objects and another for the futures generated by calling methods
on them.

Benefits:

* IO futures will now be `Send` (if the underlying source is `Send`,
  which is generally the case).
* It is easier to work with a concrete type than a `Box<dyn ...>`.
* More efficient (less boxing and virtual function calls).

Slightly smaller binary size:

  $ cargo build --all-features --profile chromeos && ls -l target/chromeos/crosvm
  before: 10,811,576
  after:  10,692,792 (1.1% smaller)

Change-Id: I7b52cd24945cfb4ff0a6c377739b5d4ab9cacb0b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4004980
Reviewed-by: Noah Gold <nkgold@google.com>
2023-04-04 20:17:23 +00:00
Takaya Saeki
205297ef95 disk: add try_clone method to DiskFile trait
Introduce `try_clone` method to `DiskFile` trait. This allows callers to
create DiskFile instances which share the same underlying file
descriptors, which enables you to manipulate them in multiple threads in
parallel. virtio-blk requires this change to run multiple worker threads
in parallel.

Note `try_clone` is introduced as a method of `DiskFile`, not as a
standalone `TryClone`, since such `TryClone` trait is not an object-safe
and thus cannot be defined actually.

BUG=b:267716786
TEST=build passes

Change-Id: I8aae4ee08992de2649b7157b8dfe7328751208b5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4281742
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Takaya Saeki <takayas@chromium.org>
2023-03-02 08:52:56 +00:00
Shintaro Kawamura
fc3e5c9b80 disk: add PunchHoleMut trait
PunchHole should be originally immutable method since the
file_punch_hole() for both unix and windows are immutable function which
do not change the underlining file offset.

QcowFile is the only object which requires mutability to punch a hole to
its file.

This commit introduce a new PunchHoleMut and the existing PunchHole
traits and make PunchHole trait immutable. This unblocks b/269981962
which tries to punch a hole to non-mut reference File.

This also remove useless top level defined functions in base crate.

BUG=b:269981962
TEST=cargo build --feature=qcow
TEST=./tools/run_test2

Change-Id: I8333d13f4adc6dff319c0ddababe400d5e995141
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4269718
Reviewed-by: David Stevens <stevensd@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Shin Kawamura <kawasin@google.com>
2023-02-22 01:53:38 +00:00
Zihan Chen
30f58a81aa crosvm: Partially convert DataInit to zerocopy (6/n)
This CL removed many uses of DataInit in devices. Some paddings
are manually added/fixed to allow AsBytes to derive without ABI
changes.

TESTED=CQ

BUG=b:204409584

Change-Id: I1f8c2d5304fc8e685cc3e5166c73481f6a3f78f7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4235224
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-02-10 01:52:24 +00:00
Frederick Mayle
32321cfa54 disk: android_sparse: fix into_inner bug
If a guest cycled the virtio-blk on and off (e.g. activate, reset,
activate), then android-sparse files would start to be treated like raw
files.

BUG=b:266440668,b:219595052

Change-Id: I9ca00668ba7a7c820a177309edf320426feba81a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4195519
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-01-26 18:36:01 +00:00
Frederick Mayle
557adc412b disk: android_sparse: delete unused trait impls
BUG=b:219595052
TEST=cd disk && cargo test --features qcow,composite-disk,android-sparse

Change-Id: Id7c49ce3f598260a3b0bd6331249354777f4aa16
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4174617
Auto-Submit: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-01-17 22:41:49 +00:00
Keiichi Watanabe
41dc95817d disk: Support async I/O for Android sparse disk
BUG=chromium:901139,b:219595052
TEST=cargo test
TEST=Start VM with rootfs of android sparse disk with sandboxes on v5.7 kernel

Change-Id: If829bffd24f23c06242124ccc8bfafb19b1ff9ed
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4160473
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-01-17 21:25:22 +00:00
Frederick Mayle
cd18fd3fcb disk: android_parse: fix length check
`get_len()` returns `AndroidSparse::total_size`, which is set to `size`,
so the check simplified to `size != size` => `false`.

Change-Id: I97ecd7923bce00fdc88e5dc49079ce3b5ee4d44b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4160754
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-01-17 21:25:22 +00:00
Frederick Mayle
0ff5d320af disk: android_sparse: constrain fill chunks to 4 bytes
The file format and canonical parser spec assert this is the case.

It doesn't simplify the code much, but it means there are fewer cases to
test and reasonable about + it's slightly more effecient.

Change-Id: Iacd64cfa439bf38546735869c1b5a815b0c5bb35
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4165863
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-01-17 21:25:22 +00:00
Frederick Mayle
118e447593 disk: android_sparse: require fixed chunk header size
The implementation didn't correctly handle the case where the file's
header size was larger than the ChunkHeader struct. It isn't a problem
in practice, so, instead of fixing it, we are turning this case into an
error.

Change-Id: Ie23a934523f5201c99352159aaa0fdf0fed7dd45
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4160753
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-01-17 21:25:22 +00:00
Daniel Verkamp
4fd6a78f0f disk: remove unused traits from DiskFile
BUG=b:219595052
TEST=cargo build --features=composite-disk,android-sparse

Change-Id: I7e37de3152d0d4c0907885533b7a88a93fba38e4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4167141
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-01-17 19:12:27 +00:00
Frederick Mayle
ffd74530ae disk: native AsyncDisk impl for CompositeDiskFile
There is a lot of code and test duplication w.r.t. the non-async impl
but we expect to delete the non-async impl in the near future, so the
temporary duplication is preferable vs increased code complexity.

Bug: 219595052
Change-Id: I402166331606d41178c1557c66be591d95c98c45
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4158596
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-01-13 20:38:20 +00:00
Frederick Mayle
b64fc1dfc6 disk: double buffered read/write methods for AsyncDisk
Change-Id: I8fe7d197951ab287d0c0c6c412034af3b8e43868
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4158595
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-01-13 00:54:26 +00:00
Frederick Mayle
e4100ef530 disk: misc cleanup in composite.rs
Change-Id: I1bac4ab9f4bf7de88d27f485c6d045560ca6664f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4158593
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-01-12 01:12:02 +00:00
Frederick Mayle
15961e1537 disk: inline CDISK_MAGIC_LEN
`str::len` is a const function now, so it can be used directly.

Change-Id: I2ec0de09adc71df9d2664e319a57f6a376f865c9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4158592
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2023-01-12 00:33:46 +00:00
Daniel Verkamp
ac0fc378a3 Fix remaining Chrome/Chromium OS instances
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>
2023-01-03 22:14:30 +00:00
Daniel Verkamp
2ddb12f0e2 Rust 1.65: Fix clippy bool_to_int_with_if lints
BUG=b:260784028
TEST=tools/clippy

Change-Id: Icacaff64624a925ad89ccf042d63d297b1bc855b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4064716
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-11-30 19:46:59 +00:00
Daniel Verkamp
0c1c7b85ca Rust 1.65: Fix clippy question_mark lints
BUG=b:260784028
TEST=tools/clippy

Change-Id: Id873ec1eca3a76a8ee17a2403cbe70f4ef07671b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4064712
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-11-30 19:21:36 +00:00
Dennis Kempin
0e4afa6513 disk/qcow: Write less blocks for testing
The test would take ~5s to run, cutting down the number of blocks
to write/read in the test will improve execution speed to .5s.

BUG=None
TEST=tools/run_tests -v disk\*

Change-Id: Ia877335bc662f4e7c5c91eff56c072bb1eb30e8d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4004300
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Auto-Submit: Dennis Kempin <denniskempin@google.com>
2022-11-09 18:39:33 +00:00
Vikram Auradkar
1b32084a56 crosvm: Enable default features on windows.
The patch makes usb feature no-op on windows as USB pass-through is
not supported on windows.

BUG=b:241251677
BUG=b:213149155
TEST=tools/presubmit

Change-Id: Id82d4c732a86e782695d2af698cc08e8e3fd2d35
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4006819
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-11-07 23:03:25 +00:00
Daniel Verkamp
e539372226 devices: virtio: block: impl DiskOption::open for Windows
Move the logic for locking and DiskFile creation into an implementation
of DiskOption::open(), matching the sys::unix structure. This will
allow future consolidation of the vhost-user devices.

For now, the Windows variant of DiskOption::open() only knows how to
create a SingleFileDisk (not qcow, composite, etc.); switching to
create_disk_file() is left as future work.

This also makes a few tweaks to the creation of the BlockAsync instance
in order to make the unix and windows versions more similar - compare:
- devices/src/virtio/vhost/user/device/block/sys/windows.rs
- devices/src/virtio/vhost/user/device/block/sys/unix.rs

No functional change intended.

BUG=None
TEST=tools/presubmit --all

Change-Id: Iadb1a8913a7445d7c091d0e359c7d8792704c35a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3892136
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-09-20 03:42:20 +00:00
Dennis Kempin
1dab58a2cf Update all copyright headers to match new style
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>
2022-09-13 18:41:29 +00:00
Christian Blichmann
44762216cf disk: Turn Android Sparse format into a feature
This is a follow-up to
https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3864926,
which implements this for QCOW.

Same rationale: allow to turn off support for disk formats that projects
do not need/want.

BUG=None
TEST=./tools/presubmit; cd crosvm-fuzz && cargo build

Change-Id: I401bad4d4ccb1a00a303ed86f1156f153b70b562
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3872278
Commit-Queue: Christian Blichmann <cblichmann@google.com>
Reviewed-by: David Stevens <stevensd@chromium.org>
Tested-by: Christian Blichmann <cblichmann@google.com>
2022-09-05 15:36:23 +00:00
Daniel Verkamp
2d01677a65 disk: remove non-async disk image support
With AsyncDiskFileWrapper, we can use all disk image formats via the
async API.

The create_async_disk_file() function is removed, and the existing
create_disk_file() function can be used to create async-capable disk
files, as the DiskFile trait now includes ToAsyncDisk.

BUG=b:219595052
TEST=cargo build --features=composite-disk
TEST=Boot x86-64 Linux in crosvm with a qcow2 disk attached

Change-Id: I430d306fe71c325ab529a7031353d20f8a9aa2f3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3824067
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-09-02 20:17:20 +00:00
Christian Blichmann
8847de2725 qcow: Turn QCOW support into a feature
This change allows to turn off support for QCOW. This is useful for
projects that do not need/want it.

A follow-up change (if this one is merged) will do the same for Android
sparse disk images.

BUG=none
TEST=./tools/presubmit

Change-Id: I69083c4c2e21d504db89eff47f4c86c6f61d67e9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3864926
Tested-by: Christian Blichmann <cblichmann@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Christian Blichmann <cblichmann@google.com>
2022-09-01 08:13:29 +00:00
Daniel Verkamp
583e650455 disk: add AsyncDiskFileWrapper
As a stepping stone toward fully asynchronous disk formats, add a
wrapper that takes a regular synchronous DiskFile and provides the
async disk API.

BUG=b:219595052
TEST=cargo build --features=composite-disk

Change-Id: Id785ad7ff69ae869a8a9007134fdb4fe7f3be4ba
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3824066
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2022-08-31 17:36:10 +00:00
Daniel Verkamp
ac9a459761 disk: make AsyncDisk take a dynamic BackingMemory
Rather than tying AsyncDisk::read_to_mem/write_from_mem to the
GuestMemory type specifically, use dyn BackingMemory like the underlying
read_to_mem/write_from_mem calls in cros_async. This will allow an async
version of QcowFile to use these functions to read/write temporary
buffers as part of its internal bookkeeping.

BUG=b:219595052
TEST=tools/presubmit

Change-Id: I4ca3c976bf5dca68e3bbe0e3f163023b47034254
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3824065
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2022-08-24 20:03:09 +00:00
Daniel Verkamp
03dd11a0d4 disk: do not require DiskFile in ToAsyncDisk
This would complicate the implementation of ToAsyncDisk for qcow and
other formats. Change the trait bounds so that only the minimal set of
traits used in the asynchronous block device is required.

BUG=b:219595052
TEST=cargo build

Change-Id: Id5ece59596b0a0989f953854a9cf4c30d32f7e34
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3824064
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
2022-08-24 20:00:49 +00:00
Daniel Verkamp
600ad38ff8 Remove redundant {self} imports
- 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>
2022-08-01 21:27:54 +00:00
Dennis Kempin
4fea399df9 Reformat imports
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>
2022-07-28 00:15:50 +00:00
Noah Gold
30074cb734 disk: upstream windows support
Splits out unix/windows code in to sys & adds windows code.

TEST=builds
BUG=b:213150316

Change-Id: I1dcc63ae978a5d72ee51b916181317b8f7008dbe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3654613
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-05-19 18:25:30 +00:00
Noah Gold
67b8f92b85 disk: only fsync composite when needed
This CL avoids fsyncing when unncessary (optimization originally created for
Windows).

TEST=builds
BUG=b:213150316

Change-Id: I9dc7d2d9c394ac83e4220e2a7ae99d670f4a5630
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3654618
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-05-19 18:25:30 +00:00
Noah Gold
ce57578ce8 disk: fix composite disk component path handling.
Currently we treat any version 1 path as absolute, and any non version 1
path as relative. The proto files don't indicate that this assumption
can be made, and we don't make it on Windows. This CL changes path
handling so that a version 1 path must actually be absolute for us to
treat it as such.

TEST=builds
BUG=b:213150316

Change-Id: I95a1c8751428a9e2f7311f9136940fbdb2410ef1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3654207
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-05-19 18:25:30 +00:00
Daniel Verkamp
45b0920767 doc: add a top-level comment to all crates
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>
2022-05-06 20:46:57 +00:00
Daniel Verkamp
97c11d70bf disk: qcow: switch to WriteZeroesAt
This removes the last usage of the non-At WriteZeroes trait.

BUG=None
TEST=cargo test -p disk

Change-Id: I54e9990140afdebccfd1b97dd2b6e75b17f3135a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3626022
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-05-05 21:11:59 +00:00
Noah Gold
ab263d1010 disk: fix punch_hole using wrong AllocateMode.
9da4030ab0 migrated consumers to use
AllocateMode, but this method got the wrong mode. This CL fixes that.

Thanks to idanr@ for spotting this during downstream merging.

BUG=NONE
TEST=bots + inspection.

Change-Id: I10792d4f293d7f672d3474288a7f706a5c0fd835
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3597038
Auto-Submit: Noah Gold <nkgold@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2022-04-21 02:19:31 +00:00
Noah Gold
9da4030ab0 cros_async: use portable enum for fallocate modes
fallocate modes were previously unix specific constants, which won't work after
we add support for Winodws. Here, we've put a generic abstraction in place so
that each platform can implement the details as appropriate.

Thanks to acourbot@ for suggesting the splits in this series.

BUG=b:213147081
TEST=see final CL in series.

Change-Id: I822ad6c4a26eea716482029e8a6c0489aa72c595
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3583613
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Noah Gold <nkgold@google.com>
2022-04-19 05:37:42 +00:00
Daniel Verkamp
f35f636cc5 Rust 1.60 clippy fixes
BUG=None
TEST=tools/presubmit # with rust-toolchain updated to 1.60.0

Change-Id: I5772e8b0593f8d92003e93aeb2145e87610abe2e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3577332
Reviewed-by: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-04-11 20:40:36 +00:00
Daniel Verkamp
ed6b27ab26 base: pass OpenOptions to open_file instead of bools
This cleans up the API and makes it easier to tell what is happening at
the call site. Additionally, callers may now use any options supported
by OpenOptions rather than the two specific flags (read_only and
o_direct) that were previously supported.

BUG=None
TEST=tools/presubmit

Change-Id: Ib8b5350c60807f14ebe0816d71bbf31e4bfef67f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3553763
Reviewed-by: Noah Gold <nkgold@google.com>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Anton Romanov <romanton@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-28 19:37:54 +00:00
Dennis Kempin
55c6a3b5cd Refactoring: Move common/cros_async to cros_async
This runs the script added in https://crrev.com/c/3533607

BUG=b:22320646
TEST=presubmit

Change-Id: I2e7efdb35508d45281f046e64c24aa43e27f2000
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3533608
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2022-03-21 19:52:56 +00:00
Alexandre Courbot
1cca2c79c9 disk: fix compile-time warning
Do not warn if the `image_path` parameter is unused, as it is only used
if the composite-disk feature is enabled.

BUG=b:221887571
TEST=cargo build

Change-Id: I91f747152c0e5f4d75f7522a33d35f91890c6df6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3531731
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-03-17 07:40:51 +00:00
Dennis Kempin
ef516189db Refactoring: Move common/base into base
Executes the script in https://crrev.com/c/3530502

BUG=b:223206469
TEST=presubmit

Change-Id: Ibeffdc8de0b2270f070e60bb2de8d9fdc78a2a6d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3530503
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-03-17 00:01:27 +00:00
Richard Fung
9f9f0b7725 Use composite disk dir for relative paths instead of crosvm working dir
This allows us to move the composite disks and partitions around instead
of needing to know the paths beforehand.

BUG=b:221887571
TEST=Manual test with composite disk created via mk_payload.

Change-Id: Ifab86bc62509e58cc95b0f8420bffc554d60f380
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3499408
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Richard Fung <richardfung@google.com>
2022-03-16 22:07:47 +00:00
Anton Romanov
bed40ad547 crosvm: migrate to Rust 2021 edition
BUG=none
TEST=cq

Change-Id: I0059c970879b78bfd40b6ce58b10debcf154b50f
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3508322
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Anton Romanov <romanton@google.com>
2022-03-09 01:16:03 +00:00
Daniel Verkamp
ee12440953 disk: qcow: restore Read/Write/Seek impls
The standard I/O traits are used by a downstream tool [1], so we can't
remove them for now. However, this is not a perfect revert because of
the other qcow cleanup patches, so some minor changes were needed (the
Write impl's write_cb needs to seek itself now that the offset is passed
in as a parameter).

Also add some basic Read/Write/Seek unit tests to ensure these keep
working.

This partially reverts commit 7f400e70fb.

[1]: https://cs.android.com/android/platform/superproject/+/master:packages/modules/Virtualization/virtualizationservice/src/aidl.rs;l=460;drc=dcf1741a18a0e552a85038a0e14671a506e8729a

BUG=b:219595052
TEST=cargo test -p disk

Change-Id: I0bdd4aed4938acde10516f31dd517bb070b51d0c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3503935
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Andrew Walbran <qwandor@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-03-07 22:53:09 +00:00
Vikram Auradkar
ae5118f5c7 Enable windows tests for a few crates
Run tests for sys_util_core, poll_token_derive and balloon_control on
windows.

Using dotfiles to disable/serialize test runs of a subset of crates does
not work well with third party crates as it forces us to commit the dot
file to the crate.

The patch modifies and uses the script that runs linux tests.
This patch also allows us to
- build/test child crate even if parent crate has disabled build/test.
- avoid building crosvm if it is not explicitly specified.

RIP short lived .windows_build_test_skip. You allowed us to run noop
kokoro tests.

Test: py .\tools\impl\test_runner.py --arch x86_64
Bug: b:215610772
Change-Id: Icc6d04ffd7c0c33d4f60aeac16fc7d23881c387d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3459809
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2022-02-18 03:18:58 +00:00