vmm, main: Support only zero or one vsock devices

The Linux kernel does not support multiple virtio-vsock devices.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-04-28 18:10:32 +01:00 committed by Sebastien Boeuf
parent 9d1f95a3cc
commit 10348f73e4
4 changed files with 33 additions and 71 deletions

View File

@ -199,7 +199,7 @@ fn create_app<'a, 'b>(
"Virtio VSOCK parameters \"cid=<context_id>,sock=<socket_path>,iommu=on|off\"",
)
.takes_value(true)
.min_values(1)
.number_of_values(1)
.group("vm-config"),
)
.arg(
@ -1435,34 +1435,13 @@ mod unit_tests {
"/path/to/kernel",
"--vsock",
"cid=123,sock=/path/to/sock/1",
"cid=456,sock=/path/to/sock/2",
],
r#"{
"kernel": {"path": "/path/to/kernel"},
"vsock": [
{"cid": 123, "sock": "/path/to/sock/1"},
{"cid": 456, "sock": "/path/to/sock/2"}
]
"vsock": {"cid": 123, "sock": "/path/to/sock/1"}
}"#,
true,
),
(
vec![
"cloud-hypervisor",
"--kernel",
"/path/to/kernel",
"--vsock",
"cid=123,sock=/path/to/sock/1",
"cid=456,sock=/path/to/sock/2",
],
r#"{
"kernel": {"path": "/path/to/kernel"},
"vsock": [
{"cid": 123, "sock": "/path/to/sock/1"}
]
}"#,
false,
),
(
vec![
"cloud-hypervisor",
@ -1473,9 +1452,7 @@ mod unit_tests {
],
r#"{
"kernel": {"path": "/path/to/kernel"},
"vsock": [
{"cid": 123, "sock": "/path/to/sock/1"}
]
"vsock": {"cid": 123, "sock": "/path/to/sock/1"}
}"#,
false,
),
@ -1489,9 +1466,7 @@ mod unit_tests {
],
r#"{
"kernel": {"path": "/path/to/kernel"},
"vsock": [
{"cid": 123, "sock": "/path/to/sock/1", "iommu": true}
],
"vsock": {"cid": 123, "sock": "/path/to/sock/1", "iommu": true},
"iommu": true
}"#,
true,
@ -1506,9 +1481,7 @@ mod unit_tests {
],
r#"{
"kernel": {"path": "/path/to/kernel"},
"vsock": [
{"cid": 123, "sock": "/path/to/sock/1", "iommu": true}
]
"vsock": {"cid": 123, "sock": "/path/to/sock/1", "iommu": true}
}"#,
false,
),
@ -1522,9 +1495,7 @@ mod unit_tests {
],
r#"{
"kernel": {"path": "/path/to/kernel"},
"vsock": [
{"cid": 123, "sock": "/path/to/sock/1", "iommu": false}
]
"vsock": {"cid": 123, "sock": "/path/to/sock/1", "iommu": false}
}"#,
true,
),

View File

@ -337,8 +337,6 @@ components:
items:
$ref: '#/components/schemas/DeviceConfig'
vsock:
type: array
items:
$ref: '#/components/schemas/VsockConfig'
iommu:
type: boolean

View File

