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 <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2022-03-17 11:24:54 +01:00
parent 9c95109a6b
commit 028961ac9f
2 changed files with 12 additions and 0 deletions
+4
View File
@@ -506,6 +506,10 @@ impl Drop for VfioUserPciDevice {
if self.common.interrupt.intx_in_use() { if self.common.interrupt.intx_in_use() {
self.common.disable_intx(&self.vfio_wrapper); self.common.disable_intx(&self.vfio_wrapper);
} }
if let Err(e) = self.client.lock().unwrap().shutdown() {
error!("Failed shutting down vfio-user client: {}", e);
}
} }
} }
+8
View File
@@ -255,6 +255,8 @@ pub enum Error {
StreamWrite(#[source] std::io::Error), StreamWrite(#[source] std::io::Error),
#[error("Error reading from stream: {0}")] #[error("Error reading from stream: {0}")]
StreamRead(#[source] std::io::Error), StreamRead(#[source] std::io::Error),
#[error("Error shutting down stream: {0}")]
StreamShutdown(#[source] std::io::Error),
#[error("Error writing with file descriptors: {0}")] #[error("Error writing with file descriptors: {0}")]
SendWithFd(#[source] vmm_sys_util::errno::Error), SendWithFd(#[source] vmm_sys_util::errno::Error),
#[error("Error reading with file descriptors: {0}")] #[error("Error reading with file descriptors: {0}")]
@@ -665,4 +667,10 @@ impl Client {
pub fn resettable(&self) -> bool { pub fn resettable(&self) -> bool {
self.resettable self.resettable
} }
pub fn shutdown(&self) -> Result<(), Error> {
self.stream
.shutdown(std::net::Shutdown::Both)
.map_err(Error::StreamShutdown)
}
} }