mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-20 15:01:16 +00:00
vm-virtio: export block::Request and related funcs/structs
Export block::Request and related functions and structs so the code can be shared with vhost-user-blk. Signed-off-by: Sergio Lopez <slp@redhat.com>
This commit is contained in:
parent
08bebaae4f
commit
3a3dd0096c
@ -45,7 +45,7 @@ pub const KILL_EVENT: DeviceEventT = 1;
|
|||||||
pub const BLOCK_EVENTS_COUNT: usize = 2;
|
pub const BLOCK_EVENTS_COUNT: usize = 2;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum Error {
|
pub enum Error {
|
||||||
/// Guest gave us bad memory addresses.
|
/// Guest gave us bad memory addresses.
|
||||||
GuestMemory(GuestMemoryError),
|
GuestMemory(GuestMemoryError),
|
||||||
/// Guest gave us offsets that would have overflowed a usize.
|
/// Guest gave us offsets that would have overflowed a usize.
|
||||||
@ -65,7 +65,7 @@ enum Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum ExecuteError {
|
pub enum ExecuteError {
|
||||||
BadRequest(Error),
|
BadRequest(Error),
|
||||||
Flush(io::Error),
|
Flush(io::Error),
|
||||||
Read(GuestMemoryError),
|
Read(GuestMemoryError),
|
||||||
@ -75,7 +75,7 @@ enum ExecuteError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ExecuteError {
|
impl ExecuteError {
|
||||||
fn status(&self) -> u32 {
|
pub fn status(&self) -> u32 {
|
||||||
match *self {
|
match *self {
|
||||||
ExecuteError::BadRequest(_) => VIRTIO_BLK_S_IOERR,
|
ExecuteError::BadRequest(_) => VIRTIO_BLK_S_IOERR,
|
||||||
ExecuteError::Flush(_) => VIRTIO_BLK_S_IOERR,
|
ExecuteError::Flush(_) => VIRTIO_BLK_S_IOERR,
|
||||||
@ -131,7 +131,7 @@ impl Clone for RawFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||||
enum RequestType {
|
pub enum RequestType {
|
||||||
In,
|
In,
|
||||||
Out,
|
Out,
|
||||||
Flush,
|
Flush,
|
||||||
@ -139,7 +139,7 @@ enum RequestType {
|
|||||||
Unsupported(u32),
|
Unsupported(u32),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn request_type(
|
pub fn request_type(
|
||||||
mem: &GuestMemoryMmap,
|
mem: &GuestMemoryMmap,
|
||||||
desc_addr: GuestAddress,
|
desc_addr: GuestAddress,
|
||||||
) -> result::Result<RequestType, Error> {
|
) -> result::Result<RequestType, Error> {
|
||||||
@ -179,7 +179,7 @@ fn build_device_id(disk_path: &PathBuf) -> result::Result<String, Error> {
|
|||||||
Ok(device_id)
|
Ok(device_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_disk_image_id(disk_path: &PathBuf) -> Vec<u8> {
|
pub fn build_disk_image_id(disk_path: &PathBuf) -> Vec<u8> {
|
||||||
let mut default_disk_image_id = vec![0; VIRTIO_BLK_ID_BYTES as usize];
|
let mut default_disk_image_id = vec![0; VIRTIO_BLK_ID_BYTES as usize];
|
||||||
match build_device_id(disk_path) {
|
match build_device_id(disk_path) {
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
@ -196,16 +196,16 @@ fn build_disk_image_id(disk_path: &PathBuf) -> Vec<u8> {
|
|||||||
default_disk_image_id
|
default_disk_image_id
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Request {
|
pub struct Request {
|
||||||
request_type: RequestType,
|
request_type: RequestType,
|
||||||
sector: u64,
|
sector: u64,
|
||||||
data_addr: GuestAddress,
|
data_addr: GuestAddress,
|
||||||
data_len: u32,
|
data_len: u32,
|
||||||
status_addr: GuestAddress,
|
pub status_addr: GuestAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Request {
|
impl Request {
|
||||||
fn parse(
|
pub fn parse(
|
||||||
avail_desc: &DescriptorChain,
|
avail_desc: &DescriptorChain,
|
||||||
mem: &GuestMemoryMmap,
|
mem: &GuestMemoryMmap,
|
||||||
) -> result::Result<Request, Error> {
|
) -> result::Result<Request, Error> {
|
||||||
@ -269,7 +269,7 @@ impl Request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::ptr_arg)]
|
#[allow(clippy::ptr_arg)]
|
||||||
fn execute<T: Seek + Read + Write>(
|
pub fn execute<T: Seek + Read + Write>(
|
||||||
&self,
|
&self,
|
||||||
disk: &mut T,
|
disk: &mut T,
|
||||||
disk_nsectors: u64,
|
disk_nsectors: u64,
|
||||||
|
@ -21,7 +21,7 @@ extern crate vm_memory;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
mod block;
|
pub mod block;
|
||||||
mod console;
|
mod console;
|
||||||
mod device;
|
mod device;
|
||||||
mod iommu;
|
mod iommu;
|
||||||
|
Loading…
Reference in New Issue
Block a user