vmm: Add "kvm_hyperv" toggle to "--cpus"

This turns on the KVM HyperV emulation.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-09-15 16:13:48 +01:00
parent c03dbe8cc7
commit 5495ab7415
2 changed files with 30 additions and 7 deletions

View File

@ -97,7 +97,7 @@ fn create_app<'a, 'b>(
.long("cpus") .long("cpus")
.help( .help(
"boot=<boot_vcpus>,max=<max_vcpus>,\ "boot=<boot_vcpus>,max=<max_vcpus>,\
topology=<threads_per_core>:<cores_per_die>:<dies_per_package>:<packages>", topology=<threads_per_core>:<cores_per_die>:<dies_per_package>:<packages>,kvm_hyperv=on|off",
) )
.default_value(&default_vcpus) .default_value(&default_vcpus)
.group("vm-config"), .group("vm-config"),
@ -532,6 +532,7 @@ mod unit_tests {
boot_vcpus: 1, boot_vcpus: 1,
max_vcpus: 1, max_vcpus: 1,
topology: None, topology: None,
kvm_hyperv: false,
}, },
memory: MemoryConfig { memory: MemoryConfig {
size: 536_870_912, size: 536_870_912,

View File

@ -318,12 +318,18 @@ pub struct CpusConfig {
pub max_vcpus: u8, pub max_vcpus: u8,
#[serde(default)] #[serde(default)]
pub topology: Option<CpuTopology>, pub topology: Option<CpuTopology>,
#[serde(default)]
pub kvm_hyperv: bool,
} }
impl CpusConfig { impl CpusConfig {
pub fn parse(cpus: &str) -> Result<Self> { pub fn parse(cpus: &str) -> Result<Self> {
let mut parser = OptionParser::new(); let mut parser = OptionParser::new();
parser.add("boot").add("max").add("topology"); parser
.add("boot")
.add("max")
.add("topology")
.add("kvm_hyperv");
parser.parse(cpus).map_err(Error::ParseCpus)?; parser.parse(cpus).map_err(Error::ParseCpus)?;
let boot_vcpus: u8 = parser let boot_vcpus: u8 = parser
@ -335,11 +341,17 @@ impl CpusConfig {
.map_err(Error::ParseCpus)? .map_err(Error::ParseCpus)?
.unwrap_or(boot_vcpus); .unwrap_or(boot_vcpus);
let topology = parser.convert("topology").map_err(Error::ParseCpus)?; let topology = parser.convert("topology").map_err(Error::ParseCpus)?;
let kvm_hyperv = parser
.convert::<Toggle>("kvm_hyperv")
.map_err(Error::ParseCpus)?
.unwrap_or(Toggle(false))
.0;
Ok(CpusConfig { Ok(CpusConfig {
boot_vcpus, boot_vcpus,
max_vcpus, max_vcpus,
topology, topology,
kvm_hyperv,
}) })
} }
} }
@ -350,6 +362,7 @@ impl Default for CpusConfig {
boot_vcpus: DEFAULT_VCPUS, boot_vcpus: DEFAULT_VCPUS,
max_vcpus: DEFAULT_VCPUS, max_vcpus: DEFAULT_VCPUS,
topology: None, topology: None,
kvm_hyperv: false,
} }
} }
} }
@ -1595,7 +1608,7 @@ mod tests {
CpusConfig { CpusConfig {
boot_vcpus: 1, boot_vcpus: 1,
max_vcpus: 1, max_vcpus: 1,
topology: None ..Default::default()
} }
); );
assert_eq!( assert_eq!(
@ -1603,7 +1616,7 @@ mod tests {
CpusConfig { CpusConfig {
boot_vcpus: 1, boot_vcpus: 1,
max_vcpus: 2, max_vcpus: 2,
topology: None ..Default::default()
} }
); );
assert_eq!( assert_eq!(
@ -1616,13 +1629,22 @@ mod tests {
cores_per_die: 2, cores_per_die: 2,
dies_per_package: 1, dies_per_package: 1,
packages: 2 packages: 2
}) }),
..Default::default()
} }
); );
assert!(CpusConfig::parse("boot=8,topology=2:2:1").is_err()); assert!(CpusConfig::parse("boot=8,topology=2:2:1").is_err());
assert!(CpusConfig::parse("boot=8,topology=2:2:1:x").is_err()); assert!(CpusConfig::parse("boot=8,topology=2:2:1:x").is_err());
assert_eq!(
CpusConfig::parse("boot=1,kvm_hyperv=on")?,
CpusConfig {
boot_vcpus: 1,
max_vcpus: 1,
kvm_hyperv: true,
..Default::default()
}
);
Ok(()) Ok(())
} }
@ -2081,7 +2103,7 @@ mod tests {
cpus: CpusConfig { cpus: CpusConfig {
boot_vcpus: 1, boot_vcpus: 1,
max_vcpus: 1, max_vcpus: 1,
topology: None, ..Default::default()
}, },
memory: MemoryConfig { memory: MemoryConfig {
size: 536_870_912, size: 536_870_912,