mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: Implement AsyncDiskFile trait for RawFileDiskAio
Add disk_file::AsyncDiskFile trait implementation for RawFileDiskAio with try_clone() and new_async_io() methods. try_clone() duplicates the underlying file descriptor and wraps it in a new RawFileDiskAio. new_async_io() creates a RawFileAsyncAio (Linux AIO) backend, wrapping errors in BlockError instead of DiskFileError. Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
@@ -117,6 +117,24 @@ impl disk_file::Resizable for RawFileDiskAio {
|
|||||||
|
|
||||||
impl disk_file::DiskFile for RawFileDiskAio {}
|
impl disk_file::DiskFile for RawFileDiskAio {}
|
||||||
|
|
||||||
|
impl disk_file::AsyncDiskFile for RawFileDiskAio {
|
||||||
|
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(RawFileDiskAio { file }))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new_async_io(&self, ring_depth: u32) -> BlockResult<Box<dyn AsyncIo>> {
|
||||||
|
let mut raw = RawFileAsyncAio::new(self.file.as_raw_fd(), ring_depth)
|
||||||
|
.map_err(|e| BlockError::new(BlockErrorKind::Io, DiskFileError::NewAsyncIo(e)))?;
|
||||||
|
raw.alignment =
|
||||||
|
DiskTopology::probe(&self.file).map_or(SECTOR_SIZE, |t| t.logical_block_size);
|
||||||
|
Ok(Box::new(raw) as Box<dyn AsyncIo>)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct RawFileAsyncAio {
|
pub struct RawFileAsyncAio {
|
||||||
fd: RawFd,
|
fd: RawFd,
|
||||||
ctx: aio::IoContext,
|
ctx: aio::IoContext,
|
||||||
|
|||||||
Reference in New Issue
Block a user