diff --git a/cloud-hypervisor/src/bin/ch-remote.rs b/cloud-hypervisor/src/bin/ch-remote.rs index fd48ffab1..6939eaa38 100644 --- a/cloud-hypervisor/src/bin/ch-remote.rs +++ b/cloud-hypervisor/src/bin/ch-remote.rs @@ -22,8 +22,8 @@ use option_parser::{ByteSized, ByteSizedParseError}; use thiserror::Error; use vmm::config::RestoreConfig; use vmm::vm_config::{ - DeviceConfig, DiskConfig, FsConfig, NetConfig, PmemConfig, UserDeviceConfig, VdpaConfig, - VsockConfig, + DeviceConfig, DiskConfig, FsConfig, GenericVhostUserConfig, NetConfig, PmemConfig, + UserDeviceConfig, VdpaConfig, VsockConfig, }; #[cfg(feature = "dbus_api")] use zbus::{proxy, zvariant::Optional}; @@ -49,6 +49,8 @@ enum Error { AddDiskConfig(#[source] vmm::config::Error), #[error("Error parsing filesystem syntax")] AddFsConfig(#[source] vmm::config::Error), + #[error("Error parsing generic vhost-user syntax")] + AddGenericVhostUserConfig(#[source] vmm::config::Error), #[error("Error parsing persistent memory syntax")] AddPmemConfig(#[source] vmm::config::Error), #[error("Error parsing network syntax")] @@ -83,6 +85,10 @@ trait DBusApi1 { fn vm_add_device(&self, device_config: &str) -> zbus::Result>; fn vm_add_disk(&self, disk_config: &str) -> zbus::Result>; fn vm_add_fs(&self, fs_config: &str) -> zbus::Result>; + fn vm_add_generic_vhost_user( + &self, + generic_vhost_user_config: &str, + ) -> zbus::Result>; fn vm_add_net(&self, net_config: &str) -> zbus::Result>; fn vm_add_pmem(&self, pmem_config: &str) -> zbus::Result>; fn vm_add_user_device(&self, vm_add_user_device: &str) -> zbus::Result>; @@ -155,6 +161,10 @@ impl<'a> DBusApi1ProxyBlocking<'a> { self.print_response(self.vm_add_fs(fs_config)) } + fn api_vm_add_generic_vhost_user(&self, generic_vhost_user_config: &str) -> ApiResult { + self.print_response(self.vm_add_generic_vhost_user(generic_vhost_user_config)) + } + fn api_vm_add_net(&self, net_config: &str) -> ApiResult { self.print_response(self.vm_add_net(net_config)) } @@ -398,6 +408,22 @@ fn rest_api_do_command(matches: &ArgMatches, socket: &mut UnixStream) -> ApiResu simple_api_command(socket, "PUT", "add-fs", Some(&fs_config)) .map_err(Error::HttpApiClient) } + Some("add-generic-vhost-user") => { + let device_config = add_generic_vhost_user_config( + matches + .subcommand_matches("add-generic-vhost-user") + .unwrap() + .get_one::("generic_vhost_user_config") + .unwrap(), + )?; + simple_api_command( + socket, + "PUT", + "add-generic-vhost-user", + Some(&device_config), + ) + .map_err(Error::HttpApiClient) + } Some("add-pmem") => { let pmem_config = add_pmem_config( matches @@ -620,6 +646,16 @@ fn dbus_api_do_command(matches: &ArgMatches, proxy: &DBusApi1ProxyBlocking<'_>) )?; proxy.api_vm_add_fs(&fs_config) } + Some("add-generic-vhost-user") => { + let generic_vhost_user_config = add_generic_vhost_user_config( + matches + .subcommand_matches("add-generic-vhost-user") + .unwrap() + .get_one::("generic_vhost_user_config") + .unwrap(), + )?; + proxy.api_vm_add_generic_vhost_user(&generic_vhost_user_config) + } Some("add-pmem") => { let pmem_config = add_pmem_config( matches @@ -835,6 +871,14 @@ fn add_fs_config(config: &str) -> Result { Ok(fs_config) } +fn add_generic_vhost_user_config(config: &str) -> Result { + let generic_vhost_user_config = + GenericVhostUserConfig::parse(config).map_err(Error::AddGenericVhostUserConfig)?; + let generic_vhost_user_config = serde_json::to_string(&generic_vhost_user_config).unwrap(); + + Ok(generic_vhost_user_config) +} + fn add_pmem_config(config: &str) -> Result { let pmem_config = PmemConfig::parse(config).map_err(Error::AddPmemConfig)?; let pmem_config = serde_json::to_string(&pmem_config).unwrap(); @@ -981,6 +1025,13 @@ fn get_cli_commands_sorted() -> Box<[Command]> { .index(1) .help(vmm::vm_config::FsConfig::SYNTAX), ), + Command::new("add-generic-vhost-user") + .about("Add generic vhost-user device") + .arg( + Arg::new("generic_vhost_user_config") + .index(1) + .help(vmm::vm_config::GenericVhostUserConfig::SYNTAX), + ), Command::new("add-net") .about("Add network device") .arg(Arg::new("net_config").index(1).help(NetConfig::SYNTAX)),