From 3dc7aff00efe2ace712e8d21ee22042c4e36a9b6 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Mon, 23 Sep 2019 19:42:52 +0200 Subject: [PATCH] vmm: Make vhost-user configuration owned Convert Path to PathBuf, &str to String and remove the associated lifetime. Fixes #298 Signed-off-by: Samuel Ortiz --- vm-virtio/src/vhost_user/blk.rs | 6 +++--- vm-virtio/src/vhost_user/net.rs | 6 +++--- vm-virtio/src/vhost_user/vu_common_ctrl.rs | 6 +++--- vmm/src/config.rs | 24 +++++++++++----------- vmm/src/device_manager.rs | 4 ++-- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/vm-virtio/src/vhost_user/blk.rs b/vm-virtio/src/vhost_user/blk.rs index ed6abc008..524b40599 100644 --- a/vm-virtio/src/vhost_user/blk.rs +++ b/vm-virtio/src/vhost_user/blk.rs @@ -46,10 +46,10 @@ pub struct Blk { interrupt_cb: Option>, } -impl<'a> Blk { +impl Blk { /// Create a new vhost-user-blk device - pub fn new(wce: bool, vu_cfg: VhostUserConfig<'a>) -> Result { - let mut vhost_user_blk = Master::connect(vu_cfg.sock, vu_cfg.num_queues as u64) + pub fn new(wce: bool, vu_cfg: VhostUserConfig) -> Result { + let mut vhost_user_blk = Master::connect(&vu_cfg.sock, vu_cfg.num_queues as u64) .map_err(Error::VhostUserCreateMaster)?; // Filling device and vring features VMM supports. diff --git a/vm-virtio/src/vhost_user/net.rs b/vm-virtio/src/vhost_user/net.rs index 14a44c5b0..53143a344 100644 --- a/vm-virtio/src/vhost_user/net.rs +++ b/vm-virtio/src/vhost_user/net.rs @@ -38,10 +38,10 @@ pub struct Net { queue_sizes: Vec, } -impl<'a> Net { +impl Net { /// Create a new vhost-user-net device - pub fn new(mac_addr: MacAddr, vu_cfg: VhostUserConfig<'a>) -> Result { - let mut vhost_user_net = Master::connect(vu_cfg.sock, vu_cfg.num_queues as u64) + pub fn new(mac_addr: MacAddr, vu_cfg: VhostUserConfig) -> Result { + let mut vhost_user_net = Master::connect(&vu_cfg.sock, vu_cfg.num_queues as u64) .map_err(Error::VhostUserCreateMaster)?; let kill_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::CreateKillEventFd)?; diff --git a/vm-virtio/src/vhost_user/vu_common_ctrl.rs b/vm-virtio/src/vhost_user/vu_common_ctrl.rs index 7639c0c0a..935c3c0e2 100644 --- a/vm-virtio/src/vhost_user/vu_common_ctrl.rs +++ b/vm-virtio/src/vhost_user/vu_common_ctrl.rs @@ -14,9 +14,9 @@ use super::{Error, Result}; use vhost_rs::vhost_user::{Master, VhostUserMaster}; use vhost_rs::{VhostBackend, VhostUserMemoryRegionInfo, VringConfigData}; -#[derive(Debug, Copy, Clone)] -pub struct VhostUserConfig<'a> { - pub sock: &'a str, +#[derive(Debug, Clone)] +pub struct VhostUserConfig { + pub sock: String, pub num_queues: usize, pub queue_size: u16, } diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 704adb466..bd8864fa0 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -463,13 +463,13 @@ impl DeviceConfig { } } -pub struct VhostUserNetConfig<'a> { +pub struct VhostUserNetConfig { pub mac: MacAddr, - pub vu_cfg: VhostUserConfig<'a>, + pub vu_cfg: VhostUserConfig, } -impl<'a> VhostUserNetConfig<'a> { - pub fn parse(vhost_user_net: &'a str) -> Result { +impl VhostUserNetConfig { + pub fn parse(vhost_user_net: &str) -> Result { // Split the parameters based on the comma delimiter let params_list: Vec<&str> = vhost_user_net.split(',').collect(); @@ -512,7 +512,7 @@ impl<'a> VhostUserNetConfig<'a> { } let vu_cfg = VhostUserConfig { - sock, + sock: sock.to_string(), num_queues, queue_size, }; @@ -553,13 +553,13 @@ impl<'a> VsockConfig<'a> { } } -pub struct VhostUserBlkConfig<'a> { +pub struct VhostUserBlkConfig { pub wce: bool, - pub vu_cfg: VhostUserConfig<'a>, + pub vu_cfg: VhostUserConfig, } -impl<'a> VhostUserBlkConfig<'a> { - pub fn parse(vhost_user_blk: &'a str) -> Result { +impl VhostUserBlkConfig { + pub fn parse(vhost_user_blk: &str) -> Result { // Split the parameters based on the comma delimiter let params_list: Vec<&str> = vhost_user_blk.split(',').collect(); @@ -599,7 +599,7 @@ impl<'a> VhostUserBlkConfig<'a> { } let vu_cfg = VhostUserConfig { - sock, + sock: sock.to_string(), num_queues, queue_size, }; @@ -621,8 +621,8 @@ pub struct VmConfig<'a> { pub serial: ConsoleConfig, pub console: ConsoleConfig, pub devices: Option>, - pub vhost_user_net: Option>>, - pub vhost_user_blk: Option>>, + pub vhost_user_net: Option>, + pub vhost_user_blk: Option>, pub vsock: Option>>, } diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index e26a3e5c8..bcbe9e17e 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -773,7 +773,7 @@ impl DeviceManager { 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, + vhost_user_net_cfg.vu_cfg.clone(), ) .map_err(DeviceManagerError::CreateVhostUserNet)?; @@ -793,7 +793,7 @@ impl DeviceManager { 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, + vhost_user_blk_cfg.vu_cfg.clone(), ) .map_err(DeviceManagerError::CreateVhostUserBlk)?;