Whamcloud - gitweb
LU-6142 lnet: use list_first_entry() in lnet/lnet subdirectory. 88/47488/3
authorMr NeilBrown <neilb@suse.de>
Tue, 31 May 2022 00:43:12 +0000 (20:43 -0400)
committerOleg Drokin <green@whamcloud.com>
Mon, 11 Jul 2022 06:49:45 +0000 (06:49 +0000)
Convert
  list_entry(foo->next .....)
to
  list_first_entry(foo, ....)

in 'lnet/lnet'

In several cases the call is combined with
a list_empty() test and list_first_entry_or_null() is used

Test-Parameters: trivial testlist=sanity-lnet
Change-Id: I45e1bdfe41854c88af98ebf24797f72a68b11dc3
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Reviewed-on: https://review.whamcloud.com/47488
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/lnet/api-ni.c
lnet/lnet/config.c
lnet/lnet/lib-move.c
lnet/lnet/lib-msg.c
lnet/lnet/lib-ptl.c
lnet/lnet/net_fault.c
lnet/lnet/nidstrings.c
lnet/lnet/peer.c
lnet/lnet/router.c

index 35e8ab3..d8922cc 100644 (file)
@@ -1459,8 +1459,8 @@ lnet_net2ni_locked(__u32 net_id, int cpt)
 
        list_for_each_entry(net, &the_lnet.ln_nets, net_list) {
                if (net->net_id == net_id) {
-                       ni = list_entry(net->net_ni_list.next, struct lnet_ni,
-                                       ni_netlist);
+                       ni = list_first_entry(&net->net_ni_list, struct lnet_ni,
+                                             ni_netlist);
                        return ni;
                }
        }
@@ -2332,12 +2332,12 @@ lnet_clear_zombies_nis_locked(struct lnet_net *net)
         * list and shut them down in guaranteed thread context
         */
        i = 2;
