mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
committed by
Rob Bradford
parent
991f3bb5da
commit
6cbdb9aa47
@@ -102,6 +102,9 @@ pub enum ApiError {
|
||||
|
||||
/// The device could not be added to the VM.
|
||||
VmAddDevice(VmError),
|
||||
|
||||
/// The device could not be removed from the VM.
|
||||
VmRemoveDevice(VmError),
|
||||
}
|
||||
pub type ApiResult<T> = std::result::Result<T, ApiError>;
|
||||
|
||||
@@ -127,6 +130,11 @@ pub struct VmAddDeviceData {
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Deserialize, Serialize)]
|
||||
pub struct VmRemoveDeviceData {
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
pub enum ApiResponsePayload {
|
||||
/// No data is sent on the channel.
|
||||
Empty,
|
||||
@@ -192,6 +200,9 @@ pub enum ApiRequest {
|
||||
|
||||
/// Add a device to the VM.
|
||||
VmAddDevice(Arc<VmAddDeviceData>, Sender<ApiResponse>),
|
||||
|
||||
/// Remove a device from the VM.
|
||||
VmRemoveDevice(Arc<VmRemoveDeviceData>, Sender<ApiResponse>),
|
||||
}
|
||||
|
||||
pub fn vm_create(
|
||||
@@ -362,3 +373,21 @@ pub fn vm_add_device(
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn vm_remove_device(
|
||||
api_evt: EventFd,
|
||||
api_sender: Sender<ApiRequest>,
|
||||
data: Arc<VmRemoveDeviceData>,
|
||||
) -> ApiResult<()> {
|
||||
let (response_sender, response_receiver) = channel();
|
||||
|
||||
// Send the VM remove-device request.
|
||||
api_sender
|
||||
.send(ApiRequest::VmRemoveDevice(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