hyperv_ic_resources/
shutdown.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Resource definitions for the shutdown IC.
5
6use mesh::MeshPayload;
7use mesh::rpc::Rpc;
8use vm_resource::ResourceId;
9use vm_resource::kind::VmbusDeviceHandleKind;
10
11/// A handle to a shutdown IC.
12#[derive(MeshPayload)]
13pub struct ShutdownIcHandle {
14    /// The channel by which to receive shutdown requests.
15    pub recv: mesh::Receiver<ShutdownRpc>,
16}
17
18impl ResourceId<VmbusDeviceHandleKind> for ShutdownIcHandle {
19    const ID: &'static str = "shutdown_ic";
20}
21
22/// An RPC request to the shutdown IC.
23#[derive(MeshPayload)]
24pub enum ShutdownRpc {
25    /// Wait for the shutdown IC to be ready.
26    ///
27    /// Returns a receiver that closes when the IC is no longer ready.
28    ///
29    /// FUTURE: this should instead be a `Sender` that is used to send the
30    /// shutdown request. Do this once `Sender` has a mechanism to wait on the
31    /// receiver to be closed.
32    WaitReady(Rpc<(), mesh::OneshotReceiver<()>>),
33    /// Send a shutdown request to the guest.
34    Shutdown(Rpc<ShutdownParams, ShutdownResult>),
35}
36
37/// Guest shutdown parameters.
38#[derive(Debug, MeshPayload)]
39pub struct ShutdownParams {
40    /// The type of power state change.
41    pub shutdown_type: ShutdownType,
42    /// Whether to force a shutdown.
43    pub force: bool,
44}
45
46/// The shutdown type.
47#[derive(Debug, MeshPayload)]
48pub enum ShutdownType {
49    /// Power off the VM.
50    PowerOff,
51    /// Reboot the VM.
52    Reboot,
53    /// Hibernate the VM.
54    Hibernate,
55}
56
57/// The result of a shutdown request.
58#[derive(MeshPayload, Debug, PartialEq)]
59pub enum ShutdownResult {
60    /// The shutdown has been initiated.
61    Ok,
62    /// The IC is not ready to send shutdown requests.
63    NotReady,
64    /// A shutdown is already in progress.
65    AlreadyInProgress,
66    /// The shutdown failed with the given error code.
67    Failed(u32),
68}