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

View File

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