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

Method vm_add_disk

vmm/src/lib.rs:2285–2308  ·  view source on GitHub ↗
(&mut self, disk_cfg: DiskConfig)

Source from the content-addressed store, hash-verified

2283 }
2284
2285 fn vm_add_disk(&mut self, disk_cfg: DiskConfig) -> result::Result<Option<Vec<u8>>, VmError> {
2286 self.vm_config.as_ref().ok_or(VmError::VmNotCreated)?;
2287
2288 {
2289 // Validate the configuration change in a cloned configuration
2290 let mut config = self.vm_config.as_ref().unwrap().lock().unwrap().clone();
2291 add_to_config(&mut config.disks, disk_cfg.clone());
2292 config.validate().map_err(VmError::ConfigValidation)?;
2293 }
2294
2295 if let Some(ref mut vm) = self.vm {
2296 let info = vm.add_disk(disk_cfg).inspect_err(|e| {
2297 error!("Error when adding new disk to the VM: {e:?}");
2298 })?;
2299 serde_json::to_vec(&info)
2300 .map(Some)
2301 .map_err(VmError::SerializeJson)
2302 } else {
2303 // Update VmConfig by adding the new device.
2304 let mut config = self.vm_config.as_ref().unwrap().lock().unwrap();
2305 add_to_config(&mut config.disks, disk_cfg);
2306 Ok(None)
2307 }
2308 }
2309
2310 fn vm_add_fs(&mut self, fs_cfg: FsConfig) -> result::Result<Option<Vec<u8>>, VmError> {
2311 self.vm_config.as_ref().ok_or(VmError::VmNotCreated)?;

Callers 1

api_vm_add_diskMethod · 0.45

Calls 5

add_to_configFunction · 0.85
cloneMethod · 0.45
validateMethod · 0.45
add_diskMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected