diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 53acc7df1..3dfbe1239 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -2855,7 +2855,12 @@ impl Snapshottable for DeviceManager { ))); } - // Then restore all devices associated with the DeviceManager. + // Now that DeviceManager is updated with the right states, it's time + // to create the devices based on the configuration. + self.create_devices() + .map_err(|e| MigratableError::Restore(anyhow!("Could not create devices {:?}", e)))?; + + // Finally, restore all devices associated with the DeviceManager. // It's important to restore devices in the right order, that's why // the device tree is the right way to ensure we restore a child before // its parent node. diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 6e1ce9e13..a739e180f 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -334,12 +334,6 @@ impl Vm { ) .map_err(Error::DeviceManager)?; - device_manager - .lock() - .unwrap() - .create_devices() - .map_err(Error::DeviceManager)?; - let cpu_manager = cpu::CpuManager::new( &config.lock().unwrap().cpus.clone(), &device_manager, @@ -392,7 +386,7 @@ impl Vm { ) .map_err(Error::MemoryManager)?; - Vm::new_from_memory_manager( + let vm = Vm::new_from_memory_manager( config, memory_manager, fd, @@ -400,7 +394,17 @@ impl Vm { exit_evt, reset_evt, vmm_path, - ) + )?; + + // The device manager must create the devices from here as it is part + // of the regular code path creating everything from scratch. + vm.device_manager + .lock() + .unwrap() + .create_devices() + .map_err(Error::DeviceManager)?; + + Ok(vm) } pub fn new_from_snapshot(