From 32af2f2a22bbc49d4c8bd07e0bc09809cd7180cd Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Mon, 13 Apr 2026 22:35:44 +0200 Subject: [PATCH] block: qcow: Test aligned_pwrite pass through path Write 4096 bytes of pattern data at offset 0 using AlignedBuf and verify data integrity via plain pread_exact. All parameters are naturally aligned to 512 so the fast path is exercised. Signed-off-by: Anatol Belski --- block/src/qcow_sync.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/block/src/qcow_sync.rs b/block/src/qcow_sync.rs index 5b4a6b216..af6bfc1ba 100644 --- a/block/src/qcow_sync.rs +++ b/block/src/qcow_sync.rs @@ -1789,4 +1789,22 @@ mod unit_tests { .collect(); assert_eq!(buf, expected); } + + #[test] + fn test_aligned_pwrite_pass_through() { + // When buffer address, length, and offset are all aligned, + // aligned_pwrite should take the fast path. + let size = 4096usize; + let (_tf, fd) = create_pattern_file(size); + let alignment = 512; + + let data: Vec = (0..size).map(|i| ((i + 1) % 251) as u8).collect(); + let mut abuf = AlignedBuf::new(size, alignment).unwrap(); + abuf.as_mut_slice(size).copy_from_slice(&data); + aligned_pwrite(fd, abuf.as_slice(size), 0, alignment).unwrap(); + + let mut readback = vec![0u8; size]; + pread_exact(fd, &mut readback, 0).unwrap(); + assert_eq!(readback, data); + } }