vm-migration: Snapshot should have a unique SnapshotDataSection

There's no reason to carry a HashMap of SnapshotDataSection per
Snapshot. And given we now provide at most one SnapshotDataSection per
Snapshot, there's no need to keep the id part of the SnapshotDataSection
structure.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2022-12-02 14:37:49 +01:00
parent 0489b6314e
commit 5b3bcfa233
8 changed files with 36 additions and 63 deletions

View File

@@ -403,10 +403,7 @@ impl Snapshottable for Vcpu {
// 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));
vcpu_snapshot.add_data_section(SnapshotDataSection::new_from_state(
VCPU_SNAPSHOT_ID,
&saved_state,
)?);
vcpu_snapshot.add_data_section(SnapshotDataSection::new_from_state(&saved_state)?);
self.saved_state = Some(saved_state);
@@ -717,7 +714,7 @@ impl CpuManager {
#[cfg(target_arch = "aarch64")]
vcpu.init(&self.vm)?;
let state: CpuState = snapshot.to_state(VCPU_SNAPSHOT_ID).map_err(|e| {
let state: CpuState = snapshot.to_state().map_err(|e| {
Error::VcpuCreate(anyhow!("Could not get vCPU state from snapshot {:?}", e))
})?;
vcpu.vcpu

View File

@@ -966,7 +966,7 @@ impl DeviceManager {
trace_scoped!("DeviceManager::new");
let (device_tree, device_id_cnt) = if let Some(snapshot) = snapshot.as_ref() {
let state: DeviceManagerState = snapshot.to_state(DEVICE_MANAGER_SNAPSHOT_ID).unwrap();
let state: DeviceManagerState = snapshot.to_state().unwrap();
(
Arc::new(Mutex::new(state.device_tree.clone())),
state.device_id_cnt,
@@ -1389,7 +1389,7 @@ impl DeviceManager {
}
let vgic_state = vgic_snapshot
.to_state(&id)
.to_state()
.map_err(DeviceManagerError::RestoreGetState)?;
let saved_vcpu_states = self.cpu_manager.lock().unwrap().get_saved_states();
interrupt_controller
@@ -2150,7 +2150,7 @@ impl DeviceManager {
.map_err(DeviceManagerError::EventFd)?,
self.force_iommu,
snapshot
.map(|s| s.to_versioned_state(&id))
.map(|s| s.to_versioned_state())
.transpose()
.map_err(DeviceManagerError::RestoreGetState)?,
) {
@@ -2249,7 +2249,7 @@ impl DeviceManager {
.try_clone()
.map_err(DeviceManagerError::EventFd)?,
snapshot
.map(|s| s.to_versioned_state(&id))
.map(|s| s.to_versioned_state())
.transpose()
.map_err(DeviceManagerError::RestoreGetState)?,
)
@@ -2332,7 +2332,7 @@ impl DeviceManager {
.map_err(DeviceManagerError::EventFd)?,
self.force_iommu,
snapshot
.map(|s| s.to_versioned_state(&id))
.map(|s| s.to_versioned_state())
.transpose()
.map_err(DeviceManagerError::RestoreGetState)?,
) {
@@ -2349,7 +2349,7 @@ impl DeviceManager {
)
} else {
let state = snapshot
.map(|s| s.to_versioned_state(&id))
.map(|s| s.to_versioned_state())
.transpose()
.map_err(DeviceManagerError::RestoreGetState)?;
@@ -4456,10 +4456,7 @@ impl Snapshottable for DeviceManager {
}
// Then we store the DeviceManager state.
snapshot.add_data_section(SnapshotDataSection::new_from_state(
DEVICE_MANAGER_SNAPSHOT_ID,
&self.state(),
)?);
snapshot.add_data_section(SnapshotDataSection::new_from_state(&self.state())?);
Ok(snapshot)
}

View File

@@ -1160,9 +1160,8 @@ impl MemoryManager {
let mut memory_file_path = url_to_path(source_url).map_err(Error::Restore)?;
memory_file_path.push(String::from(SNAPSHOT_FILENAME));
let mem_snapshot: MemoryManagerSnapshotData = snapshot
.to_versioned_state(MEMORY_MANAGER_SNAPSHOT_ID)
.map_err(Error::Restore)?;
let mem_snapshot: MemoryManagerSnapshotData =
snapshot.to_versioned_state().map_err(Error::Restore)?;
let mm = MemoryManager::new(
vm,
@@ -2444,7 +2443,6 @@ impl Snapshottable for MemoryManager {
self.snapshot_memory_ranges = memory_ranges;
memory_manager_snapshot.add_data_section(SnapshotDataSection::new_from_versioned_state(
MEMORY_MANAGER_SNAPSHOT_ID,
&self.snapshot_data(),
)?);

View File

@@ -4,10 +4,7 @@
#[cfg(all(target_arch = "x86_64", feature = "guest_debug"))]
use crate::coredump::GuestDebuggableError;
use crate::{
config::VmConfig,
vm::{VmSnapshot, VM_SNAPSHOT_ID},
};
use crate::{config::VmConfig, vm::VmSnapshot};
use anyhow::anyhow;
use std::fs::File;
use std::io::BufReader;
@@ -71,13 +68,8 @@ pub fn recv_vm_state(source_url: &str) -> std::result::Result<Snapshot, Migratab
}
pub fn get_vm_snapshot(snapshot: &Snapshot) -> std::result::Result<VmSnapshot, MigratableError> {
if let Some(vm_section) = snapshot
.snapshot_data
.get(&format!("{}-section", VM_SNAPSHOT_ID))
{
return serde_json::from_slice(&vm_section.snapshot).map_err(|e| {
MigratableError::Restore(anyhow!("Could not deserialize VM snapshot {}", e))
});
if let Some(snapshot_data) = snapshot.snapshot_data.as_ref() {
return snapshot_data.to_state();
}
Err(MigratableError::Restore(anyhow!(

View File

@@ -2522,7 +2522,6 @@ impl Snapshottable for Vm {
vm_snapshot.add_snapshot(self.device_manager.lock().unwrap().snapshot()?);
vm_snapshot.add_data_section(SnapshotDataSection {
id: format!("{}-section", VM_SNAPSHOT_ID),
snapshot: vm_snapshot_data,
});