All of lore.kernel.org
 help / color / mirror / Atom feed
From: NeilBrown <neilb@suse.com>
To: lustre-devel@lists.lustre.org
Subject: [lustre-devel] [PATCH 6/6] lustre: convert list_for_each() in ksocknal_debug_peerhash()
Date: Mon, 30 Jul 2018 13:45:39 +1000	[thread overview]
Message-ID: <153292233972.26104.9739049020807431895.stgit@noble> (raw)
In-Reply-To: <153292233170.26104.16164388413209501300.stgit@noble>

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
}

Signed-off-by: NeilBrown <neilb@suse.com>
---
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |   64 +++++++++-----------
 1 file changed, 28 insertions(+), 36 deletions(-)

diff --git a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
index 33335713b371..f0b0480686dc 100644
--- a/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
+++ b/drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c
@@ -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);
 }
 

  parent reply	other threads:[~2018-07-30  3:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-30  3:45 [lustre-devel] [PATCH 0/6] lustre: convert list_for_each() to list_for_each_entry() NeilBrown
2018-07-30  3:45 ` [lustre-devel] [PATCH 4/6] lustre: convert list_for_each in ksocknal_close_conn_locked() NeilBrown
2018-08-02  3:13   ` James Simmons
2018-07-30  3:45 ` [lustre-devel] [PATCH 1/6] lustre: convert list_for_each() to list_for_each_entry() NeilBrown
2018-07-30 20:49   ` Andreas Dilger
2018-08-02  3:12   ` James Simmons
2018-07-30  3:45 ` [lustre-devel] [PATCH 3/6] lustre: convert list_for_each in ksocknal_create_routes NeilBrown
2018-08-02  3:13   ` James Simmons
2018-07-30  3:45 ` [lustre-devel] [PATCH 2/6] lustre: lnet/config: convert list_for_each to list_for_each_entry NeilBrown
2018-07-30 20:42   ` Andreas Dilger
2018-08-02  3:13   ` James Simmons
2018-07-30  3:45 ` NeilBrown [this message]
2018-07-30 21:09   ` [lustre-devel] [PATCH 6/6] lustre: convert list_for_each() in ksocknal_debug_peerhash() Andreas Dilger
2018-08-02  3:14   ` James Simmons
2018-07-30  3:45 ` [lustre-devel] [PATCH 5/6] lustre: convert list_for_each() in ksocknal_push_peer() NeilBrown
2018-08-02  3:14   ` James Simmons
2018-08-02  3:16 ` [lustre-devel] [PATCH 0/6] lustre: convert list_for_each() to list_for_each_entry() James Simmons

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=153292233972.26104.9739049020807431895.stgit@noble \
    --to=neilb@suse.com \
    --cc=lustre-devel@lists.lustre.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.