From 662d350cf9c086f043d103a4a72a52c24b26ee86 Mon Sep 17 00:00:00 2001 From: Muminul Islam Date: Tue, 24 Mar 2026 17:36:39 -0700 Subject: [PATCH] block: Implement AsyncDiskFile trait for RawFileDiskSync Add disk_file::AsyncDiskFile trait implementation for RawFileDiskSync with try_clone() and new_async_io() methods. try_clone() duplicates the underlying file descriptor and wraps it in a new RawFileDiskSync. new_async_io() creates a RawFileSync (synchronous fallback) backend, wrapping errors in BlockError instead of DiskFileError. Add DiskFileError::Clone variant in async_io.rs for the try_clone() error path. Signed-off-by: Muminul Islam --- block/src/raw_sync.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/block/src/raw_sync.rs b/block/src/raw_sync.rs index d25709d80..0e95fa8e2 100644 --- a/block/src/raw_sync.rs +++ b/block/src/raw_sync.rs @@ -112,6 +112,23 @@ impl disk_file::Resizable for RawFileDiskSync { impl disk_file::DiskFile for RawFileDiskSync {} +impl disk_file::AsyncDiskFile for RawFileDiskSync { + fn try_clone(&self) -> BlockResult> { + let file = self + .file + .try_clone() + .map_err(|e| BlockError::new(BlockErrorKind::Io, DiskFileError::Clone(e)))?; + Ok(Box::new(RawFileDiskSync { file })) + } + + fn new_async_io(&self, _ring_depth: u32) -> BlockResult> { + let mut raw = RawFileSync::new(self.file.as_raw_fd()); + raw.alignment = + DiskTopology::probe(&self.file).map_or(SECTOR_SIZE, |t| t.logical_block_size); + Ok(Box::new(raw) as Box) + } +} + pub struct RawFileSync { fd: RawFd, eventfd: EventFd,