[Cluster-devel] [RFC dlm/next 15/15] fs: dlm: move srcu into loop call

Alexander Aring aahringo at redhat.com
Wed Jun 23 15:14:54 UTC 2021


This patch cleans up the foreach_conn() helper that we hold the srcu
lock while iterating over the connections.

Signed-off-by: Alexander Aring <aahringo at redhat.com>
---
 fs/dlm/lowcomms.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/fs/dlm/lowcomms.c b/fs/dlm/lowcomms.c
index bb088ebc1614..ac4325c4865f 100644
--- a/fs/dlm/lowcomms.c
+++ b/fs/dlm/lowcomms.c
@@ -377,13 +377,15 @@ static struct connection *nodeid2con(int nodeid, gfp_t alloc)
 /* Loop round all connections */
 static void foreach_conn(void (*conn_func)(struct connection *c))
 {
-	int i;
 	struct connection *con;
+	int i, idx;
 
+	idx = srcu_read_lock(&connections_srcu);
 	for (i = 0; i < CONN_HASH_SIZE; i++) {
 		hlist_for_each_entry_rcu(con, &connection_hash[i], list)
 			conn_func(con);
 	}
+	srcu_read_unlock(&connections_srcu, idx);
 }
 
 static struct dlm_node_addr *find_node_addr(int nodeid)
@@ -1778,8 +1780,6 @@ static void shutdown_conn(struct connection *con)
 
 void dlm_lowcomms_shutdown(void)
 {
-	int idx;
-
 	/* Set all the flags to prevent any
 	 * socket activity.
 	 */
@@ -1787,9 +1787,7 @@ void dlm_lowcomms_shutdown(void)
 	flush_work(&listen_con.rwork);
 	dlm_close_sock(&listen_con.sock);
 
-	idx = srcu_read_lock(&connections_srcu);
 	foreach_conn(shutdown_conn);
-	srcu_read_unlock(&connections_srcu, idx);
 }
 
 static void connection_release(struct rcu_head *rcu)
@@ -1816,11 +1814,7 @@ static void free_conn(struct connection *con)
 
 void dlm_lowcomms_stop(void)
 {
-	int idx;
-
-	idx = srcu_read_lock(&connections_srcu);
 	foreach_conn(free_conn);
-	srcu_read_unlock(&connections_srcu, idx);
 	work_stop();
 	deinit_local();
 
-- 
2.26.3




More information about the Cluster-devel mailing list