diff options
Diffstat (limited to 'disk/src/composite.rs')
-rw-r--r-- | disk/src/composite.rs | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/disk/src/composite.rs b/disk/src/composite.rs index c3cca00..cd048c1 100644 --- a/disk/src/composite.rs +++ b/disk/src/composite.rs @@ -13,7 +13,9 @@ use crate::{create_disk_file, DiskFile, DiskGetLen, ImageType}; use data_model::VolatileSlice; use protos::cdisk_spec; use remain::sorted; -use sys_util::{AsRawFds, FileReadWriteAtVolatile, FileSetLen, FileSync, PunchHole, WriteZeroesAt}; +use sys_util::{ + AsRawFds, FileAllocate, FileReadWriteAtVolatile, FileSetLen, FileSync, PunchHole, WriteZeroesAt, +}; #[sorted] #[derive(Debug)] @@ -292,6 +294,27 @@ impl PunchHole for CompositeDiskFile { } } +impl FileAllocate for CompositeDiskFile { + fn allocate(&mut self, offset: u64, length: u64) -> io::Result<()> { + let range = offset..(offset + length); + let disks = self.disks_in_range(&range); + for disk in disks { + let intersection = range_intersection(&range, &disk.range()); + if intersection.start >= intersection.end { + continue; + } + let result = disk.file.allocate( + intersection.start - disk.offset, + intersection.end - intersection.start, + ); + if result.is_err() { + return result; + } + } + Ok(()) + } +} + impl WriteZeroesAt for CompositeDiskFile { fn write_zeroes_at(&mut self, offset: u64, length: usize) -> io::Result<usize> { let cursor_location = offset; |