Skip to contentSkip to conversation

nfsd: set the server_scope during service startup

PATCH In review Scott Mayhew 2 participants 3 messages Feb 19, 2020 – Mar 3, 2020

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

PATCH 1/1 nfsd: set the server_scope during service startup

Currently, nfsd4_encode_exchange_id() encodes the utsname nodename string in the server_scope field. In a multi-host container environemnt, if an nfsd container is restarted on a different host than it was originally running on, clients will see a server_scope mismatch and will not attempt to reclaim opens.

Instead, set the server_scope while we're in a process context during service startup, so we get the utsname nodename of the current process and store that in nfsd_net.

---
 fs/nfsd/netns.h   | 1 +
 fs/nfsd/nfs4xdr.c | 3 ++-
 fs/nfsd/nfssvc.c  | 3 +++
 3 files changed, 6 insertions(+), 1 deletion(-)
fs/nfsd/netns.h +1 -0
index 2baf32311e00..c6d95700105e 100644
@@ -172,6 +172,7 @@ struct nfsd_net {
 	unsigned int             longest_chain_cachesize;
 
 	struct shrinker		nfsd_reply_cache_shrinker;
+	char			server_scope[UNX_MAXNODENAME+1];
 };
 
 /* Simple check to find out if a given net was properly initialized */
fs/nfsd/nfs4xdr.c +2 -1
index 9761512674a0..209174ee431a 100644
@@ -4005,10 +4005,11 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
 	int major_id_sz;
 	int server_scope_sz;
 	uint64_t minor_id = 0;
+	struct nfsd_net *nn = net_generic(SVC_NET(resp->rqstp), nfsd_net_id);
 
 	major_id = utsname()->nodename;
 	major_id_sz = strlen(major_id);
-	server_scope = utsname()->nodename;
+	server_scope = nn->server_scope;
 	server_scope_sz = strlen(server_scope);
 
 	p = xdr_reserve_space(xdr,
fs/nfsd/nfssvc.c +3 -0
index 3b77b904212d..c4e00979aca4 100644
@@ -749,6 +749,9 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred)
 	if (nrservs == 0 && nn->nfsd_serv == NULL)
 		goto out;
 
+	strlcpy(nn->server_scope, utsname()->nodename,
+		sizeof(nn->server_scope));
+
 	error = nfsd_create_serv(net);
 	if (error)
 		goto out;
Signature · 1 line
2.24.1
#1 lore raw
Quoted 9 lines · Scott Mayhew

Currently, nfsd4_encode_exchange_id() encodes the utsname nodename string in the server_scope field. In a multi-host container environemnt, if an nfsd container is restarted on a different host than it was originally running on, clients will see a server_scope mismatch and will not attempt to reclaim opens.

Instead, set the server_scope while we're in a process context during service startup, so we get the utsname nodename of the current process and store that in nfsd_net.

Thanks! Just one nit:

Quoted 24 lines
---
 fs/nfsd/netns.h   | 1 +
 fs/nfsd/nfs4xdr.c | 3 ++-
 fs/nfsd/nfssvc.c  | 3 +++
 3 files changed, 6 insertions(+), 1 deletion(-)
fs/nfsd/netns.h +1 -0
index 2baf32311e00..c6d95700105e 100644
@@ -172,6 +172,7 @@ struct nfsd_net {
 	unsigned int             longest_chain_cachesize;
 
 	struct shrinker		nfsd_reply_cache_shrinker;
+	char			server_scope[UNX_MAXNODENAME+1];
 };
 
 /* Simple check to find out if a given net was properly initialized */
fs/nfsd/nfs4xdr.c +0 -0
index 9761512674a0..209174ee431a 100644

fs/nfsd/nfs4xdr.c nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr, · line 4011

Quoted 7 lines
fs/nfsd/nfs4xdr.c +1 -0
@@ -4005,10 +4005,11 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
 	int major_id_sz;
 	int server_scope_sz;
 	uint64_t minor_id = 0;
+	struct nfsd_net *nn = net_generic(SVC_NET(resp->rqstp), nfsd_net_id);
 
 	major_id = utsname()->nodename;
 	major_id_sz = strlen(major_id);

We should do this one too. I'll fix that up and apply if that's OK.

--b.

Quoted 21 lines
fs/nfsd/nfs4xdr.c +1 -1
-	server_scope = utsname()->nodename;
+	server_scope = nn->server_scope;
 	server_scope_sz = strlen(server_scope);
 
 	p = xdr_reserve_space(xdr,
fs/nfsd/nfssvc.c +3 -0
index 3b77b904212d..c4e00979aca4 100644
@@ -749,6 +749,9 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred)
 	if (nrservs == 0 && nn->nfsd_serv == NULL)
 		goto out;
 
