MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / convert

Function convert

block/src/qcow/mod.rs:2302–2322  ·  view source on GitHub ↗

Copy the contents of a disk image in `src_file` into `dst_file`. The type of `src_file` is automatically detected, and the output file type is determined by `dst_type`.

(
    mut src_file: RawFile,
    dst_file: RawFile,
    dst_type: ImageType,
    src_max_nesting_depth: u32,
)

Source from the content-addressed store, hash-verified

2300/// The type of `src_file` is automatically detected, and the output file type is
2301/// determined by `dst_type`.
2302pub fn convert(
2303 mut src_file: RawFile,
2304 dst_file: RawFile,
2305 dst_type: ImageType,
2306 src_max_nesting_depth: u32,
2307) -> BlockResult<()> {
2308 let src_type = detect_image_type(&mut src_file)?;
2309 match src_type {
2310 ImageType::Qcow2 => {
2311 let mut src_reader =
2312 QcowFile::from_with_nesting_depth(src_file, src_max_nesting_depth, true)
2313 .map_err(|e| BlockError::new(BlockErrorKind::Io, e))?;
2314 convert_reader(&mut src_reader, dst_file, dst_type)
2315 }
2316 ImageType::Raw => {
2317 // src_file is a raw file.
2318 let mut src_reader = src_file;
2319 convert_reader(&mut src_reader, dst_file, dst_type)
2320 }
2321 }
2322}
2323
2324/// Detect the type of an image file by checking for a valid qcow2 header.
2325pub fn detect_image_type(file: &mut RawFile) -> BlockResult<ImageType> {

Callers

nothing calls this directly

Calls 3

newFunction · 0.85
convert_readerFunction · 0.85
detect_image_typeFunction · 0.70

Tested by

no test coverage detected