Skip to main content

openvmm_defs/
rpc.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! RPC types for communicating with the VM worker.
5
6use crate::config::DeviceVtl;
7use guid::Guid;
8use mesh::CancelContext;
9use mesh::MeshPayload;
10use mesh::error::RemoteError;
11use mesh::payload::message::ProtobufMessage;
12use mesh::rpc::FailableRpc;
13use mesh::rpc::Rpc;
14use std::fs::File;
15use vm_resource::Resource;
16use vm_resource::kind::PciDeviceHandleKind;
17use vm_resource::kind::VmbusDeviceHandleKind;
18
19#[derive(MeshPayload)]
20pub enum VmRpc {
21    Save(FailableRpc<(), ProtobufMessage>),
22    Resume(Rpc<(), bool>),
23    Pause(Rpc<(), bool>),
24    ClearHalt(Rpc<(), bool>),
25    Reset(FailableRpc<(), ()>),
26    Nmi(Rpc<u32, ()>),
27    AddVmbusDevice(FailableRpc<(DeviceVtl, Resource<VmbusDeviceHandleKind>), ()>),
28    ConnectHvsock(FailableRpc<(CancelContext, Guid, DeviceVtl), unix_socket::UnixStream>),
29    AddHvsockListener(FailableRpc<(DeviceVtl, Guid, unix_socket::UnixListener), ()>),
30    RemoveHvsockListener(FailableRpc<(DeviceVtl, Guid), ()>),
31    PulseSaveRestore(Rpc<(), Result<(), PulseSaveRestoreError>>),
32    StartReloadIgvm(FailableRpc<File, ()>),
33    CompleteReloadIgvm(FailableRpc<bool, ()>),
34    ReadMemory(FailableRpc<(u64, usize), Vec<u8>>),
35    WriteMemory(FailableRpc<(u64, Vec<u8>), ()>),
36    /// Updates the command line parameters that will be passed to the boot shim
37    /// on the *next* VM load. This will replace the existing command line parameters.
38    UpdateCliParams(FailableRpc<String, ()>),
39    /// Hot-add a PCIe device to a named port at runtime.
40    /// Tuple is (port_name, device_resource).
41    AddPcieDevice(FailableRpc<(String, Resource<PciDeviceHandleKind>), ()>),
42    /// Hot-remove a PCIe device from a named port at runtime.
43    RemovePcieDevice(FailableRpc<String, ()>),
44    /// Request orderly ACPI ejection and wait for host cleanup.
45    EjectPcieDevice(FailableRpc<(String, std::time::Duration), ()>),
46    /// Hot-add a VPCI device to VTL0 at runtime with the supplied instance ID.
47    AddVpciDevice(FailableRpc<(Guid, Resource<PciDeviceHandleKind>), ()>),
48    /// Hot-remove a dynamically added VPCI device by instance ID.
49    RemoveVpciDevice(FailableRpc<Guid, ()>),
50    /// Dump VM state (VP registers + memory) to a `.vmrs` file.
51    ///
52    /// The worker pauses the VM internally, collects state, and restores
53    /// the prior running state afterward. The caller provides an open file
54    /// handle to write to (typically a temporary file that gets renamed
55    /// into place on success).
56    DumpState(FailableRpc<File, ()>),
57}
58
59#[derive(Debug, MeshPayload, thiserror::Error)]
60pub enum PulseSaveRestoreError {
61    #[error("reset not supported")]
62    ResetNotSupported,
63    #[error("pulse save+restore failed")]
64    Other(#[source] RemoteError),
65}
66
67impl From<anyhow::Error> for PulseSaveRestoreError {
68    fn from(err: anyhow::Error) -> Self {
69        Self::Other(RemoteError::new(err))
70    }
71}