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<'_>)
| 83 | /// callers can perform post construction validation (e.g. type mismatch |
| 84 | /// checks, configuration warnings). |
| 85 | pub 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 | |
| 111 | fn open_vhdx( |
| 112 | file: fs::File, |