block: qcow: Migrate convert_copy() to BlockResult

Switch convert_copy() to BlockResult, preserving the original
qcow::Error variants as the BlockError source for diagnostics.
A map_err bridge at the caller converts back where needed.

Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
Anatol Belski
2026-03-09 23:15:05 +01:00
committed by Rob Bradford
parent 732cddb8b3
commit c59c5687d2
+10 -6
View File
@@ -51,6 +51,7 @@ use vmm_sys_util::seek_hole::SeekHole;
use vmm_sys_util::write_zeroes::{PunchHole, WriteZeroesAt}; use vmm_sys_util::write_zeroes::{PunchHole, WriteZeroesAt};
use crate::BlockBackend; use crate::BlockBackend;
use crate::error::{BlockError, BlockErrorKind, BlockResult};
use crate::qcow::qcow_raw_file::{BeUint, QcowRawFile}; use crate::qcow::qcow_raw_file::{BeUint, QcowRawFile};
pub use crate::qcow::raw_file::RawFile; pub use crate::qcow::raw_file::RawFile;
use crate::qcow::refcount::RefCount; use crate::qcow::refcount::RefCount;
@@ -2028,7 +2029,7 @@ impl BlockBackend for QcowFile {
} }
} }
fn convert_copy<R, W>(reader: &mut R, writer: &mut W, offset: u64, size: u64) -> Result<()> fn convert_copy<R, W>(reader: &mut R, writer: &mut W, offset: u64, size: u64) -> BlockResult<()>
where where
R: Read + Seek, R: Read + Seek,
W: Write + Seek, W: Write + Seek,
@@ -2038,16 +2039,18 @@ where
let mut read_count = 0; let mut read_count = 0;
reader reader
.seek(SeekFrom::Start(offset)) .seek(SeekFrom::Start(offset))
.map_err(Error::SeekingFile)?; .map_err(|e| BlockError::new(BlockErrorKind::Io, Error::SeekingFile(e)))?;
writer writer
.seek(SeekFrom::Start(offset)) .seek(SeekFrom::Start(offset))
.map_err(Error::SeekingFile)?; .map_err(|e| BlockError::new(BlockErrorKind::Io, Error::SeekingFile(e)))?;
loop { loop {
let this_count = min(CHUNK_SIZE as u64, size - read_count) as usize; let this_count = min(CHUNK_SIZE as u64, size - read_count) as usize;
let nread = reader let nread = reader
.read(&mut buf[..this_count]) .read(&mut buf[..this_count])
.map_err(Error::ReadingData)?; .map_err(|e| BlockError::new(BlockErrorKind::Io, Error::ReadingData(e)))?;
writer.write(&buf[..nread]).map_err(Error::WritingData)?; writer
.write(&buf[..nread])
.map_err(|e| BlockError::new(BlockErrorKind::Io, Error::WritingData(e)))?;
read_count += nread as u64; read_count += nread as u64;
if nread == 0 || read_count == size { if nread == 0 || read_count == size {
break; break;
@@ -2081,7 +2084,8 @@ where
} }
}; };
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;
} }