vm-migration: Don't store the id as part of Snapshot structure

The information about the identifier related to a Snapshot is only
relevant from the BTreeMap perspective, which is why we can get rid of
the duplicated identifier in every Snapshot structure.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2022-12-02 15:31:53 +01:00
parent 426ee39972
commit 748018ace3
32 changed files with 76 additions and 85 deletions

View File

@@ -387,11 +387,10 @@ impl Vcpu {
}
}
const VCPU_SNAPSHOT_ID: &str = "vcpu";
impl Pausable for Vcpu {}
impl Snapshottable for Vcpu {
fn id(&self) -> String {
VCPU_SNAPSHOT_ID.to_string()
self.id.to_string()
}
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
@@ -400,9 +399,7 @@ impl Snapshottable for Vcpu {
.state()
.map_err(|e| MigratableError::Pause(anyhow!("Could not get vCPU state {:?}", e)))?;
// TODO: The special format of the CPU id can be removed once ready to
// break live upgrade.
let mut vcpu_snapshot = Snapshot::new(&format!("{:03}", self.id));
let mut vcpu_snapshot = Snapshot::default();
vcpu_snapshot.add_data_section(SnapshotData::new_from_state(&saved_state)?);
self.saved_state = Some(saved_state);
@@ -776,7 +773,7 @@ impl CpuManager {
cpu_id,
// TODO: The special format of the CPU id can be removed once
// ready to break live upgrade.
snapshot_from_id(snapshot.as_ref(), &format!("{:03}", cpu_id)),
snapshot_from_id(snapshot.as_ref(), cpu_id.to_string().as_str()),
)?);
}
@@ -2076,12 +2073,12 @@ impl Snapshottable for CpuManager {
}
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let mut cpu_manager_snapshot = Snapshot::new(CPU_MANAGER_SNAPSHOT_ID);
let mut cpu_manager_snapshot = Snapshot::default();
// The CpuManager snapshot is a collection of all vCPUs snapshots.
for vcpu in &self.vcpus {
let cpu_snapshot = vcpu.lock().unwrap().snapshot()?;
cpu_manager_snapshot.add_snapshot(cpu_snapshot);
let mut vcpu = vcpu.lock().unwrap();
cpu_manager_snapshot.add_snapshot(vcpu.id(), vcpu.snapshot()?);
}
Ok(cpu_manager_snapshot)

View File

@@ -4445,13 +4445,13 @@ impl Snapshottable for DeviceManager {
}
fn snapshot(&mut self) -> std::result::Result<Snapshot, MigratableError> {
let mut snapshot = Snapshot::new(DEVICE_MANAGER_SNAPSHOT_ID);
let mut snapshot = Snapshot::default();
// We aggregate all devices snapshots.
for (_, device_node) in self.device_tree.lock().unwrap().iter() {
if let Some(migratable) = &device_node.migratable {
let device_snapshot = migratable.lock().unwrap().snapshot()?;
snapshot.add_snapshot(device_snapshot);
let mut migratable = migratable.lock().unwrap();
snapshot.add_snapshot(migratable.id(), migratable.snapshot()?);
}
}

View File

@@ -2428,7 +2428,7 @@ impl Snapshottable for MemoryManager {
}
fn snapshot(&mut self) -> result::Result<Snapshot, MigratableError> {
let mut memory_manager_snapshot = Snapshot::new(MEMORY_MANAGER_SNAPSHOT_ID);
let mut memory_manager_snapshot = Snapshot::default();
let memory_ranges = self.memory_range_table(true)?;

View File

@@ -2508,7 +2508,7 @@ impl Snapshottable for Vm {
})?
};
let mut vm_snapshot = Snapshot::new(VM_SNAPSHOT_ID);
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,10 +2517,21 @@ impl Snapshottable for Vm {
})
.map_err(|e| MigratableError::Snapshot(e.into()))?;
vm_snapshot.add_snapshot(self.cpu_manager.lock().unwrap().snapshot()?);
vm_snapshot.add_snapshot(self.memory_manager.lock().unwrap().snapshot()?);
vm_snapshot.add_snapshot(self.device_manager.lock().unwrap().snapshot()?);
let (id, snapshot) = {
let mut cpu_manager = self.cpu_manager.lock().unwrap();
(cpu_manager.id(), cpu_manager.snapshot()?)
};
vm_snapshot.add_snapshot(id, snapshot);
let (id, snapshot) = {
let mut memory_manager = self.memory_manager.lock().unwrap();
(memory_manager.id(), memory_manager.snapshot()?)
};
vm_snapshot.add_snapshot(id, snapshot);
let (id, snapshot) = {
let mut device_manager = self.device_manager.lock().unwrap();
(device_manager.id(), device_manager.snapshot()?)
};
vm_snapshot.add_snapshot(id, snapshot);
vm_snapshot.add_data_section(SnapshotData(vm_snapshot_data));
event!("vm", "snapshotted");