mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: qcow: Add open_disk_image helper with path context
Add a small helper in the block crate that opens a disk image file and wraps any failure in a BlockError carrying the file path and operation context. Use it from the vmm device manager so that a failed open now reports which path couldn't be opened. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
2bcbe25539
commit
4fea912d18
@@ -32,7 +32,7 @@ pub mod vhdx_sync;
|
||||
use std::alloc::{Layout, alloc_zeroed, dealloc};
|
||||
use std::collections::VecDeque;
|
||||
use std::fmt::{self, Debug};
|
||||
use std::fs::File;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{self, IoSlice, IoSliceMut, Read, Seek, SeekFrom, Write};
|
||||
use std::os::linux::fs::MetadataExt;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
@@ -1065,6 +1065,16 @@ pub fn read_aligned_block_size(f: &mut File) -> std::io::Result<Vec<u8>> {
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
/// Open a disk image file, returning a [`BlockError`] with path context
|
||||
/// on failure.
|
||||
pub fn open_disk_image(path: &Path, options: &OpenOptions) -> BlockResult<File> {
|
||||
options.open(path).map_err(|e| {
|
||||
BlockError::new(BlockErrorKind::Io, e)
|
||||
.with_op(ErrorOp::Open)
|
||||
.with_path(path)
|
||||
})
|
||||
}
|
||||
|
||||
/// Determine image type through file parsing.
|
||||
pub fn detect_image_type(f: &mut File) -> BlockResult<ImageType> {
|
||||
let block = read_aligned_block_size(f)
|
||||
|
||||
Reference in New Issue
Block a user