diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index f60af2019..7b8b1fca8 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -1648,7 +1648,7 @@ impl DeviceManager { } #[cfg(feature = "pci_support")] - pub fn add_device(&mut self, path: String) -> DeviceManagerResult<()> { + pub fn add_device(&mut self, path: String) -> DeviceManagerResult { let device_cfg = DeviceConfig { path: PathBuf::from(path), iommu: false, @@ -1680,7 +1680,7 @@ impl DeviceManager { // Update the PCIU bitmap self.pci_devices_up |= 1 << (device_id >> 3); - Ok(()) + Ok(device_cfg) } } diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index baf5de088..2f9def6be 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -547,19 +547,30 @@ impl Vm { if cfg!(feature = "pci_support") { #[cfg(feature = "pci_support")] { - self.devices + let device_cfg = self + .devices .lock() .unwrap() .add_device(_path) .map_err(Error::DeviceManager)?; + // Update VmConfig by adding the new device. This is important to + // ensure the device would be created in case of a reboot. + { + let mut config = self.config.lock().unwrap(); + if let Some(devices) = config.devices.as_mut() { + devices.push(device_cfg); + } else { + config.devices = Some(vec![device_cfg]); + } + } + self.devices .lock() .unwrap() .notify_hotplug(HotPlugNotificationFlags::PCI_DEVICES_CHANGED) .map_err(Error::DeviceManager)?; } - Ok(()) } else { Err(Error::NoPciSupport)