mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-11-05 03:21:13 +00:00
vmm: config: Port CPU parsing to OptionParser
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
9e6a2825ba
commit
68203ea414
@ -27,10 +27,6 @@ pub const DEFAULT_QUEUE_SIZE_VUBLK: u16 = 128;
|
|||||||
/// Errors associated with VM configuration parameters.
|
/// Errors associated with VM configuration parameters.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
/// Failed parsing cpus parameters.
|
|
||||||
ParseCpusParams(std::num::ParseIntError),
|
|
||||||
/// Unexpected vCPU parameter
|
|
||||||
ParseCpusUnknownParam,
|
|
||||||
/// Max is less than boot
|
/// Max is less than boot
|
||||||
ParseCpusMaxLowerThanBoot,
|
ParseCpusMaxLowerThanBoot,
|
||||||
/// Failed parsing memory hotplug_method parameter.
|
/// Failed parsing memory hotplug_method parameter.
|
||||||
@ -111,6 +107,8 @@ pub enum Error {
|
|||||||
ValidateMissingKernelConfig,
|
ValidateMissingKernelConfig,
|
||||||
/// Failed parsing generic on|off parameter.
|
/// Failed parsing generic on|off parameter.
|
||||||
ParseOnOff,
|
ParseOnOff,
|
||||||
|
/// Error parsing CPU options
|
||||||
|
ParseCpus(OptionParserError),
|
||||||
}
|
}
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
@ -288,28 +286,18 @@ pub struct CpusConfig {
|
|||||||
|
|
||||||
impl CpusConfig {
|
impl CpusConfig {
|
||||||
pub fn parse(cpus: &str) -> Result<Self> {
|
pub fn parse(cpus: &str) -> Result<Self> {
|
||||||
// Split the parameters based on the comma delimiter
|
let mut parser = OptionParser::new();
|
||||||
let params_list: Vec<&str> = cpus.split(',').collect();
|
parser.add("boot").add("max");
|
||||||
|
parser.parse(cpus).map_err(Error::ParseCpus)?;
|
||||||
|
|
||||||
let mut boot_str: &str = "";
|
let boot_vcpus: u8 = parser
|
||||||
let mut max_str: &str = "";
|
.convert("boot")
|
||||||
|
.map_err(Error::ParseCpus)?
|
||||||
for param in params_list.iter() {
|
.unwrap_or(DEFAULT_VCPUS);
|
||||||
if param.starts_with("boot=") {
|
let max_vcpus: u8 = parser
|
||||||
boot_str = ¶m["boot=".len()..];
|
.convert("max")
|
||||||
} else if param.starts_with("max=") {
|
.map_err(Error::ParseCpus)?
|
||||||
max_str = ¶m["max=".len()..];
|
.unwrap_or(boot_vcpus);
|
||||||
} else {
|
|
||||||
return Err(Error::ParseCpusUnknownParam);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let boot_vcpus: u8 = boot_str.parse().map_err(Error::ParseCpusParams)?;
|
|
||||||
let max_vcpus = if max_str != "" {
|
|
||||||
max_str.parse().map_err(Error::ParseCpusParams)?
|
|
||||||
} else {
|
|
||||||
boot_vcpus
|
|
||||||
};
|
|
||||||
|
|
||||||
if max_vcpus < boot_vcpus {
|
if max_vcpus < boot_vcpus {
|
||||||
return Err(Error::ParseCpusMaxLowerThanBoot);
|
return Err(Error::ParseCpusMaxLowerThanBoot);
|
||||||
|
Loading…
Reference in New Issue
Block a user