Skip to content

Commit e3191a7

Browse files
neilbrownanodos325
authored andcommitted
NFSD: simplify error paths in nfsd_svc()
commit bf32075 upstream. 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 <neilb@suse.de> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Reported-by: Li Lingfeng <lilingfeng3@huawei.com> Suggested-by: Li Lingfeng <lilingfeng3@huawei.com> Tested-by: Li Lingfeng <lilingfeng3@huawei.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8013010 commit e3191a7

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 @@ 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

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

@@ -807,26 +805,22 @@ nfsd_svc(int nrservs, struct net *net, const struct cred *cred)
807805
error = nfsd_create_serv(net);
808806
if (error)
809807
goto out;
810-
811-
nfsd_up_before = nn->nfsd_net_up;
812808
serv = nn->nfsd_serv;
813809

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

0 commit comments

Comments
 (0)