block: qcow: Remove From<qcow::Error> for BlockError

All public qcow functions now return BlockResult with explicit error
classification at every site. The temporary From impl introduced in
the first commit of this series is no longer needed and is removed.

Internal functions in header.rs and the rebuild_refcounts helpers
stay on qcow::Result. Classification happens at the call site
boundary where qcow::Result meets BlockResult.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-03-14 01:07:31 +01:00
committed by Rob Bradford
parent 5410d4b2d5
commit fc79d08d7d

View File

@@ -242,56 +242,4 @@ impl From<io::Error> for BlockError {
}
}
/// Temporary scaffolding: classify a `qcow::Error` into the appropriate
/// `BlockErrorKind`.
///
/// This impl exists only to allow an incremental migration of the qcow
/// parse/construct chain from `qcow::Result` to `BlockResult`. Each
/// subsequent commit replaces bare `?` sites with explicit
/// `BlockError::new(kind, e)` calls. Once every site is migrated this
/// impl will be removed.
impl From<crate::qcow::Error> for BlockError {
fn from(e: crate::qcow::Error) -> Self {
use crate::qcow::Error as E;
let kind = match &e {
// Structural / format violations
E::InvalidMagic
| E::BackingFileTooLong(_)
| E::InvalidBackingFileName(_)
| E::InvalidClusterSize
| E::InvalidL1TableSize(_)
| E::InvalidL1TableOffset
| E::InvalidOffset(_)
| E::InvalidRefcountTableOffset
| E::InvalidRefcountTableSize(_)
| E::FileTooBig(_)
| E::NoRefcountClusters
| E::RefcountTableOffEnd
| E::RefcountTableTooLarge
| E::TooManyL1Entries(_)
| E::TooManyRefcounts(_)
| E::SizeTooSmallForNumberOfClusters => BlockErrorKind::InvalidFormat,
// Unsupported features / versions
E::UnsupportedVersion(_)
| E::UnsupportedFeature(_)
| E::UnsupportedCompressionType
| E::UnsupportedBackingFileFormat(_)
| E::UnsupportedRefcountOrder
| E::BackingFilesDisabled
| E::ShrinkNotSupported => BlockErrorKind::UnsupportedFeature,
// Corrupt image
E::CorruptImage => BlockErrorKind::CorruptImage,
// Nesting depth overflow
E::MaxNestingDepthExceeded => BlockErrorKind::Overflow,
// Everything else is I/O
_ => BlockErrorKind::Io,
};
Self::new(kind, e)
}
}
pub type BlockResult<T> = Result<T, BlockError>;