virtio-devices: Derive thiserror::Error and drop unsed errors

Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
Bo Chen 2022-08-10 15:06:02 -07:00 committed by Rob Bradford
parent 4a2539cb92
commit b67755be17

View File

@ -20,6 +20,7 @@ extern crate log;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::convert::TryInto; use std::convert::TryInto;
use std::io; use std::io;
use thiserror::Error;
#[macro_use] #[macro_use]
mod device; mod device;
@ -77,33 +78,23 @@ const VIRTIO_F_ORDER_PLATFORM: u32 = 36;
const VIRTIO_F_SR_IOV: u32 = 37; const VIRTIO_F_SR_IOV: u32 = 37;
const VIRTIO_F_NOTIFICATION_DATA: u32 = 38; const VIRTIO_F_NOTIFICATION_DATA: u32 = 38;
#[derive(Debug)] #[derive(Error, Debug)]
pub enum ActivateError { pub enum ActivateError {
EpollCtl(std::io::Error), #[error("Failed to activate virtio device.")]
BadActivate, BadActivate,
/// Queue number is not correct #[error("Failed to clone exit event fd: {0}")]
BadQueueNum,
/// Failed to clone Kill event fd
CloneKillEventFd,
/// Failed to clone exit event fd
CloneExitEventFd(std::io::Error), CloneExitEventFd(std::io::Error),
// Failed to spawn thread #[error("Failed to spawn thread: {0}")]
ThreadSpawn(std::io::Error), ThreadSpawn(std::io::Error),
/// Failed to create Vhost-user interrupt eventfd #[error("Failed to setup vhost-user-fs daemon: {0}")]
VhostIrqCreate,
/// Failed to setup vhost-user-fs daemon.
VhostUserFsSetup(vhost_user::Error), VhostUserFsSetup(vhost_user::Error),
/// Failed to setup vhost-user-net daemon. #[error("Failed to setup vhost-user-blk daemon: {0}")]
VhostUserNetSetup(vhost_user::Error),
/// Failed to setup vhost-user-blk daemon.
VhostUserBlkSetup(vhost_user::Error), VhostUserBlkSetup(vhost_user::Error),
/// Failed to reset vhost-user daemon. #[error("Failed to create seccomp filter: {0}")]
VhostUserReset(vhost_user::Error),
/// Cannot create seccomp filter
CreateSeccompFilter(seccompiler::Error), CreateSeccompFilter(seccompiler::Error),
/// Cannot create rate limiter #[error("Failed to create rate limiter: {0}")]
CreateRateLimiter(std::io::Error), CreateRateLimiter(std::io::Error),
/// Failed activating the vDPA device #[error("Failed to activate the vDPA device: {0}")]
ActivateVdpa(vdpa::Error), ActivateVdpa(vdpa::Error),
} }
@ -111,17 +102,23 @@ pub type ActivateResult = std::result::Result<(), ActivateError>;
pub type DeviceEventT = u16; pub type DeviceEventT = u16;
#[derive(Debug)] #[derive(Error, Debug)]
pub enum Error { pub enum Error {
#[error("Failed to single used queue: {0}")]
FailedSignalingUsedQueue(io::Error), FailedSignalingUsedQueue(io::Error),
#[error("I/O Error: {0}")]
IoError(io::Error), IoError(io::Error),
VdpaUpdateMemory(vdpa::Error), #[error("Failed to update memory vhost-user: {0}")]
VhostUserUpdateMemory(vhost_user::Error), VhostUserUpdateMemory(vhost_user::Error),
#[error("Failed to add memory region vhost-user: {0}")]
VhostUserAddMemoryRegion(vhost_user::Error), VhostUserAddMemoryRegion(vhost_user::Error),
#[error("Failed to set shared memory region.")]
SetShmRegionsNotSupported, SetShmRegionsNotSupported,
#[error("Failed to process net queue: {0}")]
NetQueuePair(::net_util::NetQueuePairError), NetQueuePair(::net_util::NetQueuePairError),
ApplySeccompFilter(seccompiler::Error), #[error("Failed to : {0}")]
QueueAddUsed(virtio_queue::Error), QueueAddUsed(virtio_queue::Error),
#[error("Failed to : {0}")]
QueueIterator(virtio_queue::Error), QueueIterator(virtio_queue::Error),
} }