mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vm-migration: Simplify SnapshotDataSection structure
Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
+9
-16
@@ -80,10 +80,7 @@ pub trait Pausable {
|
|||||||
/// Splitting a component migration data into different sections
|
/// Splitting a component migration data into different sections
|
||||||
/// allows for easier and forward compatible extensions.
|
/// allows for easier and forward compatible extensions.
|
||||||
#[derive(Clone, Default, Deserialize, Serialize)]
|
#[derive(Clone, Default, Deserialize, Serialize)]
|
||||||
pub struct SnapshotDataSection {
|
pub struct SnapshotDataSection(pub Vec<u8>);
|
||||||
/// The section serialized snapshot.
|
|
||||||
pub snapshot: Vec<u8>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SnapshotDataSection {
|
impl SnapshotDataSection {
|
||||||
/// Generate the state data from the snapshot data
|
/// Generate the state data from the snapshot data
|
||||||
@@ -91,7 +88,7 @@ impl SnapshotDataSection {
|
|||||||
where
|
where
|
||||||
T: Deserialize<'a>,
|
T: Deserialize<'a>,
|
||||||
{
|
{
|
||||||
serde_json::from_slice(&self.snapshot)
|
serde_json::from_slice(&self.0)
|
||||||
.map_err(|e| MigratableError::Restore(anyhow!("Error deserialising: {}", e)))
|
.map_err(|e| MigratableError::Restore(anyhow!("Error deserialising: {}", e)))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,12 +97,8 @@ impl SnapshotDataSection {
|
|||||||
where
|
where
|
||||||
T: Versionize + VersionMapped,
|
T: Versionize + VersionMapped,
|
||||||
{
|
{
|
||||||
T::deserialize(
|
T::deserialize(&mut self.0.as_slice(), &T::version_map(), VMM_VERSION)
|
||||||
&mut self.snapshot.as_slice(),
|
.map_err(|e| MigratableError::Restore(anyhow!("Error deserialising: {}", e)))
|
||||||
&T::version_map(),
|
|
||||||
VMM_VERSION,
|
|
||||||
)
|
|
||||||
.map_err(|e| MigratableError::Restore(anyhow!("Error deserialising: {}", e)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create from state that can be serialized
|
/// Create from state that can be serialized
|
||||||
@@ -113,10 +106,10 @@ impl SnapshotDataSection {
|
|||||||
where
|
where
|
||||||
T: Serialize,
|
T: Serialize,
|
||||||
{
|
{
|
||||||
let snapshot = serde_json::to_vec(state)
|
let data = serde_json::to_vec(state)
|
||||||
.map_err(|e| MigratableError::Snapshot(anyhow!("Error serialising: {}", e)))?;
|
.map_err(|e| MigratableError::Snapshot(anyhow!("Error serialising: {}", e)))?;
|
||||||
|
|
||||||
let snapshot_data = SnapshotDataSection { snapshot };
|
let snapshot_data = SnapshotDataSection(data);
|
||||||
|
|
||||||
Ok(snapshot_data)
|
Ok(snapshot_data)
|
||||||
}
|
}
|
||||||
@@ -126,12 +119,12 @@ impl SnapshotDataSection {
|
|||||||
where
|
where
|
||||||
T: Versionize + VersionMapped,
|
T: Versionize + VersionMapped,
|
||||||
{
|
{
|
||||||
let mut snapshot = Vec::new();
|
let mut data = Vec::new();
|
||||||
state
|
state
|
||||||
.serialize(&mut snapshot, &T::version_map(), VMM_VERSION)
|
.serialize(&mut data, &T::version_map(), VMM_VERSION)
|
||||||
.map_err(|e| MigratableError::Snapshot(anyhow!("Error serialising: {}", e)))?;
|
.map_err(|e| MigratableError::Snapshot(anyhow!("Error serialising: {}", e)))?;
|
||||||
|
|
||||||
let snapshot_data = SnapshotDataSection { snapshot };
|
let snapshot_data = SnapshotDataSection(data);
|
||||||
|
|
||||||
Ok(snapshot_data)
|
Ok(snapshot_data)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -2521,9 +2521,7 @@ impl Snapshottable for Vm {
|
|||||||
vm_snapshot.add_snapshot(self.memory_manager.lock().unwrap().snapshot()?);
|
vm_snapshot.add_snapshot(self.memory_manager.lock().unwrap().snapshot()?);
|
||||||
|
|
||||||
vm_snapshot.add_snapshot(self.device_manager.lock().unwrap().snapshot()?);
|
vm_snapshot.add_snapshot(self.device_manager.lock().unwrap().snapshot()?);
|
||||||
vm_snapshot.add_data_section(SnapshotDataSection {
|
vm_snapshot.add_data_section(SnapshotDataSection(vm_snapshot_data));
|
||||||
snapshot: vm_snapshot_data,
|
|
||||||
});
|
|
||||||
|
|
||||||
event!("vm", "snapshotted");
|
event!("vm", "snapshotted");
|
||||||
Ok(vm_snapshot)
|
Ok(vm_snapshot)
|
||||||
|
|||||||
Reference in New Issue
Block a user