mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
committed by
Rob Bradford
parent
c5a656c9dc
commit
a14aee9213
@@ -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>,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user