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

Method get_new_cluster

block/src/qcow/mod.rs:1589–1618  ·  view source on GitHub ↗

Allocate a new cluster and return its offset within the raw file.

(&mut self, initial_data: Option<Vec<u8>>)

Source from the content-addressed store, hash-verified

1587
1588 // Allocate a new cluster and return its offset within the raw file.
1589 fn get_new_cluster(&mut self, initial_data: Option<Vec<u8>>) -> std::io::Result<u64> {
1590 // First use a pre allocated cluster if one is available.
1591 if let Some(free_cluster) = self.avail_clusters.pop() {
1592 if free_cluster == 0 {
1593 self.set_corrupt_bit_best_effort();
1594 return Err(io::Error::from_raw_os_error(EIO));
1595 }
1596 if let Some(initial_data) = initial_data {
1597 self.raw_file.write_cluster(free_cluster, &initial_data)?;
1598 } else {
1599 self.raw_file.zero_cluster(free_cluster)?;
1600 }
1601 return Ok(free_cluster);
1602 }
1603
1604 let max_valid_cluster_offset = self.refcounts.max_valid_cluster_offset();
1605 if let Some(new_cluster) = self.raw_file.add_cluster_end(max_valid_cluster_offset)? {
1606 if new_cluster == 0 {
1607 self.set_corrupt_bit_best_effort();
1608 return Err(io::Error::from_raw_os_error(EIO));
1609 }
1610 if let Some(initial_data) = initial_data {
1611 self.raw_file.write_cluster(new_cluster, &initial_data)?;
1612 }
1613 Ok(new_cluster)
1614 } else {
1615 error!("No free clusters in get_new_cluster()");
1616 Err(std::io::Error::from_raw_os_error(ENOSPC))
1617 }
1618 }
1619
1620 // Allocate and initialize a new data cluster. Returns the offset of the
1621 // cluster into the file on success.

Callers 4

update_cluster_addrMethod · 0.45
append_data_clusterMethod · 0.45
cache_l2_clusterMethod · 0.45
set_cluster_refcountMethod · 0.45

Calls 6

write_clusterMethod · 0.80
zero_clusterMethod · 0.80
add_cluster_endMethod · 0.80
popMethod · 0.45

Tested by

no test coverage detected