From da64acb7754a6e324da93729fa79b7232a72b6b6 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 16 Apr 2026 11:18:19 +0200 Subject: [PATCH] block: vhd: Propagate logical_size error at boundary Replace .unwrap() on FixedVhd::logical_size() with map_err in DiskSize::logical_size() and new_async_io() for both FixedVhdDiskSync and FixedVhdDiskAsync. The call is infallible today but unwrap hides that assumption from callers and would panic if it ever changed. Signed-off-by: Anatol Belski --- block/src/fixed_vhd_async.rs | 15 ++++++++------- block/src/fixed_vhd_sync.rs | 10 ++++++++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/block/src/fixed_vhd_async.rs b/block/src/fixed_vhd_async.rs index d54670315..e8b28c44c 100644 --- a/block/src/fixed_vhd_async.rs +++ b/block/src/fixed_vhd_async.rs @@ -26,7 +26,9 @@ impl FixedVhdDiskAsync { impl disk_file::DiskSize for FixedVhdDiskAsync { fn logical_size(&self) -> BlockResult { - Ok(self.0.logical_size().unwrap()) + self.0 + .logical_size() + .map_err(|e| BlockError::new(BlockErrorKind::Io, e)) } } @@ -69,13 +71,12 @@ impl disk_file::AsyncDiskFile for FixedVhdDiskAsync { } fn new_async_io(&self, ring_depth: u32) -> BlockResult> { + let size = self + .0 + .logical_size() + .map_err(|e| BlockError::new(BlockErrorKind::Io, e))?; Ok(Box::new( - FixedVhdAsync::new( - self.0.as_raw_fd(), - ring_depth, - self.0.logical_size().unwrap(), - ) - .map_err(|e| { + FixedVhdAsync::new(self.0.as_raw_fd(), ring_depth, size).map_err(|e| { BlockError::new(BlockErrorKind::Io, DiskFileError::NewAsyncIo(e)) .with_op(ErrorOp::Open) })?, diff --git a/block/src/fixed_vhd_sync.rs b/block/src/fixed_vhd_sync.rs index 877b17c1d..d7a578393 100644 --- a/block/src/fixed_vhd_sync.rs +++ b/block/src/fixed_vhd_sync.rs @@ -26,7 +26,9 @@ impl FixedVhdDiskSync { impl disk_file::DiskSize for FixedVhdDiskSync { fn logical_size(&self) -> BlockResult { - Ok(self.0.logical_size().unwrap()) + self.0 + .logical_size() + .map_err(|e| BlockError::new(BlockErrorKind::Io, e)) } } @@ -69,8 +71,12 @@ impl disk_file::AsyncDiskFile for FixedVhdDiskSync { } fn new_async_io(&self, _ring_depth: u32) -> BlockResult> { + let size = self + .0 + .logical_size() + .map_err(|e| BlockError::new(BlockErrorKind::Io, e))?; Ok(Box::new( - FixedVhdSync::new(self.0.as_raw_fd(), self.0.logical_size().unwrap()).map_err(|e| { + FixedVhdSync::new(self.0.as_raw_fd(), size).map_err(|e| { BlockError::new(BlockErrorKind::Io, DiskFileError::NewAsyncIo(e)) .with_op(ErrorOp::Open) })?,