Commit graph

180 commits

Author SHA1 Message Date
Keiichi Watanabe
4b0f24e4ef Automatic clippy fix for Rust 1.88
To prepare for Rust toolchain uprev, ran `tools/clippy --fix` with
Rust 1.88 for each platform.
To build with the current Rust version 1.81, some changes with unstable
features were manually reverted.

BUG=b:455879436
TEST=CQ

Change-Id: I4a91460d4fc2de5d7afbc2da04b7f7765219bb2e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/7089630
Reviewed-by: David Stevens <stevensd@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2025-11-17 10:25:21 -08:00
Elie Kheirallah
2329aa5b07 disk: allocate error only if hit in disk_at_offset
Only allocate errors if they are hit as opposed to always allocating the
error.

BUG=b:440153729
TEST=presubmit

Change-Id: I3aa902e4925cd73c02e9b08765fdaf72340b6aa7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6886671
Reviewed-by: Frederick Mayle <fmayle@google.com>
Auto-Submit: Elie Kheirallah <khei@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2025-08-26 14:22:58 -07:00
A. Cody Schuffelen
afaa8be303 Workspace deps grab bag
- anyhow
- argh
- cfg-if
- enumn
- gdbstub
- gdbstub_arch
- rand
- remain
- serde
- serde_json
- thiserror

This level of indirection makes it possible to centrally update the
versions of these dependencies.

Bug: b/418050464
Change-Id: I4223e83d33ea527ed3bab8028ad16160e3fa0364
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6551986
Auto-Submit: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2025-05-16 11:26:38 -07:00
A. Cody Schuffelen
f34a4abcbb Use workspace dependencies: crosvm workspace crates
Exclusions:
- perfetto
- sandbox
- rutabaga_gfx/ffi
- rutabaga_gfx/kumquat/gpu_client

This adds a level of indirection for internal crate dependencies, making
it less of a hassle to move a crate or add a new feature that is
universally enabled.

Continuation of crrev.com/c/6551983

Partially mechanically generated via
```
$ for TARGET in aarch64 aarch64_sys_reg acpi_tables android_audio anti_tamper arch argh_helpers audio_streams audio_streams_conformance_test audio_util balloon_control base base_tokio bit_field broker_ipc catapult_converter crash_report cros_async cros_fdt cros_tracing crosvm_cli crosvm_control crosvm_plugin crypto data_model devices disk e2e_tests ext2 ffmpeg fuse fuzz gpu_display hypervisor hypervisor_test_macro io_uring kernel_cmdline kernel_loader kvm kvm_sys libcras_stub linux_input_sys metrics metrics_events net_sys net_util power_monitor prebuilts proto_build_tools protos resources rutabaga_gfx serde_keyvalue snapshot swap sync system_api usb_sys usb_util vfio_sys vhost virtio_sys vm_control vm_memory vmm_vhost x86_64; do
  sed -i "s/^$TARGET =.*path[^,]\\+$/$TARGET = { workspace = true }/" $(find . -name Cargo.toml) && git restore Cargo.toml
  sed -i "s/^$TARGET =.*path[^,]\\+,/$TARGET = { workspace = true,/" $(find . -name Cargo.toml) && git restore Cargo.toml;
done
$ git restore perfetto
$ git restore sandbox
$ git restore rutabaga_gfx/ffi
$ git restore rutabaga_gfx/kumquat/gpu_client
```

Bug: b/418050464
Change-Id: I529b1a23128f19459b89e248a7c96ae2e487a441
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6554153
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2025-05-15 19:26:10 -07:00
A. Cody Schuffelen
83cec09245 Use workspace dependencies: libc
This allows all members of the workspace to depend on `libc` using
```
base = { workspace = true }
```
as opposed to the current collection of multiple numbered versions,
which had this distribution:
```
$ rg 'libc =' --no-filename --no-line-number | sort | uniq -c | sort -nr
      33 libc = "0.2"
      3 libc = "0.2.93"
      2 libc = "0.2.65"
      2 libc = "0.2.44"
      1 libc = { version = "0.2", features = ["extra_traits"] }
      1 libc = ">=0.2.39"
      1 libc = "0.2.153"
      1 libc = "0.2.116"
      1 libc = "*"
```

See:
- https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6544746/comments/c2fb58d3_1430749b
- https://doc.rust-lang.org/cargo/reference/workspaces.html#the-dependencies-table
- https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace

