mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
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 <sameo@linux.intel.com>
This commit is contained in:
committed by
Rob Bradford
parent
5f8a62f3d0
commit
3dc7aff00e
@@ -46,10 +46,10 @@ pub struct Blk {
|
|||||||
interrupt_cb: Option<Arc<VirtioInterrupt>>,
|
interrupt_cb: Option<Arc<VirtioInterrupt>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Blk {
|
impl Blk {
|
||||||
/// Create a new vhost-user-blk device
|
/// Create a new vhost-user-blk device
|
||||||
pub fn new(wce: bool, vu_cfg: VhostUserConfig<'a>) -> Result<Blk> {
|
pub fn new(wce: bool, vu_cfg: VhostUserConfig) -> Result<Blk> {
|
||||||
let mut vhost_user_blk = Master::connect(vu_cfg.sock, vu_cfg.num_queues as u64)
|
let mut vhost_user_blk = Master::connect(&vu_cfg.sock, vu_cfg.num_queues as u64)
|
||||||
.map_err(Error::VhostUserCreateMaster)?;
|
.map_err(Error::VhostUserCreateMaster)?;
|
||||||
|
|
||||||
// Filling device and vring features VMM supports.
|
// Filling device and vring features VMM supports.
|
||||||
|
|||||||
@@ -38,10 +38,10 @@ pub struct Net {
|
|||||||
queue_sizes: Vec<u16>,
|
queue_sizes: Vec<u16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Net {
|
impl Net {
|
||||||
/// Create a new vhost-user-net device
|
/// Create a new vhost-user-net device
|
||||||
pub fn new(mac_addr: MacAddr, vu_cfg: VhostUserConfig<'a>) -> Result<Net> {
|
pub fn new(mac_addr: MacAddr, vu_cfg: VhostUserConfig) -> Result<Net> {
|
||||||
let mut vhost_user_net = Master::connect(vu_cfg.sock, vu_cfg.num_queues as u64)
|
let mut vhost_user_net = Master::connect(&vu_cfg.sock, vu_cfg.num_queues as u64)
|
||||||
.map_err(Error::VhostUserCreateMaster)?;
|
.map_err(Error::VhostUserCreateMaster)?;
|
||||||
|
|
||||||
let kill_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::CreateKillEventFd)?;
|
let kill_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::CreateKillEventFd)?;
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ use super::{Error, Result};
|
|||||||
use vhost_rs::vhost_user::{Master, VhostUserMaster};
|
use vhost_rs::vhost_user::{Master, VhostUserMaster};
|
||||||
use vhost_rs::{VhostBackend, VhostUserMemoryRegionInfo, VringConfigData};
|
use vhost_rs::{VhostBackend, VhostUserMemoryRegionInfo, VringConfigData};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct VhostUserConfig<'a> {
|
pub struct VhostUserConfig {
|
||||||
pub sock: &'a str,
|
pub sock: String,
|
||||||
pub num_queues: usize,
|
pub num_queues: usize,
|
||||||
pub queue_size: u16,
|
pub queue_size: u16,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -463,13 +463,13 @@ impl DeviceConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct VhostUserNetConfig<'a> {
|
pub struct VhostUserNetConfig {
|
||||||
pub mac: MacAddr,
|
pub mac: MacAddr,
|
||||||
pub vu_cfg: VhostUserConfig<'a>,
|
pub vu_cfg: VhostUserConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VhostUserNetConfig<'a> {
|
impl VhostUserNetConfig {
|
||||||
pub fn parse(vhost_user_net: &'a str) -> Result<Self> {
|
pub fn parse(vhost_user_net: &str) -> Result<Self> {
|
||||||
// Split the parameters based on the comma delimiter
|
// Split the parameters based on the comma delimiter
|
||||||
let params_list: Vec<&str> = vhost_user_net.split(',').collect();
|
let params_list: Vec<&str> = vhost_user_net.split(',').collect();
|
||||||
|
|
||||||
@@ -512,7 +512,7 @@ impl<'a> VhostUserNetConfig<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let vu_cfg = VhostUserConfig {
|
let vu_cfg = VhostUserConfig {
|
||||||
sock,
|
sock: sock.to_string(),
|
||||||
num_queues,
|
num_queues,
|
||||||
queue_size,
|
queue_size,
|
||||||
};
|
};
|
||||||
@@ -553,13 +553,13 @@ impl<'a> VsockConfig<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct VhostUserBlkConfig<'a> {
|
pub struct VhostUserBlkConfig {
|
||||||
pub wce: bool,
|
pub wce: bool,
|
||||||
pub vu_cfg: VhostUserConfig<'a>,
|
pub vu_cfg: VhostUserConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> VhostUserBlkConfig<'a> {
|
impl VhostUserBlkConfig {
|
||||||
pub fn parse(vhost_user_blk: &'a str) -> Result<Self> {
|
pub fn parse(vhost_user_blk: &str) -> Result<Self> {
|
||||||
// Split the parameters based on the comma delimiter
|
// Split the parameters based on the comma delimiter
|
||||||
let params_list: Vec<&str> = vhost_user_blk.split(',').collect();
|
let params_list: Vec<&str> = vhost_user_blk.split(',').collect();
|
||||||
|
|
||||||
@@ -599,7 +599,7 @@ impl<'a> VhostUserBlkConfig<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let vu_cfg = VhostUserConfig {
|
let vu_cfg = VhostUserConfig {
|
||||||
sock,
|
sock: sock.to_string(),
|
||||||
num_queues,
|
num_queues,
|
||||||
queue_size,
|
queue_size,
|
||||||
};
|
};
|
||||||
@@ -621,8 +621,8 @@ pub struct VmConfig<'a> {
|
|||||||
pub serial: ConsoleConfig,
|
pub serial: ConsoleConfig,
|
||||||
pub console: ConsoleConfig,
|
pub console: ConsoleConfig,
|
||||||
pub devices: Option<Vec<DeviceConfig>>,
|
pub devices: Option<Vec<DeviceConfig>>,
|
||||||
pub vhost_user_net: Option<Vec<VhostUserNetConfig<'a>>>,
|
pub vhost_user_net: Option<Vec<VhostUserNetConfig>>,
|
||||||
pub vhost_user_blk: Option<Vec<VhostUserBlkConfig<'a>>>,
|
pub vhost_user_blk: Option<Vec<VhostUserBlkConfig>>,
|
||||||
pub vsock: Option<Vec<VsockConfig<'a>>>,
|
pub vsock: Option<Vec<VsockConfig<'a>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -773,7 +773,7 @@ impl DeviceManager {
|
|||||||
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 vhost_user_net_device = vm_virtio::vhost_user::Net::new(
|
||||||
vhost_user_net_cfg.mac,
|
vhost_user_net_cfg.mac,
|
||||||
vhost_user_net_cfg.vu_cfg,
|
vhost_user_net_cfg.vu_cfg.clone(),
|
||||||
)
|
)
|
||||||
.map_err(DeviceManagerError::CreateVhostUserNet)?;
|
.map_err(DeviceManagerError::CreateVhostUserNet)?;
|
||||||
|
|
||||||
@@ -793,7 +793,7 @@ impl DeviceManager {
|
|||||||
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 vhost_user_blk_device = vm_virtio::vhost_user::Blk::new(
|
||||||
vhost_user_blk_cfg.wce,
|
vhost_user_blk_cfg.wce,
|
||||||
vhost_user_blk_cfg.vu_cfg,
|
vhost_user_blk_cfg.vu_cfg.clone(),
|
||||||
)
|
)
|
||||||
.map_err(DeviceManagerError::CreateVhostUserBlk)?;
|
.map_err(DeviceManagerError::CreateVhostUserBlk)?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user