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

Method vm_add_vsock

vmm/src/lib.rs:2443–2471  ·  view source on GitHub ↗
(&mut self, vsock_cfg: VsockConfig)

Source from the content-addressed store, hash-verified

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)?;
2445
2446 {
2447 // Validate the configuration change in a cloned configuration
2448 let mut config = self.vm_config.as_ref().unwrap().lock().unwrap().clone();
2449
2450 if config.vsock.is_some() {
2451 return Err(VmError::TooManyVsockDevices);
2452 }
2453
2454 config.vsock = Some(vsock_cfg.clone());
2455 config.validate().map_err(VmError::ConfigValidation)?;
2456 }
2457
2458 if let Some(ref mut vm) = self.vm {
2459 let info = vm.add_vsock(vsock_cfg).inspect_err(|e| {
2460 error!("Error when adding new vsock device to the VM: {e:?}");
2461 })?;
2462 serde_json::to_vec(&info)
2463 .map(Some)
2464 .map_err(VmError::SerializeJson)
2465 } else {
2466 // Update VmConfig by adding the new device.
2467 let mut config = self.vm_config.as_ref().unwrap().lock().unwrap();
2468 config.vsock = Some(vsock_cfg);
2469 Ok(None)
2470 }
2471 }
2472
2473 fn vm_counters(&mut self) -> result::Result<Option<Vec<u8>>, VmError> {
2474 if let Some(ref mut vm) = self.vm {

Callers 1

api_vm_add_vsockMethod · 0.45

Calls 4

cloneMethod · 0.45
validateMethod · 0.45
add_vsockMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected