diff --git a/src/main.rs b/src/main.rs index bc2213b1e..f76fbfeb3 100755 --- a/src/main.rs +++ b/src/main.rs @@ -199,7 +199,7 @@ fn create_app<'a, 'b>( "Virtio VSOCK parameters \"cid=,sock=,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, ), diff --git a/vmm/src/api/openapi/cloud-hypervisor.yaml b/vmm/src/api/openapi/cloud-hypervisor.yaml index b9ccbf433..2e97bbe95 100644 --- a/vmm/src/api/openapi/cloud-hypervisor.yaml +++ b/vmm/src/api/openapi/cloud-hypervisor.yaml @@ -337,8 +337,6 @@ components: items: $ref: '#/components/schemas/DeviceConfig' vsock: - type: array - items: $ref: '#/components/schemas/VsockConfig' iommu: type: boolean diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 2fedb61ec..0526fbe8e 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -269,7 +269,7 @@ pub struct VmParams<'a> { pub serial: &'a str, pub console: &'a str, pub devices: Option>, - pub vsock: Option>, + pub vsock: Option<&'a str>, } impl<'a> VmParams<'a> { @@ -290,7 +290,7 @@ impl<'a> VmParams<'a> { let fs: Option> = args.values_of("fs").map(|x| x.collect()); let pmem: Option> = args.values_of("pmem").map(|x| x.collect()); let devices: Option> = args.values_of("device").map(|x| x.collect()); - let vsock: Option> = 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>, - pub vsock: Option>, + pub vsock: Option, #[serde(default)] pub iommu: bool, } @@ -1351,19 +1351,14 @@ impl VmConfig { devices = Some(device_config_list); } - let mut vsock: Option> = 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 = 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 = None; if let Some(k) = vm_params.kernel { kernel = Some(KernelConfig { diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index c09027815..33cd1e185 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -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)>> { 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>; - let id = migratable.lock().unwrap().id(); - self.migratable_devices.push((id, migratable)); - } + let migratable = Arc::clone(&vsock_device) as Arc>; + let id = migratable.lock().unwrap().id(); + self.migratable_devices.push((id, migratable)); } Ok(devices)