Skip to content

Commit 72fda20

Browse files
committed
snapshot-editor: always create at current version
Have snapshot-editor always create a snapshot at the current version. We cannot load snapshots that have a different snapshot version than is supported by the running binary anyway (because strongly-typed deserialization would fail), so we statically know that the `version` parameter to `save_vmstate` is always `SNAPSHOT_VERSION`. Signed-off-by: Patrick Roy <[email protected]>
1 parent fbf50aa commit 72fda20

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

src/snapshot-editor/src/edit_vmstate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ fn edit(
5151
output_path: &PathBuf,
5252
f: impl Fn(MicrovmState) -> Result<MicrovmState, EditVmStateError>,
5353
) -> Result<(), EditVmStateError> {
54-
let (microvm_state, version) = open_vmstate(vmstate_path)?;
54+
let (microvm_state, _) = open_vmstate(vmstate_path)?;
5555
let microvm_state = f(microvm_state)?;
56-
save_vmstate(microvm_state, output_path, version)?;
56+
save_vmstate(microvm_state, output_path)?;
5757
Ok(())
5858
}
5959

src/snapshot-editor/src/utils.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fs::{File, OpenOptions};
55
use std::path::PathBuf;
66

77
use semver::Version;
8-
use vmm::persist::MicrovmState;
8+
use vmm::persist::{MicrovmState, SNAPSHOT_VERSION};
99
use vmm::snapshot::Snapshot;
1010
use vmm::utils::u64_to_usize;
1111

@@ -35,18 +35,14 @@ pub fn open_vmstate(snapshot_path: &PathBuf) -> Result<(MicrovmState, Version),
3535

3636
// This method is used only in aarch64 code so far
3737
#[allow(unused)]
38-
pub fn save_vmstate(
39-
microvm_state: MicrovmState,
40-
output_path: &PathBuf,
41-
version: Version,
42-
) -> Result<(), UtilsError> {
38+
pub fn save_vmstate(microvm_state: MicrovmState, output_path: &PathBuf) -> Result<(), UtilsError> {
4339
let mut output_file = OpenOptions::new()
4440
.create(true)
4541
.write(true)
4642
.truncate(true)
4743
.open(output_path)
4844
.map_err(UtilsError::OutputFileOpen)?;
49-
let mut snapshot = Snapshot::new(version);
45+
let mut snapshot = Snapshot::new(SNAPSHOT_VERSION);
5046
snapshot
5147
.save(&mut output_file, &microvm_state)
5248
.map_err(UtilsError::VmStateSave)?;

0 commit comments

Comments
 (0)