From fa29dbd0c5ceaf80b851d1614c063ab6ac2b4576 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 31 Mar 2026 07:28:38 -0700 Subject: [PATCH] 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 --- virtio-devices/src/vhost_user/blk.rs | 12 +----------- virtio-devices/src/vhost_user/fs.rs | 11 +---------- .../src/vhost_user/generic_vhost_user.rs | 11 +---------- virtio-devices/src/vhost_user/net.rs | 14 +------------- 4 files changed, 4 insertions(+), 44 deletions(-) diff --git a/virtio-devices/src/vhost_user/blk.rs b/virtio-devices/src/vhost_user/blk.rs index 529eb517d..8221b7b50 100644 --- a/virtio-devices/src/vhost_user/blk.rs +++ b/virtio-devices/src/vhost_user/blk.rs @@ -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(); } } diff --git a/virtio-devices/src/vhost_user/fs.rs b/virtio-devices/src/vhost_user/fs.rs index 71859365e..967fdecf9 100644 --- a/virtio-devices/src/vhost_user/fs.rs +++ b/virtio-devices/src/vhost_user/fs.rs @@ -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(); } } diff --git a/virtio-devices/src/vhost_user/generic_vhost_user.rs b/virtio-devices/src/vhost_user/generic_vhost_user.rs index 83f3fe465..177883443 100644 --- a/virtio-devices/src/vhost_user/generic_vhost_user.rs +++ b/virtio-devices/src/vhost_user/generic_vhost_user.rs @@ -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(); } } diff --git a/virtio-devices/src/vhost_user/net.rs b/virtio-devices/src/vhost_user/net.rs index 7cd4e4207..1c85b5f38 100644 --- a/virtio-devices/src/vhost_user/net.rs +++ b/virtio-devices/src/vhost_user/net.rs @@ -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()