diff --git a/virtio-devices/src/device.rs b/virtio-devices/src/device.rs index 80d801f89..1fb5371ec 100644 --- a/virtio-devices/src/device.rs +++ b/virtio-devices/src/device.rs @@ -323,130 +323,3 @@ impl Pausable for VirtioCommon { Ok(()) } } - -#[macro_export] -macro_rules! virtio_pausable_trait_definition { - () => { - trait VirtioPausable { - fn virtio_pause(&mut self) -> std::result::Result<(), MigratableError>; - fn virtio_resume(&mut self) -> std::result::Result<(), MigratableError>; - } - }; -} -#[macro_export] -macro_rules! virtio_pausable_trait_inner { - () => { - // This is the common Pausable trait implementation for virtio. - fn virtio_pause(&mut self) -> result::Result<(), MigratableError> { - debug!( - "Pausing virtio-{}", - VirtioDeviceType::from(self.device_type()) - ); - self.paused.store(true, Ordering::SeqCst); - if let Some(pause_evt) = &self.pause_evt { - pause_evt - .write(1) - .map_err(|e| MigratableError::Pause(e.into()))?; - - // Wait for all threads to acknowledge the pause before going - // any further. This is exclusively performed when pause_evt - // eventfd is Some(), as this means the virtio device has been - // activated. One specific case where the device can be paused - // while it hasn't been yet activated is snapshot/restore. - self.paused_sync.wait(); - } - - Ok(()) - } - - fn virtio_resume(&mut self) -> result::Result<(), MigratableError> { - debug!( - "Resuming virtio-{}", - VirtioDeviceType::from(self.device_type()) - ); - self.paused.store(false, Ordering::SeqCst); - if let Some(epoll_threads) = &self.epoll_threads { - for i in 0..epoll_threads.len() { - epoll_threads[i].thread().unpark(); - } - } - - Ok(()) - } - }; -} - -#[macro_export] -macro_rules! virtio_pausable_trait { - ($type:ident) => { - virtio_pausable_trait_definition!(); - - impl VirtioPausable for $type { - virtio_pausable_trait_inner!(); - } - }; - - ($type:ident, T: $($bounds:tt)+) => { - virtio_pausable_trait_definition!(); - - impl VirtioPausable for $type { - virtio_pausable_trait_inner!(); - } - }; -} - -#[macro_export] -macro_rules! virtio_pausable_inner { - ($type:ident) => { - fn pause(&mut self) -> result::Result<(), MigratableError> { - self.virtio_pause() - } - - fn resume(&mut self) -> result::Result<(), MigratableError> { - self.virtio_resume() - } - }; -} - -#[macro_export] -macro_rules! virtio_pausable { - ($type:ident) => { - virtio_pausable_trait!($type); - - impl Pausable for $type { - virtio_pausable_inner!($type); - } - }; - - // For type bound virtio types - ($type:ident, T: $($bounds:tt)+) => { - virtio_pausable_trait!($type, T: $($bounds)+); - - impl Pausable for $type { - virtio_pausable_inner!($type); - } - }; -} - -#[macro_export] -macro_rules! virtio_ctrl_q_pausable { - ($type:ident) => { - virtio_pausable_trait!($type); - - impl Pausable for $type { - fn pause(&mut self) -> result::Result<(), MigratableError> { - self.virtio_pause() - } - - fn resume(&mut self) -> result::Result<(), MigratableError> { - self.virtio_resume()?; - - if let Some(ctrl_queue_epoll_thread) = &self.ctrl_queue_epoll_thread { - ctrl_queue_epoll_thread.thread().unpark(); - } - - Ok(()) - } - } - }; -}