mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Directly (de)serialise CpuManager, DeviceManager and MemoryManager state
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
committed by
Sebastien Boeuf
parent
85f7913bb3
commit
a7c4483b8b
@@ -365,41 +365,18 @@ impl Snapshottable for Vcpu {
|
||||
}
|
||||
|
||||
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
|
||||
let snapshot = serde_json::to_vec(&self.saved_state)
|
||||
.map_err(|e| MigratableError::Snapshot(e.into()))?;
|
||||
|
||||
let mut vcpu_snapshot = Snapshot::new(&format!("{}", self.id));
|
||||
vcpu_snapshot.add_data_section(SnapshotDataSection {
|
||||
id: format!("{}-section", VCPU_SNAPSHOT_ID),
|
||||
snapshot,
|
||||
});
|
||||
vcpu_snapshot.add_data_section(SnapshotDataSection::new_from_state(
|
||||
VCPU_SNAPSHOT_ID,
|
||||
&self.saved_state,
|
||||
)?);
|
||||
|
||||
Ok(vcpu_snapshot)
|
||||
}
|
||||
|
||||
fn restore(&mut self, snapshot: Snapshot) -> std::result::Result<(), MigratableError> {
|
||||
if let Some(vcpu_section) = snapshot
|
||||
.snapshot_data
|
||||
.get(&format!("{}-section", VCPU_SNAPSHOT_ID))
|
||||
{
|
||||
let vcpu_state = match serde_json::from_slice(&vcpu_section.snapshot) {
|
||||
Ok(state) => state,
|
||||
Err(error) => {
|
||||
return Err(MigratableError::Restore(anyhow!(
|
||||
"Could not deserialize the vCPU snapshot {}",
|
||||
error
|
||||
)))
|
||||
}
|
||||
};
|
||||
|
||||
self.saved_state = Some(vcpu_state);
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
Err(MigratableError::Restore(anyhow!(
|
||||
"Could not find the vCPU snapshot section"
|
||||
)))
|
||||
}
|
||||
self.saved_state = Some(snapshot.to_state(VCPU_SNAPSHOT_ID)?);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user