virtio-devices: vmm: fuzz: Switch to DiskBackend

Change Block to hold DiskBackend instead of
Box<dyn async_io::DiskFile>. In device_manager, existing formats
(raw, vhd, vhdx) are wrapped in DiskBackend::Legacy while
QcowDiskSync uses DiskBackend::Next. The fuzz target is updated
accordingly.

The Error::DiskResize variant now carries BlockError instead of
DiskFileError, matching the BlockResult return type of
DiskBackend::resize().

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-03-12 23:51:58 +01:00
committed by Rob Bradford
parent 264013b424
commit b4dad66d35
3 changed files with 24 additions and 16 deletions

View File

@@ -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,

View File

@@ -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<T> = result::Result<T, Error>;
@@ -697,7 +699,7 @@ impl EpollHelperHandler for BlockEpollHandler {
pub struct Block {
common: VirtioCommon,
id: String,
disk_image: Box<dyn DiskFile>,
disk_image: DiskBackend,
disk_path: PathBuf,
disk_nsectors: Arc<AtomicU64>,
config: VirtioBlockConfig,
@@ -727,7 +729,7 @@ impl Block {
#[allow(clippy::too_many_arguments)]
pub fn new(
id: String,
mut disk_image: Box<dyn DiskFile>,
mut disk_image: DiskBackend,
disk_path: PathBuf,
read_only: bool,
iommu: bool,

View File

@@ -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<dyn DiskFile>
) as Box<dyn DiskFile>)
}
} else {
info!("Using synchronous fixed VHD disk file");
Box::new(
DiskBackend::Legacy(Box::new(
FixedVhdDiskSync::new(file)
.map_err(DeviceManagerError::CreateFixedVhdDiskSync)?,
) as Box<dyn DiskFile>
) as Box<dyn DiskFile>)
}
}
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<dyn DiskFile>
DiskBackend::Legacy(
Box::new(RawFileDisk::new(file)) as Box<dyn DiskFile>
)
}
} else if !disk_cfg.disable_aio && self.aio_is_supported() {
info!("Using asynchronous RAW disk file (aio)");
Box::new(RawFileDiskAio::new(file)) as Box<dyn DiskFile>
DiskBackend::Legacy(Box::new(RawFileDiskAio::new(file)) as Box<dyn DiskFile>)
} else {
info!("Using synchronous RAW disk file");
Box::new(RawFileDiskSync::new(file)) as Box<dyn DiskFile>
DiskBackend::Legacy(
Box::new(RawFileDiskSync::new(file)) as Box<dyn DiskFile>
)
}
}
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<dyn DiskFile>
))
}
ImageType::Vhdx => {
info!("Using synchronous VHDX disk file");
Box::new(
DiskBackend::Legacy(Box::new(
VhdxDiskSync::new(file)
.map_err(DeviceManagerError::CreateFixedVhdxDiskSync)?,
) as Box<dyn DiskFile>
) as Box<dyn DiskFile>)
}
ImageType::Unknown => unreachable!(),
};