From e514b124ed96e91c53fe4bd4be1296e2e41cbd69 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Mon, 9 Mar 2020 14:26:03 +0100 Subject: [PATCH] vmm: Update VmConfig when removing VFIO device This commit ensures that when a VFIO device is hot-unplugged from the VM, it is also removed from the VmConfig. This prevents a potential reboot from creating the device. Signed-off-by: Sebastien Boeuf --- vmm/src/vm.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index a4898df18..eece98817 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -584,9 +584,24 @@ impl Vm { self.device_manager .lock() .unwrap() - .remove_device(_id) + .remove_device(_id.clone()) .map_err(Error::DeviceManager)?; + // Update VmConfig by removing the device. This is important to + // ensure the device would not be created in case of a reboot. + { + let mut config = self.config.lock().unwrap(); + if let Some(devices) = config.devices.as_mut() { + devices.retain(|dev| { + if let Some(dev_id) = &dev.id { + *dev_id != _id + } else { + true + } + }); + } + } + self.device_manager .lock() .unwrap()