@ -269,7 +269,7 @@ pub struct VmParams<'a> {
pub serial: &'a str,
pub console: &'a str,
pub devices: Option<Vec<&'a str>>,
pub vsock: Option<Vec<&'a str>>,
pub vsock: Option<&'a str>,
}
impl<'a> VmParams<'a> {
@ -290,7 +290,7 @@ impl<'a> VmParams<'a> {
let fs: Option<Vec<&str>> = args.values_of("fs").map(|x| x.collect());
let pmem: Option<Vec<&str>> = args.values_of("pmem").map(|x| x.collect());
let devices: Option<Vec<&str>> = args.values_of("device").map(|x| x.collect());
let vsock: Option<Vec<&str>> = args.values_of("vsock").map(|x| x.collect());
let vsock: Option<&str> = args.value_of("vsock");
VmParams {
cpus,
@ -1218,7 +1218,7 @@ pub struct VmConfig {
#[serde(default = "ConsoleConfig::default_console")]
pub console: ConsoleConfig,
pub devices: Option<Vec<DeviceConfig>>,
pub vsock: Option<Vec<VsockConfig>>,
pub vsock: Option<VsockConfig>,
#[serde(default)]
pub iommu: bool,
}
@ -1351,19 +1351,14 @@ impl VmConfig {
devices = Some(device_config_list);
}
let mut vsock: Option<Vec<VsockConfig>> = None;
if let Some(vsock_list) = &vm_params.vsock {
let mut vsock_config_list = Vec::new();
for item in vsock_list.iter() {
let vsock_config = VsockConfig::parse(item)?;
if vsock_config.iommu {
iommu = true;
}
vsock_config_list.push(vsock_config);
let mut vsock: Option<VsockConfig> = None;
if let Some(vs) = &vm_params.vsock {
let vsock_config = VsockConfig::parse(vs)?;
if vsock_config.iommu {
iommu = true;
}
vsock = Some(vsock_config_list);
vsock = Some(vsock_config);
}
let mut kernel: Option<KernelConfig> = None;
if let Some(k) = vm_params.kernel {
kernel = Some(KernelConfig {

View File

@ -1120,7 +1120,7 @@ impl DeviceManager {
devices.append(&mut self.make_virtio_pmem_devices()?);
// Add virtio-vsock if required
devices.append(&mut self.make_virtio_vsock_devices()?);
devices.append(&mut self.make_virtio_vsock_device()?);
devices.append(&mut self.make_virtio_mem_devices()?);
@ -1640,32 +1640,30 @@ impl DeviceManager {
Ok(devices)
}
fn make_virtio_vsock_devices(
fn make_virtio_vsock_device(
&mut self,
) -> DeviceManagerResult<Vec<(VirtioDeviceArc, bool, Option<String>)>> {
let mut devices = Vec::new();
// Add vsock if required
if let Some(vsock_list_cfg) = &self.config.lock().unwrap().vsock {
for vsock_cfg in vsock_list_cfg.iter() {
let socket_path = vsock_cfg
.sock
.to_str()
.ok_or(DeviceManagerError::CreateVsockConvertPath)?;
let backend =
vm_virtio::vsock::VsockUnixBackend::new(vsock_cfg.cid, socket_path.to_string())
.map_err(DeviceManagerError::CreateVsockBackend)?;
if let Some(vsock_cfg) = &self.config.lock().unwrap().vsock {
let socket_path = vsock_cfg
.sock
.to_str()
.ok_or(DeviceManagerError::CreateVsockConvertPath)?;
let backend =
vm_virtio::vsock::VsockUnixBackend::new(vsock_cfg.cid, socket_path.to_string())
.map_err(DeviceManagerError::CreateVsockBackend)?;
let vsock_device = Arc::new(Mutex::new(
vm_virtio::Vsock::new(vsock_cfg.cid, backend, vsock_cfg.iommu)
.map_err(DeviceManagerError::CreateVirtioVsock)?,
));
let vsock_device = Arc::new(Mutex::new(
vm_virtio::Vsock::new(vsock_cfg.cid, backend, vsock_cfg.iommu)
.map_err(DeviceManagerError::CreateVirtioVsock)?,
));
devices.push((Arc::clone(&vsock_device) as VirtioDeviceArc, false, None));
devices.push((Arc::clone(&vsock_device) as VirtioDeviceArc, false, None));
let migratable = Arc::clone(&vsock_device) as Arc<Mutex<dyn Migratable>>;
let id = migratable.lock().unwrap().id();
self.migratable_devices.push((id, migratable));
}
let migratable = Arc::clone(&vsock_device) as Arc<Mutex<dyn Migratable>>;
let id = migratable.lock().unwrap().id();
self.migratable_devices.push((id, migratable));
}
Ok(devices)