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:
Sebastien Boeuf
2020-10-07 11:23:20 +02:00
parent ac32b1e35f
commit 1e3a6cb450
3 changed files with 33 additions and 59 deletions
+24 -54
View File
@@ -36,7 +36,6 @@ use arch::layout;
use arch::layout::{APIC_START, IOAPIC_SIZE, IOAPIC_START};
#[cfg(target_arch = "aarch64")]
use arch::DeviceType;
#[cfg(feature = "io_uring")]
use block_util::block_io_uring_is_supported;
#[cfg(target_arch = "aarch64")]
use devices::gic;
@@ -1754,61 +1753,32 @@ impl DeviceManager {
.map_err(DeviceManagerError::DetectImageType)?;
let (virtio_device, migratable_device) = match image_type {
ImageType::Raw => {
#[cfg(feature = "io_uring")]
{
// Use asynchronous backend relying on io_uring if the
// syscalls are supported.
if block_io_uring_is_supported() {
let dev = Arc::new(Mutex::new(
virtio_devices::BlockIoUring::new(
id.clone(),
image,
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>>,
// Use asynchronous backend relying on io_uring if the
// syscalls are supported.
if block_io_uring_is_supported() {
let dev = Arc::new(Mutex::new(
virtio_devices::BlockIoUring::new(
id.clone(),
image,
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(),
)
} else {
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)?,
));
.map_err(DeviceManagerError::CreateVirtioBlock)?,
));
(
Arc::clone(&dev) as VirtioDeviceArc,
dev as Arc<Mutex<dyn Migratable>>,
)
}
}
#[cfg(not(feature = "io_uring"))]
{
(
Arc::clone(&dev) as VirtioDeviceArc,
dev as Arc<Mutex<dyn Migratable>>,
)
} else {
let dev = Arc::new(Mutex::new(
virtio_devices::Block::new(
id.clone(),