mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: Implement AsyncDiskFile trait for RawFileDisk
Add disk_file::AsyncDiskFile trait implementation for RawFileDisk with try_clone() and new_async_io() methods. try_clone() duplicates the underlying file descriptor and wraps it in a new RawFileDisk. new_async_io() creates a RawFileAsync (io_uring) backend, wrapping errors in BlockError instead of DiskFileError. Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
@@ -121,6 +121,24 @@ impl disk_file::Resizable for RawFileDisk {
|
||||
|
||||
impl disk_file::DiskFile for RawFileDisk {}
|
||||
|
||||
impl disk_file::AsyncDiskFile for RawFileDisk {
|
||||
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(RawFileDisk { file }))
|
||||
}
|
||||
|
||||
fn new_async_io(&self, ring_depth: u32) -> BlockResult<Box<dyn AsyncIo>> {
|
||||
let mut raw = RawFileAsync::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 RawFileAsync {
|
||||
fd: RawFd,
|
||||
io_uring: IoUring,
|
||||
|
||||
Reference in New Issue
Block a user