Stop VM immediately with stop() call
Rather than waiting GC to drop the handle, immediately stops the VM by
sending signal to crosvm process.
Bug: 207766487
Test: atest MicrodroidTests
Change-Id: I892d8a60238e7156609e21e9939d4e90038c396d
diff --git a/virtualizationservice/src/crosvm.rs b/virtualizationservice/src/crosvm.rs
index 46ad6b3..b6e62fe 100644
--- a/virtualizationservice/src/crosvm.rs
+++ b/virtualizationservice/src/crosvm.rs
@@ -241,7 +241,9 @@
"Microdroid failed to start payload within {} secs timeout. Shutting down",
BOOT_HANGUP_TIMEOUT.as_secs()
);
- self.kill();
+ if let Err(e) = self.kill() {
+ error!("Error stopping timed-out VM with CID {}: {:?}", self.cid, e);
+ }
true
} else {
false
@@ -304,15 +306,19 @@
}
/// Kills the crosvm instance, if it is running.
- pub fn kill(&self) {
+ pub fn kill(&self) -> Result<(), Error> {
let vm_state = &*self.vm_state.lock().unwrap();
if let VmState::Running { child } = vm_state {
let id = child.id();
debug!("Killing crosvm({})", id);
// TODO: Talk to crosvm to shutdown cleanly.
if let Err(e) = child.kill() {
- error!("Error killing crosvm({}) instance: {}", id, e);
+ bail!("Error killing crosvm({}) instance: {}", id, e);
+ } else {
+ Ok(())
}
+ } else {
+ bail!("VM is not running")
}
}