Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions src/vmm/src/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,12 @@ pub fn create_snapshot(

snapshot_state_to_file(&microvm_state, &params.snapshot_path)?;

vmm.vm
.snapshot_memory_to_file(&params.mem_file_path, params.snapshot_type)?;
// Skip memory file dumping if mem_file_path is "/dev/null"
// Note: This doesn't actually write to /dev/null - the dump is skipped entirely
if params.mem_file_path.to_string_lossy() != "/dev/null" {
vmm.vm
.snapshot_memory_to_file(&params.mem_file_path, params.snapshot_type)?;
}

// We need to mark queues as dirty again for all activated devices. The reason we
// do it here is because we don't mark pages as dirty during runtime
Expand Down
10 changes: 7 additions & 3 deletions src/vmm/src/vstate/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,15 +249,19 @@ impl Vm {
// would be reflected in the mmap of the file, meaning a truncate operation would zero
// out guest memory, and thus corrupt the VM).
// - For diff snapshots, we want to merge the diff layer directly into the file.
if file_size != expected_size {
// - Skip truncation for /dev/null as it's not a regular file and can't be truncated.
if file_size != expected_size && mem_file_path.to_string_lossy() != "/dev/null" {
file.set_len(0)
.map_err(|err| MemoryBackingFile("truncate", err))?;
}
}

// Set the length of the file to the full size of the memory area.
file.set_len(expected_size)
.map_err(|e| MemoryBackingFile("set_length", e))?;
// Skip setting length for /dev/null as it's not a regular file.
if mem_file_path.to_string_lossy() != "/dev/null" {
file.set_len(expected_size)
.map_err(|e| MemoryBackingFile("set_length", e))?;
}

match snapshot_type {
SnapshotType::Diff => {
Expand Down