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 config
This further decreases boilerplate code in lib.rs while keeping the behavior. On-behalf-of: SAP sebastian.eydam@sap.com Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
This commit is contained in:
@@ -1434,15 +1434,7 @@ impl Vmm {
|
||||
common_cpuid,
|
||||
memory_manager_data: vm.memory_manager_data(),
|
||||
};
|
||||
let config_data = serde_json::to_vec(&vm_migration_config).unwrap();
|
||||
Request::config(config_data.len() as u64).write_to(&mut socket)?;
|
||||
socket
|
||||
.write_all(&config_data)
|
||||
.map_err(MigratableError::MigrateSocket)?;
|
||||
migration_transport::expect_ok_response(
|
||||
&mut socket,
|
||||
MigratableError::MigrateSend(anyhow!("Error during config migration")),
|
||||
)?;
|
||||
migration_transport::send_config(&mut socket, &vm_migration_config)?;
|
||||
|
||||
// Let every Migratable object know about the migration being started.
|
||||
vm.start_migration()?;
|
||||
|
||||
@@ -3,17 +3,19 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
use std::io::Write;
|
||||
use std::net::{TcpListener, TcpStream};
|
||||
use std::os::unix::net::{UnixListener, UnixStream};
|
||||
use std::path::PathBuf;
|
||||
use std::result::Result;
|
||||
|
||||
use anyhow::anyhow;
|
||||
use anyhow::{Context, anyhow};
|
||||
use log::info;
|
||||
use serde_json;
|
||||
use vm_migration::MigratableError;
|
||||
use vm_migration::protocol::{Request, Response};
|
||||
|
||||
use crate::SocketStream;
|
||||
use crate::{SocketStream, VmMigrationConfig};
|
||||
|
||||
/// Extract a UNIX socket path from a "unix:" migration URL.
|
||||
fn socket_url_to_path(url: &str) -> Result<PathBuf, anyhow::Error> {
|
||||
@@ -97,3 +99,21 @@ pub(crate) fn send_request_expect_ok(
|
||||
request.write_to(socket)?;
|
||||
expect_ok_response(socket, error)
|
||||
}
|
||||
|
||||
/// Serialize and send the VM configuration payload.
|
||||
pub(crate) fn send_config(
|
||||
socket: &mut SocketStream,
|
||||
config: &VmMigrationConfig,
|
||||
) -> Result<(), MigratableError> {
|
||||
let config_data = serde_json::to_vec(config)
|
||||
.context("Error serializing VM migration config")
|
||||
.map_err(MigratableError::MigrateSend)?;
|
||||
Request::config(config_data.len() as u64).write_to(socket)?;
|
||||
socket
|
||||
.write_all(&config_data)
|
||||
.map_err(MigratableError::MigrateSocket)?;
|
||||
expect_ok_response(
|
||||
socket,
|
||||
MigratableError::MigrateSend(anyhow!("Error during config migration")),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user