Commit graph

24 commits

Author SHA1 Message Date
Dylan Reid
be88444c55 disk: Add Asyncdisk Trait
The AsyncDisk Trait will be used by block to issue asynchronous
operations on kernels that support async IO.

TEST=Added unit tests

Cq-Depend: chromium:2265040
Change-Id: I83adb83df278c4d19ac5dd4e5b91fb5bf96d4e89
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2306785
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
2020-07-30 03:16:43 +00:00
Daniel Verkamp
ddd8180a13 Fix VolatileSlice calls in all modules
The VolatileSlice API changed, but some callers were not updated to
match.  Fix them up so that builds with additional features enabled
(e.g. kokoro) pass again.

BUG=None
TEST=cargo test -p disk --features=composite-disk
TEST=docker/wrapped_smoke_test.sh

Change-Id: I97b3cd04549af30b7dc1515245f025d9439669bc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2216399
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-05-27 04:46:31 +00:00
Chirantan Ekbote
e7d1221c9d Make VolatileSlice ABI-compatible with iovec
Change VolatileSlice so that it is ABI-compatible with iovec.  This
allows us to directly pass in a VolatileSlice for a C function that
expects an iovec without having to create temporaries that convert from
one to the other.

Also change all the parameters from u64 to usize.  It's not possible to
address more memory than fits into a usize so having u64 here didn't
really provide much benefit and led to a lot of tedious casting back and
forth all over the place.

BUG=none
TEST=unit tests

Cq-Depend: chromium:2206621
Change-Id: I258f9123c603d9a4c6c5e2d4d10eb4aedf74466d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2203998
Tested-by: Chirantan Ekbote <chirantan@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
2020-05-25 19:14:07 +00:00
Daniel Verkamp
e1952dd7d4 Remove redundant single-component imports
Fix clippy 1.43.0 clippy::single-component-path-imports warnings.

BUG=None
TEST=bin/clippy

Change-Id: I3f4f54138bedce16dc1ca937bb8bc00a94594f69
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2163203
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-04-26 00:15:36 +00:00
Daniel Verkamp
fcf078c38a disk: resolve iter_nth_zero clippy warning
Replace .nth(0) with .next() to resolve this:

  error: called `.nth(0)` on a `std::iter::Iterator`

BUG=None
TEST=bin/clippy

Change-Id: I103e8b44b1564708d92d096aaf044db7f67d1ba8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2151147
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
2020-04-18 12:01:29 +00:00
A. Cody Schuffelen
f3081b120e Fix performance problem on Android Sparse images
This was adding ~11 minutes to the boot time with sparse images.

BUG=b:151981838
TEST=launch cuttlefish with sparse images.

Change-Id: I707258566aee338f742a3a5fe94d0bad8302c447
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2111117
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2020-04-07 23:03:40 +00:00
A. Cody Schuffelen
dfd0139d7c Better errors on missing composite disk components.
When there is an error opening one of the composite disk components now,
it gives the message `failed to open component file: "No such file or
directory (os error 2)"` without specifying the file path it tried to
use. Exposing the file path will make it faster to act on errors, rather
than trying to examine the composite disk file for paths.

TEST=n/a
BUG=b:150150052

Change-Id: I9341b330e7e6dcd517d5bfb5262b1657a2da46fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2072738
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2020-02-26 02:23:10 +00:00
A. Cody Schuffelen
f1f20f59be Support the Android Sparse disk format
Android defines its own "sparse disk" format, which its images are
usually published in. Cuttlefish has special-cased this to build raw
images in the android build system, but it still causes a performance
hit when downloading and extracting the image zip files. Experimentally,
running bsdtar on the zip file of raw images is about 50 seconds slower
than bsdtar on the equivalent zip file of android sparse images.

These disks can only be opened as read-only, as the Android Sparse
format is designed around writing once then interpreting the contents
while flashing a physical device through e.g. fastboot.

