From dfd21cbfc52621db7e769decd2a59b2cb8bad924 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Mon, 26 Oct 2020 16:11:02 +0000 Subject: [PATCH] vmm: Use thiserror/anyhow for vmm::Error This gives a nicer user experience and this error can now be used as the source for other errors based off this. See: #1910 Signed-off-by: Rob Bradford --- Cargo.lock | 1 + vmm/Cargo.toml | 11 ++++++----- vmm/src/lib.rs | 39 ++++++++++++++++++++++++++++----------- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0961b99e0..7247c0ca6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1649,6 +1649,7 @@ dependencies = [ "serde_json", "signal-hook", "tempfile", + "thiserror", "url", "vfio-ioctls", "virtio-devices", diff --git a/vmm/Cargo.toml b/vmm/Cargo.toml index 661fd171e..d39cbe822 100644 --- a/vmm/Cargo.toml +++ b/vmm/Cargo.toml @@ -13,13 +13,13 @@ kvm = ["hypervisor/kvm"] io_uring = ["virtio-devices/io_uring"] [dependencies] -arc-swap = ">=0.4.4" -bitflags = ">=1.2.1" -clap = "2.33.3" acpi_tables = { path = "../acpi_tables", optional = true } anyhow = "1.0" +arc-swap = ">=0.4.4" arch = { path = "../arch" } +bitflags = ">=1.2.1" block_util = { path = "../block_util" } +clap = "2.33.3" devices = { path = "../devices" } epoll = ">=4.0.1" hypervisor = { path = "../hypervisor" } @@ -35,6 +35,9 @@ seccomp = { git = "https://github.com/firecracker-microvm/firecracker", tag = "v serde = {version = ">=1.0.27", features = ["rc"] } serde_derive = ">=1.0.27" serde_json = ">=1.0.9" +signal-hook = "0.1.16" +tempfile = "3.1.0" +thiserror = "1.0" url = "2.1.1" vfio-ioctls = { git = "https://github.com/cloud-hypervisor/vfio-ioctls", branch = "ch" } virtio-devices = { path = "../virtio-devices" } @@ -44,8 +47,6 @@ vm-memory = { version = "0.3.0", features = ["backend-mmap", "backend-atomic"] } vm-migration = { path = "../vm-migration" } vm-virtio = { path = "../vm-virtio" } vmm-sys-util = { version = ">=0.5.0", features = ["with-serde"] } -signal-hook = "0.1.16" -tempfile = "3.1.0" [dependencies.linux-loader] diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index 5916b6a11..0c6e79b97 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -39,6 +39,7 @@ use std::path::PathBuf; use std::sync::mpsc::{Receiver, RecvError, SendError, Sender}; use std::sync::{Arc, Mutex}; use std::{result, thread}; +use thiserror::Error; use vm_migration::{Pausable, Snapshottable, Transportable}; use vmm_sys_util::eventfd::EventFd; @@ -57,55 +58,71 @@ pub mod vm; mod acpi; /// Errors associated with VMM management -#[derive(Debug)] +#[derive(Debug, Error)] #[allow(clippy::large_enum_variant)] pub enum Error { /// API request receive error - ApiRequestRecv(RecvError), + #[error("Error receiving API request: {0}")] + ApiRequestRecv(#[source] RecvError), /// API response send error - ApiResponseSend(SendError), + #[error("Error sending API request: {0}")] + ApiResponseSend(#[source] SendError), /// Cannot bind to the UNIX domain socket path - Bind(io::Error), + #[error("Error binding to UNIX domain socket: {0}")] + Bind(#[source] io::Error), /// Cannot clone EventFd. - EventFdClone(io::Error), + #[error("Error cloning EventFd: {0}")] + EventFdClone(#[source] io::Error), /// Cannot create EventFd. - EventFdCreate(io::Error), + #[error("Error creating EventFd: {0}")] + EventFdCreate(#[source] io::Error), /// Cannot read from EventFd. - EventFdRead(io::Error), + #[error("Error reading from EventFd: {0}")] + EventFdRead(#[source] io::Error), /// Cannot create epoll context. - Epoll(io::Error), + #[error("Error creating epoll context: {0}")] + Epoll(#[source] io::Error), /// Cannot create HTTP thread - HttpThreadSpawn(io::Error), + #[error("Error spawning HTTP thread: {0}")] + HttpThreadSpawn(#[source] io::Error), /// Cannot handle the VM STDIN stream + #[error("Error handling VM stdin: {0:?}")] Stdin(VmError), /// Cannot reboot the VM + #[error("Error rebooting VM: {0:?}")] VmReboot(VmError), /// Cannot shut a VM down + #[error("Error shutting down VM: {0:?}")] VmShutdown(VmError), /// Cannot create VMM thread - VmmThreadSpawn(io::Error), + #[error("Error spawning VMM thread {0:?}")] + VmmThreadSpawn(#[source] io::Error), /// Cannot shut the VMM down + #[error("Error shutting down VMM: {0:?}")] VmmShutdown(VmError), // Error following "exe" link - ExePathReadLink(io::Error), + #[error("Error following \"exe\" link: {0}")] + ExePathReadLink(#[source] io::Error), /// Cannot create seccomp filter + #[error("Error creating seccomp filter: {0}")] CreateSeccompFilter(seccomp::SeccompError), /// Cannot apply seccomp filter + #[error("Error applying seccomp filter: {0}")] ApplySeccompFilter(seccomp::Error), } pub type Result = result::Result;