From 7e599b445076ec4976690570edc3b43ac49e0d04 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Fri, 13 Mar 2020 10:25:17 +0000 Subject: [PATCH] vmm: Make disk path optional When using "--disk" with a vhost socket and not using self spawning then it is not necessary or helpful to specify the path. Signed-off-by: Rob Bradford --- vmm/src/config.rs | 8 ++++++-- vmm/src/device_manager.rs | 29 +++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index fb045f68c..e656524b6 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -335,7 +335,7 @@ impl CmdlineConfig { #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct DiskConfig { - pub path: PathBuf, + pub path: Option, #[serde(default)] pub readonly: bool, #[serde(default)] @@ -417,6 +417,7 @@ impl DiskConfig { let mut vhost_socket = None; let mut wce: bool = default_diskconfig_wce(); let mut poll_queue: bool = default_diskconfig_poll_queue(); + let mut path = None; if !num_queues_str.is_empty() { num_queues = num_queues_str @@ -448,9 +449,12 @@ impl DiskConfig { .parse() .map_err(Error::ParseDiskPollQueueParam)?; } + if !path_str.is_empty() { + path = Some(PathBuf::from(path_str)) + } Ok(DiskConfig { - path: PathBuf::from(path_str), + path, readonly: parse_on_off(readonly_str)?, direct: parse_on_off(direct_str)?, iommu: parse_on_off(iommu_str)?, diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 14cdbab62..9b9e731f6 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -255,6 +255,9 @@ pub enum DeviceManagerError { /// Incorrect device ID as it is already used by another device. DeviceIdAlreadyInUse, + + // No disk path was specified when one was expected + NoDiskPath, } pub type DeviceManagerResult = result::Result; @@ -1026,7 +1029,12 @@ impl DeviceManager { "--block-backend", &format!( "image={},sock={},num_queues={},queue_size={}", - disk_cfg.path.to_str().unwrap(), + disk_cfg + .path + .as_ref() + .ok_or(DeviceManagerError::NoDiskPath)? + .to_str() + .unwrap(), &sock, disk_cfg.num_queues, disk_cfg.queue_size @@ -1083,7 +1091,12 @@ impl DeviceManager { } // Open block device path let image: File = options - .open(&disk_cfg.path) + .open( + &disk_cfg + .path + .as_ref() + .ok_or(DeviceManagerError::NoDiskPath)?, + ) .map_err(DeviceManagerError::Disk)?; let mut raw_img = vm_virtio::RawFile::new(image, disk_cfg.direct); @@ -1094,7 +1107,11 @@ impl DeviceManager { ImageType::Raw => { let dev = vm_virtio::Block::new( raw_img, - disk_cfg.path.clone(), + disk_cfg + .path + .as_ref() + .ok_or(DeviceManagerError::NoDiskPath)? + .clone(), disk_cfg.readonly, disk_cfg.iommu, disk_cfg.num_queues, @@ -1116,7 +1133,11 @@ impl DeviceManager { .map_err(DeviceManagerError::QcowDeviceCreate)?; let dev = vm_virtio::Block::new( qcow_img, - disk_cfg.path.clone(), + disk_cfg + .path + .as_ref() + .ok_or(DeviceManagerError::NoDiskPath)? + .clone(), disk_cfg.readonly, disk_cfg.iommu, disk_cfg.num_queues,