diff --git a/base/src/lib.rs b/base/src/lib.rs index 2b2151477b..7207de3ea1 100644 --- a/base/src/lib.rs +++ b/base/src/lib.rs @@ -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 diff --git a/base/src/write_zeroes.rs b/base/src/write_zeroes.rs index 6489afc694..e98410b07a 100644 --- a/base/src/write_zeroes.rs +++ b/base/src/write_zeroes.rs @@ -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 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 diff --git a/disk/src/asynchronous.rs b/disk/src/asynchronous.rs index 62471cb0ca..e2738f3a09 100644 --- a/disk/src/asynchronous.rs +++ b/disk/src/asynchronous.rs @@ -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 { @@ -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 diff --git a/disk/src/qcow/mod.rs b/disk/src/qcow/mod.rs index 7b1670b9fb..59ed62eeaa 100644 --- a/disk/src/qcow/mod.rs +++ b/disk/src/qcow/mod.rs @@ -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 { - self.punch_hole_mut(offset, length as u64)?; + self.punch_hole(offset, length as u64)?; Ok(length) } }