| 3394 | |
| 3395 | impl Transportable for Vm { |
| 3396 | fn send( |
| 3397 | &self, |
| 3398 | snapshot: &Snapshot, |
| 3399 | destination_url: &str, |
| 3400 | ) -> std::result::Result<(), MigratableError> { |
| 3401 | let mut snapshot_config_path = url_to_path(destination_url)?; |
| 3402 | snapshot_config_path.push(SNAPSHOT_CONFIG_FILE); |
| 3403 | |
| 3404 | // Create the snapshot config file |
| 3405 | let mut snapshot_config_file = OpenOptions::new() |
| 3406 | .read(true) |
| 3407 | .write(true) |
| 3408 | .create_new(true) |
| 3409 | .open(snapshot_config_path) |
| 3410 | .map_err(|e| MigratableError::MigrateSend(e.into()))?; |
| 3411 | |
| 3412 | // Serialize and write the snapshot config |
| 3413 | let vm_config = serde_json::to_string(self.config.lock().unwrap().deref()) |
| 3414 | .map_err(|e| MigratableError::MigrateSend(e.into()))?; |
| 3415 | |
| 3416 | snapshot_config_file |
| 3417 | .write(vm_config.as_bytes()) |
| 3418 | .map_err(|e| MigratableError::MigrateSend(e.into()))?; |
| 3419 | |
| 3420 | let mut snapshot_state_path = url_to_path(destination_url)?; |
| 3421 | snapshot_state_path.push(SNAPSHOT_STATE_FILE); |
| 3422 | |
| 3423 | // Create the snapshot state file |
| 3424 | let mut snapshot_state_file = OpenOptions::new() |
| 3425 | .read(true) |
| 3426 | .write(true) |
| 3427 | .create_new(true) |
| 3428 | .open(snapshot_state_path) |
| 3429 | .map_err(|e| MigratableError::MigrateSend(e.into()))?; |
| 3430 | |
| 3431 | // Serialize and write the snapshot state |
| 3432 | let vm_state = |
| 3433 | serde_json::to_vec(snapshot).map_err(|e| MigratableError::MigrateSend(e.into()))?; |
| 3434 | |
| 3435 | snapshot_state_file |
| 3436 | .write(&vm_state) |
| 3437 | .map_err(|e| MigratableError::MigrateSend(e.into()))?; |
| 3438 | |
| 3439 | // Tell the memory manager to also send/write its own snapshot. |
| 3440 | if let Some(memory_manager_snapshot) = snapshot.snapshots.get(MEMORY_MANAGER_SNAPSHOT_ID) { |
| 3441 | self.memory_manager |
| 3442 | .lock() |
| 3443 | .unwrap() |
| 3444 | .send(&memory_manager_snapshot.clone(), destination_url)?; |
| 3445 | } else { |
| 3446 | return Err(MigratableError::Restore(anyhow!( |
| 3447 | "Missing memory manager snapshot" |
| 3448 | ))); |
| 3449 | } |
| 3450 | |
| 3451 | Ok(()) |
| 3452 | } |
| 3453 | } |