mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-03 20:15:45 +00:00
vmm: device_manager: Invert pci_id_list HashMap
In anticipation for further factorization, the pci_id_list is now a hashmap of PCI b/d/f leading to each device name. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
62aaccee28
commit
305e095d15
@ -894,8 +894,8 @@ pub struct DeviceManager {
|
|||||||
// Bitmap of PCI devices to hotunplug.
|
// Bitmap of PCI devices to hotunplug.
|
||||||
pci_devices_down: u32,
|
pci_devices_down: u32,
|
||||||
|
|
||||||
// Hashmap of device's name to their corresponding PCI b/d/f.
|
// Hashmap of PCI b/d/f to their corresponding device's name.
|
||||||
pci_id_list: HashMap<String, u32>,
|
pci_id_list: HashMap<u32, String>,
|
||||||
|
|
||||||
// Hashmap of PCI b/d/f to their corresponding Arc<Mutex<dyn PciDevice>>.
|
// Hashmap of PCI b/d/f to their corresponding Arc<Mutex<dyn PciDevice>>.
|
||||||
pci_devices: HashMap<u32, Arc<dyn Any + Send + Sync>>,
|
pci_devices: HashMap<u32, Arc<dyn Any + Send + Sync>>,
|
||||||
@ -2955,7 +2955,7 @@ impl DeviceManager {
|
|||||||
)
|
)
|
||||||
.map_err(DeviceManagerError::AddPciDevice)?;
|
.map_err(DeviceManagerError::AddPciDevice)?;
|
||||||
|
|
||||||
self.pci_id_list.insert(device_id, bdf);
|
self.pci_id_list.insert(bdf, device_id);
|
||||||
Ok(bars)
|
Ok(bars)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3247,8 +3247,9 @@ impl DeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_device(&mut self, id: String) -> DeviceManagerResult<()> {
|
pub fn remove_device(&mut self, id: String) -> DeviceManagerResult<()> {
|
||||||
if let Some(pci_device_bdf) = self.pci_id_list.get(&id) {
|
for (pci_device_bdf, pci_device_name) in self.pci_id_list.iter() {
|
||||||
if let Some(any_device) = self.pci_devices.get(&pci_device_bdf) {
|
if *pci_device_name == id {
|
||||||
|
if let Some(any_device) = self.pci_devices.get(pci_device_bdf) {
|
||||||
if let Ok(virtio_pci_device) =
|
if let Ok(virtio_pci_device) =
|
||||||
Arc::clone(any_device).downcast::<Mutex<VirtioPciDevice>>()
|
Arc::clone(any_device).downcast::<Mutex<VirtioPciDevice>>()
|
||||||
{
|
{
|
||||||
@ -3285,12 +3286,13 @@ impl DeviceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
return Ok(());
|
||||||
} else {
|
|
||||||
Err(DeviceManagerError::UnknownDeviceId(id))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Err(DeviceManagerError::UnknownDeviceId(id))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn eject_device(&mut self, device_id: u8) -> DeviceManagerResult<()> {
|
pub fn eject_device(&mut self, device_id: u8) -> DeviceManagerResult<()> {
|
||||||
// Retrieve the PCI bus.
|
// Retrieve the PCI bus.
|
||||||
let pci = if let Some(pci_bus) = &self.pci_bus {
|
let pci = if let Some(pci_bus) = &self.pci_bus {
|
||||||
@ -3304,7 +3306,7 @@ impl DeviceManager {
|
|||||||
|
|
||||||
// Find the device name corresponding to the PCI b/d/f while removing
|
// Find the device name corresponding to the PCI b/d/f while removing
|
||||||
// the device entry.
|
// the device entry.
|
||||||
self.pci_id_list.retain(|_, bdf| *bdf != pci_device_bdf);
|
self.pci_id_list.remove(&pci_device_bdf);
|
||||||
|
|
||||||
// Give the PCI device ID back to the PCI bus.
|
// Give the PCI device ID back to the PCI bus.
|
||||||
pci.lock()
|
pci.lock()
|
||||||
|
Loading…
Reference in New Issue
Block a user