diff --git a/src/vmm/src/persist.rs b/src/vmm/src/persist.rs index aeacadeb66e..2f88b5a1e8a 100644 --- a/src/vmm/src/persist.rs +++ b/src/vmm/src/persist.rs @@ -162,8 +162,12 @@ pub fn create_snapshot( snapshot_state_to_file(µvm_state, ¶ms.snapshot_path)?; - vmm.vm - .snapshot_memory_to_file(¶ms.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(¶ms.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 diff --git a/src/vmm/src/vstate/vm.rs b/src/vmm/src/vstate/vm.rs index 7a8965a4b9a..d658aaebfc4 100644 --- a/src/vmm/src/vstate/vm.rs +++ b/src/vmm/src/vstate/vm.rs @@ -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 => {