From 3ff82b4b65dc9dcb2f97e6ddce51f8689a48207d Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Thu, 3 Sep 2020 20:06:38 +0200 Subject: [PATCH] main, vmm: Add mandatory id to memory zones In anticipation for allowing memory zones to be removed, but also in anticipation for refactoring NUMA parameter, we introduce a mandatory 'id' option to the --memory-zone parameter. This forces the user to provide a unique identifier for each memory zone so that we can refer to these. Signed-off-by: Sebastien Boeuf --- src/main.rs | 2 +- vmm/src/api/openapi/cloud-hypervisor.yaml | 3 +++ vmm/src/config.rs | 7 +++++++ vmm/src/memory_manager.rs | 3 +++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 19d98033e..95c24abbc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -121,7 +121,7 @@ fn create_app<'a, 'b>( "User defined memory zone parameters \ \"size=,file=,\ shared=on|off,hugepages=on|off,host_numa_node=,\ - guest_numa_node=\"", + guest_numa_node=,id=\"", ) .takes_value(true) .min_values(1) diff --git a/vmm/src/api/openapi/cloud-hypervisor.yaml b/vmm/src/api/openapi/cloud-hypervisor.yaml index 59a46c7ac..6cce61861 100644 --- a/vmm/src/api/openapi/cloud-hypervisor.yaml +++ b/vmm/src/api/openapi/cloud-hypervisor.yaml @@ -453,9 +453,12 @@ components: MemoryZoneConfig: required: + - id - size type: object properties: + id: + type: string size: type: integer format: int64 diff --git a/vmm/src/config.rs b/vmm/src/config.rs index e5ef77dac..456815aa3 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -46,6 +46,8 @@ pub enum Error { ParseMemory(OptionParserError), /// Error parsing memory zone options ParseMemoryZone(OptionParserError), + /// Missing 'id' from memory zone + ParseMemoryZoneIdMissing, /// Error parsing disk options ParseDisk(OptionParserError), /// Error parsing network options @@ -154,6 +156,7 @@ impl fmt::Display for Error { ParseVsockSockMissing => write!(f, "Error parsing --vsock: socket missing"), ParseMemory(o) => write!(f, "Error parsing --memory: {}", o), ParseMemoryZone(o) => write!(f, "Error parsing --memory-zone: {}", o), + ParseMemoryZoneIdMissing => write!(f, "Error parsing --memory-zone: id missing"), ParseNetwork(o) => write!(f, "Error parsing --net: {}", o), ParseDisk(o) => write!(f, "Error parsing --disk: {}", o), ParseRNG(o) => write!(f, "Error parsing --rng: {}", o), @@ -353,6 +356,7 @@ impl Default for CpusConfig { #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct MemoryZoneConfig { + pub id: String, pub size: u64, #[serde(default)] pub file: Option, @@ -440,6 +444,7 @@ impl MemoryConfig { for memory_zone in memory_zones.iter() { let mut parser = OptionParser::new(); parser + .add("id") .add("size") .add("file") .add("shared") @@ -448,6 +453,7 @@ impl MemoryConfig { .add("guest_numa_node"); parser.parse(memory_zone).map_err(Error::ParseMemoryZone)?; + let id = parser.get("id").ok_or(Error::ParseMemoryZoneIdMissing)?; let size = parser .convert::("size") .map_err(Error::ParseMemoryZone)? @@ -472,6 +478,7 @@ impl MemoryConfig { .map_err(Error::ParseMemoryZone)?; zones.push(MemoryZoneConfig { + id, size, file, shared, diff --git a/vmm/src/memory_manager.rs b/vmm/src/memory_manager.rs index e09425078..0d4fccd07 100644 --- a/vmm/src/memory_manager.rs +++ b/vmm/src/memory_manager.rs @@ -44,6 +44,8 @@ use vm_migration::{ Transportable, }; +const DEFAULT_MEMORY_ZONE: &str = "mem0"; + #[cfg(target_arch = "x86_64")] const X86_64_IRQ_BASE: u32 = 5; @@ -426,6 +428,7 @@ impl MemoryManager { // Create a single zone from the global memory config. This lets // us reuse the codepath for user defined memory zones. let zones = vec![MemoryZoneConfig { + id: String::from(DEFAULT_MEMORY_ZONE), size: config.size, file: None, shared: config.shared,