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>
This commit is contained in:
Chuanxiao Dong 2019-12-04 16:17:02 +08:00 committed by Commit Bot
parent 672559f91a
commit fab42c86ed

View file

@ -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