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

Function combo_write_read_common

block/src/qcow/mod.rs:3795–3839  ·  view source on GitHub ↗
(direct: bool)

Source from the content-addressed store, hash-verified

3793 }
3794
3795 fn combo_write_read_common(direct: bool) {
3796 with_default_file(1024 * 1024 * 1024 * 256, direct, |mut qcow_file| {
3797 const NUM_BLOCKS: usize = 555;
3798 const BLOCK_SIZE: usize = 0x1_0000;
3799 const OFFSET: usize = 0x1_0000_0020;
3800 let data = [0x55u8; BLOCK_SIZE];
3801 let mut readback = [0u8; BLOCK_SIZE];
3802 for i in 0..NUM_BLOCKS {
3803 let seek_offset = OFFSET + i * BLOCK_SIZE;
3804 qcow_file
3805 .seek(SeekFrom::Start(seek_offset as u64))
3806 .expect("Failed to seek.");
3807 let nwritten = qcow_file.write(&data).expect("Failed to write test data.");
3808 assert_eq!(nwritten, BLOCK_SIZE);
3809 // Read back the data to check it was written correctly.
3810 qcow_file
3811 .seek(SeekFrom::Start(seek_offset as u64))
3812 .expect("Failed to seek.");
3813 let nread = qcow_file.read(&mut readback).expect("Failed to read.");
3814 assert_eq!(nread, BLOCK_SIZE);
3815 for (orig, read) in data.iter().zip(readback.iter()) {
3816 assert_eq!(orig, read);
3817 }
3818 }
3819 // Check that address 0 is still zeros.
3820 qcow_file.rewind().expect("Failed to seek.");
3821 let nread = qcow_file.read(&mut readback).expect("Failed to read.");
3822 assert_eq!(nread, BLOCK_SIZE);
3823 for read in readback.iter() {
3824 assert_eq!(*read, 0);
3825 }
3826 // Check the data again after the writes have happened.
3827 for i in 0..NUM_BLOCKS {
3828 let seek_offset = OFFSET + i * BLOCK_SIZE;
3829 qcow_file
3830 .seek(SeekFrom::Start(seek_offset as u64))
3831 .expect("Failed to seek.");
3832 let nread = qcow_file.read(&mut readback).expect("Failed to read.");
3833 assert_eq!(nread, BLOCK_SIZE);
3834 for (orig, read) in data.iter().zip(readback.iter()) {
3835 assert_eq!(orig, read);
3836 }
3837 }
3838 });
3839 }
3840
3841 fn seek_cur(file: &mut QcowFile) -> u64 {
3842 file.stream_position().unwrap()

Callers 2

combo_write_readFunction · 0.85
combo_write_read_directFunction · 0.85

Calls 5

with_default_fileFunction · 0.85
iterMethod · 0.80
seekMethod · 0.45
writeMethod · 0.45
readMethod · 0.45

Tested by 2

combo_write_readFunction · 0.68
combo_write_read_directFunction · 0.68