From de3b17d948acd4b3e28d4832b191dca02afb8bcd Mon Sep 17 00:00:00 2001 From: Bo Chen Date: Mon, 17 Aug 2020 12:45:17 -0700 Subject: [PATCH] virtio-devices: Print out worker thread errors As we never join the spawned virtio-devices worker threads, the error returned from each worker thread is lost. For now, we simply print out the error from each worker thread. Fixes: #1551 Signed-off-by: Bo Chen --- virtio-devices/src/balloon.rs | 8 ++++++-- virtio-devices/src/block_io_uring.rs | 8 ++++++-- virtio-devices/src/mem.rs | 8 ++++++-- virtio-devices/src/vhost_user/blk.rs | 12 +++++++----- virtio-devices/src/vhost_user/fs.rs | 12 ++++++++---- virtio-devices/src/vhost_user/net.rs | 20 +++++++++++++------- virtio-devices/src/vsock/device.rs | 8 ++++++-- 7 files changed, 52 insertions(+), 24 deletions(-) diff --git a/virtio-devices/src/balloon.rs b/virtio-devices/src/balloon.rs index 476160340..d61b5edb3 100644 --- a/virtio-devices/src/balloon.rs +++ b/virtio-devices/src/balloon.rs @@ -315,7 +315,7 @@ pub struct Balloon { config: Arc>, queue_evts: Option>, interrupt_cb: Option>, - epoll_threads: Option>>>, + epoll_threads: Option>>, paused: Arc, paused_sync: Arc, } @@ -453,7 +453,11 @@ impl VirtioDevice for Balloon { let mut epoll_threads = Vec::new(); thread::Builder::new() .name("virtio_balloon".to_string()) - .spawn(move || handler.run(paused, paused_sync)) + .spawn(move || { + if let Err(e) = handler.run(paused, paused_sync) { + error!("Error running worker: {:?}", e); + } + }) .map(|thread| epoll_threads.push(thread)) .map_err(|e| { error!("failed to clone virtio-balloon epoll thread: {}", e); diff --git a/virtio-devices/src/block_io_uring.rs b/virtio-devices/src/block_io_uring.rs index c3253c57e..41937eb8c 100644 --- a/virtio-devices/src/block_io_uring.rs +++ b/virtio-devices/src/block_io_uring.rs @@ -310,7 +310,7 @@ pub struct BlockIoUring { config: VirtioBlockConfig, queue_evts: Option>, interrupt_cb: Option>, - epoll_threads: Option>>>, + epoll_threads: Option>>, pause_evt: Option, paused: Arc, paused_sync: Arc, @@ -601,7 +601,11 @@ impl VirtioDevice for BlockIoUring { thread::Builder::new() .name("virtio_blk".to_string()) - .spawn(move || handler.run(paused, paused_sync)) + .spawn(move || { + if let Err(e) = handler.run(paused, paused_sync) { + error!("Error running worker: {:?}", e); + } + }) .map(|thread| epoll_threads.push(thread)) .map_err(|e| { error!("failed to clone the virtio-blk epoll thread: {}", e); diff --git a/virtio-devices/src/mem.rs b/virtio-devices/src/mem.rs index 593dd3cec..5267031b7 100644 --- a/virtio-devices/src/mem.rs +++ b/virtio-devices/src/mem.rs @@ -689,7 +689,7 @@ pub struct Mem { config: Arc>, queue_evts: Option>, interrupt_cb: Option>, - epoll_threads: Option>>>, + epoll_threads: Option>>, paused: Arc, paused_sync: Arc, } @@ -854,7 +854,11 @@ impl VirtioDevice for Mem { let mut epoll_threads = Vec::new(); thread::Builder::new() .name("virtio_mem".to_string()) - .spawn(move || handler.run(paused, paused_sync)) + .spawn(move || { + if let Err(e) = handler.run(paused, paused_sync) { + error!("Error running worker: {:?}", e); + } + }) .map(|thread| epoll_threads.push(thread)) .map_err(|e| { error!("failed to clone virtio-mem epoll thread: {}", e); diff --git a/virtio-devices/src/vhost_user/blk.rs b/virtio-devices/src/vhost_user/blk.rs index 2ce73ce18..e3a9d2114 100644 --- a/virtio-devices/src/vhost_user/blk.rs +++ b/virtio-devices/src/vhost_user/blk.rs @@ -1,9 +1,7 @@ // Copyright 2019 Intel Corporation. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -use super::super::{ - ActivateError, ActivateResult, EpollHelperError, Queue, VirtioDevice, VirtioDeviceType, -}; +use super::super::{ActivateError, ActivateResult, Queue, VirtioDevice, VirtioDeviceType}; use super::handler::*; use super::vu_common_ctrl::*; use super::{Error, Result}; @@ -42,7 +40,7 @@ pub struct Blk { queue_sizes: Vec, queue_evts: Option>, interrupt_cb: Option>, - epoll_threads: Option>>>, + epoll_threads: Option>>, paused: Arc, paused_sync: Arc, } @@ -278,7 +276,11 @@ impl VirtioDevice for Blk { let paused_sync = self.paused_sync.clone(); thread::Builder::new() .name("vhost_user_blk".to_string()) - .spawn(move || handler.run(paused, paused_sync)) + .spawn(move || { + if let Err(e) = handler.run(paused, paused_sync) { + error!("Error running worker: {:?}", e); + } + }) .map(|thread| epoll_threads.push(thread)) .map_err(|e| { error!("failed to clone virtio epoll thread: {}", e); diff --git a/virtio-devices/src/vhost_user/fs.rs b/virtio-devices/src/vhost_user/fs.rs index 968a1baff..09ce53bd1 100644 --- a/virtio-devices/src/vhost_user/fs.rs +++ b/virtio-devices/src/vhost_user/fs.rs @@ -5,8 +5,8 @@ use super::vu_common_ctrl::{reset_vhost_user, setup_vhost_user, update_mem_table use super::{Error, Result}; use crate::vhost_user::handler::{VhostUserEpollConfig, VhostUserEpollHandler}; use crate::{ - ActivateError, ActivateResult, EpollHelperError, Queue, UserspaceMapping, VirtioDevice, - VirtioDeviceType, VirtioInterrupt, VirtioSharedMemoryList, VIRTIO_F_VERSION_1, + ActivateError, ActivateResult, Queue, UserspaceMapping, VirtioDevice, VirtioDeviceType, + VirtioInterrupt, VirtioSharedMemoryList, VIRTIO_F_VERSION_1, }; use libc::{self, c_void, off64_t, pread64, pwrite64, EFD_NONBLOCK}; use std::io; @@ -278,7 +278,7 @@ pub struct Fs { slave_req_support: bool, queue_evts: Option>, interrupt_cb: Option>, - epoll_threads: Option>>>, + epoll_threads: Option>>, paused: Arc, paused_sync: Arc, } @@ -506,7 +506,11 @@ impl VirtioDevice for Fs { let mut epoll_threads = Vec::new(); thread::Builder::new() .name("virtio_fs".to_string()) - .spawn(move || handler.run(paused, paused_sync)) + .spawn(move || { + if let Err(e) = handler.run(paused, paused_sync) { + error!("Error running worker: {:?}", e); + } + }) .map(|thread| epoll_threads.push(thread)) .map_err(|e| { error!("failed to clone queue EventFd: {}", e); diff --git a/virtio-devices/src/vhost_user/net.rs b/virtio-devices/src/vhost_user/net.rs index 77667c081..13b617f0b 100644 --- a/virtio-devices/src/vhost_user/net.rs +++ b/virtio-devices/src/vhost_user/net.rs @@ -4,9 +4,7 @@ use super::super::net_util::{ build_net_config_space, CtrlVirtio, NetCtrlEpollHandler, VirtioNetConfig, }; -use super::super::{ - ActivateError, ActivateResult, EpollHelperError, Queue, VirtioDevice, VirtioDeviceType, -}; +use super::super::{ActivateError, ActivateResult, Queue, VirtioDevice, VirtioDeviceType}; use super::handler::*; use super::vu_common_ctrl::*; use super::{Error, Result}; @@ -45,8 +43,8 @@ pub struct Net { queue_sizes: Vec, queue_evts: Option>, interrupt_cb: Option>, - epoll_threads: Option>>>, - ctrl_queue_epoll_thread: Option>>, + epoll_threads: Option>>, + ctrl_queue_epoll_thread: Option>, paused: Arc, paused_sync: Arc, } @@ -268,7 +266,11 @@ impl VirtioDevice for Net { let paused_sync = self.paused_sync.clone(); thread::Builder::new() .name("virtio_net".to_string()) - .spawn(move || ctrl_handler.run_ctrl(paused, paused_sync)) + .spawn(move || { + if let Err(e) = ctrl_handler.run_ctrl(paused, paused_sync) { + error!("Error running worker: {:?}", e); + } + }) .map(|thread| self.ctrl_queue_epoll_thread = Some(thread)) .map_err(|e| { error!("failed to clone queue EventFd: {}", e); @@ -304,7 +306,11 @@ impl VirtioDevice for Net { let paused_sync = self.paused_sync.clone(); thread::Builder::new() .name("vhost_user_net".to_string()) - .spawn(move || handler.run(paused, paused_sync)) + .spawn(move || { + if let Err(e) = handler.run(paused, paused_sync) { + error!("Error running worker: {:?}", e); + } + }) .map(|thread| epoll_threads.push(thread)) .map_err(|e| { error!("failed to clone queue EventFd: {}", e); diff --git a/virtio-devices/src/vsock/device.rs b/virtio-devices/src/vsock/device.rs index a43b25c80..484fa6750 100644 --- a/virtio-devices/src/vsock/device.rs +++ b/virtio-devices/src/vsock/device.rs @@ -305,7 +305,7 @@ pub struct Vsock { acked_features: u64, queue_evts: Option>, interrupt_cb: Option>, - epoll_threads: Option>>>, + epoll_threads: Option>>, paused: Arc, paused_sync: Arc, path: PathBuf, @@ -486,7 +486,11 @@ where let mut epoll_threads = Vec::new(); thread::Builder::new() .name("virtio_vsock".to_string()) - .spawn(move || handler.run(paused, paused_sync)) + .spawn(move || { + if let Err(e) = handler.run(paused, paused_sync) { + error!("Error running worker: {:?}", e); + } + }) .map(|thread| epoll_threads.push(thread)) .map_err(|e| { error!("failed to clone the vsock epoll thread: {}", e);