@@ -16,7 +16,7 @@ use arch::regs::{get_manufacturer_id_from_host, get_manufacturer_id_from_state};
1616#[ cfg( target_arch = "x86_64" ) ]
1717use cpuid:: common:: { get_vendor_id_from_cpuid, get_vendor_id_from_host} ;
1818use devices:: virtio:: TYPE_NET ;
19- use logger:: { error, info} ;
19+ use logger:: { error, info, warn } ;
2020use seccompiler:: BpfThreadMap ;
2121use serde:: Serialize ;
2222use snapshot:: Snapshot ;
@@ -34,8 +34,9 @@ use crate::resources::VmResources;
3434#[ cfg( target_arch = "x86_64" ) ]
3535use crate :: version_map:: FC_V0_23_SNAP_VERSION ;
3636use crate :: version_map:: { FC_V1_0_SNAP_VERSION , FC_V1_1_SNAP_VERSION , FC_VERSION_TO_SNAP_VERSION } ;
37+ use crate :: vmm_config:: boot_source:: BootSourceConfig ;
3738use crate :: vmm_config:: instance_info:: InstanceInfo ;
38- use crate :: vmm_config:: machine_config:: MAX_SUPPORTED_VCPUS ;
39+ use crate :: vmm_config:: machine_config:: { CpuFeaturesTemplate , MAX_SUPPORTED_VCPUS } ;
3940use crate :: vmm_config:: snapshot:: {
4041 CreateSnapshotParams , LoadSnapshotParams , MemBackendType , SnapshotType ,
4142} ;
@@ -47,11 +48,59 @@ use crate::{mem_size_mib, memory_snapshot, vstate, Error as VmmError, EventManag
4748const FC_V0_23_MAX_DEVICES : u32 = 11 ;
4849
4950/// Holds information related to the VM that is not part of VmState.
50- #[ derive( Debug , PartialEq , Versionize ) ]
51+ #[ derive( Clone , Debug , Default , PartialEq , Versionize , Serialize ) ]
5152// NOTICE: Any changes to this structure require a snapshot version bump.
5253pub struct VmInfo {
5354 /// Guest memory size.
5455 pub mem_size_mib : u64 ,
56+ /// smt information
57+ #[ version( start = 2 , default_fn = "def_smt" , ser_fn = "ser_smt" ) ]
58+ pub smt : bool ,
59+ /// CPU template type
60+ #[ version(
61+ start = 2 ,
62+ default_fn = "def_cpu_template" ,
63+ ser_fn = "ser_cpu_template"
64+ ) ]
65+ pub cpu_template : CpuFeaturesTemplate ,
66+ /// Boot source information.
67+ #[ version( start = 2 , default_fn = "def_boot_source" , ser_fn = "ser_boot_source" ) ]
68+ pub boot_source : BootSourceConfig ,
69+ }
70+
71+ impl VmInfo {
72+ fn def_smt ( _: u16 ) -> bool {
73+ warn ! ( "SMT field not found in snapshot." ) ;
74+ false
75+ }
76+
77+ fn ser_smt ( & mut self , _target_version : u16 ) -> VersionizeResult < ( ) > {
78+ // v1.1 and older versions do not include smt info.
79+ warn ! ( "Saving to older snapshot version, SMT information will not be saved." ) ;
80+ Ok ( ( ) )
81+ }
82+
83+ fn def_cpu_template ( _: u16 ) -> CpuFeaturesTemplate {
84+ warn ! ( "CPU template field not found in snapshot." ) ;
85+ CpuFeaturesTemplate :: None
86+ }
87+
88+ fn ser_cpu_template ( & mut self , _target_version : u16 ) -> VersionizeResult < ( ) > {
89+ // v1.1 and older versions do not include cpu template info.
90+ warn ! ( "Saving to older snapshot version, CPU template information will not be saved." ) ;
91+ Ok ( ( ) )
92+ }
93+
94+ fn def_boot_source ( _: u16 ) -> BootSourceConfig {
95+ warn ! ( "Boot source information not found in snapshot." ) ;
96+ BootSourceConfig :: default ( )
97+ }
98+
99+ fn ser_boot_source ( & mut self , _target_version : u16 ) -> VersionizeResult < ( ) > {
100+ // v1.1 and older versions do not include boot source info.
101+ warn ! ( "Saving to older snapshot version, boot source information will not be saved." ) ;
102+ Ok ( ( ) )
103+ }
55104}
56105
57106/// Contains the necesary state for saving/restoring a microVM.
@@ -195,14 +244,15 @@ impl Display for CreateSnapshotError {
195244/// Creates a Microvm snapshot.
196245pub fn create_snapshot (
197246 vmm : & mut Vmm ,
247+ vm_info : & VmInfo ,
198248 params : & CreateSnapshotParams ,
199249 version_map : VersionMap ,
200250) -> std:: result:: Result < ( ) , CreateSnapshotError > {
201251 // Fail early from invalid target version.
202252 let snapshot_data_version = get_snapshot_data_version ( & params. version , & version_map, & vmm) ?;
203253
204254 let microvm_state = vmm
205- . save_state ( )
255+ . save_state ( vm_info )
206256 . map_err ( CreateSnapshotError :: MicrovmState ) ?;
207257
208258 snapshot_state_to_file (
@@ -787,7 +837,10 @@ mod tests {
787837 device_states : states,
788838 memory_state,
789839 vcpu_states,
790- vm_info : VmInfo { mem_size_mib : 1u64 } ,
840+ vm_info : VmInfo {
841+ mem_size_mib : 1u64 ,
842+ ..Default :: default ( )
843+ } ,
791844 #[ cfg( target_arch = "aarch64" ) ]
792845 vm_state : vmm. vm . save_state ( & mpidrs) . unwrap ( ) ,
793846 #[ cfg( target_arch = "x86_64" ) ]
0 commit comments