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 <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-03-13 10:25:17 +00:00
parent 477d924528
commit 7e599b4450
2 changed files with 31 additions and 6 deletions

View File

@ -335,7 +335,7 @@ impl CmdlineConfig {
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct DiskConfig {
pub path: PathBuf,
pub path: Option<PathBuf>,
#[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)?,

View File

@ -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<T> = result::Result<T, DeviceManagerError>;
@ -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,