mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
ch-remote: add generic vhost-user support
Support adding generic vhost-user devices via the ch-remote CLI. Signed-off-by: Demi Marie Obenour <demiobenour@gmail.com>
This commit is contained in:
committed by
Rob Bradford
parent
cfb69c68d2
commit
36371283c6
@@ -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<Optional<String>>;
|
||||
fn vm_add_disk(&self, disk_config: &str) -> zbus::Result<Optional<String>>;
|
||||
fn vm_add_fs(&self, fs_config: &str) -> zbus::Result<Optional<String>>;
|
||||
fn vm_add_generic_vhost_user(
|
||||
&self,
|
||||
generic_vhost_user_config: &str,
|
||||
) -> zbus::Result<Optional<String>>;
|
||||
fn vm_add_net(&self, net_config: &str) -> zbus::Result<Optional<String>>;
|
||||
fn vm_add_pmem(&self, pmem_config: &str) -> zbus::Result<Optional<String>>;
|
||||
fn vm_add_user_device(&self, vm_add_user_device: &str) -> zbus::Result<Optional<String>>;
|
||||
@@ -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::<String>("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::<String>("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<String, Error> {
|
||||
Ok(fs_config)
|
||||
}
|
||||
|
||||
fn add_generic_vhost_user_config(config: &str) -> Result<String, Error> {
|
||||
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<String, Error> {
|
||||
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)),
|
||||
|
||||
Reference in New Issue
Block a user