Skip to content

Commit 01c9a38

Browse files
committed
snapshot: add state types for previous versions
Add descriptions for MicovmState from previous Firecracker versions. Moreover, add methods to translate a snapshot file from previous versions in the current one. Signed-off-by: Babis Chalios <babis.chalios@e2b.dev>
1 parent 62743ad commit 01c9a38

21 files changed

Lines changed: 1752 additions & 57 deletions

File tree

src/vmm/src/arch/x86_64/vm.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,18 @@ pub struct VmState {
224224
pub memory: GuestMemoryState,
225225
/// resource allocator
226226
pub resource_allocator: ResourceAllocator,
227-
pitstate: kvm_pit_state2,
228-
clock: kvm_clock_data,
227+
/// KVM interrupt timer
228+
pub pitstate: kvm_pit_state2,
229+
/// KVM clock data
230+
pub clock: kvm_clock_data,
229231
// TODO: rename this field to adopt inclusive language once Linux updates it, too.
230-
pic_master: kvm_irqchip,
232+
/// Master PIC controller
233+
pub pic_master: kvm_irqchip,
231234
// TODO: rename this field to adopt inclusive language once Linux updates it, too.
232-
pic_slave: kvm_irqchip,
233-
ioapic: kvm_irqchip,
235+
/// Slave PIC controller
236+
pub pic_slave: kvm_irqchip,
237+
/// IOAPIC
238+
pub ioapic: kvm_irqchip,
234239
}
235240

