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 <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-06-24 11:59:17 +02:00
parent 1741af74ed
commit 65132fb99d

View File

@ -398,7 +398,15 @@ impl Vcpu {
} }
const VCPU_SNAPSHOT_ID: &str = "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 { impl Snapshottable for Vcpu {
fn id(&self) -> String { fn id(&self) -> String {
VCPU_SNAPSHOT_ID.to_string() VCPU_SNAPSHOT_ID.to_string()
@ -1322,17 +1330,12 @@ impl Pausable for CpuManager {
state.signal_thread(); state.signal_thread();
} }
#[cfg(target_arch = "x86_64")]
for vcpu in self.vcpus.iter() { for vcpu in self.vcpus.iter() {
vcpu.lock() let mut vcpu = vcpu.lock().unwrap();
.unwrap() vcpu.pause()?;
.fd #[cfg(target_arch = "x86_64")]
.notify_guest_clock_paused() vcpu.fd.notify_guest_clock_paused().map_err(|e| {
.map_err(|e| { MigratableError::Pause(anyhow!("Could not notify guest it has been paused {:?}", e))
MigratableError::Pause(anyhow!(
"Could not notify guest it has been paused {:?}",
e
))
})?; })?;
} }
@ -1340,6 +1343,10 @@ impl Pausable for CpuManager {
} }
fn resume(&mut self) -> std::result::Result<(), MigratableError> { fn resume(&mut self) -> std::result::Result<(), MigratableError> {
for vcpu in self.vcpus.iter() {
vcpu.lock().unwrap().resume()?;
}
// Toggle the vCPUs pause boolean // Toggle the vCPUs pause boolean
self.vcpus_pause_signalled.store(false, Ordering::SeqCst); self.vcpus_pause_signalled.store(false, Ordering::SeqCst);