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 <dverkamp@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1802155
Reviewed-by: Stephen Barber <smbarber@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
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::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 @@
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 @@
}
}
+ // 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");