From 49268bff3be87754b34478e33e4a4e8aab8b4b57 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Wed, 4 Mar 2020 16:10:11 +0100 Subject: [PATCH] pci: Remove all Weak references from PciBus 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 PciBus anymore. Signed-off-by: Sebastien Boeuf --- pci/src/bus.rs | 10 +++++----- vmm/src/device_manager.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pci/src/bus.rs b/pci/src/bus.rs index e04d81ec5..3ee9a3402 100644 --- a/pci/src/bus.rs +++ b/pci/src/bus.rs @@ -11,7 +11,7 @@ use devices::BusDevice; use std; use std::any::Any; use std::ops::DerefMut; -use std::sync::{Arc, Mutex, Weak}; +use std::sync::{Arc, Mutex}; use vm_memory::{Address, GuestAddress, GuestUsize}; const VENDOR_ID_INTEL: u16 = 0x8086; @@ -80,11 +80,11 @@ pub struct PciBus { /// Devices attached to this bus. /// Device 0 is host bridge. devices: Vec>>, - device_reloc: Weak, + device_reloc: Arc, } impl PciBus { - pub fn new(pci_root: PciRoot, device_reloc: Weak) -> Self { + pub fn new(pci_root: PciRoot, device_reloc: Arc) -> Self { let mut devices: Vec>> = Vec::new(); devices.push(Arc::new(Mutex::new(pci_root))); @@ -197,7 +197,7 @@ impl PciConfigIo { // Find out if one of the device's BAR is being reprogrammed, and // reprogram it if needed. if let Some(params) = device.detect_bar_reprogramming(register, data) { - if let Err(e) = pci_bus.device_reloc.upgrade().unwrap().move_bar( + if let Err(e) = pci_bus.device_reloc.move_bar( params.old_base, params.new_base, params.len, @@ -313,7 +313,7 @@ impl PciConfigMmio { // Find out if one of the device's BAR is being reprogrammed, and // reprogram it if needed. if let Some(params) = device.detect_bar_reprogramming(register, data) { - if let Err(e) = pci_bus.device_reloc.upgrade().unwrap().move_bar( + if let Err(e) = pci_bus.device_reloc.move_bar( params.old_base, params.new_base, params.len, diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index fab4f64f6..722d0a3db 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -630,7 +630,7 @@ impl DeviceManager { let pci_root = PciRoot::new(None); let mut pci_bus = PciBus::new( pci_root, - Arc::downgrade(&self.address_manager) as Weak, + Arc::clone(&self.address_manager) as Arc, ); let (iommu_device, iommu_mapping) = if self.config.lock().unwrap().iommu {