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>
This commit is contained in:
Muminul Islam
2026-03-27 23:55:41 -07:00
committed by Wei Liu
parent 783cc8bbd9
commit f6b4061629

View File

@@ -86,8 +86,7 @@ impl disk_file::AsyncDiskFile for RawFileDiskAio {
}
fn new_async_io(&self, ring_depth: u32) -> BlockResult<Box<dyn AsyncIo>> {
let mut raw = RawFileAsyncAio::new(self.file.as_raw_fd(), ring_depth)
.map_err(|e| BlockError::new(BlockErrorKind::Io, DiskFileError::NewAsyncIo(e)))?;
let mut raw = RawFileAsyncAio::new(self.file.as_raw_fd(), ring_depth)?;
raw.alignment =
DiskTopology::probe(&self.file).map_or(SECTOR_SIZE, |t| t.logical_block_size);
Ok(Box::new(raw) as Box<dyn AsyncIo>)
@@ -103,9 +102,11 @@ pub struct RawFileAsyncAio {
}
impl RawFileAsyncAio {
pub fn new(fd: RawFd, queue_depth: u32) -> std::io::Result<Self> {
let eventfd = EventFd::new(libc::EFD_NONBLOCK)?;
let ctx = aio::IoContext::new(queue_depth)?;
pub fn new(fd: RawFd, queue_depth: u32) -> BlockResult<Self> {
let eventfd =
EventFd::new(libc::EFD_NONBLOCK).map_err(|e| BlockError::new(BlockErrorKind::Io, e))?;
let ctx =
aio::IoContext::new(queue_depth).map_err(|e| BlockError::new(BlockErrorKind::Io, e))?;
Ok(RawFileAsyncAio {
fd,