summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2019-10-31 13:26:04 -0700
committerCommit Bot <commit-bot@chromium.org>2019-11-06 22:40:45 +0000
commit1de9cb53e1eccfaf138553c45a800f26927663bb (patch)
tree7033ba9819f53bef4b9be392cf94872cf50f9297
parentecfed3ab954dd5ecc7e9db4b24c92339e9c6b4d5 (diff)
downloadcrosvm-1de9cb53e1eccfaf138553c45a800f26927663bb.tar
crosvm-1de9cb53e1eccfaf138553c45a800f26927663bb.tar.gz
crosvm-1de9cb53e1eccfaf138553c45a800f26927663bb.tar.bz2
crosvm-1de9cb53e1eccfaf138553c45a800f26927663bb.tar.lz
crosvm-1de9cb53e1eccfaf138553c45a800f26927663bb.tar.xz
crosvm-1de9cb53e1eccfaf138553c45a800f26927663bb.tar.zst
crosvm-1de9cb53e1eccfaf138553c45a800f26927663bb.zip
devices: proxy: print failed command on error
Add some context for debugging failures so it is possible to determine
which register read is failing.

BUG=None
TEST=./build_test.py

Change-Id: I6084971bc6dbd1f7b5d46e6c5d7ba017bb32edc6
Signed-off-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1893637
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
-rw-r--r--devices/src/proxy.rs24
1 files changed, 12 insertions, 12 deletions
diff --git a/devices/src/proxy.rs b/devices/src/proxy.rs
index 6be2e21..927ea7a 100644
--- a/devices/src/proxy.rs
+++ b/devices/src/proxy.rs
@@ -37,7 +37,7 @@ impl Display for Error {
 
 const SOCKET_TIMEOUT_MS: u64 = 2000;
 
-#[derive(MsgOnSocket)]
+#[derive(Debug, MsgOnSocket)]
 enum Command {
     Read {
         len: u32,
@@ -216,12 +216,12 @@ impl ProxyDevice {
 
     /// Runs the callback given in `new_with_custom_command` in the child device process.
     pub fn run_user_command(&self) {
-        self.sync_send(Command::RunUserCommand);
+        self.sync_send(&Command::RunUserCommand);
     }
 
     /// Send a command that does not expect a response from the child device process.
-    fn send_no_result(&self, cmd: Command) {
-        let res = self.sock.send(&cmd);
+    fn send_no_result(&self, cmd: &Command) {
+        let res = self.sock.send(cmd);
         if let Err(e) = res {
             error!(
                 "failed write to child device process {}: {}",
@@ -231,13 +231,13 @@ impl ProxyDevice {
     }
 
     /// Send a command and read its response from the child device process.
-    fn sync_send(&self, cmd: Command) -> Option<CommandResult> {
+    fn sync_send(&self, cmd: &Command) -> Option<CommandResult> {
         self.send_no_result(cmd);
         match self.sock.recv() {
             Err(e) => {
                 error!(
-                    "failed read from child device process {}: {}",
-                    self.debug_label, e,
+                    "failed to read result of {:?} from child device process {}: {}",
+                    cmd, self.debug_label, e,
                 );
                 None
             }
@@ -257,7 +257,7 @@ impl BusDevice for ProxyDevice {
         buffer[0..data.len()].clone_from_slice(data);
         let reg_idx = reg_idx as u32;
         let offset = offset as u32;
-        self.send_no_result(Command::WriteConfig {
+        self.send_no_result(&Command::WriteConfig {
             reg_idx,
             offset,
             len,
@@ -266,7 +266,7 @@ impl BusDevice for ProxyDevice {
     }
 
     fn config_register_read(&self, reg_idx: usize) -> u32 {
-        let res = self.sync_send(Command::ReadConfig(reg_idx as u32));
+        let res = self.sync_send(&Command::ReadConfig(reg_idx as u32));
         if let Some(CommandResult::ReadConfigResult(val)) = res {
             val
         } else {
@@ -277,7 +277,7 @@ impl BusDevice for ProxyDevice {
     fn read(&mut self, offset: u64, data: &mut [u8]) {
         let len = data.len() as u32;
         if let Some(CommandResult::ReadResult(buffer)) =
-            self.sync_send(Command::Read { len, offset })
+            self.sync_send(&Command::Read { len, offset })
         {
             let len = data.len();
             data.clone_from_slice(&buffer[0..len]);
@@ -288,7 +288,7 @@ impl BusDevice for ProxyDevice {
         let mut buffer = [0u8; 8];
         let len = data.len() as u32;
         buffer[0..data.len()].clone_from_slice(data);
-        self.send_no_result(Command::Write {
+        self.send_no_result(&Command::Write {
             len,
             offset,
             data: buffer,
@@ -298,6 +298,6 @@ impl BusDevice for ProxyDevice {
 
 impl Drop for ProxyDevice {
     fn drop(&mut self) {
-        self.sync_send(Command::Shutdown);
+        self.sync_send(&Command::Shutdown);
     }
 }