diff --git a/cros_async/src/timer.rs b/cros_async/src/timer.rs index 3a29c8db00..dcf4e8ec21 100644 --- a/cros_async/src/timer.rs +++ b/cros_async/src/timer.rs @@ -50,6 +50,11 @@ impl TimerAsync { pub fn reset(&mut self, dur: Duration, interval: Option) -> SysResult<()> { self.io_source.as_source_mut().reset(dur, interval) } + + /// Disarms the timer. + pub fn clear(&mut self) -> SysResult<()> { + self.io_source.as_source_mut().clear() + } } impl IntoAsync for Timer {} diff --git a/devices/src/virtio/block/asynchronous.rs b/devices/src/virtio/block/asynchronous.rs index fc133cddec..4c042e3ede 100644 --- a/devices/src/virtio/block/asynchronous.rs +++ b/devices/src/virtio/block/asynchronous.rs @@ -832,6 +832,14 @@ impl BlockAsync { .fsync() .await .map_err(ExecuteError::Flush)?; + + if *flush_timer_armed.borrow() { + flush_timer + .borrow_mut() + .clear() + .map_err(ExecuteError::TimerReset)?; + *flush_timer_armed.borrow_mut() = false; + } } VIRTIO_BLK_T_GET_ID => { if let Some(id) = disk_state.id {