From fab42c86ed2aa0ead9c66efdea7adf51975258fb Mon Sep 17 00:00:00 2001 From: Chuanxiao Dong Date: Wed, 4 Dec 2019 16:17:02 +0800 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2032351 Reviewed-by: Daniel Verkamp Tested-by: kokoro --- devices/src/virtio/input/mod.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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 Worker { pub struct Input { kill_evt: Option, - worker_thread: Option>, + worker_thread: Option>>, config: VirtioInputConfig, source: Option, } @@ -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 -- cgit 1.4.1