From acc60b0ad581aabecaab2b9dfcf3010bbbfb21e2 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Mon, 23 Sep 2019 19:46:35 +0200 Subject: [PATCH] vmm: Make VsockConfig owned Convert Path to PathBuf and remove the associated lifetime. Now we can remove the VmConfig associated lifetime. Fixes #298 Signed-off-by: Samuel Ortiz --- vmm/src/config.rs | 20 ++++++++++---------- vmm/src/vm.rs | 6 +++--- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index bd8864fa0..3dc0dd9c9 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -10,7 +10,7 @@ use net_util::MacAddr; use std::convert::From; use std::net::AddrParseError; use std::net::Ipv4Addr; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use std::result; use vm_memory::GuestAddress; use vm_virtio::vhost_user::VhostUserConfig; @@ -521,13 +521,13 @@ impl VhostUserNetConfig { } } -pub struct VsockConfig<'a> { +pub struct VsockConfig { pub cid: u64, - pub sock: &'a Path, + pub sock: PathBuf, } -impl<'a> VsockConfig<'a> { - pub fn parse(vsock: &'a str) -> Result { +impl VsockConfig { + pub fn parse(vsock: &str) -> Result { // Split the parameters based on the comma delimiter let params_list: Vec<&str> = vsock.split(',').collect(); @@ -548,7 +548,7 @@ impl<'a> VsockConfig<'a> { Ok(VsockConfig { cid: cid_str.parse::().map_err(Error::ParseVsockCidParam)?, - sock: Path::new(sock_str), + sock: PathBuf::from(sock_str), }) } } @@ -608,7 +608,7 @@ impl VhostUserBlkConfig { } } -pub struct VmConfig<'a> { +pub struct VmConfig { pub cpus: CpusConfig, pub memory: MemoryConfig, pub kernel: KernelConfig, @@ -623,11 +623,11 @@ pub struct VmConfig<'a> { pub devices: Option>, pub vhost_user_net: Option>, pub vhost_user_blk: Option>, - pub vsock: Option>>, + pub vsock: Option>, } -impl<'a> VmConfig<'a> { - pub fn parse(vm_params: VmParams<'a>) -> Result { +impl VmConfig { + pub fn parse(vm_params: VmParams) -> Result { let mut disks: Option> = None; if let Some(disk_list) = &vm_params.disks { let mut disk_config_list = Vec::new(); diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index b0890213e..9e59827e0 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -426,7 +426,7 @@ impl Vcpu { pub struct VmInfo<'a> { pub memory: &'a Arc>, pub vm_fd: &'a Arc, - pub vm_cfg: &'a VmConfig<'a>, + pub vm_cfg: &'a VmConfig, } #[derive(Debug, Clone, Copy, PartialEq)] @@ -507,7 +507,7 @@ pub struct Vm<'a> { threads: Vec>, devices: DeviceManager, cpuid: CpuId, - config: &'a VmConfig<'a>, + config: &'a VmConfig, epoll: EpollContext, on_tty: bool, creation_ts: std::time::Instant, @@ -533,7 +533,7 @@ fn get_host_cpu_phys_bits() -> u8 { } impl<'a> Vm<'a> { - pub fn new(kvm: &Kvm, config: &'a VmConfig<'a>) -> Result { + pub fn new(kvm: &Kvm, config: &'a VmConfig) -> Result { let kernel = File::open(&config.kernel.path).map_err(Error::KernelFile)?; let fd = kvm.create_vm().map_err(Error::VmCreate)?; let fd = Arc::new(fd);