vmm: config: Require a socket when using vhost-user

With self-spawning being removed both parameters are now required.

Fixes: #1925

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-11-06 09:44:17 +00:00 committed by Samuel Ortiz
parent ec84abc5c7
commit 0005d11e32
2 changed files with 21 additions and 9 deletions

View File

@ -812,14 +812,12 @@ mod unit_tests {
"shared=true", "shared=true",
"--disk", "--disk",
"vhost_user=true,socket=/tmp/sock1", "vhost_user=true,socket=/tmp/sock1",
"path=/path/to/disk/2",
], ],
r#"{ r#"{
"kernel": {"path": "/path/to/kernel"}, "kernel": {"path": "/path/to/kernel"},
"memory" : { "shared": true, "size": 536870912 }, "memory" : { "shared": true, "size": 536870912 },
"disks": [ "disks": [
{"vhost_user":true, "vhost_socket":"/tmp/sock1"}, {"vhost_user":true, "vhost_socket":"/tmp/sock1"}
{"path": "/path/to/disk/2"}
] ]
}"#, }"#,
true, true,
@ -833,14 +831,12 @@ mod unit_tests {
"shared=true", "shared=true",
"--disk", "--disk",
"vhost_user=true,socket=/tmp/sock1", "vhost_user=true,socket=/tmp/sock1",
"path=/path/to/disk/2",
], ],
r#"{ r#"{
"kernel": {"path": "/path/to/kernel"}, "kernel": {"path": "/path/to/kernel"},
"memory" : { "shared": true, "size": 536870912 }, "memory" : { "shared": true, "size": 536870912 },
"disks": [ "disks": [
{"vhost_user":true, "vhost_socket":"/tmp/sock1"}, {"vhost_user":true, "vhost_socket":"/tmp/sock1"}
{"path": "/path/to/disk/2"}
] ]
}"#, }"#,
true, true,

View File

@ -95,6 +95,8 @@ pub enum ValidationError {
DiskSocketAndPath, DiskSocketAndPath,
/// Using vhost user requires shared memory /// Using vhost user requires shared memory
VhostUserRequiresSharedMemory, VhostUserRequiresSharedMemory,
/// No socket provided for vhost_use
VhostUserMissingSocket,
/// Trying to use IOMMU without PCI /// Trying to use IOMMU without PCI
IommuUnsupported, IommuUnsupported,
/// Trying to use VFIO without PCI /// Trying to use VFIO without PCI
@ -121,6 +123,7 @@ impl fmt::Display for ValidationError {
VhostUserRequiresSharedMemory => { VhostUserRequiresSharedMemory => {
write!(f, "Using vhost-user requires using shared memory") write!(f, "Using vhost-user requires using shared memory")
} }
VhostUserMissingSocket => write!(f, "No socket provided when using vhost-user"),
IommuUnsupported => write!(f, "Using an IOMMU without PCI support is unsupported"), IommuUnsupported => write!(f, "Using an IOMMU without PCI support is unsupported"),
VfioUnsupported => write!(f, "Using VFIO without PCI support is unsupported"), VfioUnsupported => write!(f, "Using VFIO without PCI support is unsupported"),
CpuTopologyZeroPart => write!(f, "No part of the CPU topology can be zero"), CpuTopologyZeroPart => write!(f, "No part of the CPU topology can be zero"),
@ -1453,6 +1456,9 @@ impl VmConfig {
if disk.vhost_user && !self.memory.shared { if disk.vhost_user && !self.memory.shared {
return Err(ValidationError::VhostUserRequiresSharedMemory); return Err(ValidationError::VhostUserRequiresSharedMemory);
} }
if disk.vhost_user && disk.vhost_socket.is_none() {
return Err(ValidationError::VhostUserMissingSocket);
}
} }
} }
@ -1788,9 +1794,9 @@ mod tests {
} }
); );
assert_eq!( assert_eq!(
DiskConfig::parse("path=/path/to_file,vhost_user=true")?, DiskConfig::parse("vhost_user=true,socket=/tmp/sock")?,
DiskConfig { DiskConfig {
path: Some(PathBuf::from("/path/to_file")), vhost_socket: Some(String::from("/tmp/sock")),
vhost_user: true, vhost_user: true,
..Default::default() ..Default::default()
} }
@ -2264,9 +2270,18 @@ mod tests {
}]); }]);
assert!(invalid_config.validate().is_err()); assert!(invalid_config.validate().is_err());
let mut invalid_config = valid_config.clone();
invalid_config.disks = Some(vec![DiskConfig {
vhost_user: true,
vhost_socket: Some("/path/to/sock".to_owned()),
..Default::default()
}]);
assert!(invalid_config.validate().is_err());
let mut still_valid_config = valid_config.clone(); let mut still_valid_config = valid_config.clone();
still_valid_config.disks = Some(vec![DiskConfig { still_valid_config.disks = Some(vec![DiskConfig {
vhost_user: true, vhost_user: true,
vhost_socket: Some("/path/to/sock".to_owned()),
..Default::default() ..Default::default()
}]); }]);
still_valid_config.memory.shared = true; still_valid_config.memory.shared = true;
@ -2282,6 +2297,7 @@ mod tests {
let mut still_valid_config = valid_config.clone(); let mut still_valid_config = valid_config.clone();
still_valid_config.net = Some(vec![NetConfig { still_valid_config.net = Some(vec![NetConfig {
vhost_user: true, vhost_user: true,
vhost_socket: Some("/path/to/sock".to_owned()),
..Default::default() ..Default::default()
}]); }]);
still_valid_config.memory.shared = true; still_valid_config.memory.shared = true;
@ -2293,7 +2309,7 @@ mod tests {
}]); }]);
assert!(invalid_config.validate().is_err()); assert!(invalid_config.validate().is_err());
let mut still_valid_config = valid_config.clone(); let mut still_valid_config = valid_config;
invalid_config.fs = Some(vec![FsConfig { invalid_config.fs = Some(vec![FsConfig {
..Default::default() ..Default::default()
}]); }]);