Skip to contentSkip to conversation

Ensure that ENETUNREACH terminates state recovery

PATCH Superseded [email protected] 2 participants 6 messages Mar 25, 2025

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

cover Ensure that ENETUNREACH terminates state recovery

From: Trond Myklebust <[email protected]>

With the recent patch series that caused containerised mounts which return ENETUNREACH or ENETDOWN errors to report fatal errors, we also want to ensure that the state manager thread also triggers fatal errors in the processes or threads that are waiting for recovery to complete.

Trond Myklebust (4):
SUNRPC: rpcbind should never reset the port to the value '0'
SUNRPC: rpc_clnt_set_transport() must not change the autobind setting
NFSv4: clp->cl_cons_state < 0 signifies an invalid nfs_client
NFSv4: Treat ENETUNREACH errors as fatal for state recovery

 fs/nfs/nfs4state.c     | 14 +++++++++++---
 net/sunrpc/clnt.c      |  3 ---
 net/sunrpc/rpcb_clnt.c |  5 +++--
 3 files changed, 14 insertions(+), 8 deletions(-)
Signature · 1 line
2.49.0
author maintainer
#1 lore raw

PATCH 1/4 SUNRPC: rpcbind should never reset the port to the value '0'

From: Trond Myklebust <[email protected]>

If we already had a valid port number for the RPC service, then we should not allow the rpcbind client to set it to the invalid value '0'.

---
 net/sunrpc/rpcb_clnt.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/sunrpc/rpcb_clnt.c +3 -2
index 102c3818bc54..53bcca365fb1 100644
@@ -820,9 +820,10 @@ static void rpcb_getport_done(struct rpc_task *child, void *data)
 	}
 
 	trace_rpcb_setport(child, map->r_status, map->r_port);
-	xprt->ops->set_port(xprt, map->r_port);
-	if (map->r_port)
+	if (map->r_port) {
+		xprt->ops->set_port(xprt, map->r_port);
 		xprt_set_bound(xprt);
+	}
 }
 
 /*
Signature · 1 line
2.49.0
author maintainer
#2 lore raw

PATCH 2/4 SUNRPC: rpc_clnt_set_transport() must not change the autobind setting

In reply to [email protected]

From: Trond Myklebust <[email protected]>

The autobind setting was supposed to be determined in rpc_create(), since commit c2866763b402 ("SUNRPC: use sockaddr + size when creating remote transport endpoints").

---
 net/sunrpc/clnt.c | 3 ---
 1 file changed, 3 deletions(-)
net/sunrpc/clnt.c +0 -3
index 1cfaf93ceec1..6f75862d9782 100644
@@ -270,9 +270,6 @@ static struct rpc_xprt *rpc_clnt_set_transport(struct rpc_clnt *clnt,
 	old = rcu_dereference_protected(clnt->cl_xprt,
 			lockdep_is_held(&clnt->cl_lock));
 
-	if (!xprt_bound(xprt))
-		clnt->cl_autobind = 1;
-
 	clnt->cl_timeout = timeout;
 	rcu_assign_pointer(clnt->cl_xprt, xprt);
 	spin_unlock(&clnt->cl_lock);
Signature · 1 line
2.49.0
author maintainer
#3 lore raw

PATCH 3/4 NFSv4: clp->cl_cons_state < 0 signifies an invalid nfs_client

In reply to [email protected]

From: Trond Myklebust <[email protected]>

If someone calls nfs_mark_client_ready(clp, status) with a negative value for status, then that should signal that the nfs_client is no longer valid.

---
 fs/nfs/nfs4state.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
fs/nfs/nfs4state.c +2 -2
index 542cdf71229f..738eb2789266 100644
@@ -1198,7 +1198,7 @@ void nfs4_schedule_state_manager(struct nfs_client *clp)
 	struct rpc_clnt *clnt = clp->cl_rpcclient;
 	bool swapon = false;
 
-	if (clnt->cl_shutdown)
+	if (clnt->cl_shutdown || clp->cl_cons_state < 0)
 		return;
 
 	set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state);
@@ -1403,7 +1403,7 @@ int nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4_
 	dprintk("%s: scheduling stateid recovery for server %s\n", __func__,
 			clp->cl_hostname);
 	nfs4_schedule_state_manager(clp);
-	return 0;
+	return clp->cl_cons_state < 0 ? clp->cl_cons_state : 0;
 }
 EXPORT_SYMBOL_GPL(nfs4_schedule_stateid_recovery);
 
Signature · 1 line
2.49.0
author maintainer
#4 lore raw

PATCH 4/4 NFSv4: Treat ENETUNREACH errors as fatal for state recovery

In reply to [email protected]

From: Trond Myklebust <[email protected]>

If a containerised process is killed and causes an ENETUNREACH or ENETDOWN error to be propagated to the state manager, then mark the nfs_client as being dead so that we don't loop in functions that are expecting recovery to succeed.

---
 fs/nfs/nfs4state.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
fs/nfs/nfs4state.c +9 -1
index 738eb2789266..629578dd4a42 100644
@@ -2739,7 +2739,15 @@ static void nfs4_state_manager(struct nfs_client *clp)
 	pr_warn_ratelimited("NFS: state manager%s%s failed on NFSv4 server %s"
 			" with error %d\n", section_sep, section,
 			clp->cl_hostname, -status);
-	ssleep(1);
+	switch (status) {
+	case -ENETDOWN:
+	case -ENETUNREACH:
+		nfs_mark_client_ready(clp, status);
+		break;
+	default:
+		ssleep(1);
+		break;
+	}
 out_drain:
 	memalloc_nofs_restore(memflags);
 	nfs4_end_drain_session(clp);
Signature · 1 line
2.49.0
#5 lore raw

Re: [PATCH 4/4] NFSv4: Treat ENETUNREACH errors as fatal for state recovery

Quoted 22 lines · On Mon, 2025-03-24 at 20:46 -0400, [email protected] wrote:

From: Trond Myklebust <[email protected]>

If a containerised process is killed and causes an ENETUNREACH or ENETDOWN error to be propagated to the state manager, then mark the nfs_client as being dead so that we don't loop in functions that are expecting recovery to succeed.

---
 fs/nfs/nfs4state.c | 10 +++++++++-

 1 file changed, 9 insertions(+), 1 deletion(-)
fs/nfs/nfs4state.c +0 -0
index 738eb2789266..629578dd4a42 100644
@@ -2739,7 +2739,15 @@ static void nfs4_state_manager(struct
 nfs_client *clp)

  pr_warn_ratelimited("NFS: state manager%s%s failed on NFSv4 server %s"
  " with error %d\n", section_sep, section, clp->cl_hostname, -status);

fs/nfs/nfs4state.c static void nfs4_state_manager(struct nfs_client *clp) · line 2745

Quoted 5 lines
fs/nfs/nfs4state.c +4 -1
-	ssleep(1);
+	switch (status) {
+	case -ENETDOWN:
+	case -ENETUNREACH:
+		nfs_mark_client_ready(clp, status);

Actually, that probably needs to be nfs_mark_client_ready(clp, -EIO) in order to make the return value a fatal I/O error.

Quoted 8 lines
fs/nfs/nfs4state.c +5 -0
+		break;
+	default:
+		ssleep(1);
+		break;
+	}

 out_drain:
  memalloc_nofs_restore(memflags);
  nfs4_end_drain_session(clp);

Signature · 3 lines
Trond Myklebust
Linux NFS client maintainer, Hammerspace
[email protected]