Ensure that ENETUNREACH terminates state recovery
Subsystems (3)
[email protected]
maintainerv3 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.
---
v2:
- Return EIO instead of ENETUNREACH in nfs4_wait_clnt_recover()
v3:
- Fix sysfs' shut down of the nfs_client
- Replace tests of cl_shutdown in NFS code
Trond Myklebust (6):
SUNRPC: rpcbind should never reset the port to the value '0'
SUNRPC: rpc_clnt_set_transport() must not change the autobind setting
NFS: Shut down the nfs_client only after all the superblocks
NFSv4: Further cleanups to shutdown loops
NFSv4: clp->cl_cons_state < 0 signifies an invalid nfs_client
NFSv4: Treat ENETUNREACH errors as fatal for state recovery
fs/nfs/nfs4proc.c | 2 +- fs/nfs/nfs4state.c | 14 +++++++++++--- fs/nfs/sysfs.c | 22 +++++++++++++++++++++- net/sunrpc/clnt.c | 3 --- net/sunrpc/rpcb_clnt.c | 5 +++-- 5 files changed, 36 insertions(+), 10 deletions(-)
Signature · 1 line
2.49.0
[email protected]
maintainerPATCH v3 1/6 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
@@ -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
[email protected]
maintainerPATCH v3 2/6 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
@@ -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
[email protected]
maintainerPATCH v3 3/6 NFS: Shut down the nfs_client only after all the superblocks
In reply to [email protected]From: Trond Myklebust <[email protected]>
The nfs_client manages state for all the superblocks in the "cl_superblocks" list, so it must not be shut down until all of them are gone.
--- fs/nfs/sysfs.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)
fs/nfs/sysfs.c +21 -1
@@ -14,6 +14,7 @@#include <linux/rcupdate.h> #include <linux/lockd/lockd.h> +#include "internal.h" #include "nfs4_fs.h" #include "netns.h" #include "sysfs.h"
@@ -228,6 +229,25 @@ static void shutdown_client(struct rpc_clnt *clnt)rpc_cancel_tasks (clnt, -EIO , shutdown_match_client,NULL ); } +/* +* Shut down the nfs_client only once all the superblocks +* have been shut down. +*/ +static void shutdown_nfs_client (struct nfs_client *clp) +{ +struct nfs_server *server; +rcu_read_lock (); +list_for_each_entry_rcu (server, &clp->cl_superblocks, client_link) { +if (!(server->flags &NFS_MOUNT_SHUTDOWN )) { +rcu_read_unlock (); +return ; + } + } +rcu_read_unlock (); +nfs_mark_client_ready (clp, -EIO ); +shutdown_client (clp->cl_rpcclient); +} +static ssize_t shutdown_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf)
@@ -259,7 +279,6 @@ shutdown_store(struct kobject *kobj, struct kobj_attribute *attr, server->flags |=NFS_MOUNT_SHUTDOWN ;shutdown_client (server->client); -shutdown_client (server->nfs_client->cl_rpcclient);if (!IS_ERR (server->client_acl))shutdown_client (server->client_acl);
@@ -267,6 +286,7 @@ shutdown_store(struct kobject *kobj, struct kobj_attribute *attr,if (server->nlm_host)shutdown_client (server->nlm_host->h_rpcclnt); out: +shutdown_nfs_client (server->nfs_client);return count; }
Signature · 1 line
2.49.0
[email protected]
maintainerPATCH v3 4/6 NFSv4: Further cleanups to shutdown loops
In reply to [email protected]From: Trond Myklebust <[email protected]>
Replace the tests for the RPC client being shut down with tests for whether the nfs_client is in an error state.
--- fs/nfs/nfs4proc.c | 2 +- fs/nfs/nfs4state.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
fs/nfs/nfs4proc.c +1 -1
@@ -9580,7 +9580,7 @@ static void nfs41_sequence_call_done(struct rpc_task *task, void *data)return ;trace_nfs4_sequence (clp, task->tk_status); -if (task->tk_status <0 && !task->tk_client->cl_shutdown) { +if (task->tk_status <0 && clp->cl_cons_state >=0 ) {dprintk ("%s ERROR %d\n" , __func__, task->tk_status);if (refcount_read (&clp->cl_count) ==1 )return ;
fs/nfs/nfs4state.c +1 -1
@@ -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 (clp->cl_cons_state <0 )return ;set_bit (NFS4CLNT_RUN_MANAGER , &clp->cl_state);
Signature · 1 line
2.49.0
[email protected]
maintainerPATCH v3 5/6 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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/nfs4state.c +1 -1
@@ -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
[email protected]
maintainerPATCH v3 6/6 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
@@ -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, -EIO ); +break ; +default : +ssleep (1 ); +break ; + } out_drain:memalloc_nofs_restore (memflags);nfs4_end_drain_session (clp);
Signature · 1 line
2.49.0
Jeff Layton
maintainerRe: [PATCH v3 3/6] NFS: Shut down the nfs_client only after all the superblocks
In reply to [email protected]Quoted 37 lines · On Tue, 2025-03-25 at 18:35 -0400, [email protected] wrote:
From: Trond Myklebust <[email protected]>
The
nfs_clientmanages state for all the superblocks in the "cl_superblocks" list, so it must not be shut down until all of them are gone.Fixes 7d3e26a054c8 ("NFS: Cancel all existing RPC tasks when shutdown")Signed-off-by Trond Myklebust <[email protected]>--- fs/nfs/sysfs.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-)fs/nfs/sysfs.c +10
-0@@ -14,6 +14,7 @@#include <linux/rcupdate.h> #include <linux/lockd/lockd.h> +#include "internal.h" #include "nfs4_fs.h" #include "netns.h" #include "sysfs.h" @@ -228,6 +229,25 @@ static void shutdown_client(struct rpc_clnt *clnt)rpc_cancel_tasks (clnt, -EIO , shutdown_match_client,NULL ); } +/* +* Shut down the nfs_client only once all the superblocks +* have been shut down. +*/ +static void shutdown_nfs_client (struct nfs_client *clp) +{ +struct nfs_server *server; +rcu_read_lock (); +list_for_each_entry_rcu (server, &clp->cl_superblocks, client_link) {
fs/nfs/sysfs.c static void shutdown_client(struct rpc_clnt *clnt) · line 250
Quoted 10 lines
fs/nfs/sysfs.c +10
-0+if (!(server->flags &NFS_MOUNT_SHUTDOWN )) { +rcu_read_unlock (); +return ; + } + } +rcu_read_unlock (); +nfs_mark_client_ready (clp, -EIO ); +shutdown_client (clp->cl_rpcclient); +} +
Isn't the upshot of this that a mount won't actually get shutdown until you shutdown all of the mounts to the same server? Personally, I find that acceptable, but we should note that it is a change in behavior.
Quoted 19 lines
fs/nfs/sysfs.c +1
-1static ssize_t shutdown_show (struct kobject *kobj,struct kobj_attribute *attr,char *buf)@@ -259,7 +279,6 @@ shutdown_store(struct kobject *kobj, struct kobj_attribute *attr, server->flags |=NFS_MOUNT_SHUTDOWN ;shutdown_client (server->client); -shutdown_client (server->nfs_client->cl_rpcclient);if (!IS_ERR (server->client_acl))shutdown_client (server->client_acl);@@ -267,6 +286,7 @@ shutdown_store(struct kobject *kobj, struct kobj_attribute *attr,if (server->nlm_host)shutdown_client (server->nlm_host->h_rpcclnt); out: +shutdown_nfs_client (server->nfs_client);return count; }
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v3 4/6] NFSv4: Further cleanups to shutdown loops
In reply to [email protected]Quoted 29 lines · On Tue, 2025-03-25 at 18:35 -0400, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Replace the tests for the RPC client being shut down with tests for whether the
nfs_clientis in an error state.Signed-off-by Trond Myklebust <[email protected]>--- fs/nfs/nfs4proc.c | 2 +- fs/nfs/nfs4state.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/nfs/nfs4proc.c +1
-1@@ -9580,7 +9580,7 @@ static void nfs41_sequence_call_done(struct rpc_task *task, void *data)return ;trace_nfs4_sequence (clp, task->tk_status); -if (task->tk_status <0 && !task->tk_client->cl_shutdown) { +if (task->tk_status <0 && clp->cl_cons_state >=0 ) {dprintk ("%s ERROR %d\n" , __func__, task->tk_status);if (refcount_read (&clp->cl_count) ==1 )return ;fs/nfs/nfs4state.c +0
-0
fs/nfs/nfs4state.c void nfs4_schedule_state_manager(struct nfs_client *clp) · line 1204
Quoted 8 lines
fs/nfs/nfs4state.c +1
-1@@ -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 (clp->cl_cons_state <0 )return ;set_bit (NFS4CLNT_RUN_MANAGER , &clp->cl_state);
This should probably also have:
...but otherwise this looks good to me.
Re: [PATCH v3 5/6] NFSv4: clp->cl_cons_state < 0 signifies an invalid nfs_client
In reply to [email protected]Quoted 16 lines · On Tue, 2025-03-25 at 18:35 -0400, [email protected] wrote:
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 thenfs_clientis no longer valid.Signed-off-by Trond Myklebust <[email protected]>--- fs/nfs/nfs4state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/nfs/nfs4state.c +0
-0
fs/nfs/nfs4state.c int nfs4_schedule_stateid_recovery(const struct nfs_server *server, struct nfs4_ · line 1409
Quoted 8 lines
fs/nfs/nfs4state.c +1
-1@@ -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);
Trond Myklebust
maintainerRe: [PATCH v3 3/6] NFS: Shut down the nfs_client only after all the superblocks
In reply to Jeff LaytonQuoted 49 lines · Jeff Layton
Quoted 48 lines · On Tue, 2025-03-25 at 18:35 -0400, [email protected] wrote:
From: Trond Myklebust <[email protected]>
The
nfs_clientmanages state for all the superblocks in the "cl_superblocks" list, so it must not be shut down until all of them are
gone.Fixes 7d3e26a054c8 ("NFS: Cancel all existing RPC tasks whenshutdown")
Signed-off-by Trond Myklebust <[email protected]>---
fs/nfs/sysfs.c | 22 +++++++++++++++++++++-1 file changed, 21 insertions(+), 1 deletion(-)fs/nfs/sysfs.c +0
-0@@ -14,6 +14,7 @@ #include <linux/rcupdate.h> #include <linux/lockd/lockd.h>
+#include "internal.h"
#include "nfs4_fs.h"
#include "netns.h"
#include "sysfs.h"fs/nfs/sysfs.c +0
-0@@ -228,6 +229,25 @@ static void shutdown_client(struct rpc_clnt *clnt) rpc_cancel_tasks(clnt, -EIO, shutdown_match_client, NULL); }fs/nfs/sysfs.c +9
-0+/* +* Shut down the nfs_client only once all the superblocks +* have been shut down. +*/ +static void shutdown_nfs_client (struct nfs_client *clp) +{ +struct nfs_server *server; +rcu_read_lock (); + list_for_each_entry_rcu(server, &clp->cl_superblocks,
client_link) {fs/nfs/sysfs.c +7
-0+if (!(server->flags &NFS_MOUNT_SHUTDOWN )) { +rcu_read_unlock (); +return ; + } + } +rcu_read_unlock (); +nfs_mark_client_ready (clp, -EIO );
Quoted 8 lines
fs/nfs/sysfs.c static void shutdown_client(struct rpc_clnt *clnt) · line 250
Quoted 3 lines
fs/nfs/sysfs.c +3
-0+shutdown_client (clp->cl_rpcclient); +} +Isn't the upshot of this that a mount won't actually get shutdown until
you shutdown all of the mounts to the same server? Personally, I find that acceptable, but we should note that it is a change in behavior.
It means that the other mounts to the same server won't inevitably and irrevocably lock up. I'm unhappy that I missed this bug when I applied the patch, but that's not a reason to not fix it.
As I said in the above changelog, the nfs_client's RPC client is there to manage state for all mounts to the same server in the same network namespace. If you shut down that client while there are still mounts that depend on it, then not only have you shot yourself in the foot, but you're going to spend a lot of electrons to just loop madly when those other mounts need to recover state but can't because you've permanently shut down the only way for recovery threads to communicate with the server.
Quoted 24 lines
Quoted 23 lines
static
ssize_t
shutdown_show(struct kobject *kobj, structkobj_attribute*attr, char *buf)fs/nfs/sysfs.c +0
-0@@ -259,7 +279,6 @@ shutdown_store(struct kobject *kobj, struct kobj_attribute *attr,
server->flags|=NFS_MOUNT_SHUTDOWN;
shutdown_client(server->client);fs/nfs/sysfs.c +0
-1-shutdown_client (server->nfs_client->cl_rpcclient);
if (!IS_ERR(server->client_acl))shutdown_client(server->client_acl);fs/nfs/sysfs.c +0
-0@@ -267,6 +286,7 @@ shutdown_store(struct kobject *kobj, struct kobj_attribute *attr, if (server->nlm_host) shutdown_client(server->nlm_host->h_rpcclnt);out:
fs/nfs/sysfs.c +1
-0+shutdown_nfs_client (server->nfs_client);return count;
}
Benjamin Coddington
Reviewed-byRe: [PATCH v3 3/6] NFS: Shut down the nfs_client only after all the superblocks
Quoted 63 lines · Trond Myklebust
Quoted 49 lines · Jeff Layton
Quoted 48 lines · On Tue, 2025-03-25 at 18:35 -0400, [email protected] wrote:
From: Trond Myklebust <[email protected]>
The
nfs_clientmanages state for all the superblocks in the "cl_superblocks" list, so it must not be shut down until all of them are
gone.Fixes 7d3e26a054c8 ("NFS: Cancel all existing RPC tasks whenshutdown")
Signed-off-by Trond Myklebust <[email protected]>---
fs/nfs/sysfs.c | 22 +++++++++++++++++++++-1 file changed, 21 insertions(+), 1 deletion(-)fs/nfs/sysfs.c +0
-0@@ -14,6 +14,7 @@ #include <linux/rcupdate.h> #include <linux/lockd/lockd.h>
+#include "internal.h"
#include "nfs4_fs.h"
#include "netns.h"
#include "sysfs.h"fs/nfs/sysfs.c +0
-0@@ -228,6 +229,25 @@ static void shutdown_client(struct rpc_clnt *clnt) rpc_cancel_tasks(clnt, -EIO, shutdown_match_client, NULL); }fs/nfs/sysfs.c +9
-0+/* +* Shut down the nfs_client only once all the superblocks +* have been shut down. +*/ +static void shutdown_nfs_client (struct nfs_client *clp) +{ +struct nfs_server *server; +rcu_read_lock (); + list_for_each_entry_rcu(server, &clp->cl_superblocks,
client_link) {fs/nfs/sysfs.c +7
-0+if (!(server->flags &NFS_MOUNT_SHUTDOWN )) { +rcu_read_unlock (); +return ; + } + } +rcu_read_unlock (); +nfs_mark_client_ready (clp, -EIO );Quoted 8 lines
fs/nfs/sysfs.c static void shutdown_client(struct rpc_clnt *clnt) · line 250
Quoted 3 lines
fs/nfs/sysfs.c +3
-0+shutdown_client (clp->cl_rpcclient); +} +Isn't the upshot of this that a mount won't actually get shutdown until
you shutdown all of the mounts to the same server? Personally, I find that acceptable, but we should note that it is a change in behavior.It means that the other mounts to the same server won't inevitably and irrevocably lock up. I'm unhappy that I missed this bug when I applied the patch, but that's not a reason to not fix it.
Quoted 8 lines
As I said in the above changelog, the nfs_client's RPC client is there to manage state for all mounts to the same server in the same network namespace. If you shut down that client while there are still mounts that depend on it, then not only have you shot yourself in the foot, but you're going to spend a lot of electrons to just loop madly when those other mounts need to recover state but can't because you've permanently shut down the only way for recovery threads to communicate with the server.
The only use for shutdown so far had been when the server is permanently unavailable, so breaking mounts to the same server didn't matter. I agree this fix is the right thing to do now.
Ben
Jeff Layton
maintainerRe: [PATCH v3 4/6] NFSv4: Further cleanups to shutdown loops
In reply to [email protected]Quoted 29 lines · On Tue, 2025-03-25 at 18:35 -0400, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Replace the tests for the RPC client being shut down with tests for whether the
nfs_clientis in an error state.Signed-off-by Trond Myklebust <[email protected]>--- fs/nfs/nfs4proc.c | 2 +- fs/nfs/nfs4state.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/nfs/nfs4proc.c +1
-1@@ -9580,7 +9580,7 @@ static void nfs41_sequence_call_done(struct rpc_task *task, void *data)return ;trace_nfs4_sequence (clp, task->tk_status); -if (task->tk_status <0 && !task->tk_client->cl_shutdown) { +if (task->tk_status <0 && clp->cl_cons_state >=0 ) {dprintk ("%s ERROR %d\n" , __func__, task->tk_status);if (refcount_read (&clp->cl_count) ==1 )return ;fs/nfs/nfs4state.c +0
-0
fs/nfs/nfs4state.c void nfs4_schedule_state_manager(struct nfs_client *clp) · line 1204
Quoted 8 lines
fs/nfs/nfs4state.c +1
-1@@ -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 (clp->cl_cons_state <0 )return ;set_bit (NFS4CLNT_RUN_MANAGER , &clp->cl_state);
One more thing:
Do we need cl_shutdown at all? If we can replace these checks here with a check for cl_cons_state < 0, why not do the same in call_start()?
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v3 6/6] NFSv4: Treat ENETUNREACH errors as fatal for state recovery
In reply to [email protected]Quoted 36 lines · On 25 Mar 2025, at 18:35, [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_clientas being dead so that we don't loop in functions that are expecting recovery to succeed.Reviewed-by Jeff Layton <[email protected]>Signed-off-by Trond Myklebust <[email protected]>--- fs/nfs/nfs4state.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)fs/nfs/nfs4state.c +9
-1@@ -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, -EIO ); +break ; +default : +ssleep (1 ); +break ; + } out_drain:memalloc_nofs_restore (memflags);nfs4_end_drain_session (clp);Signature · 1 line
2.49.0
Doesn't this have the same bug as the sysfs shutdown - in that a mount with fatal_neterrors=ENETDOWN:ENETUNREACH can take down the state manager for a mount without it? I think the same consideration applies as shutdown so
far: in practical use, you're not going to care.
Another thought - its pretty subtle that the only way those errors might/should reach us here is if that mount option is in play.
Ben
Re: [PATCH v3 1/6] SUNRPC: rpcbind should never reset the port to the value '0'
In reply to [email protected]Quoted 30 lines · On 25 Mar 2025, at 18:35, [email protected] wrote:
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'.
Reviewed-by Jeff Layton <[email protected]>Signed-off-by Trond Myklebust <[email protected]>--- net/sunrpc/rpcb_clnt.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)net/sunrpc/rpcb_clnt.c +3
-2@@ -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
Ben
Re: [PATCH v3 2/6] SUNRPC: rpc_clnt_set_transport() must not change the autobind setting
In reply to [email protected]Quoted 28 lines · On 25 Mar 2025, at 18:35, [email protected] wrote:
From: Trond Myklebust <[email protected]>
The autobind setting was supposed to be determined in
rpc_create(), since commitc2866763b402("SUNRPC: use sockaddr + size when creating remote transport endpoints").Reviewed-by Jeff Layton <[email protected]>Signed-off-by Trond Myklebust <[email protected]>--- net/sunrpc/clnt.c | 3 --- 1 file changed, 3 deletions(-)net/sunrpc/clnt.c +0
-3@@ -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
Ben
Benjamin Coddington
Reviewed-byRe: [PATCH v3 4/6] NFSv4: Further cleanups to shutdown loops
In reply to Jeff LaytonQuoted 37 lines · Jeff Layton
Quoted 36 lines · On Tue, 2025-03-25 at 18:35 -0400, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Replace the tests for the RPC client being shut down with tests for whether the
nfs_clientis in an error state.Signed-off-by Trond Myklebust <[email protected]>--- fs/nfs/nfs4proc.c | 2 +- fs/nfs/nfs4state.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)fs/nfs/nfs4proc.c +1
-1@@ -9580,7 +9580,7 @@ static void nfs41_sequence_call_done(struct rpc_task *task, void *data)return ;trace_nfs4_sequence (clp, task->tk_status); -if (task->tk_status <0 && !task->tk_client->cl_shutdown) { +if (task->tk_status <0 && clp->cl_cons_state >=0 ) {dprintk ("%s ERROR %d\n" , __func__, task->tk_status);if (refcount_read (&clp->cl_count) ==1 )return ;fs/nfs/nfs4state.c +1
-1@@ -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 (clp->cl_cons_state <0 )return ;
Quoted 8 lines
fs/nfs/nfs4state.c void nfs4_schedule_state_manager(struct nfs_client *clp) · line 1204
Quoted 1 line
fs/nfs/nfs4state.c +0
-0set_bit (NFS4CLNT_RUN_MANAGER , &clp->cl_state);One more thing:
Do we need
cl_shutdownat all? If we can replace these checks here with a check forcl_cons_state< 0, why not do the same incall_start()?Signature · 1 line
Jeff Layton <[email protected]>
Agree - I don't see why not.
Ben
Re: [PATCH v3 5/6] NFSv4: clp->cl_cons_state < 0 signifies an invalid nfs_client
In reply to [email protected]Quoted 26 lines · On 25 Mar 2025, at 18:35, [email protected] wrote:
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 thenfs_clientis no longer valid.Signed-off-by Trond Myklebust <[email protected]>--- fs/nfs/nfs4state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)fs/nfs/nfs4state.c +1
-1@@ -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
Ben
Jeff Layton
maintainerRe: [PATCH v3 6/6] NFSv4: Treat ENETUNREACH errors as fatal for state recovery
In reply to Benjamin CoddingtonQuoted 35 lines · Benjamin Coddington
Quoted 33 lines · On 25 Mar 2025, at 18:35, [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_clientas being dead so that we don't loop in functions that are expecting recovery to succeed.Reviewed-by Jeff Layton <[email protected]>Signed-off-by Trond Myklebust <[email protected]>--- fs/nfs/nfs4state.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)fs/nfs/nfs4state.c +9
-1@@ -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, -EIO ); +break ; +default : +ssleep (1 ); +break ; + } out_drain:memalloc_nofs_restore (memflags);
Quoted 9 lines
Quoted 3 lines
fs/nfs/nfs4state.c +0
-0nfs4_end_drain_session (clp);Signature · 1 line
2.49.0Doesn't this have the same bug as the sysfs shutdown - in that a mount with fatal_neterrors=ENETDOWN:ENETUNREACH can take down the state manager for a mount without it? I think the same consideration applies as shutdown so
far: in practical use, you're not going to care.
True. In principle we probably ought to avoid sharing superblocks between mounts with different fatal_errors= options. In practice, I agree that no one will care since this means that the server is borked.
Quoted 7 lines
Another thought - its pretty subtle that the only way those errors might/should reach us here is if that mount option is in play.
Reviewed-by Benjamin Coddington <[email protected]>Ben
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v3 6/6] NFSv4: Treat ENETUNREACH errors as fatal for state recovery
Quoted 54 lines · Jeff Layton
Quoted 44 lines · Benjamin Coddington
Quoted 36 lines · On 25 Mar 2025, at 18:35, [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_clientas being dead so that we don't loop in functions that are
expecting recovery to succeed.Reviewed-by Jeff Layton <[email protected]>Signed-off-by Trond Myklebust <[email protected]>---
fs/nfs/nfs4state.c | 10 +++++++++-1 file changed, 9 insertions(+), 1 deletion(-)fs/nfs/nfs4state.c +0
-0@@ -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 +9
-1-ssleep (1 ); +switch (status) { +case -ENETDOWN : +case -ENETUNREACH : +nfs_mark_client_ready (clp, -EIO ); +break ; +default : +ssleep (1 ); +break ; + }Quoted 5 lines
out_drain:
memalloc_nofs_restore(memflags);
nfs4_end_drain_session(clp);Signature · 1 line
2.49.0Quoted 8 lines
Doesn't this have the same bug as the sysfs shutdown - in that a mount with
fatal_neterrors=ENETDOWN:ENETUNREACH can take down the state manager for a
mount without it? I think the same consideration applies as shutdown so
far: in practical use, you're not going to care.
Quoted 13 lines
True. In principle we probably ought to avoid sharing superblocks between mounts with different fatal_errors= options. In practice, I agree that no one will care since this means that the server is borked.
Quoted 7 lines
Another thought - its pretty subtle that the only way those errors might/should reach us here is if that mount option is in play.
Reviewed-by Benjamin Coddington <[email protected]>Ben
The difference here is that the fatal_neterrors option as it stands today, only looks at whether or not your request is routable. It is not intended to function as a mechanism for dealing with servers being down. It only works as a last resort for when the host's orchestrator software destroys a container's local virtual network devices without first ensuring that its mounts have been safely shut down.
IOW: yes there are some subtleties here, which is why we need a mount option in the first place to allow override of the default behaviours. However those default settings as they stand are hopefully sufficiently conservative that admins should only rarely need to override them.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Re: [PATCH v3 4/6] NFSv4: Further cleanups to shutdown loops
In reply to Jeff LaytonQuoted 45 lines · Jeff Layton
Quoted 38 lines · On Tue, 2025-03-25 at 18:35 -0400, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Replace the tests for the RPC client being shut down with tests for whether the
nfs_clientis in an error state.Signed-off-by Trond Myklebust <[email protected]>---
fs/nfs/nfs4proc.c | 2 +-
fs/nfs/nfs4state.c | 2 +-2 files changed, 2 insertions(+), 2 deletions(-)fs/nfs/nfs4proc.c +0
-0@@ -9580,7 +9580,7 @@ static void nfs41_sequence_call_done(struct rpc_task *task, void *data) return;
trace_nfs4_sequence(clp, task->tk_status);fs/nfs/nfs4proc.c +0
-1-if (task->tk_status <0 && !task->tk_client->cl_shutdown){
fs/nfs/nfs4proc.c +1
-0+if (task->tk_status <0 && clp->cl_cons_state >=0 ) {dprintk("%s ERROR %d\n",
__func__, task-Quoted 1 line
tk_status);if (
refcount_read(&clp->cl_count)== 1) return;fs/nfs/nfs4state.c +0
-0@@ -1198,7 +1198,7 @@ void nfs4_schedule_state_manager(struct nfs_client *clp) struct rpc_clnt *clnt = clp->cl_rpcclient; bool swapon = false;fs/nfs/nfs4state.c +1
-1-if (clnt->cl_shutdown) +if (clp->cl_cons_state <0 )Quoted 3 lines
return;
set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state);One more thing:
Quoted 3 lines
Do we need
cl_shutdownat all? If we can replace these checks here with
a check forcl_cons_state< 0, why not do the same incall_start()?
The struct nfs_client is a NFS level object. It can't be moved to the RPC layer.
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Jeff Layton
maintainerRe: [PATCH v3 4/6] NFSv4: Further cleanups to shutdown loops
Quoted 46 lines · Trond Myklebust
Quoted 45 lines · Jeff Layton
Quoted 38 lines · On Tue, 2025-03-25 at 18:35 -0400, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Replace the tests for the RPC client being shut down with tests for whether the
nfs_clientis in an error state.Signed-off-by Trond Myklebust <[email protected]>---
fs/nfs/nfs4proc.c | 2 +-
fs/nfs/nfs4state.c | 2 +-2 files changed, 2 insertions(+), 2 deletions(-)fs/nfs/nfs4proc.c +0
-0@@ -9580,7 +9580,7 @@ static void nfs41_sequence_call_done(struct rpc_task *task, void *data) return;
trace_nfs4_sequence(clp, task->tk_status);fs/nfs/nfs4proc.c +0
-1-if (task->tk_status <0 && !task->tk_client->cl_shutdown){
fs/nfs/nfs4proc.c +1
-0+if (task->tk_status <0 && clp->cl_cons_state >=0 ) {dprintk("%s ERROR %d\n",
__func__, task-Quoted 1 line
tk_status);if (
refcount_read(&clp->cl_count)== 1) return;fs/nfs/nfs4state.c +0
-0@@ -1198,7 +1198,7 @@ void nfs4_schedule_state_manager(struct nfs_client *clp) struct rpc_clnt *clnt = clp->cl_rpcclient; bool swapon = false;fs/nfs/nfs4state.c +1
-1-if (clnt->cl_shutdown) +if (clp->cl_cons_state <0 )Quoted 3 lines
return;
set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state);One more thing:
Quoted 7 lines
Quoted 3 lines
Do we need
cl_shutdownat all? If we can replace these checks here with
a check forcl_cons_state< 0, why not do the same incall_start()?The struct
nfs_clientis a NFS level object. It can't be moved to the RPC layer.
But...cl_shutdown is an rpc_clnt field.
Signature · 1 line
Jeff Layton <[email protected]>
Re: [PATCH v3 4/6] NFSv4: Further cleanups to shutdown loops
Quoted 57 lines · Jeff Layton
Quoted 56 lines · Trond Myklebust
Quoted 54 lines · Jeff Layton
Quoted 42 lines · On Tue, 2025-03-25 at 18:35 -0400, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Replace the tests for the RPC client being shut down with tests for
whether thenfs_clientis in an error state.Signed-off-by: Trond Myklebust
<[email protected]>
---
fs/nfs/nfs4proc.c | 2 +-
fs/nfs/nfs4state.c | 2 +-2 files changed, 2 insertions(+), 2 deletions(-)fs/nfs/nfs4proc.c +0
-0@@ -9580,7 +9580,7 @@ static voidnfs41_sequence_call_done(struct
rpc_task*task, void *data)
return;
trace_nfs4_sequence(clp, task->tk_status);fs/nfs/nfs4proc.c +0
-1- if (task->tk_status < 0 && !task->tk_client-Quoted 1 line
cl_shutdown){
fs/nfs/nfs4proc.c +1
-0+if (task->tk_status <0 && clp->cl_cons_state >=0 ) {dprintk("%s ERROR %d\n",
__func__, task-Quoted 1 line
tk_status);if (
refcount_read(&clp->cl_count)== 1) return;fs/nfs/nfs4state.c +0
-0@@ -1198,7 +1198,7 @@ void nfs4_schedule_state_manager(struct nfs_client *clp) struct rpc_clnt *clnt = clp->cl_rpcclient; bool swapon = false;fs/nfs/nfs4state.c +1
-1-if (clnt->cl_shutdown) +if (clp->cl_cons_state <0 )Quoted 3 lines
return;
set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state);One more thing:
Do we need
cl_shutdownat all? If we can replace these checks here
with
a check forcl_cons_state< 0, why not do the same incall_start()?
Quoted 6 lines
Quoted 4 lines
The struct
nfs_clientis a NFS level object. It can't be moved to the
RPC layer.But...cl_shutdown is an
rpc_clntfield.
Right, but cl_cons_state is a field in struct nfs_client, hence that check cannot be moved into call_start()
Signature · 3 lines
Trond Myklebust Linux NFS client maintainer, Hammerspace [email protected]
Jeff Layton
maintainerRe: [PATCH v3 4/6] NFSv4: Further cleanups to shutdown loops
Quoted 63 lines · Trond Myklebust
Quoted 62 lines · Jeff Layton
Quoted 60 lines · Trond Myklebust
Quoted 49 lines · Jeff Layton
Quoted 42 lines · On Tue, 2025-03-25 at 18:35 -0400, [email protected] wrote:
From: Trond Myklebust <[email protected]>
Replace the tests for the RPC client being shut down with tests for
whether thenfs_clientis in an error state.Signed-off-by: Trond Myklebust
<[email protected]>
---
fs/nfs/nfs4proc.c | 2 +-
fs/nfs/nfs4state.c | 2 +-2 files changed, 2 insertions(+), 2 deletions(-)fs/nfs/nfs4proc.c +0
-0@@ -9580,7 +9580,7 @@ static voidnfs41_sequence_call_done(struct
rpc_task*task, void *data)
return;
trace_nfs4_sequence(clp, task->tk_status);fs/nfs/nfs4proc.c +0
-1- if (task->tk_status < 0 && !task->tk_client-Quoted 1 line
cl_shutdown){
fs/nfs/nfs4proc.c +1
-0+if (task->tk_status <0 && clp->cl_cons_state >=0 ) {dprintk("%s ERROR %d\n",
__func__, task-Quoted 1 line
tk_status);if (
refcount_read(&clp->cl_count)== 1) return;fs/nfs/nfs4state.c +0
-0@@ -1198,7 +1198,7 @@ void nfs4_schedule_state_manager(struct nfs_client *clp) struct rpc_clnt *clnt = clp->cl_rpcclient; bool swapon = false;fs/nfs/nfs4state.c +1
-1-if (clnt->cl_shutdown) +if (clp->cl_cons_state <0 )Quoted 3 lines
return;
set_bit(NFS4CLNT_RUN_MANAGER, &clp->cl_state);One more thing:
Quoted 5 lines
Do we need
cl_shutdownat all? If we can replace these checks here
with
a check forcl_cons_state< 0, why not do the same incall_start()?The struct
nfs_clientis a NFS level object. It can't be moved to the
RPC layer.
Quoted 4 lines
Quoted 1 line
But...cl_shutdown is an
rpc_clntfield.Right, but
cl_cons_stateis a field in structnfs_client, hence that check cannot be moved intocall_start()
Doh! Good point. Nevermind!
Signature · 1 line
Jeff Layton <[email protected]>