From 7294ca99cfd8a4626212b35eed3b988bff30a274 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Fri, 17 Apr 2026 11:07:21 +0200 Subject: [PATCH] block: raw: Return BlockResult from RawFileAsync::new Change RawFileAsync::new() from std::io::Result to BlockResult, aligning it with RawFileAsyncAio::new(). Each fallible call inside the constructor now maps to BlockErrorKind::Io explicitly. FixedVhdAsync::new() follows the same change since its only fallible operation is constructing a RawFileAsync. The intermediate DiskFileError::NewAsyncIo wrapping in both new_async_io() call sites is no longer needed and is removed. Signed-off-by: Anatol Belski --- block/src/fixed_vhd_async.rs | 13 ++++++------- block/src/raw_async.rs | 16 ++++++++++------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/block/src/fixed_vhd_async.rs b/block/src/fixed_vhd_async.rs index e8b28c44c..f1494b4b9 100644 --- a/block/src/fixed_vhd_async.rs +++ b/block/src/fixed_vhd_async.rs @@ -75,12 +75,11 @@ impl disk_file::AsyncDiskFile for FixedVhdDiskAsync { .0 .logical_size() .map_err(|e| BlockError::new(BlockErrorKind::Io, e))?; - Ok(Box::new( - FixedVhdAsync::new(self.0.as_raw_fd(), ring_depth, size).map_err(|e| { - BlockError::new(BlockErrorKind::Io, DiskFileError::NewAsyncIo(e)) - .with_op(ErrorOp::Open) - })?, - )) + Ok(Box::new(FixedVhdAsync::new( + self.0.as_raw_fd(), + ring_depth, + size, + )?)) } } @@ -90,7 +89,7 @@ pub struct FixedVhdAsync { } impl FixedVhdAsync { - pub fn new(fd: RawFd, ring_depth: u32, size: u64) -> std::io::Result { + pub fn new(fd: RawFd, ring_depth: u32, size: u64) -> BlockResult { let raw_file_async = RawFileAsync::new(fd, ring_depth)?; Ok(FixedVhdAsync { diff --git a/block/src/raw_async.rs b/block/src/raw_async.rs index 7fa3208f4..b2dbaa565 100644 --- a/block/src/raw_async.rs +++ b/block/src/raw_async.rs @@ -108,8 +108,7 @@ impl disk_file::AsyncDiskFile for RawFileDisk { } 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)))?; + let mut raw = RawFileAsync::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) @@ -124,13 +123,18 @@ pub struct RawFileAsync { } impl RawFileAsync { - pub fn new(fd: RawFd, ring_depth: u32) -> std::io::Result { - let io_uring = IoUring::new(ring_depth)?; - let eventfd = EventFd::new(libc::EFD_NONBLOCK)?; + pub fn new(fd: RawFd, ring_depth: u32) -> BlockResult { + let io_uring = + IoUring::new(ring_depth).map_err(|e| BlockError::new(BlockErrorKind::Io, e))?; + let eventfd = + EventFd::new(libc::EFD_NONBLOCK).map_err(|e| BlockError::new(BlockErrorKind::Io, e))?; // Register the io_uring eventfd that will notify when something in // the completion queue is ready. - io_uring.submitter().register_eventfd(eventfd.as_raw_fd())?; + io_uring + .submitter() + .register_eventfd(eventfd.as_raw_fd()) + .map_err(|e| BlockError::new(BlockErrorKind::Io, e))?; Ok(RawFileAsync { fd,