mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-11-05 03:21:13 +00:00
vmm: config: Port filesystem parsing to OptionParser
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
7a071c28db
commit
13dc637350
@ -33,16 +33,10 @@ pub enum Error {
|
|||||||
ParseCmdlineParams,
|
ParseCmdlineParams,
|
||||||
/// Both socket and path specified
|
/// Both socket and path specified
|
||||||
ParseDiskSocketAndPath,
|
ParseDiskSocketAndPath,
|
||||||
/// Failed parsing fs tag parameter.
|
/// Filesystem tag is missing
|
||||||
ParseFsTagParam,
|
ParseFsTagMissing,
|
||||||
/// Failed parsing fs socket path parameter.
|
/// Filesystem socket is missing
|
||||||
ParseFsSockParam,
|
ParseFsSockMissing,
|
||||||
/// Failed parsing fs number of queues parameter.
|
|
||||||
ParseFsNumQueuesParam(std::num::ParseIntError),
|
|
||||||
/// Failed parsing fs queue size parameter.
|
|
||||||
ParseFsQueueSizeParam(std::num::ParseIntError),
|
|
||||||
/// Failed parsing fs dax parameter.
|
|
||||||
ParseFsDax,
|
|
||||||
/// Cannot have dax=off along with cache_size parameter.
|
/// Cannot have dax=off along with cache_size parameter.
|
||||||
InvalidCacheSizeWithDaxOff,
|
InvalidCacheSizeWithDaxOff,
|
||||||
/// Failed parsing persitent memory file parameter.
|
/// Failed parsing persitent memory file parameter.
|
||||||
@ -71,6 +65,8 @@ pub enum Error {
|
|||||||
ParseNetwork(OptionParserError),
|
ParseNetwork(OptionParserError),
|
||||||
/// Error parsing RNG options
|
/// Error parsing RNG options
|
||||||
ParseRNG(OptionParserError),
|
ParseRNG(OptionParserError),
|
||||||
|
/// Error parsing filesystem parameters
|
||||||
|
ParseFileSystem(OptionParserError),
|
||||||
}
|
}
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
@ -787,76 +783,47 @@ impl Default for FsConfig {
|
|||||||
|
|
||||||
impl FsConfig {
|
impl FsConfig {
|
||||||
pub fn parse(fs: &str) -> Result<Self> {
|
pub fn parse(fs: &str) -> Result<Self> {
|
||||||
// Split the parameters based on the comma delimiter
|
let mut parser = OptionParser::new();
|
||||||
let params_list: Vec<&str> = fs.split(',').collect();
|
parser
|
||||||
|
.add("tag")
|
||||||
|
.add("dax")
|
||||||
|
.add("cache_size")
|
||||||
|
.add("queue_size")
|
||||||
|
.add("num_queues")
|
||||||
|
.add("sock");
|
||||||
|
parser.parse(fs).map_err(Error::ParseFileSystem)?;
|
||||||
|
|
||||||
let mut tag: &str = "";
|
let tag = parser.get("tag").ok_or(Error::ParseFsTagMissing)?;
|
||||||
let mut sock: &str = "";
|
let sock = PathBuf::from(parser.get("sock").ok_or(Error::ParseFsSockMissing)?);
|
||||||
let mut num_queues_str: &str = "";
|
|
||||||
let mut queue_size_str: &str = "";
|
|
||||||
let mut dax_str: &str = "";
|
|
||||||
let mut cache_size_str: &str = "";
|
|
||||||
|
|
||||||
for param in params_list.iter() {
|
let queue_size = parser
|
||||||
if param.starts_with("tag=") {
|
.convert("queue_size")
|
||||||
tag = ¶m[4..];
|
.map_err(Error::ParseFileSystem)?
|
||||||
} else if param.starts_with("sock=") {
|
.unwrap_or_else(default_fsconfig_queue_size);
|
||||||
sock = ¶m[5..];
|
let num_queues = parser
|
||||||
} else if param.starts_with("num_queues=") {
|
.convert("num_queues")
|
||||||
num_queues_str = ¶m[11..];
|
.map_err(Error::ParseFileSystem)?
|
||||||
} else if param.starts_with("queue_size=") {
|
.unwrap_or_else(default_fsconfig_num_queues);
|
||||||
queue_size_str = ¶m[11..];
|
|
||||||
} else if param.starts_with("dax=") {
|
|
||||||
dax_str = ¶m[4..];
|
|
||||||
} else if param.starts_with("cache_size=") {
|
|
||||||
cache_size_str = ¶m[11..];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut num_queues: usize = default_fsconfig_num_queues();
|
let dax = parser
|
||||||
let mut queue_size: u16 = default_fsconfig_queue_size();
|
.convert::<Toggle>("dax")
|
||||||
let mut dax: bool = default_fsconfig_dax();
|
.map_err(Error::ParseFileSystem)?
|
||||||
// Default cache size set to 8Gib.
|
.unwrap_or_else(|| Toggle(default_fsconfig_dax()))
|
||||||
let mut cache_size: u64 = default_fsconfig_cache_size();
|
.0;
|
||||||
|
|
||||||
if tag.is_empty() {
|
if parser.is_set("cache_size") && !dax {
|
||||||
return Err(Error::ParseFsTagParam);
|
|
||||||
}
|
|
||||||
if sock.is_empty() {
|
|
||||||
return Err(Error::ParseFsSockParam);
|
|
||||||
}
|
|
||||||
if !num_queues_str.is_empty() {
|
|
||||||
num_queues = num_queues_str
|
|
||||||
.parse()
|
|
||||||
.map_err(Error::ParseFsNumQueuesParam)?;
|
|
||||||
}
|
|
||||||
if !queue_size_str.is_empty() {
|
|
||||||
queue_size = queue_size_str
|
|
||||||
.parse()
|
|
||||||
.map_err(Error::ParseFsQueueSizeParam)?;
|
|
||||||
}
|
|
||||||
if !dax_str.is_empty() {
|
|
||||||
match dax_str {
|
|
||||||
"on" => dax = true,
|
|
||||||
"off" => dax = false,
|
|
||||||
_ => return Err(Error::ParseFsDax),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Take appropriate decision about cache_size based on DAX being
|
|
||||||
// enabled or disabled.
|
|
||||||
if !dax {
|
|
||||||
if !cache_size_str.is_empty() {
|
|
||||||
return Err(Error::InvalidCacheSizeWithDaxOff);
|
return Err(Error::InvalidCacheSizeWithDaxOff);
|
||||||
}
|
}
|
||||||
cache_size = 0;
|
|
||||||
} else if !cache_size_str.is_empty() {
|
let cache_size = parser
|
||||||
cache_size = parse_size(cache_size_str)?;
|
.convert::<ByteSized>("cache_size")
|
||||||
}
|
.map_err(Error::ParseFileSystem)?
|
||||||
|
.unwrap_or_else(|| ByteSized(default_fsconfig_cache_size()))
|
||||||
|
.0;
|
||||||
|
|
||||||
Ok(FsConfig {
|
Ok(FsConfig {
|
||||||
tag: tag.to_string(),
|
tag,
|
||||||
sock: PathBuf::from(sock),
|
sock,
|
||||||
num_queues,
|
num_queues,
|
||||||
queue_size,
|
queue_size,
|
||||||
dax,
|
dax,
|
||||||
|
Loading…
Reference in New Issue
Block a user