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 <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-09-03 20:06:38 +02:00
parent c37fb5b602
commit 3ff82b4b65
4 changed files with 14 additions and 1 deletions

View File

@ -121,7 +121,7 @@ fn create_app<'a, 'b>(
"User defined memory zone parameters \
\"size=<guest_memory_region_size>,file=<backing_file>,\
shared=on|off,hugepages=on|off,host_numa_node=<node_id>,\
guest_numa_node=<node_id>\"",
guest_numa_node=<node_id>,id=<zone_identifier>\"",
)
.takes_value(true)
.min_values(1)

View File

@ -453,9 +453,12 @@ components:
MemoryZoneConfig:
required:
- id
- size
type: object
properties:
id:
type: string
size:
type: integer
format: int64

View File

@ -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<PathBuf>,
@ -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::<ByteSized>("size")
.map_err(Error::ParseMemoryZone)?
@ -472,6 +478,7 @@ impl MemoryConfig {
.map_err(Error::ParseMemoryZone)?;
zones.push(MemoryZoneConfig {
id,
size,
file,
shared,

View File

@ -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,