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

Method snapshot

vmm/src/vm.rs:3325–3392  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

3323 }
3324
3325 fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
3326 event!("vm", "snapshotting");
3327
3328 #[cfg(feature = "tdx")]
3329 {
3330 if self.config.lock().unwrap().is_tdx_enabled() {
3331 return Err(MigratableError::Snapshot(anyhow!(
3332 "Snapshot not possible with TDX VM"
3333 )));
3334 }
3335 }
3336
3337 if self.get_state() != VmState::Paused {
3338 return Err(MigratableError::Snapshot(anyhow!(
3339 "Trying to snapshot while VM is running"
3340 )));
3341 }
3342
3343 #[cfg(all(feature = "kvm", target_arch = "x86_64"))]
3344 let common_cpuid = {
3345 let amx = self.config.lock().unwrap().cpus.features.amx;
3346 let phys_bits = physical_bits(
3347 self.hypervisor.as_ref(),
3348 self.config.lock().unwrap().cpus.max_phys_bits,
3349 );
3350 arch::generate_common_cpuid(
3351 self.hypervisor.as_ref(),
3352 &arch::CpuidConfig {
3353 phys_bits,
3354 kvm_hyperv: self.config.lock().unwrap().cpus.kvm_hyperv,
3355 #[cfg(feature = "tdx")]
3356 tdx: false,
3357 amx,
3358 },
3359 )
3360 .map_err(|e| {
3361 MigratableError::MigrateReceive(anyhow!("Error generating common cpuid: {e:?}"))
3362 })?
3363 };
3364
3365 let vm_snapshot_state = VmSnapshot {
3366 #[cfg(target_arch = "x86_64")]
3367 clock: self.saved_clock,
3368 #[cfg(all(feature = "kvm", target_arch = "x86_64"))]
3369 common_cpuid,
3370 };
3371
3372 let mut vm_snapshot = Snapshot::new_from_state(&vm_snapshot_state)?;
3373
3374 let (id, snapshot) = {
3375 let mut cpu_manager = self.cpu_manager.lock().unwrap();
3376 (cpu_manager.id(), cpu_manager.snapshot()?)
3377 };
3378 vm_snapshot.add_snapshot(id, snapshot);
3379 let (id, snapshot) = {
3380 let mut memory_manager = self.memory_manager.lock().unwrap();
3381 (memory_manager.id(), memory_manager.snapshot()?)
3382 };

Callers 2

send_migrationMethod · 0.45
vm_snapshotMethod · 0.45

Calls 7

SnapshotClass · 0.85
physical_bitsFunction · 0.85
generate_common_cpuidFunction · 0.85
is_tdx_enabledMethod · 0.80
get_stateMethod · 0.80
add_snapshotMethod · 0.80
idMethod · 0.45

Tested by

no test coverage detected