Bug: b/418050464
Change-Id: I61438cbfe47b18621ce00791a892af9a56d91fd7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6551984
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2025-05-15 17:53:02 -07:00
A. Cody Schuffelen
2eb1a03271 Use workspace dependencies: base
This allows all members of the workspace to depend on `base` using
```
base = { workspace = true }
```
as opposed to the current distribution:
```
$ rg 'base =' -g Cargo.toml --no-filename --no-line-number | sort | uniq -c | sort -nr
     43 base = { path = "../base" }
      4 base = { path = "../../../base" }
      2 base = { path = "../../base" }
      1 base = { path = "base" }
      1 base = { path = "../base/" }
```

See:
- https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6544746/comments/c2fb58d3_1430749b
- https://doc.rust-lang.org/cargo/reference/workspaces.html#the-dependencies-table
- https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace

Bug: b/418050464
Change-Id: I1439fd1a5b99233a36a30a9c542abcf54ce5ac1c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6551983
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2025-05-15 17:52:56 -07:00
Elie Kheirallah
2e16335044 disk: optimize writes to use BufWriter for header/footer
Buffer writes, producing less syscalls.

BUG=N/A
TEST=presubmit

Change-Id: I1ac161a978933d93c9f4a4c70bfccc6109beea4d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6521184
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Elie Kheirallah <khei@google.com>
2025-05-08 17:03:53 -07:00
Frederick Mayle
936e71c2c1 disk: composite: support fdatasync
We don't track "needs fsync" vs "needs fdatasync" because, as mentioned
in the original fdatasync commit (https://crrev.com/c/4523029), we don't
care about the file metadata in our use cases.

BUG=b:281609112

Change-Id: Icff7254d92e5d202557cba8bcce44dc360fb5e07
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6306252
Reviewed-by: Takaya Saeki <takayas@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2025-02-27 10:59:57 -08:00
Daniel Verkamp
f20af151e2 crosvm: upgrade zerocopy to 0.8
BUG=b:372549215
TEST=tools/dev_container tools/presubmit

Change-Id: I3fcc524d1c6c41ae92c51cecb6e4d856c3d60670
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6255229
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2025-02-24 11:35:51 -08:00
A. Cody Schuffelen
22e2cece64 Standardize on anyhow = "1" in Cargo.toml files
There was some variation before, with `anyhow = "1"` as the most common
target.

```
$ rg 'anyhow =' --no-filename --no-line-number | sort | uniq -c
      2 anyhow = "*"
     31 anyhow = "1"
      2 anyhow = "1.0"
      7 anyhow = "1.0.32"
      1 anyhow = "1.0.57"
      1 anyhow = "1.0.75"
```

With this change, everything has been aligned to the most common target.

```
$ rg 'anyhow =' --no-filename --no-line-number | sort | uniq -c
     44 anyhow = "1"
```

(Specifically the `anyhow = "*"` lines were giving me trouble with
b/394932208 and cl/723721713, I can change this to standardize on
something else if desired)

Bug: b/394932208
Change-Id: Iea4fa3d020fe5646aa9f444de50645195a1b9778
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6238753
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2025-02-06 15:07:09 -08:00
Daniel Verkamp
3ecb9a048a [clippy] use div_ceil() and next_multiple_of()
Replace open-coded reimplementations of these rounding-related math
functions where applicable (mostly identified as candidates for
div_ceil() by Rust 1.84 clippy, but in some cases, next_multiple_of()
was a better match).

Change-Id: Ib851689836cb8d44cde5a5766a3cec8fd5c90f40
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6195237
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2025-02-05 15:21:55 -08:00
Frederick Mayle
8e5ed65d77 disk: more create_composite_disk testing
Change-Id: Id245cd6184727cbf95908f9f6bf60d00f8b87530
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6222593
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2025-02-03 16:16:32 -08:00
Frederick Mayle
36a6855e36 disk: composite: fix secondary GPT header location
The secondary GPT header should be at the end of the image, but its
offset was chosen before the disk size was aligned to 64k. This caused
Linux to print warnings at boot, like

    GPT:Primary header thinks Alt. header is not at the end of the disk.
    GPT:105736 != 105855
    GPT:Alternate GPT header not at the end of the disk.
    GPT:105736 != 105855
    GPT: Use GNU Parted to correct GPT errors.

It is likely there was no practical issue besides the log noise.

As part of the fix, we no longer align the disk size to 64k. It is
unclear why we aligned to 64k to begin with and maintaining that
alignment made the appropriate fix more complicated.

Change-Id: I2f41a2033f14d34e2fd3dd3dd3afe2da80266196
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6036619
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2025-01-31 18:21:34 -08:00
Zihan Chen
5fb76bcee7 disk: Add basic cache to zstd decoder
Many reads issued by kernel is smaller than 128KB (our default frame
size). When doing sequential reads with 4K size, the current
implementation can lead to up to 32x decompression overhead due to
decompressing the same frame consecutively read again and again.
This single frame cache solves this issue.

On my very fast workstation, 4k read speed 453->829MB/s, 128k read
speed 618->838MB/s. For reference, 1 thread zstd decompress on host
of the same file is 1292MB/s. I expect much larger improvement on
CPU-bounded devices (e.g. many chromebooks).

TESTED=observed correct result when run `ls -lR` on mounted zstd disk
TESTED=`sha256sum` of files are correct

Change-Id: I9a3be6c34d3256bf5e222e3375e70e9b9dda761a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6036328
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2025-01-24 13:39:51 -08:00
Andrew Walbran
d11cbfae1e Prepare for thiserror 2.0.
TEST=cargo build

Change-Id: Ib3799b860477f85306e03fad8bd43e7110632a9f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6089577
Auto-Submit: Andrew Walbran <qwandor@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-12-13 11:05:25 -08:00
Zihan Chen
13b958b967 disk: Add seekable zstd disk support
A raw disk image can be compressed as a seekable zstd and attached
transaprently to a VM as a block device.

TESTED=can ro mount and read seekable compressed debian rootfs

BUG=b:377945783

Change-Id: Iba1950dbfc0ba99b0581e842964848d5a447b824
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6024317
Commit-Queue: Zihan Chen <zihanchen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Zihan Chen <zihanchen@google.com>
2024-11-22 21:13:38 +00:00
Frederick Mayle
b32355490c disk: more detailed create_composite_disk unit test
Change-Id: I2ab63ce9b6e01a6593388cdb94d1e9df8f8b259b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/6036618
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-11-20 19:38:15 +00:00
Daniel Verkamp
4abcdf6b45 disk: qcow: read table clusters in a single I/O
The previous implementation of QcowRawFile::read_pointer_table() called
read_exact() on the underlying File for each individual entry in the
table; for a typical 64KB cluster size, this would mean read() would be
called 8192 times per cluster. Similarly, read_refcount_block() would
issue 32768 individual read() calls per cluster.

Using zerocopy, we can read the whole Vec<u64> or Vec<u16> reinterpreted
as a byte slice in a single read() call, then perform endian translation
and masking in a separate loop, which should be significantly more
efficient.

Change-Id: Ia66f4b9363be63935388adaa185a31b515f47951
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5977144
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-10-30 00:31:03 +00:00
Daniel Verkamp
aa25762cd1 disk: qcow: flush BufWriter before dropping
As mentioned in the docs[1], we should be flushing the BufWriter to
ensure we can catch write errors.

[1]: https://doc.rust-lang.org/std/io/struct.BufWriter.html

Change-Id: I7b9d9f306618692fc5cb1c93f0c7ff7aa87c6e16
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5977146
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-10-30 00:15:45 +00:00
Frederick Mayle
511af5a116 disk: windows: restrict file sharing
This makes the behavior closer to Linux (which uses flock).

Change-Id: Iff587b58647eec7378972e5442d4da95f3e2b7a8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5841071
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-10-07 21:30:55 +00:00
Frederick Mayle
5921c375cc disk: add option to disable file locking
The recent changes to make crosvm lock nested disk files is running
afoul of Android Virtualization Framework's SELinux policies. The file
locking doesn't add much value in that environement because all the
shared files are read-only, so add an opt-out for locking to buy us time
to re-engineer the policies.

BUG=b:330911976

Change-Id: I0b35732978e946a2331507d6061729d53955a8d3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5849284
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-09-10 22:07:48 +00:00
Frederick Mayle
d7b16c03b6 disk: composite: propagate read-only param
In practice this probably only matters for the flock calls because, when
a disk is read-only, the block device should never issue write calls to
it to begin with.

BUG=b:330911976

Change-Id: I9fc4e8e09e9c5a51f53ec342fae1c69c984999c0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5838023
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-09-09 20:43:44 +00:00
Frederick Mayle
6cde4e3b9e disk: consolidate disk file opening logic
The disk crate is now responsible for opening the file and handling
options like OVERLAPPED and O_DIRECT.

O_DIRECT is now applied to all nested disk files. For now, OVERLAPPED
contiues to only apply to the root disk file.

BUG=b:330911976
BUG=b:190435784

Change-Id: Ib46a965c0589bf1c1e8e4ae5f0c81747530eff98
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5842394
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-09-09 20:39:03 +00:00
Frederick Mayle
6b965beb80 disk: use flock on nested disk files
flock is called on the root disk file to make sure nothing is
concurrently modifying a disk (which would appear to the guest as disk
corruption). This CL extends that functionality to all of the nested
files of composite and qcow2 disks.

BUG=b:330911976

Change-Id: I4489222943c3530255ffc52aba5a11aa4bc82f9a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5840920
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-09-09 20:37:08 +00:00
Frederick Mayle
312ce69076 disk: minor QcowFile::new_from_backing cleanup
new_from_header will open the backing file as part of the normal code
path, we don't need to manually insert it into the resulting QcowFile
object.

Change-Id: I06dfa0954b9ac4b8b18fc43b3047d684088ceef8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5840919
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-09-09 20:29:46 +00:00
Frederick Mayle
2b9ea3f859 disk: pass more disk options to nested DiskFiles
No behavior difference intended. This is prep work to treat nested
DiskFiles consistently, e.g. using flock for them.

BUG=b:330911976

Change-Id: Id887ca21a9d5d186ba4dc77280c1ce4bfec8b319
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5840918
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-09-09 20:29:41 +00:00
Jiyong Park
b5d19dbaf2 Add support for partition GUID
Note that this CL doesn't mandate specifying the partition GUID. If
partition GUID is omitted, it will be automatically created as before.

The commandline interface has changed but in a backwards compatible
manner. The argument synatax for 'composite-disk' command is

LABEL:PATH:[writable]:[uuid]

BUG=352244386
TEST=tools/dev_container tools/presubmit

Change-Id: Ibf5ba0c2a3aa16e8c9393943c2fee0c71c38ed25
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5690989
Commit-Queue: Jiyong Park <jiyong@google.com>
Auto-Submit: Jiyong Park <jiyong@google.com>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
2024-07-11 01:15:29 +00:00
Daniel Verkamp
dc310d7cb6 Replace ::max_value() with ::MAX
The max_value() function is considered to be a "legacy numeric constant"
now, and future clippy versions will warn about it:

<https://rust-lang.github.io/rust-clippy/master/index.html#legacy_numeric_constants>

BUG=None
TEST=tools/clippy # with rust-toolchain = "1.79"

Change-Id: I72a333dc4aa1f48cf71744c848f050097a7e7f55
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5690374
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2024-07-09 23:26:03 +00:00
Daniel Verkamp
4f7b7de714 base: remove get_filesystem_type()
This was used in a single informational log statement when opening a
disk image, which was added for debugging an issue and is no longer
needed. It was also only ever implemented for Linux and not other
platforms.

BUG=None
TEST=tools/dev_container tools/presubmit

Change-Id: Id77244a883b6bb4b90ee1a909fa305ab4193c17e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5656451
Reviewed-by: Noah Gold <nkgold@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-06-25 22:24:10 +00:00
Frederick Mayle
456fe75fad devices: virtio-blk: don't stop the worker thread on sleep/reset
The cros_async Overlapped I/O implementation on Windows does not support
roundtripping from AsyncDisk to DiskFile and then back to AsyncDisk
again with a new executor instance because, once a file is added to an
IOCP instance, it is permanently associated with that instance.
Attempting to add it to new IOCP instance results in an error.

It is possible to workaround this by changing the cros_async API so that
we can keeping using the same IOCP instance when we restart the worker
thread, but we decided that is too complex.

Instead, we'll just keep the worker thread running indefinitely. Since
`AsyncDisk::into_inner` isn't portable, we delete it so that someone in
the future doesn't accidentally design their code around it.

The main new complexity in the code is support for swapping out the
active `Interrupt` in the worker thread. Technically crosvm seems to
always resend the same `Interrupt` object, but it seems best to not make
any assumptions.

BUG=b:301269927

Change-Id: Iee0492d18fe640f45ae08ed946536b9a9dd6f525
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5640657
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Noah Gold <nkgold@google.com>
2024-06-21 02:02:13 +00:00
Daniel Verkamp
79ad1c82b2 disk: qcow: test CacheMap::get()
This exercises more of the CacheMap API, and it also silences a clippy
warning about the value inside the test's NumCache structure being
unused.

BUG=b:344974550
TEST=cargo test -p disk --features=qcow
TEST=tools/clippy

Change-Id: I4cbee164fdd7c0bc662c804c50482d118ec05df3
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5626478
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-06-18 18:15:26 +00:00
Daniel Verkamp
7cf3dcacbf Fix clippy::suspicious_open_options warnings
Use .create_new() rather than .create() for cases where we always want
to ensure that the file does not already exist, and add .truncate(false)
for a case where we do want to open an existing file and don't want to
overwrite it.

BUG=b:344974550
TEST=tools/clippy

Change-Id: Ie82a6db306532c600c140efab3d310b6c7cf25a7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5604660
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-06-10 19:39:47 +00:00
Daniel Verkamp
52b8e42869 Cargo.toml: avoid "*" versions for external crates
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>
2024-05-22 01:01:42 +00:00
Daniel Verkamp
92665a611f Cargo.toml: move tempfile to dev-dependencies
The tempfile crate is only used in tests, so it does not need to be in
the main [dependencies] section of any of our first-party crates.

Also fix a couple of [dev_dependencies] instances to the officially
documented [dev-dependencies] name for consistency.

BUG=None
TEST=cargo tree

Change-Id: I1dcb6be10c302baec4e8ebe6f72480f76e4e3760
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5521511
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-05-07 20:00:48 +00:00
Frederick Mayle
c736d23241 disk: remove mutex from AsyncDiskFileWrapper
The disk traits no longer require exclusive refs. It might be reasonable
to forgo the blocking thread as well, but I'm leaving it as is for now.

BUG=b:338274203

Change-Id: I286c8983a7e850b3aa96c96d9388c77d1c9b7f04
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507758
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-05-02 19:32:31 +00:00
Frederick Mayle
f909e42679 base: don't require &mut for File{Sync,Allocate} methods
Was only needed for QcowFile, which can now use its internal mutex.

BUG=b:338274203

Change-Id: I7db283cb946508daf8fd7bd8cf9397aa7f97a478
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507757
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-05-02 19:32:26 +00:00
Frederick Mayle
5381cc2b66 base: don't require &mut for WriteZeroesAt methods
Was only needed for QcowFile, which can now use its internal mutex.

BUG=b:338274203

Change-Id: Iff684f5a25b0f488b006e05eebe913f92f404a2b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507756
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-05-02 19:32:21 +00:00
Frederick Mayle
8515568a51 base: don't require &mut for FileReadWriteAtVolatile methods
Was only needed for QcowFile, which can now use its internal mutex.

BUG=b:338274203

Change-Id: I810b537e971bf007b6b34f0cbc605f2b3943a763
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507754
Commit-Queue: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-05-02 19:32:17 +00:00
Frederick Mayle
1cbaa32809 base: delete PunchHoleMut trait
Was only needed for QcowFile, which can now use its internal mutex.

BUG=b:338274203

Change-Id: I995cf646a66909b9b146b9a7c0ff7d5a8348acd7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507755
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-05-02 19:32:09 +00:00
Frederick Mayle
4189f738b0 disk: qcow: add internal mutex
A lot of disk traits require exclusive references to file-like objects
for operations that are generally threadsafe, e.g. you ought to be able
to have an `Arc<File>` and perform pread/pwrite-like operations from
multiple threads concurrently.

Qcow files are the only case stopping us from changing these APIs. This
patch adds a big lock inside of the implementation. Follow up patches
will make use of that lock to switch various APIs from `&mut self` to
`&self`.

There is already a big lock around qcow files in AsyncDiskFileWrapper
and that lock will go away after all the APIs are switched over, so it
is unlikely there will be a performance penalty in the end.

BUG=b:338274203

Change-Id: Ifbac628395ab64eb9a327ceba31e03fd6ba2c192
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507753
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Frederick Mayle <fmayle@google.com>
2024-05-02 19:32:03 +00:00
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