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

Method vm_add_device

vmm/src/lib.rs:2212–2238  ·  view source on GitHub ↗
(
        &mut self,
        device_cfg: DeviceConfig,
    )

Source from the content-addressed store, hash-verified

2210 }
2211
2212 fn vm_add_device(
2213 &mut self,
2214 device_cfg: DeviceConfig,
2215 ) -> result::Result<Option<Vec<u8>>, VmError> {
2216 self.vm_config.as_ref().ok_or(VmError::VmNotCreated)?;
2217
2218 {
2219 // Validate the configuration change in a cloned configuration
2220 let mut config = self.vm_config.as_ref().unwrap().lock().unwrap().clone();
2221 add_to_config(&mut config.devices, device_cfg.clone());
2222 config.validate().map_err(VmError::ConfigValidation)?;
2223 }
2224
2225 if let Some(ref mut vm) = self.vm {
2226 let info = vm.add_device(device_cfg).inspect_err(|e| {
2227 error!("Error when adding new device to the VM: {e:?}");
2228 })?;
2229 serde_json::to_vec(&info)
2230 .map(Some)
2231 .map_err(VmError::SerializeJson)
2232 } else {
2233 // Update VmConfig by adding the new device.
2234 let mut config = self.vm_config.as_ref().unwrap().lock().unwrap();
2235 add_to_config(&mut config.devices, device_cfg);
2236 Ok(None)
2237 }
2238 }
2239
2240 fn vm_add_user_device(
2241 &mut self,

Callers 1

api_vm_add_deviceMethod · 0.45

Calls 5

add_to_configFunction · 0.85
cloneMethod · 0.45
validateMethod · 0.45
add_deviceMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected