From c85aa6dfae439c6d554cca102c7c894e8face68f Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 9 Aug 2021 11:05:20 +0200 Subject: [PATCH] virtio-devices: vhost_user: Kill threads upon migration completion In order to prevent the vhost-user devices from reconnecting to the backend after the migration has been successfully performed, we make sure to kill the thread in charge of handling the reconnection mechanism. Signed-off-by: Sebastien Boeuf --- virtio-devices/src/vhost_user/blk.rs | 19 +++++++++++++++++++ virtio-devices/src/vhost_user/fs.rs | 19 +++++++++++++++++++ virtio-devices/src/vhost_user/net.rs | 19 +++++++++++++++++++ 3 files changed, 57 insertions(+) diff --git a/virtio-devices/src/vhost_user/blk.rs b/virtio-devices/src/vhost_user/blk.rs index 7e887deef..083226ac9 100644 --- a/virtio-devices/src/vhost_user/blk.rs +++ b/virtio-devices/src/vhost_user/blk.rs @@ -483,4 +483,23 @@ impl Migratable for Blk { Ok(MemoryRangeTable::default()) } } + + fn complete_migration(&mut self) -> std::result::Result<(), MigratableError> { + // Make sure the device thread is killed in order to prevent from + // reconnections to the socket. + if let Some(kill_evt) = self.common.kill_evt.take() { + kill_evt.write(1).map_err(|e| { + MigratableError::CompleteMigration(anyhow!( + "Error killing vhost-user-blk thread: {:?}", + e + )) + })?; + } + + // Drop the vhost-user handler to avoid further calls to fail because + // the connection with the backend has been closed. + self.vu = None; + + Ok(()) + } } diff --git a/virtio-devices/src/vhost_user/fs.rs b/virtio-devices/src/vhost_user/fs.rs index 93c8603cb..3aa533f66 100644 --- a/virtio-devices/src/vhost_user/fs.rs +++ b/virtio-devices/src/vhost_user/fs.rs @@ -763,4 +763,23 @@ impl Migratable for Fs { Ok(MemoryRangeTable::default()) } } + + fn complete_migration(&mut self) -> std::result::Result<(), MigratableError> { + // Make sure the device thread is killed in order to prevent from + // reconnections to the socket. + if let Some(kill_evt) = self.common.kill_evt.take() { + kill_evt.write(1).map_err(|e| { + MigratableError::CompleteMigration(anyhow!( + "Error killing vhost-user-fs threads: {:?}", + e + )) + })?; + } + + // Drop the vhost-user handler to avoid further calls to fail because + // the connection with the backend has been closed. + self.vu = None; + + Ok(()) + } } diff --git a/virtio-devices/src/vhost_user/net.rs b/virtio-devices/src/vhost_user/net.rs index 78eba4e0a..33d3f3e9b 100644 --- a/virtio-devices/src/vhost_user/net.rs +++ b/virtio-devices/src/vhost_user/net.rs @@ -569,4 +569,23 @@ impl Migratable for Net { Ok(MemoryRangeTable::default()) } } + + fn complete_migration(&mut self) -> std::result::Result<(), MigratableError> { + // Make sure the device thread is killed in order to prevent from + // reconnections to the socket. + if let Some(kill_evt) = self.common.kill_evt.take() { + kill_evt.write(1).map_err(|e| { + MigratableError::CompleteMigration(anyhow!( + "Error killing vhost-user-net threads: {:?}", + e + )) + })?; + } + + // Drop the vhost-user handler to avoid further calls to fail because + // the connection with the backend has been closed. + self.vu = None; + + Ok(()) + } }