Skip to content

Commit f6b4061

Browse files
russell-islamliuw
authored andcommitted
block: Return BlockResult from RawFileAsyncAio::new()
Change the return type of RawFileAsyncAio::new() from std::io::Result<Self> to BlockResult<Self>, wrapping internal errors from EventFd::new() and IoContext::new() in BlockError with DiskFileError::NewAsyncIo. This simplifies the caller in AsyncDiskFile::new_async_io() which no longer needs its own error mapping. Signed-off-by: Muminul Islam <muislam@microsoft.com>
1 parent 783cc8b commit f6b4061

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

block/src/raw_async_aio.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ impl disk_file::AsyncDiskFile for RawFileDiskAio {
8686
}
8787

8888
fn new_async_io(&self, ring_depth: u32) -> BlockResult<Box<dyn AsyncIo>> {
89-
let mut raw = RawFileAsyncAio::new(self.file.as_raw_fd(), ring_depth)
90-
.map_err(|e| BlockError::new(BlockErrorKind::Io, DiskFileError::NewAsyncIo(e)))?;
89+
let mut raw = RawFileAsyncAio::new(self.file.as_raw_fd(), ring_depth)?;
9190
raw.alignment =
9291
DiskTopology::probe(&self.file).map_or(SECTOR_SIZE, |t| t.logical_block_size);
9392
Ok(Box::new(raw) as Box<dyn AsyncIo>)
@@ -103,9 +102,11 @@ pub struct RawFileAsyncAio {
103102
}
104103

105104
impl RawFileAsyncAio {
106-
pub fn new(fd: RawFd, queue_depth: u32) -> std::io::Result<Self> {
107-
let eventfd = EventFd::new(libc::EFD_NONBLOCK)?;
108-
let ctx = aio::IoContext::new(queue_depth)?;
105+
pub fn new(fd: RawFd, queue_depth: u32) -> BlockResult<Self> {
106+
let eventfd =
107+
EventFd::new(libc::EFD_NONBLOCK).map_err(|e| BlockError::new(BlockErrorKind::Io, e))?;
108+
let ctx =
109+
aio::IoContext::new(queue_depth).map_err(|e| BlockError::new(BlockErrorKind::Io, e))?;
109110

110111
Ok(RawFileAsyncAio {
111112
fd,

0 commit comments

Comments
 (0)