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(()) + } }