mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
committed by
Rob Bradford
parent
a8d339c9e7
commit
da64acb775
@@ -26,7 +26,9 @@ impl FixedVhdDiskAsync {
|
||||
|
||||
impl disk_file::DiskSize for FixedVhdDiskAsync {
|
||||
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>> {
|
||||
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)
|
||||
})?,
|
||||
|
||||
@@ -26,7 +26,9 @@ impl FixedVhdDiskSync {
|
||||
|
||||
impl disk_file::DiskSize for FixedVhdDiskSync {
|
||||
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>> {
|
||||
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)
|
||||
})?,
|
||||
|
||||
Reference in New Issue
Block a user