Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/bin/ch-remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use clap::{Arg, ArgAction, ArgMatches, Command};
use log::error;
use option_parser::{ByteSized, ByteSizedParseError};
use thiserror::Error;
use vmm::api::VmMigrationProgressData;
use vmm::config::RestoreConfig;
use vmm::vm_config::{
DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, UserDeviceConfig, VdpaConfig,
Expand Down Expand Up @@ -301,6 +302,21 @@ fn rest_api_do_command(matches: &ArgMatches, socket: &mut UnixStream) -> ApiResu
Some("shutdown") => {
simple_api_command(socket, "PUT", "shutdown", None).map_err(Error::HttpApiClient)
}
Some("migration-progress") => {
let clear = matches
.subcommand_matches("migration-progress")
.unwrap()
.get_one::<bool>("clear")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can completely nuke that clear complexity - there is no problem with keeping the old state around. As soon as a new migration starts, the state is overwritten anyway

.copied();
let data = migration_progress(clear)?;
if clear.unwrap_or(false) {
simple_api_command(socket, "GET", "migration-progress", Some(&data))
.map_err(Error::HttpApiClient)
} else {
simple_api_command(socket, "PUT", "migration-progress", Some(&data))
.map_err(Error::HttpApiClient)
}
}
Some("nmi") => simple_api_command(socket, "PUT", "nmi", None).map_err(Error::HttpApiClient),
Some("resize") => {
let resize = resize_config(
Expand Down Expand Up @@ -777,6 +793,13 @@ fn dbus_api_do_command(matches: &ArgMatches, proxy: &DBusApi1ProxyBlocking<'_>)
}
}

fn migration_progress(clear: Option<bool>) -> Result<String, Error> {
let data = VmMigrationProgressData {
clear: clear.unwrap_or(false),
};
Ok(serde_json::to_string(&data).unwrap())
}

fn resize_config(
cpus: Option<&str>,
memory: Option<&str>,
Expand Down Expand Up @@ -1078,6 +1101,13 @@ fn get_cli_commands_sorted() -> Box<[Command]> {
Command::new("ping").about("Ping the VMM to check for API server availability"),
Command::new("power-button").about("Trigger a power button in the VM"),
Command::new("reboot").about("Reboot the VM"),
Command::new("migration-progress")
.about("Fetch state about the ongoing migration")
.arg(
Arg::new("clear")
.long("clear")
.help("Whether the latest snapshot should be cleared."),
),
Command::new("receive-migration")
.about("Receive a VM migration")
.arg(
Expand Down
2 changes: 2 additions & 0 deletions vm-migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
//

use anyhow::anyhow;
pub use progress::MigrationPhase;
use serde::{Deserialize, Serialize};
use thiserror::Error;

use crate::protocol::MemoryRangeTable;

mod bitpos_iterator;
pub mod progress;
pub mod protocol;
pub mod tls;

Expand Down
Loading
Loading