Commit graph

140 commits

Author SHA1 Message Date
Daniel Verkamp
20d3d0080d disk: replace div_round_up with .div_ceil()
The div_ceil() is available since Rust 1.73. Replace our custom version
with the standard library function.

BUG=None
TEST=cargo test -p disk

Change-Id: I6b44d1f5189b1653d8617a51af41cd8a7cc3d162
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5438907
Reviewed-by: Takaya Saeki <takayas@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-04-10 17:49:15 +00:00
Daniel Verkamp
742791deef tree-wide: replace data_model::zerocopy_from_*()
Use zerocopy functions directly instead. This is a step toward replacing
our data_model crate with standard crates.io functionality where
possible.

BUG=b:312312646
TEST=tools/dev_container tools/presubmit

Change-Id: I9717edce6fe2b4ca53ad9043db61de2e9bc55b78
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5046345
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2024-03-13 18:03:24 +00:00
Kaiyi Li
c28067d1d9 Reformat comments
Test: presubmit
Change-Id: I39c261d9985989873b698213c5d8b653fc13757b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5299850
Auto-Submit: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-02-15 23:30:13 +00:00
Frederick Mayle
1cad723426 cros_async: move punch hole special case into disk crate
https://crrev.com/c/5019243 added a `once_cell::unsync::OnceCell` to
`IoSource`, making it `!Sync`, which, by definition, makes `&IoSource`
`!Send` and so (nearly) any future that does IO will be `!Send`.

This commit removes the `OnceCell` from `IoSource`, making it `Sync`
again. Instead, we eagerly check whether a backing file is a block
device when the file is converted to an `AsyncDisk` so that the result
is a plain `bool` and move the branch into `SingleDiskFile::punch_hole`.

