MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / new_from_snapshot

Method new_from_snapshot

vmm/src/memory_manager.rs:1758–1802  ·  view source on GitHub ↗
(
        snapshot: &Snapshot,
        vm: Arc<dyn hypervisor::Vm>,
        config: &MemoryConfig,
        source_url: Option<&str>,
        prefault: bool,
        memory_restore_mode: MemoryRestoreM

Source from the content-addressed store, hash-verified

1756
1757 #[allow(clippy::too_many_arguments)]
1758 pub fn new_from_snapshot(
1759 snapshot: &Snapshot,
1760 vm: Arc<dyn hypervisor::Vm>,
1761 config: &MemoryConfig,
1762 source_url: Option<&str>,
1763 prefault: bool,
1764 memory_restore_mode: MemoryRestoreMode,
1765 phys_bits: u8,
1766 exit_evt: &EventFd,
1767 ) -> Result<Arc<Mutex<MemoryManager>>, Error> {
1768 if let Some(source_url) = source_url {
1769 let mut memory_file_path = url_to_path(source_url).map_err(Error::Restore)?;
1770 memory_file_path.push(String::from(SNAPSHOT_FILENAME));
1771
1772 let mem_snapshot: MemoryManagerSnapshotData =
1773 snapshot.to_state().map_err(Error::Restore)?;
1774
1775 let mm = MemoryManager::new(
1776 vm,
1777 config,
1778 Some(prefault),
1779 phys_bits,
1780 #[cfg(feature = "tdx")]
1781 false,
1782 Some(&mem_snapshot),
1783 Default::default(),
1784 )?;
1785
1786 if memory_restore_mode == MemoryRestoreMode::OnDemand {
1787 mm.lock().unwrap().restore_by_uffd(
1788 &memory_file_path,
1789 &mem_snapshot.memory_ranges,
1790 exit_evt,
1791 )?;
1792 } else {
1793 mm.lock()
1794 .unwrap()
1795 .fill_saved_regions(memory_file_path, &mem_snapshot.memory_ranges)?;
1796 }
1797
1798 Ok(mm)
1799 } else {
1800 Err(Error::RestoreMissingSourceUrl)
1801 }
1802 }
1803
1804 fn memfd_create(name: &ffi::CStr, flags: u32) -> Result<RawFd, io::Error> {
1805 // SAFETY: FFI call with correct arguments

Callers

nothing calls this directly

Calls 6

url_to_pathFunction · 0.85
newFunction · 0.85
to_stateMethod · 0.80
restore_by_uffdMethod · 0.80
fill_saved_regionsMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected