From d42ea61a5f2b3a72d675691c4211e0ae874e1e1e Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Wed, 22 Apr 2026 22:10:08 +0200 Subject: [PATCH] block: Use FixedVhdDisk in factory, remove old wrappers Update open_fixed_vhd to construct FixedVhdDisk instead of choosing between FixedVhdDiskAsync and FixedVhdDiskSync. The io_uring decision is now made inside FixedVhdDisk::create_async_io(). Remove FixedVhdDiskSync and FixedVhdDiskAsync DiskFile wrapper structs from fixed_vhd_sync.rs and fixed_vhd_async.rs. Only the FixedVhdSync and FixedVhdAsync AsyncIo worker structs remain in those files. Signed-off-by: Anatol Belski --- block/src/factory.rs | 8 ++-- block/src/fixed_vhd_async.rs | 80 ++---------------------------------- block/src/fixed_vhd_sync.rs | 79 +---------------------------------- 3 files changed, 9 insertions(+), 158 deletions(-) diff --git a/block/src/factory.rs b/block/src/factory.rs index 4d31f9860..2d59f6872 100644 --- a/block/src/factory.rs +++ b/block/src/factory.rs @@ -20,9 +20,7 @@ use log::info; use crate::block_io_uring_is_supported; use crate::disk_file::AsyncFullDiskFile; use crate::error::{BlockError, BlockErrorKind, BlockResult}; -#[cfg(feature = "io_uring")] -use crate::fixed_vhd_async::FixedVhdDiskAsync; -use crate::fixed_vhd_sync::FixedVhdDiskSync; +use crate::fixed_vhd_disk::FixedVhdDisk; #[cfg(feature = "io_uring")] use crate::qcow_async::QcowDiskAsync; use crate::qcow_sync::QcowDiskSync; @@ -131,7 +129,7 @@ fn open_fixed_vhd( if io_uring_supported() { info!("Opening fixed VHD disk file with io_uring backend"); return Ok(Box::new( - FixedVhdDiskAsync::new(file).map_err(|e| e.with_path(options.path))?, + FixedVhdDisk::new(file, true).map_err(|e| e.with_path(options.path))?, )); } info!("io_uring runtime probe failed for fixed VHD, using synchronous backend"); @@ -139,7 +137,7 @@ fn open_fixed_vhd( info!("Opening fixed VHD disk file with synchronous backend"); Ok(Box::new( - FixedVhdDiskSync::new(file).map_err(|e| e.with_path(options.path))?, + FixedVhdDisk::new(file, false).map_err(|e| e.with_path(options.path))?, )) } diff --git a/block/src/fixed_vhd_async.rs b/block/src/fixed_vhd_async.rs index bdc520284..58dbc9a93 100644 --- a/block/src/fixed_vhd_async.rs +++ b/block/src/fixed_vhd_async.rs @@ -2,86 +2,14 @@ // // SPDX-License-Identifier: Apache-2.0 -use std::fs::File; -use std::os::unix::io::{AsRawFd, RawFd}; +use std::os::unix::io::RawFd; use vmm_sys_util::eventfd::EventFd; -use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult, BorrowedDiskFd, DiskFileError}; -use crate::error::{BlockError, BlockErrorKind, BlockResult, ErrorOp}; -use crate::fixed_vhd::FixedVhd; +use crate::BatchRequest; +use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult}; +use crate::error::BlockResult; use crate::raw_async::RawFileAsync; -use crate::{BatchRequest, BlockBackend, disk_file}; - -#[derive(Debug)] -pub struct FixedVhdDiskAsync(FixedVhd); - -impl FixedVhdDiskAsync { - pub fn new(file: File) -> BlockResult { - Ok(Self( - FixedVhd::new(file).map_err(|e| BlockError::from(e).with_op(ErrorOp::Open))?, - )) - } -} - -impl disk_file::DiskSize for FixedVhdDiskAsync { - fn logical_size(&self) -> BlockResult { - self.0 - .logical_size() - .map_err(|e| BlockError::new(BlockErrorKind::Io, e)) - } -} - -impl disk_file::PhysicalSize for FixedVhdDiskAsync { - fn physical_size(&self) -> BlockResult { - self.0.physical_size().map_err(|e| match e { - crate::Error::GetFileMetadata(io) => { - BlockError::new(BlockErrorKind::Io, crate::Error::GetFileMetadata(io)) - } - _ => unreachable!("unexpected error from FixedVhd::physical_size(): {e}"), - }) - } -} - -impl disk_file::DiskFd for FixedVhdDiskAsync { - fn fd(&self) -> BorrowedDiskFd<'_> { - BorrowedDiskFd::new(self.0.as_raw_fd()) - } -} - -impl disk_file::Geometry for FixedVhdDiskAsync {} - -impl disk_file::SparseCapable for FixedVhdDiskAsync {} - -impl disk_file::Resizable for FixedVhdDiskAsync { - fn resize(&mut self, _size: u64) -> BlockResult<()> { - Err(BlockError::new( - BlockErrorKind::UnsupportedFeature, - DiskFileError::ResizeError(std::io::Error::other("resize not supported for fixed VHD")), - ) - .with_op(ErrorOp::Resize)) - } -} - -impl disk_file::DiskFile for FixedVhdDiskAsync {} - -impl disk_file::AsyncDiskFile for FixedVhdDiskAsync { - fn try_clone(&self) -> BlockResult> { - Ok(Box::new(FixedVhdDiskAsync(self.0.clone()))) - } - - fn create_async_io(&self, ring_depth: u32) -> BlockResult> { - let size = self - .0 - .logical_size() - .map_err(|e| BlockError::new(BlockErrorKind::Io, e))?; - Ok(Box::new(FixedVhdAsync::new( - self.0.as_raw_fd(), - ring_depth, - size, - )?)) - } -} pub struct FixedVhdAsync { raw_file_async: RawFileAsync, diff --git a/block/src/fixed_vhd_sync.rs b/block/src/fixed_vhd_sync.rs index fd74e0123..bcf16f4f5 100644 --- a/block/src/fixed_vhd_sync.rs +++ b/block/src/fixed_vhd_sync.rs @@ -2,87 +2,12 @@ // // SPDX-License-Identifier: Apache-2.0 -use std::fs::File; -use std::os::unix::io::{AsRawFd, RawFd}; +use std::os::unix::io::RawFd; use vmm_sys_util::eventfd::EventFd; -use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult, BorrowedDiskFd, DiskFileError}; -use crate::error::{BlockError, BlockErrorKind, BlockResult, ErrorOp}; -use crate::fixed_vhd::FixedVhd; +use crate::async_io::{AsyncIo, AsyncIoError, AsyncIoResult}; use crate::raw_sync::RawFileSync; -use crate::{BlockBackend, disk_file}; - -#[derive(Debug)] -pub struct FixedVhdDiskSync(FixedVhd); - -impl FixedVhdDiskSync { - pub fn new(file: File) -> BlockResult { - Ok(Self( - FixedVhd::new(file).map_err(|e| BlockError::from(e).with_op(ErrorOp::Open))?, - )) - } -} - -impl disk_file::DiskSize for FixedVhdDiskSync { - fn logical_size(&self) -> BlockResult { - self.0 - .logical_size() - .map_err(|e| BlockError::new(BlockErrorKind::Io, e)) - } -} - -impl disk_file::PhysicalSize for FixedVhdDiskSync { - fn physical_size(&self) -> BlockResult { - self.0.physical_size().map_err(|e| match e { - crate::Error::GetFileMetadata(io) => { - BlockError::new(BlockErrorKind::Io, crate::Error::GetFileMetadata(io)) - } - _ => unreachable!("unexpected error from FixedVhd::physical_size(): {e}"), - }) - } -} - -impl disk_file::DiskFd for FixedVhdDiskSync { - fn fd(&self) -> BorrowedDiskFd<'_> { - BorrowedDiskFd::new(self.0.as_raw_fd()) - } -} - -impl disk_file::Geometry for FixedVhdDiskSync {} - -impl disk_file::SparseCapable for FixedVhdDiskSync {} - -impl disk_file::Resizable for FixedVhdDiskSync { - fn resize(&mut self, _size: u64) -> BlockResult<()> { - Err(BlockError::new( - BlockErrorKind::UnsupportedFeature, - DiskFileError::ResizeError(std::io::Error::other("resize not supported for fixed VHD")), - ) - .with_op(ErrorOp::Resize)) - } -} - -impl disk_file::DiskFile for FixedVhdDiskSync {} - -impl disk_file::AsyncDiskFile for FixedVhdDiskSync { - fn try_clone(&self) -> BlockResult> { - Ok(Box::new(FixedVhdDiskSync(self.0.clone()))) - } - - fn create_async_io(&self, _ring_depth: u32) -> BlockResult> { - let size = self - .0 - .logical_size() - .map_err(|e| BlockError::new(BlockErrorKind::Io, e))?; - Ok(Box::new( - FixedVhdSync::new(self.0.as_raw_fd(), size).map_err(|e| { - BlockError::new(BlockErrorKind::Io, DiskFileError::NewAsyncIo(e)) - .with_op(ErrorOp::Open) - })?, - )) - } -} pub struct FixedVhdSync { raw_file_sync: RawFileSync,