MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / deallocate_bytes

Method deallocate_bytes

block/src/qcow/mod.rs:1816–1839  ·  view source on GitHub ↗

Deallocate the storage for `length` bytes starting at `address`. Any future reads of this range will return all zeroes.

(&mut self, address: u64, length: usize)

Source from the content-addressed store, hash-verified

1814 // Deallocate the storage for `length` bytes starting at `address`.
1815 // Any future reads of this range will return all zeroes.
1816 fn deallocate_bytes(&mut self, address: u64, length: usize) -> std::io::Result<()> {
1817 let write_count: usize = self.limit_range_file(address, length);
1818
1819 let mut nwritten: usize = 0;
1820 while nwritten < write_count {
1821 let curr_addr = address + nwritten as u64;
1822 let count = self.limit_range_cluster(curr_addr, write_count - nwritten);
1823
1824 if count == self.raw_file.cluster_size() as usize {
1825 // Full cluster - deallocate the storage.
1826 self.deallocate_cluster(curr_addr)?;
1827 } else {
1828 // Partial cluster - zero out the relevant bytes if it was allocated.
1829 // Any space in unallocated clusters can be left alone, since
1830 // unallocated clusters already read back as zeroes.
1831 let offset = self.file_offset_write(curr_addr)?;
1832 // Partial cluster - zero it out.
1833 self.raw_file.file_mut().write_zeroes_at(offset, count)?;
1834 }
1835
1836 nwritten += count;
1837 }
1838 Ok(())
1839 }
1840
1841 // Reads an L2 cluster from the disk, returning an error if the file can't be read or if any
1842 // cluster is compressed.

Callers 1

punch_holeMethod · 0.45

Calls 7

limit_range_fileMethod · 0.80
limit_range_clusterMethod · 0.80
file_offset_writeMethod · 0.80
file_mutMethod · 0.80
cluster_sizeMethod · 0.45
deallocate_clusterMethod · 0.45
write_zeroes_atMethod · 0.45

Tested by

no test coverage detected