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 <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-04-16 11:18:19 +02:00
committed by Rob Bradford
parent a8d339c9e7
commit da64acb775
2 changed files with 16 additions and 9 deletions
+8 -7
View File
@@ -26,7 +26,9 @@ impl FixedVhdDiskAsync {
impl disk_file::DiskSize for FixedVhdDiskAsync { impl disk_file::DiskSize for FixedVhdDiskAsync {
fn logical_size(&self) -> BlockResult<u64> { fn logical_size(&self) -> BlockResult<u64> {
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<Box<dyn AsyncIo>> { fn new_async_io(&self, ring_depth: u32) -> BlockResult<Box<dyn AsyncIo>> {
let size = self
.0
.logical_size()
.map_err(|e| BlockError::new(BlockErrorKind::Io, e))?;
Ok(Box::new( Ok(Box::new(
FixedVhdAsync::new( FixedVhdAsync::new(self.0.as_raw_fd(), ring_depth, size).map_err(|e| {
self.0.as_raw_fd(),
ring_depth,
self.0.logical_size().unwrap(),
)
.map_err(|e| {
BlockError::new(BlockErrorKind::Io, DiskFileError::NewAsyncIo(e)) BlockError::new(BlockErrorKind::Io, DiskFileError::NewAsyncIo(e))
.with_op(ErrorOp::Open) .with_op(ErrorOp::Open)
})?, })?,
+8 -2
View File
@@ -26,7 +26,9 @@ impl FixedVhdDiskSync {
impl disk_file::DiskSize for FixedVhdDiskSync { impl disk_file::DiskSize for FixedVhdDiskSync {
fn logical_size(&self) -> BlockResult<u64> { fn logical_size(&self) -> BlockResult<u64> {
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<Box<dyn AsyncIo>> { fn new_async_io(&self, _ring_depth: u32) -> BlockResult<Box<dyn AsyncIo>> {
let size = self
.0
.logical_size()
.map_err(|e| BlockError::new(BlockErrorKind::Io, e))?;
Ok(Box::new( 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)) BlockError::new(BlockErrorKind::Io, DiskFileError::NewAsyncIo(e))
.with_op(ErrorOp::Open) .with_op(ErrorOp::Open)
})?, })?,