diff --git a/fuzz/fuzz_targets/block.rs b/fuzz/fuzz_targets/block.rs index 952011b55..35d59c985 100644 --- a/fuzz/fuzz_targets/block.rs +++ b/fuzz/fuzz_targets/block.rs @@ -16,6 +16,7 @@ use std::sync::Arc; use std::{ffi, io}; use block::async_io::DiskFile; +use block::disk_file::DiskBackend; use block::fcntl::LockGranularityChoice; use block::raw_sync::RawFileDiskSync; use libfuzzer_sys::{fuzz_target, Corpus}; @@ -56,7 +57,7 @@ fuzz_target!(|bytes: &[u8]| -> Corpus { let queue_affinity = BTreeMap::new(); let mut block = Block::new( "tmp".to_owned(), - qcow_disk, + DiskBackend::Legacy(qcow_disk), PathBuf::from(""), false, false, diff --git a/virtio-devices/src/block.rs b/virtio-devices/src/block.rs index 2adbff74f..edd1327f4 100644 --- a/virtio-devices/src/block.rs +++ b/virtio-devices/src/block.rs @@ -18,7 +18,9 @@ use std::sync::{Arc, Barrier}; use std::{io, result}; use anyhow::anyhow; -use block::async_io::{AsyncIo, AsyncIoError, DiskFile, DiskFileError}; +use block::async_io::{AsyncIo, AsyncIoError}; +use block::disk_file::DiskBackend; +use block::error::BlockError; use block::fcntl::{LockError, LockGranularity, LockGranularityChoice, LockType, get_lock_state}; use block::{ ExecuteAsync, ExecuteError, Request, RequestType, VirtioBlockConfig, build_serial, fcntl, @@ -104,7 +106,7 @@ pub enum Error { #[error("Failed signal config interrupt")] ConfigChange(#[source] io::Error), #[error("Disk resize failed")] - DiskResize(#[source] DiskFileError), + DiskResize(#[source] BlockError), } pub type Result = result::Result; @@ -697,7 +699,7 @@ impl EpollHelperHandler for BlockEpollHandler { pub struct Block { common: VirtioCommon, id: String, - disk_image: Box, + disk_image: DiskBackend, disk_path: PathBuf, disk_nsectors: Arc, config: VirtioBlockConfig, @@ -727,7 +729,7 @@ impl Block { #[allow(clippy::too_many_arguments)] pub fn new( id: String, - mut disk_image: Box, + mut disk_image: DiskBackend, disk_path: PathBuf, read_only: bool, iommu: bool, diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 958d3086b..51a5e476a 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -33,6 +33,7 @@ use arch::layout::{APIC_START, IOAPIC_SIZE, IOAPIC_START}; use arch::{DeviceType, MmioDeviceInfo}; use arch::{NumaNodes, layout}; use block::async_io::DiskFile; +use block::disk_file::DiskBackend; use block::error::BlockError; use block::fixed_vhd_sync::FixedVhdDiskSync; use block::qcow_sync::QcowDiskSync; @@ -2721,17 +2722,17 @@ impl DeviceManager { unreachable!("Checked in if statement above"); #[cfg(feature = "io_uring")] { - Box::new( + DiskBackend::Legacy(Box::new( FixedVhdDiskAsync::new(file) .map_err(DeviceManagerError::CreateFixedVhdDiskAsync)?, - ) as Box + ) as Box) } } else { info!("Using synchronous fixed VHD disk file"); - Box::new( + DiskBackend::Legacy(Box::new( FixedVhdDiskSync::new(file) .map_err(DeviceManagerError::CreateFixedVhdDiskSync)?, - ) as Box + ) as Box) } } ImageType::Raw => { @@ -2755,19 +2756,23 @@ impl DeviceManager { unreachable!("Checked in if statement above"); #[cfg(feature = "io_uring")] { - Box::new(RawFileDisk::new(file)) as Box + DiskBackend::Legacy( + Box::new(RawFileDisk::new(file)) as Box + ) } } else if !disk_cfg.disable_aio && self.aio_is_supported() { info!("Using asynchronous RAW disk file (aio)"); - Box::new(RawFileDiskAio::new(file)) as Box + DiskBackend::Legacy(Box::new(RawFileDiskAio::new(file)) as Box) } else { info!("Using synchronous RAW disk file"); - Box::new(RawFileDiskSync::new(file)) as Box + DiskBackend::Legacy( + Box::new(RawFileDiskSync::new(file)) as Box + ) } } ImageType::Qcow2 => { info!("Using synchronous QCOW2 disk file"); - Box::new( + DiskBackend::Next(Box::new( QcowDiskSync::new( file, disk_cfg.direct, @@ -2779,14 +2784,14 @@ impl DeviceManager { None => e, }) .map_err(DeviceManagerError::CreateQcowDiskSync)?, - ) as Box + )) } ImageType::Vhdx => { info!("Using synchronous VHDX disk file"); - Box::new( + DiskBackend::Legacy(Box::new( VhdxDiskSync::new(file) .map_err(DeviceManagerError::CreateFixedVhdxDiskSync)?, - ) as Box + ) as Box) } ImageType::Unknown => unreachable!(), };