236241
impl fmt::Debug for VmState {

src/vmm/src/device_manager/persist.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ impl fmt::Debug for MMIODevManagerConstructorArgs<'_> {
168168

169169
#[derive(Default, Debug, Clone, Serialize, Deserialize)]
170170
pub struct ACPIDeviceManagerState {
171-
vmgenid: VMGenIDState,
171+
pub vmgenid: VMGenIDState,
172172
#[cfg(target_arch = "x86_64")]
173-
vmclock: VmClockState,
173+
pub vmclock: VmClockState,
174174
}
175175

176176
impl<'a> Persist<'a> for ACPIDeviceManager {

src/vmm/src/devices/acpi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
mod generated;
4+
pub mod generated;
55
pub mod vmclock;
66
pub mod vmgenid;

src/vmm/src/devices/acpi/vmclock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::vstate::resources::ResourceAllocator;
2222
unsafe impl ByteValued for vmclock_abi {}
2323

2424
// We are reserving a physical page to expose the [`VmClock`] data
25-
const VMCLOCK_SIZE: u32 = 0x1000;
25+
pub const VMCLOCK_SIZE: u32 = 0x1000;
2626

2727
// Write a value in `vmclock_abi` both in the Firecracker-managed state
2828
// and inside guest memory address that corresponds to it.

src/vmm/src/devices/virtio/balloon/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ unsafe impl ByteValued for ConfigSpace {}
6868

6969
/// Holds state of the free page hinting run
7070
#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)]
71-
pub(crate) struct HintingState {
71+
pub struct HintingState {
7272
/// The command requested by us. Set to STOP by default.
7373
pub host_cmd: u32,
7474
/// The last command supplied by guest.

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

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@ pub struct BalloonConfigSpaceState {
3131
/// at snapshot.
3232
#[derive(Debug, Clone, Serialize, Deserialize)]
3333
pub struct BalloonStatsState {
34-
swap_in: Option<u64>,
35-
swap_out: Option<u64>,
36-
major_faults: Option<u64>,
37-
minor_faults: Option<u64>,
38-
free_memory: Option<u64>,
39-
total_memory: Option<u64>,
40-
available_memory: Option<u64>,
41-
disk_caches: Option<u64>,
42-
hugetlb_allocations: Option<u64>,
43-
hugetlb_failures: Option<u64>,
44-
oom_kill: Option<u64>,
45-
alloc_stall: Option<u64>,
46-
async_scan: Option<u64>,
47-
direct_scan: Option<u64>,
48-
async_reclaim: Option<u64>,
49-
direct_reclaim: Option<u64>,
34+
pub swap_in: Option<u64>,
35+
pub swap_out: Option<u64>,
36+
pub major_faults: Option<u64>,
37+
pub minor_faults: Option<u64>,
38+
pub free_memory: Option<u64>,
39+
pub total_memory: Option<u64>,
40+
pub available_memory: Option<u64>,
41+
pub disk_caches: Option<u64>,
42+
pub hugetlb_allocations: Option<u64>,
43+
pub hugetlb_failures: Option<u64>,
44+
pub oom_kill: Option<u64>,
45+
pub alloc_stall: Option<u64>,
46+
pub async_scan: Option<u64>,
47+
pub direct_scan: Option<u64>,
48+
pub async_reclaim: Option<u64>,
49+
pub direct_reclaim: Option<u64>,
5050
}
5151

5252
impl BalloonStatsState {
@@ -101,11 +101,11 @@ impl BalloonStatsState {
101101
/// at snapshot.
102102
#[derive(Debug, Clone, Serialize, Deserialize)]
103103
pub struct BalloonState {
104-
stats_polling_interval_s: u16,
105-
stats_desc_index: Option<u16>,
106-
latest_stats: BalloonStatsState,
107-
config_space: BalloonConfigSpaceState,
108-
hinting_state: HintingState,
104+
pub stats_polling_interval_s: u16,
105+
pub stats_desc_index: Option<u16>,
106+
pub latest_stats: BalloonStatsState,
107+
pub config_space: BalloonConfigSpaceState,
108+
pub hinting_state: HintingState,
109109
pub virtio_state: VirtioDeviceState,
110110
}
111111

src/vmm/src/devices/virtio/block/vhost_user/persist.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ use crate::snapshot::Persist;
1515
/// vhost-user block device state.
1616
#[derive(Debug, Clone, Serialize, Deserialize)]
1717
pub struct VhostUserBlockState {
18-
id: String,
19-
partuuid: Option<String>,
20-
cache_type: CacheType,
21-
root_device: bool,
22-
socket_path: String,
23-
vu_acked_protocol_features: u64,
24-
config_space: Vec<u8>,
25-
virtio_state: VirtioDeviceState,
18+
pub id: String,
19+
pub partuuid: Option<String>,
20+
pub cache_type: CacheType,
21+
pub root_device: bool,
22+
pub socket_path: String,
23+
pub vu_acked_protocol_features: u64,
24+
pub config_space: Vec<u8>,
25+
pub virtio_state: VirtioDeviceState,
2626
}
2727

2828
impl Persist<'_> for VhostUserBlock {

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ impl From<FileEngineTypeState> for FileEngineType {
5353
/// Holds info about the block device. Gets saved in snapshot.
5454
#[derive(Debug, Clone, Serialize, Deserialize)]
5555
pub struct VirtioBlockState {
56-
id: String,
57-
partuuid: Option<String>,
58-
cache_type: CacheType,
59-
root_device: bool,
60-
disk_path: String,
56+
pub id: String,
57+
pub partuuid: Option<String>,
58+
pub cache_type: CacheType,
59+
pub root_device: bool,
60+
pub disk_path: String,
6161
pub virtio_state: VirtioDeviceState,
62-
rate_limiter_state: RateLimiterState,
63-
file_engine_type: FileEngineTypeState,
62+
pub rate_limiter_state: RateLimiterState,
63+
pub file_engine_type: FileEngineTypeState,
6464
}
6565

6666
impl Persist<'_> for VirtioBlock {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ pub struct RxBufferState {
4646
pub struct NetState {
4747
pub id: String,
4848
pub tap_if_name: String,
49-
rx_rate_limiter_state: RateLimiterState,
50-
tx_rate_limiter_state: RateLimiterState,
49+
pub rx_rate_limiter_state: RateLimiterState,
50+
pub tx_rate_limiter_state: RateLimiterState,
5151
/// The associated MMDS network stack.
5252
pub mmds_ns: Option<MmdsNetworkStackState>,
53-
config_space: NetConfigSpaceState,
53+
pub config_space: NetConfigSpaceState,
5454
pub virtio_state: VirtioDeviceState,
55-
rx_buffers_state: RxBufferState,
55+
pub rx_buffers_state: RxBufferState,
5656
}
5757

5858
/// Auxiliary structure for creating a device when resuming from a snapshot.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ impl VirtioDeviceState {
194194
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
195195
pub struct MmioTransportState {
196196
// The register where feature bits are stored.
197-
features_select: u32,
197+
pub features_select: u32,
198198
// The register where features page is selected.
199-
acked_features_select: u32,
200-
queue_select: u32,
201-
device_status: u32,
202-
config_generation: u32,
203-
interrupt_status: u32,
199+
pub acked_features_select: u32,
200+
pub queue_select: u32,
201+
pub device_status: u32,
202+
pub config_generation: u32,
203+
pub interrupt_status: u32,
204204
}
205205

206206
/// Auxiliary structure for initializing the transport when resuming from a snapshot.

0 commit comments

Comments
 (0)