mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-21 19:02:30 +00:00
tests: Enhance rate_limited_copy() to also consider free disk space
With QCOW disk images the space needed is greater than the size of the iamge as any "zero" blocks in the image are allocated when they are touched making the image bigger. Here we add a threshold of 6GiB with added debugging messages to ensure that there is sufficient disk space to run the tests. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
8820e9e133
commit
135ee4568e
@ -116,11 +116,33 @@ mod tests {
|
||||
}
|
||||
|
||||
fn rate_limited_copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<u64> {
|
||||
for _ in 0..10 {
|
||||
for i in 0..10 {
|
||||
let free_bytes = unsafe {
|
||||
let mut stats = std::mem::MaybeUninit::zeroed();
|
||||
let fs_name = std::ffi::CString::new("/tmp").unwrap();
|
||||
libc::statvfs(fs_name.as_ptr(), stats.as_mut_ptr());
|
||||
|
||||
let free_blocks = stats.assume_init().f_bfree;
|
||||
let block_size = stats.assume_init().f_bsize;
|
||||
|
||||
free_blocks * block_size
|
||||
};
|
||||
|
||||
// Make sure there is at least 6 GiB of space
|
||||
if free_bytes < 6 << 30 {
|
||||
eprintln!(
|
||||
"Not enough space on disk ({}). Attempt {} of 10. Sleeping.",
|
||||
free_bytes, i
|
||||
);
|
||||
thread::sleep(std::time::Duration::new(60, 0));
|
||||
continue;
|
||||
}
|
||||
|
||||
match fs::copy(&from, &to) {
|
||||
Err(e) => {
|
||||
if let Some(errno) = e.raw_os_error() {
|
||||
if errno == libc::ENOSPC {
|
||||
eprintln!("Copy returned ENOSPC. Attempt {} of 10. Sleeping.", i);
|
||||
thread::sleep(std::time::Duration::new(60, 0));
|
||||
continue;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user