Skip to contentSkip to conversation

lustre: convert list_for_each() to list_for_each_entry()

PATCH New NeilBrown 3 participants 17 messages Jul 30, 2018 – Aug 2, 2018 Staging

lore
Share & tools
lore

NeilBrown

author
#0 lore raw

cover lustre: convert list_for_each() to list_for_each_entry()

list_for_each_entry(foo) is generally preferred to
list_for_each(l,...)

     foo = list_entry(l,...)

as there is less noise in the code.
The first patch contains seveveral trivial conversions. The remaining patches are less obvious and are separate so they are easier to review.

NeilBrown

The following series implements...

---

NeilBrown (6):
lustre: convert list_for_each() to list_for_each_entry().
lustre: lnet/config: convert list_for_each to list_for_each_entry
lustre: convert list_for_each in ksocknal_create_routes
lustre: convert list_for_each in ksocknal_close_conn_locked()
lustre: convert list_for_each() in ksocknal_push_peer()
lustre: convert list_for_each() in ksocknal_debug_peerhash()

 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c    |   17 --
 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c |   20 +-
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |  166 +++++++-------------
 .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c |   20 +-
 drivers/staging/lustre/lnet/lnet/api-ni.c          |   29 +--
 drivers/staging/lustre/lnet/lnet/config.c          |   28 +--
 drivers/staging/lustre/lnet/lnet/lib-move.c        |    9 -
 drivers/staging/lustre/lnet/lnet/router.c          |   47 +-----
 drivers/staging/lustre/lnet/selftest/conrpc.c      |    7 -
 drivers/staging/lustre/lustre/obdclass/genops.c    |    4 
 .../staging/lustre/lustre/obdecho/echo_client.c    |    4 
 11 files changed, 99 insertions(+), 252 deletions(-)

--
Signature

author
#1 lore raw

PATCH 1/6 lustre: convert list_for_each() to list_for_each_entry().

Where we have
struct list_head *tmp;

  list_for_each(tmp,....) {
     foo = list_entry(tmp, ....);
     ...

}

convert to
list_for_each_entry(foo, .....) {
.....
}

This patch only changes instances which are straight forward, where neither the 'tmp' variable nor the 'foo' variable is not used outside the loop in any way that isn't trivially correct.

---
 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c    |   17 ++-----
 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c |   20 ++------
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |   51 +++++---------------
 .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c |   20 ++------
 drivers/staging/lustre/lnet/lnet/api-ni.c          |   29 ++---------
 drivers/staging/lustre/lnet/lnet/config.c          |   17 ++-----
 drivers/staging/lustre/lnet/lnet/lib-move.c        |    9 +---
 drivers/staging/lustre/lnet/lnet/router.c          |   47 ++++--------------
 drivers/staging/lustre/lnet/selftest/conrpc.c      |    7 +--
 drivers/staging/lustre/lustre/obdclass/genops.c    |    4 --
 .../staging/lustre/lustre/obdecho/echo_client.c    |    4 --
 11 files changed, 53 insertions(+), 172 deletions(-)
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +4 -13
index 830a5bf34c16..e15ad94151bd 100644
@@ -386,11 +386,9 @@ struct kib_peer *kiblnd_find_peer_locked(lnet_nid_t nid)
 	 * that this creates
 	 */
 	struct list_head *peer_list = kiblnd_nid2peerlist(nid);
-	struct list_head *tmp;
 	struct kib_peer *peer;
 
