mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: raw: Impl DiskFile and AsyncDiskFile for RawDisk
Add the DiskFile marker and AsyncDiskFile with try_clone and create_async_io. The dispatch creates RawFileSync, RawFileAsync, or RawFileAsyncAio depending on the backend selected at construction. Alignment handling is left to the workers as is, to be centralized separately per #8050. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
@@ -9,8 +9,12 @@ use std::os::unix::io::AsRawFd;
|
||||
|
||||
use log::warn;
|
||||
|
||||
use crate::async_io::{BorrowedDiskFd, DiskFileError};
|
||||
use crate::async_io::{AsyncIo, BorrowedDiskFd, DiskFileError};
|
||||
use crate::error::{BlockError, BlockErrorKind, BlockResult};
|
||||
#[cfg(feature = "io_uring")]
|
||||
use crate::raw_async::RawFileAsync;
|
||||
use crate::raw_async_aio::RawFileAsyncAio;
|
||||
use crate::raw_sync::RawFileSync;
|
||||
use crate::{DiskTopology, disk_file, probe_sparse_support, query_device_size};
|
||||
|
||||
/// Selects which async I/O backend a `RawDisk` uses.
|
||||
@@ -108,3 +112,33 @@ impl disk_file::Resizable for RawDisk {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl disk_file::DiskFile for RawDisk {}
|
||||
|
||||
impl disk_file::AsyncDiskFile for RawDisk {
|
||||
fn try_clone(&self) -> BlockResult<Box<dyn disk_file::AsyncDiskFile>> {
|
||||
let file = self
|
||||
.file
|
||||
.try_clone()
|
||||
.map_err(|e| BlockError::new(BlockErrorKind::Io, DiskFileError::Clone(e)))?;
|
||||
Ok(Box::new(RawDisk {
|
||||
file,
|
||||
backend: self.backend,
|
||||
}))
|
||||
}
|
||||
|
||||
fn create_async_io(&self, ring_depth: u32) -> BlockResult<Box<dyn AsyncIo>> {
|
||||
match self.backend {
|
||||
RawBackend::Sync => Ok(Box::new(RawFileSync::new(self.file.as_raw_fd()))),
|
||||
#[cfg(feature = "io_uring")]
|
||||
RawBackend::IoUring => Ok(Box::new(RawFileAsync::new(
|
||||
self.file.as_raw_fd(),
|
||||
ring_depth,
|
||||
)?)),
|
||||
RawBackend::Aio => Ok(Box::new(RawFileAsyncAio::new(
|
||||
self.file.as_raw_fd(),
|
||||
ring_depth,
|
||||
)?)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user