diff options
author | Daniel Verkamp <dverkamp@chromium.org> | 2019-10-07 12:41:00 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-10-29 22:06:22 +0000 |
commit | f1e69259f747232054f7439e10d79705537a54e1 (patch) | |
tree | dfb4004348c26c296c82c3d45326df09899103d6 /qcow | |
parent | 83e13683e462f21171e221ffc56c38e525ca04dd (diff) | |
download | crosvm-f1e69259f747232054f7439e10d79705537a54e1.tar crosvm-f1e69259f747232054f7439e10d79705537a54e1.tar.gz crosvm-f1e69259f747232054f7439e10d79705537a54e1.tar.bz2 crosvm-f1e69259f747232054f7439e10d79705537a54e1.tar.lz crosvm-f1e69259f747232054f7439e10d79705537a54e1.tar.xz crosvm-f1e69259f747232054f7439e10d79705537a54e1.tar.zst crosvm-f1e69259f747232054f7439e10d79705537a54e1.zip |
qcow: implement FileReadWriteAtVolatile trait
BUG=None TEST=cargo test -p qcow Change-Id: I9c64435999b7a5f91dd60bdd3723f18986d8e96f Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1845946 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Chirantan Ekbote <chirantan@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'qcow')
-rw-r--r-- | qcow/src/qcow.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/qcow/src/qcow.rs b/qcow/src/qcow.rs index d45bbe6..19ed922 100644 --- a/qcow/src/qcow.rs +++ b/qcow/src/qcow.rs @@ -10,7 +10,8 @@ use data_model::{VolatileMemory, VolatileSlice}; use libc::{EINVAL, ENOSPC, ENOTSUP}; use remain::sorted; use sys_util::{ - error, FileReadWriteVolatile, FileSetLen, FileSync, PunchHole, SeekHole, WriteZeroes, + error, FileReadWriteAtVolatile, FileReadWriteVolatile, FileSetLen, FileSync, PunchHole, + SeekHole, WriteZeroes, }; use std::cmp::{max, min}; @@ -1529,6 +1530,28 @@ impl FileReadWriteVolatile for QcowFile { } } +impl FileReadWriteAtVolatile for QcowFile { + fn read_at_volatile(&mut self, slice: VolatileSlice, offset: u64) -> io::Result<usize> { + self.read_cb(offset, slice.size() as usize, |file, offset, count| { + let sub_slice = slice.get_slice(offset as u64, count as u64).unwrap(); + match file { + Some(f) => f.read_exact_volatile(sub_slice), + None => { + sub_slice.write_bytes(0); + Ok(()) + } + } + }) + } + + fn write_at_volatile(&mut self, slice: VolatileSlice, offset: u64) -> io::Result<usize> { + self.write_cb(offset, slice.size() as usize, |file, offset, count| { + let sub_slice = slice.get_slice(offset as u64, count as u64).unwrap(); + file.write_all_volatile(sub_slice) + }) + } +} + impl FileSync for QcowFile { fn fsync(&mut self) -> std::io::Result<()> { self.flush() |