Skip to contentSkip to conversation

xprtrdma: Retire the connection generation when a connect attempt fails

PATCH New Tim Menninger 1 participant 1 message Nov 23

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 xprtrdma: Retire the connection generation when a connect attempt fails

When a connect attempt fails, xprt_rdma_connect_worker() wakes the tasks waiting on the transport with the connect error. For errors such as -ECONNREFUSED, call_connect_status() can then call xprt_conditional_disconnect() with the task's rq_connect_cookie, which was copied from xprt->connect_cookie when the task started waiting for the connection.

The failure path tears down the endpoint through rpcrdma_xprt_disconnect() without advancing connect_cookie, so that cookie still matches and the conditional disconnect requests an autoclose. If another task has already started the next connect attempt, that attempt holds XPRT_LOCKED and the close request sets XPRT_CLOSE_WAIT. When the attempt succeeds and releases the lock, the pending autoclose tears down the newly established connection.

This was observed on 7.4-rc3 after restarting the NFS service on a pNFS data server reached over RDMA. Connect attempts made while the server was not yet listening were rejected, and the first connections that then succeeded were closed within a millisecond of being established.

Advance connect_cookie once per connect attempt, whether it succeeds or fails, before waking its waiters, so that their conditional disconnects no longer match.

Also wake pending tasks before releasing the connect lock. Otherwise, a task can capture the updated cookie and join the pending queue for the next attempt before the previous attempt's error is delivered.

Fixes f99fa50880f5 ("SUNRPC/xprtrdma: Fix reconnection locking")

---
Changes in v2:
- Advance connect_cookie in one place, just after xprt_clear_connecting(), for every connect attempt (Chuck)
- Add a comment explaining why pending tasks are woken before the connect lock is released (Chuck)
- Update the commit message to match

v1: https://lore.kernel.org/all/[email protected]

 net/sunrpc/xprtrdma/transport.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
net/sunrpc/xprtrdma/transport.c +5 -2
index e38637c2ec787..d27de0ad6732b 100644
@@ -232,8 +232,8 @@ xprt_rdma_connect_worker(struct work_struct *work)
 		current->flags |= PF_MEMALLOC;
 	rc = rpcrdma_xprt_connect(r_xprt);
 	xprt_clear_connecting(xprt);
+	xprt->connect_cookie++;
 	if (!rc) {
-		xprt->connect_cookie++;
 		xprt->stat.connect_count++;
 		xprt->stat.connect_time += (long)jiffies -
 					   xprt->stat.connect_start;
@@ -241,8 +241,11 @@ xprt_rdma_connect_worker(struct work_struct *work)
 		rc = -EAGAIN;
 	} else
 		rpcrdma_xprt_disconnect(r_xprt);
-	xprt_unlock_connect(xprt, r_xprt);
+	/* Wake waiters before unlocking, so that a task which records the
+	 * new connect_cookie cannot receive this attempt's result.
+	 */
 	xprt_wake_pending_tasks(xprt, rc);
+	xprt_unlock_connect(xprt, r_xprt);
 	current_restore_flags(pflags, PF_MEMALLOC);
 }
 

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3

Signature · 1 line
2.53.0