From 36137232f0065d0d567d33c10e8744c7a0047839 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Mon, 23 Sep 2019 19:30:22 +0200 Subject: [PATCH] vmm: Make ConsoleConfig owned Convert Path to PathBuf and remove the associated lifetime. Fixes #298 Signed-off-by: Samuel Ortiz --- vmm/src/config.rs | 14 +++++++------- vmm/src/device_manager.rs | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 7909c887c..b732c5bdf 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -417,13 +417,13 @@ impl ConsoleOutputMode { } } -pub struct ConsoleConfig<'a> { - pub file: Option<&'a Path>, +pub struct ConsoleConfig { + pub file: Option, pub mode: ConsoleOutputMode, } -impl<'a> ConsoleConfig<'a> { - pub fn parse(param: &'a str) -> Result { +impl ConsoleConfig { + pub fn parse(param: &str) -> Result { if param == "off" { Ok(Self { mode: ConsoleOutputMode::Off, @@ -437,7 +437,7 @@ impl<'a> ConsoleConfig<'a> { } else if param.starts_with("file=") { Ok(Self { mode: ConsoleOutputMode::File, - file: Some(Path::new(¶m[5..])), + file: Some(PathBuf::from(¶m[5..])), }) } else if param.starts_with("null") { Ok(Self { @@ -618,8 +618,8 @@ pub struct VmConfig<'a> { pub rng: RngConfig, pub fs: Option>, pub pmem: Option>, - pub serial: ConsoleConfig<'a>, - pub console: ConsoleConfig<'a>, + pub serial: ConsoleConfig, + pub console: ConsoleConfig, pub devices: Option>>, pub vhost_user_net: Option>>, pub vhost_user_blk: Option>>, diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index ee4346c7a..567282ae4 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -325,7 +325,7 @@ impl DeviceManager { let serial_writer: Option> = match vm_info.vm_cfg.serial.mode { ConsoleOutputMode::File => Some(Box::new( - File::create(vm_info.vm_cfg.serial.file.unwrap()) + File::create(vm_info.vm_cfg.serial.file.as_ref().unwrap()) .map_err(DeviceManagerError::SerialOutputFileOpen)?, )), ConsoleOutputMode::Tty => Some(Box::new(stdout())), @@ -386,7 +386,7 @@ impl DeviceManager { let console_writer: Option> = match vm_info.vm_cfg.console.mode { ConsoleOutputMode::File => Some(Box::new( - File::create(vm_info.vm_cfg.console.file.unwrap()) + File::create(vm_info.vm_cfg.console.file.as_ref().unwrap()) .map_err(DeviceManagerError::ConsoleOutputFileOpen)?, )), ConsoleOutputMode::Tty => Some(Box::new(stdout())),