vmm: Add an identifier to the --vsock device

It's possible to have multiple vsock devices so in preparation for
hotplug/unplug it is important to be able to have a unique identifier
for each device.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Sebastien Boeuf
2020-04-27 10:15:30 +02:00
committed by Rob Bradford
parent 10348f73e4
commit 6e049e0da1
3 changed files with 55 additions and 26 deletions
+14 -4
View File
@@ -1136,12 +1136,14 @@ pub struct VsockConfig {
pub sock: PathBuf,
#[serde(default)]
pub iommu: bool,
#[serde(default)]
pub id: Option<String>,
}
impl VsockConfig {
pub fn parse(vsock: &str) -> Result<Self> {
let mut parser = OptionParser::new();
parser.add("sock").add("cid").add("iommu");
parser.add("sock").add("cid").add("iommu").add("id");
parser.parse(vsock).map_err(Error::ParseVsock)?;
let sock = parser
@@ -1157,8 +1159,14 @@ impl VsockConfig {
.convert("cid")
.map_err(Error::ParseVsock)?
.ok_or(Error::ParseVsockCidMissing)?;
let id = parser.get("id");
Ok(VsockConfig { cid, sock, iommu })
Ok(VsockConfig {
cid,
sock,
iommu,
id,
})
}
}
@@ -1878,7 +1886,8 @@ mod tests {
VsockConfig {
cid: 1,
sock: PathBuf::from("/tmp/sock"),
iommu: false
iommu: false,
id: None,
}
);
assert_eq!(
@@ -1886,7 +1895,8 @@ mod tests {
VsockConfig {
cid: 1,
sock: PathBuf::from("/tmp/sock"),
iommu: true
iommu: true,
id: None,
}
);
Ok(())