mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: extract a helper to send the VM state
On-behalf-of: SAP sebastian.eydam@sap.com Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
This commit is contained in:
@@ -1453,15 +1453,7 @@ impl Vmm {
|
||||
|
||||
// Capture snapshot and send it
|
||||
let vm_snapshot = vm.snapshot()?;
|
||||
let snapshot_data = serde_json::to_vec(&vm_snapshot).unwrap();
|
||||
Request::state(snapshot_data.len() as u64).write_to(&mut socket)?;
|
||||
socket
|
||||
.write_all(&snapshot_data)
|
||||
.map_err(MigratableError::MigrateSocket)?;
|
||||
migration_transport::expect_ok_response(
|
||||
&mut socket,
|
||||
MigratableError::MigrateSend(anyhow!("Error during state migration")),
|
||||
)?;
|
||||
migration_transport::send_state(&mut socket, &vm_snapshot)?;
|
||||
// Complete the migration
|
||||
// At this step, the receiving VMM will acquire disk locks again.
|
||||
migration_transport::send_request_expect_ok(
|
||||
|
||||
@@ -12,8 +12,8 @@ use std::result::Result;
|
||||
use anyhow::{Context, anyhow};
|
||||
use log::info;
|
||||
use serde_json;
|
||||
use vm_migration::MigratableError;
|
||||
use vm_migration::protocol::{Request, Response};
|
||||
use vm_migration::{MigratableError, Snapshot};
|
||||
|
||||
use crate::{SocketStream, VmMigrationConfig};
|
||||
|
||||
@@ -117,3 +117,21 @@ pub(crate) fn send_config(
|
||||
MigratableError::MigrateSend(anyhow!("Error during config migration")),
|
||||
)
|
||||
}
|
||||
|
||||
/// Serialize and send the VM snapshot payload.
|
||||
pub(crate) fn send_state(
|
||||
socket: &mut SocketStream,
|
||||
snapshot: &Snapshot,
|
||||
) -> Result<(), MigratableError> {
|
||||
let snapshot_data = serde_json::to_vec(snapshot)
|
||||
.context("Error serializing VM snapshot")
|
||||
.map_err(MigratableError::MigrateSend)?;
|
||||
Request::state(snapshot_data.len() as u64).write_to(socket)?;
|
||||
socket
|
||||
.write_all(&snapshot_data)
|
||||
.map_err(MigratableError::MigrateSocket)?;
|
||||
expect_ok_response(
|
||||
socket,
|
||||
MigratableError::MigrateSend(anyhow!("Error during state migration")),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user