mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-22 11:22:26 +00:00
vmm: config: Port vsock to OptionParser
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
37264cf21b
commit
c731a943d4
@ -47,10 +47,10 @@ pub enum Error {
|
|||||||
ParseSizeParam(std::num::ParseIntError),
|
ParseSizeParam(std::num::ParseIntError),
|
||||||
/// Both console and serial are tty.
|
/// Both console and serial are tty.
|
||||||
ParseTTYParam,
|
ParseTTYParam,
|
||||||
/// Failed parsing vsock context ID parameter.
|
/// Missing vsock socket path parameter.
|
||||||
ParseVsockCidParam(std::num::ParseIntError),
|
ParseVsockSockMissing,
|
||||||
/// Failed parsing vsock socket path parameter.
|
/// Missing vsock cid parameter.
|
||||||
ParseVsockSockParam,
|
ParseVsockCidMissing,
|
||||||
/// Missing kernel configuration
|
/// Missing kernel configuration
|
||||||
ValidateMissingKernelConfig,
|
ValidateMissingKernelConfig,
|
||||||
/// Failed parsing generic on|off parameter.
|
/// Failed parsing generic on|off parameter.
|
||||||
@ -79,6 +79,8 @@ pub enum Error {
|
|||||||
ParseDevice(OptionParserError),
|
ParseDevice(OptionParserError),
|
||||||
/// Missing path from device,
|
/// Missing path from device,
|
||||||
ParseDevicePathMissing,
|
ParseDevicePathMissing,
|
||||||
|
/// Failed to parse vsock parameters
|
||||||
|
ParseVsock(OptionParserError),
|
||||||
}
|
}
|
||||||
pub type Result<T> = result::Result<T, Error>;
|
pub type Result<T> = result::Result<T, Error>;
|
||||||
|
|
||||||
@ -1047,32 +1049,25 @@ pub struct VsockConfig {
|
|||||||
|
|
||||||
impl VsockConfig {
|
impl VsockConfig {
|
||||||
pub fn parse(vsock: &str) -> Result<Self> {
|
pub fn parse(vsock: &str) -> Result<Self> {
|
||||||
// Split the parameters based on the comma delimiter
|
let mut parser = OptionParser::new();
|
||||||
let params_list: Vec<&str> = vsock.split(',').collect();
|
parser.add("sock").add("cid").add("iommu");
|
||||||
|
parser.parse(vsock).map_err(Error::ParseVsock)?;
|
||||||
|
|
||||||
let mut cid_str: &str = "";
|
let sock = parser
|
||||||
let mut sock_str: &str = "";
|
.get("sock")
|
||||||
let mut iommu_str: &str = "";
|
.map(PathBuf::from)
|
||||||
|
.ok_or(Error::ParseVsockSockMissing)?;
|
||||||
|
let iommu = parser
|
||||||
|
.convert::<Toggle>("iommu")
|
||||||
|
.map_err(Error::ParseVsock)?
|
||||||
|
.unwrap_or(Toggle(false))
|
||||||
|
.0;
|
||||||
|
let cid = parser
|
||||||
|
.convert("cid")
|
||||||
|
.map_err(Error::ParseVsock)?
|
||||||
|
.ok_or(Error::ParseVsockCidMissing)?;
|
||||||
|
|
||||||
for param in params_list.iter() {
|
Ok(VsockConfig { cid, sock, iommu })
|
||||||
if param.starts_with("cid=") {
|
|
||||||
cid_str = ¶m[4..];
|
|
||||||
} else if param.starts_with("sock=") {
|
|
||||||
sock_str = ¶m[5..];
|
|
||||||
} else if param.starts_with("iommu=") {
|
|
||||||
iommu_str = ¶m[6..];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if sock_str.is_empty() {
|
|
||||||
return Err(Error::ParseVsockSockParam);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(VsockConfig {
|
|
||||||
cid: cid_str.parse::<u64>().map_err(Error::ParseVsockCidParam)?,
|
|
||||||
sock: PathBuf::from(sock_str),
|
|
||||||
iommu: parse_on_off(iommu_str)?,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user