vhost_user_block: Make Error behave like net and fs versions

Make the Error struct behave more like the net and fs equivalents.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-02-06 11:31:05 +00:00 committed by Sebastien Boeuf
parent f1e19d6c96
commit 4f4c3d3ebe

View File

@ -32,6 +32,7 @@ use vhost_user_backend::{VhostUserBackend, VhostUserDaemon, Vring, VringWorker};
use virtio_bindings::bindings::virtio_blk::*;
use vm_memory::{Bytes, GuestMemoryError, GuestMemoryMmap};
use vm_virtio::block::{build_disk_image_id, Request};
use std::{fmt, error, convert,io};
const QUEUE_SIZE: usize = 1024;
const SECTOR_SHIFT: u8 = 9;
@ -64,6 +65,20 @@ pub enum Error {
ParseBlkNumQueuesParam(std::num::ParseIntError),
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "vhost_user_block_error: {:?}", self)
}
}
impl error::Error for Error {}
impl convert::From<Error> for io::Error {
fn from(e: Error) -> Self {
io::Error::new(io::ErrorKind::Other, e)
}
}
pub struct VhostUserBlkBackend {
mem: Option<GuestMemoryMmap>,
vring_worker: Option<Arc<VringWorker>>,