vmm: device_manager: Add 'direct' 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 'direct' property, honor
it while opening the file backing the disk image, and pass it to
vm_virtio::RawFile.

Fixes #631

Signed-off-by: Sergio Lopez <slp@redhat.com>
This commit is contained in:
Sergio Lopez 2020-01-21 12:36:27 +01:00 committed by Rob Bradford
parent 2bd90d9263
commit 925c862f98
2 changed files with 14 additions and 4 deletions

View File

@ -340,6 +340,8 @@ pub struct DiskConfig {
#[serde(default)]
pub readonly: bool,
#[serde(default)]
pub direct: bool,
#[serde(default)]
pub iommu: bool,
}
@ -350,6 +352,7 @@ impl DiskConfig {
let mut path_str: &str = "";
let mut readonly_str: &str = "";
let mut direct_str: &str = "";
let mut iommu_str: &str = "";
for param in params_list.iter() {
@ -357,6 +360,8 @@ impl DiskConfig {
path_str = &param[5..];
} else if param.starts_with("readonly=") {
readonly_str = &param[9..];
} else if param.starts_with("direct=") {
direct_str = &param[7..];
} else if param.starts_with("iommu=") {
iommu_str = &param[6..];
}
@ -365,6 +370,7 @@ impl DiskConfig {
Ok(DiskConfig {
path: PathBuf::from(path_str),
readonly: parse_on_off(readonly_str)?,
direct: parse_on_off(direct_str)?,
iommu: parse_on_off(iommu_str)?,
})
}

View File

@ -935,14 +935,18 @@ impl DeviceManager {
if let Some(disk_list_cfg) = &vm_info.vm_cfg.lock().unwrap().disks {
for disk_cfg in disk_list_cfg.iter() {
let mut options = OpenOptions::new();
options.read(true);
options.write(!disk_cfg.readonly);
if disk_cfg.direct {
options.custom_flags(libc::O_DIRECT);
}
// Open block device path
let image: File = OpenOptions::new()
.read(true)
.write(!disk_cfg.readonly)
let image: File = options
.open(&disk_cfg.path)
.map_err(DeviceManagerError::Disk)?;
let mut raw_img = vm_virtio::RawFile::new(image, false);
let mut raw_img = vm_virtio::RawFile::new(image, disk_cfg.direct);
let image_type = qcow::detect_image_type(&mut raw_img)
.map_err(DeviceManagerError::DetectImageType)?;