mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-08 20:51:28 +00:00
vmm: config: Add "id" parameter to {Net, Disk, Pmem}Config
This id will be used to unplug the device if the user has chosen an id. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
1beb62ed2d
commit
b38470df4b
@ -538,6 +538,8 @@ pub struct DiskConfig {
|
|||||||
pub wce: bool,
|
pub wce: bool,
|
||||||
#[serde(default = "default_diskconfig_poll_queue")]
|
#[serde(default = "default_diskconfig_poll_queue")]
|
||||||
pub poll_queue: bool,
|
pub poll_queue: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_diskconfig_num_queues() -> usize {
|
fn default_diskconfig_num_queues() -> usize {
|
||||||
@ -569,6 +571,7 @@ impl Default for DiskConfig {
|
|||||||
vhost_socket: None,
|
vhost_socket: None,
|
||||||
wce: default_diskconfig_wce(),
|
wce: default_diskconfig_wce(),
|
||||||
poll_queue: default_diskconfig_poll_queue(),
|
poll_queue: default_diskconfig_poll_queue(),
|
||||||
|
id: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -577,7 +580,7 @@ impl DiskConfig {
|
|||||||
pub const SYNTAX: &'static str = "Disk parameters \
|
pub const SYNTAX: &'static str = "Disk parameters \
|
||||||
\"path=<disk_image_path>,readonly=on|off,iommu=on|off,num_queues=<number_of_queues>,\
|
\"path=<disk_image_path>,readonly=on|off,iommu=on|off,num_queues=<number_of_queues>,\
|
||||||
queue_size=<size_of_each_queue>,vhost_user=<vhost_user_enable>,\
|
queue_size=<size_of_each_queue>,vhost_user=<vhost_user_enable>,\
|
||||||
socket=<vhost_user_socket_path>,wce=<true|false, default true>\"";
|
socket=<vhost_user_socket_path>,wce=<true|false, default true>,id=<device_id>\"";
|
||||||
|
|
||||||
pub fn parse(disk: &str) -> Result<Self> {
|
pub fn parse(disk: &str) -> Result<Self> {
|
||||||
let mut parser = OptionParser::new();
|
let mut parser = OptionParser::new();
|
||||||
@ -591,7 +594,8 @@ impl DiskConfig {
|
|||||||
.add("vhost_user")
|
.add("vhost_user")
|
||||||
.add("socket")
|
.add("socket")
|
||||||
.add("wce")
|
.add("wce")
|
||||||
.add("poll_queue");
|
.add("poll_queue")
|
||||||
|
.add("id");
|
||||||
parser.parse(disk).map_err(Error::ParseDisk)?;
|
parser.parse(disk).map_err(Error::ParseDisk)?;
|
||||||
|
|
||||||
let path = parser.get("path").map(PathBuf::from);
|
let path = parser.get("path").map(PathBuf::from);
|
||||||
@ -631,6 +635,7 @@ impl DiskConfig {
|
|||||||
.convert("poll_queue")
|
.convert("poll_queue")
|
||||||
.map_err(Error::ParseDisk)?
|
.map_err(Error::ParseDisk)?
|
||||||
.unwrap_or_else(default_diskconfig_poll_queue);
|
.unwrap_or_else(default_diskconfig_poll_queue);
|
||||||
|
let id = parser.get("id");
|
||||||
|
|
||||||
if parser.is_set("wce") && !vhost_user {
|
if parser.is_set("wce") && !vhost_user {
|
||||||
warn!("wce parameter currently only has effect when used vhost_user=true");
|
warn!("wce parameter currently only has effect when used vhost_user=true");
|
||||||
@ -651,6 +656,7 @@ impl DiskConfig {
|
|||||||
vhost_user,
|
vhost_user,
|
||||||
wce,
|
wce,
|
||||||
poll_queue,
|
poll_queue,
|
||||||
|
id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -674,6 +680,8 @@ pub struct NetConfig {
|
|||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub vhost_user: bool,
|
pub vhost_user: bool,
|
||||||
pub vhost_socket: Option<String>,
|
pub vhost_socket: Option<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_netconfig_tap() -> Option<String> {
|
fn default_netconfig_tap() -> Option<String> {
|
||||||
@ -712,6 +720,7 @@ impl Default for NetConfig {
|
|||||||
queue_size: default_netconfig_queue_size(),
|
queue_size: default_netconfig_queue_size(),
|
||||||
vhost_user: false,
|
vhost_user: false,
|
||||||
vhost_socket: None,
|
vhost_socket: None,
|
||||||
|
id: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -720,7 +729,7 @@ impl NetConfig {
|
|||||||
pub const SYNTAX: &'static str = "Network parameters \
|
pub const SYNTAX: &'static str = "Network parameters \
|
||||||
\"tap=<if_name>,ip=<ip_addr>,mask=<net_mask>,mac=<mac_addr>,iommu=on|off,\
|
\"tap=<if_name>,ip=<ip_addr>,mask=<net_mask>,mac=<mac_addr>,iommu=on|off,\
|
||||||
num_queues=<number_of_queues>,queue_size=<size_of_each_queue>,\
|
num_queues=<number_of_queues>,queue_size=<size_of_each_queue>,\
|
||||||
vhost_user=<vhost_user_enable>,socket=<vhost_user_socket_path>\"";
|
vhost_user=<vhost_user_enable>,socket=<vhost_user_socket_path>,id=<device_id>\"";
|
||||||
|
|
||||||
pub fn parse(net: &str) -> Result<Self> {
|
pub fn parse(net: &str) -> Result<Self> {
|
||||||
let mut parser = OptionParser::new();
|
let mut parser = OptionParser::new();
|
||||||
@ -734,7 +743,8 @@ impl NetConfig {
|
|||||||
.add("queue_size")
|
.add("queue_size")
|
||||||
.add("num_queues")
|
.add("num_queues")
|
||||||
.add("vhost_user")
|
.add("vhost_user")
|
||||||
.add("socket");
|
.add("socket")
|
||||||
|
.add("id");
|
||||||
parser.parse(net).map_err(Error::ParseNetwork)?;
|
parser.parse(net).map_err(Error::ParseNetwork)?;
|
||||||
|
|
||||||
let tap = parser.get("tap");
|
let tap = parser.get("tap");
|
||||||
@ -768,6 +778,7 @@ impl NetConfig {
|
|||||||
.map_err(Error::ParseNetwork)?
|
.map_err(Error::ParseNetwork)?
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
let vhost_socket = parser.get("socket");
|
let vhost_socket = parser.get("socket");
|
||||||
|
let id = parser.get("id");
|
||||||
|
|
||||||
Ok(NetConfig {
|
Ok(NetConfig {
|
||||||
tap,
|
tap,
|
||||||
@ -779,6 +790,7 @@ impl NetConfig {
|
|||||||
queue_size,
|
queue_size,
|
||||||
vhost_user,
|
vhost_user,
|
||||||
vhost_socket,
|
vhost_socket,
|
||||||
|
id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -924,12 +936,14 @@ pub struct PmemConfig {
|
|||||||
pub mergeable: bool,
|
pub mergeable: bool,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub discard_writes: bool,
|
pub discard_writes: bool,
|
||||||
|
#[serde(default)]
|
||||||
|
pub id: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PmemConfig {
|
impl PmemConfig {
|
||||||
pub const SYNTAX: &'static str = "Persistent memory parameters \
|
pub const SYNTAX: &'static str = "Persistent memory parameters \
|
||||||
\"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,id=<device_id>\"";
|
||||||
pub fn parse(pmem: &str) -> Result<Self> {
|
pub fn parse(pmem: &str) -> Result<Self> {
|
||||||
let mut parser = OptionParser::new();
|
let mut parser = OptionParser::new();
|
||||||
parser
|
parser
|
||||||
@ -937,7 +951,8 @@ impl PmemConfig {
|
|||||||
.add("file")
|
.add("file")
|
||||||
.add("mergeable")
|
.add("mergeable")
|
||||||
.add("iommu")
|
.add("iommu")
|
||||||
.add("discard_writes");
|
.add("discard_writes")
|
||||||
|
.add("id");
|
||||||
parser.parse(pmem).map_err(Error::ParsePersistentMemory)?;
|
parser.parse(pmem).map_err(Error::ParsePersistentMemory)?;
|
||||||
|
|
||||||
let file = PathBuf::from(parser.get("file").ok_or(Error::ParsePmemFileMissing)?);
|
let file = PathBuf::from(parser.get("file").ok_or(Error::ParsePmemFileMissing)?);
|
||||||
@ -961,6 +976,7 @@ impl PmemConfig {
|
|||||||
.map_err(Error::ParsePersistentMemory)?
|
.map_err(Error::ParsePersistentMemory)?
|
||||||
.unwrap_or(Toggle(false))
|
.unwrap_or(Toggle(false))
|
||||||
.0;
|
.0;
|
||||||
|
let id = parser.get("id");
|
||||||
|
|
||||||
Ok(PmemConfig {
|
Ok(PmemConfig {
|
||||||
file,
|
file,
|
||||||
@ -968,6 +984,7 @@ impl PmemConfig {
|
|||||||
iommu,
|
iommu,
|
||||||
mergeable,
|
mergeable,
|
||||||
discard_writes,
|
discard_writes,
|
||||||
|
id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1455,6 +1472,14 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
DiskConfig::parse("path=/path/to_file,id=mydisk0")?,
|
||||||
|
DiskConfig {
|
||||||
|
path: Some(PathBuf::from("/path/to_file")),
|
||||||
|
id: Some("mydisk0".to_owned()),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
DiskConfig::parse("path=/path/to_file,vhost_user=true")?,
|
DiskConfig::parse("path=/path/to_file,vhost_user=true")?,
|
||||||
DiskConfig {
|
DiskConfig {
|
||||||
@ -1545,6 +1570,15 @@ mod tests {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
NetConfig::parse("mac=de:ad:be:ef:12:34,id=mynet0")?,
|
||||||
|
NetConfig {
|
||||||
|
mac: MacAddr::parse_str("de:ad:be:ef:12:34").unwrap(),
|
||||||
|
id: Some("mynet0".to_owned()),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
NetConfig::parse(
|
NetConfig::parse(
|
||||||
"mac=de:ad:be:ef:12:34,tap=tap0,ip=192.168.100.1,mask=255.255.255.128"
|
"mac=de:ad:be:ef:12:34,tap=tap0,ip=192.168.100.1,mask=255.255.255.128"
|
||||||
@ -1681,6 +1715,15 @@ mod tests {
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
assert_eq!(
|
||||||
|
PmemConfig::parse("file=/tmp/pmem,size=128M,id=mypmem0")?,
|
||||||
|
PmemConfig {
|
||||||
|
file: PathBuf::from("/tmp/pmem"),
|
||||||
|
size: 128 << 20,
|
||||||
|
id: Some("mypmem0".to_owned()),
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
PmemConfig::parse("file=/tmp/pmem,size=128M,iommu=on,mergeable=on,discard_writes=on")?,
|
PmemConfig::parse("file=/tmp/pmem,size=128M,iommu=on,mergeable=on,discard_writes=on")?,
|
||||||
PmemConfig {
|
PmemConfig {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user