vmm: Free PCI BARs when unplugging PCI device

Now that PciDevice trait has a dedicated function to remove the bars,
the DeviceManager can invoke this function whenever a PCI device is
unplugged from the VM.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-03-11 10:05:37 +01:00 committed by Rob Bradford
parent f0dff8b58c
commit 432eb5b70a

View File

@ -135,6 +135,10 @@ pub enum DeviceManagerError {
#[cfg(feature = "pci_support")]
AllocateBars(pci::PciDeviceError),
/// Could not free the BARs associated with a PCI device.
#[cfg(feature = "pci_support")]
FreePciBars(pci::PciDeviceError),
/// Cannot register ioevent.
RegisterIoevent(kvm_ioctls::Error),
@ -1861,6 +1865,13 @@ impl DeviceManager {
return Ok(());
};
// Free the allocated BARs
pci_device
.lock()
.unwrap()
.free_bars(&mut self.address_manager.allocator.lock().unwrap())
.map_err(DeviceManagerError::FreePciBars)?;
// Remove the device from the PCI bus
pci.lock()
.unwrap()