vmm: Make DiskConfig 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:12:19 +02:00 committed by Rob Bradford
parent 036890e5be
commit 675e46355c
2 changed files with 11 additions and 13 deletions

View File

@ -205,14 +205,14 @@ impl CmdlineConfig {
} }
#[derive(Debug)] #[derive(Debug)]
pub struct DiskConfig<'a> { pub struct DiskConfig {
pub path: &'a Path, pub path: PathBuf,
} }
impl<'a> DiskConfig<'a> { impl DiskConfig {
pub fn parse(disk: &'a str) -> Result<Self> { pub fn parse(disk: &str) -> Result<Self> {
Ok(DiskConfig { Ok(DiskConfig {
path: Path::new(disk), path: PathBuf::from(disk),
}) })
} }
} }
@ -613,7 +613,7 @@ pub struct VmConfig<'a> {
pub memory: MemoryConfig, pub memory: MemoryConfig,
pub kernel: KernelConfig, pub kernel: KernelConfig,
pub cmdline: CmdlineConfig, pub cmdline: CmdlineConfig,
pub disks: Option<Vec<DiskConfig<'a>>>, pub disks: Option<Vec<DiskConfig>>,
pub net: Option<Vec<NetConfig<'a>>>, pub net: Option<Vec<NetConfig<'a>>>,
pub rng: RngConfig<'a>, pub rng: RngConfig<'a>,
pub fs: Option<Vec<FsConfig<'a>>>, pub fs: Option<Vec<FsConfig<'a>>>,

View File

@ -540,7 +540,7 @@ impl DeviceManager {
let raw_img: File = OpenOptions::new() let raw_img: File = OpenOptions::new()
.read(true) .read(true)
.write(true) .write(true)
.open(disk_cfg.path) .open(&disk_cfg.path)
.map_err(DeviceManagerError::Disk)?; .map_err(DeviceManagerError::Disk)?;
let image_type = qcow::detect_image_type(&raw_img) let image_type = qcow::detect_image_type(&raw_img)
@ -548,17 +548,15 @@ impl DeviceManager {
let block = match image_type { let block = match image_type {
ImageType::Raw => { ImageType::Raw => {
let raw_img = vm_virtio::RawFile::new(raw_img); let raw_img = vm_virtio::RawFile::new(raw_img);
let dev = let dev = vm_virtio::Block::new(raw_img, disk_cfg.path.clone(), false)
vm_virtio::Block::new(raw_img, disk_cfg.path.to_path_buf(), false) .map_err(DeviceManagerError::CreateVirtioBlock)?;
.map_err(DeviceManagerError::CreateVirtioBlock)?;
Box::new(dev) as Box<dyn vm_virtio::VirtioDevice> Box::new(dev) as Box<dyn vm_virtio::VirtioDevice>
} }
ImageType::Qcow2 => { ImageType::Qcow2 => {
let qcow_img = QcowFile::from(raw_img) let qcow_img = QcowFile::from(raw_img)
.map_err(DeviceManagerError::QcowDeviceCreate)?; .map_err(DeviceManagerError::QcowDeviceCreate)?;
let dev = let dev = vm_virtio::Block::new(qcow_img, disk_cfg.path.clone(), false)
vm_virtio::Block::new(qcow_img, disk_cfg.path.to_path_buf(), false) .map_err(DeviceManagerError::CreateVirtioBlock)?;
.map_err(DeviceManagerError::CreateVirtioBlock)?;
Box::new(dev) as Box<dyn vm_virtio::VirtioDevice> Box::new(dev) as Box<dyn vm_virtio::VirtioDevice>
} }
}; };