Skip to content

Commit 62743ad

Browse files
committed
feat: make network device snapshots backwards compatible
TODO Signed-off-by: Babis Chalios <babis.chalios@e2b.dev>
1 parent 352a867 commit 62743ad

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/vmm/src/devices/virtio/net/persist.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ pub struct NetConfigSpaceState {
3030
guest_mac: Option<MacAddr>,
3131
}
3232

33+
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
34+
pub struct RxBufferState {
35+
// Number of iovecs we have parsed from the guest
36+
parsed_descriptor_chains_nr: u16,
37+
// Number of used descriptors
38+
used_descriptors: u16,
39+
// Number of used bytes
40+
used_bytes: u32,
41+
}
42+
3343
/// Information about the network device that are saved
3444
/// at snapshot.
3545
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -42,6 +52,7 @@ pub struct NetState {
4252
pub mmds_ns: Option<MmdsNetworkStackState>,
4353
config_space: NetConfigSpaceState,
4454
pub virtio_state: VirtioDeviceState,
55+
rx_buffers_state: RxBufferState,
4556
}
4657

4758
/// Auxiliary structure for creating a device when resuming from a snapshot.
@@ -84,6 +95,7 @@ impl Persist<'_> for Net {
8495
guest_mac: self.guest_mac,
8596
},
8697
virtio_state: VirtioDeviceState::from_device(self),
98+
rx_buffers_state: RxBufferState::default(),
8799
}
88100
}
89101

@@ -128,6 +140,10 @@ impl Persist<'_> for Net {
128140
net.avail_features = state.virtio_state.avail_features;
129141
net.acked_features = state.virtio_state.acked_features;
130142

143+
if state.virtio_state.activated {
144+
net.queues[RX_INDEX].next_avail -= state.rx_buffers_state.parsed_descriptor_chains_nr;
145+
}
146+
131147
Ok(net)
132148
}
133149
}

0 commit comments

Comments
 (0)