1 From c3cd2872f4aed958f70d7f871ea6cf3ff29d4674 Mon Sep 17 00:00:00 2001
2 From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
3 Date: Sat, 13 Jan 2024 10:38:35 +0100
4 Subject: Revert "nfsd: separate nfsd_last_thread() from nfsd_put()"
6 From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
8 This reverts commit 03d68ffc48b94cc1e15bbf3b4f16f1e1e4fa286a which is
9 commit 9f28a971ee9fdf1bf8ce8c88b103f483be610277 upstream.
11 It is reported to cause issues, so revert it.
13 Reported-by: email200202 <email200202@yahoo.com>
14 Link: https://lore.kernel.org/r/e341cb408b5663d8c91b8fa57b41bb984be43448.camel@kernel.org
15 Cc: NeilBrown <neilb@suse.de>
16 Cc: Jeff Layton <jlayton@kernel.org>
17 Cc: Chuck Lever <chuck.lever@oracle.com>
18 Cc: Sasha Levin <sashal@kernel.org>
19 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
21 fs/nfsd/nfsd.h | 7 +------
22 fs/nfsd/nfssvc.c | 52 +++++++++++++++++++++++++++++++++-------------------
23 2 files changed, 34 insertions(+), 25 deletions(-)
27 @@ -97,12 +97,7 @@ int nfsd_pool_stats_open(struct inode *
28 int nfsd_pool_stats_release(struct inode *, struct file *);
29 void nfsd_shutdown_threads(struct net *net);
31 -static inline void nfsd_put(struct net *net)
33 - struct nfsd_net *nn = net_generic(net, nfsd_net_id);
35 - svc_put(nn->nfsd_serv);
37 +void nfsd_put(struct net *net);
41 --- a/fs/nfsd/nfssvc.c
42 +++ b/fs/nfsd/nfssvc.c
43 @@ -523,14 +523,9 @@ static struct notifier_block nfsd_inet6a
44 /* Only used under nfsd_mutex, so this atomic may be overkill: */
45 static atomic_t nfsd_notifier_refcount = ATOMIC_INIT(0);
47 -static void nfsd_last_thread(struct net *net)
48 +static void nfsd_last_thread(struct svc_serv *serv, struct net *net)
50 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
51 - struct svc_serv *serv = nn->nfsd_serv;
53 - spin_lock(&nfsd_notifier_lock);
54 - nn->nfsd_serv = NULL;
55 - spin_unlock(&nfsd_notifier_lock);
57 /* check if the notifier still has clients */
58 if (atomic_dec_return(&nfsd_notifier_refcount) == 0) {
59 @@ -540,8 +535,6 @@ static void nfsd_last_thread(struct net
63 - svc_xprt_destroy_all(serv, net);
66 * write_ports can create the server without actually starting
67 * any threads--if we get shut down before any threads are
68 @@ -632,8 +625,7 @@ void nfsd_shutdown_threads(struct net *n
70 /* Kill outstanding nfsd threads */
71 svc_set_num_threads(serv, NULL, 0);
72 - nfsd_last_thread(net);
75 mutex_unlock(&nfsd_mutex);
78 @@ -663,6 +655,9 @@ int nfsd_create_serv(struct net *net)
79 serv->sv_maxconn = nn->max_connections;
80 error = svc_bind(serv, net);
82 + /* NOT nfsd_put() as notifiers (see below) haven't
88 @@ -705,6 +700,29 @@ int nfsd_get_nrthreads(int n, int *nthre
92 +/* This is the callback for kref_put() below.
93 + * There is no code here as the first thing to be done is
94 + * call svc_shutdown_net(), but we cannot get the 'net' from
95 + * the kref. So do all the work when kref_put returns true.
97 +static void nfsd_noop(struct kref *ref)
101 +void nfsd_put(struct net *net)
103 + struct nfsd_net *nn = net_generic(net, nfsd_net_id);
105 + if (kref_put(&nn->nfsd_serv->sv_refcnt, nfsd_noop)) {
106 + svc_xprt_destroy_all(nn->nfsd_serv, net);
107 + nfsd_last_thread(nn->nfsd_serv, net);
108 + svc_destroy(&nn->nfsd_serv->sv_refcnt);
109 + spin_lock(&nfsd_notifier_lock);
110 + nn->nfsd_serv = NULL;
111 + spin_unlock(&nfsd_notifier_lock);
115 int nfsd_set_nrthreads(int n, int *nthreads, struct net *net)
118 @@ -755,7 +773,7 @@ int nfsd_set_nrthreads(int n, int *nthre
122 - svc_put(nn->nfsd_serv);
127 @@ -770,7 +788,6 @@ nfsd_svc(int nrservs, struct net *net, c
130 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
131 - struct svc_serv *serv;
133 mutex_lock(&nfsd_mutex);
134 dprintk("nfsd: creating service\n");
135 @@ -790,25 +807,22 @@ nfsd_svc(int nrservs, struct net *net, c
138 nfsd_up_before = nn->nfsd_net_up;
139 - serv = nn->nfsd_serv;
141 error = nfsd_startup_net(net, cred);
144 - error = svc_set_num_threads(serv, NULL, nrservs);
145 + error = svc_set_num_threads(nn->nfsd_serv, NULL, nrservs);
148 - error = serv->sv_nrthreads;
150 - nfsd_last_thread(net);
151 + error = nn->nfsd_serv->sv_nrthreads;
153 if (error < 0 && !nfsd_up_before)
154 nfsd_shutdown_net(net);
156 /* Threads now hold service active */
157 if (xchg(&nn->keep_active, 0))
163 mutex_unlock(&nfsd_mutex);