vmm: Ensure proper cleanup on boot errors
Clean up already set up resources in case of boot errors.
@@ -433,8 +433,7 @@ impl Vmm {
self.kernel_config = Some(kernel_config);
}
- /// only call this from run_vmm() or other functions
- /// that can guarantee single instances
+ /// make sure to check Result of this function and call self.stop() in case of Err
pub fn boot_kernel(&mut self) -> Result<()> {
if self.kernel_config.is_none() {
return Err(Error::MissingKernelConfig);
@@ -743,7 +742,10 @@ impl Vmm {
AsyncRequest::StartInstance(sender) => {
let result = match self.boot_kernel() {
Ok(_) => AsyncOutcome::Ok(0),
- Err(e) => AsyncOutcome::Error(format!("cannot boot kernel: {:?}", e)),
+ Err(e) => {
+ self.stop();
+ AsyncOutcome::Error(format!("cannot boot kernel: {:?}", e))
+ }
};
sender.send(result).expect("one-shot channel closed");
}
