| 50 | |
| 51 | impl QcowDisk { |
| 52 | pub fn new( |
| 53 | file: File, |
| 54 | direct_io: bool, |
| 55 | backing_files: bool, |
| 56 | sparse: bool, |
| 57 | use_io_uring: bool, |
| 58 | ) -> BlockResult<Self> { |
| 59 | #[cfg(not(feature = "io_uring"))] |
| 60 | if use_io_uring { |
| 61 | return Err(BlockError::new( |
| 62 | BlockErrorKind::UnsupportedFeature, |
| 63 | DiskFileError::NewAsyncIo(io::Error::other( |
| 64 | "io_uring requested but feature is not enabled", |
| 65 | )), |
| 66 | )); |
| 67 | } |
| 68 | |
| 69 | let max_nesting_depth = if backing_files { MAX_NESTING_DEPTH } else { 0 }; |
| 70 | let raw_file = RawFile::new(file, direct_io); |
| 71 | let (inner, backing_file, sparse) = parse_qcow(raw_file, max_nesting_depth, sparse) |
| 72 | .map_err(|e| { |
| 73 | let e = if !backing_files && matches!(e.kind(), BlockErrorKind::Overflow) { |
| 74 | e.with_kind(BlockErrorKind::UnsupportedFeature) |
| 75 | } else { |
| 76 | e |
| 77 | }; |
| 78 | e.with_op(ErrorOp::Open) |
| 79 | })?; |
| 80 | let data_raw_file = inner.raw_file.clone(); |
| 81 | Ok(QcowDisk { |
| 82 | metadata: Arc::new(QcowMetadata::new(inner)), |
| 83 | backing_file: backing_file.map(shared_backing_from).transpose()?, |
| 84 | sparse, |
| 85 | data_raw_file, |
| 86 | use_io_uring, |
| 87 | }) |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | impl Drop for QcowDisk { |