virtio-devices: vhost-user: Derive thiserror::Error

Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
Bo Chen 2022-08-10 14:34:44 -07:00 committed by Rob Bradford
parent f39b08f21f
commit 4a2539cb92

View File

@ -12,6 +12,7 @@ use std::io;
use std::ops::Deref; use std::ops::Deref;
use std::os::unix::io::AsRawFd; use std::os::unix::io::AsRawFd;
use std::sync::{atomic::AtomicBool, Arc, Barrier, Mutex}; use std::sync::{atomic::AtomicBool, Arc, Barrier, Mutex};
use thiserror::Error;
use versionize::Versionize; use versionize::Versionize;
use vhost::vhost_user::message::{ use vhost::vhost_user::message::{
VhostUserInflight, VhostUserProtocolFeatures, VhostUserVirtioFeatures, VhostUserInflight, VhostUserProtocolFeatures, VhostUserVirtioFeatures,
@ -38,109 +39,109 @@ pub use self::fs::*;
pub use self::net::Net; pub use self::net::Net;
pub use self::vu_common_ctrl::VhostUserConfig; pub use self::vu_common_ctrl::VhostUserConfig;
#[derive(Debug)] #[derive(Error, Debug)]
pub enum Error { pub enum Error {
/// Failed accepting connection. #[error("Failed accepting connection: {0}")]
AcceptConnection(io::Error), AcceptConnection(io::Error),
/// Invalid available address. #[error("Invalid available address.")]
AvailAddress, AvailAddress,
/// Queue number is not correct #[error("Queue number is not correct.")]
BadQueueNum, BadQueueNum,
/// Failed binding vhost-user socket. #[error("Failed binding vhost-user socket: {0}")]
BindSocket(io::Error), BindSocket(io::Error),
/// Creating kill eventfd failed. #[error("Creating kill eventfd failed: {0}")]
CreateKillEventFd(io::Error), CreateKillEventFd(io::Error),
/// Cloning kill eventfd failed. #[error("Cloning kill eventfd failed: {0}")]
CloneKillEventFd(io::Error), CloneKillEventFd(io::Error),
/// Invalid descriptor table address. #[error("Invalid descriptor table address.")]
DescriptorTableAddress, DescriptorTableAddress,
/// Signal used queue failed. #[error("Signal used queue failed: {0}")]
FailedSignalingUsedQueue(io::Error), FailedSignalingUsedQueue(io::Error),
/// Failed to read vhost eventfd. #[error("Failed to read vhost eventfd: {0}")]
MemoryRegions(MmapError), MemoryRegions(MmapError),
/// Failed removing socket path #[error("Failed removing socket path: {0}")]
RemoveSocketPath(io::Error), RemoveSocketPath(io::Error),
/// Failed to create master. #[error("Failed to create master: {0}")]
VhostUserCreateMaster(VhostError), VhostUserCreateMaster(VhostError),
/// Failed to open vhost device. #[error("Failed to open vhost device: {0}")]
VhostUserOpen(VhostError), VhostUserOpen(VhostError),
/// Connection to socket failed. #[error("Connection to socket failed.")]
VhostUserConnect, VhostUserConnect,
/// Get features failed. #[error("Get features failed: {0}")]
VhostUserGetFeatures(VhostError), VhostUserGetFeatures(VhostError),
/// Get queue max number failed. #[error("Get queue max number failed: {0}")]
VhostUserGetQueueMaxNum(VhostError), VhostUserGetQueueMaxNum(VhostError),
/// Get protocol features failed. #[error("Get protocol features failed: {0}")]
VhostUserGetProtocolFeatures(VhostError), VhostUserGetProtocolFeatures(VhostError),
/// Get vring base failed. #[error("Get vring base failed: {0}")]
VhostUserGetVringBase(VhostError), VhostUserGetVringBase(VhostError),
/// Vhost-user Backend not support vhost-user protocol. #[error("Vhost-user Backend not support vhost-user protocol.")]
VhostUserProtocolNotSupport, VhostUserProtocolNotSupport,
/// Set owner failed. #[error("Set owner failed: {0}")]
VhostUserSetOwner(VhostError), VhostUserSetOwner(VhostError),
/// Reset owner failed. #[error("Reset owner failed: {0}")]
VhostUserResetOwner(VhostError), VhostUserResetOwner(VhostError),
/// Set features failed. #[error("Set features failed: {0}")]
VhostUserSetFeatures(VhostError), VhostUserSetFeatures(VhostError),
/// Set protocol features failed. #[error("Set protocol features failed: {0}")]
VhostUserSetProtocolFeatures(VhostError), VhostUserSetProtocolFeatures(VhostError),
/// Set mem table failed. #[error("Set mem table failed: {0}")]
VhostUserSetMemTable(VhostError), VhostUserSetMemTable(VhostError),
/// Set vring num failed. #[error("Set vring num failed: {0}")]
VhostUserSetVringNum(VhostError), VhostUserSetVringNum(VhostError),
/// Set vring addr failed. #[error("Set vring addr failed: {0}")]
VhostUserSetVringAddr(VhostError), VhostUserSetVringAddr(VhostError),
/// Set vring base failed. #[error("Set vring base failed: {0}")]
VhostUserSetVringBase(VhostError), VhostUserSetVringBase(VhostError),
/// Set vring call failed. #[error("Set vring call failed: {0}")]
VhostUserSetVringCall(VhostError), VhostUserSetVringCall(VhostError),
/// Set vring kick failed. #[error("Set vring kick failed: {0}")]
VhostUserSetVringKick(VhostError), VhostUserSetVringKick(VhostError),
/// Set vring enable failed. #[error("Set vring enable failed: {0}")]
VhostUserSetVringEnable(VhostError), VhostUserSetVringEnable(VhostError),
/// Failed to create vhost eventfd. #[error("Failed to create vhost eventfd: {0}")]
VhostIrqCreate(io::Error), VhostIrqCreate(io::Error),
/// Failed to read vhost eventfd. #[error("Failed to read vhost eventfd: {0}")]
VhostIrqRead(io::Error), VhostIrqRead(io::Error),
/// Failed to read vhost eventfd. #[error("Failed to read vhost eventfd: {0}")]
VhostUserMemoryRegion(MmapError), VhostUserMemoryRegion(MmapError),
/// Failed to create the master request handler from slave. #[error("Failed to create the master request handler from slave: {0}")]
MasterReqHandlerCreation(vhost::vhost_user::Error), MasterReqHandlerCreation(vhost::vhost_user::Error),
/// Set slave request fd failed. #[error("Set slave request fd failed: {0}")]
VhostUserSetSlaveRequestFd(vhost::Error), VhostUserSetSlaveRequestFd(vhost::Error),
/// Add memory region failed. #[error("Add memory region failed: {0}")]
VhostUserAddMemReg(VhostError), VhostUserAddMemReg(VhostError),
/// Failed getting the configuration. #[error("Failed getting the configuration: {0}")]
VhostUserGetConfig(VhostError), VhostUserGetConfig(VhostError),
/// Failed setting the configuration. #[error("Failed setting the configuration: {0}")]
VhostUserSetConfig(VhostError), VhostUserSetConfig(VhostError),
/// Failed getting inflight shm log. #[error("Failed getting inflight shm log: {0}")]
VhostUserGetInflight(VhostError), VhostUserGetInflight(VhostError),
/// Failed setting inflight shm log. #[error("Failed setting inflight shm log: {0}")]
VhostUserSetInflight(VhostError), VhostUserSetInflight(VhostError),
/// Failed setting the log base. #[error("Failed setting the log base: {0}")]
VhostUserSetLogBase(VhostError), VhostUserSetLogBase(VhostError),
/// Invalid used address. #[error("Invalid used address.")]
UsedAddress, UsedAddress,
/// Invalid features provided from vhost-user backend #[error("Invalid features provided from vhost-user backe.")]
InvalidFeatures, InvalidFeatures,
/// Missing file descriptor for the region. #[error("Missing file descriptor for the region.")]
MissingRegionFd, MissingRegionFd,
/// Missing IrqFd #[error("Missing IrqFd.")]
MissingIrqFd, MissingIrqFd,
/// Failed getting the available index. #[error("Failed getting the available index: {0}")]
GetAvailableIndex(QueueError), GetAvailableIndex(QueueError),
/// Migration is not supported by this vhost-user device. #[error("Migration is not supported by this vhost-user device.")]
MigrationNotSupported, MigrationNotSupported,
/// Failed creating memfd. #[error("Failed creating memfd: {0}")]
MemfdCreate(io::Error), MemfdCreate(io::Error),
/// Failed truncating the file size to the expected size. #[error("Failed truncating the file size to the expected size: {0}")]
SetFileSize(io::Error), SetFileSize(io::Error),
/// Failed to set the seals on the file. #[error("Failed to set the seals on the file: {0}")]
SetSeals(io::Error), SetSeals(io::Error),
/// Failed creating new mmap region #[error("Failed creating new mmap region: {0}")]
NewMmapRegion(MmapRegionError), NewMmapRegion(MmapRegionError),
/// Could not find the shm log region #[error("Could not find the shm log region.")]
MissingShmLogRegion, MissingShmLogRegion,
} }
type Result<T> = std::result::Result<T, Error>; type Result<T> = std::result::Result<T, Error>;