mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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:
@@ -148,15 +148,19 @@ pub struct Snapshot {
|
||||
}
|
||||
|
||||
impl Snapshot {
|
||||
pub fn from_data(data: SnapshotData) -> Self {
|
||||
Snapshot {
|
||||
snapshot_data: Some(data),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
/// Create from state that can be serialized
|
||||
pub fn new_from_state<T>(state: &T) -> Result<Self, MigratableError>
|
||||
where
|
||||
T: Serialize,
|
||||
{
|
||||
let mut snapshot_data = Snapshot::default();
|
||||
snapshot_data.add_data(SnapshotData::new_from_state(state)?);
|
||||
|
||||
Ok(snapshot_data)
|
||||
Ok(Snapshot::from_data(SnapshotData::new_from_state(state)?))
|
||||
}
|
||||
|
||||
/// Create from versioned state
|
||||
@@ -164,10 +168,9 @@ impl Snapshot {
|
||||
where
|
||||
T: Versionize + VersionMapped,
|
||||
{
|
||||
let mut snapshot_data = Snapshot::default();
|
||||
snapshot_data.add_data(SnapshotData::new_from_versioned_state(state)?);
|
||||
|
||||
Ok(snapshot_data)
|
||||
Ok(Snapshot::from_data(SnapshotData::new_from_versioned_state(
|
||||
state,
|
||||
)?))
|
||||
}
|
||||
|
||||
/// Add a sub-component's Snapshot to the Snapshot.
|
||||
@@ -175,11 +178,6 @@ impl Snapshot {
|
||||
self.snapshots.insert(id, snapshot);
|
||||
}
|
||||
|
||||
/// Add a SnapshotData to the component snapshot data.
|
||||
pub fn add_data(&mut self, section: SnapshotData) {
|
||||
self.snapshot_data = Some(section);
|
||||
}
|
||||
|
||||
/// Generate the state data from the snapshot
|
||||
pub fn to_state<'a, T>(&'a self) -> Result<T, MigratableError>
|
||||
where
|
||||
|
||||
Reference in New Issue
Block a user