upcall: remove upcall client when stopping vm

In order to avoid resource leak, we need to remove upcall client in vm
and vcpu manager when stopping vm.

Signed-off-by: Chao Wu <chaowu@linux.alibaba.com>
This commit is contained in:
Chao Wu 2022-12-28 20:23:39 +08:00
parent 3605062258
commit a2e3715e01
2 changed files with 14 additions and 0 deletions

View File

@ -492,6 +492,13 @@ impl Vm {
.map_err(StopMicrovmError::DeviceManager) .map_err(StopMicrovmError::DeviceManager)
} }
/// Remove upcall client when the VM is destoryed.
#[cfg(feature = "dbs-upcall")]
pub fn remove_upcall(&mut self) -> std::result::Result<(), StopMicrovmError> {
self.upcall_client = None;
Ok(())
}
/// Reset the console into canonical mode. /// Reset the console into canonical mode.
pub fn reset_console(&self) -> std::result::Result<(), DeviceMgrError> { pub fn reset_console(&self) -> std::result::Result<(), DeviceMgrError> {
self.device_manager.reset_console() self.device_manager.reset_console()

View File

@ -162,6 +162,11 @@ impl Vmm {
warn!("failed to remove devices: {:?}", e); warn!("failed to remove devices: {:?}", e);
} }
#[cfg(feature = "dbs-upcall")]
if let Err(e) = vm.remove_upcall() {
warn!("failed to remove upcall: {:?}", e);
}
if let Err(e) = vm.reset_console() { if let Err(e) = vm.reset_console() {
warn!("Cannot set canonical mode for the terminal. {:?}", e); warn!("Cannot set canonical mode for the terminal. {:?}", e);
} }
@ -174,6 +179,8 @@ impl Vmm {
if let Err(e) = mgr.exit_all_vcpus() { if let Err(e) = mgr.exit_all_vcpus() {
warn!("Failed to exit vcpu thread. {:?}", e); warn!("Failed to exit vcpu thread. {:?}", e);
} }
#[cfg(feature = "dbs-upcall")]
mgr.set_upcall_channel(None);
} }
Err(e) => warn!("Failed to get vcpu manager {:?}", e), Err(e) => warn!("Failed to get vcpu manager {:?}", e),
} }