From 65132fb99d392a3d8b912b62c9d0745b1a01e289 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Wed, 24 Jun 2020 11:59:17 +0200 Subject: [PATCH] vmm: Implement Pausable trait for Vcpu We want each Vcpu to store the vCPU state upon VM pausing. This is the reason why we need to explicitly implement the Pausable trait for the Vcpu structure. Signed-off-by: Sebastien Boeuf --- vmm/src/cpu.rs | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index 0828a0966..9ec481458 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -398,7 +398,15 @@ impl Vcpu { } const VCPU_SNAPSHOT_ID: &str = "vcpu"; -impl Pausable for Vcpu {} +impl Pausable for Vcpu { + fn pause(&mut self) -> std::result::Result<(), MigratableError> { + Ok(()) + } + + fn resume(&mut self) -> std::result::Result<(), MigratableError> { + Ok(()) + } +} impl Snapshottable for Vcpu { fn id(&self) -> String { VCPU_SNAPSHOT_ID.to_string() @@ -1322,24 +1330,23 @@ impl Pausable for CpuManager { state.signal_thread(); } - #[cfg(target_arch = "x86_64")] for vcpu in self.vcpus.iter() { - vcpu.lock() - .unwrap() - .fd - .notify_guest_clock_paused() - .map_err(|e| { - MigratableError::Pause(anyhow!( - "Could not notify guest it has been paused {:?}", - e - )) - })?; + let mut vcpu = vcpu.lock().unwrap(); + vcpu.pause()?; + #[cfg(target_arch = "x86_64")] + vcpu.fd.notify_guest_clock_paused().map_err(|e| { + MigratableError::Pause(anyhow!("Could not notify guest it has been paused {:?}", e)) + })?; } Ok(()) } fn resume(&mut self) -> std::result::Result<(), MigratableError> { + for vcpu in self.vcpus.iter() { + vcpu.lock().unwrap().resume()?; + } + // Toggle the vCPUs pause boolean self.vcpus_pause_signalled.store(false, Ordering::SeqCst);