mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
This is a prerequisite for the next steps. Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de> On-behalf-of: SAP philipp.schuster@sap.com
70 lines
2.1 KiB
Rust
70 lines
2.1 KiB
Rust
// Copyright © 2021 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
|
|
|
use std::os::fd::RawFd;
|
|
|
|
use thiserror::Error;
|
|
use vmm_sys_util::eventfd::EventFd;
|
|
|
|
use crate::DiskTopology;
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum DiskFileError {
|
|
/// Failed getting disk file size.
|
|
#[error("Failed getting disk file size: {0}")]
|
|
Size(#[source] std::io::Error),
|
|
/// Failed creating a new AsyncIo.
|
|
#[error("Failed creating a new AsyncIo: {0}")]
|
|
NewAsyncIo(#[source] std::io::Error),
|
|
}
|
|
|
|
pub type DiskFileResult<T> = std::result::Result<T, DiskFileError>;
|
|
|
|
pub trait DiskFile: Send {
|
|
fn size(&mut self) -> DiskFileResult<u64>;
|
|
fn new_async_io(&self, ring_depth: u32) -> DiskFileResult<Box<dyn AsyncIo>>;
|
|
fn topology(&mut self) -> DiskTopology {
|
|
DiskTopology::default()
|
|
}
|
|
/// Returns the file descriptor of the underlying disk image file.
|
|
// Impl Note:
|
|
// This must be `RawFd` instead of `BorrowedFd` or `&File`, as some
|
|
// implementations wrap the file in an `Arc<Mutex<T>>`, which makes it
|
|
// impossible to return a reference.
|
|
fn fd(&mut self) -> RawFd;
|
|
}
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum AsyncIoError {
|
|
/// Failed vectored reading from file.
|
|
#[error("Failed vectored reading from file: {0}")]
|
|
ReadVectored(#[source] std::io::Error),
|
|
/// Failed vectored writing to file.
|
|
#[error("Failed vectored writing to file: {0}")]
|
|
WriteVectored(#[source] std::io::Error),
|
|
/// Failed synchronizing file.
|
|
#[error("Failed synchronizing file: {0}")]
|
|
Fsync(#[source] std::io::Error),
|
|
}
|
|
|
|
pub type AsyncIoResult<T> = std::result::Result<T, AsyncIoError>;
|
|
|
|
pub trait AsyncIo: Send {
|
|
fn notifier(&self) -> &EventFd;
|
|
fn read_vectored(
|
|
&mut self,
|
|
offset: libc::off_t,
|
|
iovecs: &[libc::iovec],
|
|
user_data: u64,
|
|
) -> AsyncIoResult<()>;
|
|
fn write_vectored(
|
|
&mut self,
|
|
offset: libc::off_t,
|
|
iovecs: &[libc::iovec],
|
|
user_data: u64,
|
|
) -> AsyncIoResult<()>;
|
|
fn fsync(&mut self, user_data: Option<u64>) -> AsyncIoResult<()>;
|
|
fn next_completed_request(&mut self) -> Option<(u64, i32)>;
|
|
}
|