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

View File

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