mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
virtio-devices, vmm: Shutdown VMM on virtio thread panic
Shutdown the VMM in the virtio (or VMM side of vhost-user) thread panics. See: #3031 Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
@@ -8,13 +8,18 @@ use crate::{
|
||||
ActivateError,
|
||||
};
|
||||
use seccompiler::{apply_filter, SeccompAction};
|
||||
use std::thread::{self, JoinHandle};
|
||||
use std::{
|
||||
panic::AssertUnwindSafe,
|
||||
thread::{self, JoinHandle},
|
||||
};
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
|
||||
pub(crate) fn spawn_virtio_thread<F>(
|
||||
name: &str,
|
||||
seccomp_action: &SeccompAction,
|
||||
thread_type: Thread,
|
||||
epoll_threads: &mut Vec<JoinHandle<()>>,
|
||||
exit_evt: &EventFd,
|
||||
f: F,
|
||||
) -> Result<(), ActivateError>
|
||||
where
|
||||
@@ -24,20 +29,31 @@ where
|
||||
let seccomp_filter = get_seccomp_filter(seccomp_action, thread_type)
|
||||
.map_err(ActivateError::CreateSeccompFilter)?;
|
||||
|
||||
let thread_exit_evt = exit_evt
|
||||
.try_clone()
|
||||
.map_err(ActivateError::CloneExitEventFd)?;
|
||||
let thread_name = name.to_string();
|
||||
|
||||
thread::Builder::new()
|
||||
.name(name.to_string())
|
||||
.spawn(move || {
|
||||
if !seccomp_filter.is_empty() {
|
||||
if let Err(e) = apply_filter(&seccomp_filter) {
|
||||
error!("Error applying seccomp filter: {:?}", e);
|
||||
thread_exit_evt.write(1).ok();
|
||||
return;
|
||||
}
|
||||
}
|
||||
f()
|
||||
std::panic::catch_unwind(AssertUnwindSafe(move || f()))
|
||||
.or_else(|_| {
|
||||
error!("{} thread panicked", thread_name);
|
||||
thread_exit_evt.write(1)
|
||||
})
|
||||
.ok();
|
||||
})
|
||||
.map(|thread| epoll_threads.push(thread))
|
||||
.map_err(|e| {
|
||||
error!("Failed to spawn thread for {}: {}", name, e);
|
||||
ActivateError::BadActivate
|
||||
ActivateError::ThreadSpawn(e)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user