mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-23 03:42:20 +00:00
vmm: Simplify some of the io_uring code
Small patch creating a dedicated `block_io_uring_is_supported()` function for the non-io_uring case, so that we can simplify the code in the DeviceManager. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
ac32b1e35f
commit
1e3a6cb450
@ -14,13 +14,15 @@ extern crate log;
|
|||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
|
|
||||||
#[cfg(feature = "io_uring")]
|
#[cfg(feature = "io_uring")]
|
||||||
use io_uring::{opcode, squeue, IoUring, Probe};
|
use io_uring::Probe;
|
||||||
|
use io_uring::{opcode, squeue, IoUring};
|
||||||
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")]
|
#[cfg(feature = "io_uring")]
|
||||||
use std::os::unix::io::{AsRawFd, RawFd};
|
use std::os::unix::io::AsRawFd;
|
||||||
|
use std::os::unix::io::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::*;
|
||||||
@ -266,7 +268,6 @@ impl Request {
|
|||||||
Ok(len)
|
Ok(len)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "io_uring")]
|
|
||||||
pub fn execute_io_uring(
|
pub fn execute_io_uring(
|
||||||
&self,
|
&self,
|
||||||
mem: &GuestMemoryMmap,
|
mem: &GuestMemoryMmap,
|
||||||
@ -565,3 +566,8 @@ pub fn block_io_uring_is_supported() -> bool {
|
|||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "io_uring"))]
|
||||||
|
pub fn block_io_uring_is_supported() -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
@ -31,7 +31,6 @@ 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;
|
||||||
@ -48,7 +47,6 @@ 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::*;
|
||||||
|
@ -36,7 +36,6 @@ 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;
|
||||||
@ -1754,8 +1753,6 @@ 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() {
|
||||||
@ -1806,33 +1803,6 @@ 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,
|
|
||||||
self.seccomp_action.clone(),
|
|
||||||
)
|
|
||||||
.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)?;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user