mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 12:34:31 +00:00
vhost: convert to ThisError and sort
BUG=b:197143586 TEST=cargo check Change-Id: Ib3ecfa6e6c9fc88edcf592d511cacfd97b2dd195 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3105429 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
This commit is contained in:
parent
3878e5c6ba
commit
06875127b2
3 changed files with 26 additions and 28 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -1243,6 +1243,8 @@ dependencies = [
|
|||
"base",
|
||||
"libc",
|
||||
"net_util",
|
||||
"remain",
|
||||
"thiserror",
|
||||
"virtio_sys",
|
||||
"vm_memory",
|
||||
]
|
||||
|
|
|
@ -9,5 +9,7 @@ assertions = { path = "../assertions" }
|
|||
libc = "*"
|
||||
net_util = { path = "../net_util" }
|
||||
base = { path = "../base" }
|
||||
remain = "*"
|
||||
thiserror = "*"
|
||||
virtio_sys = { path = "../virtio_sys" }
|
||||
vm_memory = { path = "../vm_memory" }
|
||||
|
|
|
@ -10,50 +10,44 @@ pub use crate::net::NetT;
|
|||
pub use crate::vsock::Vsock;
|
||||
|
||||
use std::alloc::Layout;
|
||||
use std::fmt::{self, Display};
|
||||
use std::io::Error as IoError;
|
||||
use std::ptr::null;
|
||||
|
||||
use assertions::const_assert;
|
||||
use base::{ioctl, ioctl_with_mut_ref, ioctl_with_ptr, ioctl_with_ref};
|
||||
use base::{AsRawDescriptor, Event, LayoutAllocation};
|
||||
use remain::sorted;
|
||||
use thiserror::Error;
|
||||
use vm_memory::{GuestAddress, GuestMemory, GuestMemoryError};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[sorted]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
/// Error opening vhost device.
|
||||
VhostOpen(IoError),
|
||||
/// Error while running ioctl.
|
||||
IoctlError(IoError),
|
||||
/// Invalid queue.
|
||||
InvalidQueue,
|
||||
/// Invalid descriptor table address.
|
||||
DescriptorTableAddress(GuestMemoryError),
|
||||
/// Invalid used address.
|
||||
UsedAddress(GuestMemoryError),
|
||||
/// Invalid available address.
|
||||
#[error("invalid available address: {0}")]
|
||||
AvailAddress(GuestMemoryError),
|
||||
/// Invalid descriptor table address.
|
||||
#[error("invalid descriptor table address: {0}")]
|
||||
DescriptorTableAddress(GuestMemoryError),
|
||||
/// Invalid queue.
|
||||
#[error("invalid queue")]
|
||||
InvalidQueue,
|
||||
/// Error while running ioctl.
|
||||
#[error("failed to run ioctl: {0}")]
|
||||
IoctlError(IoError),
|
||||
/// Invalid log address.
|
||||
#[error("invalid log address: {0}")]
|
||||
LogAddress(GuestMemoryError),
|
||||
/// Invalid used address.
|
||||
#[error("invalid used address: {0}")]
|
||||
UsedAddress(GuestMemoryError),
|
||||
/// Error opening vhost device.
|
||||
#[error("failed to open vhost device: {0}")]
|
||||
VhostOpen(IoError),
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
use self::Error::*;
|
||||
|
||||
match self {
|
||||
VhostOpen(e) => write!(f, "failed to open vhost device: {}", e),
|
||||
IoctlError(e) => write!(f, "failed to run ioctl: {}", e),
|
||||
InvalidQueue => write!(f, "invalid queue"),
|
||||
DescriptorTableAddress(e) => write!(f, "invalid descriptor table address: {}", e),
|
||||
UsedAddress(e) => write!(f, "invalid used address: {}", e),
|
||||
AvailAddress(e) => write!(f, "invalid available address: {}", e),
|
||||
LogAddress(e) => write!(f, "invalid log address: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn ioctl_result<T>() -> Result<T> {
|
||||
Err(Error::IoctlError(IoError::last_os_error()))
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue