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/aidl.rs b/virtualizationservice/src/aidl.rs
index 4135253..0078736 100644
--- a/virtualizationservice/src/aidl.rs
+++ b/virtualizationservice/src/aidl.rs
@@ -823,6 +823,13 @@
})
}
+ fn stop(&self) -> binder::Result<()> {
+ self.instance.kill().map_err(|e| {
+ error!("Error stopping VM with CID {}: {:?}", self.instance.cid, e);
+ new_binder_exception(ExceptionCode::SERVICE_SPECIFIC, e.to_string())
+ })
+ }
+
fn connectVsock(&self, port: i32) -> binder::Result<ParcelFileDescriptor> {
if !matches!(&*self.instance.vm_state.lock().unwrap(), VmState::Running { .. }) {
return Err(new_binder_exception(ExceptionCode::SERVICE_SPECIFIC, "VM is not running"));
@@ -841,7 +848,9 @@
impl Drop for VirtualMachine {
fn drop(&mut self) {
debug!("Dropping {:?}", self);
- self.instance.kill();
+ if let Err(e) = self.instance.kill() {
+ debug!("Error stopping dropped VM with CID {}: {:?}", self.instance.cid, e);
+ }
}
}