mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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 <anbelski@linux.microsoft.com>
This commit is contained in:
@@ -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))?,
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Self> {
|
||||
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<u64> {
|
||||
self.0
|
||||
.logical_size()
|
||||
.map_err(|e| BlockError::new(BlockErrorKind::Io, e))
|
||||
}
|
||||
}
|
||||
|
||||
impl disk_file::PhysicalSize for FixedVhdDiskAsync {
|
||||
fn physical_size(&self) -> BlockResult<u64> {
|
||||
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<Box<dyn disk_file::AsyncDiskFile>> {
|
||||
Ok(Box::new(FixedVhdDiskAsync(self.0.clone())))
|
||||
}
|
||||
|
||||
fn create_async_io(&self, ring_depth: u32) -> BlockResult<Box<dyn AsyncIo>> {
|
||||
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,
|
||||
|
||||
@@ -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<Self> {
|
||||
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<u64> {
|
||||
self.0
|
||||
.logical_size()
|
||||
.map_err(|e| BlockError::new(BlockErrorKind::Io, e))
|
||||
}
|
||||
}
|
||||
|
||||
impl disk_file::PhysicalSize for FixedVhdDiskSync {
|
||||
fn physical_size(&self) -> BlockResult<u64> {
|
||||
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<Box<dyn disk_file::AsyncDiskFile>> {
|
||||
Ok(Box::new(FixedVhdDiskSync(self.0.clone())))
|
||||
}
|
||||
|
||||
fn create_async_io(&self, _ring_depth: u32) -> BlockResult<Box<dyn AsyncIo>> {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user