mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-11-04 19:11:11 +00:00
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:
parent
9ac06bf613
commit
fb79e75afc
@ -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 = ¶m[5..];
|
||||
} else if param.starts_with("readonly=") {
|
||||
readonly_str = ¶m[9..];
|
||||
} else if param.starts_with("iommu=") {
|
||||
iommu_str = ¶m[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)?,
|
||||
})
|
||||
}
|
||||
|
@ -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)?;
|
||||
|
Loading…
Reference in New Issue
Block a user