vmm: Make add_vfio_device mutable

The method add_vfio_device() from the DeviceManager needs to be mutable
if we want later to be able to update some internal fields from the
DeviceManager from this same function.

This commit simply takes care of making the necessary changes to change
this function as mutable.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-03-04 15:54:42 +01:00
parent 948f808da6
commit d0820cc026
2 changed files with 25 additions and 8 deletions

View File

@ -1387,7 +1387,7 @@ impl DeviceManager {
#[cfg(feature = "pci_support")] #[cfg(feature = "pci_support")]
fn add_vfio_device( fn add_vfio_device(
&self, &mut self,
pci: &mut PciBus, pci: &mut PciBus,
interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>, interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
device_fd: &Arc<DeviceFd>, device_fd: &Arc<DeviceFd>,
@ -1461,8 +1461,9 @@ impl DeviceManager {
interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>, interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
) -> DeviceManagerResult<Vec<u32>> { ) -> DeviceManagerResult<Vec<u32>> {
let mut iommu_attached_device_ids = Vec::new(); let mut iommu_attached_device_ids = Vec::new();
let devices = self.config.lock().unwrap().devices.clone();
if let Some(device_list_cfg) = &self.config.lock().unwrap().devices { if let Some(device_list_cfg) = &devices {
// Create the KVM VFIO device // Create the KVM VFIO device
let device_fd = DeviceManager::create_kvm_device(&self.address_manager.vm_fd)?; let device_fd = DeviceManager::create_kvm_device(&self.address_manager.vm_fd)?;
let device_fd = Arc::new(device_fd); let device_fd = Arc::new(device_fd);
@ -1670,8 +1671,8 @@ impl DeviceManager {
iommu: false, iommu: false,
}; };
let mut pci = if let Some(pci_bus) = &self.pci_bus { let pci = if let Some(pci_bus) = &self.pci_bus {
pci_bus.lock().unwrap() Arc::clone(&pci_bus)
} else { } else {
return Err(DeviceManagerError::NoPciBus); return Err(DeviceManagerError::NoPciBus);
}; };
@ -1690,8 +1691,12 @@ impl DeviceManager {
device_fd device_fd
}; };
let device_id = let device_id = self.add_vfio_device(
self.add_vfio_device(&mut pci, &interrupt_manager, &device_fd, &device_cfg)?; &mut pci.lock().unwrap(),
&interrupt_manager,
&device_fd,
&device_cfg,
)?;
// Update the PCIU bitmap // Update the PCIU bitmap
self.pci_devices_up |= 1 << (device_id >> 3); self.pci_devices_up |= 1 << (device_id >> 3);

View File

@ -621,7 +621,13 @@ impl Vm {
.start_boot_vcpus(entry_addr) .start_boot_vcpus(entry_addr)
.map_err(Error::CpuManager)?; .map_err(Error::CpuManager)?;
if self.device_manager.lock().unwrap().console().input_enabled() { if self
.device_manager
.lock()
.unwrap()
.console()
.input_enabled()
{
let console = self.device_manager.lock().unwrap().console().clone(); let console = self.device_manager.lock().unwrap().console().clone();
let signals = Signals::new(&[SIGWINCH, SIGINT, SIGTERM]); let signals = Signals::new(&[SIGWINCH, SIGINT, SIGTERM]);
match signals { match signals {
@ -660,7 +666,13 @@ impl Vm {
.read_raw(&mut out) .read_raw(&mut out)
.map_err(Error::Console)?; .map_err(Error::Console)?;
if self.device_manager.lock().unwrap().console().input_enabled() { if self
.device_manager
.lock()
.unwrap()
.console()
.input_enabled()
{
self.device_manager self.device_manager
.lock() .lock()
.unwrap() .unwrap()