mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
committed by
Rob Bradford
parent
0f1396acef
commit
0e58741a09
@@ -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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user