| 5782 | |
| 5783 | impl Drop for DeviceManager { |
| 5784 | fn drop(&mut self) { |
| 5785 | // Explicitly clear the regions owned by this device to ensure |
| 5786 | // that they are dropped and unmapped before the container is cleared. |
| 5787 | // See eject_device() for the device hot-unplug equivalent. |
| 5788 | self.mmio_regions.lock().unwrap().clear(); |
| 5789 | |
| 5790 | // Wake up the DeviceManager threads (mainly virtio device workers), |
| 5791 | // to avoid deadlock on waiting for paused/parked worker threads. |
| 5792 | if let Err(e) = self.resume() { |
| 5793 | error!("Error resuming DeviceManager: {e:?}"); |
| 5794 | } |
| 5795 | |
| 5796 | for handle in self.virtio_devices.drain(..) { |
| 5797 | handle.virtio_device.lock().unwrap().shutdown(); |
| 5798 | } |
| 5799 | |
| 5800 | if let Some(termios) = *self.original_termios_opt.lock().unwrap() { |
| 5801 | // SAFETY: FFI call |
| 5802 | let _ = unsafe { tcsetattr(stdout().lock().as_raw_fd(), TCSANOW, &termios) }; |
| 5803 | } |
| 5804 | } |
| 5805 | } |
| 5806 | |
| 5807 | #[cfg(test)] |