mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: vmm: streamline #[source] and Error
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de> On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
committed by
Rob Bradford
parent
5db92f79bf
commit
fff62d9302
+3
-3
@@ -83,14 +83,14 @@ enum Error {
|
|||||||
EventMonitorThread(#[source] vmm::Error),
|
EventMonitorThread(#[source] vmm::Error),
|
||||||
#[cfg(feature = "guest_debug")]
|
#[cfg(feature = "guest_debug")]
|
||||||
#[error("Error parsing --gdb: {0}")]
|
#[error("Error parsing --gdb: {0}")]
|
||||||
ParsingGdb(option_parser::OptionParserError),
|
ParsingGdb(#[source] option_parser::OptionParserError),
|
||||||
#[cfg(feature = "guest_debug")]
|
#[cfg(feature = "guest_debug")]
|
||||||
#[error("Error parsing --gdb: path required")]
|
#[error("Error parsing --gdb: path required")]
|
||||||
BareGdb,
|
BareGdb,
|
||||||
#[error("Error creating log file: {0}")]
|
#[error("Error creating log file: {0}")]
|
||||||
LogFileCreation(std::io::Error),
|
LogFileCreation(#[source] std::io::Error),
|
||||||
#[error("Error setting up logger: {0}")]
|
#[error("Error setting up logger: {0}")]
|
||||||
LoggerSetup(log::SetLoggerError),
|
LoggerSetup(#[source] log::SetLoggerError),
|
||||||
#[error("Failed to gracefully shutdown http api: {0}")]
|
#[error("Failed to gracefully shutdown http api: {0}")]
|
||||||
HttpApiShutdown(#[source] vmm::Error),
|
HttpApiShutdown(#[source] vmm::Error),
|
||||||
#[error("Failed to create Landlock object: {0}")]
|
#[error("Failed to create Landlock object: {0}")]
|
||||||
|
|||||||
+10
-5
@@ -9,6 +9,7 @@ use std::io::Write;
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use hypervisor::arch::x86::{DescriptorTable, SegmentRegister};
|
use hypervisor::arch::x86::{DescriptorTable, SegmentRegister};
|
||||||
use linux_loader::elf;
|
use linux_loader::elf;
|
||||||
|
use thiserror::Error;
|
||||||
use vm_memory::ByteValued;
|
use vm_memory::ByteValued;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -33,12 +34,16 @@ pub struct DumpState {
|
|||||||
pub file: Option<File>,
|
pub file: Option<File>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum GuestDebuggableError {
|
pub enum GuestDebuggableError {
|
||||||
Coredump(anyhow::Error),
|
#[error("coredump: {0}")]
|
||||||
CoredumpFile(std::io::Error),
|
Coredump(#[source] anyhow::Error),
|
||||||
Pause(vm_migration::MigratableError),
|
#[error("coredump file: {0}")]
|
||||||
Resume(vm_migration::MigratableError),
|
CoredumpFile(#[source] std::io::Error),
|
||||||
|
#[error("Failed to pause: {0}")]
|
||||||
|
Pause(#[source] vm_migration::MigratableError),
|
||||||
|
#[error("Failed to resume: {0}")]
|
||||||
|
Resume(#[source] vm_migration::MigratableError),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait GuestDebuggable: vm_migration::Pausable {
|
pub trait GuestDebuggable: vm_migration::Pausable {
|
||||||
|
|||||||
+29
-14
@@ -29,22 +29,32 @@ use gdbstub_arch::aarch64::AArch64 as GdbArch;
|
|||||||
use gdbstub_arch::x86::reg::X86_64CoreRegs as CoreRegs;
|
use gdbstub_arch::x86::reg::X86_64CoreRegs as CoreRegs;
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use gdbstub_arch::x86::X86_64_SSE as GdbArch;
|
use gdbstub_arch::x86::X86_64_SSE as GdbArch;
|
||||||
|
use thiserror::Error;
|
||||||
use vm_memory::{GuestAddress, GuestMemoryAtomic, GuestMemoryError};
|
use vm_memory::{GuestAddress, GuestMemoryAtomic, GuestMemoryError};
|
||||||
|
|
||||||
use crate::GuestMemoryMmap;
|
use crate::GuestMemoryMmap;
|
||||||
|
|
||||||
type ArchUsize = u64;
|
type ArchUsize = u64;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum DebuggableError {
|
pub enum DebuggableError {
|
||||||
SetDebug(hypervisor::HypervisorCpuError),
|
#[error("Setting debug failed: {0}")]
|
||||||
Pause(vm_migration::MigratableError),
|
SetDebug(#[source] hypervisor::HypervisorCpuError),
|
||||||
Resume(vm_migration::MigratableError),
|
#[error("Pausing failed: {0}")]
|
||||||
ReadRegs(crate::cpu::Error),
|
Pause(#[source] vm_migration::MigratableError),
|
||||||
WriteRegs(crate::cpu::Error),
|
#[error("Resuming failed: {0}")]
|
||||||
ReadMem(GuestMemoryError),
|
Resume(#[source] vm_migration::MigratableError),
|
||||||
WriteMem(GuestMemoryError),
|
#[error("Reading registers failed: {0}")]
|
||||||
TranslateGva(crate::cpu::Error),
|
ReadRegs(#[source] crate::cpu::Error),
|
||||||
|
#[error("Writing registers failed: {0}")]
|
||||||
|
WriteRegs(#[source] crate::cpu::Error),
|
||||||
|
#[error("Reading memory failed: {0}")]
|
||||||
|
ReadMem(#[source] GuestMemoryError),
|
||||||
|
#[error("Writing memory failed: {0}")]
|
||||||
|
WriteMem(#[source] GuestMemoryError),
|
||||||
|
#[error("Translating GVA failed: {0}")]
|
||||||
|
TranslateGva(#[source] crate::cpu::Error),
|
||||||
|
#[error("The lock is poisened")]
|
||||||
PoisonedState,
|
PoisonedState,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,13 +90,18 @@ pub trait Debuggable: vm_migration::Pausable {
|
|||||||
fn active_vcpus(&self) -> usize;
|
fn active_vcpus(&self) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
Vm(crate::vm::Error),
|
#[error("VM failed: {0}")]
|
||||||
|
Vm(#[source] crate::vm::Error),
|
||||||
|
#[error("GDB request failed")]
|
||||||
GdbRequest,
|
GdbRequest,
|
||||||
GdbResponseNotify(std::io::Error),
|
#[error("GDB couldn't be notified: {0}")]
|
||||||
GdbResponse(mpsc::RecvError),
|
GdbResponseNotify(#[source] std::io::Error),
|
||||||
GdbResponseTimeout(mpsc::RecvTimeoutError),
|
#[error("GDB response failed: {0}")]
|
||||||
|
GdbResponse(#[source] mpsc::RecvError),
|
||||||
|
#[error("GDB response timeout: {0}")]
|
||||||
|
GdbResponseTimeout(#[source] mpsc::RecvTimeoutError),
|
||||||
}
|
}
|
||||||
type GdbResult<T> = std::result::Result<T, Error>;
|
type GdbResult<T> = std::result::Result<T, Error>;
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -114,7 +114,7 @@ pub enum Error {
|
|||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
#[error("Cannot load the UEFI binary in memory: {0:?}")]
|
#[error("Cannot load the UEFI binary in memory: {0:?}")]
|
||||||
UefiLoad(arch::aarch64::uefi::Error),
|
UefiLoad(#[source] arch::aarch64::uefi::Error),
|
||||||
|
|
||||||
#[error("Cannot load the initramfs into memory")]
|
#[error("Cannot load the initramfs into memory")]
|
||||||
InitramfsLoad,
|
InitramfsLoad,
|
||||||
@@ -136,7 +136,7 @@ pub enum Error {
|
|||||||
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
#[error("Cannot enable interrupt controller: {0:?}")]
|
#[error("Cannot enable interrupt controller: {0:?}")]
|
||||||
EnableInterruptController(interrupt_controller::Error),
|
EnableInterruptController(#[source] interrupt_controller::Error),
|
||||||
|
|
||||||
#[error("VM state is poisoned")]
|
#[error("VM state is poisoned")]
|
||||||
PoisonedState,
|
PoisonedState,
|
||||||
@@ -277,7 +277,7 @@ pub enum Error {
|
|||||||
|
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
#[error("Error allocating TDVF memory: {0:?}")]
|
#[error("Error allocating TDVF memory: {0:?}")]
|
||||||
AllocatingTdvfMemory(crate::memory_manager::Error),
|
AllocatingTdvfMemory(#[source] crate::memory_manager::Error),
|
||||||
|
|
||||||
#[cfg(feature = "tdx")]
|
#[cfg(feature = "tdx")]
|
||||||
#[error("Error enabling TDX VM: {0}")]
|
#[error("Error enabling TDX VM: {0}")]
|
||||||
@@ -301,7 +301,7 @@ pub enum Error {
|
|||||||
|
|
||||||
#[cfg(feature = "guest_debug")]
|
#[cfg(feature = "guest_debug")]
|
||||||
#[error("Error debugging VM: {0:?}")]
|
#[error("Error debugging VM: {0:?}")]
|
||||||
Debug(DebuggableError),
|
Debug(#[source] DebuggableError),
|
||||||
|
|
||||||
#[error("Error spawning kernel loading thread")]
|
#[error("Error spawning kernel loading thread")]
|
||||||
KernelLoadThreadSpawn(#[source] std::io::Error),
|
KernelLoadThreadSpawn(#[source] std::io::Error),
|
||||||
|
|||||||
Reference in New Issue
Block a user