vmm: Add 'memory_zones' option to NumaConfig

This new option provides a new way to describe the memory associated
with a NUMA node. This is the first step before we can remove the
'guest_numa_node' option from the --memory-zone parameter.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-09-04 09:36:10 +02:00
parent 5d7215915f
commit dc42324351
3 changed files with 35 additions and 3 deletions

View File

@ -248,3 +248,19 @@ impl FromStr for TupleTwoIntegers {
Ok(TupleTwoIntegers(list))
}
}
pub struct StringList(pub Vec<String>);
pub enum StringListParseError {
InvalidValue(String),
}
impl FromStr for StringList {
type Err = StringListParseError;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
let string_list: Vec<String> = s.trim().split(':').map(|e| e.to_owned()).collect();
Ok(StringList(string_list))
}
}

View File

@ -754,6 +754,10 @@ components:
type: array
items:
$ref: '#/components/schemas/NumaDistance'
memory_zones:
type: array
items:
type: string
VmResize:
type: object

View File

@ -6,7 +6,7 @@
use clap::ArgMatches;
use net_util::MacAddr;
use option_parser::{
ByteSized, IntegerList, OptionParser, OptionParserError, Toggle, TupleTwoIntegers,
ByteSized, IntegerList, OptionParser, OptionParserError, StringList, Toggle, TupleTwoIntegers,
};
use std::convert::From;
use std::fmt;
@ -1235,14 +1235,21 @@ pub struct NumaConfig {
pub cpus: Option<Vec<u8>>,
#[serde(default)]
pub distances: Option<Vec<NumaDistance>>,
#[serde(default)]
pub memory_zones: Option<Vec<String>>,
}
impl NumaConfig {
pub const SYNTAX: &'static str = "Settings related to a given NUMA node \
\"id=<node_id>,cpus=<cpus_id>,distances=<list_of_distances_to_destination_nodes>\"";
\"id=<node_id>,cpus=<cpus_id>,distances=<list_of_distances_to_destination_nodes>,\
memory_zones=<list_of_memory_zones>\"";
pub fn parse(numa: &str) -> Result<Self> {
let mut parser = OptionParser::new();
parser.add("id").add("cpus").add("distances");
parser
.add("id")
.add("cpus")
.add("distances")
.add("memory_zones");
parser.parse(numa).map_err(Error::ParseNuma)?;
let id = parser
@ -1264,11 +1271,16 @@ impl NumaConfig {
})
.collect()
});
let memory_zones = parser
.convert::<StringList>("memory_zones")
.map_err(Error::ParseNuma)?
.map(|v| v.0);
Ok(NumaConfig {
id,
cpus,
distances,
memory_zones,
})
}
}