Skip to content

Commit 28c80dd

Browse files
committed
Adding host device renaming for snapshot restore
1 parent a46d1b9 commit 28c80dd

File tree

6 files changed

+54
-3
lines changed

6 files changed

+54
-3
lines changed

src/firecracker/src/api_server/request/snapshot.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ fn parse_put_snapshot_load(body: &Body) -> Result<ParsedRequest, RequestError> {
105105
mem_backend,
106106
enable_diff_snapshots: snapshot_config.enable_diff_snapshots,
107107
resume_vm: snapshot_config.resume_vm,
108+
network_overrides: snapshot_config.network_overrides,
108109
};
109110

110111
// Construct the `ParsedRequest` object.

src/firecracker/swagger/firecracker.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,24 @@ definitions:
12031203
Type of snapshot to create. It is optional and by default, a full
12041204
snapshot is created.
12051205

1206+
NetworkOverride:
1207+
type: object
1208+
description:
1209+
Allows for changing the mapping between tap devices and host devices
1210+
during snapshot restore
1211+
required:
1212+
- iface_id
1213+
- host_dev_name
1214+
properties:
1215+
iface_id:
1216+
type: string
1217+
description:
1218+
The name of the interface to modify
1219+
host_dev_name:
1220+
type: string
1221+
description:
1222+
The new host device of the interface
1223+
12061224
SnapshotLoadParams:
12071225
type: object
12081226
description:
@@ -1234,6 +1252,12 @@ definitions:
12341252
type: boolean
12351253
description:
12361254
When set to true, the vm is also resumed if the snapshot load is successful.
1255+
network_overrides:
1256+
type: array
1257+
description: Network host device names to override
1258+
items:
1259+
$ref: "#/definitions/NetworkOverride"
1260+
12371261

12381262
TokenBucket:
12391263
type: object

src/vmm/src/builder.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ pub enum BuildMicrovmFromSnapshotError {
443443
ACPIDeviManager(#[from] ACPIDeviceManagerRestoreError),
444444
/// VMGenID update failed: {0}
445445
VMGenIDUpdate(std::io::Error),
446+
/// Unknown Network Device.
447+
UnknownNetworkDevice,
446448
}
447449

448450
/// Builds and starts a microVM based on the provided MicrovmState.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ pub struct NetConfigSpaceState {
3535
/// at snapshot.
3636
#[derive(Debug, Clone, Serialize, Deserialize)]
3737
pub struct NetState {
38-
id: String,
39-
tap_if_name: String,
38+
pub id: String,
39+
pub tap_if_name: String,
4040
rx_rate_limiter_state: RateLimiterState,
4141
tx_rate_limiter_state: RateLimiterState,
4242
/// The associated MMDS network stack.

src/vmm/src/persist.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,16 @@ pub fn restore_from_snapshot(
398398
params: &LoadSnapshotParams,
399399
vm_resources: &mut VmResources,
400400
) -> Result<Arc<Mutex<Vmm>>, RestoreFromSnapshotError> {
401-
let microvm_state = snapshot_state_from_file(&params.snapshot_path)?;
401+
let mut microvm_state = snapshot_state_from_file(&params.snapshot_path)?;
402+
for entry in &params.network_overrides {
403+
let net_devices = &mut microvm_state.device_states.net_devices;
404+
if let Some(idx) = net_devices.iter().position(|x| x.device_state.id == entry.iface_id) {
405+
406+
net_devices.get_mut(idx).unwrap().device_state.tap_if_name = entry.host_dev_name.clone();
407+
} else {
408+
return Err(BuildMicrovmFromSnapshotError::UnknownNetworkDevice.into());
409+
}
410+
}
402411
let track_dirty_pages = params.enable_diff_snapshots;
403412

404413
let vcpu_count = microvm_state

src/vmm/src/vmm_config/snapshot.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ pub struct CreateSnapshotParams {
4747
pub mem_file_path: PathBuf,
4848
}
4949

50+
/// Allows for changing the mapping between tap devices and host devices
51+
/// during snapshot restore
52+
#[derive(Debug, PartialEq, Eq, Deserialize)]
53+
pub struct NetworkOverride {
54+
/// The index of the interface to modify
55+
pub iface_id: String,
56+
/// The new name of the interface to be assigned
57+
pub host_dev_name: String,
58+
}
59+
5060
/// Stores the configuration that will be used for loading a snapshot.
5161
#[derive(Debug, PartialEq, Eq)]
5262
pub struct LoadSnapshotParams {
@@ -60,6 +70,8 @@ pub struct LoadSnapshotParams {
6070
/// When set to true, the vm is also resumed if the snapshot load
6171
/// is successful.
6272
pub resume_vm: bool,
73+
/// The network devices to override on load.
74+
pub network_overrides: Vec<NetworkOverride>,
6375
}
6476

6577
/// Stores the configuration for loading a snapshot that is provided by the user.
@@ -82,6 +94,9 @@ pub struct LoadSnapshotConfig {
8294
/// Whether or not to resume the vm post snapshot load.
8395
#[serde(default)]
8496
pub resume_vm: bool,
97+
/// The network devices to override on load.
98+
#[serde(default)]
99+
pub network_overrides: Vec<NetworkOverride>,
85100
}
86101

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

0 commit comments

Comments
 (0)