Whamcloud - gitweb
LU-14733 o2iblnd: Move racy NULL assignment
[fs/lustre-release.git] / lnet / klnds / o2iblnd / o2iblnd.c
index 337b74e..f3028b4 100644 (file)
@@ -27,7 +27,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lnet/klnds/o2iblnd/o2iblnd.c
  *
@@ -526,7 +525,6 @@ kiblnd_get_conn_by_idx(struct lnet_ni *ni, int index)
 {
        struct kib_peer_ni *peer_ni;
        struct kib_conn *conn;
-       struct list_head *ctmp;
        int i;
        unsigned long flags;
 
@@ -538,11 +536,11 @@ kiblnd_get_conn_by_idx(struct lnet_ni *ni, int index)
                if (peer_ni->ibp_ni != ni)
                        continue;
 
-               list_for_each(ctmp, &peer_ni->ibp_conns) {
+               list_for_each_entry(conn, &peer_ni->ibp_conns,
+                                   ibc_list) {
                        if (index-- > 0)
                                continue;
 
-                       conn = list_entry(ctmp, struct kib_conn, ibc_list);
                        kiblnd_conn_addref(conn);
                        read_unlock_irqrestore(&kiblnd_data.kib_global_lock,
                                               flags);
@@ -1630,16 +1628,16 @@ out_fpo:
 static void
 kiblnd_fail_fmr_poolset(struct kib_fmr_poolset *fps, struct list_head *zombies)
 {
+       struct kib_fmr_pool *fpo;
+
        if (fps->fps_net == NULL) /* intialized? */
                return;
 
        spin_lock(&fps->fps_lock);
 
-       while (!list_empty(&fps->fps_pool_list)) {
-               struct kib_fmr_pool *fpo = list_entry(fps->fps_pool_list.next,
-                                                     struct kib_fmr_pool,
-                                                     fpo_list);
-
+       while ((fpo = list_first_entry_or_null(&fps->fps_pool_list,
+                                              struct kib_fmr_pool,
+                                              fpo_list)) != NULL) {
                fpo->fpo_failed = 1;
                if (fpo->fpo_map_count == 0)
                        list_move(&fpo->fpo_list, zombies);
@@ -1753,10 +1751,10 @@ kiblnd_fmr_pool_unmap(struct kib_fmr *fmr, int status)
 
                if (frd) {
                        frd->frd_valid = false;
+                       fmr->fmr_frd = NULL;
                        spin_lock(&fps->fps_lock);
                        list_add_tail(&frd->frd_list, &fpo->fast_reg.fpo_pool_list);
                        spin_unlock(&fps->fps_lock);
-                       fmr->fmr_frd = NULL;
                }
        }
        fmr->fmr_pool = NULL;
@@ -2003,8 +2001,9 @@ kiblnd_destroy_pool_list(struct list_head *head)
 {
        struct kib_pool *pool;
 
-       while (!list_empty(head)) {
-               pool = list_entry(head->next, struct kib_pool, po_list);
+       while ((pool = list_first_entry_or_null(head,
+                                               struct kib_pool,
+                                               po_list)) != NULL) {
                list_del(&pool->po_list);
 
                LASSERT(pool->po_owner != NULL);
@@ -2015,14 +2014,15 @@ kiblnd_destroy_pool_list(struct list_head *head)
 static void
 kiblnd_fail_poolset(struct kib_poolset *ps, struct list_head *zombies)
 {
+       struct kib_pool *po;
+
        if (ps->ps_net == NULL) /* intialized? */
                return;
 
        spin_lock(&ps->ps_lock);
-       while (!list_empty(&ps->ps_pool_list)) {
-               struct kib_pool *po = list_entry(ps->ps_pool_list.next,
-                                                struct kib_pool, po_list);
-
+       while ((po = list_first_entry_or_null(&ps->ps_pool_list,
+                                             struct kib_pool,
+                                             po_list)) != NULL) {
                po->po_failed = 1;
                if (po->po_allocated == 0)
                        list_move(&po->po_list, zombies);
@@ -2956,8 +2956,8 @@ kiblnd_base_shutdown(void)
                cfs_percpt_for_each(sched, i, kiblnd_data.kib_scheds)
                        wake_up_all(&sched->ibs_waitq);
 
-               wake_up_all(&kiblnd_data.kib_connd_waitq);
-               wake_up_all(&kiblnd_data.kib_failover_waitq);
+               wake_up(&kiblnd_data.kib_connd_waitq);
+               wake_up(&kiblnd_data.kib_failover_waitq);
 
                wait_var_event_warning(&kiblnd_data.kib_nthreads,
                                       !atomic_read(&kiblnd_data.kib_nthreads),