vmm: memory_manager: Make the snapshot source directory an Option

This allows the code to be reused when creating the VM from a snapshot
when doing VM migration.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-11-04 14:58:18 +00:00 committed by Samuel Ortiz
parent 523029449e
commit dfe2dadb3e
3 changed files with 48 additions and 42 deletions

View File

@ -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(),

View File

@ -760,10 +760,13 @@ impl MemoryManager {
snapshot: &Snapshot,
vm: Arc<dyn hypervisor::Vm>,
config: &MemoryConfig,
source_url: &str,
source_url: Option<&str>,
prefault: bool,
phys_bits: u8,
) -> Result<Arc<Mutex<MemoryManager>>, Error> {
let mm = MemoryManager::new(vm, config, prefault, phys_bits)?;
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();
@ -800,8 +803,8 @@ impl MemoryManager {
}
}
let mm = MemoryManager::new(vm, config, prefault, phys_bits)?;
mm.lock().unwrap().fill_saved_regions(saved_regions)?;
Ok(mm)
} else {
Err(Error::Restore(MigratableError::Restore(anyhow!(
@ -809,6 +812,9 @@ impl MemoryManager {
MEMORY_MANAGER_SNAPSHOT_ID
))))
}
} else {
Ok(mm)
}
}
fn memfd_create(name: &ffi::CStr, flags: u32) -> Result<RawFd, io::Error> {

View File

@ -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<dyn hypervisor::Hypervisor>,