summary refs log tree commit diff
path: root/devices/src/virtio/block.rs
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2019-10-07 13:06:22 -0700
committerCommit Bot <commit-bot@chromium.org>2019-10-29 22:06:22 +0000
commitec5916daa056b2ad68a5dc2a7c604299aa3e2c8f (patch)
treea28c4c670fb0a52b31534e28fe0cfbeb0c18e710 /devices/src/virtio/block.rs
parentf1e69259f747232054f7439e10d79705537a54e1 (diff)
downloadcrosvm-ec5916daa056b2ad68a5dc2a7c604299aa3e2c8f.tar
crosvm-ec5916daa056b2ad68a5dc2a7c604299aa3e2c8f.tar.gz
crosvm-ec5916daa056b2ad68a5dc2a7c604299aa3e2c8f.tar.bz2
crosvm-ec5916daa056b2ad68a5dc2a7c604299aa3e2c8f.tar.lz
crosvm-ec5916daa056b2ad68a5dc2a7c604299aa3e2c8f.tar.xz
crosvm-ec5916daa056b2ad68a5dc2a7c604299aa3e2c8f.tar.zst
crosvm-ec5916daa056b2ad68a5dc2a7c604299aa3e2c8f.zip
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>
Diffstat (limited to 'devices/src/virtio/block.rs')
-rw-r--r--devices/src/virtio/block.rs21
1 files changed, 9 insertions, 12 deletions
diff --git a/devices/src/virtio/block.rs b/devices/src/virtio/block.rs
index a2a1d3d..2288849 100644
--- a/devices/src/virtio/block.rs
+++ b/devices/src/virtio/block.rs
@@ -601,15 +601,14 @@ impl Block {
                     .checked_shl(u32::from(SECTOR_SHIFT))
                     .ok_or(ExecuteError::OutOfRange)?;
                 check_range(offset, data_len as u64, disk_size)?;
-                disk.seek(SeekFrom::Start(offset))
-                    .map_err(|e| ExecuteError::Seek { ioerr: e, sector })?;
-                let actual_length = writer.write_from(disk, data_len).map_err(|desc_error| {
-                    ExecuteError::ReadIo {
-                        length: data_len,
-                        sector,
-                        desc_error,
-                    }
-                })?;
+                let actual_length =
+                    writer
+                        .write_from_at(disk, data_len, offset)
+                        .map_err(|desc_error| ExecuteError::ReadIo {
+                            length: data_len,
+                            sector,
+                            desc_error,
+                        })?;
                 if actual_length < data_len {
                     return Err(ExecuteError::ShortRead {
                         sector,
@@ -624,11 +623,9 @@ impl Block {
                     .checked_shl(u32::from(SECTOR_SHIFT))
                     .ok_or(ExecuteError::OutOfRange)?;
                 check_range(offset, data_len as u64, disk_size)?;
-                disk.seek(SeekFrom::Start(offset))
-                    .map_err(|e| ExecuteError::Seek { ioerr: e, sector })?;
                 let actual_length =
                     reader
-                        .read_to(disk, data_len)
+                        .read_to_at(disk, data_len, offset)
                         .map_err(|desc_error| ExecuteError::WriteIo {
                             length: data_len,
                             sector,