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 <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-03-09 14:26:03 +01:00 committed by Rob Bradford
parent 81173bf4ab
commit e514b124ed

View File

@ -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()