(&mut self, net_cfg: NetConfig)
| 2391 | } |
| 2392 | |
| 2393 | fn vm_add_net(&mut self, net_cfg: NetConfig) -> result::Result<Option<Vec<u8>>, VmError> { |
| 2394 | self.vm_config.as_ref().ok_or(VmError::VmNotCreated)?; |
| 2395 | |
| 2396 | { |
| 2397 | // Validate the configuration change in a cloned configuration |
| 2398 | let mut config = self.vm_config.as_ref().unwrap().lock().unwrap().clone(); |
| 2399 | add_to_config(&mut config.net, net_cfg.clone()); |
| 2400 | config.validate().map_err(VmError::ConfigValidation)?; |
| 2401 | } |
| 2402 | |
| 2403 | if let Some(ref mut vm) = self.vm { |
| 2404 | let info = vm.add_net(net_cfg).inspect_err(|e| { |
| 2405 | error!("Error when adding new network device to the VM: {e:?}"); |
| 2406 | })?; |
| 2407 | serde_json::to_vec(&info) |
| 2408 | .map(Some) |
| 2409 | .map_err(VmError::SerializeJson) |
| 2410 | } else { |
| 2411 | // Update VmConfig by adding the new device. |
| 2412 | let mut config = self.vm_config.as_ref().unwrap().lock().unwrap(); |
| 2413 | add_to_config(&mut config.net, net_cfg); |
| 2414 | Ok(None) |
| 2415 | } |
| 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)?; |
no test coverage detected