summary refs log tree commit diff
diff options
context:
space:
mode:
authorChuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>2019-12-04 16:17:02 +0800
committerCommit Bot <commit-bot@chromium.org>2020-02-06 12:31:56 +0000
commitfab42c86ed2aa0ead9c66efdea7adf51975258fb (patch)
tree58817347ba40b33954a8c204979db1903ca028ce
parent672559f91ae54664fc1f76326c0ecc4008da4c09 (diff)
downloadcrosvm-fab42c86ed2aa0ead9c66efdea7adf51975258fb.tar
crosvm-fab42c86ed2aa0ead9c66efdea7adf51975258fb.tar.gz
crosvm-fab42c86ed2aa0ead9c66efdea7adf51975258fb.tar.bz2
crosvm-fab42c86ed2aa0ead9c66efdea7adf51975258fb.tar.lz
crosvm-fab42c86ed2aa0ead9c66efdea7adf51975258fb.tar.xz
crosvm-fab42c86ed2aa0ead9c66efdea7adf51975258fb.tar.zst
crosvm-fab42c86ed2aa0ead9c66efdea7adf51975258fb.zip
virtio-input: implement the reset method
the event_source needs to be returned through the reset method to allow
the virtio-input device model reactivated again.

BUG=None
TEST=cargo test -p devices

Change-Id: I07a4add40b1c233e1ed328ccef1a1abd453ea0f7
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2032351
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
-rw-r--r--devices/src/virtio/input/mod.rs26
1 files changed, 25 insertions, 1 deletions
diff --git a/devices/src/virtio/input/mod.rs b/devices/src/virtio/input/mod.rs
index ea99720..88a2637 100644
--- a/devices/src/virtio/input/mod.rs
+++ b/devices/src/virtio/input/mod.rs
@@ -561,7 +561,7 @@ impl<T: EventSource> Worker<T> {
 
 pub struct Input<T: EventSource> {
     kill_evt: Option<EventFd>,
-    worker_thread: Option<thread::JoinHandle<()>>,
+    worker_thread: Option<thread::JoinHandle<Worker<T>>>,
     config: VirtioInputConfig,
     source: Option<T>,
 }
@@ -645,6 +645,7 @@ where
                         guest_memory: mem,
                     };
                     worker.run(event_queue_evt_fd, status_queue_evt_fd, kill_evt);
+                    worker
                 });
 
             match worker_result {
@@ -659,6 +660,29 @@ where
             error!("tried to activate device without a source for events");
         }
     }
+
+    fn reset(&mut self) -> bool {
+        if let Some(kill_evt) = self.kill_evt.take() {
+            if kill_evt.write(1).is_err() {
+                error!("{}: failed to notify the kill event", self.debug_label());
+                return false;
+            }
+        }
+
+        if let Some(worker_thread) = self.worker_thread.take() {
+            match worker_thread.join() {
+                Err(_) => {
+                    error!("{}: failed to get back resources", self.debug_label());
+                    return false;
+                }
+                Ok(worker) => {
+                    self.source = Some(worker.event_source);
+                    return true;
+                }
+            }
+        }
+        false
+    }
 }
 
 /// Creates a new virtio input device from an event device node