vmm: add TLS API option to receive migration call

As we now have more than one parameter for the receive migration call,
this commit also adds parsing and validation for those parameters. We
maintain backwards compatibility by also correctly parsing the case
where the caller only provides a URL.

On-behalf-of: SAP sebastian.eydam@sap.com
Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
This commit is contained in:
Sebastian Eydam
2026-04-15 10:32:02 +02:00
committed by Rob Bradford
parent c23edda98b
commit 58baee16ac
5 changed files with 130 additions and 12 deletions

View File

@@ -71,6 +71,8 @@ enum Error {
ReadingFile(#[source] std::io::Error),
#[error("Invalid disk size")]
InvalidDiskSize(#[source] ByteSizedParseError),
#[error("Error parsing receive migration configuration")]
ReceiveMigrationConfig(#[from] vmm::api::VmReceiveMigrationConfigError),
#[error("Error parsing send migration configuration")]
SendMigrationConfig(#[from] vmm::api::VmSendMigrationConfigError),
}
@@ -534,7 +536,7 @@ fn rest_api_do_command(matches: &ArgMatches, socket: &mut UnixStream) -> ApiResu
.unwrap()
.get_one::<String>("receive_migration_config")
.unwrap(),
);
)?;
simple_api_command(
socket,
"PUT",
@@ -753,7 +755,7 @@ fn dbus_api_do_command(matches: &ArgMatches, proxy: &DBusApi1ProxyBlocking<'_>)
.unwrap()
.get_one::<String>("receive_migration_config")
.unwrap(),
);
)?;
proxy.api_vm_receive_migration(&receive_migration_data)
}
Some("create") => {
@@ -941,12 +943,10 @@ fn coredump_config(destination_url: &str) -> String {
serde_json::to_string(&coredump_config).unwrap()
}
fn receive_migration_data(url: &str) -> String {
let receive_migration_data = vmm::api::VmReceiveMigrationData {
receiver_url: url.to_owned(),
};
serde_json::to_string(&receive_migration_data).unwrap()
fn receive_migration_data(config: &str) -> Result<String, Error> {
let receive_migration_data =
vmm::api::VmReceiveMigrationData::parse(config).map_err(Error::ReceiveMigrationConfig)?;
Ok(serde_json::to_string(&receive_migration_data).unwrap())
}
fn send_migration_data(config: &str) -> Result<String, Error> {
@@ -1069,7 +1069,7 @@ fn get_cli_commands_sorted() -> Box<[Command]> {
.arg(
Arg::new("receive_migration_config")
.index(1)
.help("<receiver_url>"),
.help(vmm::api::VmReceiveMigrationData::SYNTAX),
),
Command::new("remove-device")
.about("Remove VFIO and PCI device")

View File

@@ -1136,7 +1136,7 @@ pub(crate) fn start_live_migration(
.args([
&format!("--api-socket={dest_api_socket}"),
"receive-migration",
&format! {"unix:{migration_socket}"},
&format!("receiver_url=unix:{migration_socket}"),
])
.stderr(Stdio::piped())
.stdout(Stdio::piped())

View File

@@ -6740,7 +6740,7 @@ mod common_parallel {
.args([
&format!("--api-socket={dest_api_socket}"),
"receive-migration",
&format!("tcp:0.0.0.0:{migration_port}"),
&format!("receiver_url=tcp:0.0.0.0:{migration_port}"),
])
.stdin(Stdio::null())
.stderr(Stdio::piped())
@@ -7077,7 +7077,7 @@ mod common_parallel {
.args([
&format!("--api-socket={dest_api_socket}"),
"receive-migration",
&format!("tcp:0.0.0.0:{migration_port}"),
&format!("receiver_url=tcp:0.0.0.0:{migration_port}"),
])
.stdin(Stdio::null())
.stderr(Stdio::piped())