+	strlcpy(nn->server_scope, utsname()->nodename,
+		sizeof(nn->server_scope));
+
 	error = nfsd_create_serv(net);
 	if (error)
 		goto out;
Signature · 1 line
2.24.1
#2 lore raw
Quoted 42 lines · J. Bruce Fields
Quoted 9 lines · Scott Mayhew

Currently, nfsd4_encode_exchange_id() encodes the utsname nodename string in the server_scope field. In a multi-host container environemnt, if an nfsd container is restarted on a different host than it was originally running on, clients will see a server_scope mismatch and will not attempt to reclaim opens.

Instead, set the server_scope while we're in a process context during service startup, so we get the utsname nodename of the current process and store that in nfsd_net.

Thanks! Just one nit:

Quoted 29 lines
---
 fs/nfsd/netns.h   | 1 +
 fs/nfsd/nfs4xdr.c | 3 ++-
 fs/nfsd/nfssvc.c  | 3 +++
 3 files changed, 6 insertions(+), 1 deletion(-)
fs/nfsd/netns.h +1 -0
index 2baf32311e00..c6d95700105e 100644
@@ -172,6 +172,7 @@ struct nfsd_net {
 	unsigned int             longest_chain_cachesize;
 
 	struct shrinker		nfsd_reply_cache_shrinker;
+	char			server_scope[UNX_MAXNODENAME+1];
 };
 
 /* Simple check to find out if a given net was properly initialized */
fs/nfsd/nfs4xdr.c +1 -0
index 9761512674a0..209174ee431a 100644
@@ -4005,10 +4005,11 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
 	int major_id_sz;
 	int server_scope_sz;
 	uint64_t minor_id = 0;
+	struct nfsd_net *nn = net_generic(SVC_NET(resp->rqstp), nfsd_net_id);
 
Quoted 4 lines

fs/nfsd/nfs4xdr.c nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr, · line 4011

Quoted 2 lines
fs/nfsd/nfs4xdr.c +0 -0
 	major_id = utsname()->nodename;
 	major_id_sz = strlen(major_id);

We should do this one too. I'll fix that up and apply if that's OK.

And then maybe "server_scope" isn't the best name for the variable any more. Applying as below if you don't see any objection.--b.

commit 9eb54e92718a

Author: Scott Mayhew <[email protected]>
Date:   Wed Feb 19 15:52:15 2020 -0500

nfsd: set the server_scope during service startup

Currently, nfsd4_encode_exchange_id() encodes the utsname nodename string in the server_scope field. In a multi-host container environemnt, if an nfsd container is restarted on a different host than it was originally running on, clients will see a server_scope mismatch and will not attempt to reclaim opens.

Instead, set the server_scope while we're in a process context during service startup, so we get the utsname nodename of the current process and store that in nfsd_net.

[bfields: fix up major_id too]
fs/nfsd/netns.h +2 -0
index 2baf32311e00..09aa545825bd 100644
@@ -172,6 +172,8 @@ struct nfsd_net {
 	unsigned int             longest_chain_cachesize;
 
 	struct shrinker		nfsd_reply_cache_shrinker;
+	/* utsname taken from the the process that starts the server */
+	char			nfsd_name[UNX_MAXNODENAME+1];
 };
 
 /* Simple check to find out if a given net was properly initialized */
fs/nfsd/nfs4xdr.c +5 -4
index 9761512674a0..ad38aed6f5c2 100644
@@ -4005,11 +4005,12 @@ nfsd4_encode_exchange_id(struct nfsd4_compoundres *resp, __be32 nfserr,
 	int major_id_sz;
 	int server_scope_sz;
 	uint64_t minor_id = 0;
+	struct nfsd_net *nn = net_generic(SVC_NET(resp->rqstp), nfsd_net_id);
 
-	major_id = utsname()->nodename;
-	major_id_sz = strlen(major_id);
-	server_scope = utsname()->nodename;
-	server_scope_sz = strlen(server_scope);
+	major_id = nn->nfsd_name;
+	major_id_sz = strlen(nn->nfsd_name);
+	server_scope = nn->nfsd_name;
+	server_scope_sz = strlen(nn->nfsd_name);
 
 	p = xdr_reserve_space(xdr,
 		8 /* eir_clientid */ +
fs/nfsd/nfssvc.c +3 -0
index 3b77b904212d..ca9fd348548b 100644
@@ -749,6 +749,9 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred)
 	if (nrservs == 0 && nn->nfsd_serv == NULL)
 		goto out;
 
+	strlcpy(nn->nfsd_name, utsname()->nodename,
+		sizeof(nn->nfsd_name));
+
 	error = nfsd_create_serv(net);
 	if (error)
 		goto out;