From 491c5493c5c8dc72c8f972770940df3f7ddb1247 Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Tue, 24 Mar 2026 17:25:44 -0700 Subject: [PATCH] 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 --- block/src/raw_async.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/block/src/raw_async.rs b/block/src/raw_async.rs index 153a0a94f..42309edda 100644 --- a/block/src/raw_async.rs +++ b/block/src/raw_async.rs @@ -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> { + 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> { + 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) + } +} + pub struct RawFileAsync { fd: RawFd, io_uring: IoUring,