vmm: device_manager: Add read-only support for virtio-blk

vhost_user_blk already has it, so it's only fair to give it to
virtio-blk too. Extend DiskConfig with a 'readonly' properly, and pass
it to vm_virtio::Block.

Signed-off-by: Sergio Lopez <slp@redhat.com>
This commit is contained in:
Sergio Lopez 2020-01-21 12:22:09 +01:00 committed by Rob Bradford
parent 9ac06bf613
commit fb79e75afc
2 changed files with 9 additions and 3 deletions

View File

@ -338,6 +338,8 @@ impl CmdlineConfig {
pub struct DiskConfig {
pub path: PathBuf,
#[serde(default)]
pub readonly: bool,
#[serde(default)]
pub iommu: bool,
}
@ -347,11 +349,14 @@ impl DiskConfig {
let params_list: Vec<&str> = disk.split(',').collect();
let mut path_str: &str = "";
let mut readonly_str: &str = "";
let mut iommu_str: &str = "";
for param in params_list.iter() {
if param.starts_with("path=") {
path_str = &param[5..];
} else if param.starts_with("readonly=") {
readonly_str = &param[9..];
} else if param.starts_with("iommu=") {
iommu_str = &param[6..];
}
@ -359,6 +364,7 @@ impl DiskConfig {
Ok(DiskConfig {
path: PathBuf::from(path_str),
readonly: parse_on_off(readonly_str)?,
iommu: parse_on_off(iommu_str)?,
})
}

View File

@ -938,7 +938,7 @@ impl DeviceManager {
// Open block device path
let image: File = OpenOptions::new()
.read(true)
.write(true)
.write(!disk_cfg.readonly)
.open(&disk_cfg.path)
.map_err(DeviceManagerError::Disk)?;
@ -951,7 +951,7 @@ impl DeviceManager {
let dev = vm_virtio::Block::new(
raw_img,
disk_cfg.path.clone(),
false,
disk_cfg.readonly,
disk_cfg.iommu,
)
.map_err(DeviceManagerError::CreateVirtioBlock)?;
@ -970,7 +970,7 @@ impl DeviceManager {
let dev = vm_virtio::Block::new(
qcow_img,
disk_cfg.path.clone(),
false,
disk_cfg.readonly,
disk_cfg.iommu,
)
.map_err(DeviceManagerError::CreateVirtioBlock)?;