diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 97de78db0..813fe6b43 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -366,6 +366,9 @@ pub enum DeviceManagerError { /// Missing virtio-balloon, can't proceed as expected. MissingVirtioBalloon, + + /// Failed to do power button notification + PowerButtonNotification(io::Error), } pub type DeviceManagerResult = result::Result; @@ -3177,6 +3180,18 @@ impl DeviceManager { pub fn device_tree(&self) -> Arc> { self.device_tree.clone() } + + #[cfg(feature = "acpi")] + pub fn notify_power_button(&self) -> DeviceManagerResult<()> { + return self + .ged_notification_device + .as_ref() + .unwrap() + .lock() + .unwrap() + .notify(AcpiNotificationFlags::POWER_BUTTON_CHANGED) + .map_err(DeviceManagerError::PowerButtonNotification); + } } #[cfg(feature = "acpi")] diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 76845d594..a2df724ba 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -234,6 +234,12 @@ pub enum Error { /// Cannot activate virtio devices ActivateVirtioDevices(device_manager::DeviceManagerError), + + /// Power button not supported + PowerButtonNotSupported, + + /// Error triggering power button + PowerButton(device_manager::DeviceManagerError), } pub type Result = result::Result; @@ -1762,6 +1768,18 @@ impl Vm { .activate_virtio_devices() .map_err(Error::ActivateVirtioDevices) } + + pub fn power_button(&self) -> Result<()> { + #[cfg(feature = "acpi")] + return self + .device_manager + .lock() + .unwrap() + .notify_power_button() + .map_err(Error::PowerButton); + #[cfg(not(feature = "acpi"))] + Err(Error::PowerButtonNotSupported) + } } impl Pausable for Vm {