TEST=Run with aosp/1184800 on cuttlefish, unit tests
BUG=b:145841395
Change-Id: I13337b042e92841bd3cba88dc8b231fde88c091e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1956487
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2020-02-25 20:28:09 +00:00
A. Cody Schuffelen
5ad3bc3459 Initialize qcow clusters off the backing file when present
This preserves any data that the backing file had on a cluster when
doing a write to a subset of that cluster. These writes cause a
performance penalty on creating new clusters if a backing file is
present.

TEST=unit tests
BUG=b:140069322
Change-Id: I724990225617c05e5f2dea39e39ce84c940328fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1982832
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-25 20:28:07 +00:00
A. Cody Schuffelen
d8144a56e2 Read from the backing file if present on read miss
Reads to qcow files with backing files will fall through to the backing
file if there is no allocated cluster. As of this change, a write will
still trash the cluster and hide any data already present.

TEST=unit tests
BUG=b:140069322
Change-Id: Iba353fa1e7c25bb6267eb96b30b8f5a6ac61d423
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1982831
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-02-21 21:52:56 +00:00
A. Cody Schuffelen
9ca6039b03 Support generating and opening backing files
The new functionality can be invoked through
"crosvm create_qcow2 --backing_file=backing new_file".

The old behavior of creating a qcow image with a particular size is
still available with its original syntax.

This is relevant to implement as by default something like qemu-img will
create a new image that assumes the backing file is raw or qcow, while
crosvm can use its knowledge of other formats (such as composite disk,
and later android sparse) to determine the true size of the backing
file.

TEST=unit tests
BUG=b:140069322
Change-Id: I22de6a79c6d8566a9fcb0bc8124e2d74fea9ca55
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1982833
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-02-21 21:52:53 +00:00
Daniel Verkamp
977f873a41 sys_util: add FileAllocate trait
This trait provides a generic interface for allocating space on the
filesystem within a given file.  It is equivalent to the fallocate(2)
system call with the default mode (mode = 0).

BUG=chromium:858815
TEST=cargo build --features=composite-disk

Change-Id: I2f4e8aceb4878790e8dec2e3d539071915efd205
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2015828
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-01-24 20:22:47 +00:00
A. Cody Schuffelen
e058314700 Use DiskFile in read_cb
This will allow passing in other data sources for the qcow read methods,
without adding extra copies.

TEST=Unit tests
BUG=b:140069322
Change-Id: I2815fa6e416b554968b97959e4b6cd4c93a722f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1982829
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
2020-01-22 07:50:03 +00:00
A. Cody Schuffelen
e99b6c7e81 Make DiskFile, CompositeDisk Debug
Making DiskFile Debug allows placing it inside the QcowFile.

TEST=Compiles
BUG=b:140069322
Change-Id: Idf20b7909146b0c2a60d864da386e362e8be97a4
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1982828
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2020-01-22 07:50:01 +00:00
Daniel Verkamp
d5aa995423 disk: use seek to determine file length
Add a new disk-specific DiskGetLen trait which uses io::Seek instead of
File::metadata() to determine the length so that it works on raw block
devices (e.g. /dev/sda) as well as regular files.

BUG=b:146811529
TEST=`crosvm run --disk /dev/sda` and verify block device length

Change-Id: I6936863490efaa479a3c8745c75c373748c800a1
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1990855
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Trent Begin <tbegin@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-01-13 21:16:29 +00:00
Daniel Verkamp
f2eecc4152 disk: move qcow into disk crate
Move qcow from being its own crate into a module of the disk crate,
similar to the composite disk module.

This will allow use of qcow from disk and vice versa without introducing
a circular crate dependency.

BUG=None
TEST=./build_test.py
TEST=USE='asan fuzzer' emerge-nami crosvm

Change-Id: I77512bbe4b94faff1b5460f9796ee56505135580
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1972477
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2020-01-06 21:26:38 +00:00
Daniel Verkamp
4cc280bcff disk: add get_len() to eliminate need for Seek
This new trait allows DiskFile implementors to provide the length of the
file directly rather than using SeekFrom::End with seek().

BUG=None
TEST=./build_test
TEST=Boot Termina in crosvm

