vmm: Make ConsoleConfig owned

Convert Path to PathBuf and remove the associated lifetime.

Fixes #298

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2019-09-23 19:30:22 +02:00 committed by Rob Bradford
parent 79a02f9171
commit 36137232f0
2 changed files with 9 additions and 9 deletions

View File

@ -417,13 +417,13 @@ impl ConsoleOutputMode {
} }
} }
pub struct ConsoleConfig<'a> { pub struct ConsoleConfig {
pub file: Option<&'a Path>, pub file: Option<PathBuf>,
pub mode: ConsoleOutputMode, pub mode: ConsoleOutputMode,
} }
impl<'a> ConsoleConfig<'a> { impl ConsoleConfig {
pub fn parse(param: &'a str) -> Result<Self> { pub fn parse(param: &str) -> Result<Self> {
if param == "off" { if param == "off" {
Ok(Self { Ok(Self {
mode: ConsoleOutputMode::Off, mode: ConsoleOutputMode::Off,
@ -437,7 +437,7 @@ impl<'a> ConsoleConfig<'a> {
} else if param.starts_with("file=") { } else if param.starts_with("file=") {
Ok(Self { Ok(Self {
mode: ConsoleOutputMode::File, mode: ConsoleOutputMode::File,
file: Some(Path::new(&param[5..])), file: Some(PathBuf::from(&param[5..])),
}) })
} else if param.starts_with("null") { } else if param.starts_with("null") {
Ok(Self { Ok(Self {
@ -618,8 +618,8 @@ pub struct VmConfig<'a> {
pub rng: RngConfig, pub rng: RngConfig,
pub fs: Option<Vec<FsConfig>>, pub fs: Option<Vec<FsConfig>>,
pub pmem: Option<Vec<PmemConfig>>, pub pmem: Option<Vec<PmemConfig>>,
pub serial: ConsoleConfig<'a>, pub serial: ConsoleConfig,
pub console: ConsoleConfig<'a>, pub console: ConsoleConfig,
pub devices: Option<Vec<DeviceConfig<'a>>>, pub devices: Option<Vec<DeviceConfig<'a>>>,
pub vhost_user_net: Option<Vec<VhostUserNetConfig<'a>>>, pub vhost_user_net: Option<Vec<VhostUserNetConfig<'a>>>,
pub vhost_user_blk: Option<Vec<VhostUserBlkConfig<'a>>>, pub vhost_user_blk: Option<Vec<VhostUserBlkConfig<'a>>>,

View File

@ -325,7 +325,7 @@ impl DeviceManager {
let serial_writer: Option<Box<dyn io::Write + Send>> = match vm_info.vm_cfg.serial.mode { let serial_writer: Option<Box<dyn io::Write + Send>> = match vm_info.vm_cfg.serial.mode {
ConsoleOutputMode::File => Some(Box::new( 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)?, .map_err(DeviceManagerError::SerialOutputFileOpen)?,
)), )),
ConsoleOutputMode::Tty => Some(Box::new(stdout())), ConsoleOutputMode::Tty => Some(Box::new(stdout())),
@ -386,7 +386,7 @@ impl DeviceManager {
let console_writer: Option<Box<dyn io::Write + Send>> = match vm_info.vm_cfg.console.mode { let console_writer: Option<Box<dyn io::Write + Send>> = match vm_info.vm_cfg.console.mode {
ConsoleOutputMode::File => Some(Box::new( 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)?, .map_err(DeviceManagerError::ConsoleOutputFileOpen)?,
)), )),
ConsoleOutputMode::Tty => Some(Box::new(stdout())), ConsoleOutputMode::Tty => Some(Box::new(stdout())),