block: qcow: Migrate convert_reader_writer() to BlockResult

Switch convert_reader_writer() to BlockResult, preserving the
original qcow::Error variants as the BlockError source. The
inner convert_copy() call now propagates BlockResult naturally.
Callers get map_err bridges where they still return qcow::Error.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-03-09 23:18:34 +01:00
committed by Rob Bradford
parent c59c5687d2
commit 748666fe4d
+16 -6
View File
@@ -2060,7 +2060,7 @@ where
Ok(()) Ok(())
} }
fn convert_reader_writer<R, W>(reader: &mut R, writer: &mut W, size: u64) -> Result<()> fn convert_reader_writer<R, W>(reader: &mut R, writer: &mut W, size: u64) -> BlockResult<()>
where where
R: Read + Seek + SeekHole, R: Read + Seek + SeekHole,
W: Write + Seek, W: Write + Seek,
@@ -2068,24 +2068,32 @@ where
let mut offset = 0; let mut offset = 0;
while offset < size { while offset < size {
// Find the next range of data. // Find the next range of data.
let next_data = match reader.seek_data(offset).map_err(Error::SeekingFile)? { let next_data = match reader
.seek_data(offset)
.map_err(|e| BlockError::new(BlockErrorKind::Io, Error::SeekingFile(e)))?
{
Some(o) => o, Some(o) => o,
None => { None => {
// No more data in the file. // No more data in the file.
break; break;
} }
}; };
let next_hole = match reader.seek_hole(next_data).map_err(Error::SeekingFile)? { let next_hole = match reader
.seek_hole(next_data)
.map_err(|e| BlockError::new(BlockErrorKind::Io, Error::SeekingFile(e)))?
{
Some(o) => o, Some(o) => o,
None => { None => {
// This should not happen - there should always be at least one hole // This should not happen - there should always be at least one hole
// after any data. // after any data.
return Err(Error::SeekingFile(io::Error::from_raw_os_error(EINVAL))); return Err(BlockError::new(
BlockErrorKind::Io,
Error::SeekingFile(io::Error::from_raw_os_error(EINVAL)),
));
} }
}; };
let count = next_hole - next_data; let count = next_hole - next_data;
convert_copy(reader, writer, next_data, count) convert_copy(reader, writer, next_data, count)?;
.map_err(|e| Error::ReadingData(io::Error::other(e)))?;
offset = next_hole; offset = next_hole;
} }
@@ -2106,6 +2114,7 @@ where
ImageType::Qcow2 => { ImageType::Qcow2 => {
let mut dst_writer = QcowFile::new(dst_file, 3, src_size, true)?; let mut dst_writer = QcowFile::new(dst_file, 3, src_size, true)?;
convert_reader_writer(reader, &mut dst_writer, src_size) convert_reader_writer(reader, &mut dst_writer, src_size)
.map_err(|e| Error::WritingData(io::Error::other(e)))
} }
ImageType::Raw => { ImageType::Raw => {
let mut dst_writer = dst_file; let mut dst_writer = dst_file;
@@ -2115,6 +2124,7 @@ where
.set_len(src_size) .set_len(src_size)
.map_err(Error::SettingFileSize)?; .map_err(Error::SettingFileSize)?;
convert_reader_writer(reader, &mut dst_writer, src_size) convert_reader_writer(reader, &mut dst_writer, src_size)
.map_err(|e| Error::WritingData(io::Error::other(e)))
} }
} }
} }