From dd79b1899d657c0c18b1a9ac5bf34039677ee965 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 16 Apr 2026 22:41:53 +0200 Subject: [PATCH] block: qcow: Test async alignment() with O_DIRECT Verify that QcowAsync reports at least SECTOR_SIZE alignment when O_DIRECT is active. Skipped on filesystems that do not support O_DIRECT (e.g. tmpfs). Signed-off-by: Anatol Belski --- block/src/qcow_async.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/block/src/qcow_async.rs b/block/src/qcow_async.rs index 16272f496..390b863e9 100644 --- a/block/src/qcow_async.rs +++ b/block/src/qcow_async.rs @@ -1009,4 +1009,27 @@ mod unit_tests { let async_io = disk.new_async_io(1).unwrap(); assert_eq!(async_io.alignment(), SECTOR_SIZE); } + + /// Returns None if O_DIRECT is not supported (e.g. tmpfs). + fn try_create_direct_io_disk(temp_file: &TempFile, file_size: u64) -> Option { + { + let raw_file = RawFile::new(temp_file.as_file().try_clone().unwrap(), false); + QcowFile::new(raw_file, 3, file_size, true).unwrap(); + } + QcowDiskAsync::new(temp_file.as_file().try_clone().unwrap(), true, false, true).ok() + } + + #[test] + fn test_qcow_async_alignment_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 async_io = disk.new_async_io(1).unwrap(); + assert!(async_io.alignment() >= SECTOR_SIZE); + } }