vmm: Add iommu=on|off option for --console

Having the virtual IOMMU created with --iommu is one thing, but we also
need a way to decide if a virtio-console 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".

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2019-10-04 12:01:32 -07:00 committed by Samuel Ortiz
parent 63869bde75
commit 32d07e40cc
3 changed files with 54 additions and 24 deletions

View File

@ -187,7 +187,10 @@ fn main() {
.arg(
Arg::with_name("console")
.long("console")
.help("Control (virtio) console: off|null|tty|file=/path/to/a/file")
.help(
"Control (virtio) console: \"off|null|tty|file=/path/to/a/file,\
iommu=on|off\"",
)
.default_value("tty")
.group("vm-config"),
)

View File

@ -303,6 +303,9 @@ components:
mode:
type: string
enum: [Off, Tty, File, Null]
iommu:
type: boolean
default: false
DeviceConfig:
required:

View File

@ -504,39 +504,59 @@ impl ConsoleOutputMode {
pub struct ConsoleConfig {
pub file: Option<PathBuf>,
pub mode: ConsoleOutputMode,
#[serde(default)]
pub iommu: bool,
}
impl ConsoleConfig {
pub fn parse(param: &str) -> Result<Self> {
if param == "off" {
Ok(Self {
mode: ConsoleOutputMode::Off,
file: None,
})
} else if param == "tty" {
Ok(Self {
mode: ConsoleOutputMode::Tty,
file: None,
})
} else if param.starts_with("file=") {
Ok(Self {
mode: ConsoleOutputMode::File,
file: Some(PathBuf::from(&param[5..])),
})
} else if param.starts_with("null") {
Ok(Self {
mode: ConsoleOutputMode::Null,
file: None,
})
} else {
Err(Error::ParseConsoleParam)
pub fn parse(console: &str) -> Result<Self> {
// Split the parameters based on the comma delimiter
let params_list: Vec<&str> = console.split(',').collect();
let mut valid = false;
let mut file: Option<PathBuf> = None;
let mut mode: ConsoleOutputMode = ConsoleOutputMode::Off;
let mut iommu_str: &str = "";
for param in params_list.iter() {
if param.starts_with("iommu=") {
iommu_str = &param[6..];
} else {
if *param == "off" {
mode = ConsoleOutputMode::Off;
file = None;
} else if *param == "tty" {
mode = ConsoleOutputMode::Tty;
file = None;
} else if param.starts_with("file=") {
mode = ConsoleOutputMode::File;
file = Some(PathBuf::from(&param[5..]));
} else if param.starts_with("null") {
mode = ConsoleOutputMode::Null;
file = None;
} else {
return Err(Error::ParseConsoleParam);
}
valid = true;
}
}
if !valid {
return Err(Error::ParseConsoleParam);
}
Ok(Self {
mode,
file,
iommu: parse_iommu(iommu_str)?,
})
}
pub fn default_serial() -> Self {
ConsoleConfig {
file: None,
mode: ConsoleOutputMode::Null,
iommu: false,
}
}
@ -544,6 +564,7 @@ impl ConsoleConfig {
ConsoleConfig {
file: None,
mode: ConsoleOutputMode::Tty,
iommu: false,
}
}
}
@ -804,6 +825,9 @@ impl VmConfig {
}
let console = ConsoleConfig::parse(vm_params.console)?;
if console.iommu {
iommu = true;
}
let serial = ConsoleConfig::parse(vm_params.serial)?;
if console.mode == ConsoleOutputMode::Tty && serial.mode == ConsoleOutputMode::Tty {
return Err(Error::ParseTTYParam);