qcow: Use RawFile as backend instead of File

Use RawFile as backend instead of File. This allows us to abstract
the access to the actual image with a specialized layer, so we have a
place where we can deal with the low-level peculiarities.

Signed-off-by: Sergio Lopez <slp@redhat.com>
This commit is contained in:
Sergio Lopez
2020-01-15 13:20:02 -05:00
committed by Rob Bradford
parent c5a656c9dc
commit a14aee9213
6 changed files with 93 additions and 73 deletions

View File

@@ -927,17 +927,18 @@ impl DeviceManager {
if let Some(disk_list_cfg) = &vm_info.vm_cfg.lock().unwrap().disks {
for disk_cfg in disk_list_cfg.iter() {
// Open block device path
let raw_img: File = OpenOptions::new()
let image: File = OpenOptions::new()
.read(true)
.write(true)
.open(&disk_cfg.path)
.map_err(DeviceManagerError::Disk)?;
let image_type = qcow::detect_image_type(&raw_img)
let mut raw_img = vm_virtio::RawFile::new(image, false);
let image_type = qcow::detect_image_type(&mut raw_img)
.map_err(DeviceManagerError::DetectImageType)?;
match image_type {
ImageType::Raw => {
let raw_img = vm_virtio::RawFile::new(raw_img, false);
let dev = vm_virtio::Block::new(
raw_img,
disk_cfg.path.clone(),