From e67195ce481c182887306852992e869b6fe1cfe5 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 16 Apr 2026 22:44:57 +0200 Subject: [PATCH] block: qcow: Test sub sector O_DIRECT read Verify that a 512 byte read from an allocated cluster succeeds with O_DIRECT. This exercises the synchronous fallback path in resolve_read() that is taken when alignment is nonzero. Signed-off-by: Anatol Belski --- block/src/qcow_async.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/block/src/qcow_async.rs b/block/src/qcow_async.rs index 390b863e9..cbcd62042 100644 --- a/block/src/qcow_async.rs +++ b/block/src/qcow_async.rs @@ -1032,4 +1032,25 @@ mod unit_tests { let async_io = disk.new_async_io(1).unwrap(); assert!(async_io.alignment() >= SECTOR_SIZE); } + + #[test] + fn test_qcow_async_sub_sector_read_with_direct_io() { + let temp_file = TempFile::new().unwrap(); + let disk = match try_create_direct_io_disk(&temp_file, 100 * 1024 * 1024) { + Some(d) => d, + None => { + eprintln!("skipping: O_DIRECT not supported on this filesystem"); + return; + } + }; + + let pattern = vec![0xAB; 65536]; + async_write(&disk, 0, &pattern); + + let buf = async_read(&disk, 0, 512); + assert!( + buf.iter().all(|&b| b == 0xAB), + "sub-sector O_DIRECT read should return written data" + ); + } }