From d6ce546eb7e250237141d3a11380f9d5389c50eb Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Sat, 18 Jan 2020 08:55:58 -0500 Subject: [PATCH] LU-10467 obdclass: convert waiting in cl_sync_io_wait(). The l_wait_event() call in cl_sync_io_wait() will wait indefinitely if timeout is zero, or for a limited time if timeout is positive. This doesn't have an exact analogue in wait_event* macros, so we need to revise the code more broadly. This function will *always* wait until ->csi_sync_nr reaches zero. The effect of the timeout is: 1/ to report an error if the count doesn't reach zero in the given time 2/ to return -ETIMEDOUt instead of csi_sync_rc if the timeout was exceeded. So we rearrange the code to make that more obvious. A small exrta change is that we now call wait_event_idle() again even if there was a timeout and the first wait succeeded. This will simply test csi_sync_nr again and not actually wait. We could protected it with 'rc != 0 || timeout == 0' but there seems no point. Signed-off-by: Mr NeilBrown Change-Id: I3c507a7fe01bfdf2ed5e9e71ea8215e6cfd0b54e Reviewed-on: https://review.whamcloud.com/36102 Reviewed-by: Bobi Jam Reviewed-by: Wang Shilong Reviewed-by: James Simmons Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lustre/obdclass/cl_io.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lustre/obdclass/cl_io.c b/lustre/obdclass/cl_io.c index 910d474..824aa6e 100644 --- a/lustre/obdclass/cl_io.c +++ b/lustre/obdclass/cl_io.c @@ -1143,25 +1143,25 @@ EXPORT_SYMBOL(cl_sync_io_init_notify); int cl_sync_io_wait(const struct lu_env *env, struct cl_sync_io *anchor, long timeout) { - struct l_wait_info lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(timeout), - NULL, NULL, NULL); - int rc; + int rc = 0; ENTRY; LASSERT(timeout >= 0); - rc = l_wait_event(anchor->csi_waitq, - atomic_read(&anchor->csi_sync_nr) == 0, - &lwi); - if (rc < 0) { + if (timeout > 0 && + wait_event_idle_timeout(anchor->csi_waitq, + atomic_read(&anchor->csi_sync_nr) == 0, + cfs_time_seconds(timeout)) == 0) { + rc = -ETIMEDOUT; CERROR("IO failed: %d, still wait for %d remaining entries\n", rc, atomic_read(&anchor->csi_sync_nr)); + } - wait_event_idle(anchor->csi_waitq, - atomic_read(&anchor->csi_sync_nr) == 0); - } else { + wait_event_idle(anchor->csi_waitq, + atomic_read(&anchor->csi_sync_nr) == 0); + if (!rc) rc = anchor->csi_sync_rc; - } + /* We take the lock to ensure that cl_sync_io_note() has finished */ spin_lock(&anchor->csi_waitq.lock); LASSERT(atomic_read(&anchor->csi_sync_nr) == 0); -- 1.8.3.1