mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-05 18:20:34 +00:00
plugin: convert to ThisError and sort
BUG=b:197143586 TEST=cargo check Change-Id: If39509d73741df08fdc876431dfc096ee0b8d158 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3105433 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Tomasz Jeznach <tjeznach@chromium.org>
This commit is contained in:
parent
847cbf13c9
commit
8eda3ea975
1 changed files with 59 additions and 74 deletions
|
@ -5,7 +5,6 @@
|
||||||
mod process;
|
mod process;
|
||||||
mod vcpu;
|
mod vcpu;
|
||||||
|
|
||||||
use std::fmt::{self, Display};
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
@ -25,6 +24,7 @@ use libc::{
|
||||||
|
|
||||||
use protobuf::ProtobufError;
|
use protobuf::ProtobufError;
|
||||||
use remain::sorted;
|
use remain::sorted;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
use base::{
|
use base::{
|
||||||
add_fd_flags, block_signal, clear_signal, drop_capabilities, enable_core_scheduling, error,
|
add_fd_flags, block_signal, clear_signal, drop_capabilities, enable_core_scheduling, error,
|
||||||
|
@ -46,144 +46,129 @@ const MAX_VCPU_DATAGRAM_SIZE: usize = 0x40000;
|
||||||
|
|
||||||
/// An error that occurs during the lifetime of a plugin process.
|
/// An error that occurs during the lifetime of a plugin process.
|
||||||
#[sorted]
|
#[sorted]
|
||||||
|
#[derive(Error, Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
|
#[error("failed to clone event: {0}")]
|
||||||
CloneEvent(SysError),
|
CloneEvent(SysError),
|
||||||
|
#[error("failed to clone vcpu pipe: {0}")]
|
||||||
CloneVcpuPipe(io::Error),
|
CloneVcpuPipe(io::Error),
|
||||||
|
#[error("failed to create event: {0}")]
|
||||||
CreateEvent(SysError),
|
CreateEvent(SysError),
|
||||||
|
#[error("failed to create kvm irqchip: {0}")]
|
||||||
CreateIrqChip(SysError),
|
CreateIrqChip(SysError),
|
||||||
|
#[error("failed to create jail: {0}")]
|
||||||
CreateJail(minijail::Error),
|
CreateJail(minijail::Error),
|
||||||
|
#[error("error creating Kvm: {0}")]
|
||||||
CreateKvm(SysError),
|
CreateKvm(SysError),
|
||||||
|
#[error("error creating main request socket: {0}")]
|
||||||
CreateMainSocket(SysError),
|
CreateMainSocket(SysError),
|
||||||
|
#[error("failed to create kvm PIT: {0}")]
|
||||||
CreatePIT(SysError),
|
CreatePIT(SysError),
|
||||||
|
#[error("failed to create signalfd: {0}")]
|
||||||
CreateSignalFd(SignalFdError),
|
CreateSignalFd(SignalFdError),
|
||||||
|
#[error("failed to create socket pair: {0}")]
|
||||||
CreateSocketPair(io::Error),
|
CreateSocketPair(io::Error),
|
||||||
|
#[error("failed to create stderr pipe: {0}")]
|
||||||
CreateStderrPipe(SysError),
|
CreateStderrPipe(SysError),
|
||||||
|
#[error("failed to create tap device from raw fd: {0}")]
|
||||||
CreateTapFd(TapError),
|
CreateTapFd(TapError),
|
||||||
|
#[error("error creating vcpu: {0}")]
|
||||||
CreateVcpu(SysError),
|
CreateVcpu(SysError),
|
||||||
|
#[error("error creating vcpu request socket: {0}")]
|
||||||
CreateVcpuSocket(SysError),
|
CreateVcpuSocket(SysError),
|
||||||
|
#[error("error creating vm: {0}")]
|
||||||
CreateVm(SysError),
|
CreateVm(SysError),
|
||||||
|
#[error("failed to create wait context: {0}")]
|
||||||
CreateWaitContext(SysError),
|
CreateWaitContext(SysError),
|
||||||
|
#[error("failed to decode plugin request: {0}")]
|
||||||
DecodeRequest(ProtobufError),
|
DecodeRequest(ProtobufError),
|
||||||
|
#[error("failed to drop process capabilities: {0}")]
|
||||||
DropCapabilities(SysError),
|
DropCapabilities(SysError),
|
||||||
|
#[error("failed to encode plugin response: {0}")]
|
||||||
EncodeResponse(ProtobufError),
|
EncodeResponse(ProtobufError),
|
||||||
|
#[error("failed to mount: {0}")]
|
||||||
Mount(minijail::Error),
|
Mount(minijail::Error),
|
||||||
|
#[error("failed to mount dev: {0}")]
|
||||||
MountDev(minijail::Error),
|
MountDev(minijail::Error),
|
||||||
|
#[error("failed to mount lib: {0}")]
|
||||||
MountLib(minijail::Error),
|
MountLib(minijail::Error),
|
||||||
|
#[error("failed to mount lib64: {0}")]
|
||||||
MountLib64(minijail::Error),
|
MountLib64(minijail::Error),
|
||||||
|
#[error("failed to mount plugin: {0}")]
|
||||||
MountPlugin(minijail::Error),
|
MountPlugin(minijail::Error),
|
||||||
|
#[error("failed to mount pluginlib: {0}")]
|
||||||
MountPluginLib(minijail::Error),
|
MountPluginLib(minijail::Error),
|
||||||
|
#[error("failed to mount proc: {0}")]
|
||||||
MountProc(minijail::Error),
|
MountProc(minijail::Error),
|
||||||
|
#[error("failed to mount root: {0}")]
|
||||||
MountRoot(minijail::Error),
|
MountRoot(minijail::Error),
|
||||||
|
#[error("no root directory for jailed process to pivot root into")]
|
||||||
NoRootDir,
|
NoRootDir,
|
||||||
|
#[error("failed to set jail pivot root: {0}")]
|
||||||
ParsePivotRoot(minijail::Error),
|
ParsePivotRoot(minijail::Error),
|
||||||
|
#[error("failed to parse jail seccomp filter: {0}")]
|
||||||
ParseSeccomp(minijail::Error),
|
ParseSeccomp(minijail::Error),
|
||||||
|
#[error("plugin exited with error: {0}")]
|
||||||
PluginFailed(i32),
|
PluginFailed(i32),
|
||||||
|
#[error("error sending kill signal to plugin: {0}")]
|
||||||
PluginKill(SysError),
|
PluginKill(SysError),
|
||||||
|
#[error("plugin exited with signal {0}")]
|
||||||
PluginKilled(i32),
|
PluginKilled(i32),
|
||||||
|
#[error("failed to run jail: {0}")]
|
||||||
PluginRunJail(minijail::Error),
|
PluginRunJail(minijail::Error),
|
||||||
|
#[error("plugin request socket has been hung up")]
|
||||||
PluginSocketHup,
|
PluginSocketHup,
|
||||||
|
#[error("failed to poll plugin request sockets: {0}")]
|
||||||
PluginSocketPoll(SysError),
|
PluginSocketPoll(SysError),
|
||||||
|
#[error("failed to recv from plugin request socket: {0}")]
|
||||||
PluginSocketRecv(SysError),
|
PluginSocketRecv(SysError),
|
||||||
|
#[error("failed to send to plugin request socket: {0}")]
|
||||||
PluginSocketSend(SysError),
|
PluginSocketSend(SysError),
|
||||||
|
#[error("failed to spawn plugin: {0}")]
|
||||||
PluginSpawn(io::Error),
|
PluginSpawn(io::Error),
|
||||||
|
#[error("plugin did not exit within timeout")]
|
||||||
PluginTimeout,
|
PluginTimeout,
|
||||||
|
#[error("error waiting for plugin to exit: {0}")]
|
||||||
PluginWait(SysError),
|
PluginWait(SysError),
|
||||||
|
#[error("failed to poll all FDs: {0}")]
|
||||||
Poll(SysError),
|
Poll(SysError),
|
||||||
|
#[error("path to the root directory must be absolute")]
|
||||||
RootNotAbsolute,
|
RootNotAbsolute,
|
||||||
|
#[error("specified root directory is not a directory")]
|
||||||
RootNotDir,
|
RootNotDir,
|
||||||
|
#[error("failed to set gidmap for jail: {0}")]
|
||||||
SetGidMap(minijail::Error),
|
SetGidMap(minijail::Error),
|
||||||
|
#[error("failed to set uidmap for jail: {0}")]
|
||||||
SetUidMap(minijail::Error),
|
SetUidMap(minijail::Error),
|
||||||
|
#[error("process {pid} died with signal {signo}, status {status}, and code {code}")]
|
||||||
SigChild {
|
SigChild {
|
||||||
pid: u32,
|
pid: u32,
|
||||||
signo: u32,
|
signo: u32,
|
||||||
status: i32,
|
status: i32,
|
||||||
code: i32,
|
code: i32,
|
||||||
},
|
},
|
||||||
|
#[error("failed to read signal fd: {0}")]
|
||||||
SignalFd(SignalFdError),
|
SignalFd(SignalFdError),
|
||||||
|
#[error("error spawning vcpu thread: {0}")]
|
||||||
SpawnVcpu(io::Error),
|
SpawnVcpu(io::Error),
|
||||||
|
#[error("error marking stderr nonblocking: {0}")]
|
||||||
StderrNonblock(SysError),
|
StderrNonblock(SysError),
|
||||||
|
#[error("error enabling tap device: {0}")]
|
||||||
TapEnable(TapError),
|
TapEnable(TapError),
|
||||||
|
#[error("error opening tap device: {0}")]
|
||||||
TapOpen(TapError),
|
TapOpen(TapError),
|
||||||
|
#[error("error setting tap ip: {0}")]
|
||||||
TapSetIp(TapError),
|
TapSetIp(TapError),
|
||||||
|
#[error("error setting tap mac address: {0}")]
|
||||||
TapSetMacAddress(TapError),
|
TapSetMacAddress(TapError),
|
||||||
|
#[error("error setting tap netmask: {0}")]
|
||||||
TapSetNetmask(TapError),
|
TapSetNetmask(TapError),
|
||||||
|
#[error("failed to validate raw tap fd: {0}")]
|
||||||
ValidateTapFd(SysError),
|
ValidateTapFd(SysError),
|
||||||
|
#[error("failed to add descriptor to wait context: {0}")]
|
||||||
WaitContextAdd(SysError),
|
WaitContextAdd(SysError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for Error {
|
|
||||||
#[remain::check]
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
use self::Error::*;
|
|
||||||
|
|
||||||
#[sorted]
|
|
||||||
match self {
|
|
||||||
CloneEvent(e) => write!(f, "failed to clone event: {}", e),
|
|
||||||
CloneVcpuPipe(e) => write!(f, "failed to clone vcpu pipe: {}", e),
|
|
||||||
CreateEvent(e) => write!(f, "failed to create event: {}", e),
|
|
||||||
CreateIrqChip(e) => write!(f, "failed to create kvm irqchip: {}", e),
|
|
||||||
CreateJail(e) => write!(f, "failed to create jail: {}", e),
|
|
||||||
CreateKvm(e) => write!(f, "error creating Kvm: {}", e),
|
|
||||||
CreateMainSocket(e) => write!(f, "error creating main request socket: {}", e),
|
|
||||||
CreatePIT(e) => write!(f, "failed to create kvm PIT: {}", e),
|
|
||||||
CreateSignalFd(e) => write!(f, "failed to create signalfd: {}", e),
|
|
||||||
CreateSocketPair(e) => write!(f, "failed to create socket pair: {}", e),
|
|
||||||
CreateStderrPipe(e) => write!(f, "failed to create stderr pipe: {}", e),
|
|
||||||
CreateTapFd(e) => write!(f, "failed to create tap device from raw fd: {}", e),
|
|
||||||
CreateVcpu(e) => write!(f, "error creating vcpu: {}", e),
|
|
||||||
CreateVcpuSocket(e) => write!(f, "error creating vcpu request socket: {}", e),
|
|
||||||
CreateVm(e) => write!(f, "error creating vm: {}", e),
|
|
||||||
CreateWaitContext(e) => write!(f, "failed to create wait context: {}", e),
|
|
||||||
DecodeRequest(e) => write!(f, "failed to decode plugin request: {}", e),
|
|
||||||
DropCapabilities(e) => write!(f, "failed to drop process capabilities: {}", e),
|
|
||||||
EncodeResponse(e) => write!(f, "failed to encode plugin response: {}", e),
|
|
||||||
Mount(e) | MountDev(e) | MountLib(e) | MountLib64(e) | MountPlugin(e)
|
|
||||||
| MountPluginLib(e) | MountProc(e) | MountRoot(e) => {
|
|
||||||
write!(f, "failed to mount: {}", e)
|
|
||||||
}
|
|
||||||
NoRootDir => write!(f, "no root directory for jailed process to pivot root into"),
|
|
||||||
ParsePivotRoot(e) => write!(f, "failed to set jail pivot root: {}", e),
|
|
||||||
ParseSeccomp(e) => write!(f, "failed to parse jail seccomp filter: {}", e),
|
|
||||||
PluginFailed(e) => write!(f, "plugin exited with error: {}", e),
|
|
||||||
PluginKill(e) => write!(f, "error sending kill signal to plugin: {}", e),
|
|
||||||
PluginKilled(e) => write!(f, "plugin exited with signal {}", e),
|
|
||||||
PluginRunJail(e) => write!(f, "failed to run jail: {}", e),
|
|
||||||
PluginSocketHup => write!(f, "plugin request socket has been hung up"),
|
|
||||||
PluginSocketPoll(e) => write!(f, "failed to poll plugin request sockets: {}", e),
|
|
||||||
PluginSocketRecv(e) => write!(f, "failed to recv from plugin request socket: {}", e),
|
|
||||||
PluginSocketSend(e) => write!(f, "failed to send to plugin request socket: {}", e),
|
|
||||||
PluginSpawn(e) => write!(f, "failed to spawn plugin: {}", e),
|
|
||||||
PluginTimeout => write!(f, "plugin did not exit within timeout"),
|
|
||||||
PluginWait(e) => write!(f, "error waiting for plugin to exit: {}", e),
|
|
||||||
Poll(e) => write!(f, "failed to poll all FDs: {}", e),
|
|
||||||
RootNotAbsolute => write!(f, "path to the root directory must be absolute"),
|
|
||||||
RootNotDir => write!(f, "specified root directory is not a directory"),
|
|
||||||
SetGidMap(e) => write!(f, "failed to set gidmap for jail: {}", e),
|
|
||||||
SetUidMap(e) => write!(f, "failed to set uidmap for jail: {}", e),
|
|
||||||
SigChild {
|
|
||||||
pid,
|
|
||||||
signo,
|
|
||||||
status,
|
|
||||||
code,
|
|
||||||
} => write!(
|
|
||||||
f,
|
|
||||||
"process {} died with signal {}, status {}, and code {}",
|
|
||||||
pid, signo, status, code
|
|
||||||
),
|
|
||||||
SignalFd(e) => write!(f, "failed to read signal fd: {}", e),
|
|
||||||
SpawnVcpu(e) => write!(f, "error spawning vcpu thread: {}", e),
|
|
||||||
StderrNonblock(e) => write!(f, "error marking stderr nonblocking: {}", e),
|
|
||||||
TapEnable(e) => write!(f, "error enabling tap device: {}", e),
|
|
||||||
TapOpen(e) => write!(f, "error opening tap device: {}", e),
|
|
||||||
TapSetIp(e) => write!(f, "error setting tap ip: {}", e),
|
|
||||||
TapSetMacAddress(e) => write!(f, "error setting tap mac address: {}", e),
|
|
||||||
TapSetNetmask(e) => write!(f, "error setting tap netmask: {}", e),
|
|
||||||
ValidateTapFd(e) => write!(f, "failed to validate raw tap fd: {}", e),
|
|
||||||
WaitContextAdd(e) => write!(f, "failed to add descriptor to wait context: {}", e),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type Result<T> = result::Result<T, Error>;
|
type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
fn new_seqpacket_pair() -> SysResult<(UnixDatagram, UnixDatagram)> {
|
fn new_seqpacket_pair() -> SysResult<(UnixDatagram, UnixDatagram)> {
|
||||||
|
|
Loading…
Reference in a new issue