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

Function open_disk

block/src/factory.rs:85–109  ·  view source on GitHub ↗

Open a disk image and construct the appropriate async backend. - Opens the file with the requested access mode and flags. - Detects the image format from the file header. - Probes io_uring and Linux AIO support on the running kernel. - Constructs the most capable backend available for the detected format, preferring io_uring over AIO over synchronous fallback. The returned [`OpenedDisk`] exposes

(options: &DiskOpenOptions<'_>)

Source from the content-addressed store, hash-verified

83/// callers can perform post construction validation (e.g. type mismatch
84/// checks, configuration warnings).
85pub fn open_disk(options: &DiskOpenOptions<'_>) -> BlockResult<OpenedDisk> {
86 let mut fs_options = fs::OpenOptions::new();
87 fs_options.read(true);
88 fs_options.write(!options.readonly);
89 if options.direct {
90 fs_options.custom_flags(libc::O_DIRECT);
91 }
92
93 let mut file = open_disk_image(options.path, &fs_options)?;
94 let image_type = detect_image_type(&mut file)?;
95
96 let disk: Box<dyn AsyncFullDiskFile> = match image_type {
97 ImageType::FixedVhd => open_fixed_vhd(file, options)?,
98 ImageType::Raw => open_raw(file, options)?,
99 ImageType::Qcow2 => open_qcow2(file, options)?,
100 ImageType::Vhdx => open_vhdx(file, options)?,
101 ImageType::Unknown => {
102 return Err(
103 BlockError::from_kind(BlockErrorKind::UnsupportedFeature).with_path(options.path)
104 );
105 }
106 };
107
108 Ok(OpenedDisk { image_type, disk })
109}
110
111fn open_vhdx(
112 file: fs::File,

Callers 6

detect_raw_imageFunction · 0.85
detect_qcow2_imageFunction · 0.85
open_readonlyFunction · 0.85

Calls 10

newFunction · 0.85
open_disk_imageFunction · 0.85
open_fixed_vhdFunction · 0.85
open_rawFunction · 0.85
open_qcow2Function · 0.85
open_vhdxFunction · 0.85
with_pathMethod · 0.80
detect_image_typeFunction · 0.70
readMethod · 0.45
writeMethod · 0.45

Tested by 5

detect_raw_imageFunction · 0.68
detect_qcow2_imageFunction · 0.68
open_readonlyFunction · 0.68