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