Skip to content

Commit bf32075

Browse files
neilbrownchucklever
authored andcommitted
NFSD: simplify error paths in nfsd_svc()
The error paths in nfsd_svc() are needlessly complex and can result in a final call to svc_put() without nfsd_last_thread() being called. This results in the listening sockets not being closed properly. The per-netns setup provided by nfsd_startup_new() and removed by nfsd_shutdown_net() is needed precisely when there are running threads. So we don't need nfsd_up_before. We don't need to know if it *was* up. We only need to know if any threads are left. If none are, then we must call nfsd_shutdown_net(). But we don't need to do that explicitly as nfsd_last_thread() does that for us. So simply call nfsd_last_thread() before the last svc_put() if there are no running threads. That will always do the right thing. Also discard: pr_info("nfsd: last server has exited, flushing export cache\n"); It may not be true if an attempt to start the first server failed, and it isn't particularly helpful and it simply reports normal behaviour. Signed-off-by: NeilBrown <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 1f121e2 commit bf32075

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

fs/nfsd/nfssvc.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,6 @@ static void nfsd_last_thread(struct net *net)
572572
return;
573573

574574
nfsd_shutdown_net(net);
575-
pr_info("nfsd: last server has exited, flushing export cache\n");
576575
nfsd_export_flush(net);
577576
}
578577

@@ -786,7 +785,6 @@ int
786785
nfsd_svc(int nrservs, struct net *net, const struct cred *cred)
787786
{
788787
int error;
789-
bool nfsd_up_before;
790788
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
791789
struct svc_serv *serv;
792790

@@ -806,26 +804,22 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred)
806804
error = nfsd_create_serv(net);
807805
if (error)
808806
goto out;
809-
810-
nfsd_up_before = nn->nfsd_net_up;
811807
serv = nn->nfsd_serv;
812808

813809
error = nfsd_startup_net(net, cred);
814810
if (error)
815811
goto out_put;
816812
error = svc_set_num_threads(serv, NULL, nrservs);
817813
if (error)
818-
goto out_shutdown;
814+
goto out_put;
819815
error = serv->sv_nrthreads;
820-
if (error == 0)
821-
nfsd_last_thread(net);
822-
out_shutdown:
823-
if (error < 0 && !nfsd_up_before)
824-
nfsd_shutdown_net(net);
825816
out_put:
826817
/* Threads now hold service active */
827818
if (xchg(&nn->keep_active, 0))
828819
svc_put(serv);
820+
821+
if (serv->sv_nrthreads == 0)
822+
nfsd_last_thread(net);
829823
svc_put(serv);
830824
out:
831825
mutex_unlock(&nfsd_mutex);

0 commit comments

Comments
 (0)