mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Update VmConfig when adding new device
Ensures the configuration is updated after a new device has been hotplugged. In the event of a reboot, this means the new VM will be started with the new device that had been previously hotplugged. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
committed by
Rob Bradford
parent
a86f4369a7
commit
c1af13efeb
@@ -1648,7 +1648,7 @@ impl DeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "pci_support")]
|
#[cfg(feature = "pci_support")]
|
||||||
pub fn add_device(&mut self, path: String) -> DeviceManagerResult<()> {
|
pub fn add_device(&mut self, path: String) -> DeviceManagerResult<DeviceConfig> {
|
||||||
let device_cfg = DeviceConfig {
|
let device_cfg = DeviceConfig {
|
||||||
path: PathBuf::from(path),
|
path: PathBuf::from(path),
|
||||||
iommu: false,
|
iommu: false,
|
||||||
@@ -1680,7 +1680,7 @@ impl DeviceManager {
|
|||||||
// Update the PCIU bitmap
|
// Update the PCIU bitmap
|
||||||
self.pci_devices_up |= 1 << (device_id >> 3);
|
self.pci_devices_up |= 1 << (device_id >> 3);
|
||||||
|
|
||||||
Ok(())
|
Ok(device_cfg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -547,19 +547,30 @@ impl Vm {
|
|||||||
if cfg!(feature = "pci_support") {
|
if cfg!(feature = "pci_support") {
|
||||||
#[cfg(feature = "pci_support")]
|
#[cfg(feature = "pci_support")]
|
||||||
{
|
{
|
||||||
self.devices
|
let device_cfg = self
|
||||||
|
.devices
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.add_device(_path)
|
.add_device(_path)
|
||||||
.map_err(Error::DeviceManager)?;
|
.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
|
self.devices
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.notify_hotplug(HotPlugNotificationFlags::PCI_DEVICES_CHANGED)
|
.notify_hotplug(HotPlugNotificationFlags::PCI_DEVICES_CHANGED)
|
||||||
.map_err(Error::DeviceManager)?;
|
.map_err(Error::DeviceManager)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
Err(Error::NoPciSupport)
|
Err(Error::NoPciSupport)
|
||||||
|
|||||||
Reference in New Issue
Block a user