io_uring: Add new feature gate

By adding a new io_uring feature gate, we let the user the possibility
to choose if he wants to enable the io_uring improvements or not.
Since the io_uring feature depends on the availability on recent host
kernels, it's better if we leave it off for now.

As soon as our CI will have support for a kernel 5.6 with all the
features needed from io_uring, we'll enable this feature gate
permanently.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-08-03 08:32:28 +02:00 committed by Rob Bradford
parent a85304196e
commit 8f0bf82648
7 changed files with 67 additions and 24 deletions

View File

@ -42,6 +42,7 @@ mmio = ["vmm/mmio_support"]
cmos = ["vmm/cmos"] cmos = ["vmm/cmos"]
fwdebug = ["vmm/fwdebug"] fwdebug = ["vmm/fwdebug"]
kvm = ["vmm/kvm"] kvm = ["vmm/kvm"]
io_uring = ["vmm/io_uring"]
# Integration tests require a special environment to run in # Integration tests require a special environment to run in
integration_tests = [] integration_tests = []

View File

@ -4,6 +4,10 @@ version = "0.1.0"
authors = ["The Cloud Hypervisor Authors"] authors = ["The Cloud Hypervisor Authors"]
edition = "2018" edition = "2018"
[features]
default = []
io_uring = []
[dependencies] [dependencies]
io-uring = { git = "https://github.com/tokio-rs/io-uring.git", branch = "0.4" } io-uring = { git = "https://github.com/tokio-rs/io-uring.git", branch = "0.4" }
libc = "0.2.74" libc = "0.2.74"

View File

@ -13,17 +13,20 @@ extern crate log;
#[macro_use] #[macro_use]
extern crate serde_derive; extern crate serde_derive;
#[cfg(feature = "io_uring")]
use io_uring::{opcode, IoUring, Probe}; use io_uring::{opcode, IoUring, Probe};
use serde::ser::{Serialize, SerializeStruct, Serializer}; use serde::ser::{Serialize, SerializeStruct, Serializer};
use std::cmp; use std::cmp;
use std::io::{self, Read, Seek, SeekFrom, Write}; use std::io::{self, Read, Seek, SeekFrom, Write};
use std::os::linux::fs::MetadataExt; use std::os::linux::fs::MetadataExt;
#[cfg(feature = "io_uring")]
use std::os::unix::io::{AsRawFd, RawFd}; use std::os::unix::io::{AsRawFd, RawFd};
use std::path::PathBuf; use std::path::PathBuf;
use std::result; use std::result;
use virtio_bindings::bindings::virtio_blk::*; use virtio_bindings::bindings::virtio_blk::*;
use vm_memory::{ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError, GuestMemoryMmap}; use vm_memory::{ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError, GuestMemoryMmap};
use vm_virtio::DescriptorChain; use vm_virtio::DescriptorChain;
#[cfg(feature = "io_uring")]
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
const SECTOR_SHIFT: u8 = 9; const SECTOR_SHIFT: u8 = 9;
@ -263,6 +266,7 @@ impl Request {
Ok(0) Ok(0)
} }
#[cfg(feature = "io_uring")]
pub fn execute_io_uring( pub fn execute_io_uring(
&self, &self,
mem: &GuestMemoryMmap, mem: &GuestMemoryMmap,
@ -473,6 +477,7 @@ unsafe impl ByteValued for VirtioBlockGeometry {}
/// Check if io_uring for block device can be used on the current system, as /// Check if io_uring for block device can be used on the current system, as
/// it correctly supports the expected io_uring features. /// it correctly supports the expected io_uring features.
#[cfg(feature = "io_uring")]
pub fn block_io_uring_is_supported() -> bool { pub fn block_io_uring_is_supported() -> bool {
let error_msg = "io_uring not supported:"; let error_msg = "io_uring not supported:";

View File

@ -8,6 +8,7 @@ edition = "2018"
default = [] default = []
pci_support = ["pci"] pci_support = ["pci"]
mmio_support = [] mmio_support = []
io_uring = ["block_util/io_uring"]
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"

View File

@ -31,6 +31,7 @@ use std::io;
mod device; mod device;
pub mod balloon; pub mod balloon;
pub mod block; pub mod block;
#[cfg(feature = "io_uring")]
pub mod block_io_uring; pub mod block_io_uring;
mod console; mod console;
pub mod epoll_helper; pub mod epoll_helper;
@ -46,6 +47,7 @@ pub mod vsock;
pub use self::balloon::*; pub use self::balloon::*;
pub use self::block::*; pub use self::block::*;
#[cfg(feature = "io_uring")]
pub use self::block_io_uring::*; pub use self::block_io_uring::*;
pub use self::console::*; pub use self::console::*;
pub use self::device::*; pub use self::device::*;

View File

@ -12,6 +12,7 @@ mmio_support = ["virtio-devices/mmio_support"]
cmos = ["devices/cmos"] cmos = ["devices/cmos"]
fwdebug = ["devices/fwdebug"] fwdebug = ["devices/fwdebug"]
kvm = ["hypervisor/kvm"] kvm = ["hypervisor/kvm"]
io_uring = ["virtio-devices/io_uring"]
[dependencies] [dependencies]
arc-swap = ">=0.4.4" arc-swap = ">=0.4.4"

View File

@ -32,6 +32,7 @@ use arch::layout;
use arch::layout::{APIC_START, IOAPIC_SIZE, IOAPIC_START}; use arch::layout::{APIC_START, IOAPIC_SIZE, IOAPIC_START};
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
use arch::DeviceType; use arch::DeviceType;
#[cfg(feature = "io_uring")]
use block_util::block_io_uring_is_supported; use block_util::block_io_uring_is_supported;
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
use devices::gic; use devices::gic;
@ -1669,6 +1670,8 @@ impl DeviceManager {
.map_err(DeviceManagerError::DetectImageType)?; .map_err(DeviceManagerError::DetectImageType)?;
let (virtio_device, migratable_device) = match image_type { let (virtio_device, migratable_device) = match image_type {
ImageType::Raw => { ImageType::Raw => {
#[cfg(feature = "io_uring")]
{
// Use asynchronous backend relying on io_uring if the // Use asynchronous backend relying on io_uring if the
// syscalls are supported. // syscalls are supported.
if block_io_uring_is_supported() { if block_io_uring_is_supported() {
@ -1717,6 +1720,32 @@ impl DeviceManager {
) )
} }
} }
#[cfg(not(feature = "io_uring"))]
{
let dev = Arc::new(Mutex::new(
virtio_devices::Block::new(
id.clone(),
raw_img,
disk_cfg
.path
.as_ref()
.ok_or(DeviceManagerError::NoDiskPath)?
.clone(),
disk_cfg.readonly,
disk_cfg.iommu,
disk_cfg.num_queues,
disk_cfg.queue_size,
)
.map_err(DeviceManagerError::CreateVirtioBlock)?,
));
(
Arc::clone(&dev) as VirtioDeviceArc,
dev as Arc<Mutex<dyn Migratable>>,
)
}
}
ImageType::Qcow2 => { ImageType::Qcow2 => {
let qcow_img = let qcow_img =
QcowFile::from(raw_img).map_err(DeviceManagerError::QcowDeviceCreate)?; QcowFile::from(raw_img).map_err(DeviceManagerError::QcowDeviceCreate)?;