mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-22 12:35:19 +00:00
vmm: Store PCI devices as Any devices from DeviceManager
As we try to keep track of every PCI device related to the VM, we don't want to have separate lists depending on the concrete type associated with the PciDevice trait. Also, we want to be able to cast the actual type into any trait or concrete type. The most efficient way to solve all these issues is to store every device as an Arc<dyn Any + Send + Sync>. This gives the ability to downcast into the appropriate concrete type, and then to cast back into any trait that we might need. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
0f99d3f7cc
commit
08604ac6a8
@ -33,6 +33,8 @@ use pci::{
|
||||
DeviceRelocation, PciBarRegionType, PciBus, PciConfigIo, PciConfigMmio, PciDevice, PciRoot,
|
||||
};
|
||||
use qcow::{self, ImageType, QcowFile};
|
||||
#[cfg(feature = "pci_support")]
|
||||
use std::any::Any;
|
||||
use std::collections::HashMap;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io::{self, sink, stdout};
|
||||
@ -479,6 +481,10 @@ pub struct DeviceManager {
|
||||
// Counter to keep track of the consumed device IDs.
|
||||
#[cfg(feature = "pci_support")]
|
||||
device_id_cnt: Wrapping<usize>,
|
||||
|
||||
// Hashmap of PCI b/d/f to their corresponding Arc<Mutex<dyn PciDevice>>.
|
||||
#[cfg(feature = "pci_support")]
|
||||
pci_devices: HashMap<u32, Arc<dyn Any + Send + Sync>>,
|
||||
}
|
||||
|
||||
impl DeviceManager {
|
||||
@ -582,6 +588,8 @@ impl DeviceManager {
|
||||
pci_id_list: HashMap::new(),
|
||||
#[cfg(feature = "pci_support")]
|
||||
device_id_cnt: Wrapping(0),
|
||||
#[cfg(feature = "pci_support")]
|
||||
pci_devices: HashMap::new(),
|
||||
};
|
||||
|
||||
device_manager
|
||||
@ -1494,6 +1502,10 @@ impl DeviceManager {
|
||||
pci.add_device(vfio_pci_device.clone())
|
||||
.map_err(DeviceManagerError::AddPciDevice)?;
|
||||
|
||||
self.pci_devices.insert(
|
||||
pci_device_bdf,
|
||||
Arc::clone(&vfio_pci_device) as Arc<dyn Any + Send + Sync>,
|
||||
);
|
||||
self.bus_devices
|
||||
.push(Arc::clone(&vfio_pci_device) as Arc<Mutex<dyn BusDevice>>);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user