Whamcloud - gitweb
LU-10467 obdclass: convert waiting in cl_sync_io_wait(). 02/36102/11
authorMr NeilBrown <neilb@suse.com>
Sat, 18 Jan 2020 13:55:58 +0000 (08:55 -0500)
committerOleg Drokin <green@whamcloud.com>
Tue, 28 Jan 2020 06:03:12 +0000 (06:03 +0000)
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 <neilb@suse.com>
Change-Id: I3c507a7fe01bfdf2ed5e9e71ea8215e6cfd0b54e
Reviewed-on: https://review.whamcloud.com/36102
Reviewed-by: Bobi Jam <bobijam@hotmail.com>
Reviewed-by: Wang Shilong <wshilong@ddn.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre/obdclass/cl_io.c

index 910d474..824aa6e 100644 (file)
@@ -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)
 {
 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);
 
        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));
                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;
                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);
        /* 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);