mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Add support for hotplugging user devices
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
@@ -14,8 +14,8 @@
|
||||
#[cfg(any(target_arch = "aarch64", feature = "acpi"))]
|
||||
use crate::config::NumaConfig;
|
||||
use crate::config::{
|
||||
DeviceConfig, DiskConfig, FsConfig, HotplugMethod, NetConfig, PmemConfig, ValidationError,
|
||||
VmConfig, VsockConfig,
|
||||
DeviceConfig, DiskConfig, FsConfig, HotplugMethod, NetConfig, PmemConfig, UserDeviceConfig,
|
||||
ValidationError, VmConfig, VsockConfig,
|
||||
};
|
||||
use crate::cpu;
|
||||
use crate::device_manager::{
|
||||
@@ -1345,6 +1345,37 @@ impl Vm {
|
||||
Ok(pci_device_info)
|
||||
}
|
||||
|
||||
pub fn add_user_device(&mut self, mut device_cfg: UserDeviceConfig) -> Result<PciDeviceInfo> {
|
||||
{
|
||||
// Validate on a clone of the config
|
||||
let mut config = self.config.lock().unwrap().clone();
|
||||
Self::add_to_config(&mut config.user_devices, device_cfg.clone());
|
||||
config.validate().map_err(Error::ConfigValidation)?;
|
||||
}
|
||||
|
||||
let pci_device_info = self
|
||||
.device_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.add_user_device(&mut device_cfg)
|
||||
.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();
|
||||
Self::add_to_config(&mut config.user_devices, device_cfg);
|
||||
}
|
||||
|
||||
self.device_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.notify_hotplug(AcpiNotificationFlags::PCI_DEVICES_CHANGED)
|
||||
.map_err(Error::DeviceManager)?;
|
||||
|
||||
Ok(pci_device_info)
|
||||
}
|
||||
|
||||
pub fn remove_device(&mut self, _id: String) -> Result<()> {
|
||||
self.device_manager
|
||||
.lock()
|
||||
|
||||
Reference in New Issue
Block a user