Change-Id: I9447ebb43dbd5fbb32a3a6b6d2fc969b9406cdbc
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913961
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-11-27 21:22:41 +00:00
Daniel Verkamp
624c51bee3 disk: switch from WriteZeroes to WriteZeroesAt
This eliminates an extra seek per guest write zeroes request.

Additionally, it allows us to stop depending on the file cursor and pass
the offset directly, making multi-queue implementation easier.

BUG=chromium:858815
TEST=Boot Termina in crosvm

Change-Id: I8b15a39752a1b68597a2b1e1fd72382a484a3cb2
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913521
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-11-27 21:22:40 +00:00
Daniel Verkamp
bdd708edd2 disk: fix composite unit test build
This was unintentionally broken when changing ReadWriteVolatile to
ReadWriteVolatileAt (the composite unit tests aren't built or run by
default since they are behind a feature flag).

BUG=None
TEST=cargo test --features=composite-disk -p disk

Change-Id: I864d7063bd27a401c3d878fcd22b52e2357fde8d
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1913960
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
2019-11-25 06:36:36 +00:00
Daniel Verkamp
32f22987c8 disk: replace into_iter() with equivalent iter()
Fixes clippy warning:

  warning: this .into_iter() call is equivalent to .iter() and will not
  move the slice

BUG=None
TEST=bin/clippy

Change-Id: I5361495f02609dd5e5313b7bc792e663841212ad
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1896091
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-11-08 22:18:19 +00:00
Daniel Verkamp
ec5916daa0 devices: virtio: block: use FileReadWriteAtVolatile
Use the "at" variants of the read/write functions in the block device.
This reduces the number of syscalls on the host per I/O to one
(pread64/pwrite64) rather than two (lseek + read/write).

The CompositeDiskFile implementation is also updated in this commit,
since it's both a producer and consumer of DiskFile, and it isn't
trivial to update it in a separate commit without breaking compilation.

BUG=None
TEST=Start Crostini on kevin, banon, and nami

Change-Id: I031e7e87cd6c99504db8c56b1725ea51c1e27a53
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1845948
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen Barber <smbarber@chromium.org>
2019-10-29 22:06:22 +00:00
Cody Schuffelen
f9b035d50c Support composite disks.
This adds a new disk file type next to raw files and qcow images that
represent an indirection to further raw disk files. The disk file
itself is a proto file with references to file paths for other disks to
open and their virtual offsets and lengths.

The intention is to make it easy to assemble a single virtual hard disk
out of several distinct partition files. In the particular case of
Cuttlefish running Android in a VM, this is relevant as the Android
build system distributes partitions as separate raw files. While the
simple solution is to pass each partition as a separate raw disk, some
functionality (like the bootloader) assumes there is a partition table
with multiple distinct partitions on a single disk.

Implementing composite disk support in the VMM bridges this gap through
supporting the general-purpose case of a disk built out of multiple
component files.

If desired, this can be extended to support qcow files to support
unusual configurations like a mixed qcow/raw disk.

Enabled with the "composite-disk" feature.

Bug: b/133432409
Change-Id: I2b0c47d92fab13b5dc0ca5a960c7cfd2b7145b87
Signed-off-by: Cody Schuffelen <schuffelen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1667767
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-10-03 00:59:14 +00:00
Cody Schuffelen
30c5a9ef0b Replace "AsRawFd" with "AsRawFds" for disks.
This supports virtio disks that depend on multiple file descriptors. All
of the file descriptors are passed to the jail when relevant.

Bug: b/133432409
Change-Id: Idf2e24cd2984c0d12a47a523c13d24c1ba8d173e
Signed-off-by: Cody Schuffelen <schuffelen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1691761
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-30 16:08:58 +00:00
Cody Schuffelen
7d533e5952 Extract disk creation logic out of qcow and src.
Bug: b/133432409
Change-Id: Iba25d5f6bb5f60619bb2f5a3d72ddfd3a81650b4
Signed-off-by: Cody Schuffelen <schuffelen@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1691460
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
2019-08-28 23:52:36 +00:00