mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
tests,vm-virtio,vmm: Use 'socket' for all CLI/API parameters
This patch unifies the inconsistent uses of 'socket' and 'sock' from our CLI/API parameters. Fixes: #1091 Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
@@ -506,12 +506,12 @@ components:
|
||||
FsConfig:
|
||||
required:
|
||||
- tag
|
||||
- sock
|
||||
- socket
|
||||
type: object
|
||||
properties:
|
||||
tag:
|
||||
type: string
|
||||
sock:
|
||||
socket:
|
||||
type: string
|
||||
num_queues:
|
||||
type: integer
|
||||
@@ -581,7 +581,7 @@ components:
|
||||
VsockConfig:
|
||||
required:
|
||||
- cid
|
||||
- sock
|
||||
- socket
|
||||
type: object
|
||||
properties:
|
||||
cid:
|
||||
@@ -589,7 +589,7 @@ components:
|
||||
format: int64
|
||||
minimum: 3
|
||||
description: Guest Vsock CID
|
||||
sock:
|
||||
socket:
|
||||
type: string
|
||||
description: Path to UNIX domain socket, used to proxy vsock connections.
|
||||
iommu:
|
||||
|
||||
@@ -123,7 +123,7 @@ impl fmt::Display for Error {
|
||||
ParseDevice(o) => write!(f, "Error parsing --device: {}", o),
|
||||
ParseDevicePathMissing => write!(f, "Error parsing --device: path missing"),
|
||||
ParseFileSystem(o) => write!(f, "Error parsing --fs: {}", o),
|
||||
ParseFsSockMissing => write!(f, "Error parsing --fs: sock missing"),
|
||||
ParseFsSockMissing => write!(f, "Error parsing --fs: socket missing"),
|
||||
ParseFsTagMissing => write!(f, "Error parsing --fs: tag missing"),
|
||||
InvalidCacheSizeWithDaxOff => {
|
||||
write!(f, "Error parsing --fs: cache_size used with dax=on")
|
||||
@@ -132,7 +132,7 @@ impl fmt::Display for Error {
|
||||
ParsePmemFileMissing => write!(f, "Error parsing --pmem: file missing"),
|
||||
ParseVsock(o) => write!(f, "Error parsing --vsock: {}", o),
|
||||
ParseVsockCidMissing => write!(f, "Error parsing --vsock: cid missing"),
|
||||
ParseVsockSockMissing => write!(f, "Error parsing --vsock: sock missing"),
|
||||
ParseVsockSockMissing => write!(f, "Error parsing --vsock: socket missing"),
|
||||
ParseMemory(o) => write!(f, "Error parsing --memory: {}", o),
|
||||
ParseNetwork(o) => write!(f, "Error parsing --net: {}", o),
|
||||
ParseDisk(o) => write!(f, "Error parsing --disk: {}", o),
|
||||
@@ -857,7 +857,7 @@ impl Default for RngConfig {
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
|
||||
pub struct FsConfig {
|
||||
pub tag: String,
|
||||
pub sock: PathBuf,
|
||||
pub socket: PathBuf,
|
||||
#[serde(default = "default_fsconfig_num_queues")]
|
||||
pub num_queues: usize,
|
||||
#[serde(default = "default_fsconfig_queue_size")]
|
||||
@@ -890,7 +890,7 @@ impl Default for FsConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
tag: "".to_owned(),
|
||||
sock: PathBuf::new(),
|
||||
socket: PathBuf::new(),
|
||||
num_queues: default_fsconfig_num_queues(),
|
||||
queue_size: default_fsconfig_queue_size(),
|
||||
dax: default_fsconfig_dax(),
|
||||
@@ -902,7 +902,7 @@ impl Default for FsConfig {
|
||||
|
||||
impl FsConfig {
|
||||
pub const SYNTAX: &'static str = "virtio-fs parameters \
|
||||
\"tag=<tag_name>,sock=<socket_path>,num_queues=<number_of_queues>,\
|
||||
\"tag=<tag_name>,socket=<socket_path>,num_queues=<number_of_queues>,\
|
||||
queue_size=<size_of_each_queue>,dax=on|off,cache_size=<DAX cache size: \
|
||||
default 8Gib>,id=<device_id>\"";
|
||||
|
||||
@@ -914,12 +914,12 @@ impl FsConfig {
|
||||
.add("cache_size")
|
||||
.add("queue_size")
|
||||
.add("num_queues")
|
||||
.add("sock")
|
||||
.add("socket")
|
||||
.add("id");
|
||||
parser.parse(fs).map_err(Error::ParseFileSystem)?;
|
||||
|
||||
let tag = parser.get("tag").ok_or(Error::ParseFsTagMissing)?;
|
||||
let sock = PathBuf::from(parser.get("sock").ok_or(Error::ParseFsSockMissing)?);
|
||||
let socket = PathBuf::from(parser.get("socket").ok_or(Error::ParseFsSockMissing)?);
|
||||
|
||||
let queue_size = parser
|
||||
.convert("queue_size")
|
||||
@@ -950,7 +950,7 @@ impl FsConfig {
|
||||
|
||||
Ok(FsConfig {
|
||||
tag,
|
||||
sock,
|
||||
socket,
|
||||
num_queues,
|
||||
queue_size,
|
||||
dax,
|
||||
@@ -1141,7 +1141,7 @@ impl DeviceConfig {
|
||||
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Default)]
|
||||
pub struct VsockConfig {
|
||||
pub cid: u64,
|
||||
pub sock: PathBuf,
|
||||
pub socket: PathBuf,
|
||||
#[serde(default)]
|
||||
pub iommu: bool,
|
||||
#[serde(default)]
|
||||
@@ -1150,14 +1150,14 @@ pub struct VsockConfig {
|
||||
|
||||
impl VsockConfig {
|
||||
pub const SYNTAX: &'static str = "Virtio VSOCK parameters \
|
||||
\"cid=<context_id>,sock=<socket_path>,iommu=on|off,id=<device_id>\"";
|
||||
\"cid=<context_id>,socket=<socket_path>,iommu=on|off,id=<device_id>\"";
|
||||
pub fn parse(vsock: &str) -> Result<Self> {
|
||||
let mut parser = OptionParser::new();
|
||||
parser.add("sock").add("cid").add("iommu").add("id");
|
||||
parser.add("socket").add("cid").add("iommu").add("id");
|
||||
parser.parse(vsock).map_err(Error::ParseVsock)?;
|
||||
|
||||
let sock = parser
|
||||
.get("sock")
|
||||
let socket = parser
|
||||
.get("socket")
|
||||
.map(PathBuf::from)
|
||||
.ok_or(Error::ParseVsockSockMissing)?;
|
||||
let iommu = parser
|
||||
@@ -1173,7 +1173,7 @@ impl VsockConfig {
|
||||
|
||||
Ok(VsockConfig {
|
||||
cid,
|
||||
sock,
|
||||
socket,
|
||||
iommu,
|
||||
id,
|
||||
})
|
||||
@@ -1663,12 +1663,14 @@ mod tests {
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
NetConfig::parse("mac=de:ad:be:ef:12:34,host_mac=12:34:de:ad:be:ef,vhost_user=true,socket=/tmp/socket")?,
|
||||
NetConfig::parse(
|
||||
"mac=de:ad:be:ef:12:34,host_mac=12:34:de:ad:be:ef,vhost_user=true,socket=/tmp/sock"
|
||||
)?,
|
||||
NetConfig {
|
||||
mac: MacAddr::parse_str("de:ad:be:ef:12:34").unwrap(),
|
||||
host_mac: MacAddr::parse_str("12:34:de:ad:be:ef").unwrap(),
|
||||
vhost_user: true,
|
||||
vhost_socket: Some("/tmp/socket".to_owned()),
|
||||
vhost_socket: Some("/tmp/sock".to_owned()),
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
@@ -1720,27 +1722,27 @@ mod tests {
|
||||
// "tag" and "socket" must be supplied
|
||||
assert!(FsConfig::parse("").is_err());
|
||||
assert!(FsConfig::parse("tag=mytag").is_err());
|
||||
assert!(FsConfig::parse("sock=/tmp/sock").is_err());
|
||||
assert!(FsConfig::parse("socket=/tmp/sock").is_err());
|
||||
assert_eq!(
|
||||
FsConfig::parse("tag=mytag,sock=/tmp/sock")?,
|
||||
FsConfig::parse("tag=mytag,socket=/tmp/sock")?,
|
||||
FsConfig {
|
||||
sock: PathBuf::from("/tmp/sock"),
|
||||
socket: PathBuf::from("/tmp/sock"),
|
||||
tag: "mytag".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
FsConfig::parse("tag=mytag,sock=/tmp/sock")?,
|
||||
FsConfig::parse("tag=mytag,socket=/tmp/sock")?,
|
||||
FsConfig {
|
||||
sock: PathBuf::from("/tmp/sock"),
|
||||
socket: PathBuf::from("/tmp/sock"),
|
||||
tag: "mytag".to_owned(),
|
||||
..Default::default()
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
FsConfig::parse("tag=mytag,sock=/tmp/sock,num_queues=4,queue_size=1024")?,
|
||||
FsConfig::parse("tag=mytag,socket=/tmp/sock,num_queues=4,queue_size=1024")?,
|
||||
FsConfig {
|
||||
sock: PathBuf::from("/tmp/sock"),
|
||||
socket: PathBuf::from("/tmp/sock"),
|
||||
tag: "mytag".to_owned(),
|
||||
num_queues: 4,
|
||||
queue_size: 1024,
|
||||
@@ -1749,9 +1751,9 @@ mod tests {
|
||||
);
|
||||
// DAX on -> default cache size
|
||||
assert_eq!(
|
||||
FsConfig::parse("tag=mytag,sock=/tmp/sock,dax=on")?,
|
||||
FsConfig::parse("tag=mytag,socket=/tmp/sock,dax=on")?,
|
||||
FsConfig {
|
||||
sock: PathBuf::from("/tmp/sock"),
|
||||
socket: PathBuf::from("/tmp/sock"),
|
||||
tag: "mytag".to_owned(),
|
||||
dax: true,
|
||||
cache_size: default_fsconfig_cache_size(),
|
||||
@@ -1759,9 +1761,9 @@ mod tests {
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
FsConfig::parse("tag=mytag,sock=/tmp/sock,dax=on,cache_size=4G")?,
|
||||
FsConfig::parse("tag=mytag,socket=/tmp/sock,dax=on,cache_size=4G")?,
|
||||
FsConfig {
|
||||
sock: PathBuf::from("/tmp/sock"),
|
||||
socket: PathBuf::from("/tmp/sock"),
|
||||
tag: "mytag".to_owned(),
|
||||
dax: true,
|
||||
cache_size: 4 << 30,
|
||||
@@ -1769,7 +1771,7 @@ mod tests {
|
||||
}
|
||||
);
|
||||
// Cache size without DAX is an error
|
||||
assert!(FsConfig::parse("tag=mytag,sock=/tmp/sock,dax=off,cache_size=4G").is_err());
|
||||
assert!(FsConfig::parse("tag=mytag,socket=/tmp/sock,dax=off,cache_size=4G").is_err());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1901,22 +1903,22 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_vsock_parsing() -> Result<()> {
|
||||
// sock and cid is required
|
||||
// socket and cid is required
|
||||
assert!(VsockConfig::parse("").is_err());
|
||||
assert_eq!(
|
||||
VsockConfig::parse("sock=/tmp/sock,cid=1")?,
|
||||
VsockConfig::parse("socket=/tmp/sock,cid=1")?,
|
||||
VsockConfig {
|
||||
cid: 1,
|
||||
sock: PathBuf::from("/tmp/sock"),
|
||||
socket: PathBuf::from("/tmp/sock"),
|
||||
iommu: false,
|
||||
id: None,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
VsockConfig::parse("sock=/tmp/sock,cid=1,iommu=on")?,
|
||||
VsockConfig::parse("socket=/tmp/sock,cid=1,iommu=on")?,
|
||||
VsockConfig {
|
||||
cid: 1,
|
||||
sock: PathBuf::from("/tmp/sock"),
|
||||
socket: PathBuf::from("/tmp/sock"),
|
||||
iommu: true,
|
||||
id: None,
|
||||
}
|
||||
@@ -1993,7 +1995,7 @@ mod tests {
|
||||
|
||||
let mut invalid_config = valid_config.clone();
|
||||
invalid_config.disks = Some(vec![DiskConfig {
|
||||
vhost_socket: Some("/path/to/socket".to_owned()),
|
||||
vhost_socket: Some("/path/to/sock".to_owned()),
|
||||
path: Some(PathBuf::from("/path/to/image")),
|
||||
..Default::default()
|
||||
}]);
|
||||
|
||||
@@ -135,7 +135,7 @@ pub enum DeviceManagerError {
|
||||
/// Cannot create virtio-fs device
|
||||
CreateVirtioFs(vm_virtio::vhost_user::Error),
|
||||
|
||||
/// Virtio-fs device was created without a sock.
|
||||
/// Virtio-fs device was created without a socket.
|
||||
NoVirtioFsSock,
|
||||
|
||||
/// Cannot create vhost-user-blk device
|
||||
@@ -1331,7 +1331,7 @@ impl DeviceManager {
|
||||
/// Launch block backend
|
||||
fn start_block_backend(&mut self, disk_cfg: &DiskConfig) -> DeviceManagerResult<String> {
|
||||
let _socket_file = NamedTempFile::new().map_err(DeviceManagerError::CreateSocketFile)?;
|
||||
let sock = _socket_file.path().to_str().unwrap().to_owned();
|
||||
let socket = _socket_file.path().to_str().unwrap().to_owned();
|
||||
|
||||
let child = std::process::Command::new(&self.vmm_path)
|
||||
.args(&[
|
||||
@@ -1344,7 +1344,7 @@ impl DeviceManager {
|
||||
.ok_or(DeviceManagerError::NoDiskPath)?
|
||||
.to_str()
|
||||
.unwrap(),
|
||||
&sock,
|
||||
&socket,
|
||||
disk_cfg.num_queues,
|
||||
disk_cfg.queue_size
|
||||
),
|
||||
@@ -1358,7 +1358,7 @@ impl DeviceManager {
|
||||
_socket_file,
|
||||
});
|
||||
|
||||
Ok(sock)
|
||||
Ok(socket)
|
||||
}
|
||||
|
||||
fn make_virtio_block_device(
|
||||
@@ -1374,13 +1374,13 @@ impl DeviceManager {
|
||||
};
|
||||
|
||||
if disk_cfg.vhost_user {
|
||||
let sock = if let Some(sock) = disk_cfg.vhost_socket.clone() {
|
||||
sock
|
||||
let socket = if let Some(socket) = disk_cfg.vhost_socket.clone() {
|
||||
socket
|
||||
} else {
|
||||
self.start_block_backend(disk_cfg)?
|
||||
};
|
||||
let vu_cfg = VhostUserConfig {
|
||||
sock,
|
||||
socket,
|
||||
num_queues: disk_cfg.num_queues,
|
||||
queue_size: disk_cfg.queue_size,
|
||||
};
|
||||
@@ -1506,7 +1506,7 @@ impl DeviceManager {
|
||||
/// Launch network backend
|
||||
fn start_net_backend(&mut self, net_cfg: &NetConfig) -> DeviceManagerResult<String> {
|
||||
let _socket_file = NamedTempFile::new().map_err(DeviceManagerError::CreateSocketFile)?;
|
||||
let sock = _socket_file.path().to_str().unwrap().to_owned();
|
||||
let socket = _socket_file.path().to_str().unwrap().to_owned();
|
||||
|
||||
let child = std::process::Command::new(&self.vmm_path)
|
||||
.args(&[
|
||||
@@ -1515,7 +1515,7 @@ impl DeviceManager {
|
||||
"ip={},mask={},socket={},num_queues={},queue_size={},host_mac={}",
|
||||
net_cfg.ip,
|
||||
net_cfg.mask,
|
||||
&sock,
|
||||
&socket,
|
||||
net_cfg.num_queues,
|
||||
net_cfg.queue_size,
|
||||
net_cfg.host_mac
|
||||
@@ -1530,7 +1530,7 @@ impl DeviceManager {
|
||||
_socket_file,
|
||||
});
|
||||
|
||||
Ok(sock)
|
||||
Ok(socket)
|
||||
}
|
||||
|
||||
fn make_virtio_net_device(
|
||||
@@ -1546,13 +1546,13 @@ impl DeviceManager {
|
||||
};
|
||||
|
||||
if net_cfg.vhost_user {
|
||||
let sock = if let Some(sock) = net_cfg.vhost_socket.clone() {
|
||||
sock
|
||||
let socket = if let Some(socket) = net_cfg.vhost_socket.clone() {
|
||||
socket
|
||||
} else {
|
||||
self.start_net_backend(net_cfg)?
|
||||
};
|
||||
let vu_cfg = VhostUserConfig {
|
||||
sock,
|
||||
socket,
|
||||
num_queues: net_cfg.num_queues,
|
||||
queue_size: net_cfg.queue_size,
|
||||
};
|
||||
@@ -1715,7 +1715,7 @@ impl DeviceManager {
|
||||
None
|
||||
};
|
||||
|
||||
if let Some(fs_sock) = fs_cfg.sock.to_str() {
|
||||
if let Some(fs_socket) = fs_cfg.socket.to_str() {
|
||||
let cache = if fs_cfg.dax {
|
||||
let (cache_base, cache_size) = if let Some((base, size)) = cache_range {
|
||||
// The memory needs to be 2MiB aligned in order to support
|
||||
@@ -1792,7 +1792,7 @@ impl DeviceManager {
|
||||
let virtio_fs_device = Arc::new(Mutex::new(
|
||||
vm_virtio::vhost_user::Fs::new(
|
||||
id.clone(),
|
||||
fs_sock,
|
||||
fs_socket,
|
||||
&fs_cfg.tag,
|
||||
fs_cfg.num_queues,
|
||||
fs_cfg.queue_size,
|
||||
@@ -2028,7 +2028,7 @@ impl DeviceManager {
|
||||
};
|
||||
|
||||
let socket_path = vsock_cfg
|
||||
.sock
|
||||
.socket
|
||||
.to_str()
|
||||
.ok_or(DeviceManagerError::CreateVsockConvertPath)?;
|
||||
let backend =
|
||||
@@ -2039,7 +2039,7 @@ impl DeviceManager {
|
||||
vm_virtio::Vsock::new(
|
||||
id.clone(),
|
||||
vsock_cfg.cid,
|
||||
vsock_cfg.sock.clone(),
|
||||
vsock_cfg.socket.clone(),
|
||||
backend,
|
||||
vsock_cfg.iommu,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user