staging: lustre: introduce and use l_wait_event_abortable()
authorNeilBrown <neilb@suse.com>
Mon, 12 Feb 2018 21:22:36 +0000 (08:22 +1100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 16 Feb 2018 14:19:10 +0000 (15:19 +0100)
lustre sometimes wants to wait for an event, but abort if
one of a specific list of signals arrives.  This is a little
bit like wait_event_killable(), except that the signals are
identified a different way.

So introduce l_wait_event_abortable() which provides this
functionality.
Having separate functions for separate needs is more in line
with the pattern set by include/linux/wait.h, than having a
single function which tries to include all possible needs.

Also introduce l_wait_event_abortable_exclusive().

Note that l_wait_event() return -EINTR on a signal, while
Linux wait_event functions return -ERESTARTSYS.
l_wait_event_{abortable_,}exclusive follow the Linux pattern.

Reviewed-by: James Simmons <jsimmons@infradead.org>
Signed-off-by: NeilBrown <neilb@suse.com>
Reviewed-by: Patrick Farrell <paf@cray.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/lustre/lustre/include/lustre_lib.h
drivers/staging/lustre/lustre/ldlm/ldlm_resource.c
drivers/staging/lustre/lustre/llite/llite_lib.c
drivers/staging/lustre/lustre/obdclass/genops.c
drivers/staging/lustre/lustre/obdclass/llog_obd.c
drivers/staging/lustre/lustre/osc/osc_page.c
drivers/staging/lustre/lustre/osc/osc_request.c

index 7d950c53e962f1d15524e892c228e8fe14c0fb34..b2a64d0e682c41ae43417f43d0c07316c15fee72 100644 (file)
@@ -336,4 +336,28 @@ do {                                                                          \
 /** @} lib */
 
 
+
+/* l_wait_event_abortable() is a bit like wait_event_killable()
+ * except there is a fixed set of signals which will abort:
+ * LUSTRE_FATAL_SIGS
+ */
+#define l_wait_event_abortable(wq, condition)                          \
+({                                                                     \
+       sigset_t __blocked;                                             \
+       int __ret = 0;                                                  \
+       __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS);               \
+       __ret = wait_event_interruptible(wq, condition);                \
+       cfs_restore_sigs(__blocked);                                    \
+       __ret;                                                          \
+})
+
+#define l_wait_event_abortable_exclusive(wq, condition)                        \
+({                                                                     \
+       sigset_t __blocked;                                             \
+       int __ret = 0;                                                  \
+       __blocked = cfs_block_sigsinv(LUSTRE_FATAL_SIGS);               \
+       __ret = wait_event_interruptible_exclusive(wq, condition);      \
+       cfs_restore_sigs(__blocked);                                    \
+       __ret;                                                          \
+})
 #endif /* _LUSTRE_LIB_H */
index 2e66825c8f4ba98266f07976fe9e7fe156f9623e..4c44603ab6f94a4d52bf9969e030614c89dbf2f6 100644 (file)
@@ -879,7 +879,6 @@ static int __ldlm_namespace_free(struct ldlm_namespace *ns, int force)
        ldlm_namespace_cleanup(ns, force ? LDLM_FL_LOCAL_ONLY : 0);
 
        if (atomic_read(&ns->ns_bref) > 0) {
-               struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
                int rc;
 
                CDEBUG(D_DLMTRACE,
@@ -887,11 +886,12 @@ static int __ldlm_namespace_free(struct ldlm_namespace *ns, int force)
                       ldlm_ns_name(ns), atomic_read(&ns->ns_bref));
 force_wait:
                if (force)
-                       lwi = LWI_TIMEOUT(msecs_to_jiffies(obd_timeout *
-                                         MSEC_PER_SEC) / 4, NULL, NULL);
-
-               rc = l_wait_event(ns->ns_waitq,
-                                 atomic_read(&ns->ns_bref) == 0, &lwi);
+                       rc = wait_event_idle_timeout(ns->ns_waitq,
+                                                    atomic_read(&ns->ns_bref) == 0,
+                                                    obd_timeout * HZ / 4) ? 0 : -ETIMEDOUT;
+               else
+                       rc = l_wait_event_abortable(ns->ns_waitq,
+                                                   atomic_read(&ns->ns_bref) == 0);
 
                /* Forced cleanups should be able to reclaim all references,
                 * so it's safe to wait forever... we can't leak locks...
index c820b201af7141f9f79bedb997d6afc52a5373d9..ccb614bd7f53350a4f53a819e75d30cc53a6254b 100644 (file)
@@ -986,16 +986,12 @@ void ll_put_super(struct super_block *sb)
        }
 
        /* Wait for unstable pages to be committed to stable storage */
-       if (!force) {
-               struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
-
-               rc = l_wait_event(sbi->ll_cache->ccc_unstable_waitq,
-                                 !atomic_long_read(&sbi->ll_cache->ccc_unstable_nr),
-                                 &lwi);
-       }
+       if (!force)
+               rc = l_wait_event_abortable(sbi->ll_cache->ccc_unstable_waitq,
+                                           !atomic_long_read(&sbi->ll_cache->ccc_unstable_nr));
 
        ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
-       if (!force && rc != -EINTR)
+       if (!force && rc != -ERESTARTSYS)
                LASSERTF(!ccc_count, "count: %li\n", ccc_count);
 
        /* We need to set force before the lov_disconnect in
index 3ff25b8d3b4802569a7eb3fa0647967c2c5a00f0..8f776a4058a98f369df0a03006b6ec21adf2884f 100644 (file)
@@ -1332,7 +1332,6 @@ static bool obd_request_slot_avail(struct client_obd *cli,
 int obd_get_request_slot(struct client_obd *cli)
 {
        struct obd_request_slot_waiter orsw;
-       struct l_wait_info lwi;
        int rc;
 
        spin_lock(&cli->cl_loi_list_lock);
@@ -1347,11 +1346,9 @@ int obd_get_request_slot(struct client_obd *cli)
        orsw.orsw_signaled = false;
        spin_unlock(&cli->cl_loi_list_lock);
 
-       lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
-       rc = l_wait_event(orsw.orsw_waitq,
-                         obd_request_slot_avail(cli, &orsw) ||
-                         orsw.orsw_signaled,
-                         &lwi);
+       rc = l_wait_event_abortable(orsw.orsw_waitq,
+                                   obd_request_slot_avail(cli, &orsw) ||
+                                   orsw.orsw_signaled);
 
        /*
         * Here, we must take the lock to avoid the on-stack 'orsw' to be
index 28bbaa2136ac14ced292572bab25f44535691b91..26aea114a29bdd41c192463189f58dc755f84e14 100644 (file)
@@ -104,7 +104,6 @@ EXPORT_SYMBOL(__llog_ctxt_put);
 
 int llog_cleanup(const struct lu_env *env, struct llog_ctxt *ctxt)
 {
-       struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
        struct obd_llog_group *olg;
        int rc, idx;
 
@@ -129,8 +128,8 @@ int llog_cleanup(const struct lu_env *env, struct llog_ctxt *ctxt)
                CERROR("Error %d while cleaning up ctxt %p\n",
                       rc, ctxt);
 
-       l_wait_event(olg->olg_waitq,
-                    llog_group_ctxt_null(olg, idx), &lwi);
+       l_wait_event_abortable(olg->olg_waitq,
+                            llog_group_ctxt_null(olg, idx));
 
        return rc;
 }
index 20094b6309f936d5e9e410ff832266514792e763..6fdd521feb21f7bf6eef00113407d025d6fa0ebc 100644 (file)
@@ -759,7 +759,6 @@ out:
 static int osc_lru_alloc(const struct lu_env *env, struct client_obd *cli,
                         struct osc_page *opg)
 {
-       struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
        struct osc_io *oio = osc_env_io(env);
        int rc = 0;
 
@@ -782,9 +781,8 @@ static int osc_lru_alloc(const struct lu_env *env, struct client_obd *cli,
 
                cond_resched();
 
-               rc = l_wait_event(osc_lru_waitq,
-                                 atomic_long_read(cli->cl_lru_left) > 0,
-                                 &lwi);
+               rc = l_wait_event_abortable(osc_lru_waitq,
+                                           atomic_long_read(cli->cl_lru_left) > 0);
 
                if (rc < 0)
                        break;
index 45b1ebf33363427aa31904c3707c7780f26b8519..074b5ce6284cc332c41130c0a4c95ca7658c8736 100644 (file)
@@ -552,14 +552,12 @@ static int osc_destroy(const struct lu_env *env, struct obd_export *exp,
 
        req->rq_interpret_reply = osc_destroy_interpret;
        if (!osc_can_send_destroy(cli)) {
-               struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
-
                /*
                 * Wait until the number of on-going destroy RPCs drops
                 * under max_rpc_in_flight
                 */
-               l_wait_event_exclusive(cli->cl_destroy_waitq,
-                                      osc_can_send_destroy(cli), &lwi);
+               l_wait_event_abortable_exclusive(cli->cl_destroy_waitq,
+                                              osc_can_send_destroy(cli));
        }
 
        /* Do not wait for response */