From 4f4c3d3ebe77ef0e305219dad669ca511320a747 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Thu, 6 Feb 2020 11:31:05 +0000 Subject: [PATCH] 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 --- vhost_user_block/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/vhost_user_block/src/lib.rs b/vhost_user_block/src/lib.rs index e8b792fb8..ce7827652 100644 --- a/vhost_user_block/src/lib.rs +++ b/vhost_user_block/src/lib.rs @@ -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 for io::Error { + fn from(e: Error) -> Self { + io::Error::new(io::ErrorKind::Other, e) + } +} + pub struct VhostUserBlkBackend { mem: Option, vring_worker: Option>,