Skip to content

Commit bc289f1

Browse files
committed
refactor(vmm): Generalize struct for MMDS state
Currently the only MMDS-related state saved in the snapshot is the version info. To enable persisting more MMDS-related state, generalize the struct for MMDS state. Bumped up the snapshot major version since it is a breaking change. Signed-off-by: Takahiro Itazuri <[email protected]>
1 parent 466ed8c commit bc289f1

File tree

2 files changed

+12
-33
lines changed

2 files changed

+12
-33
lines changed

src/vmm/src/device_manager/persist.rs

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -151,29 +151,9 @@ pub struct ConnectedLegacyState {
151151
pub device_info: MMIODeviceInfo,
152152
}
153153

154-
/// Holds the MMDS data store version.
155-
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
156-
pub enum MmdsVersionState {
157-
V1,
158-
V2,
159-
}
160-
161-
impl From<MmdsVersionState> for MmdsVersion {
162-
fn from(state: MmdsVersionState) -> Self {
163-
match state {
164-
MmdsVersionState::V1 => MmdsVersion::V1,
165-
MmdsVersionState::V2 => MmdsVersion::V2,
166-
}
167-
}
168-
}
169-
170-
impl From<MmdsVersion> for MmdsVersionState {
171-
fn from(version: MmdsVersion) -> Self {
172-
match version {
173-
MmdsVersion::V1 => MmdsVersionState::V1,
174-
MmdsVersion::V2 => MmdsVersionState::V2,
175-
}
176-
}
154+
#[derive(Debug, Clone, Serialize, Deserialize)]
155+
pub struct MmdsState {
156+
version: MmdsVersion,
177157
}
178158

179159
/// Holds the device states.
@@ -191,7 +171,7 @@ pub struct DeviceStates {
191171
/// Balloon device state.
192172
pub balloon_device: Option<ConnectedBalloonState>,
193173
/// Mmds version.
194-
pub mmds_version: Option<MmdsVersionState>,
174+
pub mmds: Option<MmdsState>,
195175
/// Entropy device state.
196176
pub entropy_device: Option<ConnectedEntropyState>,
197177
}
@@ -345,11 +325,10 @@ impl<'a> Persist<'a> for MMIODeviceManager {
345325
}
346326
TYPE_NET => {
347327
let net = locked_device.as_any().downcast_ref::<Net>().unwrap();
348-
if let (Some(mmds_ns), None) =
349-
(net.mmds_ns.as_ref(), states.mmds_version.as_ref())
350-
{
351-
states.mmds_version =
352-
Some(mmds_ns.mmds.lock().expect("Poisoned lock").version().into());
328+
if let (Some(mmds_ns), None) = (net.mmds_ns.as_ref(), states.mmds.as_ref()) {
329+
states.mmds = Some(MmdsState {
330+
version: mmds_ns.mmds.lock().expect("Poisoned lock").version(),
331+
});
353332
}
354333

355334
states.net_devices.push(ConnectedNetState {
@@ -557,10 +536,10 @@ impl<'a> Persist<'a> for MMIODeviceManager {
557536
}
558537

559538
// Initialize MMDS if MMDS state is included.
560-
if let Some(mmds_version) = &state.mmds_version {
539+
if let Some(mmds) = &state.mmds {
561540
constructor_args
562541
.vm_resources
563-
.set_mmds_version(mmds_version.clone().into(), constructor_args.instance_id)?;
542+
.set_mmds_version(mmds.version, constructor_args.instance_id)?;
564543
}
565544

566545
for net_state in &state.net_devices {
@@ -880,7 +859,7 @@ mod tests {
880859
.version(),
881860
MmdsVersion::V2
882861
);
883-
assert_eq!(device_states.mmds_version.unwrap(), MmdsVersion::V2.into());
862+
assert_eq!(device_states.mmds.unwrap().version, MmdsVersion::V2.into());
884863

885864
assert_eq!(restored_dev_manager, original_mmio_device_manager);
886865
assert_eq!(

src/vmm/src/persist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub enum CreateSnapshotError {
148148
}
149149

150150
/// Snapshot version
151-
pub const SNAPSHOT_VERSION: Version = Version::new(7, 0, 0);
151+
pub const SNAPSHOT_VERSION: Version = Version::new(8, 0, 0);
152152

153153
/// Creates a Microvm snapshot.
154154
pub fn create_snapshot(

0 commit comments

Comments
 (0)