From 135ee4568eb841838261bfd95a6ede001b86a7de Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Thu, 2 Jul 2020 09:26:34 +0100 Subject: [PATCH] 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 --- tests/integration.rs | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/integration.rs b/tests/integration.rs index 9f30809cd..1c0931278 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -116,11 +116,33 @@ mod tests { } fn rate_limited_copy, Q: AsRef>(from: P, to: Q) -> io::Result { - 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; }