Skip to main content

openvmm_helpers/snapshot/
restore.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Reading VM snapshots from a directory.
5
6use super::SnapshotManifest;
7use anyhow::Context;
8use std::path::Path;
9
10/// Read a snapshot from the given directory.
11///
12/// Returns the decoded manifest and the raw saved-state bytes.
13/// The caller is responsible for opening `memory.bin` separately.
14pub fn read_snapshot(dir: &Path) -> anyhow::Result<(SnapshotManifest, Vec<u8>)> {
15    let manifest_bytes =
16        fs_err::read(dir.join("manifest.bin")).context("failed to read manifest.bin")?;
17    let manifest: SnapshotManifest =
18        mesh::payload::decode(&manifest_bytes).context("failed to decode snapshot manifest")?;
19
20    let state_bytes = fs_err::read(dir.join("state.bin")).context("failed to read state.bin")?;
21
22    Ok((manifest, state_bytes))
23}