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

Method cluster_allocated

block/src/qcow/mod.rs:1630–1653  ·  view source on GitHub ↗

Returns true if the cluster containing `address` is already allocated.

(&mut self, address: u64)

Source from the content-addressed store, hash-verified

1628
1629 // Returns true if the cluster containing `address` is already allocated.
1630 fn cluster_allocated(&mut self, address: u64) -> std::io::Result<bool> {
1631 if address >= self.virtual_size() {
1632 return Err(std::io::Error::from_raw_os_error(EINVAL));
1633 }
1634
1635 let l1_index = self.l1_table_index(address) as usize;
1636 let l2_addr_disk = *self
1637 .l1_table
1638 .get(l1_index)
1639 .ok_or_else(|| std::io::Error::from_raw_os_error(EINVAL))?;
1640 let l2_index = self.l2_table_index(address) as usize;
1641
1642 if l2_addr_disk == 0 {
1643 // The whole L2 table for this address is not allocated yet,
1644 // so the cluster must also be unallocated.
1645 return Ok(false);
1646 }
1647
1648 self.cache_l2_cluster(l1_index, l2_addr_disk, false)?;
1649
1650 let cluster_addr = self.l2_cache.get(l1_index).unwrap()[l2_index];
1651 // If cluster_addr != 0, the cluster is allocated.
1652 Ok(cluster_addr != 0)
1653 }
1654
1655 // Find the first guest address greater than or equal to `address` whose allocation state
1656 // matches `allocated`.

Callers 1

Calls 5

virtual_sizeMethod · 0.45
l1_table_indexMethod · 0.45
getMethod · 0.45
l2_table_indexMethod · 0.45
cache_l2_clusterMethod · 0.45

Tested by

no test coverage detected