diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index 7f83c1185..98a39a736 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -397,7 +397,7 @@ impl Vmm { &snapshot, exit_evt, reset_evt, - source_url, + Some(source_url), restore_cfg.prefault, &self.seccomp_action, self.hypervisor.clone(), diff --git a/vmm/src/memory_manager.rs b/vmm/src/memory_manager.rs index edeb5eb97..91ec67f34 100644 --- a/vmm/src/memory_manager.rs +++ b/vmm/src/memory_manager.rs @@ -760,54 +760,60 @@ impl MemoryManager { snapshot: &Snapshot, vm: Arc, config: &MemoryConfig, - source_url: &str, + source_url: Option<&str>, prefault: bool, phys_bits: u8, ) -> Result>, Error> { - let url = Url::parse(source_url).unwrap(); - /* url must be valid dir which is verified in recv_vm_snapshot() */ - let vm_snapshot_path = url.to_file_path().unwrap(); + let mm = MemoryManager::new(vm, config, prefault, phys_bits)?; - if let Some(mem_section) = snapshot - .snapshot_data - .get(&format!("{}-section", MEMORY_MANAGER_SNAPSHOT_ID)) - { - let mem_snapshot: MemoryManagerSnapshotData = - match serde_json::from_slice(&mem_section.snapshot) { - Ok(snapshot) => snapshot, - Err(error) => { - return Err(Error::Restore(MigratableError::Restore(anyhow!( - "Could not deserialize MemoryManager {}", - error - )))) + if let Some(source_url) = source_url { + let url = Url::parse(source_url).unwrap(); + /* url must be valid dir which is verified in recv_vm_snapshot() */ + let vm_snapshot_path = url.to_file_path().unwrap(); + + if let Some(mem_section) = snapshot + .snapshot_data + .get(&format!("{}-section", MEMORY_MANAGER_SNAPSHOT_ID)) + { + let mem_snapshot: MemoryManagerSnapshotData = + match serde_json::from_slice(&mem_section.snapshot) { + Ok(snapshot) => snapshot, + Err(error) => { + return Err(Error::Restore(MigratableError::Restore(anyhow!( + "Could not deserialize MemoryManager {}", + error + )))) + } + }; + + // Here we turn the content file name into a content file path as + // this will be needed to copy the content of the saved memory + // region into the newly created memory region. + // We simply ignore the content files that are None, as they + // represent regions that have been directly saved by the user, with + // no need for saving into a dedicated external file. For these + // files, the VmConfig already contains the information on where to + // find them. + let mut saved_regions = mem_snapshot.memory_regions; + for region in saved_regions.iter_mut() { + if let Some(content) = &mut region.content { + let mut memory_region_path = vm_snapshot_path.clone(); + memory_region_path.push(content.clone()); + *content = memory_region_path; } - }; - - // Here we turn the content file name into a content file path as - // this will be needed to copy the content of the saved memory - // region into the newly created memory region. - // We simply ignore the content files that are None, as they - // represent regions that have been directly saved by the user, with - // no need for saving into a dedicated external file. For these - // files, the VmConfig already contains the information on where to - // find them. - let mut saved_regions = mem_snapshot.memory_regions; - for region in saved_regions.iter_mut() { - if let Some(content) = &mut region.content { - let mut memory_region_path = vm_snapshot_path.clone(); - memory_region_path.push(content.clone()); - *content = memory_region_path; } - } - let mm = MemoryManager::new(vm, config, prefault, phys_bits)?; - mm.lock().unwrap().fill_saved_regions(saved_regions)?; - Ok(mm) + mm.lock().unwrap().fill_saved_regions(saved_regions)?; + + Ok(mm) + } else { + Err(Error::Restore(MigratableError::Restore(anyhow!( + "Could not find {}-section from snapshot", + MEMORY_MANAGER_SNAPSHOT_ID + )))) + } } else { - Err(Error::Restore(MigratableError::Restore(anyhow!( - "Could not find {}-section from snapshot", - MEMORY_MANAGER_SNAPSHOT_ID - )))) + Ok(mm) } } diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 8316117f2..864da7dac 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -680,7 +680,7 @@ impl Vm { snapshot: &Snapshot, exit_evt: EventFd, reset_evt: EventFd, - source_url: &str, + source_url: Option<&str>, prefault: bool, seccomp_action: &SeccompAction, hypervisor: Arc,