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 <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-04-17 11:07:21 +02:00
committed by Rob Bradford
parent cd9fc52472
commit 7294ca99cf
2 changed files with 16 additions and 13 deletions

View File

@@ -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<Self> {
pub fn new(fd: RawFd, ring_depth: u32, size: u64) -> BlockResult<Self> {
let raw_file_async = RawFileAsync::new(fd, ring_depth)?;
Ok(FixedVhdAsync {

View File

@@ -108,8 +108,7 @@ impl disk_file::AsyncDiskFile for RawFileDisk {
}
fn new_async_io(&self, ring_depth: u32) -> BlockResult<Box<dyn AsyncIo>> {
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<dyn AsyncIo>)
@@ -124,13 +123,18 @@ pub struct RawFileAsync {
}
impl RawFileAsync {
pub fn new(fd: RawFd, ring_depth: u32) -> std::io::Result<Self> {
let io_uring = IoUring::new(ring_depth)?;
let eventfd = EventFd::new(libc::EFD_NONBLOCK)?;
pub fn new(fd: RawFd, ring_depth: u32) -> BlockResult<Self> {
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,