(&mut self, vdpa_cfg: VdpaConfig)
| 2416 | } |
| 2417 | |
| 2418 | fn vm_add_vdpa(&mut self, vdpa_cfg: VdpaConfig) -> result::Result<Option<Vec<u8>>, VmError> { |
| 2419 | self.vm_config.as_ref().ok_or(VmError::VmNotCreated)?; |
| 2420 | |
| 2421 | { |
| 2422 | // Validate the configuration change in a cloned configuration |
| 2423 | let mut config = self.vm_config.as_ref().unwrap().lock().unwrap().clone(); |
| 2424 | add_to_config(&mut config.vdpa, vdpa_cfg.clone()); |
| 2425 | config.validate().map_err(VmError::ConfigValidation)?; |
| 2426 | } |
| 2427 | |
| 2428 | if let Some(ref mut vm) = self.vm { |
| 2429 | let info = vm.add_vdpa(vdpa_cfg).inspect_err(|e| { |
| 2430 | error!("Error when adding new vDPA device to the VM: {e:?}"); |
| 2431 | })?; |
| 2432 | serde_json::to_vec(&info) |
| 2433 | .map(Some) |
| 2434 | .map_err(VmError::SerializeJson) |
| 2435 | } else { |
| 2436 | // Update VmConfig by adding the new device. |
| 2437 | let mut config = self.vm_config.as_ref().unwrap().lock().unwrap(); |
| 2438 | add_to_config(&mut config.vdpa, vdpa_cfg); |
| 2439 | Ok(None) |
| 2440 | } |
| 2441 | } |
| 2442 | |
| 2443 | fn vm_add_vsock(&mut self, vsock_cfg: VsockConfig) -> result::Result<Option<Vec<u8>>, VmError> { |
| 2444 | self.vm_config.as_ref().ok_or(VmError::VmNotCreated)?; |
no test coverage detected