Whamcloud - gitweb
LU-12678 lnet: change list_for_each in ksocknal_debug_peerhash 36/36836/3
authorMr NeilBrown <neilb@suse.de>
Mon, 18 Nov 2019 01:24:09 +0000 (12:24 +1100)
committerOleg Drokin <green@whamcloud.com>
Fri, 10 Jan 2020 07:42:16 +0000 (07:42 +0000)
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 <neilb@suse.de>
Change-Id: Idea32bf2ab4037650d6698d4f82f6b6764b4d1b2
Reviewed-on: https://review.whamcloud.com/36836
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Amir Shehata <ashehata@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lnet/klnds/socklnd/socklnd.c

index 18c7e6a..3357110 100644 (file)
@@ -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);
 }