-       while (!list_empty(zombie_list)) {
-               int     *ref;
-               int     j;
+       while ((ni = list_first_entry_or_null(zombie_list,
+                                             struct lnet_ni,
+                                             ni_netlist)) != NULL) {
+               int *ref;
+               int j;
 
-               ni = list_entry(zombie_list->next,
-                               struct lnet_ni, ni_netlist);
                list_del_init(&ni->ni_netlist);
                /* the ni should be in deleting state. If it's not it's
                 * a bug */
@@ -2430,9 +2430,9 @@ lnet_shutdown_lndnet(struct lnet_net *net)
 
        list_del_init(&net->net_list);
 
-       while (!list_empty(&net->net_ni_list)) {
-               ni = list_entry(net->net_ni_list.next,
-                               struct lnet_ni, ni_netlist);
+       while ((ni = list_first_entry_or_null(&net->net_ni_list,
+                                             struct lnet_ni,
+                                             ni_netlist)) != NULL) {
                lnet_net_unlock(LNET_LOCK_EX);
                lnet_shutdown_lndni(ni);
                lnet_net_lock(LNET_LOCK_EX);
@@ -2478,11 +2478,10 @@ lnet_shutdown_lndnets(void)
        lnet_net_unlock(LNET_LOCK_EX);
 
        /* iterate through the net zombie list and delete each net */
-       while (!list_empty(&the_lnet.ln_net_zombie)) {
-               net = list_entry(the_lnet.ln_net_zombie.next,
-                                struct lnet_net, net_list);
+       while ((net = list_first_entry_or_null(&the_lnet.ln_net_zombie,
+                                              struct lnet_net,
+                                              net_list)) != NULL)
                lnet_shutdown_lndnet(net);
-       }
 
        spin_lock(&the_lnet.ln_msg_resend_lock);
        list_splice(&the_lnet.ln_msg_resend, &resend);
@@ -2660,9 +2659,9 @@ lnet_startup_lndnet(struct lnet_net *net, struct lnet_lnd_tunables *tun)
         * After than we want to delete the network being added,
         * to avoid a memory leak.
         */
-       while (!list_empty(&net->net_ni_added)) {
-               ni = list_entry(net->net_ni_added.next, struct lnet_ni,
-                               ni_netlist);
+       while ((ni = list_first_entry_or_null(&net->net_ni_added,
+                                             struct lnet_ni,
+                                             ni_netlist)) != NULL) {
                list_del_init(&ni->ni_netlist);
 
                /* make sure that the the NI we're about to start
@@ -2726,12 +2725,10 @@ failed1:
         * shutdown the new NIs that are being started up
         * free the NET being started
         */
-       while (!list_empty(&local_ni_list)) {
-               ni = list_entry(local_ni_list.next, struct lnet_ni,
-                               ni_netlist);
-
+       while ((ni = list_first_entry_or_null(&local_ni_list,
+                                             struct lnet_ni,
+                                             ni_netlist)) != NULL)
                lnet_shutdown_lndni(ni);
-       }
 
 failed0:
        lnet_net_free(net);
@@ -2755,8 +2752,9 @@ lnet_startup_lndnets(struct list_head *netlist)
        the_lnet.ln_state = LNET_STATE_RUNNING;
        lnet_net_unlock(LNET_LOCK_EX);
 
-       while (!list_empty(netlist)) {
-               net = list_entry(netlist->next, struct lnet_net, net_list);
+       while ((net = list_first_entry_or_null(netlist,
+                                              struct lnet_net,
+                                              net_list)) != NULL) {
                list_del_init(&net->net_list);
 
                rc = lnet_startup_lndnet(net, NULL);
@@ -3081,10 +3079,9 @@ err_empty_list:
        lnet_unprepare();
        LASSERT(rc < 0);
        mutex_unlock(&the_lnet.ln_api_mutex);
-       while (!list_empty(&net_head)) {
-               struct lnet_net *net;
-
-               net = list_entry(net_head.next, struct lnet_net, net_list);
+       while ((net = list_first_entry_or_null(&net_head,
+                                              struct lnet_net,
+                                              net_list)) != NULL) {
                list_del_init(&net->net_list);
                lnet_net_free(net);
        }
@@ -3328,14 +3325,15 @@ lnet_get_next_ni_locked(struct lnet_net *mynet, struct lnet_ni *prev)
         * a message being sent. This function accessed the net without
         * checking if the list is empty
         */
-       if (prev == NULL) {
-               if (net == NULL)
-                       net = list_entry(the_lnet.ln_nets.next, struct lnet_net,
-                                       net_list);
+       if (!prev) {
+               if (!net)
+                       net = list_first_entry(&the_lnet.ln_nets,
+                                              struct lnet_net,
+                                              net_list);
                if (list_empty(&net->net_ni_list))
                        return NULL;
-               ni = list_entry(net->net_ni_list.next, struct lnet_ni,
-                               ni_netlist);
+               ni = list_first_entry(&net->net_ni_list, struct lnet_ni,
+                                     ni_netlist);
 
                return ni;
        }
@@ -3353,13 +3351,13 @@ lnet_get_next_ni_locked(struct lnet_net *mynet, struct lnet_ni *prev)
                        return NULL;
 
                /* get the next net */
-               net = list_entry(prev->ni_net->net_list.next, struct lnet_net,
-                                net_list);
+               net = list_first_entry(&prev->ni_net->net_list, struct lnet_net,
+                                      net_list);
                if (list_empty(&net->net_ni_list))
                        return NULL;
                /* get the ni on it */
-               ni = list_entry(net->net_ni_list.next, struct lnet_ni,
-                               ni_netlist);
+               ni = list_first_entry(&net->net_ni_list, struct lnet_ni,
+                                     ni_netlist);
 
                return ni;
        }
@@ -3368,7 +3366,7 @@ lnet_get_next_ni_locked(struct lnet_net *mynet, struct lnet_ni *prev)
                return NULL;
 
        /* there are more nis left */
-       ni = list_entry(prev->ni_netlist.next, struct lnet_ni, ni_netlist);
+       ni = list_first_entry(&prev->ni_netlist, struct lnet_ni, ni_netlist);
 
        return ni;
 }
@@ -3589,8 +3587,10 @@ static int lnet_handle_legacy_ip2nets(char *ip2nets,
                rc = -ESHUTDOWN;
                goto out;
        }
-       while (!list_empty(&net_head)) {
-               net = list_entry(net_head.next, struct lnet_net, net_list);
+
+       while ((net = list_first_entry_or_null(&net_head,
+                                              struct lnet_net,
+                                              net_list)) != NULL) {
                list_del_init(&net->net_list);
                rc = lnet_add_net_common(net, tun);
                if (rc < 0)
@@ -3600,8 +3600,9 @@ static int lnet_handle_legacy_ip2nets(char *ip2nets,
 out:
        mutex_unlock(&the_lnet.ln_api_mutex);
 
-       while (!list_empty(&net_head)) {
-               net = list_entry(net_head.next, struct lnet_net, net_list);
+       while ((net = list_first_entry_or_null(&net_head,
+                                              struct lnet_net,
+                                              net_list)) != NULL) {
                list_del_init(&net->net_list);
                lnet_net_free(net);
        }
@@ -3785,7 +3786,7 @@ lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
                goto out_unlock_clean;
        }
 
-       net = list_entry(net_head.next, struct lnet_net, net_list);
+       net = list_first_entry(&net_head, struct lnet_net, net_list);
        list_del_init(&net->net_list);
 
        LASSERT(lnet_net_unique(net->net_id, &the_lnet.ln_nets, NULL));
@@ -3808,9 +3809,10 @@ lnet_dyn_add_net(struct lnet_ioctl_config_data *conf)
 
 out_unlock_clean:
        mutex_unlock(&the_lnet.ln_api_mutex);
-       while (!list_empty(&net_head)) {
-               /* net_head list is empty in success case */
-               net = list_entry(net_head.next, struct lnet_net, net_list);
+       /* net_head list is empty in success case */
+       while ((net = list_first_entry_or_null(&net_head,
+                                              struct lnet_net,
+                                              net_list)) != NULL) {
                list_del_init(&net->net_list);
                lnet_net_free(net);
        }
index 09fe96d..1718b09 100644 (file)
@@ -804,9 +804,9 @@ lnet_parse_networks(struct list_head *netlist, const char *networks)
        lnet_syntax("networks", networks, (int)(str - tokens), strlen(str));
  failed:
        /* free the net list and all the nis on each net */
-       while (!list_empty(netlist)) {
-               net = list_entry(netlist->next, struct lnet_net, net_list);
-
+       while ((net = list_first_entry_or_null(netlist,
+                                              struct lnet_net,
+                                              net_list)) != NULL) {
                list_del_init(&net->net_list);
                lnet_net_free(net);
        }
@@ -861,9 +861,8 @@ lnet_free_text_bufs(struct list_head *tbs)
 {
        struct lnet_text_buf  *ltb;
 
-       while (!list_empty(tbs)) {
-               ltb = list_entry(tbs->next, struct lnet_text_buf, ltb_list);
-
+       while ((ltb = list_first_entry_or_null(tbs, struct lnet_text_buf,
+                                              ltb_list)) != NULL) {
                list_del(&ltb->ltb_list);
                lnet_free_text_buf(ltb);
        }
@@ -1083,7 +1082,8 @@ lnet_parse_route(char *str, int *im_a_router)
        struct list_head *tmp2;
        __u32 net;
        struct lnet_nid nid;
-       struct lnet_text_buf  *ltb;
+       struct lnet_text_buf *ltb = NULL;
+       struct lnet_text_buf *ltb1, *ltb2;
        int rc;
        char *sep;
        char *token = str;
@@ -1176,13 +1176,11 @@ lnet_parse_route(char *str, int *im_a_router)
        LASSERT(!list_empty(&nets));
        LASSERT(!list_empty(&gateways));
 
-       list_for_each(tmp1, &nets) {
-               ltb = list_entry(tmp1, struct lnet_text_buf, ltb_list);
-               net = libcfs_str2net(ltb->ltb_text);
+       list_for_each_entry(ltb1, &nets, ltb_list) {
+               net = libcfs_str2net(ltb1->ltb_text);
                LASSERT(net != LNET_NET_ANY);
 
-               list_for_each(tmp2, &gateways) {
-                       ltb = list_entry(tmp2, struct lnet_text_buf, ltb_list);
+               list_for_each_entry(ltb2, &gateways, ltb_list) {
                        LASSERT(libcfs_strnid(&nid, ltb->ltb_text) == 0);
 
                        if (lnet_islocalnid(&nid)) {
@@ -1215,11 +1213,10 @@ out:
 static int
 lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
 {
-       struct lnet_text_buf   *ltb;
-
-       while (!list_empty(tbs)) {
-               ltb = list_entry(tbs->next, struct lnet_text_buf, ltb_list);
+       struct lnet_text_buf *ltb;
 
+       while ((ltb = list_first_entry_or_null(tbs, struct lnet_text_buf,
+                                              ltb_list)) != NULL) {
                if (lnet_parse_route(ltb->ltb_text, im_a_router) < 0) {
                        lnet_free_text_bufs(tbs);
                        return -EINVAL;
@@ -1352,7 +1349,6 @@ lnet_splitnets(char *source, struct list_head *nets)
        int               len;
        struct lnet_text_buf  *tb;
        struct lnet_text_buf  *tb2;
-       struct list_head *t;
        char             *sep;
        char             *bracket;
        __u32             net;
@@ -1360,7 +1356,7 @@ lnet_splitnets(char *source, struct list_head *nets)
        LASSERT(!list_empty(nets));
        LASSERT(nets->next == nets->prev);      /* single entry */
 
-       tb = list_entry(nets->next, struct lnet_text_buf, ltb_list);
+       tb = list_first_entry(nets, struct lnet_text_buf, ltb_list);
 
        for (;;) {
                sep = strchr(tb->ltb_text, ',');
@@ -1395,9 +1391,7 @@ lnet_splitnets(char *source, struct list_head *nets)
                        return -EINVAL;
                }
 
-               list_for_each(t, nets) {
-                       tb2 = list_entry(t, struct lnet_text_buf, ltb_list);
-
+               list_for_each_entry(tb2, nets, ltb_list) {
                        if (tb2 == tb)
                                continue;
 
@@ -1454,10 +1448,9 @@ lnet_match_networks(const char **networksp, const char *ip2nets,
        len = 0;
        rc = 0;
 
-       while (!list_empty(&raw_entries)) {
-               tb = list_entry(raw_entries.next, struct lnet_text_buf,
-                               ltb_list);
-
+       while ((tb = list_first_entry_or_null(&raw_entries,
+                                             struct lnet_text_buf,
+                                             ltb_list)) != NULL) {
                strncpy(source, tb->ltb_text, sizeof(source));
                source[sizeof(source) - 1] = '\0';
 
index e262623..81261c9 100644 (file)
@@ -229,9 +229,9 @@ lnet_fail_nid(lnet_nid_t nid4, unsigned int threshold)
 
        lnet_net_unlock(0);
 
-       while (!list_empty(&cull)) {
-               tp = list_entry(cull.next, struct lnet_test_peer, tp_list);
-
+       while ((tp = list_first_entry_or_null(&cull,
+                                             struct lnet_test_peer,
+                                             tp_list)) != NULL) {
                list_del(&tp->tp_list);
                LIBCFS_FREE(tp, sizeof(*tp));
        }
@@ -282,10 +282,10 @@ fail_peer(struct lnet_nid *nid, int outgoing)
 
        lnet_net_unlock(0);
 
-       while (!list_empty(&cull)) {
-               tp = list_entry(cull.next, struct lnet_test_peer, tp_list);
+       while ((tp = list_first_entry_or_null(&cull,
+                                             struct lnet_test_peer,
+                                             tp_list)) != NULL) {
                list_del(&tp->tp_list);
-
                LIBCFS_FREE(tp, sizeof(*tp));
        }
 
@@ -1034,7 +1034,7 @@ lnet_post_routed_recv_locked(struct lnet_msg *msg, int do_recv)
        }
 
        LASSERT(!list_empty(&rbp->rbp_bufs));
-       rb = list_entry(rbp->rbp_bufs.next, struct lnet_rtrbuf, rb_list);
+       rb = list_first_entry(&rbp->rbp_bufs, struct lnet_rtrbuf, rb_list);
        list_del(&rb->rb_list);
 
        msg->msg_niov = rbp->rbp_npages;
@@ -1074,8 +1074,8 @@ lnet_return_tx_credits_locked(struct lnet_msg *msg)
                tq->tq_credits++;
                atomic_inc(&ni->ni_tx_credits);
                if (tq->tq_credits <= 0) {
-                       msg2 = list_entry(tq->tq_delayed.next,
-                                         struct lnet_msg, msg_list);
+                       msg2 = list_first_entry(&tq->tq_delayed,
+                                               struct lnet_msg, msg_list);
                        list_del(&msg2->msg_list);
 
                        LASSERT(msg2->msg_txni == ni);
@@ -1102,8 +1102,8 @@ lnet_return_tx_credits_locked(struct lnet_msg *msg)
                if (txpeer->lpni_txcredits <= 0) {
                        int msg2_cpt;
 
-                       msg2 = list_entry(txpeer->lpni_txq.next,
-                                             struct lnet_msg, msg_list);
+                       msg2 = list_first_entry(&txpeer->lpni_txq,
+                                               struct lnet_msg, msg_list);
                        list_del(&msg2->msg_list);
                        spin_unlock(&txpeer->lpni_lock);
 
@@ -1155,8 +1155,8 @@ lnet_schedule_blocked_locked(struct lnet_rtrbufpool *rbp)
 
        if (list_empty(&rbp->rbp_msgs))
                return;
-       msg = list_entry(rbp->rbp_msgs.next,
-                        struct lnet_msg, msg_list);
+       msg = list_first_entry(&rbp->rbp_msgs,
+                              struct lnet_msg, msg_list);
        list_del(&msg->msg_list);
 
        (void)lnet_post_routed_recv_locked(msg, 1);
@@ -1260,8 +1260,8 @@ routing_off:
                } else if (!list_empty(&lp->lp_rtrq)) {
                        int msg2_cpt;
 
-                       msg2 = list_entry(lp->lp_rtrq.next,
-                                         struct lnet_msg, msg_list);
+                       msg2 = list_first_entry(&lp->lp_rtrq,
+                                               struct lnet_msg, msg_list);
                        list_del(&msg2->msg_list);
                        msg2_cpt = msg2->msg_rx_cpt;
                        spin_unlock(&lp->lp_lock);
@@ -3637,9 +3637,9 @@ lnet_clean_local_ni_recoveryq(void)
        /* This is only called when the monitor thread has stopped */
        lnet_net_lock(0);
 
-       while (!list_empty(&the_lnet.ln_mt_localNIRecovq)) {
-               ni = list_entry(the_lnet.ln_mt_localNIRecovq.next,
-                               struct lnet_ni, ni_recovery);
+       while ((ni = list_first_entry_or_null(&the_lnet.ln_mt_localNIRecovq,
+                                             struct lnet_ni,
+                                             ni_recovery)) != NULL) {
                list_del_init(&ni->ni_recovery);
                lnet_ni_lock(ni);
                lnet_unlink_ni_recovery_mdh_locked(ni, 0, true);
@@ -4845,11 +4845,12 @@ EXPORT_SYMBOL(lnet_parse);
 void
 lnet_drop_delayed_msg_list(struct list_head *head, char *reason)
 {
-       while (!list_empty(head)) {
+       struct lnet_msg *msg;
+
+       while ((msg = list_first_entry_or_null(head, struct lnet_msg,
+                                              msg_list)) != NULL) {
                struct lnet_processid id = {};
-               struct lnet_msg *msg;
 
-               msg = list_entry(head->next, struct lnet_msg, msg_list);
                list_del(&msg->msg_list);
 
                id.nid = msg->msg_hdr.src_nid;
@@ -4889,11 +4890,12 @@ lnet_drop_delayed_msg_list(struct list_head *head, char *reason)
 void
 lnet_recv_delayed_msg_list(struct list_head *head)
 {
-       while (!list_empty(head)) {
-               struct lnet_msg *msg;
+       struct lnet_msg *msg;
+
+       while ((msg = list_first_entry_or_null(head, struct lnet_msg,
+                                              msg_list)) != NULL) {
                struct lnet_processid id;
 
-               msg = list_entry(head->next, struct lnet_msg, msg_list);
                list_del(&msg->msg_list);
 
                /* md won't disappear under me, since each msg
@@ -5353,7 +5355,6 @@ EXPORT_SYMBOL(LNetGet);
 int
 LNetDist(struct lnet_nid *dstnid, struct lnet_nid *srcnid, __u32 *orderp)
 {
-       struct list_head *e;
        struct lnet_ni *ni = NULL;
        struct lnet_remotenet *rnet;
        __u32 dstnet = LNET_NID_NET(dstnid);
@@ -5425,9 +5426,7 @@ LNetDist(struct lnet_nid *dstnid, struct lnet_nid *srcnid, __u32 *orderp)
        }
 
        rn_list = lnet_net2rnethash(dstnet);
-       list_for_each(e, rn_list) {
-               rnet = list_entry(e, struct lnet_remotenet, lrn_list);
-
+       list_for_each_entry(rnet, rn_list, lrn_list) {
                if (rnet->lrn_net == dstnet) {
                        struct lnet_route *route;
                        struct lnet_route *shortest = NULL;
index 39a2ba2..69a85be 100644 (file)
@@ -739,9 +739,9 @@ lnet_attempt_msg_resend(struct lnet_msg *msg)
                return 0;
        }
 
-       while (!list_empty(&container->msc_resending)) {
-               msg = list_entry(container->msc_resending.next,
-                                       struct lnet_msg, msg_list);
+       while ((msg = list_first_entry_or_null(&container->msc_resending,
+                                              struct lnet_msg,
+                                              msg_list)) != NULL) {
                list_del(&msg->msg_list);
 
                /*
@@ -1199,10 +1199,9 @@ again:
        }
 
        rc = 0;
-       while (!list_empty(&container->msc_finalizing)) {
-               msg = list_entry(container->msc_finalizing.next,
-                                struct lnet_msg, msg_list);
-
+       while ((msg = list_first_entry_or_null(&container->msc_finalizing,
+                                              struct lnet_msg,
+                                              msg_list)) != NULL) {
                list_del_init(&msg->msg_list);
 
                /* NB drops and regains the lnet lock if it actually does
@@ -1229,16 +1228,15 @@ EXPORT_SYMBOL(lnet_finalize);
 void
 lnet_msg_container_cleanup(struct lnet_msg_container *container)
 {
-       int     count = 0;
+       struct lnet_msg *msg;
+       int count = 0;
 
        if (container->msc_init == 0)
                return;
 
-       while (!list_empty(&container->msc_active)) {
-               struct lnet_msg *msg;
-
-               msg  = list_entry(container->msc_active.next,
-                                 struct lnet_msg, msg_activelist);
+       while ((msg = list_first_entry_or_null(&container->msc_active,
+                                              struct lnet_msg,
+                                              msg_activelist)) != NULL) {
                LASSERT(msg->msg_onactivelist);
                msg->msg_onactivelist = 0;
                list_del_init(&msg->msg_activelist);
index cbe7a30..4196424 100644 (file)
@@ -765,9 +765,9 @@ lnet_ptl_cleanup(struct lnet_portal *ptl)
                mhash = mtable->mt_mhash;
                /* cleanup ME */
                for (j = 0; j < LNET_MT_HASH_SIZE + 1; j++) {
-                       while (!list_empty(&mhash[j])) {
-                               me = list_entry(mhash[j].next,
-                                               struct lnet_me, me_list);
+                       while ((me = list_first_entry_or_null(&mhash[j],
+                                                             struct lnet_me,
+                                                             me_list)) != NULL) {
                                CERROR("Active ME %p on exit\n", me);
                                list_del(&me->me_list);
                                CDEBUG(D_MALLOC,
index 113a908..98f9b31 100644 (file)
@@ -661,8 +661,8 @@ delayed_msg_check(struct lnet_delay_rule *rule, bool all,
        } else if (!list_empty(msg_list)) {
                /* dequeued some timedout messages, update timer for the
                 * next delayed message on rule */
-               msg = list_entry(rule->dl_msg_list.next,
-                                struct lnet_msg, msg_list);
+               msg = list_first_entry(&rule->dl_msg_list,
+                                      struct lnet_msg, msg_list);
                rule->dl_msg_send = msg->msg_delay_send;
                mod_timer(&rule->dl_timer,
                          jiffies +
@@ -676,13 +676,12 @@ delayed_msg_process(struct list_head *msg_list, bool drop)
 {
        struct lnet_msg *msg;
 
-       while (!list_empty(msg_list)) {
+       while ((msg = list_first_entry_or_null(msg_list, struct lnet_msg,
+                                              msg_list)) != NULL) {
                struct lnet_ni *ni;
                int             cpt;
                int             rc;
 
-               msg = list_entry(msg_list->next, struct lnet_msg, msg_list);
-
                if (msg->msg_sending) {
                        /* Delayed send */
                        list_del_init(&msg->msg_list);
@@ -754,8 +753,8 @@ lnet_delay_rule_check(void)
                        break;
                }
 
-               rule = list_entry(delay_dd.dd_sched_rules.next,
-                                 struct lnet_delay_rule, dl_sched_link);
+               rule = list_first_entry(&delay_dd.dd_sched_rules,
+                                       struct lnet_delay_rule, dl_sched_link);
                list_del_init(&rule->dl_sched_link);
                spin_unlock_bh(&delay_dd.dd_lock);
 
index d732684..2af9d8a 100644 (file)
@@ -277,11 +277,11 @@ failed:
 static void
 free_addrranges(struct list_head *list)
 {
-       while (!list_empty(list)) {
-               struct addrrange *ar;
-
-               ar = list_entry(list->next, struct addrrange, ar_link);
+       struct addrrange *ar;
 
+       while ((ar = list_first_entry_or_null(list,
+                                             struct addrrange,
+                                             ar_link)) != NULL) {
                cfs_expr_list_free_list(&ar->ar_numaddr_ranges);
                list_del(&ar->ar_link);
                CFS_FREE_PTR(ar);
@@ -702,7 +702,7 @@ libcfs_num_match(__u32 addr, struct list_head *numaddr)
        struct cfs_expr_list *el;
 
        LASSERT(!list_empty(numaddr));
-       el = list_entry(numaddr->next, struct cfs_expr_list, el_link);
+       el = list_first_entry(numaddr, struct cfs_expr_list, el_link);
 
        return cfs_expr_list_match(addr, el);
 }
index 07626f7..11c22f0 100644 (file)
@@ -801,12 +801,12 @@ lnet_get_next_peer_ni_locked(struct lnet_peer *peer,
                        if (list_empty(&peer->lp_peer_nets))
                                return NULL;
 
-                       net = list_entry(peer->lp_peer_nets.next,
-                                        struct lnet_peer_net,
-                                        lpn_peer_nets);
+                       net = list_first_entry(&peer->lp_peer_nets,
+                                              struct lnet_peer_net,
+                                              lpn_peer_nets);
                }
-               lpni = list_entry(net->lpn_peer_nis.next, struct lnet_peer_ni,
-                                 lpni_peer_nis);
+               lpni = list_first_entry(&net->lpn_peer_nis, struct lnet_peer_ni,
+                                       lpni_peer_nis);
 
                return lpni;
        }
@@ -830,19 +830,19 @@ lnet_get_next_peer_ni_locked(struct lnet_peer *peer,
                        return NULL;
 
                /* get the next net */
-               net = list_entry(prev->lpni_peer_net->lpn_peer_nets.next,
-                                struct lnet_peer_net,
-                                lpn_peer_nets);
+               net = list_first_entry(&prev->lpni_peer_net->lpn_peer_nets,
+                                      struct lnet_peer_net,
+                                      lpn_peer_nets);
                /* get the ni on it */
-               lpni = list_entry(net->lpn_peer_nis.next, struct lnet_peer_ni,
-                                 lpni_peer_nis);
+               lpni = list_first_entry(&net->lpn_peer_nis, struct lnet_peer_ni,
+                                       lpni_peer_nis);
 
                return lpni;
        }
 
        /* there are more nis left */
-       lpni = list_entry(prev->lpni_peer_nis.next,
-                         struct lnet_peer_ni, lpni_peer_nis);
+       lpni = list_first_entry(&prev->lpni_peer_nis,
+                               struct lnet_peer_ni, lpni_peer_nis);
 
        return lpni;
 }
index c40b031..d581fa2 100644 (file)
@@ -187,13 +187,13 @@ lnet_move_route(struct lnet_route *route, struct lnet_peer *lp,
 
        if (lp) {
                route = list_first_entry(l, struct lnet_route,
-                                       lr_list);
+                                        lr_list);
                route->lr_gateway = lp;
                lnet_add_route_to_rnet(rnet, route);
        } else {
                while (!list_empty(l) && !rt_list) {
                        route = list_first_entry(l, struct lnet_route,
-                                lr_list);
+                                                lr_list);
                        list_del(&route->lr_list);
                        LIBCFS_FREE(route, sizeof(*route));
                }
@@ -582,15 +582,12 @@ struct lnet_remotenet *
 lnet_find_rnet_locked(__u32 net)
 {
        struct lnet_remotenet *rnet;
-       struct list_head *tmp;
        struct list_head *rn_list;
 
        LASSERT(the_lnet.ln_state == LNET_STATE_RUNNING);
 
        rn_list = lnet_net2rnethash(net);
-       list_for_each(tmp, rn_list) {
-               rnet = list_entry(tmp, struct lnet_remotenet, lrn_list);
-
+       list_for_each_entry(rnet, rn_list, lrn_list) {
                if (rnet->lrn_net == net)
                        return rnet;
        }
@@ -979,8 +976,6 @@ lnet_get_route(int idx, __u32 *net, __u32 *hops, lnet_nid_t *gateway,
        struct lnet_remotenet *rnet;
        struct list_head *rn_list;
        struct lnet_route *route;
-       struct list_head *e1;
-       struct list_head *e2;
        int cpt;
        int i;
 
@@ -988,13 +983,8 @@ lnet_get_route(int idx, __u32 *net, __u32 *hops, lnet_nid_t *gateway,
 
        for (i = 0; i < LNET_REMOTE_NETS_HASH_SIZE; i++) {
                rn_list = &the_lnet.ln_remote_nets_hash[i];
-               list_for_each(e1, rn_list) {
-                       rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
-
-                       list_for_each(e2, &rnet->lrn_routes) {
-                               route = list_entry(e2, struct lnet_route,
-                                                  lr_list);
-
+               list_for_each_entry(rnet, rn_list, lrn_list) {
+                       list_for_each_entry(route, &rnet->lrn_routes, lr_list) {
                                if (idx-- == 0) {
                                        *net      = rnet->lrn_net;
                                        *gateway  = lnet_nid_to_nid4(&route->lr_nid);
@@ -1025,7 +1015,6 @@ static void
 lnet_wait_known_routerstate(void)
 {
        struct lnet_peer *rtr;
-       struct list_head *entry;
        int all_known;
 
        LASSERT(the_lnet.ln_mt_state == LNET_MT_STATE_RUNNING);
@@ -1034,10 +1023,7 @@ lnet_wait_known_routerstate(void)
                int cpt = lnet_net_lock_current();
 
                all_known = 1;
-               list_for_each(entry, &the_lnet.ln_routers) {
-                       rtr = list_entry(entry, struct lnet_peer,
-                                        lp_rtr_list);
-
+               list_for_each_entry(rtr, &the_lnet.ln_routers, lp_rtr_list) {
                        spin_lock(&rtr->lp_lock);
 
                        if ((rtr->lp_state & LNET_PEER_RTR_DISCOVERED) == 0) {
@@ -1159,7 +1145,6 @@ lnet_check_routers(void)
        struct lnet_peer_net *first_lpn;
        struct lnet_peer_net *lpn;
        struct lnet_peer_ni *lpni;
-       struct list_head *entry;
        struct lnet_peer *rtr;
        bool push = false;
        bool needs_ping;
@@ -1174,10 +1159,7 @@ lnet_check_routers(void)
 rescan:
        version = the_lnet.ln_routers_version;
 
-       list_for_each(entry, &the_lnet.ln_routers) {
-               rtr = list_entry(entry, struct lnet_peer,
-                                lp_rtr_list);
-
+       list_for_each_entry(rtr, &the_lnet.ln_routers, lp_rtr_list) {
                /* If we're currently discovering the peer then don't
                 * issue another discovery
                 */
@@ -1345,7 +1327,7 @@ lnet_rtrpool_free_bufs(struct lnet_rtrbufpool *rbp, int cpt)
 
        /* Free buffers on the free list. */
        while (!list_empty(&tmp)) {
-               rb = list_entry(tmp.next, struct lnet_rtrbuf, rb_list);
+               rb = list_first_entry(&tmp, struct lnet_rtrbuf, rb_list);
                list_del(&rb->rb_list);
                lnet_destroy_rtrbuf(rb, npages);
        }
@@ -1419,8 +1401,9 @@ lnet_rtrpool_adjust_bufs(struct lnet_rtrbufpool *rbp, int nbufs, int cpt)
        return 0;
 
 failed:
-       while (!list_empty(&rb_list)) {
-               rb = list_entry(rb_list.next, struct lnet_rtrbuf, rb_list);
+       while ((rb = list_first_entry_or_null(&rb_list,
+                                             struct lnet_rtrbuf,
+                                             rb_list)) != NULL) {
                list_del(&rb->rb_list);
                lnet_destroy_rtrbuf(rb, npages);
        }