mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Add iommu=on|off option for --disk
Having the virtual IOMMU created with --iommu is one thing, but we also need a way to decide if a virtio-blk device should be attached to this virtual IOMMU or not. That's why we introduce an extra option "iommu" with the value "on" or "off". By default, the device is not attached, which means "iommu=off". One side effect of this new option is that we had to introduce a new option for the disk path, simply called "path=". Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
committed by
Samuel Ortiz
parent
6e0aa56f06
commit
4b8d7e718d
@@ -225,6 +225,9 @@ components:
|
||||
properties:
|
||||
path:
|
||||
type: string
|
||||
iommu:
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
NetConfig:
|
||||
required:
|
||||
|
||||
@@ -75,6 +75,8 @@ pub enum Error<'a> {
|
||||
ParseVsockSockParam,
|
||||
/// Missing kernel configuration
|
||||
ValidateMissingKernelConfig,
|
||||
/// Failed parsing iommu parameter for the device.
|
||||
ParseDeviceIommu,
|
||||
}
|
||||
pub type Result<'a, T> = result::Result<T, Error<'a>>;
|
||||
|
||||
@@ -114,6 +116,20 @@ fn parse_size(size: &str) -> Result<u64> {
|
||||
Ok(res << shift)
|
||||
}
|
||||
|
||||
fn parse_iommu(iommu: &str) -> Result<bool> {
|
||||
if !iommu.is_empty() {
|
||||
let res = match iommu {
|
||||
"on" => true,
|
||||
"off" => false,
|
||||
_ => return Err(Error::ParseDeviceIommu),
|
||||
};
|
||||
|
||||
Ok(res)
|
||||
} else {
|
||||
Ok(false)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct CpusConfig(pub u8);
|
||||
|
||||
@@ -210,12 +226,29 @@ impl CmdlineConfig {
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct DiskConfig {
|
||||
pub path: PathBuf,
|
||||
#[serde(default)]
|
||||
pub iommu: bool,
|
||||
}
|
||||
|
||||
impl DiskConfig {
|
||||
pub fn parse(disk: &str) -> Result<Self> {
|
||||
// Split the parameters based on the comma delimiter
|
||||
let params_list: Vec<&str> = disk.split(',').collect();
|
||||
|
||||
let mut path_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("iommu=") {
|
||||
iommu_str = ¶m[6..];
|
||||
}
|
||||
}
|
||||
|
||||
Ok(DiskConfig {
|
||||
path: PathBuf::from(disk),
|
||||
path: PathBuf::from(path_str),
|
||||
iommu: parse_iommu(iommu_str)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -679,13 +712,17 @@ impl VmConfig {
|
||||
}
|
||||
|
||||
pub fn parse(vm_params: VmParams) -> Result<Self> {
|
||||
let iommu = false;
|
||||
let mut iommu = false;
|
||||
|
||||
let mut disks: Option<Vec<DiskConfig>> = None;
|
||||
if let Some(disk_list) = &vm_params.disks {
|
||||
let mut disk_config_list = Vec::new();
|
||||
for item in disk_list.iter() {
|
||||
disk_config_list.push(DiskConfig::parse(item)?);
|
||||
let disk_config = DiskConfig::parse(item)?;
|
||||
if disk_config.iommu {
|
||||
iommu = true;
|
||||
}
|
||||
disk_config_list.push(disk_config);
|
||||
}
|
||||
disks = Some(disk_config_list);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user