From 94c352752e1109fc6cf7c0cf9c6ce121ad1d46b9 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Thu, 12 Sep 2019 13:31:30 -0700 Subject: linux: drop VM before exiting to allow cleanup Clean up the `linux` object (which contains the devices) before the control sockets passed to `run_control` are closed. This allows crosvm to shut down cleanly without any error messages about short reads from the control sockets. BUG=chromium:992494 TEST=exit crosvm without errors Change-Id: I1040c2f9ecbd03f820c7082da3327962ecc445f1 Signed-off-by: Daniel Verkamp Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1802155 Reviewed-by: Stephen Barber Tested-by: kokoro --- src/linux.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/linux.rs') diff --git a/src/linux.rs b/src/linux.rs index 7ce7c82..58e0971 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -10,6 +10,7 @@ use std::ffi::CStr; use std::fmt::{self, Display}; use std::fs::{File, OpenOptions}; use std::io::{self, stdin, Read}; +use std::mem; use std::net::Ipv4Addr; #[cfg(feature = "gpu")] use std::num::NonZeroU8; @@ -1517,7 +1518,8 @@ fn run_control( let vcpu_thread_barrier = Arc::new(Barrier::new(linux.vcpus.len() + 1)); let run_mode_arc = Arc::new(VcpuRunMode::default()); setup_vcpu_signal_handler()?; - for (cpu_id, vcpu) in linux.vcpus.into_iter().enumerate() { + let vcpus = linux.vcpus.split_off(0); + for (cpu_id, vcpu) in vcpus.into_iter().enumerate() { let handle = run_vcpu( vcpu, cpu_id as u32, @@ -1804,6 +1806,10 @@ fn run_control( } } + // Explicitly drop the VM structure here to allow the devices to clean up before the + // control sockets are closed when this function exits. + mem::drop(linux); + stdin_lock .set_canon_mode() .expect("failed to restore canonical mode for terminal"); -- cgit 1.4.1