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

This commit introduces the new command "add-device" that will let a user
hotplug a VFIO PCI device to an already running VM.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2020-02-27 14:00:46 +01:00
committed by Rob Bradford
parent 0f1396acef
commit 0e58741a09
7 changed files with 134 additions and 4 deletions

View File

@@ -99,6 +99,9 @@ pub enum ApiError {
/// The VM could not be resized
VmResize(VmError),
/// The device could not be added to the VM.
VmAddDevice(VmError),
}
pub type ApiResult<T> = std::result::Result<T, ApiError>;
@@ -119,6 +122,11 @@ pub struct VmResizeData {
pub desired_ram: Option<u64>,
}
#[derive(Clone, Deserialize, Serialize)]
pub struct VmAddDeviceData {
pub path: String,
}
pub enum ApiResponsePayload {
/// No data is sent on the channel.
Empty,
@@ -179,8 +187,11 @@ pub enum ApiRequest {
/// VMM process.
VmmShutdown(Sender<ApiResponse>),
/// Resize the VMM
/// Resize the VM.
VmResize(Arc<VmResizeData>, Sender<ApiResponse>),
/// Add a device to the VM.
VmAddDevice(Arc<VmAddDeviceData>, Sender<ApiResponse>),
}
pub fn vm_create(
@@ -333,3 +344,21 @@ pub fn vm_resize(
Ok(())
}
pub fn vm_add_device(
api_evt: EventFd,
api_sender: Sender<ApiRequest>,
data: Arc<VmAddDeviceData>,
) -> ApiResult<()> {
let (response_sender, response_receiver) = channel();
// Send the VM add-device request.
api_sender
.send(ApiRequest::VmAddDevice(data, response_sender))
.map_err(ApiError::RequestSend)?;
api_evt.write(1).map_err(ApiError::EventFdWrite)?;
response_receiver.recv().map_err(ApiError::ResponseRecv)??;
Ok(())
}