From 880f62bab8b497cf1a08c325359499118fc9597f Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Tue, 19 Nov 2019 15:40:57 -0800 Subject: [PATCH] vmm: Add mergeable=on|off option to --memory flag In order to let the user indicate if the guest RAM pages should be marked as mergeable or not, a new option is being introduced. Signed-off-by: Sebastien Boeuf --- src/main.rs | 2 +- vmm/src/api/openapi/cloud-hypervisor.yaml | 3 +++ vmm/src/config.rs | 33 ++++++++++++++--------- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/main.rs b/src/main.rs index df8563993..b91348848 100755 --- a/src/main.rs +++ b/src/main.rs @@ -101,7 +101,7 @@ fn main() { .long("memory") .help( "Memory parameters \"size=,\ - file=\"", + file=,mergeable=on|off\"", ) .default_value(&default_memory) .group("vm-config"), diff --git a/vmm/src/api/openapi/cloud-hypervisor.yaml b/vmm/src/api/openapi/cloud-hypervisor.yaml index 421aac2a2..c77368a03 100644 --- a/vmm/src/api/openapi/cloud-hypervisor.yaml +++ b/vmm/src/api/openapi/cloud-hypervisor.yaml @@ -226,6 +226,9 @@ components: default: 512 MB file: type: string + mergeable: + type: boolean + default: false KernelConfig: required: diff --git a/vmm/src/config.rs b/vmm/src/config.rs index e18e2a5cf..34194ed09 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -75,8 +75,8 @@ pub enum Error<'a> { ParseVsockSockParam, /// Missing kernel configuration ValidateMissingKernelConfig, - /// Failed parsing iommu parameter for the device. - ParseDeviceIommu, + /// Failed parsing generic on|off parameter. + ParseOnOff, } pub type Result<'a, T> = result::Result>; @@ -116,12 +116,12 @@ fn parse_size(size: &str) -> Result { Ok(res << shift) } -fn parse_iommu(iommu: &str) -> Result { - if !iommu.is_empty() { - let res = match iommu { +fn parse_on_off(param: &str) -> Result { + if !param.is_empty() { + let res = match param { "on" => true, "off" => false, - _ => return Err(Error::ParseDeviceIommu), + _ => return Err(Error::ParseOnOff), }; Ok(res) @@ -155,6 +155,8 @@ impl Default for CpusConfig { pub struct MemoryConfig { pub size: u64, pub file: Option, + #[serde(default)] + pub mergeable: bool, } impl MemoryConfig { @@ -164,6 +166,7 @@ impl MemoryConfig { let mut size_str: &str = ""; let mut file_str: &str = ""; + let mut mergeable_str: &str = ""; let mut backed = false; for param in params_list.iter() { @@ -172,6 +175,8 @@ impl MemoryConfig { } else if param.starts_with("file=") { backed = true; file_str = ¶m[5..]; + } else if param.starts_with("mergeable=") { + mergeable_str = ¶m[10..]; } } @@ -188,6 +193,7 @@ impl MemoryConfig { Ok(MemoryConfig { size: parse_size(size_str)?, file, + mergeable: parse_on_off(mergeable_str)?, }) } } @@ -197,6 +203,7 @@ impl Default for MemoryConfig { MemoryConfig { size: DEFAULT_MEMORY_MB << 20, file: None, + mergeable: false, } } } @@ -246,7 +253,7 @@ impl DiskConfig { Ok(DiskConfig { path: PathBuf::from(path_str), - iommu: parse_iommu(iommu_str)?, + iommu: parse_on_off(iommu_str)?, }) } } @@ -290,7 +297,7 @@ impl NetConfig { let mut ip: Ipv4Addr = Ipv4Addr::new(192, 168, 249, 1); let mut mask: Ipv4Addr = Ipv4Addr::new(255, 255, 255, 0); let mut mac: MacAddr = MacAddr::local_random(); - let iommu = parse_iommu(iommu_str)?; + let iommu = parse_on_off(iommu_str)?; if !tap_str.is_empty() { tap = Some(tap_str.to_string()); @@ -340,7 +347,7 @@ impl RngConfig { Ok(RngConfig { src: PathBuf::from(src_str), - iommu: parse_iommu(iommu_str)?, + iommu: parse_on_off(iommu_str)?, }) } } @@ -476,7 +483,7 @@ impl PmemConfig { Ok(PmemConfig { file: PathBuf::from(file_str), size: parse_size(size_str)?, - iommu: parse_iommu(iommu_str)?, + iommu: parse_on_off(iommu_str)?, }) } } @@ -546,7 +553,7 @@ impl ConsoleConfig { Ok(Self { mode, file, - iommu: parse_iommu(iommu_str)?, + iommu: parse_on_off(iommu_str)?, }) } @@ -592,7 +599,7 @@ impl DeviceConfig { Ok(DeviceConfig { path: PathBuf::from(path_str), - iommu: parse_iommu(iommu_str)?, + iommu: parse_on_off(iommu_str)?, }) } } @@ -697,7 +704,7 @@ impl VsockConfig { Ok(VsockConfig { cid: cid_str.parse::().map_err(Error::ParseVsockCidParam)?, sock: PathBuf::from(sock_str), - iommu: parse_iommu(iommu_str)?, + iommu: parse_on_off(iommu_str)?, }) } }