1
2
3
4
5
6
7
8
9
10#ifndef SUNRPC_SVC_H
11#define SUNRPC_SVC_H
12
13#include <linux/in.h>
14#include <linux/in6.h>
15#include <linux/sunrpc/types.h>
16#include <linux/sunrpc/xdr.h>
17#include <linux/sunrpc/auth.h>
18#include <linux/sunrpc/svcauth.h>
19#include <linux/wait.h>
20#include <linux/mm.h>
21
22
23
24
25typedef int (*svc_thread_fn)(void *);
26
27
28struct svc_pool_stats {
29 unsigned long packets;
30 unsigned long sockets_queued;
31 unsigned long threads_woken;
32 unsigned long threads_timedout;
33};
34
35
36
37
38
39
40
41
42
43
44
45struct svc_pool {
46 unsigned int sp_id;
47 spinlock_t sp_lock;
48 struct list_head sp_threads;
49 struct list_head sp_sockets;
50 unsigned int sp_nrthreads;
51 struct list_head sp_all_threads;
52 struct svc_pool_stats sp_stats;
53} ____cacheline_aligned_in_smp;
54
55
56
57
58
59
60
61
62
63
64
65struct svc_serv {
66 struct svc_program * sv_program;
67 struct svc_stat * sv_stats;
68 spinlock_t sv_lock;
69 unsigned int sv_nrthreads;
70 unsigned int sv_maxconn;
71
72
73
74 unsigned int sv_max_payload;
75 unsigned int sv_max_mesg;
76 unsigned int sv_xdrsize;
77 struct list_head sv_permsocks;
78 struct list_head sv_tempsocks;
79 int sv_tmpcnt;
80 struct timer_list sv_temptimer;
81
82 char * sv_name;
83
84 unsigned int sv_nrpools;
85 struct svc_pool * sv_pools;
86
87 void (*sv_shutdown)(struct svc_serv *serv,
88 struct net *net);
89
90
91
92
93 struct module * sv_module;
94
95 svc_thread_fn sv_function;
96#if defined(CONFIG_SUNRPC_BACKCHANNEL)
97 struct list_head sv_cb_list;
98
99
100 spinlock_t sv_cb_lock;
101 wait_queue_head_t sv_cb_waitq;
102
103 struct svc_xprt *sv_bc_xprt;
104#endif
105};
106
107
108
109
110
111
112
113static inline void svc_get(struct svc_serv *serv)
114{
115 serv->sv_nrthreads++;
116}
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139#define RPCSVC_MAXPAYLOAD (1*1024*1024u)
140#define RPCSVC_MAXPAYLOAD_TCP RPCSVC_MAXPAYLOAD
141#define RPCSVC_MAXPAYLOAD_UDP (32*1024u)
142
143extern u32 svc_max_payload(const struct svc_rqst *rqstp);
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172#define RPCSVC_MAXPAGES ((RPCSVC_MAXPAYLOAD+PAGE_SIZE-1)/PAGE_SIZE \
173 + 2 + 1)
174
175static inline u32 svc_getnl(struct kvec *iov)
176{
177 __be32 val, *vp;
178 vp = iov->iov_base;
179 val = *vp++;
180 iov->iov_base = (void*)vp;
181 iov->iov_len -= sizeof(__be32);
182 return ntohl(val);
183}
184
185static inline void svc_putnl(struct kvec *iov, u32 val)
186{
187 __be32 *vp = iov->iov_base + iov->iov_len;
188 *vp = htonl(val);
189 iov->iov_len += sizeof(__be32);
190}
191
192static inline __be32 svc_getu32(struct kvec *iov)
193{
194 __be32 val, *vp;
195 vp = iov->iov_base;
196 val = *vp++;
197 iov->iov_base = (void*)vp;
198 iov->iov_len -= sizeof(__be32);
199 return val;
200}
201
202static inline void svc_ungetu32(struct kvec *iov)
203{
204 __be32 *vp = (__be32 *)iov->iov_base;
205 iov->iov_base = (void *)(vp - 1);
206 iov->iov_len += sizeof(*vp);
207}
208
209static inline void svc_putu32(struct kvec *iov, __be32 val)
210{
211 __be32 *vp = iov->iov_base + iov->iov_len;
212 *vp = val;
213 iov->iov_len += sizeof(__be32);
214}
215
216
217
218
219
220struct svc_rqst {
221 struct list_head rq_list;
222 struct list_head rq_all;
223 struct svc_xprt * rq_xprt;
224
225 struct sockaddr_storage rq_addr;
226 size_t rq_addrlen;
227 struct sockaddr_storage rq_daddr;
228
229 size_t rq_daddrlen;
230
231 struct svc_serv * rq_server;
232 struct svc_pool * rq_pool;
233 struct svc_procedure * rq_procinfo;
234 struct auth_ops * rq_authop;
235 struct svc_cred rq_cred;
236 void * rq_xprt_ctxt;
237 struct svc_deferred_req*rq_deferred;
238 int rq_usedeferral;
239
240 size_t rq_xprt_hlen;
241 struct xdr_buf rq_arg;
242 struct xdr_buf rq_res;
243 struct page * rq_pages[RPCSVC_MAXPAGES];
244 struct page * *rq_respages;
245 int rq_resused;
246
247 struct kvec rq_vec[RPCSVC_MAXPAGES];
248
249 __be32 rq_xid;
250 u32 rq_prog;
251 u32 rq_vers;
252 u32 rq_proc;
253 u32 rq_prot;
254 unsigned short
255 rq_secure : 1;
256
257 void * rq_argp;
258 void * rq_resp;
259 void * rq_auth_data;
260
261 int rq_reserved;
262
263
264
265 struct cache_req rq_chandle;
266
267
268 bool rq_dropme;
269
270 struct auth_domain * rq_client;
271 struct auth_domain * rq_gssclient;
272 int rq_cachetype;
273 struct svc_cacherep * rq_cacherep;
274 int rq_splice_ok;
275
276
277 wait_queue_head_t rq_wait;
278 struct task_struct *rq_task;
279};
280
281#define SVC_NET(svc_rqst) (svc_rqst->rq_xprt->xpt_net)
282
283
284
285
286static inline struct sockaddr_in *svc_addr_in(const struct svc_rqst *rqst)
287{
288 return (struct sockaddr_in *) &rqst->rq_addr;
289}
290
291static inline struct sockaddr_in6 *svc_addr_in6(const struct svc_rqst *rqst)
292{
293 return (struct sockaddr_in6 *) &rqst->rq_addr;
294}
295
296static inline struct sockaddr *svc_addr(const struct svc_rqst *rqst)
297{
298 return (struct sockaddr *) &rqst->rq_addr;
299}
300
301static inline struct sockaddr_in *svc_daddr_in(const struct svc_rqst *rqst)
302{
303 return (struct sockaddr_in *) &rqst->rq_daddr;
304}
305
306static inline struct sockaddr_in6 *svc_daddr_in6(const struct svc_rqst *rqst)
307{
308 return (struct sockaddr_in6 *) &rqst->rq_daddr;
309}
310
311static inline struct sockaddr *svc_daddr(const struct svc_rqst *rqst)
312{
313 return (struct sockaddr *) &rqst->rq_daddr;
314}
315
316
317
318
319static inline int
320xdr_argsize_check(struct svc_rqst *rqstp, __be32 *p)
321{
322 char *cp = (char *)p;
323 struct kvec *vec = &rqstp->rq_arg.head[0];
324 return cp >= (char*)vec->iov_base
325 && cp <= (char*)vec->iov_base + vec->iov_len;
326}
327
328static inline int
329xdr_ressize_check(struct svc_rqst *rqstp, __be32 *p)
330{
331 struct kvec *vec = &rqstp->rq_res.head[0];
332 char *cp = (char*)p;
333
334 vec->iov_len = cp - (char*)vec->iov_base;
335
336 return vec->iov_len <= PAGE_SIZE;
337}
338
339static inline void svc_free_res_pages(struct svc_rqst *rqstp)
340{
341 while (rqstp->rq_resused) {
342 struct page **pp = (rqstp->rq_respages +
343 --rqstp->rq_resused);
344 if (*pp) {
345 put_page(*pp);
346 *pp = NULL;
347 }
348 }
349}
350
351struct svc_deferred_req {
352 u32 prot;
353 struct svc_xprt *xprt;
354 struct sockaddr_storage addr;
355 size_t addrlen;
356 struct sockaddr_storage daddr;
357 size_t daddrlen;
358 struct cache_deferred_req handle;
359 size_t xprt_hlen;
360 int argslen;
361 __be32 args[0];
362};
363
364
365
366
367struct svc_program {
368 struct svc_program * pg_next;
369 u32 pg_prog;
370 unsigned int pg_lovers;
371 unsigned int pg_hivers;
372 unsigned int pg_nvers;
373 struct svc_version ** pg_vers;
374 char * pg_name;
375 char * pg_class;
376 struct svc_stat * pg_stats;
377 int (*pg_authenticate)(struct svc_rqst *);
378};
379
380
381
382
383struct svc_version {
384 u32 vs_vers;
385 u32 vs_nproc;
386 struct svc_procedure * vs_proc;
387 u32 vs_xdrsize;
388
389 unsigned int vs_hidden : 1;
390
391
392
393
394
395
396 int (*vs_dispatch)(struct svc_rqst *, __be32 *);
397};
398
399
400
401
402typedef __be32 (*svc_procfunc)(struct svc_rqst *, void *argp, void *resp);
403struct svc_procedure {
404 svc_procfunc pc_func;
405 kxdrproc_t pc_decode;
406 kxdrproc_t pc_encode;
407 kxdrproc_t pc_release;
408 unsigned int pc_argsize;
409 unsigned int pc_ressize;
410 unsigned int pc_count;
411 unsigned int pc_cachetype;
412 unsigned int pc_xdrressize;
413};
414
415
416
417
418int svc_rpcb_setup(struct svc_serv *serv, struct net *net);
419void svc_rpcb_cleanup(struct svc_serv *serv, struct net *net);
420int svc_bind(struct svc_serv *serv, struct net *net);
421struct svc_serv *svc_create(struct svc_program *, unsigned int,
422 void (*shutdown)(struct svc_serv *, struct net *net));
423struct svc_rqst *svc_prepare_thread(struct svc_serv *serv,
424 struct svc_pool *pool, int node);
425void svc_exit_thread(struct svc_rqst *);
426struct svc_serv * svc_create_pooled(struct svc_program *, unsigned int,
427 void (*shutdown)(struct svc_serv *, struct net *net),
428 svc_thread_fn, struct module *);
429int svc_set_num_threads(struct svc_serv *, struct svc_pool *, int);
430int svc_pool_stats_open(struct svc_serv *serv, struct file *file);
431void svc_destroy(struct svc_serv *);
432void svc_shutdown_net(struct svc_serv *, struct net *);
433int svc_process(struct svc_rqst *);
434int bc_svc_process(struct svc_serv *, struct rpc_rqst *,
435 struct svc_rqst *);
436int svc_register(const struct svc_serv *, struct net *, const int,
437 const unsigned short, const unsigned short);
438
439void svc_wake_up(struct svc_serv *);
440void svc_reserve(struct svc_rqst *rqstp, int space);
441struct svc_pool * svc_pool_for_cpu(struct svc_serv *serv, int cpu);
442char * svc_print_addr(struct svc_rqst *, char *, size_t);
443
444#define RPC_MAX_ADDRBUFLEN (63U)
445
446
447
448
449
450
451
452
453static inline void svc_reserve_auth(struct svc_rqst *rqstp, int space)
454{
455 int added_space = 0;
456
457 if (rqstp->rq_authop->flavour)
458 added_space = RPC_MAX_AUTH_SIZE;
459 svc_reserve(rqstp, space + added_space);
460}
461
462#endif
463