ch-remote: Support adding VFIO devices

Add an "add-device" command that allows adding VFIO devices to the VM
after boot.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-03-10 16:38:04 +00:00 committed by Sebastien Boeuf
parent babefbd9bf
commit 0d53ba4395

View File

@ -22,6 +22,7 @@ enum Error {
ServerResponse(StatusCode), ServerResponse(StatusCode),
InvalidCPUCount(std::num::ParseIntError), InvalidCPUCount(std::num::ParseIntError),
InvalidMemorySize(std::num::ParseIntError), InvalidMemorySize(std::num::ParseIntError),
AddDeviceConfig(vmm::config::Error),
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
@ -190,6 +191,17 @@ fn resize_api_command(
) )
} }
fn add_device_api_command(socket: &mut UnixStream, config: &str) -> Result<(), Error> {
let device_config = vmm::config::DeviceConfig::parse(config).map_err(Error::AddDeviceConfig)?;
simple_api_command(
socket,
"PUT",
"add-device",
Some(&serde_json::to_string(&device_config).unwrap()),
)
}
fn do_command(matches: &ArgMatches) -> Result<(), Error> { fn do_command(matches: &ArgMatches) -> Result<(), Error> {
let mut socket = let mut socket =
UnixStream::connect(matches.value_of("api-socket").unwrap()).map_err(Error::Socket)?; UnixStream::connect(matches.value_of("api-socket").unwrap()).map_err(Error::Socket)?;
@ -207,6 +219,14 @@ fn do_command(matches: &ArgMatches) -> Result<(), Error> {
.unwrap() .unwrap()
.value_of("memory"), .value_of("memory"),
), ),
Some("add-device") => add_device_api_command(
&mut socket,
matches
.subcommand_matches("add-device")
.unwrap()
.value_of("device_config")
.unwrap(),
),
Some(c) => simple_api_command(&mut socket, "PUT", c, None), Some(c) => simple_api_command(&mut socket, "PUT", c, None),
None => unreachable!(), None => unreachable!(),
} }
@ -225,6 +245,14 @@ fn main() {
.min_values(1) .min_values(1)
.required(true), .required(true),
) )
.subcommand(
SubCommand::with_name("add-device")
.about("Add VFIO device")
.arg(Arg::with_name("device_config").index(1).help(
"Direct device assignment parameters \
\"path=<device_path>,iommu=on|off\"",
)),
)
.subcommand(SubCommand::with_name("info").about("Info on the VM")) .subcommand(SubCommand::with_name("info").about("Info on the VM"))
.subcommand(SubCommand::with_name("pause").about("Pause the VM")) .subcommand(SubCommand::with_name("pause").about("Pause the VM"))
.subcommand(SubCommand::with_name("reboot").about("Reboot the VM")) .subcommand(SubCommand::with_name("reboot").about("Reboot the VM"))