vmm: api: Add a VMM shutdown command

This shuts the current VM down, if any, and then exits the VMM process.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz
2019-10-08 15:23:29 +02:00
committed by Sebastien Boeuf
parent 228adebc32
commit a95fa1c4e8
5 changed files with 80 additions and 11 deletions

View File

@@ -87,6 +87,9 @@ pub enum ApiError {
/// The VM could not reboot.
VmReboot(VmError),
/// The VMM could not shutdown.
VmmShutdown(VmError),
}
pub type ApiResult<T> = std::result::Result<T, ApiError>;
@@ -138,6 +141,11 @@ pub enum ApiRequest {
/// If the VM was not previously booted or created, the VMM API server
/// will send a VmReboot error back.
VmReboot(Sender<ApiResponse>),
/// Shut the VMM down.
/// This will shutdown and delete the current VM, if any, and then exit the
/// VMM process.
VmmShutdown(Sender<ApiResponse>),
}
pub fn vm_create(
@@ -226,3 +234,17 @@ pub fn vm_info(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<Vm
_ => Err(ApiError::ResponsePayloadType),
}
}
pub fn vmm_shutdown(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResult<()> {
let (response_sender, response_receiver) = channel();
// Send the VMM shutdown request.
api_sender
.send(ApiRequest::VmmShutdown(response_sender))
.map_err(ApiError::RequestSend)?;
api_evt.write(1).map_err(ApiError::EventFdWrite)?;
response_receiver.recv().map_err(ApiError::ResponseRecv)??;
Ok(())
}