From ec5916daa056b2ad68a5dc2a7c604299aa3e2c8f Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 7 Oct 2019 13:06:22 -0700 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1845948 Tested-by: kokoro Reviewed-by: Stephen Barber --- devices/src/virtio/block.rs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) (limited to 'devices/src/virtio/block.rs') 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, -- cgit 1.4.1