From 6208f3caee063ec1f813d237cd39934b365575bb Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 30 Mar 2026 23:16:36 +0200 Subject: [PATCH] block: qcow: Test async read of unallocated region Add a QcowAsync unit test that reads from a range that was never written. Verifies the fundamental QCOW contract that unallocated clusters return zeroes. Signed-off-by: Anatol Belski --- block/src/qcow_async.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/block/src/qcow_async.rs b/block/src/qcow_async.rs index 4501502a9..bdc4fe341 100644 --- a/block/src/qcow_async.rs +++ b/block/src/qcow_async.rs @@ -839,4 +839,22 @@ mod unit_tests { assert_eq!(read_a, write_a, "batch read A should match written data"); assert_eq!(read_b, write_b, "batch read B should match written data"); } + + #[test] + fn test_qcow_async_read_unallocated() { + let file_size = 100 * 1024 * 1024; + let temp_file = TempFile::new().unwrap(); + { + let raw_file = RawFile::new(temp_file.as_file().try_clone().unwrap(), false); + QcowFile::new(raw_file, 3, file_size, true).unwrap(); + } + let disk = QcowDiskAsync::new(temp_file.as_file().try_clone().unwrap(), false, false, true) + .unwrap(); + + let buf = async_read(&disk, 0, 128 * 1024); + assert!( + buf.iter().all(|&b| b == 0), + "unallocated region should read as zeroes" + ); + } }