MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / vm_add_net

Method vm_add_net

vmm/src/lib.rs:2393–2416  ·  view source on GitHub ↗
(&mut self, net_cfg: NetConfig)

Source from the content-addressed store, hash-verified

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)?;

Callers 1

api_vm_add_netMethod · 0.45

Calls 5

add_to_configFunction · 0.85
cloneMethod · 0.45
validateMethod · 0.45
add_netMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected