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;
}
}
* 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 */
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);
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);
* 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
* 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);
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);
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);
}
* 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;
}
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;
}
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;
}
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)
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);
}
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));
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);
}
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);
}
{
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(<b->ltb_list);
lnet_free_text_buf(ltb);
}
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;
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)) {
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;
int len;
struct lnet_text_buf *tb;
struct lnet_text_buf *tb2;
- struct list_head *t;
char *sep;
char *bracket;
__u32 net;
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, ',');
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;
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';
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));
}
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));
}
}
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;
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);
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);
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);
} 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);
/* 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);
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;
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
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);
}
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;
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);
/*
}
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
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);
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,
} 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 +
{
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);
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);
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);
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);
}
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;
}
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;
}
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));
}
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;
}
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;
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);
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);
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) {
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;
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
*/
/* 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);
}
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);
}