vmm: api: Introduce new "remove-device" HTTP endpoint

This commit introduces the new command "remove-device" that will let a
user hot-unplug a VFIO PCI device from an already running VM.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2020-03-09 11:49:15 +01:00
committed by Rob Bradford
parent 991f3bb5da
commit 6cbdb9aa47
8 changed files with 175 additions and 17 deletions

View File

@@ -236,6 +236,10 @@ pub enum DeviceManagerError {
/// Failed removing a bus device from the MMIO bus.
RemoveDeviceFromMmioBus(devices::BusError),
/// Failed to find VFIO device corresponding to the given identifier.
#[cfg(feature = "pci_support")]
UnknownVfioDeviceId(String),
}
pub type DeviceManagerResult<T> = result::Result<T, DeviceManagerError>;
@@ -1791,6 +1795,18 @@ impl DeviceManager {
Ok(device_cfg)
}
#[cfg(feature = "pci_support")]
pub fn remove_device(&mut self, id: String) -> DeviceManagerResult<()> {
if let Some(pci_device_bdf) = self.pci_id_list.get(&id) {
// Update the PCID bitmap
self.pci_devices_down |= 1 << (*pci_device_bdf >> 3);
Ok(())
} else {
Err(DeviceManagerError::UnknownVfioDeviceId(id))
}
}
#[cfg(feature = "pci_support")]
pub fn eject_device(&mut self, device_id: u8) -> DeviceManagerResult<()> {
// Retrieve the PCI bus.