mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
pci: Give PCI device ID back when removing a device
Upon removal of a PCI device, make sure we don't hold onto the device ID as it could be reused for another device later. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
committed by
Rob Bradford
parent
df71aaee3f
commit
b50cbe5064
@@ -244,6 +244,10 @@ pub enum DeviceManagerError {
|
||||
/// Failed to find an available PCI device ID.
|
||||
#[cfg(feature = "pci_support")]
|
||||
NextPciDeviceId(pci::PciRootError),
|
||||
|
||||
/// Could not give the PCI device ID back.
|
||||
#[cfg(feature = "pci_support")]
|
||||
PutPciDeviceId(pci::PciRootError),
|
||||
}
|
||||
pub type DeviceManagerResult<T> = result::Result<T, DeviceManagerError>;
|
||||
|
||||
@@ -1839,6 +1843,12 @@ impl DeviceManager {
|
||||
// the device entry.
|
||||
self.pci_id_list.retain(|_, bdf| *bdf != pci_device_bdf);
|
||||
|
||||
// Give the PCI device ID back to the PCI bus.
|
||||
pci.lock()
|
||||
.unwrap()
|
||||
.put_device_id(device_id as usize)
|
||||
.map_err(DeviceManagerError::PutPciDeviceId)?;
|
||||
|
||||
if let Some(any_device) = self.pci_devices.remove(&pci_device_bdf) {
|
||||
let (pci_device, bus_device, migratable_device) =
|
||||
if let Ok(vfio_pci_device) = any_device.downcast::<Mutex<VfioPciDevice>>() {
|
||||
|
||||
Reference in New Issue
Block a user