Skip to content

Commit 6df7cda

Browse files
russell-islamliuw
authored andcommitted
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>
1 parent 39bbbaa commit 6df7cda

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

block/src/raw_async_aio.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,24 @@ impl disk_file::Resizable for RawFileDiskAio {
117117

118118
impl disk_file::DiskFile for RawFileDiskAio {}
119119

120+
impl disk_file::AsyncDiskFile for RawFileDiskAio {
121+
fn try_clone(&self) -> BlockResult<Box<dyn disk_file::AsyncDiskFile>> {
122+
let file = self
123+
.file
124+
.try_clone()
125+
.map_err(|e| BlockError::new(BlockErrorKind::Io, DiskFileError::Clone(e)))?;
126+
Ok(Box::new(RawFileDiskAio { file }))
127+
}
128+
129+
fn new_async_io(&self, ring_depth: u32) -> BlockResult<Box<dyn AsyncIo>> {
130+
let mut raw = RawFileAsyncAio::new(self.file.as_raw_fd(), ring_depth)
131+
.map_err(|e| BlockError::new(BlockErrorKind::Io, DiskFileError::NewAsyncIo(e)))?;
132+
raw.alignment =
133+
DiskTopology::probe(&self.file).map_or(SECTOR_SIZE, |t| t.logical_block_size);
134+
Ok(Box::new(raw) as Box<dyn AsyncIo>)
135+
}
136+
}
137+
120138
pub struct RawFileAsyncAio {
121139
fd: RawFd,
122140
ctx: aio::IoContext,

0 commit comments

Comments
 (0)