From 9c5bfb8e130e1422e511f63fa4231d9c3809dd88 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Mon, 23 Sep 2019 18:51:36 +0200 Subject: [PATCH] vmm: Make MemoryConfig owned Convert Path to PathBuf and remove the associated lifetime. Fixes #298 Signed-off-by: Samuel Ortiz --- vmm/src/config.rs | 14 +++++++------- vmm/src/vm.rs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 13530bf48..8f4ac0138 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; +use std::path::{Path, PathBuf}; use std::result; use vm_memory::GuestAddress; use vm_virtio::vhost_user::VhostUserConfig; @@ -132,13 +132,13 @@ impl From<&CpusConfig> for u8 { } } -pub struct MemoryConfig<'a> { +pub struct MemoryConfig { pub size: u64, - pub file: Option<&'a Path>, + pub file: Option, } -impl<'a> MemoryConfig<'a> { - pub fn parse(memory: &'a str) -> Result { +impl MemoryConfig { + pub fn parse(memory: &str) -> Result { // Split the parameters based on the comma delimiter let params_list: Vec<&str> = memory.split(',').collect(); @@ -160,7 +160,7 @@ impl<'a> MemoryConfig<'a> { return Err(Error::ParseMemoryFileParam); } - Some(Path::new(file_str)) + Some(PathBuf::from(file_str)) } else { None }; @@ -610,7 +610,7 @@ impl<'a> VhostUserBlkConfig<'a> { pub struct VmConfig<'a> { pub cpus: CpusConfig, - pub memory: MemoryConfig<'a>, + pub memory: MemoryConfig, pub kernel: KernelConfig<'a>, pub cmdline: CmdlineConfig, pub disks: Option>>, diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index c6d30228f..b0890213e 100755 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -564,7 +564,7 @@ impl<'a> Vm<'a> { } let guest_memory = match config.memory.file { - Some(file) => { + Some(ref file) => { let mut mem_regions = Vec::<(GuestAddress, usize, Option)>::new(); for region in ram_regions.iter() { if file.is_file() {