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

Method refcount_block

block/src/qcow/refcount.rs:233–260  ·  view source on GitHub ↗

Returns the refcounts stored in the given block.

(
        &mut self,
        raw_file: &mut QcowRawFile,
        table_index: usize,
    )

Source from the content-addressed store, hash-verified

231
232 /// Returns the refcounts stored in the given block.
233 pub fn refcount_block(
234 &mut self,
235 raw_file: &mut QcowRawFile,
236 table_index: usize,
237 ) -> Result<Option<&[u64]>> {
238 let block_addr_disk = *self.ref_table.get(table_index).ok_or(Error::InvalidIndex)?;
239 if block_addr_disk == 0 {
240 return Ok(None);
241 }
242 if !self.refblock_cache.contains_key(table_index) {
243 let table = VecCache::from_vec(
244 raw_file
245 .read_refcount_block(block_addr_disk)
246 .map_err(Error::ReadingRefCounts)?,
247 );
248 // TODO(dgreid) - closure needs to return an error.
249 let ref_table = &self.ref_table;
250 self.refblock_cache
251 .insert(table_index, table, |index, evicted| {
252 raw_file.write_refcount_block(ref_table[index], evicted.get_values())
253 })
254 .map_err(Error::EvictingRefCounts)?;
255 }
256 // The index must exist as it was just inserted if it didn't already.
257 Ok(Some(
258 self.refblock_cache.get(table_index).unwrap().get_values(),
259 ))
260 }
261
262 // Gets the address of the refcount block and the index into the block for the given address.
263 fn get_refcount_index(&self, address: u64) -> (usize, usize) {

Callers

nothing calls this directly

Calls 6

read_refcount_blockMethod · 0.80
write_refcount_blockMethod · 0.80
get_valuesMethod · 0.80
getMethod · 0.45
contains_keyMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected