vmm: support removing devices before VM is booted

If the VM has been configured but not yet booted, all we need to do to
support removing a device is to remove it from the config, so it will
never be created.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
This commit is contained in:
Alyssa Ross
2023-07-10 08:53:34 +00:00
committed by Bo Chen
parent 87d81dd2b1
commit 69bd0036d9
3 changed files with 76 additions and 45 deletions
+9 -2
View File
@@ -1025,13 +1025,20 @@ impl Vmm {
fn vm_remove_device(&mut self, id: String) -> result::Result<(), VmError> {
if let Some(ref mut vm) = self.vm {
if let Err(e) = vm.remove_device(id) {
error!("Error when removing new device to the VM: {:?}", e);
error!("Error when removing device from the VM: {:?}", e);
Err(e)
} else {
Ok(())
}
} else if let Some(ref config) = self.vm_config {
let mut config = config.lock().unwrap();
if config.remove_device(&id) {
Ok(())
} else {
Err(VmError::NoDeviceToRemove(id))
}
} else {
Err(VmError::VmNotRunning)
Err(VmError::VmNotCreated)
}
}