From 028961ac9fc7296b71d77ee536c5a31c7ff54c14 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Thu, 17 Mar 2022 11:24:54 +0100 Subject: [PATCH] vfio_user: Shutdown the communication with the backend Whenever a vfio-user device is dropped, the communication between the VMM and the backend should be shutdown. Signed-off-by: Sebastien Boeuf --- pci/src/vfio_user.rs | 4 ++++ vfio_user/src/lib.rs | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/pci/src/vfio_user.rs b/pci/src/vfio_user.rs index 82a25b931..348a10891 100644 --- a/pci/src/vfio_user.rs +++ b/pci/src/vfio_user.rs @@ -506,6 +506,10 @@ impl Drop for VfioUserPciDevice { if self.common.interrupt.intx_in_use() { self.common.disable_intx(&self.vfio_wrapper); } + + if let Err(e) = self.client.lock().unwrap().shutdown() { + error!("Failed shutting down vfio-user client: {}", e); + } } } diff --git a/vfio_user/src/lib.rs b/vfio_user/src/lib.rs index 0ad01c651..0f4424f4a 100644 --- a/vfio_user/src/lib.rs +++ b/vfio_user/src/lib.rs @@ -255,6 +255,8 @@ pub enum Error { StreamWrite(#[source] std::io::Error), #[error("Error reading from stream: {0}")] StreamRead(#[source] std::io::Error), + #[error("Error shutting down stream: {0}")] + StreamShutdown(#[source] std::io::Error), #[error("Error writing with file descriptors: {0}")] SendWithFd(#[source] vmm_sys_util::errno::Error), #[error("Error reading with file descriptors: {0}")] @@ -665,4 +667,10 @@ impl Client { pub fn resettable(&self) -> bool { self.resettable } + + pub fn shutdown(&self) -> Result<(), Error> { + self.stream + .shutdown(std::net::Shutdown::Both) + .map_err(Error::StreamShutdown) + } }