Skip to main content

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    ///
35    /// Waits for the guest acknowledgment, not completion of the power-state change.
36    /// Stopping the caller's wait does not withdraw a command already sent to the
37    /// guest. The device continues waiting for acknowledgment and rejects further
38    /// shutdown requests with [`ShutdownResult::AlreadyInProgress`].
39    Shutdown(Rpc<ShutdownParams, ShutdownResult>),
40}
41
42/// Guest shutdown parameters.
43#[derive(Debug, MeshPayload)]
44pub struct ShutdownParams {
45    /// The type of power state change.
46    pub shutdown_type: ShutdownType,
47    /// Whether to force a shutdown.
48    pub force: bool,
49}
50
51/// The shutdown type.
52#[derive(Debug, MeshPayload)]
53pub enum ShutdownType {
54    /// Power off the VM.
55    PowerOff,
56    /// Reboot the VM.
57    Reboot,
58    /// Hibernate the VM.
59    Hibernate,
60}
61
62/// The result of a shutdown request.
63#[derive(MeshPayload, Debug, PartialEq)]
64pub enum ShutdownResult {
65    /// The shutdown has been initiated.
66    Ok,
67    /// The IC is not ready to send shutdown requests.
68    NotReady,
69    /// A shutdown is already in progress.
70    AlreadyInProgress,
71    /// The shutdown failed with the given error code.
72    Failed(u32),
73}