vm-migration: Introduce new constructor for Snapshot

This simplifies the Snapshot creation as we expect a SnapshotData to be
provided most of the time.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2022-12-02 16:03:50 +01:00
parent 4ae6b595d7
commit 3931b99d4e
5 changed files with 20 additions and 30 deletions

View File

@@ -2508,7 +2508,6 @@ impl Snapshottable for Vm {
})?
};
let mut vm_snapshot = Snapshot::default();
let vm_snapshot_data = serde_json::to_vec(&VmSnapshot {
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
clock: self.saved_clock,
@@ -2517,6 +2516,8 @@ impl Snapshottable for Vm {
})
.map_err(|e| MigratableError::Snapshot(e.into()))?;
let mut vm_snapshot = Snapshot::from_data(SnapshotData(vm_snapshot_data));
let (id, snapshot) = {
let mut cpu_manager = self.cpu_manager.lock().unwrap();
(cpu_manager.id(), cpu_manager.snapshot()?)
@@ -2532,7 +2533,6 @@ impl Snapshottable for Vm {
(device_manager.id(), device_manager.snapshot()?)
};
vm_snapshot.add_snapshot(id, snapshot);
vm_snapshot.add_data(SnapshotData(vm_snapshot_data));
event!("vm", "snapshotted");
Ok(vm_snapshot)