mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-27 23:15:21 +00:00
vmm: config: Port pmem option to OptionParser
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
233ad78b3a
commit
5ab58e743a
@ -39,8 +39,10 @@ pub enum Error {
|
|||||||
ParseFsSockMissing,
|
ParseFsSockMissing,
|
||||||
/// 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.
|
/// Missing persistant memory file parameter.
|
||||||
ParsePmemFileParam,
|
ParsePmemFileMissing,
|
||||||
|
/// Missing persistant memory size parameter.
|
||||||
|
ParsePmemSizeMissing,
|
||||||
/// Failed parsing size parameter.
|
/// Failed parsing size parameter.
|
||||||
ParseSizeParam(std::num::ParseIntError),
|
ParseSizeParam(std::num::ParseIntError),
|
||||||
/// Failed parsing console parameter.
|
/// Failed parsing console parameter.
|
||||||
@ -67,6 +69,8 @@ pub enum Error {
|
|||||||
ParseRNG(OptionParserError),
|
ParseRNG(OptionParserError),
|
||||||
/// Error parsing filesystem parameters
|
/// Error parsing filesystem parameters
|
||||||
ParseFileSystem(OptionParserError),
|
ParseFileSystem(OptionParserError),
|
||||||
|
/// Error parsing persistent memorry parameters
|
||||||
|
ParsePersistentMemory(OptionParserError),
|
||||||
}
|
}
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
@ -849,39 +853,43 @@ impl PmemConfig {
|
|||||||
\"file=<backing_file_path>,size=<persistent_memory_size>,iommu=on|off,\
|
\"file=<backing_file_path>,size=<persistent_memory_size>,iommu=on|off,\
|
||||||
mergeable=on|off,discard_writes=on|off,\"";
|
mergeable=on|off,discard_writes=on|off,\"";
|
||||||
pub fn parse(pmem: &str) -> Result<Self> {
|
pub fn parse(pmem: &str) -> Result<Self> {
|
||||||
// Split the parameters based on the comma delimiter
|
let mut parser = OptionParser::new();
|
||||||
let params_list: Vec<&str> = pmem.split(',').collect();
|
parser
|
||||||
|
.add("size")
|
||||||
|
.add("file")
|
||||||
|
.add("mergeable")
|
||||||
|
.add("iommu")
|
||||||
|
.add("discard_writes");
|
||||||
|
parser.parse(pmem).map_err(Error::ParsePersistentMemory)?;
|
||||||
|
|
||||||
let mut file_str: &str = "";
|
let file = PathBuf::from(parser.get("file").ok_or(Error::ParsePmemFileMissing)?);
|
||||||
let mut size_str: &str = "";
|
let size = parser
|
||||||
let mut iommu_str: &str = "";
|
.convert::<ByteSized>("size")
|
||||||
let mut mergeable_str: &str = "";
|
.map_err(Error::ParseMemory)?
|
||||||
let mut discard_writes_str: &str = "";
|
.ok_or(Error::ParsePmemSizeMissing)?
|
||||||
|
.0;
|
||||||
for param in params_list.iter() {
|
let mergeable = parser
|
||||||
if param.starts_with("file=") {
|
.convert::<Toggle>("mergeable")
|
||||||
file_str = ¶m[5..];
|
.map_err(Error::ParsePersistentMemory)?
|
||||||
} else if param.starts_with("size=") {
|
.unwrap_or(Toggle(false))
|
||||||
size_str = ¶m[5..];
|
.0;
|
||||||
} else if param.starts_with("iommu=") {
|
let iommu = parser
|
||||||
iommu_str = ¶m[6..];
|
.convert::<Toggle>("iommu")
|
||||||
} else if param.starts_with("mergeable=") {
|
.map_err(Error::ParsePersistentMemory)?
|
||||||
mergeable_str = ¶m[10..];
|
.unwrap_or(Toggle(false))
|
||||||
} else if param.starts_with("discard_writes=") {
|
.0;
|
||||||
discard_writes_str = ¶m[15..];
|
let discard_writes = parser
|
||||||
}
|
.convert::<Toggle>("discard_writes")
|
||||||
}
|
.map_err(Error::ParsePersistentMemory)?
|
||||||
|
.unwrap_or(Toggle(false))
|
||||||
if file_str.is_empty() {
|
.0;
|
||||||
return Err(Error::ParsePmemFileParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(PmemConfig {
|
Ok(PmemConfig {
|
||||||
file: PathBuf::from(file_str),
|
file,
|
||||||
size: parse_size(size_str)?,
|
size,
|
||||||
iommu: parse_on_off(iommu_str)?,
|
iommu,
|
||||||
mergeable: parse_on_off(mergeable_str)?,
|
mergeable,
|
||||||
discard_writes: parse_on_off(discard_writes_str)?,
|
discard_writes,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user