Skip to content

Commit e114aee

Browse files
committed
chore: Remove 4.14 related io_uring checks
io_uring is not supported on 4.14 hosts. Since firecracker-microvm#4689 dropped support for 4.14 hosts, and 5.10 does support io_uring, remove various checks related to unsupported (4.14) host kernels. Signed-off-by: Patrick Roy <[email protected]>
1 parent aa07f77 commit e114aee

File tree

6 files changed

+2
-138
lines changed

6 files changed

+2
-138
lines changed

src/utils/src/kernel_version.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,24 +89,6 @@ pub fn min_kernel_version_for_io_uring() -> KernelVersion {
8989
KernelVersion::new(5, 10, 51)
9090
}
9191

92-
#[macro_export]
93-
macro_rules! skip_if_io_uring_unsupported {
94-
() => {
95-
if KernelVersion::get().unwrap() < min_kernel_version_for_io_uring() {
96-
return;
97-
}
98-
};
99-
}
100-
101-
#[macro_export]
102-
macro_rules! skip_if_io_uring_supported {
103-
() => {
104-
if KernelVersion::get().unwrap() >= min_kernel_version_for_io_uring() {
105-
return;
106-
}
107-
};
108-
}
109-
11092
#[cfg(test)]
11193
mod tests {
11294
use super::*;

src/vmm/src/devices/virtio/block/virtio/device.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use std::sync::Arc;
1616
use block_io::FileEngine;
1717
use serde::{Deserialize, Serialize};
1818
use utils::eventfd::EventFd;
19-
use utils::kernel_version::{min_kernel_version_for_io_uring, KernelVersion};
2019
use utils::u64_to_usize;
2120

2221
use super::io::async_io;
@@ -50,16 +49,6 @@ pub enum FileEngineType {
5049
Sync,
5150
}
5251

53-
impl FileEngineType {
54-
/// Whether the Async engine is supported on the current host kernel.
55-
pub fn is_supported(&self) -> Result<bool, utils::kernel_version::KernelVersionError> {
56-
match self {
57-
Self::Async if KernelVersion::get()? < min_kernel_version_for_io_uring() => Ok(false),
58-
_ => Ok(true),
59-
}
60-
}
61-
}
62-
6352
/// Helper object for setting up all `Block` fields derived from its backing file.
6453
#[derive(Debug)]
6554
pub struct DiskProperties {
@@ -687,7 +676,6 @@ mod tests {
687676
use std::thread;
688677
use std::time::Duration;
689678

690-
use utils::skip_if_io_uring_unsupported;
691679
use utils::tempfile::TempFile;
692680

693681
use super::*;
@@ -1555,9 +1543,6 @@ mod tests {
15551543

15561544
#[test]
15571545
fn test_io_engine_throttling() {
1558-
// skip this test if kernel < 5.10 since in this case the sync engine will be used.
1559-
skip_if_io_uring_unsupported!();
1560-
15611546
// FullSQueue BlockError
15621547
{
15631548
let mut block = default_block(FileEngineType::Async);

src/vmm/src/devices/virtio/block/virtio/io/mod.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ pub enum BlockIoError {
3030
Sync(SyncIoError),
3131
/// Async error: {0}
3232
Async(AsyncIoError),
33-
/// Unsupported engine type: {0:?}
34-
UnsupportedEngine(FileEngineType),
3533
/// Could not get kernel version: {0}
3634
GetKernelVersion(utils::kernel_version::KernelVersionError),
3735
}
@@ -64,12 +62,6 @@ impl<T: Debug> FileEngine<T> {
6462
file: File,
6563
engine_type: FileEngineType,
6664
) -> Result<FileEngine<T>, BlockIoError> {
67-
if !engine_type
68-
.is_supported()
69-
.map_err(BlockIoError::GetKernelVersion)?
70-
{
71-
return Err(BlockIoError::UnsupportedEngine(engine_type));
72-
}
7365
match engine_type {
7466
FileEngineType::Async => Ok(FileEngine::Async(
7567
AsyncFileEngine::from_file(file).map_err(BlockIoError::Async)?,
@@ -199,13 +191,11 @@ pub mod tests {
199191
use std::os::unix::ffi::OsStrExt;
200192
use std::os::unix::io::FromRawFd;
201193

202-
use utils::kernel_version::{min_kernel_version_for_io_uring, KernelVersion};
203194
use utils::tempfile::TempFile;
204-
use utils::{skip_if_io_uring_supported, skip_if_io_uring_unsupported, u64_to_usize};
195+
use utils::u64_to_usize;
205196

206197
use super::*;
207198
use crate::devices::virtio::block::virtio::device::FileEngineType;
208-
use crate::devices::virtio::block::virtio::request::PendingRequest;
209199
use crate::vmm_config::machine_config::HugePageConfig;
210200
use crate::vstate::memory::{Bitmap, Bytes, GuestMemory, GuestMemoryExtension};
211201

@@ -275,19 +265,6 @@ pub mod tests {
275265
}
276266
}
277267

278-
#[test]
279-
fn test_unsupported_engine_type() {
280-
skip_if_io_uring_supported!();
281-
282-
assert!(matches!(
283-
FileEngine::<PendingRequest>::from_file(
284-
TempFile::new().unwrap().into_file(),
285-
FileEngineType::Async
286-
),
287-
Err(BlockIoError::UnsupportedEngine(FileEngineType::Async))
288-
));
289-
}
290-
291268
#[test]
292269
fn test_sync() {
293270
// Check invalid file
@@ -367,8 +344,6 @@ pub mod tests {
367344

368345
#[test]
369346
fn test_async() {
370-
skip_if_io_uring_unsupported!();
371-
372347
// Check invalid file
373348
let file = unsafe { File::from_raw_fd(-2) };
374349
FileEngine::<()>::from_file(file, FileEngineType::Async).unwrap_err();

src/vmm/src/devices/virtio/block/virtio/persist.rs

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use crate::devices::virtio::device::{DeviceState, IrqTrigger};
1818
use crate::devices::virtio::gen::virtio_blk::VIRTIO_BLK_F_RO;
1919
use crate::devices::virtio::persist::VirtioDeviceState;
2020
use crate::devices::virtio::TYPE_BLOCK;
21-
use crate::logger::warn;
2221
use crate::rate_limiter::persist::RateLimiterState;
2322
use crate::rate_limiter::RateLimiter;
2423
use crate::snapshot::Persist;
@@ -97,21 +96,7 @@ impl Persist<'_> for VirtioBlock {
9796
state.disk_path.clone(),
9897
is_read_only,
9998
state.file_engine_type.into(),
100-
)
101-
.or_else(|err| match err {
102-
VirtioBlockError::FileEngine(io::BlockIoError::UnsupportedEngine(
103-
FileEngineType::Async,
104-
)) => {
105-
// If the kernel does not support `Async`, fallback to `Sync`.
106-
warn!(
107-
"The \"Async\" io_engine is supported for kernels starting with {}. \
108-
Defaulting to \"Sync\" mode.",
109-
utils::kernel_version::min_kernel_version_for_io_uring()
110-
);
111-
DiskProperties::new(state.disk_path.clone(), is_read_only, FileEngineType::Sync)
112-
}
113-
other => Err(other),
114-
})?;
99+
)?;
115100

116101
let queue_evts = [EventFd::new(libc::EFD_NONBLOCK).map_err(VirtioBlockError::EventFd)?];
117102

@@ -214,49 +199,6 @@ mod tests {
214199
assert_eq!(FileEngineType::Sync, FileEngineTypeState::Sync.into());
215200
// Test default impl.
216201
assert_eq!(FileEngineTypeState::default(), FileEngineTypeState::Sync);
217-
218-
let f = TempFile::new().unwrap();
219-
f.as_file().set_len(0x1000).unwrap();
220-
221-
if !FileEngineType::Async.is_supported().unwrap() {
222-
// Test what happens when restoring an Async engine on a kernel that does not support
223-
// it.
224-
225-
let config = VirtioBlockConfig {
226-
drive_id: "test".to_string(),
227-
path_on_host: f.as_path().to_str().unwrap().to_string(),
228-
is_root_device: false,
229-
partuuid: None,
230-
is_read_only: false,
231-
cache_type: CacheType::Writeback,
232-
rate_limiter: None,
233-
// Need to use Sync because it will otherwise return an error.
234-
// We'll overwrite the state instead.
235-
file_engine_type: FileEngineType::Sync,
236-
};
237-
238-
let block = VirtioBlock::new(config).unwrap();
239-
240-
// Save the block device.
241-
let mut mem = vec![0; 4096];
242-
243-
let mut block_state = <VirtioBlock as Persist>::save(&block);
244-
// Overwrite the engine type state with Async.
245-
block_state.file_engine_type = FileEngineTypeState::Async;
246-
247-
Snapshot::serialize(&mut mem.as_mut_slice(), &block_state).unwrap();
248-
249-
// Restore the block device.
250-
let restored_block = VirtioBlock::restore(
251-
BlockConstructorArgs { mem: default_mem() },
252-
&Snapshot::deserialize(&mut mem.as_slice()).unwrap(),
253-
)
254-
.unwrap();
255-
256-
// On kernels that don't support io_uring, the restore() function will catch the
257-
// `UnsupportedEngine` error and default to Sync.
258-
assert_eq!(restored_block.file_engine_type(), FileEngineType::Sync);
259-
}
260202
}
261203

262204
#[test]

src/vmm/src/io_uring/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,6 @@ mod tests {
389389
use proptest::prelude::*;
390390
use proptest::strategy::Strategy;
391391
use proptest::test_runner::{Config, TestRunner};
392-
use utils::kernel_version::{min_kernel_version_for_io_uring, KernelVersion};
393-
use utils::skip_if_io_uring_unsupported;
394392
use utils::syscall::SyscallReturnCode;
395393
use utils::tempfile::TempFile;
396394
use vm_memory::VolatileMemory;
@@ -475,7 +473,6 @@ mod tests {
475473

476474
#[test]
477475
fn proptest_read_write_correctness() {
478-
skip_if_io_uring_unsupported!();
479476
// Performs a sequence of random read and write operations on two files, with sync and
480477
// async IO, respectively.
481478
// Verifies that the files are identical afterwards and that the read operations returned

src/vmm/tests/io_uring.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ use std::time::Duration;
1010

1111
use utils::epoll::{ControlOperation, Epoll, EpollEvent, EventSet};
1212
use utils::eventfd::EventFd;
13-
use utils::kernel_version::{min_kernel_version_for_io_uring, KernelVersion};
14-
use utils::skip_if_io_uring_unsupported;
1513
use utils::tempfile::TempFile;
1614
use vm_memory::VolatileMemory;
1715
use vmm::vstate::memory::{Bytes, MmapRegion};
@@ -93,8 +91,6 @@ const NUM_ENTRIES: u32 = 128;
9391

9492
#[test]
9593
fn test_ring_new() {
96-
skip_if_io_uring_unsupported!();
97-
9894
// Invalid entries count: 0.
9995
assert!(matches!(
10096
IoUring::<u8>::new(0, vec![], vec![], None),
@@ -110,7 +106,6 @@ fn test_ring_new() {
110106

111107
#[test]
112108
fn test_eventfd() {
113-
skip_if_io_uring_unsupported!();
114109
// Test that events get delivered.
115110
let eventfd = EventFd::new(0).unwrap();
116111

@@ -145,8 +140,6 @@ fn test_eventfd() {
145140

146141
#[test]
147142
fn test_restrictions() {
148-
skip_if_io_uring_unsupported!();
149-
150143
// Check that only the allowlisted opcodes are permitted.
151144
{
152145
let file = TempFile::new().unwrap().into_file();
@@ -180,8 +173,6 @@ fn test_restrictions() {
180173

181174
#[test]
182175
fn test_ring_push() {
183-
skip_if_io_uring_unsupported!();
184-
185176
// Forgot to register file.
186177
{
187178
let buf = [0; 4];
@@ -267,8 +258,6 @@ fn test_ring_push() {
267258

268259
#[test]
269260
fn test_ring_submit() {
270-
skip_if_io_uring_unsupported!();
271-
272261
{
273262
let file = TempFile::new().unwrap().into_file();
274263
let mut ring = IoUring::new(NUM_ENTRIES, vec![&file], vec![], None).unwrap();
@@ -298,8 +287,6 @@ fn test_ring_submit() {
298287

299288
#[test]
300289
fn test_submit_and_wait_all() {
301-
skip_if_io_uring_unsupported!();
302-
303290
let file = TempFile::new().unwrap().into_file();
304291
let mut ring = IoUring::new(NUM_ENTRIES, vec![&file], vec![], None).unwrap();
305292
let user_data: u8 = 71;
@@ -345,8 +332,6 @@ fn test_submit_and_wait_all() {
345332

346333
#[test]
347334
fn test_write() {
348-
skip_if_io_uring_unsupported!();
349-
350335
// Test that writing the sorted values 1-100 into a file works correctly.
351336

352337
const NUM_BYTES: usize = 100;
@@ -386,8 +371,6 @@ fn test_write() {
386371

387372
#[test]
388373
fn test_read() {
389-
skip_if_io_uring_unsupported!();
390-
391374
// Test that reading the sorted values 1-100 from a file works correctly.
392375

393376
const NUM_BYTES: usize = 100;

0 commit comments

Comments
 (0)