The other `AsyncDisk` implementors don't need this logic.
"android_sparse" is read-only (i.e. you can't punch a hole).
"composite_disk" delegates hole punching to the backing disk.
"qcow" might benefit from it, but it doesn't use async yet, so
there is no regression.

BUG=b:271297810

Change-Id: Ifd1d2361adabfd4db1b48e71d3a3a31e57a0cfb1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5086673
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-12-15 19:40:13 +00:00
Dennis Kempin
73aed77b49 Run rustfmt on whole codebase with nightly enabled
Nigthly is enabled as part of https://crrev.com/c/4950268
This change contains the formatting changes resulting from the switch.

BUG=b:302055317
TEST=dev_container presubmit format --no-delta

Change-Id: Idaf2b8bae2e09c624b19d9cd3dd5fc8e4d099b3c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5067088
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2023-11-29 18:41:29 +00:00
Daniel Verkamp
fcc28f5573 data_model: move IoBuf and VolatileMemory to base
IoBuf is defined in a platform-specific way (it is either iovec on unix
or WSABUF for windows), so it fits into the mission statement of the
base crate, which is meant to be *the* platform abstraction layer in
crosvm.

IoBufMut and VolatileMemory/VolatileSlice are defined in terms of IoBuf,
so they are also moved into base for consistency. Every crate that uses
these types already depended on base, so no extra dependencies are
added, and a few can be removed.

BUG=b:312312646
TEST=tools/dev_container tools/presubmit

Change-Id: I4dddc55d46906dfc55b88e8e6a967d7e1c1922dd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5046605
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-11-27 21:42:49 +00:00
Takaya Saeki
dd2769b549 base: move PunchHoleMut from disk crate to base crate
`PunchHoleMut` trait is defined in the disk crate, but the base crate is
more suitable since `PunchHole` is defined by the base. This change
moves `PunchHoleMut` to base.

BUG=None
TEST=./tools/presubmit

Change-Id: Iee3eb48c88e58e4f54118bedde62a78fa9ff05dc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5019622
Commit-Queue: Takaya Saeki <takayas@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-11-20 09:56:30 +00:00
Takaya Saeki
85f1221536 cros_async: remove fallocate from IoSource and delegate it to base
Currently, cros_async's async IO source provides async `fallocate`
function, and `punch_hole` and `write_zeroes_at` are delegated to
`fallocate`. However, this design has three rooms for improvements.
1. Actually, no one calls async `fallocate`.
2. We have duplicated `fallocate` and `AllocateMode` implementations in
   `base::sys`.
3. Windows has to pretend to have `fallocate` to provide `punch_hole`
   and `write_zeroes_at`

So, this change removes `fallocate` and `AllocateMode`, which no one
actually calls, from `IoSource` and deletegate it to `base::sys`. With
this, we don't have to maintain `fallocate` implementation in
cros_async.

This will also enable us to call a non-`fallocate` systemcall in
`punch_hole` implementation which will be necessary to correctly support
block files.

BUG=b:302437024
TEST=./tools/presubmit

Change-Id: I8e7fcd94380da980cc52e6f751b134fa325d7b39
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5019241
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Takaya Saeki <takayas@chromium.org>
2023-11-14 07:12:11 +00:00
Alyssa Ross
d9bc6e99ff Fix tests with non-4K pages
Change-Id: Ifc242d81fbaa7022554b96a9bb181ae390f231d7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5017868
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-11-10 23:26:00 +00:00
Vikram Auradkar
a35c24c3d0 block: introduce a way to use overlapped source
BUG=b:303249046
TEST=tested downstream

Change-Id: If436c5bff6a44d6dbebb6e0aa2bf9e743dd25f59
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4950198
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2023-10-25 16:29:00 +00:00
A. Cody Schuffelen
4748c54b95 Rename "unix" to "linux" in code and docs
$ for DIR in $(find . -name "unix"); do mv $DIR $(echo $DIR | sed "s/unix/linux/"); done
$ for FILE in $(find . -name "unix.rs"); do mv $FILE $(echo $FILE | sed "s/unix/linux/"); done
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -E -i "s/mod unix/mod linux/g" {}
$ find . -type f -not -path '*/\.git/*' -not -path '*/third_party/perfetto/*' | xargs -I {} sed -E -i "s/([^o][^s])::unix/\1::linux/g" {}
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -E -i "s/use unix::/use linux::/g" {}
$ find . -type f -not -path '*/\.git/*' -not -path '*/third_party/perfetto/*' | xargs -I {} sed -E -i "s/sys::unix/sys::linux/g" {}
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -E -i "s/use unix as platform/use linux as platform/g" {}

Test: ./tools/dev_container ./tools/presubmit
Bug: b/298269162
Change-Id: I2c8acb14d77a5588dab4eae124f4a9afbb9025f5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4909060
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2023-10-11 01:15:07 +00:00
A. Cody Schuffelen
97dff044f8 Replace #[cfg(unix)] with #[cfg(any(target_os = "android", target_os = "linux"))]
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>
2023-10-11 00:43:29 +00:00
Zihan Chen
cbba480ebe crosvm: Uprev zerocopy to 0.7.x
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>
2023-10-10 17:34:32 +00:00
Daniel Verkamp
03dd1feab7 Cargo.toml: depend on zerocopy 0.6 explicitly
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>
2023-09-20 21:28:58 +00:00
Junichi Uekawa
8d83d0d1c1 crosvm: Rename to open_file_or_duplicate.
open_file does not always open_file. It reuses given fd when it points
to a special path /proc/self/fd/XX.

BUG=b:291832160
TEST=build

Change-Id: If821834e3adbc457616c71e5b8425962286245e7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4706830
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
2023-07-24 01:30:27 +00:00
Daniel Verkamp
ce5a78e83b clippy fixes for Rust 1.70 and 1.71
Change-Id: If86c6cd531b854293a93208de5254664f5ee6bec
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4637612
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-07-13 20:29:05 +00:00
Frederick Mayle
49794f44da virtio: block: flush disk image as part of sleep
This is mainly for qcow2, which doesn't immediately write all mutations
to file. It is important that all writes be sent to the OS so that
snapshots taken while asleep do not lose information.

BUG=b:266514327
TEST=patched into AOSP and manually ran snapshot-restore flow

Change-Id: I2a9f24120d51fd053ff1440d0e1750e9bbebf379
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4679843
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Elie Kheirallah <khei@google.com>
2023-07-12 22:26:17 +00:00
Daniel Verkamp
024a5e44f2 cros_async: add MemRegion iterator
MemRegionIter allows iteration over a &[MemRegion] list, with additional
helper functions to skip bytes and truncate the list.

In particular, this is useful for the virtio DescriptorChain utilities
(Reader/Writer) that previously needed to call collect() to allocate a
new copy of the regions list when it was necessary to limit the length
or skip part of the beginning of the chain.

This also replaces the functionality of MemRegion::truncate(), which
used Cow<[MemRegion]>, meaning it would sometimes need to allocate and
copy. The new MemRegionIter implementation never needs to copy the list
of regions; it just maintains a couple of internal counters and adjusts
the returned MemRegions on the fly.

BUG=None
TEST=tools/dev_container tools/presubmit
TEST=cargo test -p cros_async

Change-Id: Ie66c7a8c4061a166c986c6d6937e21549ddb205e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4559367
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-06-28 19:45:38 +00:00
Zihan Chen
a62b3f33e4 disk/android_sparse: Remove DataInit usage
TEST=CQ

BUG=b:204409584

Change-Id: I7d0998d3749cd09b45ba00a588158c0f4fb78846
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4618948
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
2023-06-15 19:56:37 +00:00
Takaya Saeki
7781380f01 devices: virtio: block: use fdatasync for FLUSH
Currently, virtio-blk translates a FLUSH request to fsync system call.
However, fsync always updates the metadata of a file, which causes extra
journaling for metadata update. Since virtio-blk cares only the data of
the given block image file, we should avoid updating extra metadata.

After this change, virtio-blk now calls fdatasync for a FLUSH request.
If a write operation wrote to a data block that is already allocated
before, fdatasync can avoid triggering jdb2 journaling on an ext4 file
system.

Note there are structs which fall back to fsync for fdatasync. In
addition, io_uring executor does not implement fdatasync yet.

We observed statistically significant play_store_shown_time improvement
on trogdor-arc-r by -1.614% with this change. Including non
statistically significant data, we observed the following improvements.

|         Name          |  delta  | Count |
|-----------------------|---------|-------|
| trogdor-arc-r (lazor) | -1.614% |  170  |
| brya-arc-t (primus)   | -1.478% |  200  |
| octopus-arc-t (apel)  | -0.887% |  190  |
| kukui-arc-r (kakadu)  | -0.451% |  170  |

BUG=b:281609112
TEST=run a vm with block and confirmed fdatasync is called by strace

Change-Id: Idc94a3ec169e9a5e04394079967f6d79ff4c32db
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4523029
Commit-Queue: Takaya Saeki <takayas@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-05-12 18:15:54 +00:00
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