NFSD: simplify error paths in nfsd_svc()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: NeilBrown <neilb@xxxxxxx>

[ Upstream commit bf32075256e9dd9c6b736859e2c5813981339908 ]

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@xxxxxxx>
Reviewed-by: Jeff Layton <jlayton@xxxxxxxxxx>
Signed-off-by: Chuck Lever <chuck.lever@xxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 fs/nfsd/nfssvc.c |   14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -567,7 +567,6 @@ void nfsd_last_thread(struct net *net)
 		return;
 
 	nfsd_shutdown_net(net);
-	pr_info("nfsd: last server has exited, flushing export cache\n");
 	nfsd_export_flush(net);
 }
 
@@ -782,7 +781,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;
 
@@ -802,8 +800,6 @@ nfsd_svc(int nrservs, struct net *net, c
 	error = nfsd_create_serv(net);
 	if (error)
 		goto out;
-
-	nfsd_up_before = nn->nfsd_net_up;
 	serv = nn->nfsd_serv;
 
 	error = nfsd_startup_net(net, cred);
@@ -811,17 +807,15 @@ nfsd_svc(int nrservs, struct net *net, c
 		goto out_put;
 	error = svc_set_num_threads(serv, NULL, nrservs);
 	if (error)
-		goto out_shutdown;
+		goto out_put;
 	error = serv->sv_nrthreads;
-	if (error == 0)
-		nfsd_last_thread(net);
-out_shutdown:
-	if (error < 0 && !nfsd_up_before)
-		nfsd_shutdown_net(net);
 out_put:
 	/* Threads now hold service active */
 	if (xchg(&nn->keep_active, 0))
 		svc_put(serv);
+
+	if (serv->sv_nrthreads == 0)
+		nfsd_last_thread(net);
 	svc_put(serv);
 out:
 	mutex_unlock(&nfsd_mutex);


Patches currently in stable-queue which might be from cel@xxxxxxxxxx are

queue-5.10/nfsd-rename-nfsd_net_-to-nfsd_stats_.patch
queue-5.10/nfsd-rename-nfsd_reply_cache_alloc.patch
queue-5.10/nfsd-simplify-error-paths-in-nfsd_svc.patch
queue-5.10/sunrpc-pass-in-the-sv_stats-struct-through-svc_create_pooled.patch
queue-5.10/nfsd-move-init-of-percpu-reply_cache_stats-counters-back-to-nfsd_init_net.patch
queue-5.10/sunrpc-use-the-struct-net-as-the-svc-proc-private.patch
queue-5.10/nfsd-rewrite-synopsis-of-nfsd_percpu_counters_init.patch
queue-5.10/nfsd-replace-nfsd_prune_bucket.patch
queue-5.10/nfsd-refactor-the-duplicate-reply-cache-shrinker.patch
queue-5.10/sunrpc-remove-pg_stats-from-svc_program.patch
queue-5.10/nfsd-make-all-of-the-nfsd-stats-per-network-namespace.patch
queue-5.10/nfsd-fix-frame-size-warning-in-svc_export_parse.patch
queue-5.10/nfsd-expose-proc-net-sunrpc-nfsd-in-net-namespaces.patch
queue-5.10/nfsd-move-reply-cache-initialization-into-nfsd-startup.patch
queue-5.10/nfsd-remove-nfsd_stats-make-th_cnt-a-global-counter.patch
queue-5.10/nfsd-make-svc_stat-per-network-namespace-instead-of-global.patch
queue-5.10/sunrpc-don-t-change-sv_stats-if-it-doesn-t-exist.patch
queue-5.10/nfsd-refactor-nfsd_reply_cache_free_locked.patch
queue-5.10/nfsd-stop-setting-pg_stats-for-unused-stats.patch




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux