diff --git a/block/src/lib.rs b/block/src/lib.rs index 1b739beaf..6507076a7 100644 --- a/block/src/lib.rs +++ b/block/src/lib.rs @@ -59,6 +59,7 @@ use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::{aio, ioctl_io_nr}; use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult}; +use crate::error::{BlockError, BlockErrorKind, BlockResult, ErrorOp}; use crate::vhdx::VhdxError; const SECTOR_SHIFT: u8 = 9; @@ -1065,13 +1066,16 @@ pub fn read_aligned_block_size(f: &mut File) -> std::io::Result> { } /// Determine image type through file parsing. -pub fn detect_image_type(f: &mut File) -> std::io::Result { - let block = read_aligned_block_size(f)?; +pub fn detect_image_type(f: &mut File) -> BlockResult { + let block = read_aligned_block_size(f) + .map_err(|e| BlockError::new(BlockErrorKind::Io, e).with_op(ErrorOp::DetectImageType))?; // Check 4 first bytes to get the header value and determine the image type let image_type = if u32::from_be_bytes(block[0..4].try_into().unwrap()) == QCOW_MAGIC { ImageType::Qcow2 - } else if vhd::is_fixed_vhd(f)? { + } else if vhd::is_fixed_vhd(f) + .map_err(|e| BlockError::new(BlockErrorKind::Io, e).with_op(ErrorOp::DetectImageType))? + { ImageType::FixedVhd } else if u64::from_le_bytes(block[0..8].try_into().unwrap()) == VHDX_SIGN { ImageType::Vhdx diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index aa02f479e..325084395 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -41,7 +41,7 @@ use block::raw_sync::RawFileDiskSync; use block::vhdx_sync::VhdxDiskSync; use block::{ ImageType, block_aio_is_supported, block_io_uring_is_supported, detect_image_type, - preallocate_disk, qcow, vhdx, + preallocate_disk, vhdx, }; #[cfg(feature = "io_uring")] use block::{fixed_vhd_async::FixedVhdDiskAsync, raw_async::RawFileDisk}; @@ -266,7 +266,7 @@ pub enum DeviceManagerError { /// Failed to parse disk image format #[error("Failed to parse disk image format")] - DetectImageType(#[source] io::Error), + DetectImageType(#[source] BlockError), /// Cannot create serial manager #[error("Cannot create serial manager")]