diff options
author | Daniel Verkamp <dverkamp@chromium.org> | 2020-01-15 12:53:43 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-01-24 20:22:47 +0000 |
commit | 977f873a4140c29f838712e6f37137df4f0cd840 (patch) | |
tree | f194b4f166c1995f5ef7e482e36a51c5a5db96c3 /disk/src/composite.rs | |
parent | e43d300aef5fa4cc6eaf8539580acce1e2990a98 (diff) | |
download | crosvm-977f873a4140c29f838712e6f37137df4f0cd840.tar crosvm-977f873a4140c29f838712e6f37137df4f0cd840.tar.gz crosvm-977f873a4140c29f838712e6f37137df4f0cd840.tar.bz2 crosvm-977f873a4140c29f838712e6f37137df4f0cd840.tar.lz crosvm-977f873a4140c29f838712e6f37137df4f0cd840.tar.xz crosvm-977f873a4140c29f838712e6f37137df4f0cd840.tar.zst crosvm-977f873a4140c29f838712e6f37137df4f0cd840.zip |
sys_util: add FileAllocate trait
This trait provides a generic interface for allocating space on the filesystem within a given file. It is equivalent to the fallocate(2) system call with the default mode (mode = 0). BUG=chromium:858815 TEST=cargo build --features=composite-disk Change-Id: I2f4e8aceb4878790e8dec2e3d539071915efd205 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2015828 Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
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; |