@@ -31,7 +31,7 @@ use crate::device_manager::persist::ACPIDeviceManagerState;
31
31
use crate :: device_manager:: persist:: { DevicePersistError , DeviceStates } ;
32
32
use crate :: logger:: { info, warn} ;
33
33
use crate :: resources:: VmResources ;
34
- use crate :: snapshot:: Snapshot ;
34
+ use crate :: snapshot:: { Snapshot , SnapshotHdr } ;
35
35
use crate :: vmm_config:: boot_source:: BootSourceConfig ;
36
36
use crate :: vmm_config:: instance_info:: InstanceInfo ;
37
37
use crate :: vmm_config:: machine_config:: { HugePageConfig , MachineConfigUpdate , VmConfigError } ;
@@ -191,9 +191,10 @@ fn snapshot_state_to_file(
191
191
. open ( snapshot_path)
192
192
. map_err ( |err| SnapshotBackingFile ( "open" , err) ) ?;
193
193
194
- let snapshot = Snapshot :: new ( SNAPSHOT_VERSION ) ;
194
+ let snapshot_hdr = SnapshotHdr :: new ( SNAPSHOT_VERSION ) ;
195
+ let snapshot = Snapshot :: new ( snapshot_hdr, microvm_state) ;
195
196
snapshot
196
- . save ( & mut snapshot_file, microvm_state )
197
+ . save ( & mut snapshot_file)
197
198
. map_err ( SerializeMicrovmState ) ?;
198
199
snapshot_file
199
200
. flush ( )
@@ -475,15 +476,14 @@ pub enum SnapshotStateFromFileError {
475
476
fn snapshot_state_from_file (
476
477
snapshot_path : & Path ,
477
478
) -> Result < MicrovmState , SnapshotStateFromFileError > {
478
- let snapshot = Snapshot :: new ( SNAPSHOT_VERSION ) ;
479
479
let mut snapshot_reader =
480
480
File :: open ( snapshot_path) . map_err ( SnapshotStateFromFileError :: Open ) ?;
481
481
let metadata = std:: fs:: metadata ( snapshot_path) . map_err ( SnapshotStateFromFileError :: Meta ) ?;
482
482
let snapshot_len = u64_to_usize ( metadata. len ( ) ) ;
483
- let state: MicrovmState = snapshot
484
- . load_with_version_check ( & mut snapshot_reader, snapshot_len)
483
+ let state: Snapshot < MicrovmState > = Snapshot :: load ( & mut snapshot_reader, snapshot_len)
485
484
. map_err ( SnapshotStateFromFileError :: Load ) ?;
486
- Ok ( state)
485
+
486
+ Ok ( state. data )
487
487
}
488
488
489
489
/// Error type for [`guest_memory_from_file`].
@@ -732,10 +732,14 @@ mod tests {
732
732
} ;
733
733
734
734
let mut buf = vec ! [ 0 ; 10000 ] ;
735
- Snapshot :: serialize ( & mut buf. as_mut_slice ( ) , & microvm_state) . unwrap ( ) ;
736
735
737
- let restored_microvm_state: MicrovmState =
738
- Snapshot :: deserialize ( & mut buf. as_slice ( ) ) . unwrap ( ) ;
736
+ let snapshot_hdr = SnapshotHdr :: new ( Version :: new ( 1 , 0 , 42 ) ) ;
737
+ let snapshot = Snapshot :: new ( snapshot_hdr, microvm_state) ;
738
+ snapshot. save ( & mut buf. as_mut_slice ( ) ) . unwrap ( ) ;
739
+
740
+ let restored_snapshot: Snapshot < MicrovmState > =
741
+ Snapshot :: load ( & mut buf. as_slice ( ) , buf. len ( ) ) . unwrap ( ) ;
742
+ let restored_microvm_state = restored_snapshot. data ;
739
743
740
744
assert_eq ! ( restored_microvm_state. vm_info, microvm_state. vm_info) ;
741
745
assert_eq ! (
0 commit comments