-	list_for_each(tmp, peer_list) {
-		peer = list_entry(tmp, struct kib_peer, ibp_list);
+	list_for_each_entry(peer, peer_list, ibp_list) {
 		LASSERT(!kiblnd_peer_idle(peer));
 
 		if (peer->ibp_nid != nid)
@@ -419,15 +417,13 @@ static int kiblnd_get_peer_info(struct lnet_ni *ni, int index,
 				lnet_nid_t *nidp, int *count)
 {
 	struct kib_peer *peer;
-	struct list_head *ptmp;
 	int i;
 	unsigned long flags;
 
 	read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
 
 	for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++) {
-		list_for_each(ptmp, &kiblnd_data.kib_peers[i]) {
-			peer = list_entry(ptmp, struct kib_peer, ibp_list);
+		list_for_each_entry(peer, &kiblnd_data.kib_peers[i], ibp_list) {
 			LASSERT(!kiblnd_peer_idle(peer));
 
 			if (peer->ibp_ni != ni)
@@ -526,28 +522,23 @@ static int kiblnd_del_peer(struct lnet_ni *ni, lnet_nid_t nid)
 static struct kib_conn *kiblnd_get_conn_by_idx(struct lnet_ni *ni, int index)
 {
 	struct kib_peer *peer;
-	struct list_head *ptmp;
 	struct kib_conn *conn;
-	struct list_head *ctmp;
 	int i;
 	unsigned long flags;
 
 	read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
 
 	for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++) {
-		list_for_each(ptmp, &kiblnd_data.kib_peers[i]) {
-			peer = list_entry(ptmp, struct kib_peer, ibp_list);
+		list_for_each_entry(peer, &kiblnd_data.kib_peers[i], ibp_list) {
 			LASSERT(!kiblnd_peer_idle(peer));
 
 			if (peer->ibp_ni != ni)
 				continue;
 
-			list_for_each(ctmp, &peer->ibp_conns) {
+			list_for_each_entry(conn, &peer->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,
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c +5 -15
index bda67d49597d..2f7a64f2f13a 100644
@@ -225,11 +225,9 @@ kiblnd_post_rx(struct kib_rx *rx, int credit)
 static struct kib_tx *
 kiblnd_find_waiting_tx_locked(struct kib_conn *conn, int txtype, __u64 cookie)
 {
-	struct list_head *tmp;
-
-	list_for_each(tmp, &conn->ibc_active_txs) {
-		struct kib_tx *tx = list_entry(tmp, struct kib_tx, tx_list);
+	struct kib_tx *tx;
 
+	list_for_each_entry(tx, &conn->ibc_active_txs, tx_list) {
 		LASSERT(!tx->tx_queued);
 		LASSERT(tx->tx_sending || tx->tx_waiting);
 
@@ -3142,11 +3140,8 @@ static int
 kiblnd_check_txs_locked(struct kib_conn *conn, struct list_head *txs)
 {
 	struct kib_tx *tx;
-	struct list_head *ttmp;
-
-	list_for_each(ttmp, txs) {
-		tx = list_entry(ttmp, struct kib_tx, tx_list);
 
+	list_for_each_entry(tx, txs, tx_list) {
 		if (txs != &conn->ibc_active_txs) {
 			LASSERT(tx->tx_queued);
 		} else {
@@ -3182,10 +3177,8 @@ kiblnd_check_conns(int idx)
 	LIST_HEAD(closes);
 	LIST_HEAD(checksends);
 	struct list_head *peers = &kiblnd_data.kib_peers[idx];
-	struct list_head *ptmp;
 	struct kib_peer *peer;
 	struct kib_conn *conn;
-	struct list_head *ctmp;
 	unsigned long flags;
 
 	/*
@@ -3195,15 +3188,12 @@ kiblnd_check_conns(int idx)
 	 */
 	read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
 
-	list_for_each(ptmp, peers) {
-		peer = list_entry(ptmp, struct kib_peer, ibp_list);
+	list_for_each_entry(peer, peers, ibp_list) {
 
-		list_for_each(ctmp, &peer->ibp_conns) {
+		list_for_each_entry(conn, &peer->ibp_conns, ibc_list) {
 			int timedout;
 			int sendnoop;
 
-			conn = list_entry(ctmp, struct kib_conn, ibc_list);
-
 			LASSERT(conn->ibc_state == IBLND_CONN_ESTABLISHED);
 
 			spin_lock(&conn->ibc_lock);
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +13 -38

147 lines not on this page · raw message

drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +5 -15
index d531847305e4..a5c0e8a9bc40 100644
@@ -561,18 +561,16 @@ struct ksock_conn *
 ksocknal_find_conn_locked(struct ksock_peer *peer, struct ksock_tx *tx,
 			  int nonblk)
 {
-	struct list_head *tmp;
+	struct ksock_conn *c;
 	struct ksock_conn *conn;
 	struct ksock_conn *typed = NULL;
 	struct ksock_conn *fallback = NULL;
 	int tnob = 0;
 	int fnob = 0;
 
-	list_for_each(tmp, &peer->ksnp_conns) {
-		struct ksock_conn *c;
+	list_for_each_entry(c, &peer->ksnp_conns, ksnc_list) {
 		int nob, rc;
 
-		c = list_entry(tmp, struct ksock_conn, ksnc_list);
 		nob = atomic_read(&c->ksnc_tx_nob) +
 		      c->ksnc_sock->sk->sk_wmem_queued;
 
@@ -729,12 +727,9 @@ struct ksock_route *
 ksocknal_find_connectable_route_locked(struct ksock_peer *peer)
 {
 	time64_t now = ktime_get_seconds();
-	struct list_head *tmp;
 	struct ksock_route *route;
 
-	list_for_each(tmp, &peer->ksnp_routes) {
-		route = list_entry(tmp, struct ksock_route, ksnr_list);
-
+	list_for_each_entry(route, &peer->ksnp_routes, ksnr_list) {
 		LASSERT(!route->ksnr_connecting || route->ksnr_scheduled);
 
 		/* connections being established */
@@ -765,11 +760,9 @@ ksocknal_find_connectable_route_locked(struct ksock_peer *peer)
 struct ksock_route *
 ksocknal_find_connecting_route_locked(struct ksock_peer *peer)
 {
-	struct list_head *tmp;
 	struct ksock_route *route;
 
-	list_for_each(tmp, &peer->ksnp_routes) {
-		route = list_entry(tmp, struct ksock_route, ksnr_list);
+	list_for_each_entry(route, &peer->ksnp_routes, ksnr_list) {
 
 		LASSERT(!route->ksnr_connecting || route->ksnr_scheduled);
 
@@ -2180,13 +2173,10 @@ ksocknal_find_timed_out_conn(struct ksock_peer *peer)
 {
 	/* We're called with a shared lock on ksnd_global_lock */
 	struct ksock_conn *conn;
-	struct list_head *ctmp;
 
-	list_for_each(ctmp, &peer->ksnp_conns) {
+	list_for_each_entry(conn, &peer->ksnp_conns, ksnc_list) {
 		int error;
 
-		conn = list_entry(ctmp, struct ksock_conn, ksnc_list);
-
 		/* Don't need the {get,put}connsock dance to deref ksnc_sock */
 		LASSERT(!conn->ksnc_closing);
 
drivers/staging/lustre/lnet/lnet/api-ni.c +6 -23
index 51a81075f8d5..14b797802a85 100644
@@ -269,12 +269,9 @@ static struct lnet_lnd *
 lnet_find_lnd_by_type(__u32 type)
 {
 	struct lnet_lnd *lnd;
-	struct list_head *tmp;
 
 	/* holding lnd mutex */
-	list_for_each(tmp, &the_lnet.ln_lnds) {
-		lnd = list_entry(tmp, struct lnet_lnd, lnd_list);
-
+	list_for_each_entry(lnd, &the_lnet.ln_lnds, lnd_list) {
 		if (lnd->lnd_type == type)
 			return lnd;
 	}
@@ -653,14 +650,11 @@ lnet_unprepare(void)
 struct lnet_ni  *
 lnet_net2ni_locked(__u32 net, int cpt)
 {
-	struct list_head *tmp;
 	struct lnet_ni *ni;
 
 	LASSERT(cpt != LNET_LOCK_EX);
 
-	list_for_each(tmp, &the_lnet.ln_nis) {
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (LNET_NIDNET(ni->ni_nid) == net) {
 			lnet_ni_addref_locked(ni, cpt);
 			return ni;
@@ -767,13 +761,10 @@ struct lnet_ni  *
 lnet_nid2ni_locked(lnet_nid_t nid, int cpt)
 {
 	struct lnet_ni *ni;
-	struct list_head *tmp;
 
 	LASSERT(cpt != LNET_LOCK_EX);
 
-	list_for_each(tmp, &the_lnet.ln_nis) {
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (ni->ni_nid == nid) {
 			lnet_ni_addref_locked(ni, cpt);
 			return ni;
@@ -803,14 +794,11 @@ lnet_count_acceptor_nis(void)
 {
 	/* Return the # of NIs that need the acceptor. */
 	int count = 0;
-	struct list_head *tmp;
 	struct lnet_ni *ni;
 	int cpt;
 
 	cpt = lnet_net_lock_current();
-	list_for_each(tmp, &the_lnet.ln_nis) {
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (ni->ni_lnd->lnd_accept)
 			count++;
 	}
@@ -1731,18 +1719,16 @@ static int
 lnet_get_net_config(struct lnet_ioctl_config_data *config)
 {
 	struct lnet_ni *ni;
-	struct list_head *tmp;
 	int idx = config->cfg_count;
 	int cpt, i = 0;
 	int rc = -ENOENT;
 
 	cpt = lnet_net_lock_current();
 
-	list_for_each(tmp, &the_lnet.ln_nis) {
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (i++ != idx)
 			continue;
 
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
 		lnet_ni_lock(ni);
 		lnet_fill_ni_info(ni, config);
 		lnet_ni_unlock(ni);
@@ -2119,7 +2105,6 @@ int
 LNetGetId(unsigned int index, struct lnet_process_id *id)
 {
 	struct lnet_ni *ni;
-	struct list_head *tmp;
 	int cpt;
 	int rc = -ENOENT;
 
@@ -2127,12 +2112,10 @@ LNetGetId(unsigned int index, struct lnet_process_id *id)
 
 	cpt = lnet_net_lock_current();
 
-	list_for_each(tmp, &the_lnet.ln_nis) {
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (index--)
 			continue;
 
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
 		id->nid = ni->ni_nid;
 		id->pid = the_lnet.ln_pid;
 		rc = 0;
drivers/staging/lustre/lnet/lnet/config.c +4 -13
index 26b799e66e53..96336ecdacaf 100644
@@ -81,12 +81,9 @@ lnet_issep(char c)
 int
 lnet_net_unique(__u32 net, struct list_head *nilist)
 {
-	struct list_head *tmp;
 	struct lnet_ni *ni;
 
-	list_for_each(tmp, nilist) {
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, nilist, ni_list) {
 		if (LNET_NIDNET(ni->ni_nid) == net)
 			return 0;
 	}
@@ -942,7 +939,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;
@@ -983,9 +979,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;
 
@@ -1074,14 +1068,11 @@ lnet_match_networks(char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
 			break;
 
 		dup = 0;
-		list_for_each(t, &current_nets) {
-			tb = list_entry(t, struct lnet_text_buf, ltb_list);
+		list_for_each_entry(tb, &current_nets, ltb_list) {
 			net1 = lnet_netspec2net(tb->ltb_text);
 			LASSERT(net1 != LNET_NIDNET(LNET_NID_ANY));
 
-			list_for_each(t2, &matched_nets) {
-				tb2 = list_entry(t2, struct lnet_text_buf,
-						 ltb_list);
+			list_for_each_entry(tb2, &matched_nets, ltb_list) {
 				net2 = lnet_netspec2net(tb2->ltb_text);
 				LASSERT(net2 != LNET_NIDNET(LNET_NID_ANY));
 
drivers/staging/lustre/lnet/lnet/lib-move.c +2 -7
index 19cab374b6bc..edcafac055ed 100644
@@ -2288,7 +2288,6 @@ EXPORT_SYMBOL(LNetGet);
 int
 LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
 {
-	struct list_head *e;
 	struct lnet_ni *ni;
 	struct lnet_remotenet *rnet;
 	__u32 dstnet = LNET_NIDNET(dstnid);
@@ -2307,9 +2306,7 @@ LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
 
 	cpt = lnet_net_lock_current();
 
-	list_for_each(e, &the_lnet.ln_nis) {
-		ni = list_entry(e, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (ni->ni_nid == dstnid) {
 			if (srcnidp)
 				*srcnidp = dstnid;
@@ -2346,9 +2343,7 @@ LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __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;
drivers/staging/lustre/lnet/lnet/router.c +10 -37

132 lines not on this page · raw message

drivers/staging/lustre/lnet/selftest/conrpc.c +2 -5
index 3afde0141db5..e73b956d15e4 100644
@@ -1327,7 +1327,6 @@ lstcon_rpc_cleanup_wait(void)
 {
 	struct lstcon_rpc_trans *trans;
 	struct lstcon_rpc *crpc;
-	struct list_head *pacer;
 	struct list_head zlist;
 
 	/* Called with hold of global mutex */
@@ -1335,10 +1334,8 @@ lstcon_rpc_cleanup_wait(void)
 	LASSERT(console_session.ses_shutdown);
 
 	while (!list_empty(&console_session.ses_trans_list)) {
-		list_for_each(pacer, &console_session.ses_trans_list) {
-			trans = list_entry(pacer, struct lstcon_rpc_trans,
-					   tas_link);
-
+		list_for_each_entry(trans, &console_session.ses_trans_list,
+				    tas_link) {
 			CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
 			       lstcon_rpc_trans_name(trans->tas_opc));
 
drivers/staging/lustre/lustre/obdclass/genops.c +1 -3
index 234f383ce6d9..8454b4470b8c 100644
@@ -84,12 +84,10 @@ static void obd_device_free(struct obd_device *obd)
 
 static struct obd_type *class_search_type(const char *name)
 {
-	struct list_head *tmp;
 	struct obd_type *type;
 
 	spin_lock(&obd_types_lock);
-	list_for_each(tmp, &obd_types) {
-		type = list_entry(tmp, struct obd_type, typ_chain);
+	list_for_each_entry(type, &obd_types, typ_chain) {
 		if (strcmp(type->typ_name, name) == 0) {
 			spin_unlock(&obd_types_lock);
 			return type;
drivers/staging/lustre/lustre/obdecho/echo_client.c +1 -3
index 484b8d6db6ef..3022706c6985 100644
@@ -950,12 +950,10 @@ static int cl_echo_cancel0(struct lu_env *env, struct echo_device *ed,
 {
 	struct echo_client_obd *ec = ed->ed_ec;
 	struct echo_lock       *ecl = NULL;
-	struct list_head	     *el;
 	int found = 0, still_used = 0;
 
 	spin_lock(&ec->ec_lock);
-	list_for_each(el, &ec->ec_locks) {
-		ecl = list_entry(el, struct echo_lock, el_chain);
+	list_for_each_entry(ecl, &ec->ec_locks, el_chain) {
 		CDEBUG(D_INFO, "ecl: %p, cookie: %#llx\n", ecl, ecl->el_cookie);
 		found = (ecl->el_cookie == cookie);
 		if (found) {
#2 lore raw

PATCH 1/6 lustre: convert list_for_each() to list_for_each_entry().

Quoted 13 lines · NeilBrown

Where we have
struct list_head *tmp;

 list_for_each(tmp,....) {
    foo = list_entry(tmp, ....);
    ...

}

convert to
list_for_each_entry(foo, .....) {
.....
}

Quoted 5 lines

This patch only changes instances which are straight forward, where neither the 'tmp' variable nor the 'foo' variable is not used outside the loop in any way that isn't trivially correct.

Quoted 765 lines

---

.../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c    |   17 ++-----
.../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c |   20 ++------
.../staging/lustre/lnet/klnds/socklnd/socklnd.c    |   51 +++++---------------
.../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c |   20 ++------
drivers/staging/lustre/lnet/lnet/api-ni.c          |   29 ++---------
drivers/staging/lustre/lnet/lnet/config.c          |   17 ++-----
drivers/staging/lustre/lnet/lnet/lib-move.c        |    9 +---
drivers/staging/lustre/lnet/lnet/router.c          |   47 ++++--------------
drivers/staging/lustre/lnet/selftest/conrpc.c      |    7 +--
drivers/staging/lustre/lustre/obdclass/genops.c    |    4 --
.../staging/lustre/lustre/obdecho/echo_client.c    |    4 --
11 files changed, 53 insertions(+), 172 deletions(-)
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +4 -13
index 830a5bf34c16..e15ad94151bd 100644
@@ -386,11 +386,9 @@ struct kib_peer *kiblnd_find_peer_locked(lnet_nid_t nid)
 	 * that this creates
 	 */
 	struct list_head *peer_list = kiblnd_nid2peerlist(nid);
-	struct list_head *tmp;
 	struct kib_peer *peer;
 
-	list_for_each(tmp, peer_list) {
-		peer = list_entry(tmp, struct kib_peer, ibp_list);
+	list_for_each_entry(peer, peer_list, ibp_list) {
 		LASSERT(!kiblnd_peer_idle(peer));
 
 		if (peer->ibp_nid != nid)
@@ -419,15 +417,13 @@ static int kiblnd_get_peer_info(struct lnet_ni *ni, int index,
 				lnet_nid_t *nidp, int *count)
 {
 	struct kib_peer *peer;
-	struct list_head *ptmp;
 	int i;
 	unsigned long flags;
 
 	read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
 
 	for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++) {
-		list_for_each(ptmp, &kiblnd_data.kib_peers[i]) {
-			peer = list_entry(ptmp, struct kib_peer, ibp_list);
+		list_for_each_entry(peer, &kiblnd_data.kib_peers[i], ibp_list) {
 			LASSERT(!kiblnd_peer_idle(peer));
 
 			if (peer->ibp_ni != ni)
@@ -526,28 +522,23 @@ static int kiblnd_del_peer(struct lnet_ni *ni, lnet_nid_t nid)
 static struct kib_conn *kiblnd_get_conn_by_idx(struct lnet_ni *ni, int index)
 {
 	struct kib_peer *peer;
-	struct list_head *ptmp;
 	struct kib_conn *conn;
-	struct list_head *ctmp;
 	int i;
 	unsigned long flags;
 
 	read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
 
 	for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++) {
-		list_for_each(ptmp, &kiblnd_data.kib_peers[i]) {
-			peer = list_entry(ptmp, struct kib_peer, ibp_list);
+		list_for_each_entry(peer, &kiblnd_data.kib_peers[i], ibp_list) {
 			LASSERT(!kiblnd_peer_idle(peer));
 
 			if (peer->ibp_ni != ni)
 				continue;
 
-			list_for_each(ctmp, &peer->ibp_conns) {
+			list_for_each_entry(conn, &peer->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,
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c +0 -0
index bda67d49597d..2f7a64f2f13a 100644
@@ -225,11 +225,9 @@ kiblnd_post_rx(struct kib_rx *rx, int credit)

static struct kib_tx *
kiblnd_find_waiting_tx_locked(struct kib_conn *conn, int txtype, __u64 cookie) {

drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c +2 -4
-	struct list_head *tmp;
-
-	list_for_each(tmp, &conn->ibc_active_txs) {
-		struct kib_tx *tx = list_entry(tmp, struct kib_tx, tx_list);
+	struct kib_tx *tx;
 
+	list_for_each_entry(tx, &conn->ibc_active_txs, tx_list) {
		LASSERT(!tx->tx_queued);
		LASSERT(tx->tx_sending || tx->tx_waiting);
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c +3 -11
@@ -3142,11 +3140,8 @@ static int
 kiblnd_check_txs_locked(struct kib_conn *conn, struct list_head *txs)
 {
 	struct kib_tx *tx;
-	struct list_head *ttmp;
-
-	list_for_each(ttmp, txs) {
-		tx = list_entry(ttmp, struct kib_tx, tx_list);
 
+	list_for_each_entry(tx, txs, tx_list) {
 		if (txs != &conn->ibc_active_txs) {
 			LASSERT(tx->tx_queued);
 		} else {
@@ -3182,10 +3177,8 @@ kiblnd_check_conns(int idx)
 	LIST_HEAD(closes);
 	LIST_HEAD(checksends);
 	struct list_head *peers = &kiblnd_data.kib_peers[idx];
-	struct list_head *ptmp;
 	struct kib_peer *peer;
 	struct kib_conn *conn;
-	struct list_head *ctmp;
 	unsigned long flags;
 
 	/*
@@ -3195,15 +3188,12 @@ kiblnd_check_conns(int idx)
 	 */
 	read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
 
-	list_for_each(ptmp, peers) {
-		peer = list_entry(ptmp, struct kib_peer, ibp_list);
+	list_for_each_entry(peer, peers, ibp_list) {
 
-		list_for_each(ctmp, &peer->ibp_conns) {
+		list_for_each_entry(conn, &peer->ibp_conns, ibc_list) {
 			int timedout;
 			int sendnoop;
 
-			conn = list_entry(ctmp, struct kib_conn, ibc_list);
-
 			LASSERT(conn->ibc_state == IBLND_CONN_ESTABLISHED);
 
 			spin_lock(&conn->ibc_lock);
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +3 -8
index a48b1b9a850b..491d2ed5b673 100644
@@ -250,9 +250,7 @@ ksocknal_get_peer_info(struct lnet_ni *ni, int index,
 		       int *port, int *conn_count, int *share_count)
 {
 	struct ksock_peer *peer;
-	struct list_head *ptmp;
 	struct ksock_route *route;
-	struct list_head *rtmp;
 	int i;
 	int j;
 	int rc = -ENOENT;
@@ -260,8 +258,7 @@ ksocknal_get_peer_info(struct lnet_ni *ni, int index,
 	read_lock(&ksocknal_data.ksnd_global_lock);
 
 	for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
-		list_for_each(ptmp, &ksocknal_data.ksnd_peers[i]) {
-			peer = list_entry(ptmp, struct ksock_peer, ksnp_list);
+		list_for_each_entry(peer, &ksocknal_data.ksnd_peers[i], ksnp_list) {
 
 			if (peer->ksnp_ni != ni)
 				continue;
@@ -295,13 +292,11 @@ ksocknal_get_peer_info(struct lnet_ni *ni, int index,
 				goto out;
 			}
 
-			list_for_each(rtmp, &peer->ksnp_routes) {
+			list_for_each_entry(route, &peer->ksnp_routes,
+					    ksnr_list) {
 				if (index-- > 0)
 					continue;
 
-				route = list_entry(rtmp, struct ksock_route,
-						   ksnr_list);
-
 				*id = peer->ksnp_id;
 				*myip = route->ksnr_myipaddr;
 				*peer_ip = route->ksnr_ipaddr;
@@ -368,7 +363,6 @@ ksocknal_associate_route_conn_locked(struct ksock_route *route,

static void
ksocknal_add_route_locked(struct ksock_peer *peer, struct ksock_route *route) {

drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +0 -1
-	struct list_head *tmp;
	struct ksock_conn *conn;
	struct ksock_route *route2;
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +10 -29
@@ -379,9 +373,7 @@ ksocknal_add_route_locked(struct ksock_peer *peer, struct ksock_route *route)
 	LASSERT(!route->ksnr_connected);
 
 	/* LASSERT(unique) */
-	list_for_each(tmp, &peer->ksnp_routes) {
-		route2 = list_entry(tmp, struct ksock_route, ksnr_list);
-
+	list_for_each_entry(route2, &peer->ksnp_routes, ksnr_list) {
 		if (route2->ksnr_ipaddr == route->ksnr_ipaddr) {
 			CERROR("Duplicate route %s %pI4h\n",
 			       libcfs_id2str(peer->ksnp_id),
@@ -395,9 +387,7 @@ ksocknal_add_route_locked(struct ksock_peer *peer, struct ksock_route *route)
 	/* peer's routelist takes over my ref on 'route' */
 	list_add_tail(&route->ksnr_list, &peer->ksnp_routes);
 
-	list_for_each(tmp, &peer->ksnp_conns) {
-		conn = list_entry(tmp, struct ksock_conn, ksnc_list);
-
+	list_for_each_entry(conn, &peer->ksnp_conns, ksnc_list) {
 		if (conn->ksnc_ipaddr != route->ksnr_ipaddr)
 			continue;
 
@@ -624,28 +614,22 @@ static struct ksock_conn *
 ksocknal_get_conn_by_idx(struct lnet_ni *ni, int index)
 {
 	struct ksock_peer *peer;
-	struct list_head *ptmp;
 	struct ksock_conn *conn;
-	struct list_head *ctmp;
 	int i;
 
 	read_lock(&ksocknal_data.ksnd_global_lock);
 
 	for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
-		list_for_each(ptmp, &ksocknal_data.ksnd_peers[i]) {
-			peer = list_entry(ptmp, struct ksock_peer, ksnp_list);
-
+		list_for_each_entry(peer, &ksocknal_data.ksnd_peers[i], ksnp_list) {
 			LASSERT(!peer->ksnp_closing);
 
 			if (peer->ksnp_ni != ni)
 				continue;
 
-			list_for_each(ctmp, &peer->ksnp_conns) {
+			list_for_each_entry(conn, &peer->ksnp_conns, ksnc_list) {
 				if (index-- > 0)
 					continue;
 
-				conn = list_entry(ctmp, struct ksock_conn,
-						  ksnc_list);
 				ksocknal_conn_addref(conn);
 				read_unlock(&ksocknal_data.ksnd_global_lock);
 				return conn;
@@ -1025,7 +1009,6 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route,
 	rwlock_t *global_lock = &ksocknal_data.ksnd_global_lock;
 	LIST_HEAD(zombies);
 	struct lnet_process_id peerid;
-	struct list_head *tmp;
 	__u64 incarnation;
 	struct ksock_conn *conn;
 	struct ksock_conn *conn2;
@@ -1226,8 +1209,7 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route,
 	 * loopback connection
 	 */
 	if (conn->ksnc_ipaddr != conn->ksnc_myipaddr) {
-		list_for_each(tmp, &peer->ksnp_conns) {
-			conn2 = list_entry(tmp, struct ksock_conn, ksnc_list);
+		list_for_each_entry(conn2, &peer->ksnp_conns, ksnc_list) {
 
 			if (conn2->ksnc_ipaddr != conn->ksnc_ipaddr ||
 			    conn2->ksnc_myipaddr != conn->ksnc_myipaddr ||
@@ -1266,9 +1248,7 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route,
 	 * by routes in my peer to match my own route entries so I don't
 	 * continually create duplicate routes.
 	 */
-	list_for_each(tmp, &peer->ksnp_routes) {
-		route = list_entry(tmp, struct ksock_route, ksnr_list);
-
+	list_for_each_entry(route, &peer->ksnp_routes, ksnr_list) {
 		if (route->ksnr_ipaddr != conn->ksnc_ipaddr)
 			continue;
 
@@ -1980,9 +1960,7 @@ ksocknal_add_interface(struct lnet_ni *ni, __u32 ipaddress, __u32 netmask)
 	int rc;
 	int i;
 	int j;
-	struct list_head *ptmp;
 	struct ksock_peer *peer;
-	struct list_head *rtmp;
 	struct ksock_route *route;
 
 	if (!ipaddress || !netmask)
@@ -2005,18 +1983,15 @@ ksocknal_add_interface(struct lnet_ni *ni, __u32 ipaddress, __u32 netmask)
 		iface->ksni_npeers = 0;
 
 		for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
-			list_for_each(ptmp, &ksocknal_data.ksnd_peers[i]) {
-				peer = list_entry(ptmp, struct ksock_peer,
-						  ksnp_list);
+			list_for_each_entry(peer, &ksocknal_data.ksnd_peers[i],
+					    ksnp_list) {
 
 				for (j = 0; j < peer->ksnp_n_passive_ips; j++)
 					if (peer->ksnp_passive_ips[j] == ipaddress)
 						iface->ksni_npeers++;
 
-				list_for_each(rtmp, &peer->ksnp_routes) {
-					route = list_entry(rtmp, struct ksock_route,
-							   ksnr_list);
-
+				list_for_each_entry(route, &peer->ksnp_routes,
+						    ksnr_list) {
 					if (route->ksnr_myipaddr == ipaddress)
 						iface->ksni_nroutes++;
 				}
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +3 -8
index d531847305e4..a5c0e8a9bc40 100644
@@ -561,18 +561,16 @@ struct ksock_conn *
 ksocknal_find_conn_locked(struct ksock_peer *peer, struct ksock_tx *tx,
 			  int nonblk)
 {
-	struct list_head *tmp;
+	struct ksock_conn *c;
 	struct ksock_conn *conn;
 	struct ksock_conn *typed = NULL;
 	struct ksock_conn *fallback = NULL;
 	int tnob = 0;
 	int fnob = 0;
 
-	list_for_each(tmp, &peer->ksnp_conns) {
-		struct ksock_conn *c;
+	list_for_each_entry(c, &peer->ksnp_conns, ksnc_list) {
 		int nob, rc;
 
-		c = list_entry(tmp, struct ksock_conn, ksnc_list);
 		nob = atomic_read(&c->ksnc_tx_nob) +
 		      c->ksnc_sock->sk->sk_wmem_queued;
 
@@ -729,12 +727,9 @@ struct ksock_route *
 ksocknal_find_connectable_route_locked(struct ksock_peer *peer)
 {
 	time64_t now = ktime_get_seconds();
-	struct list_head *tmp;
 	struct ksock_route *route;
 
-	list_for_each(tmp, &peer->ksnp_routes) {
-		route = list_entry(tmp, struct ksock_route, ksnr_list);
-
+	list_for_each_entry(route, &peer->ksnp_routes, ksnr_list) {
 		LASSERT(!route->ksnr_connecting || route->ksnr_scheduled);
 
 		/* connections being established */
@@ -765,11 +760,9 @@ ksocknal_find_connectable_route_locked(struct ksock_peer *peer)

struct ksock_route * ksocknal_find_connecting_route_locked(struct ksock_peer *peer) {

drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +0 -1
-	struct list_head *tmp;
	struct ksock_route *route;
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +1 -2
-	list_for_each(tmp, &peer->ksnp_routes) {
-		route = list_entry(tmp, struct ksock_route, ksnr_list);
+	list_for_each_entry(route, &peer->ksnp_routes, ksnr_list) {
		LASSERT(!route->ksnr_connecting || route->ksnr_scheduled);
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +1 -4
@@ -2180,13 +2173,10 @@ ksocknal_find_timed_out_conn(struct ksock_peer *peer)
 {
 	/* We're called with a shared lock on ksnd_global_lock */
 	struct ksock_conn *conn;
-	struct list_head *ctmp;
 
-	list_for_each(ctmp, &peer->ksnp_conns) {
+	list_for_each_entry(conn, &peer->ksnp_conns, ksnc_list) {
 		int error;
 
-		conn = list_entry(ctmp, struct ksock_conn, ksnc_list);
-
 		/* Don't need the {get,put}connsock dance to deref ksnc_sock */
 		LASSERT(!conn->ksnc_closing);
 
drivers/staging/lustre/lnet/lnet/api-ni.c +1 -4
index 51a81075f8d5..14b797802a85 100644
@@ -269,12 +269,9 @@ static struct lnet_lnd *
 lnet_find_lnd_by_type(__u32 type)
 {
 	struct lnet_lnd *lnd;
-	struct list_head *tmp;
 
 	/* holding lnd mutex */
-	list_for_each(tmp, &the_lnet.ln_lnds) {
-		lnd = list_entry(tmp, struct lnet_lnd, lnd_list);
-
+	list_for_each_entry(lnd, &the_lnet.ln_lnds, lnd_list) {
 		if (lnd->lnd_type == type)
 			return lnd;
 	}
@@ -653,14 +650,11 @@ lnet_unprepare(void)

struct lnet_ni *
lnet_net2ni_locked(__u32 net, int cpt)
{

drivers/staging/lustre/lnet/lnet/api-ni.c +0 -1
-	struct list_head *tmp;
	struct lnet_ni *ni;

	LASSERT(cpt != LNET_LOCK_EX);
drivers/staging/lustre/lnet/lnet/api-ni.c +1 -3
-	list_for_each(tmp, &the_lnet.ln_nis) {
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
		if (LNET_NIDNET(ni->ni_nid) == net) {
			lnet_ni_addref_locked(ni, cpt);
			return ni;
drivers/staging/lustre/lnet/lnet/api-ni.c +4 -15
@@ -767,13 +761,10 @@ struct lnet_ni  *
 lnet_nid2ni_locked(lnet_nid_t nid, int cpt)
 {
 	struct lnet_ni *ni;
-	struct list_head *tmp;
 
 	LASSERT(cpt != LNET_LOCK_EX);
 
-	list_for_each(tmp, &the_lnet.ln_nis) {
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (ni->ni_nid == nid) {
 			lnet_ni_addref_locked(ni, cpt);
 			return ni;
@@ -803,14 +794,11 @@ lnet_count_acceptor_nis(void)
 {
 	/* Return the # of NIs that need the acceptor. */
 	int count = 0;
-	struct list_head *tmp;
 	struct lnet_ni *ni;
 	int cpt;
 
 	cpt = lnet_net_lock_current();
-	list_for_each(tmp, &the_lnet.ln_nis) {
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (ni->ni_lnd->lnd_accept)
 			count++;
 	}
@@ -1731,18 +1719,16 @@ static int
 lnet_get_net_config(struct lnet_ioctl_config_data *config)
 {
 	struct lnet_ni *ni;
-	struct list_head *tmp;
 	int idx = config->cfg_count;
 	int cpt, i = 0;
 	int rc = -ENOENT;
 
 	cpt = lnet_net_lock_current();
 
-	list_for_each(tmp, &the_lnet.ln_nis) {
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (i++ != idx)
 			continue;
 
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
 		lnet_ni_lock(ni);
 		lnet_fill_ni_info(ni, config);
 		lnet_ni_unlock(ni);
@@ -2119,7 +2105,6 @@ int
 LNetGetId(unsigned int index, struct lnet_process_id *id)
 {
 	struct lnet_ni *ni;
-	struct list_head *tmp;
 	int cpt;
 	int rc = -ENOENT;
 
@@ -2127,12 +2112,10 @@ LNetGetId(unsigned int index, struct lnet_process_id *id)
 
 	cpt = lnet_net_lock_current();
 
-	list_for_each(tmp, &the_lnet.ln_nis) {
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (index--)
 			continue;
 
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
 		id->nid = ni->ni_nid;
 		id->pid = the_lnet.ln_pid;
 		rc = 0;
drivers/staging/lustre/lnet/lnet/config.c +0 -0
index 26b799e66e53..96336ecdacaf 100644
@@ -81,12 +81,9 @@ lnet_issep(char c)

int
lnet_net_unique(__u32 net, struct list_head *nilist) {

drivers/staging/lustre/lnet/lnet/config.c +0 -1
-	struct list_head *tmp;
	struct lnet_ni *ni;
drivers/staging/lustre/lnet/lnet/config.c +1 -3
-	list_for_each(tmp, nilist) {
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, nilist, ni_list) {
		if (LNET_NIDNET(ni->ni_nid) == net)
			return 0;
	}
drivers/staging/lustre/lnet/lnet/config.c +3 -9
@@ -942,7 +939,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;
@@ -983,9 +979,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;
 
@@ -1074,14 +1068,11 @@ lnet_match_networks(char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
 			break;
 
 		dup = 0;
-		list_for_each(t, &current_nets) {
-			tb = list_entry(t, struct lnet_text_buf, ltb_list);
+		list_for_each_entry(tb, &current_nets, ltb_list) {
 			net1 = lnet_netspec2net(tb->ltb_text);
 			LASSERT(net1 != LNET_NIDNET(LNET_NID_ANY));
 
-			list_for_each(t2, &matched_nets) {
-				tb2 = list_entry(t2, struct lnet_text_buf,
-						 ltb_list);
+			list_for_each_entry(tb2, &matched_nets, ltb_list) {
 				net2 = lnet_netspec2net(tb2->ltb_text);
 				LASSERT(net2 != LNET_NIDNET(LNET_NID_ANY));
 
drivers/staging/lustre/lnet/lnet/lib-move.c +0 -0
index 19cab374b6bc..edcafac055ed 100644
@@ -2288,7 +2288,6 @@ EXPORT_SYMBOL(LNetGet);

int
LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp) {

drivers/staging/lustre/lnet/lnet/lib-move.c +0 -1
-	struct list_head *e;
	struct lnet_ni *ni;
	struct lnet_remotenet *rnet;
	__u32 dstnet = LNET_NIDNET(dstnid);
drivers/staging/lustre/lnet/lnet/lib-move.c +2 -6
@@ -2307,9 +2306,7 @@ LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
 
 	cpt = lnet_net_lock_current();
 
-	list_for_each(e, &the_lnet.ln_nis) {
-		ni = list_entry(e, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (ni->ni_nid == dstnid) {
 			if (srcnidp)
 				*srcnidp = dstnid;
@@ -2346,9 +2343,7 @@ LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __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;
drivers/staging/lustre/lnet/lnet/router.c +9 -34
index 965087b7359c..53373372b526 100644
@@ -292,10 +292,10 @@ int
 lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
 	       unsigned int priority)
 {
-	struct list_head *e;
 	struct lnet_remotenet *rnet;
 	struct lnet_remotenet *rnet2;
 	struct lnet_route *route;
+	struct lnet_route *route2;
 	struct lnet_ni *ni;
 	int add_route;
 	int rc;
@@ -359,10 +359,8 @@ lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
 
 	/* Search for a duplicate route (it's a NOOP if it is) */
 	add_route = 1;
-	list_for_each(e, &rnet2->lrn_routes) {
-		struct lnet_route *route2;
+	list_for_each_entry(route2, &rnet2->lrn_routes, lr_list) {
 
-		route2 = list_entry(e, struct lnet_route, lr_list);
 		if (route2->lr_gateway == route->lr_gateway) {
 			add_route = 0;
 			break;
@@ -411,8 +409,6 @@ lnet_check_routes(void)
 	struct lnet_remotenet *rnet;
 	struct lnet_route *route;
 	struct lnet_route *route2;
-	struct list_head *e1;
-	struct list_head *e2;
 	int cpt;
 	struct list_head *rn_list;
 	int i;
@@ -421,17 +417,13 @@ lnet_check_routes(void)
 
 	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_entry(rnet, rn_list, lrn_list) {
 			route2 = NULL;
-			list_for_each(e2, &rnet->lrn_routes) {
+			list_for_each_entry(route, &rnet->lrn_routes, lr_list) {
 				lnet_nid_t nid1;
 				lnet_nid_t nid2;
 				int net;
 
-				route = list_entry(e2, struct lnet_route, lr_list);
-
 				if (!route2) {
 					route2 = route;
 					continue;
@@ -466,8 +458,6 @@ lnet_del_route(__u32 net, lnet_nid_t gw_nid)
 	struct lnet_peer *gateway;
 	struct lnet_remotenet *rnet;
 	struct lnet_route *route;
-	struct list_head *e1;
-	struct list_head *e2;
 	int rc = -ENOENT;
 	struct list_head *rn_list;
 	int idx = 0;
@@ -486,16 +476,12 @@ lnet_del_route(__u32 net, lnet_nid_t gw_nid)
 		rn_list = lnet_net2rnethash(net);
 
 again:
-	list_for_each(e1, rn_list) {
-		rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
-
+	list_for_each_entry(rnet, rn_list, lrn_list) {
 		if (!(net == LNET_NIDNET(LNET_NID_ANY) ||
 		      net == rnet->lrn_net))
 			continue;
 
-		list_for_each(e2, &rnet->lrn_routes) {
-			route = list_entry(e2, struct lnet_route, lr_list);
-
+		list_for_each_entry(route, &rnet->lrn_routes, lr_list) {
 			gateway = route->lr_gateway;
 			if (!(gw_nid == LNET_NID_ANY ||
 			      gw_nid == gateway->lp_nid))
@@ -576,8 +562,6 @@ int
 lnet_get_route(int idx, __u32 *net, __u32 *hops,
 	       lnet_nid_t *gateway, __u32 *alive, __u32 *priority)
 {
-	struct list_head *e1;
-	struct list_head *e2;
 	struct lnet_remotenet *rnet;
 	struct lnet_route *route;
 	int cpt;
@@ -588,13 +572,8 @@ lnet_get_route(int idx, __u32 *net, __u32 *hops,
 
 	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--) {
 					*net      = rnet->lrn_net;
 					*hops     = route->lr_hops;
@@ -784,7 +763,6 @@ static void
 lnet_wait_known_routerstate(void)
 {
 	struct lnet_peer *rtr;
-	struct list_head *entry;
 	int all_known;
 
 	LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
@@ -793,9 +771,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) {
 			if (!rtr->lp_alive_count) {
 				all_known = 0;
 				break;
@@ -1223,7 +1199,6 @@ static int
 lnet_router_checker(void *arg)
 {
 	struct lnet_peer *rtr;
-	struct list_head *entry;
 
 	while (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING) {
 		__u64 version;
@@ -1234,9 +1209,7 @@ lnet_router_checker(void *arg)

rescan:

		version = the_lnet.ln_routers_version;
drivers/staging/lustre/lnet/lnet/router.c +1 -3
-		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) {
			cpt2 = lnet_cpt_of_nid_locked(rtr->lp_nid);
			if (cpt != cpt2) {
				lnet_net_unlock(cpt);
drivers/staging/lustre/lnet/selftest/conrpc.c +2 -5
index 3afde0141db5..e73b956d15e4 100644
@@ -1327,7 +1327,6 @@ lstcon_rpc_cleanup_wait(void)
 {
 	struct lstcon_rpc_trans *trans;
 	struct lstcon_rpc *crpc;
-	struct list_head *pacer;
 	struct list_head zlist;
 
 	/* Called with hold of global mutex */
@@ -1335,10 +1334,8 @@ lstcon_rpc_cleanup_wait(void)
 	LASSERT(console_session.ses_shutdown);
 
 	while (!list_empty(&console_session.ses_trans_list)) {
-		list_for_each(pacer, &console_session.ses_trans_list) {
-			trans = list_entry(pacer, struct lstcon_rpc_trans,
-					   tas_link);
-
+		list_for_each_entry(trans, &console_session.ses_trans_list,
+				    tas_link) {
 			CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
 			       lstcon_rpc_trans_name(trans->tas_opc));
 
drivers/staging/lustre/lustre/obdclass/genops.c +1 -3
index 234f383ce6d9..8454b4470b8c 100644
@@ -84,12 +84,10 @@ static void obd_device_free(struct obd_device *obd)
 
 static struct obd_type *class_search_type(const char *name)
 {
-	struct list_head *tmp;
 	struct obd_type *type;
 
 	spin_lock(&obd_types_lock);
-	list_for_each(tmp, &obd_types) {
-		type = list_entry(tmp, struct obd_type, typ_chain);
+	list_for_each_entry(type, &obd_types, typ_chain) {
 		if (strcmp(type->typ_name, name) == 0) {
 			spin_unlock(&obd_types_lock);
 			return type;
drivers/staging/lustre/lustre/obdecho/echo_client.c +0 -0
index 484b8d6db6ef..3022706c6985 100644
@@ -950,12 +950,10 @@ static int cl_echo_cancel0(struct lu_env *env, struct echo_device *ed,
 {
 	struct echo_client_obd *ec = ed->ed_ec;
 	struct echo_lock       *ecl = NULL;

drivers/staging/lustre/lustre/obdecho/echo_client.c static int cl_echo_cancel0(struct lu_env *env, struct echo_device *ed, · line 959

Quoted 10 lines
drivers/staging/lustre/lustre/obdecho/echo_client.c +1 -3
-	struct list_head	     *el;
 	int found = 0, still_used = 0;
 
 	spin_lock(&ec->ec_lock);
-	list_for_each(el, &ec->ec_locks) {
-		ecl = list_entry(el, struct echo_lock, el_chain);
+	list_for_each_entry(ecl, &ec->ec_locks, el_chain) {
 		CDEBUG(D_INFO, "ecl: %p, cookie: %#llx\n", ecl, ecl->el_cookie);
 		found = (ecl->el_cookie == cookie);
 		if (found) {

Cheers, Andreas
---
Andreas Dilger
Principal Lustre Architect
Whamcloud

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 235 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20180730/e4f15c10/attachment-0001.sig>

#3 lore raw

PATCH 1/6 lustre: convert list_for_each() to list_for_each_entry().

In reply to NeilBrown
Quoted 7 lines · NeilBrown

Where we have
struct list_head *tmp;

  list_for_each(tmp,....) {
     foo = list_entry(tmp, ....);
     ...

}

Quoted 8 lines

convert to
list_for_each_entry(foo, .....) {
.....
}

This patch only changes instances which are straight forward, where neither the 'tmp' variable nor the 'foo' variable is not used outside the loop in any way that isn't trivially correct.

Quoted 777 lines
---
 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c    |   17 ++-----
 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c |   20 ++------
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |   51 +++++---------------
 .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c |   20 ++------
 drivers/staging/lustre/lnet/lnet/api-ni.c          |   29 ++---------
 drivers/staging/lustre/lnet/lnet/config.c          |   17 ++-----
 drivers/staging/lustre/lnet/lnet/lib-move.c        |    9 +---
 drivers/staging/lustre/lnet/lnet/router.c          |   47 ++++--------------
 drivers/staging/lustre/lnet/selftest/conrpc.c      |    7 +--
 drivers/staging/lustre/lustre/obdclass/genops.c    |    4 --
 .../staging/lustre/lustre/obdecho/echo_client.c    |    4 --
 11 files changed, 53 insertions(+), 172 deletions(-)
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +4 -13
index 830a5bf34c16..e15ad94151bd 100644
@@ -386,11 +386,9 @@ struct kib_peer *kiblnd_find_peer_locked(lnet_nid_t nid)
 	 * that this creates
 	 */
 	struct list_head *peer_list = kiblnd_nid2peerlist(nid);
-	struct list_head *tmp;
 	struct kib_peer *peer;
 
-	list_for_each(tmp, peer_list) {
-		peer = list_entry(tmp, struct kib_peer, ibp_list);
+	list_for_each_entry(peer, peer_list, ibp_list) {
 		LASSERT(!kiblnd_peer_idle(peer));
 
 		if (peer->ibp_nid != nid)
@@ -419,15 +417,13 @@ static int kiblnd_get_peer_info(struct lnet_ni *ni, int index,
 				lnet_nid_t *nidp, int *count)
 {
 	struct kib_peer *peer;
-	struct list_head *ptmp;
 	int i;
 	unsigned long flags;
 
 	read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
 
 	for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++) {
-		list_for_each(ptmp, &kiblnd_data.kib_peers[i]) {
-			peer = list_entry(ptmp, struct kib_peer, ibp_list);
+		list_for_each_entry(peer, &kiblnd_data.kib_peers[i], ibp_list) {
 			LASSERT(!kiblnd_peer_idle(peer));
 
 			if (peer->ibp_ni != ni)
@@ -526,28 +522,23 @@ static int kiblnd_del_peer(struct lnet_ni *ni, lnet_nid_t nid)
 static struct kib_conn *kiblnd_get_conn_by_idx(struct lnet_ni *ni, int index)
 {
 	struct kib_peer *peer;
-	struct list_head *ptmp;
 	struct kib_conn *conn;
-	struct list_head *ctmp;
 	int i;
 	unsigned long flags;
 
 	read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
 
 	for (i = 0; i < kiblnd_data.kib_peer_hash_size; i++) {
-		list_for_each(ptmp, &kiblnd_data.kib_peers[i]) {
-			peer = list_entry(ptmp, struct kib_peer, ibp_list);
+		list_for_each_entry(peer, &kiblnd_data.kib_peers[i], ibp_list) {
 			LASSERT(!kiblnd_peer_idle(peer));
 
 			if (peer->ibp_ni != ni)
 				continue;
 
-			list_for_each(ctmp, &peer->ibp_conns) {
+			list_for_each_entry(conn, &peer->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,
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c +5 -15
index bda67d49597d..2f7a64f2f13a 100644
@@ -225,11 +225,9 @@ kiblnd_post_rx(struct kib_rx *rx, int credit)
 static struct kib_tx *
 kiblnd_find_waiting_tx_locked(struct kib_conn *conn, int txtype, __u64 cookie)
 {
-	struct list_head *tmp;
-
-	list_for_each(tmp, &conn->ibc_active_txs) {
-		struct kib_tx *tx = list_entry(tmp, struct kib_tx, tx_list);
+	struct kib_tx *tx;
 
+	list_for_each_entry(tx, &conn->ibc_active_txs, tx_list) {
 		LASSERT(!tx->tx_queued);
 		LASSERT(tx->tx_sending || tx->tx_waiting);
 
@@ -3142,11 +3140,8 @@ static int
 kiblnd_check_txs_locked(struct kib_conn *conn, struct list_head *txs)
 {
 	struct kib_tx *tx;
-	struct list_head *ttmp;
-
-	list_for_each(ttmp, txs) {
-		tx = list_entry(ttmp, struct kib_tx, tx_list);
 
+	list_for_each_entry(tx, txs, tx_list) {
 		if (txs != &conn->ibc_active_txs) {
 			LASSERT(tx->tx_queued);
 		} else {
@@ -3182,10 +3177,8 @@ kiblnd_check_conns(int idx)
 	LIST_HEAD(closes);
 	LIST_HEAD(checksends);
 	struct list_head *peers = &kiblnd_data.kib_peers[idx];
-	struct list_head *ptmp;
 	struct kib_peer *peer;
 	struct kib_conn *conn;
-	struct list_head *ctmp;
 	unsigned long flags;
 
 	/*
@@ -3195,15 +3188,12 @@ kiblnd_check_conns(int idx)
 	 */
 	read_lock_irqsave(&kiblnd_data.kib_global_lock, flags);
 
-	list_for_each(ptmp, peers) {
-		peer = list_entry(ptmp, struct kib_peer, ibp_list);
+	list_for_each_entry(peer, peers, ibp_list) {
 
-		list_for_each(ctmp, &peer->ibp_conns) {
+		list_for_each_entry(conn, &peer->ibp_conns, ibc_list) {
 			int timedout;
 			int sendnoop;
 
-			conn = list_entry(ctmp, struct kib_conn, ibc_list);
-
 			LASSERT(conn->ibc_state == IBLND_CONN_ESTABLISHED);
 
 			spin_lock(&conn->ibc_lock);
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +13 -38
index a48b1b9a850b..491d2ed5b673 100644
@@ -250,9 +250,7 @@ ksocknal_get_peer_info(struct lnet_ni *ni, int index,
 		       int *port, int *conn_count, int *share_count)
 {
 	struct ksock_peer *peer;
-	struct list_head *ptmp;
 	struct ksock_route *route;
-	struct list_head *rtmp;
 	int i;
 	int j;
 	int rc = -ENOENT;
@@ -260,8 +258,7 @@ ksocknal_get_peer_info(struct lnet_ni *ni, int index,
 	read_lock(&ksocknal_data.ksnd_global_lock);
 
 	for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
-		list_for_each(ptmp, &ksocknal_data.ksnd_peers[i]) {
-			peer = list_entry(ptmp, struct ksock_peer, ksnp_list);
+		list_for_each_entry(peer, &ksocknal_data.ksnd_peers[i], ksnp_list) {
 
 			if (peer->ksnp_ni != ni)
 				continue;
@@ -295,13 +292,11 @@ ksocknal_get_peer_info(struct lnet_ni *ni, int index,
 				goto out;
 			}
 
-			list_for_each(rtmp, &peer->ksnp_routes) {
+			list_for_each_entry(route, &peer->ksnp_routes,
+					    ksnr_list) {
 				if (index-- > 0)
 					continue;
 
-				route = list_entry(rtmp, struct ksock_route,
-						   ksnr_list);
-
 				*id = peer->ksnp_id;
 				*myip = route->ksnr_myipaddr;
 				*peer_ip = route->ksnr_ipaddr;
@@ -368,7 +363,6 @@ ksocknal_associate_route_conn_locked(struct ksock_route *route,
 static void
 ksocknal_add_route_locked(struct ksock_peer *peer, struct ksock_route *route)
 {
-	struct list_head *tmp;
 	struct ksock_conn *conn;
 	struct ksock_route *route2;
 
@@ -379,9 +373,7 @@ ksocknal_add_route_locked(struct ksock_peer *peer, struct ksock_route *route)
 	LASSERT(!route->ksnr_connected);
 
 	/* LASSERT(unique) */
-	list_for_each(tmp, &peer->ksnp_routes) {
-		route2 = list_entry(tmp, struct ksock_route, ksnr_list);
-
+	list_for_each_entry(route2, &peer->ksnp_routes, ksnr_list) {
 		if (route2->ksnr_ipaddr == route->ksnr_ipaddr) {
 			CERROR("Duplicate route %s %pI4h\n",
 			       libcfs_id2str(peer->ksnp_id),
@@ -395,9 +387,7 @@ ksocknal_add_route_locked(struct ksock_peer *peer, struct ksock_route *route)
 	/* peer's routelist takes over my ref on 'route' */
 	list_add_tail(&route->ksnr_list, &peer->ksnp_routes);
 
-	list_for_each(tmp, &peer->ksnp_conns) {
-		conn = list_entry(tmp, struct ksock_conn, ksnc_list);
-
+	list_for_each_entry(conn, &peer->ksnp_conns, ksnc_list) {
 		if (conn->ksnc_ipaddr != route->ksnr_ipaddr)
 			continue;
 
@@ -624,28 +614,22 @@ static struct ksock_conn *
 ksocknal_get_conn_by_idx(struct lnet_ni *ni, int index)
 {
 	struct ksock_peer *peer;
-	struct list_head *ptmp;
 	struct ksock_conn *conn;
-	struct list_head *ctmp;
 	int i;
 
 	read_lock(&ksocknal_data.ksnd_global_lock);
 
 	for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
-		list_for_each(ptmp, &ksocknal_data.ksnd_peers[i]) {
-			peer = list_entry(ptmp, struct ksock_peer, ksnp_list);
-
+		list_for_each_entry(peer, &ksocknal_data.ksnd_peers[i], ksnp_list) {
 			LASSERT(!peer->ksnp_closing);
 
 			if (peer->ksnp_ni != ni)
 				continue;
 
-			list_for_each(ctmp, &peer->ksnp_conns) {
+			list_for_each_entry(conn, &peer->ksnp_conns, ksnc_list) {
 				if (index-- > 0)
 					continue;
 
-				conn = list_entry(ctmp, struct ksock_conn,
-						  ksnc_list);
 				ksocknal_conn_addref(conn);
 				read_unlock(&ksocknal_data.ksnd_global_lock);
 				return conn;
@@ -1025,7 +1009,6 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route,
 	rwlock_t *global_lock = &ksocknal_data.ksnd_global_lock;
 	LIST_HEAD(zombies);
 	struct lnet_process_id peerid;
-	struct list_head *tmp;
 	__u64 incarnation;
 	struct ksock_conn *conn;
 	struct ksock_conn *conn2;
@@ -1226,8 +1209,7 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route,
 	 * loopback connection
 	 */
 	if (conn->ksnc_ipaddr != conn->ksnc_myipaddr) {
-		list_for_each(tmp, &peer->ksnp_conns) {
-			conn2 = list_entry(tmp, struct ksock_conn, ksnc_list);
+		list_for_each_entry(conn2, &peer->ksnp_conns, ksnc_list) {
 
 			if (conn2->ksnc_ipaddr != conn->ksnc_ipaddr ||
 			    conn2->ksnc_myipaddr != conn->ksnc_myipaddr ||
@@ -1266,9 +1248,7 @@ ksocknal_create_conn(struct lnet_ni *ni, struct ksock_route *route,
 	 * by routes in my peer to match my own route entries so I don't
 	 * continually create duplicate routes.
 	 */
-	list_for_each(tmp, &peer->ksnp_routes) {
-		route = list_entry(tmp, struct ksock_route, ksnr_list);
-
+	list_for_each_entry(route, &peer->ksnp_routes, ksnr_list) {
 		if (route->ksnr_ipaddr != conn->ksnc_ipaddr)
 			continue;
 
@@ -1980,9 +1960,7 @@ ksocknal_add_interface(struct lnet_ni *ni, __u32 ipaddress, __u32 netmask)
 	int rc;
 	int i;
 	int j;
-	struct list_head *ptmp;
 	struct ksock_peer *peer;
-	struct list_head *rtmp;
 	struct ksock_route *route;
 
 	if (!ipaddress || !netmask)
@@ -2005,18 +1983,15 @@ ksocknal_add_interface(struct lnet_ni *ni, __u32 ipaddress, __u32 netmask)
 		iface->ksni_npeers = 0;
 
 		for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
-			list_for_each(ptmp, &ksocknal_data.ksnd_peers[i]) {
-				peer = list_entry(ptmp, struct ksock_peer,
-						  ksnp_list);
+			list_for_each_entry(peer, &ksocknal_data.ksnd_peers[i],
+					    ksnp_list) {
 
 				for (j = 0; j < peer->ksnp_n_passive_ips; j++)
 					if (peer->ksnp_passive_ips[j] == ipaddress)
 						iface->ksni_npeers++;
 
-				list_for_each(rtmp, &peer->ksnp_routes) {
-					route = list_entry(rtmp, struct ksock_route,
-							   ksnr_list);
-
+				list_for_each_entry(route, &peer->ksnp_routes,
+						    ksnr_list) {
 					if (route->ksnr_myipaddr == ipaddress)
 						iface->ksni_nroutes++;
 				}
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c +5 -15
index d531847305e4..a5c0e8a9bc40 100644
@@ -561,18 +561,16 @@ struct ksock_conn *
 ksocknal_find_conn_locked(struct ksock_peer *peer, struct ksock_tx *tx,
 			  int nonblk)
 {
-	struct list_head *tmp;
+	struct ksock_conn *c;
 	struct ksock_conn *conn;
 	struct ksock_conn *typed = NULL;
 	struct ksock_conn *fallback = NULL;
 	int tnob = 0;
 	int fnob = 0;
 
-	list_for_each(tmp, &peer->ksnp_conns) {
-		struct ksock_conn *c;
+	list_for_each_entry(c, &peer->ksnp_conns, ksnc_list) {
 		int nob, rc;
 
-		c = list_entry(tmp, struct ksock_conn, ksnc_list);
 		nob = atomic_read(&c->ksnc_tx_nob) +
 		      c->ksnc_sock->sk->sk_wmem_queued;
 
@@ -729,12 +727,9 @@ struct ksock_route *
 ksocknal_find_connectable_route_locked(struct ksock_peer *peer)
 {
 	time64_t now = ktime_get_seconds();
-	struct list_head *tmp;
 	struct ksock_route *route;
 
-	list_for_each(tmp, &peer->ksnp_routes) {
-		route = list_entry(tmp, struct ksock_route, ksnr_list);
-
+	list_for_each_entry(route, &peer->ksnp_routes, ksnr_list) {
 		LASSERT(!route->ksnr_connecting || route->ksnr_scheduled);
 
 		/* connections being established */
@@ -765,11 +760,9 @@ ksocknal_find_connectable_route_locked(struct ksock_peer *peer)
 struct ksock_route *
 ksocknal_find_connecting_route_locked(struct ksock_peer *peer)
 {
-	struct list_head *tmp;
 	struct ksock_route *route;
 
-	list_for_each(tmp, &peer->ksnp_routes) {
-		route = list_entry(tmp, struct ksock_route, ksnr_list);
+	list_for_each_entry(route, &peer->ksnp_routes, ksnr_list) {
 
 		LASSERT(!route->ksnr_connecting || route->ksnr_scheduled);
 
@@ -2180,13 +2173,10 @@ ksocknal_find_timed_out_conn(struct ksock_peer *peer)
 {
 	/* We're called with a shared lock on ksnd_global_lock */
 	struct ksock_conn *conn;
-	struct list_head *ctmp;
 
-	list_for_each(ctmp, &peer->ksnp_conns) {
+	list_for_each_entry(conn, &peer->ksnp_conns, ksnc_list) {
 		int error;
 
-		conn = list_entry(ctmp, struct ksock_conn, ksnc_list);
-
 		/* Don't need the {get,put}connsock dance to deref ksnc_sock */
 		LASSERT(!conn->ksnc_closing);
 
drivers/staging/lustre/lnet/lnet/api-ni.c +6 -23
index 51a81075f8d5..14b797802a85 100644
@@ -269,12 +269,9 @@ static struct lnet_lnd *
 lnet_find_lnd_by_type(__u32 type)
 {
 	struct lnet_lnd *lnd;
-	struct list_head *tmp;
 
 	/* holding lnd mutex */
-	list_for_each(tmp, &the_lnet.ln_lnds) {
-		lnd = list_entry(tmp, struct lnet_lnd, lnd_list);
-
+	list_for_each_entry(lnd, &the_lnet.ln_lnds, lnd_list) {
 		if (lnd->lnd_type == type)
 			return lnd;
 	}
@@ -653,14 +650,11 @@ lnet_unprepare(void)
 struct lnet_ni  *
 lnet_net2ni_locked(__u32 net, int cpt)
 {
-	struct list_head *tmp;
 	struct lnet_ni *ni;
 
 	LASSERT(cpt != LNET_LOCK_EX);
 
-	list_for_each(tmp, &the_lnet.ln_nis) {
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (LNET_NIDNET(ni->ni_nid) == net) {
 			lnet_ni_addref_locked(ni, cpt);
 			return ni;
@@ -767,13 +761,10 @@ struct lnet_ni  *
 lnet_nid2ni_locked(lnet_nid_t nid, int cpt)
 {
 	struct lnet_ni *ni;
-	struct list_head *tmp;
 
 	LASSERT(cpt != LNET_LOCK_EX);
 
-	list_for_each(tmp, &the_lnet.ln_nis) {
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (ni->ni_nid == nid) {
 			lnet_ni_addref_locked(ni, cpt);
 			return ni;
@@ -803,14 +794,11 @@ lnet_count_acceptor_nis(void)
 {
 	/* Return the # of NIs that need the acceptor. */
 	int count = 0;
-	struct list_head *tmp;
 	struct lnet_ni *ni;
 	int cpt;
 
 	cpt = lnet_net_lock_current();
-	list_for_each(tmp, &the_lnet.ln_nis) {
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (ni->ni_lnd->lnd_accept)
 			count++;
 	}
@@ -1731,18 +1719,16 @@ static int
 lnet_get_net_config(struct lnet_ioctl_config_data *config)
 {
 	struct lnet_ni *ni;
-	struct list_head *tmp;
 	int idx = config->cfg_count;
 	int cpt, i = 0;
 	int rc = -ENOENT;
 
 	cpt = lnet_net_lock_current();
 
-	list_for_each(tmp, &the_lnet.ln_nis) {
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (i++ != idx)
 			continue;
 
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
 		lnet_ni_lock(ni);
 		lnet_fill_ni_info(ni, config);
 		lnet_ni_unlock(ni);
@@ -2119,7 +2105,6 @@ int
 LNetGetId(unsigned int index, struct lnet_process_id *id)
 {
 	struct lnet_ni *ni;
-	struct list_head *tmp;
 	int cpt;
 	int rc = -ENOENT;
 
@@ -2127,12 +2112,10 @@ LNetGetId(unsigned int index, struct lnet_process_id *id)
 
 	cpt = lnet_net_lock_current();
 
-	list_for_each(tmp, &the_lnet.ln_nis) {
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (index--)
 			continue;
 
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
 		id->nid = ni->ni_nid;
 		id->pid = the_lnet.ln_pid;
 		rc = 0;
drivers/staging/lustre/lnet/lnet/config.c +4 -13
index 26b799e66e53..96336ecdacaf 100644
@@ -81,12 +81,9 @@ lnet_issep(char c)
 int
 lnet_net_unique(__u32 net, struct list_head *nilist)
 {
-	struct list_head *tmp;
 	struct lnet_ni *ni;
 
-	list_for_each(tmp, nilist) {
-		ni = list_entry(tmp, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, nilist, ni_list) {
 		if (LNET_NIDNET(ni->ni_nid) == net)
 			return 0;
 	}
@@ -942,7 +939,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;
@@ -983,9 +979,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;
 
@@ -1074,14 +1068,11 @@ lnet_match_networks(char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
 			break;
 
 		dup = 0;
-		list_for_each(t, &current_nets) {
-			tb = list_entry(t, struct lnet_text_buf, ltb_list);
+		list_for_each_entry(tb, &current_nets, ltb_list) {
 			net1 = lnet_netspec2net(tb->ltb_text);
 			LASSERT(net1 != LNET_NIDNET(LNET_NID_ANY));
 
-			list_for_each(t2, &matched_nets) {
-				tb2 = list_entry(t2, struct lnet_text_buf,
-						 ltb_list);
+			list_for_each_entry(tb2, &matched_nets, ltb_list) {
 				net2 = lnet_netspec2net(tb2->ltb_text);
 				LASSERT(net2 != LNET_NIDNET(LNET_NID_ANY));
 
drivers/staging/lustre/lnet/lnet/lib-move.c +2 -7
index 19cab374b6bc..edcafac055ed 100644
@@ -2288,7 +2288,6 @@ EXPORT_SYMBOL(LNetGet);
 int
 LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
 {
-	struct list_head *e;
 	struct lnet_ni *ni;
 	struct lnet_remotenet *rnet;
 	__u32 dstnet = LNET_NIDNET(dstnid);
@@ -2307,9 +2306,7 @@ LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
 
 	cpt = lnet_net_lock_current();
 
-	list_for_each(e, &the_lnet.ln_nis) {
-		ni = list_entry(e, struct lnet_ni, ni_list);
-
+	list_for_each_entry(ni, &the_lnet.ln_nis, ni_list) {
 		if (ni->ni_nid == dstnid) {
 			if (srcnidp)
 				*srcnidp = dstnid;
@@ -2346,9 +2343,7 @@ LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __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;
drivers/staging/lustre/lnet/lnet/router.c +10 -37
index 965087b7359c..53373372b526 100644
@@ -292,10 +292,10 @@ int
 lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
 	       unsigned int priority)
 {
-	struct list_head *e;
 	struct lnet_remotenet *rnet;
 	struct lnet_remotenet *rnet2;
 	struct lnet_route *route;
+	struct lnet_route *route2;
 	struct lnet_ni *ni;
 	int add_route;
 	int rc;
@@ -359,10 +359,8 @@ lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
 
 	/* Search for a duplicate route (it's a NOOP if it is) */
 	add_route = 1;
-	list_for_each(e, &rnet2->lrn_routes) {
-		struct lnet_route *route2;
+	list_for_each_entry(route2, &rnet2->lrn_routes, lr_list) {
 
-		route2 = list_entry(e, struct lnet_route, lr_list);
 		if (route2->lr_gateway == route->lr_gateway) {
 			add_route = 0;
 			break;
@@ -411,8 +409,6 @@ lnet_check_routes(void)
 	struct lnet_remotenet *rnet;
 	struct lnet_route *route;
 	struct lnet_route *route2;
-	struct list_head *e1;
-	struct list_head *e2;
 	int cpt;
 	struct list_head *rn_list;
 	int i;
@@ -421,17 +417,13 @@ lnet_check_routes(void)
 
 	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_entry(rnet, rn_list, lrn_list) {
 			route2 = NULL;
-			list_for_each(e2, &rnet->lrn_routes) {
+			list_for_each_entry(route, &rnet->lrn_routes, lr_list) {
 				lnet_nid_t nid1;
 				lnet_nid_t nid2;
 				int net;
 
-				route = list_entry(e2, struct lnet_route, lr_list);
-
 				if (!route2) {
 					route2 = route;
 					continue;
@@ -466,8 +458,6 @@ lnet_del_route(__u32 net, lnet_nid_t gw_nid)
 	struct lnet_peer *gateway;
 	struct lnet_remotenet *rnet;
 	struct lnet_route *route;
-	struct list_head *e1;
-	struct list_head *e2;
 	int rc = -ENOENT;
 	struct list_head *rn_list;
 	int idx = 0;
@@ -486,16 +476,12 @@ lnet_del_route(__u32 net, lnet_nid_t gw_nid)
 		rn_list = lnet_net2rnethash(net);
 
  again:
-	list_for_each(e1, rn_list) {
-		rnet = list_entry(e1, struct lnet_remotenet, lrn_list);
-
+	list_for_each_entry(rnet, rn_list, lrn_list) {
 		if (!(net == LNET_NIDNET(LNET_NID_ANY) ||
 		      net == rnet->lrn_net))
 			continue;
 
-		list_for_each(e2, &rnet->lrn_routes) {
-			route = list_entry(e2, struct lnet_route, lr_list);
-
+		list_for_each_entry(route, &rnet->lrn_routes, lr_list) {
 			gateway = route->lr_gateway;
 			if (!(gw_nid == LNET_NID_ANY ||
 			      gw_nid == gateway->lp_nid))
@@ -576,8 +562,6 @@ int
 lnet_get_route(int idx, __u32 *net, __u32 *hops,
 	       lnet_nid_t *gateway, __u32 *alive, __u32 *priority)
 {
-	struct list_head *e1;
-	struct list_head *e2;
 	struct lnet_remotenet *rnet;
 	struct lnet_route *route;
 	int cpt;
@@ -588,13 +572,8 @@ lnet_get_route(int idx, __u32 *net, __u32 *hops,
 
 	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--) {
 					*net      = rnet->lrn_net;
 					*hops     = route->lr_hops;
@@ -784,7 +763,6 @@ static void
 lnet_wait_known_routerstate(void)
 {
 	struct lnet_peer *rtr;
-	struct list_head *entry;
 	int all_known;
 
 	LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
@@ -793,9 +771,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) {
 			if (!rtr->lp_alive_count) {
 				all_known = 0;
 				break;
@@ -1223,7 +1199,6 @@ static int
 lnet_router_checker(void *arg)
 {
 	struct lnet_peer *rtr;
-	struct list_head *entry;
 
 	while (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING) {
 		__u64 version;
@@ -1234,9 +1209,7 @@ lnet_router_checker(void *arg)
 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) {
 			cpt2 = lnet_cpt_of_nid_locked(rtr->lp_nid);
 			if (cpt != cpt2) {
 				lnet_net_unlock(cpt);
drivers/staging/lustre/lnet/selftest/conrpc.c +2 -5
index 3afde0141db5..e73b956d15e4 100644
@@ -1327,7 +1327,6 @@ lstcon_rpc_cleanup_wait(void)
 {
 	struct lstcon_rpc_trans *trans;
 	struct lstcon_rpc *crpc;
-	struct list_head *pacer;
 	struct list_head zlist;
 
 	/* Called with hold of global mutex */
@@ -1335,10 +1334,8 @@ lstcon_rpc_cleanup_wait(void)
 	LASSERT(console_session.ses_shutdown);
 
 	while (!list_empty(&console_session.ses_trans_list)) {
-		list_for_each(pacer, &console_session.ses_trans_list) {
-			trans = list_entry(pacer, struct lstcon_rpc_trans,
-					   tas_link);
-
+		list_for_each_entry(trans, &console_session.ses_trans_list,
+				    tas_link) {
 			CDEBUG(D_NET, "Session closed, wakeup transaction %s\n",
 			       lstcon_rpc_trans_name(trans->tas_opc));
 
drivers/staging/lustre/lustre/obdclass/genops.c +1 -3
index 234f383ce6d9..8454b4470b8c 100644
@@ -84,12 +84,10 @@ static void obd_device_free(struct obd_device *obd)
 
 static struct obd_type *class_search_type(const char *name)
 {
-	struct list_head *tmp;
 	struct obd_type *type;
 
 	spin_lock(&obd_types_lock);
-	list_for_each(tmp, &obd_types) {
-		type = list_entry(tmp, struct obd_type, typ_chain);
+	list_for_each_entry(type, &obd_types, typ_chain) {
 		if (strcmp(type->typ_name, name) == 0) {
 			spin_unlock(&obd_types_lock);
 			return type;
drivers/staging/lustre/lustre/obdecho/echo_client.c +1 -3
index 484b8d6db6ef..3022706c6985 100644
@@ -950,12 +950,10 @@ static int cl_echo_cancel0(struct lu_env *env, struct echo_device *ed,
 {
 	struct echo_client_obd *ec = ed->ed_ec;
 	struct echo_lock       *ecl = NULL;
-	struct list_head	     *el;
 	int found = 0, still_used = 0;
 
 	spin_lock(&ec->ec_lock);
-	list_for_each(el, &ec->ec_locks) {
-		ecl = list_entry(el, struct echo_lock, el_chain);
+	list_for_each_entry(ecl, &ec->ec_locks, el_chain) {
 		CDEBUG(D_INFO, "ecl: %p, cookie: %#llx\n", ecl, ecl->el_cookie);
 		found = (ecl->el_cookie == cookie);
 		if (found) {
author
#4 lore raw

PATCH 2/6 lustre: lnet/config: convert list_for_each to list_for_each_entry

In reply to NeilBrown

This conversion to list_for_each_entry isn't quite trivial as the 'tmp' loop variables are used elsewhere in the function. This means we cannot just delete them, and so must inspect the code to ensure the values aren't used elsewhere - they aren't.

Also we need to introduce new loop variables: ltb1 and ltb2 as the lnet_text_buf was the some for both the original (nested) loops.

---
 drivers/staging/lustre/lnet/lnet/config.c |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/staging/lustre/lnet/lnet/config.c +5 -6
index 96336ecdacaf..091c4f714e84 100644
@@ -662,6 +662,7 @@ lnet_parse_route(char *str, int *im_a_router)
 	__u32 net;
 	lnet_nid_t nid;
 	struct lnet_text_buf *ltb;
+	struct lnet_text_buf *ltb1, *ltb2;
 	int rc;
 	char *sep;
 	char *token = str;
@@ -760,14 +761,12 @@ 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_NIDNET(LNET_NID_ANY));
 
-		list_for_each(tmp2, &gateways) {
-			ltb = list_entry(tmp2, struct lnet_text_buf, ltb_list);
-			nid = libcfs_str2nid(ltb->ltb_text);
+		list_for_each_entry(ltb2, &gateways, ltb_list) {
+			nid = libcfs_str2nid(ltb2->ltb_text);
 			LASSERT(nid != LNET_NID_ANY);
 
 			if (lnet_islocalnid(nid)) {
#5 lore raw

PATCH 2/6 lustre: lnet/config: convert list_for_each to list_for_each_entry

Quoted 9 lines · NeilBrown

This conversion to list_for_each_entry isn't quite trivial as the 'tmp' loop variables are used elsewhere in the function. This means we cannot just delete them, and so must inspect the code to ensure the values aren't used elsewhere - they aren't.

Quoted 4 lines

Also we need to introduce new loop variables: ltb1 and ltb2 as the lnet_text_buf was the some for both the original (nested) loops.

Quoted 27 lines

---
drivers/staging/lustre/lnet/lnet/config.c | 11 +++++------

1 file changed, 5 insertions(+), 6 deletions(-)
drivers/staging/lustre/lnet/lnet/config.c +3 -3
index 96336ecdacaf..091c4f714e84 100644
@@ -662,6 +662,7 @@ lnet_parse_route(char *str, int *im_a_router)
 	__u32 net;
 	lnet_nid_t nid;
 	struct lnet_text_buf *ltb;
+	struct lnet_text_buf *ltb1, *ltb2;
 	int rc;
 	char *sep;
 	char *token = str;
@@ -760,14 +761,12 @@ 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);

drivers/staging/lustre/lnet/lnet/config.c lnet_parse_route(char *str, int *im_a_router) · line 772

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/config.c +2 -3
 		LASSERT(net != LNET_NIDNET(LNET_NID_ANY));
 
-		list_for_each(tmp2, &gateways) {
-			ltb = list_entry(tmp2, struct lnet_text_buf, ltb_list);
-			nid = libcfs_str2nid(ltb->ltb_text);
+		list_for_each_entry(ltb2, &gateways, ltb_list) {
+			nid = libcfs_str2nid(ltb2->ltb_text);
 			LASSERT(nid != LNET_NID_ANY);
 
 			if (lnet_islocalnid(nid)) {

Cheers, Andreas
---
Andreas Dilger
Principal Lustre Architect
Whamcloud

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 235 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20180730/db409863/attachment.sig>

#6 lore raw

PATCH 2/6 lustre: lnet/config: convert list_for_each to list_for_each_entry

In reply to NeilBrown
Quoted 8 lines

This conversion to list_for_each_entry isn't quite trivial as the 'tmp' loop variables are used elsewhere in the function. This means we cannot just delete them, and so must inspect the code to ensure the values aren't used elsewhere - they aren't.

Also we need to introduce new loop variables: ltb1 and ltb2 as the lnet_text_buf was the some for both the original (nested) loops.

Quoted 39 lines
---
 drivers/staging/lustre/lnet/lnet/config.c |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)
drivers/staging/lustre/lnet/lnet/config.c +5 -6
index 96336ecdacaf..091c4f714e84 100644
@@ -662,6 +662,7 @@ lnet_parse_route(char *str, int *im_a_router)
 	__u32 net;
 	lnet_nid_t nid;
 	struct lnet_text_buf *ltb;
+	struct lnet_text_buf *ltb1, *ltb2;
 	int rc;
 	char *sep;
 	char *token = str;
@@ -760,14 +761,12 @@ 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_NIDNET(LNET_NID_ANY));
 
-		list_for_each(tmp2, &gateways) {
-			ltb = list_entry(tmp2, struct lnet_text_buf, ltb_list);
-			nid = libcfs_str2nid(ltb->ltb_text);
+		list_for_each_entry(ltb2, &gateways, ltb_list) {
+			nid = libcfs_str2nid(ltb2->ltb_text);
 			LASSERT(nid != LNET_NID_ANY);
 
 			if (lnet_islocalnid(nid)) {
author
#7 lore raw

PATCH 3/6 lustre: convert list_for_each in ksocknal_create_routes

In reply to NeilBrown

The two list_for_each() loops in ksocknal_create_routes() cannot be trivially converted to list_for_each_entry() as the new loop variable is expected to be NULL after the loop, if the loop completed normally.

If the loop did not complete normally - if an interesting entry was found - a 'continue' is required in the higher level loop. Change this 'continue' to a 'goto' so it can be called in the inner loop, and we don't need to check for a variable being NULL.

---
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |   29 +++++---------------
 1 file changed, 7 insertions(+), 22 deletions(-)
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +7 -22
index 491d2ed5b673..f495e0faeac4 100644
@@ -846,7 +846,6 @@ ksocknal_create_routes(struct ksock_peer *peer, int port,
 	rwlock_t *global_lock = &ksocknal_data.ksnd_global_lock;
 	struct lnet_ni *ni = peer->ksnp_ni;
 	struct ksock_net *net = ni->ni_data;
-	struct list_head *rtmp;
 	struct ksock_route *route;
 	struct ksock_interface *iface;
 	struct ksock_interface *best_iface;
@@ -894,17 +893,9 @@ ksocknal_create_routes(struct ksock_peer *peer, int port,
 		}
 
 		/* Already got a route? */
-		route = NULL;
-		list_for_each(rtmp, &peer->ksnp_routes) {
-			route = list_entry(rtmp, struct ksock_route, ksnr_list);
-
-			if (route->ksnr_ipaddr == newroute->ksnr_ipaddr)
-				break;
-
-			route = NULL;
-		}
-		if (route)
-			continue;
+		list_for_each_entry(route, &peer->ksnp_routes, ksnr_list)
+			if (route->ksnr_ipaddr != newroute->ksnr_ipaddr)
+				goto next_ipaddr;
 
 		best_iface = NULL;
 		best_nroutes = 0;
@@ -917,17 +908,9 @@ ksocknal_create_routes(struct ksock_peer *peer, int port,
 			iface = &net->ksnn_interfaces[j];
 
 			/* Using this interface already? */
-			list_for_each(rtmp, &peer->ksnp_routes) {
-				route = list_entry(rtmp, struct ksock_route,
-						   ksnr_list);
-
+			list_for_each_entry(route, &peer->ksnp_routes, ksnr_list)
 				if (route->ksnr_myipaddr == iface->ksni_ipaddr)
-					break;
-
-				route = NULL;
-			}
-			if (route)
-				continue;
+					goto next_iface;
 
 			this_netmatch = (!((iface->ksni_ipaddr ^
 					   newroute->ksnr_ipaddr) &
@@ -942,6 +925,7 @@ ksocknal_create_routes(struct ksock_peer *peer, int port,
 			best_iface = iface;
 			best_netmatch = this_netmatch;
 			best_nroutes = iface->ksni_nroutes;
+		next_iface:;
 		}
 
 		if (!best_iface)
@@ -952,6 +936,7 @@ ksocknal_create_routes(struct ksock_peer *peer, int port,
 
 		ksocknal_add_route_locked(peer, newroute);
 		newroute = NULL;
+	next_ipaddr:;
 	}
 
 	write_unlock_bh(global_lock);
#8 lore raw

PATCH 3/6 lustre: convert list_for_each in ksocknal_create_routes

Quoted 9 lines

The two list_for_each() loops in ksocknal_create_routes() cannot be trivially converted to list_for_each_entry() as the new loop variable is expected to be NULL after the loop, if the loop completed normally.

If the loop did not complete normally - if an interesting entry was found - a 'continue' is required in the higher level loop. Change this 'continue' to a 'goto' so it can be called in the inner loop, and we don't need to check for a variable being NULL.

Quoted 77 lines
---
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |   29 +++++---------------
 1 file changed, 7 insertions(+), 22 deletions(-)
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +7 -22
index 491d2ed5b673..f495e0faeac4 100644
@@ -846,7 +846,6 @@ ksocknal_create_routes(struct ksock_peer *peer, int port,
 	rwlock_t *global_lock = &ksocknal_data.ksnd_global_lock;
 	struct lnet_ni *ni = peer->ksnp_ni;
 	struct ksock_net *net = ni->ni_data;
-	struct list_head *rtmp;
 	struct ksock_route *route;
 	struct ksock_interface *iface;
 	struct ksock_interface *best_iface;
@@ -894,17 +893,9 @@ ksocknal_create_routes(struct ksock_peer *peer, int port,
 		}
 
 		/* Already got a route? */
-		route = NULL;
-		list_for_each(rtmp, &peer->ksnp_routes) {
-			route = list_entry(rtmp, struct ksock_route, ksnr_list);
-
-			if (route->ksnr_ipaddr == newroute->ksnr_ipaddr)
-				break;
-
-			route = NULL;
-		}
-		if (route)
-			continue;
+		list_for_each_entry(route, &peer->ksnp_routes, ksnr_list)
+			if (route->ksnr_ipaddr != newroute->ksnr_ipaddr)
+				goto next_ipaddr;
 
 		best_iface = NULL;
 		best_nroutes = 0;
@@ -917,17 +908,9 @@ ksocknal_create_routes(struct ksock_peer *peer, int port,
 			iface = &net->ksnn_interfaces[j];
 
 			/* Using this interface already? */
-			list_for_each(rtmp, &peer->ksnp_routes) {
-				route = list_entry(rtmp, struct ksock_route,
-						   ksnr_list);
-
+			list_for_each_entry(route, &peer->ksnp_routes, ksnr_list)
 				if (route->ksnr_myipaddr == iface->ksni_ipaddr)
-					break;
-
-				route = NULL;
-			}
-			if (route)
-				continue;
+					goto next_iface;
 
 			this_netmatch = (!((iface->ksni_ipaddr ^
 					   newroute->ksnr_ipaddr) &
@@ -942,6 +925,7 @@ ksocknal_create_routes(struct ksock_peer *peer, int port,
 			best_iface = iface;
 			best_netmatch = this_netmatch;
 			best_nroutes = iface->ksni_nroutes;
+		next_iface:;
 		}
 
 		if (!best_iface)
@@ -952,6 +936,7 @@ ksocknal_create_routes(struct ksock_peer *peer, int port,
 
 		ksocknal_add_route_locked(peer, newroute);
 		newroute = NULL;
+	next_ipaddr:;
 	}
 
 	write_unlock_bh(global_lock);
author
#9 lore raw

PATCH 4/6 lustre: convert list_for_each in ksocknal_close_conn_locked()

In reply to NeilBrown

The use of list_for_each in ksocknal_close_conn_locked() cannot be trivially converted to list_for_each_entry() as the new loop variable has NULL tests outside the loop.

Change these to use a goto inside the loop.

---
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |   15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +4 -11
index f495e0faeac4..ea95bff79996 100644
@@ -1402,7 +1402,6 @@ ksocknal_close_conn_locked(struct ksock_conn *conn, int error)
 	struct ksock_peer *peer = conn->ksnc_peer;
 	struct ksock_route *route;
 	struct ksock_conn *conn2;
-	struct list_head *tmp;
 
 	LASSERT(!peer->ksnp_error);
 	LASSERT(!conn->ksnc_closing);
@@ -1417,19 +1416,13 @@ ksocknal_close_conn_locked(struct ksock_conn *conn, int error)
 		LASSERT(!route->ksnr_deleted);
 		LASSERT(route->ksnr_connected & (1 << conn->ksnc_type));
 
-		conn2 = NULL;
-		list_for_each(tmp, &peer->ksnp_conns) {
-			conn2 = list_entry(tmp, struct ksock_conn, ksnc_list);
-
+		list_for_each_entry(conn2, &peer->ksnp_conns, ksnc_list) {
 			if (conn2->ksnc_route == route &&
 			    conn2->ksnc_type == conn->ksnc_type)
-				break;
-
-			conn2 = NULL;
+				goto conn2_found;
 		}
-		if (!conn2)
-			route->ksnr_connected &= ~(1 << conn->ksnc_type);
-
+		route->ksnr_connected &= ~(1 << conn->ksnc_type);
+	conn2_found:
 		conn->ksnc_route = NULL;
 
 		ksocknal_route_decref(route);     /* drop conn's ref on route */
#10 lore raw

PATCH 4/6 lustre: convert list_for_each in ksocknal_close_conn_locked()

Quoted 6 lines

The use of list_for_each in ksocknal_close_conn_locked() cannot be trivially converted to list_for_each_entry() as the new loop variable has NULL tests outside the loop.

Change these to use a goto inside the loop.

Quoted 44 lines
---
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |   15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +4 -11
index f495e0faeac4..ea95bff79996 100644
@@ -1402,7 +1402,6 @@ ksocknal_close_conn_locked(struct ksock_conn *conn, int error)
 	struct ksock_peer *peer = conn->ksnc_peer;
 	struct ksock_route *route;
 	struct ksock_conn *conn2;
-	struct list_head *tmp;
 
 	LASSERT(!peer->ksnp_error);
 	LASSERT(!conn->ksnc_closing);
@@ -1417,19 +1416,13 @@ ksocknal_close_conn_locked(struct ksock_conn *conn, int error)
 		LASSERT(!route->ksnr_deleted);
 		LASSERT(route->ksnr_connected & (1 << conn->ksnc_type));
 
-		conn2 = NULL;
-		list_for_each(tmp, &peer->ksnp_conns) {
-			conn2 = list_entry(tmp, struct ksock_conn, ksnc_list);
-
+		list_for_each_entry(conn2, &peer->ksnp_conns, ksnc_list) {
 			if (conn2->ksnc_route == route &&
 			    conn2->ksnc_type == conn->ksnc_type)
-				break;
-
-			conn2 = NULL;
+				goto conn2_found;
 		}
-		if (!conn2)
-			route->ksnr_connected &= ~(1 << conn->ksnc_type);
-
+		route->ksnr_connected &= ~(1 << conn->ksnc_type);
+	conn2_found:
 		conn->ksnc_route = NULL;
 
 		ksocknal_route_decref(route);     /* drop conn's ref on route */
author
#11 lore raw

PATCH 5/6 lustre: convert list_for_each() in ksocknal_push_peer()

In reply to NeilBrown

The use of list_for_each() in ksocknal_push_peer() cannot be trivially converted to list_for_each_entry() as the new loop variable is tested outside the loop. We can change that test to compare 'i' to 'index' instead. Then a trivial conversion is possible.

---
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +2 -5
index ea95bff79996..33335713b371 100644
@@ -1853,7 +1853,6 @@ ksocknal_push_peer(struct ksock_peer *peer)
 {
 	int index;
 	int i;
-	struct list_head *tmp;
 	struct ksock_conn *conn;
 
 	for (index = 0; ; index++) {
@@ -1862,10 +1861,8 @@ ksocknal_push_peer(struct ksock_peer *peer)
 		i = 0;
 		conn = NULL;
 
-		list_for_each(tmp, &peer->ksnp_conns) {
+		list_for_each_entry(conn, &peer->ksnp_conns, ksnc_list) {
 			if (i++ == index) {
-				conn = list_entry(tmp, struct ksock_conn,
-						  ksnc_list);
 				ksocknal_conn_addref(conn);
 				break;
 			}
@@ -1873,7 +1870,7 @@ ksocknal_push_peer(struct ksock_peer *peer)
 
 		read_unlock(&ksocknal_data.ksnd_global_lock);
 
-		if (!conn)
+		if (i <= index)
 			break;
 
 		ksocknal_lib_push_conn(conn);
#12 lore raw

PATCH 5/6 lustre: convert list_for_each() in ksocknal_push_peer()

Quoted 6 lines

The use of list_for_each() in ksocknal_push_peer() cannot be trivially converted to list_for_each_entry() as the new loop variable is tested outside the loop. We can change that test to compare 'i' to 'index' instead. Then a trivial conversion is possible.

Quoted 41 lines
---
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +2 -5
index ea95bff79996..33335713b371 100644
@@ -1853,7 +1853,6 @@ ksocknal_push_peer(struct ksock_peer *peer)
 {
 	int index;
 	int i;
-	struct list_head *tmp;
 	struct ksock_conn *conn;
 
 	for (index = 0; ; index++) {
@@ -1862,10 +1861,8 @@ ksocknal_push_peer(struct ksock_peer *peer)
 		i = 0;
 		conn = NULL;
 
-		list_for_each(tmp, &peer->ksnp_conns) {
+		list_for_each_entry(conn, &peer->ksnp_conns, ksnc_list) {
 			if (i++ == index) {
-				conn = list_entry(tmp, struct ksock_conn,
-						  ksnc_list);
 				ksocknal_conn_addref(conn);
 				break;
 			}
@@ -1873,7 +1870,7 @@ ksocknal_push_peer(struct ksock_peer *peer)
 
 		read_unlock(&ksocknal_data.ksnd_global_lock);
 
-		if (!conn)
+		if (i <= index)
 			break;
 
 		ksocknal_lib_push_conn(conn);
author
#13 lore raw

PATCH 6/6 lustre: convert list_for_each() in ksocknal_debug_peerhash()

In reply to NeilBrown

This list_for_each() loop searches for a particular entry, then acts of in. It currently acts after the loop by testing if the variable is NULL. When we convert to list_for_each_entry() it won't be NULL.

Change the code so the acting happens inside the loop.
list_for_each_entry() {
if (this isn't it)
continue;
act on entry;
goto done; // break out of 2 loops
}

---
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |   64 +++++++++-----------
 1 file changed, 28 insertions(+), 36 deletions(-)
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +28 -36
index 33335713b371..f0b0480686dc 100644
@@ -2462,52 +2462,44 @@ static void
 ksocknal_debug_peerhash(struct lnet_ni *ni)
 {
 	struct ksock_peer *peer = NULL;
-	struct list_head *tmp;
 	int i;
 
 	read_lock(&ksocknal_data.ksnd_global_lock);
 
 	for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
-		list_for_each(tmp, &ksocknal_data.ksnd_peers[i]) {
-			peer = list_entry(tmp, struct ksock_peer, ksnp_list);
-
-			if (peer->ksnp_ni == ni)
-				break;
+		list_for_each_entry(peer, &ksocknal_data.ksnd_peers[i], ksnp_list) {
+			struct ksock_route *route;
+			struct ksock_conn  *conn;
 
-			peer = NULL;
-		}
-	}
+			if (peer->ksnp_ni != ni)
+				continue;
 
-	if (peer) {
-		struct ksock_route *route;
-		struct ksock_conn  *conn;
-
-		CWARN("Active peer on shutdown: %s, ref %d, scnt %d, closing %d, accepting %d, err %d, zcookie %llu, txq %d, zc_req %d\n",
-		      libcfs_id2str(peer->ksnp_id),
-		      atomic_read(&peer->ksnp_refcount),
-		      peer->ksnp_sharecount, peer->ksnp_closing,
-		      peer->ksnp_accepting, peer->ksnp_error,
-		      peer->ksnp_zc_next_cookie,
-		      !list_empty(&peer->ksnp_tx_queue),
-		      !list_empty(&peer->ksnp_zc_req_list));
-
-		list_for_each(tmp, &peer->ksnp_routes) {
-			route = list_entry(tmp, struct ksock_route, ksnr_list);
-			CWARN("Route: ref %d, schd %d, conn %d, cnted %d, del %d\n",
-			      atomic_read(&route->ksnr_refcount),
-			      route->ksnr_scheduled, route->ksnr_connecting,
-			      route->ksnr_connected, route->ksnr_deleted);
-		}
+			CWARN("Active peer on shutdown: %s, ref %d, scnt %d, closing %d, accepting %d, err %d, zcookie %llu, txq %d, zc_req %d\n",
+			      libcfs_id2str(peer->ksnp_id),
+			      atomic_read(&peer->ksnp_refcount),
+			      peer->ksnp_sharecount, peer->ksnp_closing,
+			      peer->ksnp_accepting, peer->ksnp_error,
+			      peer->ksnp_zc_next_cookie,
+			      !list_empty(&peer->ksnp_tx_queue),
+			      !list_empty(&peer->ksnp_zc_req_list));
+
+			list_for_each_entry(route, &peer->ksnp_routes, ksnr_list) {
+				CWARN("Route: ref %d, schd %d, conn %d, cnted %d, del %d\n",
+				      atomic_read(&route->ksnr_refcount),
+				      route->ksnr_scheduled, route->ksnr_connecting,
+				      route->ksnr_connected, route->ksnr_deleted);
+			}
 
-		list_for_each(tmp, &peer->ksnp_conns) {
-			conn = list_entry(tmp, struct ksock_conn, ksnc_list);
-			CWARN("Conn: ref %d, sref %d, t %d, c %d\n",
-			      atomic_read(&conn->ksnc_conn_refcount),
-			      atomic_read(&conn->ksnc_sock_refcount),
-			      conn->ksnc_type, conn->ksnc_closing);
+			list_for_each_entry(conn, &peer->ksnp_conns, ksnc_list) {
+				CWARN("Conn: ref %d, sref %d, t %d, c %d\n",
+				      atomic_read(&conn->ksnc_conn_refcount),
+				      atomic_read(&conn->ksnc_sock_refcount),
+				      conn->ksnc_type, conn->ksnc_closing);
+			}
+			goto done;
 		}
 	}
-
+done:
 	read_unlock(&ksocknal_data.ksnd_global_lock);
 }
 
#14 lore raw

PATCH 6/6 lustre: convert list_for_each() in ksocknal_debug_peerhash()

Quoted 9 lines · NeilBrown

This list_for_each() loop searches for a particular entry, then acts of in. It currently acts after the loop by testing if the variable is NULL. When we convert to list_for_each_entry() it won't be NULL.

Change the code so the acting happens inside the loop. list_for_each_entry() {
if (this isn't it)

Quoted 6 lines
       continue;

act on entry;
goto done; // break out of 2 loops
}

Quoted 81 lines

---
.../staging/lustre/lnet/klnds/socklnd/socklnd.c | 64 +++++++++-----------

1 file changed, 28 insertions(+), 36 deletions(-)
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +24 -35
index 33335713b371..f0b0480686dc 100644
@@ -2462,52 +2462,44 @@ static void
 ksocknal_debug_peerhash(struct lnet_ni *ni)
 {
 	struct ksock_peer *peer = NULL;
-	struct list_head *tmp;
 	int i;
 
 	read_lock(&ksocknal_data.ksnd_global_lock);
 
 	for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
-		list_for_each(tmp, &ksocknal_data.ksnd_peers[i]) {
-			peer = list_entry(tmp, struct ksock_peer, ksnp_list);
-
-			if (peer->ksnp_ni == ni)
-				break;
+		list_for_each_entry(peer, &ksocknal_data.ksnd_peers[i], ksnp_list) {
+			struct ksock_route *route;
+			struct ksock_conn  *conn;
 
-			peer = NULL;
-		}
-	}
+			if (peer->ksnp_ni != ni)
+				continue;
 
-	if (peer) {
-		struct ksock_route *route;
-		struct ksock_conn  *conn;
-
-		CWARN("Active peer on shutdown: %s, ref %d, scnt %d, closing %d, accepting %d, err %d, zcookie %llu, txq %d, zc_req %d\n",
-		      libcfs_id2str(peer->ksnp_id),
-		      atomic_read(&peer->ksnp_refcount),
-		      peer->ksnp_sharecount, peer->ksnp_closing,
-		      peer->ksnp_accepting, peer->ksnp_error,
-		      peer->ksnp_zc_next_cookie,
-		      !list_empty(&peer->ksnp_tx_queue),
-		      !list_empty(&peer->ksnp_zc_req_list));
-
-		list_for_each(tmp, &peer->ksnp_routes) {
-			route = list_entry(tmp, struct ksock_route, ksnr_list);
-			CWARN("Route: ref %d, schd %d, conn %d, cnted %d, del %d\n",
-			      atomic_read(&route->ksnr_refcount),
-			      route->ksnr_scheduled, route->ksnr_connecting,
-			      route->ksnr_connected, route->ksnr_deleted);
-		}
+			CWARN("Active peer on shutdown: %s, ref %d, scnt %d, closing %d, accepting %d, err %d, zcookie %llu, txq %d, zc_req %d\n",
+			      libcfs_id2str(peer->ksnp_id),
+			      atomic_read(&peer->ksnp_refcount),
+			      peer->ksnp_sharecount, peer->ksnp_closing,
+			      peer->ksnp_accepting, peer->ksnp_error,
+			      peer->ksnp_zc_next_cookie,
+			      !list_empty(&peer->ksnp_tx_queue),
+			      !list_empty(&peer->ksnp_zc_req_list));
+
+			list_for_each_entry(route, &peer->ksnp_routes, ksnr_list) {
+				CWARN("Route: ref %d, schd %d, conn %d, cnted %d, del %d\n",
+				      atomic_read(&route->ksnr_refcount),
+				      route->ksnr_scheduled, route->ksnr_connecting,
+				      route->ksnr_connected, route->ksnr_deleted);
+			}
 
-		list_for_each(tmp, &peer->ksnp_conns) {
-			conn = list_entry(tmp, struct ksock_conn, ksnc_list);
-			CWARN("Conn: ref %d, sref %d, t %d, c %d\n",
-			      atomic_read(&conn->ksnc_conn_refcount),
-			      atomic_read(&conn->ksnc_sock_refcount),
-			      conn->ksnc_type, conn->ksnc_closing);
+			list_for_each_entry(conn, &peer->ksnp_conns, ksnc_list) {
+				CWARN("Conn: ref %d, sref %d, t %d, c %d\n",
+				      atomic_read(&conn->ksnc_conn_refcount),
+				      atomic_read(&conn->ksnc_sock_refcount),

drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c static void · line 2505

Quoted 10 lines
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +4 -1
+				      conn->ksnc_type, conn->ksnc_closing);
+			}
+			goto done;
 		}
 	}
-
+done:
 	read_unlock(&ksocknal_data.ksnd_global_lock);
 }
 

Cheers, Andreas
---
Andreas Dilger
CTO Whamcloud

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 235 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.lustre.org/pipermail/lustre-devel-lustre.org/attachments/20180730/ec2a82cb/attachment.sig>

#15 lore raw

PATCH 6/6 lustre: convert list_for_each() in ksocknal_debug_peerhash()

In reply to NeilBrown
Quoted 6 lines

This list_for_each() loop searches for a particular entry, then acts of in. It currently acts after the loop by testing if the variable is NULL. When we convert to list_for_each_entry() it won't be NULL.

Quoted 7 lines

Change the code so the acting happens inside the loop.
list_for_each_entry() {
if (this isn't it)
continue;
act on entry;
goto done; // break out of 2 loops
}

Quoted 93 lines
---
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |   64 +++++++++-----------
 1 file changed, 28 insertions(+), 36 deletions(-)
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +28 -36
index 33335713b371..f0b0480686dc 100644
@@ -2462,52 +2462,44 @@ static void
 ksocknal_debug_peerhash(struct lnet_ni *ni)
 {
 	struct ksock_peer *peer = NULL;
-	struct list_head *tmp;
 	int i;
 
 	read_lock(&ksocknal_data.ksnd_global_lock);
 
 	for (i = 0; i < ksocknal_data.ksnd_peer_hash_size; i++) {
-		list_for_each(tmp, &ksocknal_data.ksnd_peers[i]) {
-			peer = list_entry(tmp, struct ksock_peer, ksnp_list);
-
-			if (peer->ksnp_ni == ni)
-				break;
+		list_for_each_entry(peer, &ksocknal_data.ksnd_peers[i], ksnp_list) {
+			struct ksock_route *route;
+			struct ksock_conn  *conn;
 
-			peer = NULL;
-		}
-	}
+			if (peer->ksnp_ni != ni)
+				continue;
 
-	if (peer) {
-		struct ksock_route *route;
-		struct ksock_conn  *conn;
-
-		CWARN("Active peer on shutdown: %s, ref %d, scnt %d, closing %d, accepting %d, err %d, zcookie %llu, txq %d, zc_req %d\n",
-		      libcfs_id2str(peer->ksnp_id),
-		      atomic_read(&peer->ksnp_refcount),
-		      peer->ksnp_sharecount, peer->ksnp_closing,
-		      peer->ksnp_accepting, peer->ksnp_error,
-		      peer->ksnp_zc_next_cookie,
-		      !list_empty(&peer->ksnp_tx_queue),
-		      !list_empty(&peer->ksnp_zc_req_list));
-
-		list_for_each(tmp, &peer->ksnp_routes) {
-			route = list_entry(tmp, struct ksock_route, ksnr_list);
-			CWARN("Route: ref %d, schd %d, conn %d, cnted %d, del %d\n",
-			      atomic_read(&route->ksnr_refcount),
-			      route->ksnr_scheduled, route->ksnr_connecting,
-			      route->ksnr_connected, route->ksnr_deleted);
-		}
+			CWARN("Active peer on shutdown: %s, ref %d, scnt %d, closing %d, accepting %d, err %d, zcookie %llu, txq %d, zc_req %d\n",
+			      libcfs_id2str(peer->ksnp_id),
+			      atomic_read(&peer->ksnp_refcount),
+			      peer->ksnp_sharecount, peer->ksnp_closing,
+			      peer->ksnp_accepting, peer->ksnp_error,
+			      peer->ksnp_zc_next_cookie,
+			      !list_empty(&peer->ksnp_tx_queue),
+			      !list_empty(&peer->ksnp_zc_req_list));
+
+			list_for_each_entry(route, &peer->ksnp_routes, ksnr_list) {
+				CWARN("Route: ref %d, schd %d, conn %d, cnted %d, del %d\n",
+				      atomic_read(&route->ksnr_refcount),
+				      route->ksnr_scheduled, route->ksnr_connecting,
+				      route->ksnr_connected, route->ksnr_deleted);
+			}
 
-		list_for_each(tmp, &peer->ksnp_conns) {
-			conn = list_entry(tmp, struct ksock_conn, ksnc_list);
-			CWARN("Conn: ref %d, sref %d, t %d, c %d\n",
-			      atomic_read(&conn->ksnc_conn_refcount),
-			      atomic_read(&conn->ksnc_sock_refcount),
-			      conn->ksnc_type, conn->ksnc_closing);
+			list_for_each_entry(conn, &peer->ksnp_conns, ksnc_list) {
+				CWARN("Conn: ref %d, sref %d, t %d, c %d\n",
+				      atomic_read(&conn->ksnc_conn_refcount),
+				      atomic_read(&conn->ksnc_sock_refcount),
+				      conn->ksnc_type, conn->ksnc_closing);
+			}
+			goto done;
 		}
 	}
-
+done:
 	read_unlock(&ksocknal_data.ksnd_global_lock);
 }
 
#16 lore raw

cover lustre: convert list_for_each() to list_for_each_entry()

In reply to NeilBrown
Quoted 5 lines

list_for_each_entry(foo) is generally preferred to
list_for_each(l,...)

     foo = list_entry(l,...)
Quoted 8 lines

as there is less noise in the code.
The first patch contains seveveral trivial conversions. The remaining patches are less obvious and are separate so they are easier to review.

NeilBrown

The following series implements...

Looks good and testing shows no problems. I will poke the LNet guys to look at these as well.

Quoted 28 lines

---

NeilBrown (6):
lustre: convert list_for_each() to list_for_each_entry().
lustre: lnet/config: convert list_for_each to list_for_each_entry
lustre: convert list_for_each in ksocknal_create_routes
lustre: convert list_for_each in ksocknal_close_conn_locked()
lustre: convert list_for_each() in ksocknal_push_peer()
lustre: convert list_for_each() in ksocknal_debug_peerhash()

 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c    |   17 --
 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd_cb.c |   20 +-
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |  166 +++++++-------------
 .../staging/lustre/lnet/klnds/socklnd/socklnd_cb.c |   20 +-
 drivers/staging/lustre/lnet/lnet/api-ni.c          |   29 +--
 drivers/staging/lustre/lnet/lnet/config.c          |   28 +--
 drivers/staging/lustre/lnet/lnet/lib-move.c        |    9 -
 drivers/staging/lustre/lnet/lnet/router.c          |   47 +-----
 drivers/staging/lustre/lnet/selftest/conrpc.c      |    7 -
 drivers/staging/lustre/lustre/obdclass/genops.c    |    4 
 .../staging/lustre/lustre/obdecho/echo_client.c    |    4 
 11 files changed, 99 insertions(+), 252 deletions(-)

--
Signature