From f67d0569b493e6a50b8517fcae2f253e53b26511 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Sat, 9 May 2026 00:21:23 +0000 Subject: [PATCH] block: fix `cargo test -p block` `RawBackend::IoUring` is only available when `io_uring` feature is defined. Signed-off-by: Wei Liu --- Cargo.lock | 1 + block/Cargo.toml | 3 +++ block/src/raw_disk.rs | 13 +++++++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aea8920a8..312a258c0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -325,6 +325,7 @@ version = "0.1.0" dependencies = [ "bitflags 2.11.1", "byteorder", + "cfg-if", "crc-any", "flate2", "io-uring", diff --git a/block/Cargo.toml b/block/Cargo.toml index 6183c7337..22ea206de 100644 --- a/block/Cargo.toml +++ b/block/Cargo.toml @@ -33,5 +33,8 @@ vm-virtio = { path = "../vm-virtio" } vmm-sys-util = { workspace = true } zstd = "0.13" +[dev-dependencies] +cfg-if = { workspace = true } + [lints] workspace = true diff --git a/block/src/raw_disk.rs b/block/src/raw_disk.rs index a6d3eab5c..82dd3c530 100644 --- a/block/src/raw_disk.rs +++ b/block/src/raw_disk.rs @@ -170,10 +170,15 @@ mod unit_tests { fn assert_async_io_from_dyn(disk: &dyn AsyncDiskFile, expect_backend: RawBackend) { let io: Box = disk.create_async_io(128).unwrap(); - assert_eq!( - io.batch_requests_enabled(), - expect_backend == RawBackend::IoUring - ); + cfg_if::cfg_if! { + if #[cfg(feature = "io_uring")] { + let expected_batch_requests = expect_backend == RawBackend::IoUring; + } else { + let _ = expect_backend; + let expected_batch_requests = false; + } + } + assert_eq!(io.batch_requests_enabled(), expected_batch_requests); } fn assert_sync_backend(disk: &RawDisk) {