From 0d53ba43957714491288818171942db1d705b796 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 10 Mar 2020 16:38:04 +0000 Subject: [PATCH] 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 --- src/bin/ch-remote.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/bin/ch-remote.rs b/src/bin/ch-remote.rs index ed78f29c0..6e1dd164c 100644 --- a/src/bin/ch-remote.rs +++ b/src/bin/ch-remote.rs @@ -22,6 +22,7 @@ enum Error { ServerResponse(StatusCode), InvalidCPUCount(std::num::ParseIntError), InvalidMemorySize(std::num::ParseIntError), + AddDeviceConfig(vmm::config::Error), } #[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> { let mut 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() .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), None => unreachable!(), } @@ -225,6 +245,14 @@ fn main() { .min_values(1) .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=,iommu=on|off\"", + )), + ) .subcommand(SubCommand::with_name("info").about("Info on the VM")) .subcommand(SubCommand::with_name("pause").about("Pause the VM")) .subcommand(SubCommand::with_name("reboot").about("Reboot the VM"))