vmm: Break the cyclic dependency between DeviceManager and IO bus

By inserting the DeviceManager on the IO bus, we introduced some cyclic
dependency:

  DeviceManager ---> AddressManager ---> Bus ---> BusDevice
        ^                                             |
        |                                             |
        +---------------------------------------------+

This cycle needs to be broken by inserting a Weak reference instead of
an Arc (considered as a strong reference).

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2020-02-28 18:11:34 +01:00
committed by Rob Bradford
parent c1af13efeb
commit d47f733e51
3 changed files with 34 additions and 12 deletions
+6
View File
@@ -222,6 +222,8 @@ pub struct Vm {
state: RwLock<VmState>,
cpu_manager: Arc<Mutex<cpu::CpuManager>>,
memory_manager: Arc<Mutex<MemoryManager>>,
// Hold the strong reference onto the IO bus.
_io_bus: Arc<devices::Bus>,
}
impl Vm {
@@ -329,6 +331,8 @@ impl Vm {
.ok_or(Error::CreateSystemAllocator)?,
));
let io_bus = Arc::new(devices::Bus::new());
let memory_config = config.lock().unwrap().memory.clone();
let memory_manager = MemoryManager::new(
@@ -351,6 +355,7 @@ impl Vm {
&exit_evt,
&reset_evt,
vmm_path,
&io_bus,
)
.map_err(Error::DeviceManager)?;
@@ -379,6 +384,7 @@ impl Vm {
state: RwLock::new(VmState::Created),
cpu_manager,
memory_manager,
_io_bus: io_bus,
})
}