From 659bb641e2a1c55dd293533388f86a6adfec8a2b Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Mon, 18 Nov 2019 12:24:09 +1100 Subject: [PATCH] LU-12678 lnet: change list_for_each in ksocknal_debug_peerhash 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 } Note that identing is deliberately left unchanged, as the next patch will change the 2 loops to a single loop, after which the current indents will be correct. Signed-off-by: Mr NeilBrown Change-Id: Idea32bf2ab4037650d6698d4f82f6b6764b4d1b2 Reviewed-on: https://review.whamcloud.com/36836 Tested-by: jenkins Tested-by: Maloo Reviewed-by: Amir Shehata Reviewed-by: James Simmons Reviewed-by: Oleg Drokin --- lnet/klnds/socklnd/socklnd.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/lnet/klnds/socklnd/socklnd.c b/lnet/klnds/socklnd/socklnd.c index 18c7e6a..3357110 100644 --- a/lnet/klnds/socklnd/socklnd.c +++ b/lnet/klnds/socklnd/socklnd.c @@ -2454,26 +2454,19 @@ ksocknal_base_startup(void) static void ksocknal_debug_peerhash(struct lnet_ni *ni) { - struct ksock_peer_ni *peer_ni = NULL; - struct list_head *tmp; + struct ksock_peer_ni *peer_ni; 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_ni = list_entry(tmp, struct ksock_peer_ni, ksnp_list); - - if (peer_ni->ksnp_ni == ni) - break; - - peer_ni = NULL; - } - } - - if (peer_ni != NULL) { + list_for_each_entry(peer_ni, &ksocknal_data.ksnd_peers[i], + ksnp_list) { struct ksock_route *route; - struct ksock_conn *conn; + struct ksock_conn *conn; + + if (peer_ni->ksnp_ni != ni) + continue; CWARN("Active peer_ni on shutdown: %s, ref %d, " "closing %d, accepting %d, err %d, zcookie %llu, " @@ -2485,23 +2478,23 @@ ksocknal_debug_peerhash(struct lnet_ni *ni) !list_empty(&peer_ni->ksnp_tx_queue), !list_empty(&peer_ni->ksnp_zc_req_list)); - list_for_each(tmp, &peer_ni->ksnp_routes) { - route = list_entry(tmp, struct ksock_route, ksnr_list); + list_for_each_entry(route, &peer_ni->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_ni->ksnp_conns) { - conn = list_entry(tmp, struct ksock_conn, ksnc_list); + list_for_each_entry(conn, &peer_ni->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); } -- 1.8.3.1