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

@@ -78,18 +78,17 @@ struct VhostUserBlkBackend {
impl VhostUserBlkBackend {
pub fn new(image_path: String, rdonly: bool) -> Result<Self> {
let raw_img: File = OpenOptions::new()
let image: File = OpenOptions::new()
.read(true)
.write(!rdonly)
.open(&image_path)
.unwrap();
let mut raw_img = vm_virtio::RawFile::new(image, false);
let image_id = build_disk_image_id(&PathBuf::from(&image_path));
let image_type = qcow::detect_image_type(&raw_img).unwrap();
let image_type = qcow::detect_image_type(&mut raw_img).unwrap();
let mut image = match image_type {
ImageType::Raw => {
Box::new(vm_virtio::RawFile::new(raw_img, false)) as Box<dyn DiskFile>
}
ImageType::Raw => Box::new(raw_img) as Box<dyn DiskFile>,
ImageType::Qcow2 => Box::new(QcowFile::from(raw_img).unwrap()) as Box<dyn DiskFile>,
};