hvlite_helpers/
underhill.rs1use anyhow::Context;
7use get_resources::ged::GuestEmulationRequest;
8use get_resources::ged::GuestServicingFlags;
9use hvlite_defs::rpc::VmRpc;
10use mesh::rpc::RpcSend;
11
12pub async fn save_underhill(
14 vm_send: &mesh::Sender<VmRpc>,
15 send: &mesh::Sender<GuestEmulationRequest>,
16 flags: GuestServicingFlags,
17 file: std::fs::File,
18) -> anyhow::Result<()> {
19 tracing::debug!("staging new IGVM file");
21 vm_send
22 .call_failable(VmRpc::StartReloadIgvm, file)
23 .await
24 .context("failed to stage new IGVM file")?;
25
26 tracing::debug!("waiting for guest to send saved state");
31 let r = send
32 .call_failable(GuestEmulationRequest::SaveGuestVtl2State, flags)
33 .await
34 .context("failed to save VTL2 state");
35
36 if r.is_err() {
37 tracing::debug!(?r, "save state failed, clearing staged IGVM file");
39 let _ = vm_send.call(VmRpc::CompleteReloadIgvm, false).await;
40 }
41
42 r
43}
44
45pub async fn restore_underhill(
47 vm_send: &mesh::Sender<VmRpc>,
48 send: &mesh::Sender<GuestEmulationRequest>,
49) -> anyhow::Result<()> {
50 tracing::debug!("reloading IGVM file");
52 vm_send
53 .call_failable(VmRpc::CompleteReloadIgvm, true)
54 .await
55 .context("failed to reload VTL2 firmware")?;
56
57 tracing::debug!("waiting for VTL0 to start");
61 send.call_failable(GuestEmulationRequest::WaitForVtl0Start, ())
62 .await
63 .context("vtl0 start failed")?;
64
65 Ok(())
66}