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

Function create_qcow_tempfile

performance-metrics/src/util.rs:38–51  ·  view source on GitHub ↗

Create a QCOW2 image with `num_clusters` allocated clusters and return the tempfile handle. Each cluster is default QCOW2 cluster size of 64 KiB. The image is created via `QcowFile::new` then populated with writes so that the clusters are actually allocated in the L2 / refcount tables.

(num_clusters: usize)

Source from the content-addressed store, hash-verified

36/// created via `QcowFile::new` then populated with writes so that the
37/// clusters are actually allocated in the L2 / refcount tables.
38fn create_qcow_tempfile(num_clusters: usize) -> TempFile {
39 let tmp = TempFile::new().expect("failed to create tempfile");
40 let virtual_size = QCOW_CLUSTER_SIZE * num_clusters as u64;
41 let raw = RawFile::new(tmp.as_file().try_clone().unwrap(), false);
42 let mut qcow = QcowFile::new(raw, 3, virtual_size, true).expect("failed to create QCOW2 file");
43 let buf = vec![0xA5u8; QCOW_CLUSTER_SIZE as usize];
44 for i in 0..num_clusters {
45 qcow.seek(SeekFrom::Start(i as u64 * QCOW_CLUSTER_SIZE))
46 .expect("seek failed");
47 qcow.write_all(&buf).expect("write failed");
48 }
49 qcow.flush().expect("flush failed");
50 tmp
51}
52
53/// Create a QCOW2 image with `num_clusters` allocated clusters opened
54/// via QcowDisk with synchronous backend.

Callers 2

qcow_tempfileFunction · 0.85
qcow_async_tempfileFunction · 0.85

Calls 4

newFunction · 0.85
try_cloneMethod · 0.45
seekMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected