summary refs log tree commit diff
path: root/src/plugin
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@chromium.org>2019-02-12 17:51:26 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-02-20 08:20:02 -0800
commitb4bd00fdad094b16c785b8ead9f92d68264f5fb4 (patch)
tree540ad033c789aa08a1ffed17e9c161df331600d2 /src/plugin
parent0373b9f154b5ec1894138b7c10ad495fcce7b64f (diff)
downloadcrosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar
crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.gz
crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.bz2
crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.lz
crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.xz
crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.tar.zst
crosvm-b4bd00fdad094b16c785b8ead9f92d68264f5fb4.zip
error: Print errors using Display impl
I have been running into Debug-printed error messages too often and
needing to look up in the source code each level of nested errors to
find out from the comment on the error variant what the short name of
the variant means in human terms. Worse, many errors (like the one shown
below) already had error strings written but were being printed from the
calling code in the less helpful Debug representation anyway.

Before:
    [ERROR:src/main.rs:705] The architecture failed to build the vm: NoVarEmpty

After:
    [ERROR:src/main.rs:705] The architecture failed to build the vm: /var/empty doesn't exist, can't jail devices.

TEST=cargo check --all-features
TEST=FEATURES=test emerge-amd64-generic crosvm

Change-Id: I77122c7d6861b2d610de2fff718896918ab21e10
Reviewed-on: https://chromium-review.googlesource.com/1469225
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'src/plugin')
-rw-r--r--src/plugin/mod.rs129
-rw-r--r--src/plugin/process.rs6
-rw-r--r--src/plugin/vcpu.rs4
3 files changed, 61 insertions, 78 deletions
diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs
index d886f0d..9ad0fd7 100644
--- a/src/plugin/mod.rs
+++ b/src/plugin/mod.rs
@@ -105,66 +105,49 @@ pub enum Error {
 
 impl fmt::Display for Error {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        match *self {
-            Error::CloneEventFd(ref e) => write!(f, "failed to clone eventfd: {:?}", e),
-            Error::CloneVcpuSocket(ref e) => write!(f, "failed to clone vcpu socket: {:?}", e),
-            Error::CreateEventFd(ref e) => write!(f, "failed to create eventfd: {:?}", e),
-            Error::CreateIrqChip(ref e) => write!(f, "failed to create kvm irqchip: {:?}", e),
-            Error::CreateJail(ref e) => write!(f, "failed to create jail: {}", e),
-            Error::CreateKvm(ref e) => write!(f, "error creating Kvm: {:?}", e),
-            Error::CreateMainSocket(ref e) => {
-                write!(f, "error creating main request socket: {:?}", e)
-            }
-            Error::CreatePIT(ref e) => write!(f, "failed to create kvm PIT: {:?}", e),
-            Error::CreatePollContext(ref e) => write!(f, "failed to create poll context: {:?}", e),
-            Error::CreateSignalFd(ref e) => write!(f, "failed to create signalfd: {:?}", e),
-            Error::CreateSocketPair(ref e) => write!(f, "failed to create socket pair: {}", e),
-            Error::CreateTapFd(ref e) => {
-                write!(f, "failed to create tap device from raw fd: {:?}", e)
-            }
-            Error::CreateVcpu(ref e) => write!(f, "error creating vcpu: {:?}", e),
-            Error::CreateVcpuSocket(ref e) => {
-                write!(f, "error creating vcpu request socket: {:?}", e)
-            }
-            Error::CreateVm(ref e) => write!(f, "error creating vm: {:?}", e),
-            Error::DecodeRequest(ref e) => write!(f, "failed to decode plugin request: {}", e),
-            Error::EncodeResponse(ref e) => write!(f, "failed to encode plugin response: {}", e),
-            Error::Mount(ref e) => write!(f, "failed to mount: {}", e),
-            Error::MountDev(ref e) => write!(f, "failed to mount: {}", e),
-            Error::MountLib(ref e) => write!(f, "failed to mount: {}", e),
-            Error::MountLib64(ref e) => write!(f, "failed to mount: {}", e),
-            Error::MountPlugin(ref e) => write!(f, "failed to mount: {}", e),
-            Error::MountPluginLib(ref e) => write!(f, "failed to mount: {}", e),
-            Error::MountRoot(ref e) => write!(f, "failed to mount: {}", e),
-            Error::NoRootDir => {
-                write!(f, "no root directory for jailed process to pivot root into")
-            }
-            Error::ParsePivotRoot(ref e) => write!(f, "failed to set jail pivot root: {}", e),
-            Error::ParseSeccomp(ref e) => write!(f, "failed to parse jail seccomp filter: {}", e),
-            Error::PluginFailed(ref e) => write!(f, "plugin exited with error: {}", e),
-            Error::PluginKill(ref e) => write!(f, "error sending kill signal to plugin: {:?}", e),
-            Error::PluginKilled(ref e) => write!(f, "plugin exited with signal {}", e),
-            Error::PluginRunJail(ref e) => write!(f, "failed to run jail: {}", e),
-            Error::PluginSocketHup => write!(f, "plugin request socket has been hung up"),
-            Error::PluginSocketPoll(ref e) => {
-                write!(f, "failed to poll plugin request sockets: {:?}", e)
-            }
-            Error::PluginSocketRecv(ref e) => {
-                write!(f, "failed to recv from plugin request socket: {:?}", e)
-            }
-            Error::PluginSocketSend(ref e) => {
-                write!(f, "failed to send to plugin request socket: {:?}", e)
-            }
-            Error::PluginSpawn(ref e) => write!(f, "failed to spawn plugin: {}", e),
-            Error::PluginTimeout => write!(f, "plugin did not exit within timeout"),
-            Error::PluginWait(ref e) => write!(f, "error waiting for plugin to exit: {:?}", e),
-            Error::Poll(ref e) => write!(f, "failed to poll all FDs: {:?}", e),
-            Error::PollContextAdd(ref e) => write!(f, "failed to add fd to poll context: {:?}", e),
-            Error::RootNotAbsolute => write!(f, "path to the root directory must be absolute"),
-            Error::RootNotDir => write!(f, "specified root directory is not a directory"),
-            Error::SetGidMap(ref e) => write!(f, "failed to set gidmap for jail: {}", e),
-            Error::SetUidMap(ref e) => write!(f, "failed to set uidmap for jail: {}", e),
-            Error::SigChild {
+        use self::Error::*;
+
+        match self {
+            CloneEventFd(e) => write!(f, "failed to clone eventfd: {}", e),
+            CloneVcpuSocket(e) => write!(f, "failed to clone vcpu socket: {}", e),
+            CreateEventFd(e) => write!(f, "failed to create eventfd: {}", 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),
+            CreatePollContext(e) => write!(f, "failed to create poll context: {}", e),
+            CreateSignalFd(e) => write!(f, "failed to create signalfd: {}", e),
+            CreateSocketPair(e) => write!(f, "failed to create socket pair: {}", 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),
+            DecodeRequest(e) => write!(f, "failed to decode plugin request: {}", e),
+            EncodeResponse(e) => write!(f, "failed to encode plugin response: {}", e),
+            Mount(e) | MountDev(e) | MountLib(e) | MountLib64(e) | MountPlugin(e)
+            | MountPluginLib(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),
+            PollContextAdd(e) => write!(f, "failed to add fd to poll context: {}", 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,
@@ -174,14 +157,14 @@ impl fmt::Display for Error {
                 "process {} died with signal {}, status {}, and code {}",
                 pid, signo, status, code
             ),
-            Error::SignalFd(ref e) => write!(f, "failed to read signal fd: {:?}", e),
-            Error::SpawnVcpu(ref e) => write!(f, "error spawning vcpu thread: {}", e),
-            Error::TapOpen(ref e) => write!(f, "error opening tap device: {:?}", e),
-            Error::TapSetIp(ref e) => write!(f, "error setting tap ip: {:?}", e),
-            Error::TapSetNetmask(ref e) => write!(f, "error setting tap netmask: {:?}", e),
-            Error::TapSetMacAddress(ref e) => write!(f, "error setting tap mac address: {:?}", e),
-            Error::TapEnable(ref e) => write!(f, "error enabling tap device: {:?}", e),
-            Error::ValidateTapFd(ref e) => write!(f, "failed to validate raw tap fd: {:?}", e),
+            SignalFd(e) => write!(f, "failed to read signal fd: {}", e),
+            SpawnVcpu(e) => write!(f, "error spawning vcpu thread: {}", e),
+            TapOpen(e) => write!(f, "error opening tap device: {}", e),
+            TapSetIp(e) => write!(f, "error setting tap ip: {}", e),
+            TapSetNetmask(e) => write!(f, "error setting tap netmask: {}", e),
+            TapSetMacAddress(e) => write!(f, "error setting tap mac address: {}", e),
+            TapEnable(e) => write!(f, "error enabling tap device: {}", e),
+            ValidateTapFd(e) => write!(f, "failed to validate raw tap fd: {}", e),
         }
     }
 }
@@ -368,7 +351,7 @@ pub fn run_vcpus(
                     let res = vcpu_plugin.init(&vcpu);
                     vcpu_thread_barrier.wait();
                     if let Err(e) = res {
-                        error!("failed to initialize vcpu {}: {:?}", cpu_id, e);
+                        error!("failed to initialize vcpu {}: {}", cpu_id, e);
                     } else {
                         loop {
                             let run_res = vcpu.run();
@@ -382,7 +365,7 @@ pub fn run_vcpus(
                                         }
                                         vcpu_plugin.io_read(port as u64, &mut data[..size], &vcpu);
                                         if let Err(e) = vcpu.set_data(&data[..size]) {
-                                            error!("failed to set return data for IoIn: {:?}", e);
+                                            error!("failed to set return data for IoIn: {}", e);
                                         }
                                     }
                                     VcpuExit::IoOut {
@@ -428,7 +411,7 @@ pub fn run_vcpus(
                                 Err(e) => match e.errno() {
                                     EAGAIN | EINTR => {}
                                     _ => {
-                                        error!("vcpu hit unknown error: {:?}", e);
+                                        error!("vcpu hit unknown error: {}", e);
                                         break;
                                     }
                                 },
@@ -442,7 +425,7 @@ pub fn run_vcpus(
                             clear_signal(SIGRTMIN() + 0).expect("failed to clear pending signal");
 
                             if let Err(e) = vcpu_plugin.pre_run(&vcpu) {
-                                error!("failed to process pause on vcpu {}: {:?}", cpu_id, e);
+                                error!("failed to process pause on vcpu {}: {}", cpu_id, e);
                                 break;
                             }
                         }
@@ -723,7 +706,7 @@ pub fn run_config(cfg: Config) -> Result<()> {
                     error!("failed to join vcpu thread: {:?}", e);
                 }
             }
-            Err(e) => error!("failed to kill vcpu thread: {:?}", e),
+            Err(e) => error!("failed to kill vcpu thread: {}", e),
         }
     }
 
diff --git a/src/plugin/process.rs b/src/plugin/process.rs
index 2f3560d..2df9284 100644
--- a/src/plugin/process.rs
+++ b/src/plugin/process.rs
@@ -412,7 +412,7 @@ impl Process {
             if cpu_mask & (1 << cpu_id) != 0 {
                 per_cpu_state.lock().request_pause(user_data);
                 if let Err(e) = handle.kill(SIGRTMIN() + 0) {
-                    error!("failed to interrupt vcpu {}: {:?}", cpu_id, e);
+                    error!("failed to interrupt vcpu {}: {}", cpu_id, e);
                 }
             }
         }
@@ -425,7 +425,7 @@ impl Process {
         // Log any NetError so that the cause can be found later, but extract and return the
         // underlying errno for the client as well.
         fn map_net_error(s: &str, e: NetError) -> SysError {
-            error!("failed to get {}: {:?}", s, e);
+            error!("failed to get {}: {}", s, e);
             e.sys_error()
         }
 
@@ -683,7 +683,7 @@ impl Drop for Process {
     fn drop(&mut self) {
         // Ignore the result because there is nothing we can do about it.
         if let Err(e) = self.signal_kill() {
-            error!("failed to signal kill event for plugin: {:?}", e);
+            error!("failed to signal kill event for plugin: {}", e);
         }
     }
 }
diff --git a/src/plugin/vcpu.rs b/src/plugin/vcpu.rs
index 70cf914..c2350a6 100644
--- a/src/plugin/vcpu.rs
+++ b/src/plugin/vcpu.rs
@@ -329,7 +329,7 @@ impl PluginVcpu {
         let vcpu_state_lock = match self.shared_vcpu_state.read() {
             Ok(l) => l,
             Err(e) => {
-                error!("error read locking shared cpu state: {:?}", e);
+                error!("error read locking shared cpu state: {}", e);
                 return false;
             }
         };
@@ -360,7 +360,7 @@ impl PluginVcpu {
                 match self.handle_until_resume(vcpu) {
                     Ok(resume_data) => data.copy_from_slice(&resume_data),
                     Err(e) if e.errno() == EPIPE => {}
-                    Err(e) => error!("failed to process vcpu requests: {:?}", e),
+                    Err(e) => error!("failed to process vcpu requests: {}", e),
                 }
                 true
             }