vmm: api: Add "power-button" API entry point

This will lead to the triggering of an ACPI button inside the guest in
order to cleanly shutdown the guest.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2021-01-13 10:06:36 +00:00
parent 843a010163
commit 981bb72a09
4 changed files with 44 additions and 3 deletions

View File

@@ -146,6 +146,9 @@ pub enum ApiError {
/// Error starting migration sender
VmSendMigration(MigratableError),
/// Error triggering power button
VmPowerButton(VmError),
}
pub type ApiResult<T> = std::result::Result<T, ApiError>;
@@ -302,6 +305,9 @@ pub enum ApiRequest {
/// Outgoing migration
VmSendMigration(Arc<VmSendMigrationData>, Sender<ApiResponse>),
// Trigger power button
VmPowerButton(Sender<ApiResponse>),
}
pub fn vm_create(
@@ -385,6 +391,9 @@ pub enum VmAction {
/// Outgoing migration
SendMigration(Arc<VmSendMigrationData>),
/// Power Button for clean shutdown
PowerButton,
}
fn vm_action(
@@ -416,6 +425,7 @@ fn vm_action(
Snapshot(v) => ApiRequest::VmSnapshot(v, response_sender),
ReceiveMigration(v) => ApiRequest::VmReceiveMigration(v, response_sender),
SendMigration(v) => ApiRequest::VmSendMigration(v, response_sender),
PowerButton => ApiRequest::VmPowerButton(response_sender),
};
// Send the VM request.
@@ -459,6 +469,13 @@ pub fn vm_counters(api_evt: EventFd, api_sender: Sender<ApiRequest>) -> ApiResul
vm_action(api_evt, api_sender, VmAction::Counters)
}
pub fn vm_power_button(
api_evt: EventFd,
api_sender: Sender<ApiRequest>,
) -> ApiResult<Option<Body>> {
vm_action(api_evt, api_sender, VmAction::PowerButton)
}
pub fn vm_receive_migration(
api_evt: EventFd,
api_sender: Sender<ApiRequest>,