Skip to content

Refactor Snapshot Module #5195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix issues with src/snapshot-editor/src/utils.rs
Signed-off-by: Gabriel Keller <[email protected]>
  • Loading branch information
beamandala authored and gjkeller committed May 7, 2025
commit 86eae9ccd8e0adf0123c16893b904be443e8856c
13 changes: 8 additions & 5 deletions src/snapshot-editor/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::path::PathBuf;
use fc_utils::u64_to_usize;
use semver::Version;
use vmm::persist::MicrovmState;
use vmm::snapshot::Snapshot;
use vmm::snapshot::{Snapshot, SnapshotError, SnapshotHdr};

// Some errors are only used in aarch64 code
#[allow(unused)]
Expand All @@ -26,11 +26,13 @@ pub enum UtilsError {
}

#[allow(unused)]
pub fn open_vmstate(snapshot_path: &PathBuf) -> Result<(MicrovmState, Version), UtilsError> {
pub fn open_vmstate(snapshot_path: &PathBuf) -> Result<Snapshot<MicrovmState>, UtilsError> {
let mut snapshot_reader = File::open(snapshot_path).map_err(UtilsError::VmStateFileOpen)?;
let metadata = std::fs::metadata(snapshot_path).map_err(UtilsError::VmStateFileMeta)?;
let snapshot_len = u64_to_usize(metadata.len());
Snapshot::load(&mut snapshot_reader, snapshot_len).map_err(UtilsError::VmStateLoad)

let snapshot: Result<Snapshot<MicrovmState>, UtilsError> = Snapshot::load(&mut snapshot_reader, snapshot_len).map_err(UtilsError::VmStateLoad);
snapshot
}

// This method is used only in aarch64 code so far
Expand All @@ -46,9 +48,10 @@ pub fn save_vmstate(
.truncate(true)
.open(output_path)
.map_err(UtilsError::OutputFileOpen)?;
let mut snapshot = Snapshot::new(version);
let snapshot_hdr = SnapshotHdr::new(version);
let snapshot = Snapshot::new(snapshot_hdr, microvm_state);
snapshot
.save(&mut output_file, &microvm_state)
.save(&mut output_file)
.map_err(UtilsError::VmStateSave)?;
Ok(())
}