From 9a7d9c94654135682c88fec82c6cb0534a0e9826 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Tue, 10 Mar 2020 16:38:04 +0000 Subject: [PATCH] ch-remote: Support removing VFIO devices Add a "remove-device" command that allows removing VFIO devices from the VM after boot. Signed-off-by: Rob Bradford --- src/bin/ch-remote.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/bin/ch-remote.rs b/src/bin/ch-remote.rs index 6e1dd164c..38964b455 100644 --- a/src/bin/ch-remote.rs +++ b/src/bin/ch-remote.rs @@ -202,6 +202,17 @@ fn add_device_api_command(socket: &mut UnixStream, config: &str) -> Result<(), E ) } +fn remove_device_api_command(socket: &mut UnixStream, id: &str) -> Result<(), Error> { + let remove_device_data = vmm::api::VmRemoveDeviceData { id: id.to_owned() }; + + simple_api_command( + socket, + "PUT", + "remove-device", + Some(&serde_json::to_string(&remove_device_data).unwrap()), + ) +} + fn do_command(matches: &ArgMatches) -> Result<(), Error> { let mut socket = UnixStream::connect(matches.value_of("api-socket").unwrap()).map_err(Error::Socket)?; @@ -227,6 +238,14 @@ fn do_command(matches: &ArgMatches) -> Result<(), Error> { .value_of("device_config") .unwrap(), ), + Some("remove-device") => remove_device_api_command( + &mut socket, + matches + .subcommand_matches("remove-device") + .unwrap() + .value_of("id") + .unwrap(), + ), Some(c) => simple_api_command(&mut socket, "PUT", c, None), None => unreachable!(), } @@ -250,9 +269,14 @@ fn main() { .about("Add VFIO device") .arg(Arg::with_name("device_config").index(1).help( "Direct device assignment parameters \ - \"path=,iommu=on|off\"", + \"path=,iommu=on|off,id=\"", )), ) + .subcommand( + SubCommand::with_name("remove-device") + .about("Remove VFIO device") + .arg(Arg::with_name("id").index(1).help("")), + ) .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"))