mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-28 09:33:01 +00:00
base: delete PunchHoleMut trait
Was only needed for QcowFile, which can now use its internal mutex. BUG=b:338274203 Change-Id: I995cf646a66909b9b146b9a7c0ff7d5a8348acd7 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5507755 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Frederick Mayle <fmayle@google.com>
This commit is contained in:
parent
4189f738b0
commit
1cbaa32809
4 changed files with 10 additions and 26 deletions
|
@ -80,7 +80,6 @@ pub use wait_context::TriggeredEvent;
|
|||
pub use wait_context::WaitContext;
|
||||
pub use worker_thread::WorkerThread;
|
||||
pub use write_zeroes::PunchHole;
|
||||
pub use write_zeroes::PunchHoleMut;
|
||||
pub use write_zeroes::WriteZeroesAt;
|
||||
|
||||
// TODO(b/233233301): reorganize platform specific exports under platform
|
||||
|
|
|
@ -19,18 +19,6 @@ impl PunchHole for File {
|
|||
}
|
||||
}
|
||||
|
||||
/// A trait for deallocating space in a file of a mutable reference
|
||||
pub trait PunchHoleMut {
|
||||
/// Replace a range of bytes with a hole.
|
||||
fn punch_hole_mut(&mut self, offset: u64, length: u64) -> io::Result<()>;
|
||||
}
|
||||
|
||||
impl<T: PunchHole> PunchHoleMut for T {
|
||||
fn punch_hole_mut(&mut self, offset: u64, length: u64) -> io::Result<()> {
|
||||
self.punch_hole(offset, length)
|
||||
}
|
||||
}
|
||||
|
||||
/// A trait for writing zeroes to an arbitrary position in a file.
|
||||
pub trait WriteZeroesAt {
|
||||
/// Write up to `length` bytes of zeroes starting at `offset`, returning how many bytes were
|
||||
|
|
|
@ -13,7 +13,7 @@ use base::AsRawDescriptors;
|
|||
use base::FileAllocate;
|
||||
use base::FileSetLen;
|
||||
use base::FileSync;
|
||||
use base::PunchHoleMut;
|
||||
use base::PunchHole;
|
||||
use base::RawDescriptor;
|
||||
use base::WriteZeroesAt;
|
||||
use cros_async::BackingMemory;
|
||||
|
@ -84,7 +84,7 @@ impl<
|
|||
+ FileAllocate
|
||||
+ FileSetLen
|
||||
+ FileSync
|
||||
+ PunchHoleMut
|
||||
+ PunchHole
|
||||
+ WriteZeroesAt,
|
||||
> AsyncDisk for AsyncDiskFileWrapper<T>
|
||||
{
|
||||
|
@ -186,9 +186,9 @@ impl<
|
|||
let inner_clone = self.inner.clone();
|
||||
self.blocking_pool
|
||||
.spawn(move || {
|
||||
let mut disk_file = inner_clone.lock();
|
||||
let disk_file = inner_clone.lock();
|
||||
disk_file
|
||||
.punch_hole_mut(file_offset, length)
|
||||
.punch_hole(file_offset, length)
|
||||
.map_err(Error::IoPunchHole)
|
||||
})
|
||||
.await
|
||||
|
|
|
@ -27,7 +27,7 @@ use base::FileAllocate;
|
|||
use base::FileReadWriteAtVolatile;
|
||||
use base::FileSetLen;
|
||||
use base::FileSync;
|
||||
use base::PunchHoleMut;
|
||||
use base::PunchHole;
|
||||
use base::RawDescriptor;
|
||||
use base::VolatileMemory;
|
||||
use base::VolatileSlice;
|
||||
|
@ -1244,10 +1244,7 @@ impl QcowFileInner {
|
|||
// This cluster is no longer in use; deallocate the storage.
|
||||
// The underlying FS may not support FALLOC_FL_PUNCH_HOLE,
|
||||
// so don't treat an error as fatal. Future reads will return zeros anyways.
|
||||
let _ = self
|
||||
.raw_file
|
||||
.file_mut()
|
||||
.punch_hole_mut(cluster_addr, cluster_size);
|
||||
let _ = self.raw_file.file().punch_hole(cluster_addr, cluster_size);
|
||||
self.unref_clusters.push(cluster_addr);
|
||||
}
|
||||
Ok(())
|
||||
|
@ -1617,9 +1614,9 @@ impl FileAllocate for QcowFile {
|
|||
}
|
||||
}
|
||||
|
||||
impl PunchHoleMut for QcowFile {
|
||||
fn punch_hole_mut(&mut self, offset: u64, length: u64) -> std::io::Result<()> {
|
||||
let inner = self.inner.get_mut();
|
||||
impl PunchHole for QcowFile {
|
||||
fn punch_hole(&self, offset: u64, length: u64) -> std::io::Result<()> {
|
||||
let mut inner = self.inner.lock();
|
||||
let mut remaining = length;
|
||||
let mut offset = offset;
|
||||
while remaining > 0 {
|
||||
|
@ -1634,7 +1631,7 @@ impl PunchHoleMut for QcowFile {
|
|||
|
||||
impl WriteZeroesAt for QcowFile {
|
||||
fn write_zeroes_at(&mut self, offset: u64, length: usize) -> io::Result<usize> {
|
||||
self.punch_hole_mut(offset, length as u64)?;
|
||||
self.punch_hole(offset, length as u64)?;
|
||||
Ok(length)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue