From 95cbb2048a3fe2f74d7140197b0dd34ae0ed538b Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Wed, 22 Apr 2026 23:32:21 +0200 Subject: [PATCH] block: vhd: Test backend dispatch Verify that create_async_io dispatches to the correct backend depending on use_io_uring. The sync backend does not support batch requests, while the io_uring backend does. Assisted-by: Claude:Opus-4.6 Signed-off-by: Anatol Belski --- block/src/fixed_vhd_disk.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/block/src/fixed_vhd_disk.rs b/block/src/fixed_vhd_disk.rs index 3c611c825..ee43c10ed 100644 --- a/block/src/fixed_vhd_disk.rs +++ b/block/src/fixed_vhd_disk.rs @@ -124,7 +124,8 @@ mod unit_tests { use vmm_sys_util::tempfile::TempFile; use super::*; - use crate::disk_file::DiskSize; + use crate::async_io::AsyncIo; + use crate::disk_file::{AsyncDiskFile, DiskSize}; /// Minimal fixed VHD footer (disk type = 2, current_size = 0x11223344). fn fixed_vhd_footer() -> &'static [u8] { @@ -162,4 +163,28 @@ mod unit_tests { let disk = FixedVhdDisk::new(file, false).unwrap(); assert_eq!(disk.logical_size().unwrap(), 0x1122_3344); } + + fn assert_async_io_from_dyn(disk: &dyn AsyncDiskFile, expect_batch: bool) { + let io: Box = disk.create_async_io(128).unwrap(); + assert_eq!(io.batch_requests_enabled(), expect_batch); + } + + fn assert_async_io(disk: &FixedVhdDisk, expect_batch: bool) { + assert_async_io_from_dyn(disk, expect_batch); + } + + #[test] + fn sync_backend_disables_batch_requests() { + let file = make_vhd_file(); + let disk = FixedVhdDisk::new(file, false).unwrap(); + assert_async_io(&disk, false); + } + + #[cfg(feature = "io_uring")] + #[test] + fn io_uring_backend_enables_batch_requests() { + let file = make_vhd_file(); + let disk = FixedVhdDisk::new(file, true).unwrap(); + assert_async_io(&disk, true); + } }