vmm: config: Make VhostUser configs serializable

They point to a vm_virtio structure (VhostUserConfig) and in order to
make the whole config serializable (through the serde crate for
example), we'd have to add a serde dependency to the vm_virtio crate.

Instead we use a local, serializable structure and convert it to
VhostUserConfig from the DeviceManager code.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2019-09-27 09:46:19 +02:00
parent aa31748781
commit 6a722e5c0b
2 changed files with 28 additions and 15 deletions

View File

@ -12,7 +12,6 @@ use std::net::AddrParseError;
use std::net::Ipv4Addr;
use std::path::PathBuf;
use std::result;
use vm_virtio::vhost_user::VhostUserConfig;
pub const DEFAULT_VCPUS: &str = "1";
pub const DEFAULT_MEMORY: &str = "size=512M";
@ -459,10 +458,17 @@ impl DeviceConfig {
}
}
#[derive(Clone, Debug)]
pub struct VuConfig {
pub sock: String,
pub num_queues: usize,
pub queue_size: u16,
}
#[derive(Clone, Debug)]
pub struct VhostUserNetConfig {
pub mac: MacAddr,
pub vu_cfg: VhostUserConfig,
pub vu_cfg: VuConfig,
}
impl VhostUserNetConfig {
@ -508,7 +514,7 @@ impl VhostUserNetConfig {
.map_err(Error::ParseVuQueueSizeParam)?;
}
let vu_cfg = VhostUserConfig {
let vu_cfg = VuConfig {
sock: sock.to_string(),
num_queues,
queue_size,
@ -554,7 +560,7 @@ impl VsockConfig {
#[derive(Clone, Debug)]
pub struct VhostUserBlkConfig {
pub wce: bool,
pub vu_cfg: VhostUserConfig,
pub vu_cfg: VuConfig,
}
impl VhostUserBlkConfig {
@ -597,7 +603,7 @@ impl VhostUserBlkConfig {
wce = wce_str.parse().map_err(Error::ParseVuBlkWceParam)?;
}
let vu_cfg = VhostUserConfig {
let vu_cfg = VuConfig {
sock: sock.to_string(),
num_queues,
queue_size,

View File

@ -43,6 +43,7 @@ use vm_memory::GuestAddress;
use vm_memory::{Address, GuestMemoryMmap, GuestUsize};
#[cfg(feature = "pci_support")]
use vm_virtio::transport::VirtioPciDevice;
use vm_virtio::vhost_user::VhostUserConfig;
use vm_virtio::{VirtioSharedMemory, VirtioSharedMemoryList};
use vmm_sys_util::eventfd::EventFd;
@ -801,11 +802,14 @@ impl DeviceManager {
// Add vhost-user-net if required
if let Some(vhost_user_net_list_cfg) = &vm_info.vm_cfg.vhost_user_net {
for vhost_user_net_cfg in vhost_user_net_list_cfg.iter() {
let vhost_user_net_device = vm_virtio::vhost_user::Net::new(
vhost_user_net_cfg.mac,
vhost_user_net_cfg.vu_cfg.clone(),
)
.map_err(DeviceManagerError::CreateVhostUserNet)?;
let vu_cfg = VhostUserConfig {
sock: vhost_user_net_cfg.vu_cfg.sock.clone(),
num_queues: vhost_user_net_cfg.vu_cfg.num_queues,
queue_size: vhost_user_net_cfg.vu_cfg.queue_size,
};
let vhost_user_net_device =
vm_virtio::vhost_user::Net::new(vhost_user_net_cfg.mac, vu_cfg)
.map_err(DeviceManagerError::CreateVhostUserNet)?;
devices.push(Box::new(vhost_user_net_device) as Box<dyn vm_virtio::VirtioDevice>);
}
@ -821,11 +825,14 @@ impl DeviceManager {
// Add vhost-user-blk if required
if let Some(vhost_user_blk_list_cfg) = &vm_info.vm_cfg.vhost_user_blk {
for vhost_user_blk_cfg in vhost_user_blk_list_cfg.iter() {
let vhost_user_blk_device = vm_virtio::vhost_user::Blk::new(
vhost_user_blk_cfg.wce,
vhost_user_blk_cfg.vu_cfg.clone(),
)
.map_err(DeviceManagerError::CreateVhostUserBlk)?;
let vu_cfg = VhostUserConfig {
sock: vhost_user_blk_cfg.vu_cfg.sock.clone(),
num_queues: vhost_user_blk_cfg.vu_cfg.num_queues,
queue_size: vhost_user_blk_cfg.vu_cfg.queue_size,
};
let vhost_user_blk_device =
vm_virtio::vhost_user::Blk::new(vhost_user_blk_cfg.wce, vu_cfg)
.map_err(DeviceManagerError::CreateVhostUserBlk)?;
devices.push(Box::new(vhost_user_blk_device) as Box<dyn vm_virtio::VirtioDevice>);
}