virtio-devices: properly join all threads on Drop

This change is important to do a proper resource cleanup. We decided
to do this repetitive approach as VirtioCommon can't implement Drop
without major changes to the corresponding code. Also, devices such as
Net can't easily use the epoll_threads-abstraction from VirtioCommon as
it has multiple threads with different semantics.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
This commit is contained in:
Philipp Schuster 2023-01-12 10:07:55 +01:00 committed by Rob Bradford
parent b1f6a59579
commit ad6c0ee52b
13 changed files with 39 additions and 0 deletions

View File

@ -450,6 +450,7 @@ impl Drop for Balloon {
// Ignore the result because there is nothing we can do about it.
let _ = kill_evt.write(1);
}
self.common.wait_for_epoll_threads();
}
}

View File

@ -658,6 +658,7 @@ impl Drop for Block {
// Ignore the result because there is nothing we can do about it.
let _ = kill_evt.write(1);
}
self.common.wait_for_epoll_threads();
}
}

View File

@ -710,6 +710,7 @@ impl Drop for Console {
// Ignore the result because there is nothing we can do about it.
let _ = kill_evt.write(1);
}
self.common.wait_for_epoll_threads();
}
}

View File

@ -1000,6 +1000,7 @@ impl Drop for Iommu {
// Ignore the result because there is nothing we can do about it.
let _ = kill_evt.write(1);
}
self.common.wait_for_epoll_threads();
}
}

View File

@ -902,6 +902,7 @@ impl Drop for Mem {
// Ignore the result because there is nothing we can do about it.
let _ = kill_evt.write(1);
}
self.common.wait_for_epoll_threads();
}
}

View File

@ -670,6 +670,11 @@ impl Drop for Net {
}
// Needed to ensure all references to tap FDs are dropped (#4868)
self.common.wait_for_epoll_threads();
if let Some(thread) = self.ctrl_queue_epoll_thread.take() {
if let Err(e) = thread.join() {
error!("Error joining thread: {:?}", e);
}
}
}
}

View File

@ -364,6 +364,7 @@ impl Drop for Pmem {
// Ignore the result because there is nothing we can do about it.
let _ = kill_evt.write(1);
}
self.common.wait_for_epoll_threads();
}
}

View File

@ -228,6 +228,7 @@ impl Drop for Rng {
// Ignore the result because there is nothing we can do about it.
let _ = kill_evt.write(1);
}
self.common.wait_for_epoll_threads();
}
}

View File

@ -223,6 +223,12 @@ impl Drop for Blk {
error!("failed to kill vhost-user-blk: {:?}", e);
}
}
self.common.wait_for_epoll_threads();
if let Some(thread) = self.epoll_thread.take() {
if let Err(e) = thread.join() {
error!("Error joining thread: {:?}", e);
}
}
}
}

View File

@ -462,6 +462,12 @@ impl Drop for Fs {
// Ignore the result because there is nothing we can do about it.
let _ = kill_evt.write(1);
}
self.common.wait_for_epoll_threads();
if let Some(thread) = self.epoll_thread.take() {
if let Err(e) = thread.join() {
error!("Error joining thread: {:?}", e);
}
}
}
}

View File

@ -251,6 +251,19 @@ impl Drop for Net {
error!("failed to kill vhost-user-net: {:?}", e);
}
}
self.common.wait_for_epoll_threads();
if let Some(thread) = self.epoll_thread.take() {
if let Err(e) = thread.join() {
error!("Error joining thread: {:?}", e);
}
}
if let Some(thread) = self.ctrl_queue_epoll_thread.take() {
if let Err(e) = thread.join() {
error!("Error joining thread: {:?}", e);
}
}
}
}

View File

@ -397,6 +397,7 @@ where
// Ignore the result because there is nothing we can do about it.
let _ = kill_evt.write(1);
}
self.common.wait_for_epoll_threads();
}
}

View File

@ -278,6 +278,7 @@ impl Drop for Watchdog {
// Ignore the result because there is nothing we can do about it.
let _ = kill_evt.write(1);
}
self.common.wait_for_epoll_threads();
}
}