Skip to content

Commit f217762

Browse files
snapshot: add container_snapshot_path to load snapshot request
When a snapshot of a VM created by firecracker-containerd is restored, due to the non-deterministic container snapshot path (it depends on the containerd snapshotter implementation), the container snapshot path at the time of the snapshot creation is different from the container snapshot path at the time of the snapshot loading. Firecracker does not support renaming resources at snapshot-restore, so as a workaround we manually substitute the VM state with the path of the block device backing the container snapshot to the path of the new container snapshot path received from the LoadSnapshot request. Closes firecracker-microvm#4014 Signed-off-by: Georgiy Lebedev <[email protected]>
1 parent 02dd032 commit f217762

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

src/api_server/src/request/snapshot.rs

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ fn parse_put_snapshot_load(body: &Body) -> Result<ParsedRequest, Error> {
9494
mem_backend,
9595
enable_diff_snapshots: snapshot_config.enable_diff_snapshots,
9696
resume_vm: snapshot_config.resume_vm,
97+
container_snapshot_path: snapshot_config.container_snapshot_path,
9798
};
9899

99100
// Construct the `ParsedRequest` object.

src/api_server/swagger/firecracker.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,7 @@ definitions:
11881188
the two `mem_*` fields must be present in the body of the request.
11891189
required:
11901190
- snapshot_path
1191+
- container_snapshot_path
11911192
properties:
11921193
enable_diff_snapshots:
11931194
type: boolean
@@ -1212,6 +1213,10 @@ definitions:
12121213
type: boolean
12131214
description:
12141215
When set to true, the vm is also resumed if the snapshot load is successful.
1216+
container_snapshot_path:
1217+
type: string
1218+
description:
1219+
Path to the disk device backing the disk state at the time of the snapshot creation.
12151220

12161221
TokenBucket:
12171222
type: object

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ pub struct BlockState {
8686
)]
8787
cache_type: CacheTypeState,
8888
root_device: bool,
89-
disk_path: String,
89+
pub disk_path: String,
9090
virtio_state: VirtioDeviceState,
9191
rate_limiter_state: RateLimiterState,
9292
#[version(start = 3)]

src/vmm/src/persist.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,19 @@ pub fn restore_from_snapshot(
523523
version_map: VersionMap,
524524
vm_resources: &mut VmResources,
525525
) -> std::result::Result<Arc<Mutex<Vmm>>, RestoreFromSnapshotError> {
526-
let microvm_state = snapshot_state_from_file(&params.snapshot_path, version_map)?;
526+
let mut microvm_state = snapshot_state_from_file(&params.snapshot_path, version_map)?;
527+
528+
let container_snapshot_path = &params.container_snapshot_path;
529+
// We assume that each microVM is backed by exactly one container image
530+
// snapshot device (i.e., that no more than one container is run on each microVM).
531+
assert_eq!(microvm_state.device_states.block_devices.len(), 2);
532+
for i in 0..2 {
533+
// We assume that one of the block devices is the rootfs, the other being the
534+
// container image snapshot.
535+
if microvm_state.device_states.block_devices[i].device_state.disk_path.contains("snap") {
536+
microvm_state.device_states.block_devices[i].device_state.disk_path = container_snapshot_path.clone();
537+
}
538+
}
527539

528540
// Some sanity checks before building the microvm.
529541
snapshot_state_sanity_check(&microvm_state)?;

src/vmm/src/vmm_config/snapshot.rs

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ pub struct LoadSnapshotParams {
6161
/// When set to true, the vm is also resumed if the snapshot load
6262
/// is successful.
6363
pub resume_vm: bool,
64+
/// Path to the disk device backing the container snapshot.
65+
pub container_snapshot_path: String,
6466
}
6567

6668
/// Stores the configuration for loading a snapshot that is provided by the user.
@@ -83,6 +85,8 @@ pub struct LoadSnapshotConfig {
8385
/// Whether or not to resume the vm post snapshot load.
8486
#[serde(default)]
8587
pub resume_vm: bool,
88+
/// Path to the disk device backing the container snapshot.
89+
pub container_snapshot_path: String,
8690
}
8791

8892
/// Stores the configuration used for managing snapshot memory.

0 commit comments

Comments
 (0)