mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-06 02:25:23 +00:00
disk: Make AsyncDisk trait's interface align with sys_util
* Make AsyncDisk as a supertrait of some sys_util's traits * Rename write_zeroes to write_zeroes_at BUG=none TEST=cargo test Change-Id: I714d82092b3ee2930383541b67b958dc1a7cf441 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2340732 Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org> Tested-by: Keiichi Watanabe <keiichiw@chromium.org> Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
This commit is contained in:
parent
f32d0b48fd
commit
cdc9f57e47
1 changed files with 11 additions and 14 deletions
|
@ -341,16 +341,7 @@ pub fn create_disk_file(raw_image: File) -> Result<Box<dyn DiskFile>> {
|
|||
|
||||
/// An asynchronously accessible disk.
|
||||
#[async_trait(?Send)]
|
||||
pub trait AsyncDisk {
|
||||
/// Returns the length of the disk image.
|
||||
fn get_len(&self) -> io::Result<u64>;
|
||||
|
||||
/// Sets the length of the disk image. Similar to ftruncate.
|
||||
fn set_len(&self, len: u64) -> io::Result<()>;
|
||||
|
||||
/// Allocates storage for the region of the file starting at `offset` and extending `len` bytes.
|
||||
fn allocate(&mut self, offset: u64, len: u64) -> io::Result<()>;
|
||||
|
||||
pub trait AsyncDisk: DiskGetLen + FileSetLen + FileAllocate {
|
||||
/// Returns the inner file consuming self.
|
||||
fn into_inner(self: Box<Self>) -> Box<dyn ToAsyncDisk>;
|
||||
|
||||
|
@ -378,7 +369,7 @@ pub trait AsyncDisk {
|
|||
async fn punch_hole(&self, file_offset: u64, length: u64) -> Result<()>;
|
||||
|
||||
/// Writes up to `length` bytes of zeroes to the stream, returning how many bytes were written.
|
||||
async fn write_zeroes(&self, file_offset: u64, length: u64) -> Result<()>;
|
||||
async fn write_zeroes_at(&self, file_offset: u64, length: u64) -> Result<()>;
|
||||
}
|
||||
|
||||
use cros_async::PollOrRing;
|
||||
|
@ -397,20 +388,26 @@ impl TryFrom<File> for SingleFileDisk {
|
|||
}
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl AsyncDisk for SingleFileDisk {
|
||||
impl DiskGetLen for SingleFileDisk {
|
||||
fn get_len(&self) -> io::Result<u64> {
|
||||
self.inner.get_len()
|
||||
}
|
||||
}
|
||||
|
||||
impl FileSetLen for SingleFileDisk {
|
||||
fn set_len(&self, len: u64) -> io::Result<()> {
|
||||
self.inner.set_len(len)
|
||||
}
|
||||
}
|
||||
|
||||
impl FileAllocate for SingleFileDisk {
|
||||
fn allocate(&mut self, offset: u64, len: u64) -> io::Result<()> {
|
||||
self.inner.allocate(offset, len)
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
impl AsyncDisk for SingleFileDisk {
|
||||
fn into_inner(self: Box<Self>) -> Box<dyn ToAsyncDisk> {
|
||||
Box::new(self.inner.into_source())
|
||||
}
|
||||
|
@ -454,7 +451,7 @@ impl AsyncDisk for SingleFileDisk {
|
|||
.map_err(Error::Fallocate)
|
||||
}
|
||||
|
||||
async fn write_zeroes(&self, file_offset: u64, length: u64) -> Result<()> {
|
||||
async fn write_zeroes_at(&self, file_offset: u64, length: u64) -> Result<()> {
|
||||
if self
|
||||
.inner
|
||||
.fallocate(
|
||||
|
|
Loading…
Reference in a new issue