1 From 026255b4acd23ff7758be0d33ba77f541a4e8ce6 Mon Sep 17 00:00:00 2001
2 From: Sasha Levin <sashal@kernel.org>
3 Date: Wed, 16 Feb 2022 12:16:27 -0500
4 Subject: NFSD: Move svc_serv_ops::svo_function into struct svc_serv
6 From: Chuck Lever <chuck.lever@oracle.com>
8 [ Upstream commit 37902c6313090235c847af89c5515591261ee338 ]
10 Hoist svo_function back into svc_serv and remove struct
11 svc_serv_ops, since the struct is now devoid of fields.
13 Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
15 fs/lockd/svc.c | 6 +-----
16 fs/nfs/callback.c | 43 ++++++++++----------------------------
17 fs/nfsd/nfssvc.c | 7 +------
18 include/linux/sunrpc/svc.h | 14 ++++---------
19 net/sunrpc/svc.c | 37 ++++++++++++++++++++++----------
20 5 files changed, 43 insertions(+), 64 deletions(-)
22 diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
23 index bfde31124f3af..59ef8a1f843f3 100644
26 @@ -349,10 +349,6 @@ static struct notifier_block lockd_inet6addr_notifier = {
30 -static const struct svc_serv_ops lockd_sv_ops = {
31 - .svo_function = lockd,
34 static int lockd_get(void)
36 struct svc_serv *serv;
37 @@ -376,7 +372,7 @@ static int lockd_get(void)
38 nlm_timeout = LOCKD_DFLT_TIMEO;
39 nlmsvc_timeout = nlm_timeout * HZ;
41 - serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, &lockd_sv_ops);
42 + serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, lockd);
44 printk(KERN_WARNING "lockd_up: create service failed\n");
46 diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
47 index a494f9e7bd0a0..456af7d230cf1 100644
48 --- a/fs/nfs/callback.c
49 +++ b/fs/nfs/callback.c
50 @@ -231,29 +231,10 @@ static int nfs_callback_up_net(int minorversion, struct svc_serv *serv,
54 -static const struct svc_serv_ops nfs40_cb_sv_ops = {
55 - .svo_function = nfs4_callback_svc,
57 -#if defined(CONFIG_NFS_V4_1)
58 -static const struct svc_serv_ops nfs41_cb_sv_ops = {
59 - .svo_function = nfs41_callback_svc,
62 -static const struct svc_serv_ops *nfs4_cb_sv_ops[] = {
63 - [0] = &nfs40_cb_sv_ops,
64 - [1] = &nfs41_cb_sv_ops,
67 -static const struct svc_serv_ops *nfs4_cb_sv_ops[] = {
68 - [0] = &nfs40_cb_sv_ops,
73 static struct svc_serv *nfs_callback_create_svc(int minorversion)
75 struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion];
76 - const struct svc_serv_ops *sv_ops;
77 + int (*threadfn)(void *data);
78 struct svc_serv *serv;
81 @@ -262,17 +243,6 @@ static struct svc_serv *nfs_callback_create_svc(int minorversion)
83 return svc_get(cb_info->serv);
85 - switch (minorversion) {
87 - sv_ops = nfs4_cb_sv_ops[0];
90 - sv_ops = nfs4_cb_sv_ops[1];
94 - return ERR_PTR(-ENOTSUPP);
97 * Sanity check: if there's no task,
98 * we should be the first user ...
99 @@ -281,7 +251,16 @@ static struct svc_serv *nfs_callback_create_svc(int minorversion)
100 printk(KERN_WARNING "nfs_callback_create_svc: no kthread, %d users??\n",
103 - serv = svc_create(&nfs4_callback_program, NFS4_CALLBACK_BUFSIZE, sv_ops);
104 + threadfn = nfs4_callback_svc;
105 +#if defined(CONFIG_NFS_V4_1)
107 + threadfn = nfs41_callback_svc;
110 + return ERR_PTR(-ENOTSUPP);
112 + serv = svc_create(&nfs4_callback_program, NFS4_CALLBACK_BUFSIZE,
115 printk(KERN_ERR "nfs_callback_create_svc: create service failed\n");
116 return ERR_PTR(-ENOMEM);
117 diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
118 index d25d4c12a499a..2f74be98ff2d9 100644
119 --- a/fs/nfsd/nfssvc.c
120 +++ b/fs/nfsd/nfssvc.c
121 @@ -612,10 +612,6 @@ static int nfsd_get_default_max_blksize(void)
125 -static const struct svc_serv_ops nfsd_thread_sv_ops = {
126 - .svo_function = nfsd,
129 void nfsd_shutdown_threads(struct net *net)
131 struct nfsd_net *nn = net_generic(net, nfsd_net_id);
132 @@ -654,8 +650,7 @@ int nfsd_create_serv(struct net *net)
133 if (nfsd_max_blksize == 0)
134 nfsd_max_blksize = nfsd_get_default_max_blksize();
135 nfsd_reset_versions(nn);
136 - serv = svc_create_pooled(&nfsd_program, nfsd_max_blksize,
137 - &nfsd_thread_sv_ops);
138 + serv = svc_create_pooled(&nfsd_program, nfsd_max_blksize, nfsd);
142 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
143 index 61768495354a0..1d9a81bab3fa2 100644
144 --- a/include/linux/sunrpc/svc.h
145 +++ b/include/linux/sunrpc/svc.h
146 @@ -52,13 +52,6 @@ struct svc_pool {
147 unsigned long sp_flags;
148 } ____cacheline_aligned_in_smp;
152 -struct svc_serv_ops {
153 - /* function for service threads to run */
154 - int (*svo_function)(void *);
160 @@ -91,7 +84,8 @@ struct svc_serv {
162 unsigned int sv_nrpools; /* number of thread pools */
163 struct svc_pool * sv_pools; /* array of thread pools */
164 - const struct svc_serv_ops *sv_ops; /* server operations */
165 + int (*sv_threadfn)(void *data);
167 #if defined(CONFIG_SUNRPC_BACKCHANNEL)
168 struct list_head sv_cb_list; /* queue for callback requests
169 * that arrive over the same
170 @@ -494,7 +488,7 @@ int svc_rpcb_setup(struct svc_serv *serv, struct net *net);
171 void svc_rpcb_cleanup(struct svc_serv *serv, struct net *net);
172 int svc_bind(struct svc_serv *serv, struct net *net);
173 struct svc_serv *svc_create(struct svc_program *, unsigned int,
174 - const struct svc_serv_ops *);
175 + int (*threadfn)(void *data));
176 struct svc_rqst *svc_rqst_alloc(struct svc_serv *serv,
177 struct svc_pool *pool, int node);
178 void svc_rqst_replace_page(struct svc_rqst *rqstp,
179 @@ -502,7 +496,7 @@ void svc_rqst_replace_page(struct svc_rqst *rqstp,
180 void svc_rqst_free(struct svc_rqst *);
181 void svc_exit_thread(struct svc_rqst *);
182 struct svc_serv * svc_create_pooled(struct svc_program *, unsigned int,
183 - const struct svc_serv_ops *);
184 + int (*threadfn)(void *data));
185 int svc_set_num_threads(struct svc_serv *, struct svc_pool *, int);
186 int svc_pool_stats_open(struct svc_serv *serv, struct file *file);
187 int svc_process(struct svc_rqst *);
188 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
189 index 239d10018216a..87da3ff46ce9a 100644
190 --- a/net/sunrpc/svc.c
191 +++ b/net/sunrpc/svc.c
192 @@ -448,7 +448,7 @@ __svc_init_bc(struct svc_serv *serv)
194 static struct svc_serv *
195 __svc_create(struct svc_program *prog, unsigned int bufsize, int npools,
196 - const struct svc_serv_ops *ops)
197 + int (*threadfn)(void *data))
199 struct svc_serv *serv;
201 @@ -465,7 +465,7 @@ __svc_create(struct svc_program *prog, unsigned int bufsize, int npools,
202 bufsize = RPCSVC_MAXPAYLOAD;
203 serv->sv_max_payload = bufsize? bufsize : 4096;
204 serv->sv_max_mesg = roundup(serv->sv_max_payload + PAGE_SIZE, PAGE_SIZE);
205 - serv->sv_ops = ops;
206 + serv->sv_threadfn = threadfn;
209 prog->pg_lovers = prog->pg_nvers-1;
210 @@ -511,22 +511,37 @@ __svc_create(struct svc_program *prog, unsigned int bufsize, int npools,
215 -svc_create(struct svc_program *prog, unsigned int bufsize,
216 - const struct svc_serv_ops *ops)
218 + * svc_create - Create an RPC service
219 + * @prog: the RPC program the new service will handle
220 + * @bufsize: maximum message size for @prog
221 + * @threadfn: a function to service RPC requests for @prog
223 + * Returns an instantiated struct svc_serv object or NULL.
225 +struct svc_serv *svc_create(struct svc_program *prog, unsigned int bufsize,
226 + int (*threadfn)(void *data))
228 - return __svc_create(prog, bufsize, /*npools*/1, ops);
229 + return __svc_create(prog, bufsize, 1, threadfn);
231 EXPORT_SYMBOL_GPL(svc_create);
234 -svc_create_pooled(struct svc_program *prog, unsigned int bufsize,
235 - const struct svc_serv_ops *ops)
237 + * svc_create_pooled - Create an RPC service with pooled threads
238 + * @prog: the RPC program the new service will handle
239 + * @bufsize: maximum message size for @prog
240 + * @threadfn: a function to service RPC requests for @prog
242 + * Returns an instantiated struct svc_serv object or NULL.
244 +struct svc_serv *svc_create_pooled(struct svc_program *prog,
245 + unsigned int bufsize,
246 + int (*threadfn)(void *data))
248 struct svc_serv *serv;
249 unsigned int npools = svc_pool_map_get();
251 - serv = __svc_create(prog, bufsize, npools, ops);
252 + serv = __svc_create(prog, bufsize, npools, threadfn);
256 @@ -736,7 +751,7 @@ svc_start_kthreads(struct svc_serv *serv, struct svc_pool *pool, int nrservs)
258 return PTR_ERR(rqstp);
260 - task = kthread_create_on_node(serv->sv_ops->svo_function, rqstp,
261 + task = kthread_create_on_node(serv->sv_threadfn, rqstp,
262 node, "%s", serv->sv_name);
264 svc_exit_thread(rqstp);