nfsd: fix error handling in nfsd_svc
Subsystems (2)
Jeff Layton
maintainerRFC PATCH 1/1 nfsd: fix error handling in nfsd_svc
Once we've set the nfsd_serv pointer in nfsd_svc, we still need to call nfsd_last_thread if the server fails to be started. Remove the special casing for nfsd_up_before case since shutting down the per-net stuff is also handled by nfsd_last_thread.
Finally, add a new special case at the start and skip doing anything if the service already exists, 0 threads were requested and serv->sv_nrthreads is 0.
---
Here's what I was thinking for a targeted patch for stable. Testing it now, but I won't have results until tomorrow.
--- fs/nfsd/nfssvc.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
fs/nfsd/nfssvc.c +5 -10
@@ -787,7 +787,6 @@ int nfsd_svc(int nrservs, struct net *net, const struct cred *cred) { int error; -bool nfsd_up_before;struct nfsd_net *nn =net_generic (net, nfsd_net_id);struct svc_serv *serv;
@@ -797,8 +796,9 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred) nrservs =max (nrservs,0 ); nrservs =min (nrservs,NFSD_MAXSERVS ); error =0 ; + serv = nn->nfsd_serv; -if (nrservs ==0 && nn->nfsd_serv ==NULL ) +if (nrservs ==0 && (serv ==NULL || serv->sv_nrthreads ==0 )) goto out; strscpy(nn->nfsd_name, utsname()->nodename,
@@ -808,22 +808,17 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred)if (error) goto out; - nfsd_up_before = nn->nfsd_net_up; serv = nn->nfsd_serv; error =nfsd_startup_net (net, cred);if (error) goto out_put; error =svc_set_num_threads (serv,NULL , nrservs); -if (error) - goto out_shutdown; - error = serv->sv_nrthreads;if (error ==0 ) -nfsd_last_thread (net); -out_shutdown: -if (error <0 && !nfsd_up_before) -nfsd_shutdown_net (net); + error = serv->sv_nrthreads; out_put: +if (serv->sv_nrthreads ==0 ) +nfsd_last_thread (net);/* Threads now hold service active */ if (xchg (&nn->keep_active,0 ))svc_put (serv);
---
base-commit: 31b5a36c4b88b44c91cdd523997b1e86fb47339d
change-id: 20231030-kdevops-5f7366897ef4
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 8 lines · Jeff Layton
Once we've set the
nfsd_servpointer innfsd_svc, we still need to callnfsd_last_threadif the server fails to be started. Remove the special casing fornfsd_up_beforecase since shutting down the per-net stuff is also handled bynfsd_last_thread.Finally, add a new special case at the start and skip doing anything if the service already exists, 0 threads were requested and
serv->sv_nrthreadsis 0.
This is very similar to my
Commit bf32075256e9 ("NFSD: simplify error paths in nfsd_svc()")
The main difference being that special case you mention. I don't like that bit.
If I run "rpc.nfsd 0" then I want the nfsd_svc to be destroyed, whether there were threads running or not.
Is there a reason my patch isn't sufficient?
Thanks,
NeilBrown
Quoted 70 lines
Fixes 9f28a971ee9f ("nfsd: separate nfsd_last_thread() from nfsd_put()")Reported-by Zhi Li <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
Here's what I was thinking for a targeted patch for stable. Testing it now, but I won't have results until tomorrow.--- fs/nfsd/nfssvc.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)fs/nfsd/nfssvc.c +5
-11@@ -787,7 +787,6 @@ int nfsd_svc(int nrservs, struct net *net, const struct cred *cred) { int error; -bool nfsd_up_before;struct nfsd_net *nn =net_generic (net, nfsd_net_id);struct svc_serv *serv;@@ -797,8 +796,9 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred) nrservs =max (nrservs,0 ); nrservs =min (nrservs,NFSD_MAXSERVS ); error =0 ; + serv = nn->nfsd_serv; -if (nrservs ==0 && nn->nfsd_serv ==NULL ) +if (nrservs ==0 && (serv ==NULL || serv->sv_nrthreads ==0 )) goto out; strscpy(nn->nfsd_name, utsname()->nodename,@@ -808,22 +808,17 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred)if (error) goto out; - nfsd_up_before = nn->nfsd_net_up; serv = nn->nfsd_serv; error =nfsd_startup_net (net, cred);if (error) goto out_put; error =svc_set_num_threads (serv,NULL , nrservs); -if (error) - goto out_shutdown; - error = serv->sv_nrthreads;if (error ==0 ) -nfsd_last_thread (net); -out_shutdown: -if (error <0 && !nfsd_up_before) -nfsd_shutdown_net (net); + error = serv->sv_nrthreads; out_put: +if (serv->sv_nrthreads ==0 ) +nfsd_last_thread (net);/* Threads now hold service active */ if (xchg (&nn->keep_active,0 ))svc_put (serv); ---base-commit:
31b5a36c4b88b44c91cdd523997b1e86fb47339d
change-id: 20231030-kdevops-5f7366897ef4Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Jeff Layton
maintainerQuoted 13 lines · NeilBrown
Quoted 8 lines · Jeff Layton
Once we've set the
nfsd_servpointer innfsd_svc, we still need to callnfsd_last_threadif the server fails to be started. Remove the special casing fornfsd_up_beforecase since shutting down the per-net stuff is also handled bynfsd_last_thread.Finally, add a new special case at the start and skip doing anything if the service already exists, 0 threads were requested and
serv->sv_nrthreadsis 0.This is very similar to my
Commitbf32075256e9("NFSD: simplify error paths innfsd_svc()")
Quoted 7 lines
The main difference being that special case you mention. I don't like that bit.
If I run "rpc.nfsd 0" then I want thenfsd_svcto be destroyed, whether there were threads running or not.Is there a reason my patch isn't sufficient?
Ok, I wasn't sure whether that was the desired behavior or not. Your patch should be fine actually, and it has already had some testing, so let's just mark that for stable?
Quoted 75 lines
Thanks,
NeilBrownQuoted 70 lines
Fixes 9f28a971ee9f ("nfsd: separate nfsd_last_thread() from nfsd_put()")Reported-by Zhi Li <[email protected]>Signed-off-by Jeff Layton <[email protected]>---
Here's what I was thinking for a targeted patch for stable. Testing it now, but I won't have results until tomorrow.--- fs/nfsd/nfssvc.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)fs/nfsd/nfssvc.c +5
-11@@ -787,7 +787,6 @@ int nfsd_svc(int nrservs, struct net *net, const struct cred *cred) { int error; -bool nfsd_up_before;struct nfsd_net *nn =net_generic (net, nfsd_net_id);struct svc_serv *serv;@@ -797,8 +796,9 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred) nrservs =max (nrservs,0 ); nrservs =min (nrservs,NFSD_MAXSERVS ); error =0 ; + serv = nn->nfsd_serv; -if (nrservs ==0 && nn->nfsd_serv ==NULL ) +if (nrservs ==0 && (serv ==NULL || serv->sv_nrthreads ==0 )) goto out; strscpy(nn->nfsd_name, utsname()->nodename,@@ -808,22 +808,17 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred)if (error) goto out; - nfsd_up_before = nn->nfsd_net_up; serv = nn->nfsd_serv; error =nfsd_startup_net (net, cred);if (error) goto out_put; error =svc_set_num_threads (serv,NULL , nrservs); -if (error) - goto out_shutdown; - error = serv->sv_nrthreads;if (error ==0 ) -nfsd_last_thread (net); -out_shutdown: -if (error <0 && !nfsd_up_before) -nfsd_shutdown_net (net); + error = serv->sv_nrthreads; out_put: +if (serv->sv_nrthreads ==0 ) +nfsd_last_thread (net);/* Threads now hold service active */ if (xchg (&nn->keep_active,0 ))svc_put (serv); ---base-commit:
31b5a36c4b88b44c91cdd523997b1e86fb47339d
change-id: 20231030-kdevops-5f7366897ef4Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Signature · 1 line
Jeff Layton <[email protected]>