virtio-devices: Reuse common shutdown code in drop implementations

Now that the VhostUserCommon::shutdown implementation has been filled
out to support migration it can also be used for the drop
implementations in the vhost-user devices.

It's worth noting that the call to wait_for_epoll_threads() was a no-op
as those threads are only configured on conventional virtio devices.

Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
Rob Bradford
2026-03-31 07:28:38 -07:00
parent 266ad8aa0e
commit fa29dbd0c5
4 changed files with 4 additions and 44 deletions

View File

@@ -202,17 +202,7 @@ impl Blk {
impl Drop for Blk {
fn drop(&mut self) {
if let Some(kill_evt) = self.vu_common.virtio_common.kill_evt.take()
&& let Err(e) = kill_evt.write(1)
{
error!("failed to kill vhost-user-blk: {e:?}");
}
self.vu_common.virtio_common.wait_for_epoll_threads();
if let Some(thread) = self.vu_common.epoll_thread.take()
&& let Err(e) = thread.join()
{
error!("Error joining thread: {e:?}");
}
self.vu_common.shutdown();
}
}

View File

@@ -211,16 +211,7 @@ impl Fs {
impl Drop for Fs {
fn drop(&mut self) {
if let Some(kill_evt) = self.vu_common.virtio_common.kill_evt.take() {
// Ignore the result because there is nothing we can do about it.
let _ = kill_evt.write(1);
}
self.vu_common.virtio_common.wait_for_epoll_threads();
if let Some(thread) = self.vu_common.epoll_thread.take()
&& let Err(e) = thread.join()
{
error!("Error joining thread: {e:?}");
}
self.vu_common.shutdown();
}
}

View File

@@ -186,16 +186,7 @@ space access. Reads will return 0xFF and writes will be ignored."
impl Drop for GenericVhostUser {
fn drop(&mut self) {
if let Some(kill_evt) = self.vu_common.virtio_common.kill_evt.take() {
// Ignore the result because there is nothing we can do about it.
let _ = kill_evt.write(1);
}
self.vu_common.virtio_common.wait_for_epoll_threads();
if let Some(thread) = self.vu_common.epoll_thread.take()
&& let Err(e) = thread.join()
{
error!("Error joining thread: {e:?}");
}
self.vu_common.shutdown();
}
}

View File

@@ -231,19 +231,7 @@ impl Net {
impl Drop for Net {
fn drop(&mut self) {
if let Some(kill_evt) = self.vu_common.virtio_common.kill_evt.take()
&& let Err(e) = kill_evt.write(1)
{
error!("failed to kill vhost-user-net: {e:?}");
}
self.vu_common.virtio_common.wait_for_epoll_threads();
if let Some(thread) = self.vu_common.epoll_thread.take()
&& let Err(e) = thread.join()
{
error!("Error joining thread: {e:?}");
}
self.vu_common.shutdown();
if let Some(thread) = self.ctrl_queue_epoll_thread.take()
&& let Err(e) = thread.join()