vmm: Remove all Weak references from DeviceManager

Now that the BusDevice devices are stored as Weak references by the
IO and MMIO buses, there's no need to use Weak references from the
DeviceManager anymore.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2020-03-04 16:24:15 +01:00
parent 9e915a0284
commit 2dbb376175
2 changed files with 7 additions and 26 deletions
+1 -1
View File
@@ -507,7 +507,7 @@ impl CpuManager {
let cpu_manager = Arc::new(Mutex::new(CpuManager { let cpu_manager = Arc::new(Mutex::new(CpuManager {
boot_vcpus, boot_vcpus,
max_vcpus, max_vcpus,
io_bus: device_manager.io_bus(), io_bus: device_manager.io_bus().clone(),
mmio_bus: device_manager.mmio_bus().clone(), mmio_bus: device_manager.mmio_bus().clone(),
ioapic: device_manager.ioapic().clone(), ioapic: device_manager.ioapic().clone(),
vm_memory: guest_memory, vm_memory: guest_memory,
+6 -25
View File
@@ -39,7 +39,6 @@ use std::io::{self, sink, stdout};
use std::os::unix::fs::OpenOptionsExt; use std::os::unix::fs::OpenOptionsExt;
use std::path::PathBuf; use std::path::PathBuf;
use std::result; use std::result;
use std::sync::Weak;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use tempfile::NamedTempFile; use tempfile::NamedTempFile;
#[cfg(feature = "pci_support")] #[cfg(feature = "pci_support")]
@@ -277,7 +276,7 @@ impl Console {
struct AddressManager { struct AddressManager {
allocator: Arc<Mutex<SystemAllocator>>, allocator: Arc<Mutex<SystemAllocator>>,
io_bus: Weak<devices::Bus>, io_bus: Arc<devices::Bus>,
mmio_bus: Arc<devices::Bus>, mmio_bus: Arc<devices::Bus>,
vm_fd: Arc<VmFd>, vm_fd: Arc<VmFd>,
} }
@@ -310,8 +309,6 @@ impl DeviceRelocation for AddressManager {
// Update PIO bus // Update PIO bus
self.io_bus self.io_bus
.upgrade()
.unwrap()
.update_range(old_base, len, new_base, len) .update_range(old_base, len, new_base, len)
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
} }
@@ -489,7 +486,7 @@ impl DeviceManager {
let address_manager = Arc::new(AddressManager { let address_manager = Arc::new(AddressManager {
allocator, allocator,
io_bus: Arc::downgrade(io_bus), io_bus: Arc::clone(io_bus),
mmio_bus: Arc::new(devices::Bus::new()), mmio_bus: Arc::new(devices::Bus::new()),
vm_fd: vm_fd.clone(), vm_fd: vm_fd.clone(),
}); });
@@ -535,8 +532,6 @@ impl DeviceManager {
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
address_manager address_manager
.io_bus .io_bus
.upgrade()
.unwrap()
.insert(memory_manager.clone(), 0xa00, 0x18) .insert(memory_manager.clone(), 0xa00, 0x18)
.map_err(DeviceManagerError::BusError)?; .map_err(DeviceManagerError::BusError)?;
@@ -608,8 +603,6 @@ impl DeviceManager {
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
address_manager address_manager
.io_bus .io_bus
.upgrade()
.unwrap()
.insert( .insert(
Arc::clone(&device_manager) as Arc<Mutex<dyn BusDevice>>, Arc::clone(&device_manager) as Arc<Mutex<dyn BusDevice>>,
0xae00, 0xae00,
@@ -685,8 +678,6 @@ impl DeviceManager {
.push(Arc::clone(&pci_config_io) as Arc<Mutex<dyn BusDevice>>); .push(Arc::clone(&pci_config_io) as Arc<Mutex<dyn BusDevice>>);
self.address_manager self.address_manager
.io_bus .io_bus
.upgrade()
.unwrap()
.insert(pci_config_io, 0xcf8, 0x8) .insert(pci_config_io, 0xcf8, 0x8)
.map_err(DeviceManagerError::BusError)?; .map_err(DeviceManagerError::BusError)?;
let pci_config_mmio = Arc::new(Mutex::new(PciConfigMmio::new(Arc::clone(&pci_bus)))); let pci_config_mmio = Arc::new(Mutex::new(PciConfigMmio::new(Arc::clone(&pci_bus))));
@@ -774,8 +765,6 @@ impl DeviceManager {
self.address_manager self.address_manager
.io_bus .io_bus
.upgrade()
.unwrap()
.insert(acpi_device, 0x3c0, 0x4) .insert(acpi_device, 0x3c0, 0x4)
.map_err(DeviceManagerError::BusError)?; .map_err(DeviceManagerError::BusError)?;
@@ -810,8 +799,6 @@ impl DeviceManager {
self.address_manager self.address_manager
.io_bus .io_bus
.upgrade()
.unwrap()
.insert(ged_device.clone(), 0xb000, 0x1) .insert(ged_device.clone(), 0xb000, 0x1)
.map_err(DeviceManagerError::BusError)?; .map_err(DeviceManagerError::BusError)?;
Ok(Some(ged_device)) Ok(Some(ged_device))
@@ -826,8 +813,6 @@ impl DeviceManager {
self.address_manager self.address_manager
.io_bus .io_bus
.upgrade()
.unwrap()
.insert(i8042, 0x61, 0x4) .insert(i8042, 0x61, 0x4)
.map_err(DeviceManagerError::BusError)?; .map_err(DeviceManagerError::BusError)?;
#[cfg(feature = "cmos")] #[cfg(feature = "cmos")]
@@ -856,8 +841,6 @@ impl DeviceManager {
self.address_manager self.address_manager
.io_bus .io_bus
.upgrade()
.unwrap()
.insert(cmos, 0x70, 0x2) .insert(cmos, 0x70, 0x2)
.map_err(DeviceManagerError::BusError)?; .map_err(DeviceManagerError::BusError)?;
} }
@@ -906,8 +889,6 @@ impl DeviceManager {
self.address_manager self.address_manager
.io_bus .io_bus
.upgrade()
.unwrap()
.insert(serial.clone(), 0x3f8, 0x8) .insert(serial.clone(), 0x3f8, 0x8)
.map_err(DeviceManagerError::BusError)?; .map_err(DeviceManagerError::BusError)?;
@@ -1476,7 +1457,7 @@ impl DeviceManager {
pci.register_mapping( pci.register_mapping(
vfio_pci_device, vfio_pci_device,
self.address_manager.io_bus.upgrade().unwrap().as_ref(), self.address_manager.io_bus.as_ref(),
self.address_manager.mmio_bus.as_ref(), self.address_manager.mmio_bus.as_ref(),
bars, bars,
) )
@@ -1585,7 +1566,7 @@ impl DeviceManager {
pci.register_mapping( pci.register_mapping(
virtio_pci_device.clone(), virtio_pci_device.clone(),
self.address_manager.io_bus.upgrade().unwrap().as_ref(), self.address_manager.io_bus.as_ref(),
self.address_manager.mmio_bus.as_ref(), self.address_manager.mmio_bus.as_ref(),
bars, bars,
) )
@@ -1659,8 +1640,8 @@ impl DeviceManager {
Ok(()) Ok(())
} }
pub fn io_bus(&self) -> Arc<devices::Bus> { pub fn io_bus(&self) -> &Arc<devices::Bus> {
Arc::clone(&self.address_manager.io_bus.upgrade().unwrap()) &self.address_manager.io_bus
} }
pub fn mmio_bus(&self) -> &Arc<devices::Bus> { pub fn mmio_bus(&self) -> &Arc<devices::Bus> {