Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | /* |
3 | * linux/include/linux/sunrpc/svc.h | |
4 | * | |
5 | * RPC server declarations. | |
6 | * | |
7 | * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de> | |
8 | */ | |
9 | ||
10 | ||
11 | #ifndef SUNRPC_SVC_H | |
12 | #define SUNRPC_SVC_H | |
13 | ||
14 | #include <linux/in.h> | |
73df0dba | 15 | #include <linux/in6.h> |
1da177e4 LT |
16 | #include <linux/sunrpc/types.h> |
17 | #include <linux/sunrpc/xdr.h> | |
7adae489 | 18 | #include <linux/sunrpc/auth.h> |
1da177e4 LT |
19 | #include <linux/sunrpc/svcauth.h> |
20 | #include <linux/wait.h> | |
21 | #include <linux/mm.h> | |
2f0f88f4 | 22 | #include <linux/pagevec.h> |
1da177e4 | 23 | |
03cf6c9f GB |
24 | /* statistics for svc_pool structures */ |
25 | struct svc_pool_stats { | |
403c7b44 | 26 | atomic_long_t packets; |
03cf6c9f | 27 | unsigned long sockets_queued; |
403c7b44 JL |
28 | atomic_long_t threads_woken; |
29 | atomic_long_t threads_timedout; | |
03cf6c9f GB |
30 | }; |
31 | ||
3262c816 GB |
32 | /* |
33 | * | |
34 | * RPC service thread pool. | |
35 | * | |
36 | * Pool of threads and temporary sockets. Generally there is only | |
37 | * a single one of these per RPC service, but on NUMA machines those | |
38 | * services that can benefit from it (i.e. nfs but not lockd) will | |
39 | * have one pool per NUMA node. This optimisation reduces cross- | |
40 | * node traffic on multi-node NUMA NFS servers. | |
41 | */ | |
42 | struct svc_pool { | |
43 | unsigned int sp_id; /* pool id; also node id on NUMA */ | |
44 | spinlock_t sp_lock; /* protects all fields */ | |
3262c816 GB |
45 | struct list_head sp_sockets; /* pending sockets */ |
46 | unsigned int sp_nrthreads; /* # of threads in pool */ | |
a7455442 | 47 | struct list_head sp_all_threads; /* all server threads */ |
03cf6c9f | 48 | struct svc_pool_stats sp_stats; /* statistics on pool operation */ |
4d5db3f5 JL |
49 | #define SP_TASK_PENDING (0) /* still work to do even if no |
50 | * xprt is queued. */ | |
22700f3c | 51 | #define SP_CONGESTED (1) |
4d5db3f5 | 52 | unsigned long sp_flags; |
3262c816 GB |
53 | } ____cacheline_aligned_in_smp; |
54 | ||
ea126e74 JL |
55 | struct svc_serv; |
56 | ||
57 | struct svc_serv_ops { | |
58 | /* Callback to use when last thread exits. */ | |
c369014f | 59 | void (*svo_shutdown)(struct svc_serv *, struct net *); |
758f62ff JL |
60 | |
61 | /* function for service threads to run */ | |
c369014f | 62 | int (*svo_function)(void *); |
758f62ff | 63 | |
b9e13cdf JL |
64 | /* queue up a transport for servicing */ |
65 | void (*svo_enqueue_xprt)(struct svc_xprt *); | |
66 | ||
598e2359 JL |
67 | /* set up thread (or whatever) execution context */ |
68 | int (*svo_setup)(struct svc_serv *, struct svc_pool *, int); | |
69 | ||
758f62ff JL |
70 | /* optional module to count when adding threads (pooled svcs only) */ |
71 | struct module *svo_module; | |
ea126e74 JL |
72 | }; |
73 | ||
1da177e4 LT |
74 | /* |
75 | * RPC service. | |
76 | * | |
77 | * An RPC service is a ``daemon,'' possibly multithreaded, which | |
78 | * receives and processes incoming RPC messages. | |
79 | * It has one or more transport sockets associated with it, and maintains | |
80 | * a list of idle threads waiting for input. | |
81 | * | |
82 | * We currently do not support more than one RPC program per daemon. | |
83 | */ | |
84 | struct svc_serv { | |
1da177e4 LT |
85 | struct svc_program * sv_program; /* RPC program */ |
86 | struct svc_stat * sv_stats; /* RPC statistics */ | |
87 | spinlock_t sv_lock; | |
88 | unsigned int sv_nrthreads; /* # of server threads */ | |
c9233eb7 JL |
89 | unsigned int sv_maxconn; /* max connections allowed or |
90 | * '0' causing max to be based | |
91 | * on number of threads. */ | |
92 | ||
c6b0a9f8 N |
93 | unsigned int sv_max_payload; /* datagram payload size */ |
94 | unsigned int sv_max_mesg; /* max_payload + 1 page for overheads */ | |
1da177e4 | 95 | unsigned int sv_xdrsize; /* XDR buffer size */ |
1da177e4 LT |
96 | struct list_head sv_permsocks; /* all permanent sockets */ |
97 | struct list_head sv_tempsocks; /* all temporary sockets */ | |
98 | int sv_tmpcnt; /* count of temporary sockets */ | |
36bdfc8b | 99 | struct timer_list sv_temptimer; /* timer for aging temporary sockets */ |
1da177e4 LT |
100 | |
101 | char * sv_name; /* service name */ | |
bc591ccf | 102 | |
3262c816 GB |
103 | unsigned int sv_nrpools; /* number of thread pools */ |
104 | struct svc_pool * sv_pools; /* array of thread pools */ | |
afea5657 | 105 | const struct svc_serv_ops *sv_ops; /* server operations */ |
9e00abc3 | 106 | #if defined(CONFIG_SUNRPC_BACKCHANNEL) |
56632b5b RL |
107 | struct list_head sv_cb_list; /* queue for callback requests |
108 | * that arrive over the same | |
109 | * connection */ | |
110 | spinlock_t sv_cb_lock; /* protects the svc_cb_list */ | |
111 | wait_queue_head_t sv_cb_waitq; /* sleep here if there are no | |
112 | * entries in the svc_cb_list */ | |
a289ce53 | 113 | bool sv_bc_enabled; /* service uses backchannel */ |
9e00abc3 | 114 | #endif /* CONFIG_SUNRPC_BACKCHANNEL */ |
1da177e4 LT |
115 | }; |
116 | ||
9a24ab57 GB |
117 | /* |
118 | * We use sv_nrthreads as a reference count. svc_destroy() drops | |
119 | * this refcount, so we need to bump it up around operations that | |
120 | * change the number of threads. Horrible, but there it is. | |
3c519914 | 121 | * Should be called with the "service mutex" held. |
9a24ab57 GB |
122 | */ |
123 | static inline void svc_get(struct svc_serv *serv) | |
124 | { | |
125 | serv->sv_nrthreads++; | |
126 | } | |
127 | ||
1da177e4 LT |
128 | /* |
129 | * Maximum payload size supported by a kernel RPC server. | |
130 | * This is use to determine the max number of pages nfsd is | |
131 | * willing to return in a single READ operation. | |
7adae489 GB |
132 | * |
133 | * These happen to all be powers of 2, which is not strictly | |
134 | * necessary but helps enforce the real limitation, which is | |
ea1754a0 | 135 | * that they should be multiples of PAGE_SIZE. |
7adae489 GB |
136 | * |
137 | * For UDP transports, a block plus NFS,RPC, and UDP headers | |
138 | * has to fit into the IP datagram limit of 64K. The largest | |
139 | * feasible number for all known page sizes is probably 48K, | |
140 | * but we choose 32K here. This is the same as the historical | |
141 | * Linux limit; someone who cares more about NFS/UDP performance | |
142 | * can test a larger number. | |
143 | * | |
144 | * For TCP transports we have more freedom. A size of 1MB is | |
145 | * chosen to match the client limit. Other OSes are known to | |
146 | * have larger limits, but those numbers are probably beyond | |
147 | * the point of diminishing returns. | |
1da177e4 | 148 | */ |
7adae489 GB |
149 | #define RPCSVC_MAXPAYLOAD (1*1024*1024u) |
150 | #define RPCSVC_MAXPAYLOAD_TCP RPCSVC_MAXPAYLOAD | |
151 | #define RPCSVC_MAXPAYLOAD_UDP (32*1024u) | |
152 | ||
153 | extern u32 svc_max_payload(const struct svc_rqst *rqstp); | |
1da177e4 LT |
154 | |
155 | /* | |
156 | * RPC Requsts and replies are stored in one or more pages. | |
157 | * We maintain an array of pages for each server thread. | |
158 | * Requests are copied into these pages as they arrive. Remaining | |
159 | * pages are available to write the reply into. | |
160 | * | |
161 | * Pages are sent using ->sendpage so each server thread needs to | |
162 | * allocate more to replace those used in sending. To help keep track | |
163 | * of these pages we have a receive list where all pages initialy live, | |
164 | * and a send list where pages are moved to when there are to be part | |
165 | * of a reply. | |
166 | * | |
167 | * We use xdr_buf for holding responses as it fits well with NFS | |
168 | * read responses (that have a header, and some data pages, and possibly | |
169 | * a tail) and means we can share some client side routines. | |
170 | * | |
171 | * The xdr_buf.head kvec always points to the first page in the rq_*pages | |
172 | * list. The xdr_buf.pages pointer points to the second page on that | |
173 | * list. xdr_buf.tail points to the end of the first page. | |
174 | * This assumes that the non-page part of an rpc reply will fit | |
175 | * in a page - NFSd ensures this. lockd also has no trouble. | |
176 | * | |
177 | * Each request/reply pair can have at most one "payload", plus two pages, | |
178 | * one for the request, and one for the reply. | |
250f3915 N |
179 | * We using ->sendfile to return read data, we might need one extra page |
180 | * if the request is not page-aligned. So add another '1'. | |
1da177e4 | 181 | */ |
250f3915 N |
182 | #define RPCSVC_MAXPAGES ((RPCSVC_MAXPAYLOAD+PAGE_SIZE-1)/PAGE_SIZE \ |
183 | + 2 + 1) | |
1da177e4 | 184 | |
76994313 | 185 | static inline u32 svc_getnl(struct kvec *iov) |
1da177e4 | 186 | { |
76994313 | 187 | __be32 val, *vp; |
1da177e4 LT |
188 | vp = iov->iov_base; |
189 | val = *vp++; | |
190 | iov->iov_base = (void*)vp; | |
76994313 AD |
191 | iov->iov_len -= sizeof(__be32); |
192 | return ntohl(val); | |
193 | } | |
194 | ||
195 | static inline void svc_putnl(struct kvec *iov, u32 val) | |
196 | { | |
197 | __be32 *vp = iov->iov_base + iov->iov_len; | |
198 | *vp = htonl(val); | |
199 | iov->iov_len += sizeof(__be32); | |
200 | } | |
201 | ||
202 | static inline __be32 svc_getu32(struct kvec *iov) | |
203 | { | |
204 | __be32 val, *vp; | |
205 | vp = iov->iov_base; | |
206 | val = *vp++; | |
207 | iov->iov_base = (void*)vp; | |
208 | iov->iov_len -= sizeof(__be32); | |
1da177e4 LT |
209 | return val; |
210 | } | |
211 | ||
212 | static inline void svc_ungetu32(struct kvec *iov) | |
213 | { | |
76994313 | 214 | __be32 *vp = (__be32 *)iov->iov_base; |
1da177e4 LT |
215 | iov->iov_base = (void *)(vp - 1); |
216 | iov->iov_len += sizeof(*vp); | |
217 | } | |
218 | ||
76994313 | 219 | static inline void svc_putu32(struct kvec *iov, __be32 val) |
1da177e4 | 220 | { |
76994313 | 221 | __be32 *vp = iov->iov_base + iov->iov_len; |
1da177e4 | 222 | *vp = val; |
76994313 | 223 | iov->iov_len += sizeof(__be32); |
1da177e4 LT |
224 | } |
225 | ||
1da177e4 LT |
226 | /* |
227 | * The context of a single thread, including the request currently being | |
228 | * processed. | |
1da177e4 LT |
229 | */ |
230 | struct svc_rqst { | |
a7455442 | 231 | struct list_head rq_all; /* all threads list */ |
81244386 | 232 | struct rcu_head rq_rcu_head; /* for RCU deferred kfree */ |
57b1d3ba | 233 | struct svc_xprt * rq_xprt; /* transport ptr */ |
849a1cf1 | 234 | |
27459f09 CL |
235 | struct sockaddr_storage rq_addr; /* peer address */ |
236 | size_t rq_addrlen; | |
849a1cf1 MJ |
237 | struct sockaddr_storage rq_daddr; /* dest addr of request |
238 | * - reply from here */ | |
239 | size_t rq_daddrlen; | |
1da177e4 LT |
240 | |
241 | struct svc_serv * rq_server; /* RPC service definition */ | |
3262c816 | 242 | struct svc_pool * rq_pool; /* thread pool */ |
860bda29 | 243 | const struct svc_procedure *rq_procinfo;/* procedure info */ |
1da177e4 LT |
244 | struct auth_ops * rq_authop; /* authentication flavour */ |
245 | struct svc_cred rq_cred; /* auth info */ | |
5148bf4e | 246 | void * rq_xprt_ctxt; /* transport specific context ptr */ |
1da177e4 LT |
247 | struct svc_deferred_req*rq_deferred; /* deferred request we are replaying */ |
248 | ||
260c1d12 | 249 | size_t rq_xprt_hlen; /* xprt header len */ |
1da177e4 | 250 | struct xdr_buf rq_arg; |
5191955d | 251 | struct xdr_stream rq_arg_stream; |
bddfdbcd | 252 | struct xdr_stream rq_res_stream; |
5191955d | 253 | struct page *rq_scratch_page; |
1da177e4 | 254 | struct xdr_buf rq_res; |
8c6ae498 | 255 | struct page *rq_pages[RPCSVC_MAXPAGES + 1]; |
44524359 | 256 | struct page * *rq_respages; /* points into rq_pages */ |
afc59400 | 257 | struct page * *rq_next_page; /* next reply page to use */ |
2825a7f9 | 258 | struct page * *rq_page_end; /* one past the last page */ |
1da177e4 | 259 | |
2f0f88f4 | 260 | struct pagevec rq_pvec; |
3cc03b16 | 261 | struct kvec rq_vec[RPCSVC_MAXPAGES]; /* generally useful.. */ |
ca07eda3 | 262 | struct bio_vec rq_bvec[RPCSVC_MAXPAGES]; |
3cc03b16 | 263 | |
d8ed029d | 264 | __be32 rq_xid; /* transmission id */ |
1da177e4 LT |
265 | u32 rq_prog; /* program number */ |
266 | u32 rq_vers; /* program version */ | |
267 | u32 rq_proc; /* procedure number */ | |
268 | u32 rq_prot; /* IP protocol */ | |
62978b3c | 269 | int rq_cachetype; /* catering to nfsd */ |
4d152e2c | 270 | #define RQ_SECURE (0) /* secure port */ |
7501cc2b | 271 | #define RQ_LOCAL (1) /* local request */ |
30660e04 | 272 | #define RQ_USEDEFERRAL (2) /* use deferral */ |
78b65eb3 | 273 | #define RQ_DROPME (3) /* drop current reply */ |
779fb0f3 JL |
274 | #define RQ_SPLICE_OK (4) /* turned off in gss privacy |
275 | * to prevent encrypting page | |
276 | * cache pages */ | |
81244386 | 277 | #define RQ_VICTIM (5) /* about to be shut down */ |
b1691bc0 | 278 | #define RQ_BUSY (6) /* request is busy */ |
ff3ac5c3 | 279 | #define RQ_DATA (7) /* request has data */ |
4d152e2c | 280 | unsigned long rq_flags; /* flags field */ |
55f5088c | 281 | ktime_t rq_qtime; /* enqueue time */ |
1da177e4 | 282 | |
1da177e4 LT |
283 | void * rq_argp; /* decoded arguments */ |
284 | void * rq_resp; /* xdr'd results */ | |
285 | void * rq_auth_data; /* flavor-specific data */ | |
438623a0 | 286 | __be32 rq_auth_stat; /* authentication status */ |
a5cddc88 BF |
287 | int rq_auth_slack; /* extra space xdr code |
288 | * should leave in head | |
289 | * for krb5i, krb5p. | |
290 | */ | |
1da177e4 LT |
291 | int rq_reserved; /* space on socket outq |
292 | * reserved for this request | |
293 | */ | |
aaba72cd | 294 | ktime_t rq_stime; /* start time */ |
1da177e4 LT |
295 | |
296 | struct cache_req rq_chandle; /* handle passed to caches for | |
297 | * request delaying | |
298 | */ | |
299 | /* Catering to nfsd */ | |
300 | struct auth_domain * rq_client; /* RPC peer info */ | |
3ab4d8b1 | 301 | struct auth_domain * rq_gssclient; /* "gss/"-style peer info */ |
1da177e4 | 302 | struct svc_cacherep * rq_cacherep; /* cache info */ |
a7455442 | 303 | struct task_struct *rq_task; /* service thread */ |
b1691bc0 | 304 | spinlock_t rq_lock; /* per-request lock */ |
d4b09acf VA |
305 | struct net *rq_bc_net; /* pointer to backchannel's |
306 | * net namespace | |
307 | */ | |
28df3d15 | 308 | void ** rq_lease_breaker; /* The v4 client breaking a lease */ |
1da177e4 LT |
309 | }; |
310 | ||
d4b09acf | 311 | #define SVC_NET(rqst) (rqst->rq_xprt ? rqst->rq_xprt->xpt_net : rqst->rq_bc_net) |
9695c705 | 312 | |
27459f09 CL |
313 | /* |
314 | * Rigorous type checking on sockaddr type conversions | |
315 | */ | |
5344b12d | 316 | static inline struct sockaddr_in *svc_addr_in(const struct svc_rqst *rqst) |
27459f09 CL |
317 | { |
318 | return (struct sockaddr_in *) &rqst->rq_addr; | |
319 | } | |
320 | ||
5344b12d | 321 | static inline struct sockaddr_in6 *svc_addr_in6(const struct svc_rqst *rqst) |
95756482 CL |
322 | { |
323 | return (struct sockaddr_in6 *) &rqst->rq_addr; | |
324 | } | |
325 | ||
5344b12d | 326 | static inline struct sockaddr *svc_addr(const struct svc_rqst *rqst) |
27459f09 CL |
327 | { |
328 | return (struct sockaddr *) &rqst->rq_addr; | |
329 | } | |
330 | ||
849a1cf1 MJ |
331 | static inline struct sockaddr_in *svc_daddr_in(const struct svc_rqst *rqst) |
332 | { | |
333 | return (struct sockaddr_in *) &rqst->rq_daddr; | |
334 | } | |
335 | ||
336 | static inline struct sockaddr_in6 *svc_daddr_in6(const struct svc_rqst *rqst) | |
337 | { | |
338 | return (struct sockaddr_in6 *) &rqst->rq_daddr; | |
339 | } | |
340 | ||
341 | static inline struct sockaddr *svc_daddr(const struct svc_rqst *rqst) | |
342 | { | |
343 | return (struct sockaddr *) &rqst->rq_daddr; | |
344 | } | |
345 | ||
1da177e4 LT |
346 | /* |
347 | * Check buffer bounds after decoding arguments | |
348 | */ | |
349 | static inline int | |
d8ed029d | 350 | xdr_argsize_check(struct svc_rqst *rqstp, __be32 *p) |
1da177e4 LT |
351 | { |
352 | char *cp = (char *)p; | |
353 | struct kvec *vec = &rqstp->rq_arg.head[0]; | |
9512a16b BF |
354 | return cp >= (char*)vec->iov_base |
355 | && cp <= (char*)vec->iov_base + vec->iov_len; | |
1da177e4 LT |
356 | } |
357 | ||
358 | static inline int | |
d8ed029d | 359 | xdr_ressize_check(struct svc_rqst *rqstp, __be32 *p) |
1da177e4 LT |
360 | { |
361 | struct kvec *vec = &rqstp->rq_res.head[0]; | |
362 | char *cp = (char*)p; | |
363 | ||
364 | vec->iov_len = cp - (char*)vec->iov_base; | |
365 | ||
366 | return vec->iov_len <= PAGE_SIZE; | |
367 | } | |
368 | ||
44524359 | 369 | static inline void svc_free_res_pages(struct svc_rqst *rqstp) |
a257cdd0 | 370 | { |
afc59400 BF |
371 | while (rqstp->rq_next_page != rqstp->rq_respages) { |
372 | struct page **pp = --rqstp->rq_next_page; | |
44524359 N |
373 | if (*pp) { |
374 | put_page(*pp); | |
375 | *pp = NULL; | |
1da177e4 LT |
376 | } |
377 | } | |
378 | } | |
379 | ||
1da177e4 LT |
380 | struct svc_deferred_req { |
381 | u32 prot; /* protocol (UDP or TCP) */ | |
8c7b0172 | 382 | struct svc_xprt *xprt; |
24422222 CL |
383 | struct sockaddr_storage addr; /* where reply must go */ |
384 | size_t addrlen; | |
849a1cf1 MJ |
385 | struct sockaddr_storage daddr; /* where reply must come from */ |
386 | size_t daddrlen; | |
1da177e4 | 387 | struct cache_deferred_req handle; |
260c1d12 | 388 | size_t xprt_hlen; |
1da177e4 | 389 | int argslen; |
469aef23 | 390 | __be32 args[]; |
1da177e4 LT |
391 | }; |
392 | ||
8e5b6773 TM |
393 | struct svc_process_info { |
394 | union { | |
395 | int (*dispatch)(struct svc_rqst *, __be32 *); | |
396 | struct { | |
397 | unsigned int lovers; | |
398 | unsigned int hivers; | |
399 | } mismatch; | |
400 | }; | |
401 | }; | |
402 | ||
1da177e4 | 403 | /* |
9ba02638 | 404 | * List of RPC programs on the same transport endpoint |
1da177e4 LT |
405 | */ |
406 | struct svc_program { | |
9ba02638 | 407 | struct svc_program * pg_next; /* other programs (same xprt) */ |
1da177e4 LT |
408 | u32 pg_prog; /* program number */ |
409 | unsigned int pg_lovers; /* lowest version */ | |
28303ca3 | 410 | unsigned int pg_hivers; /* highest version */ |
1da177e4 | 411 | unsigned int pg_nvers; /* number of versions */ |
e9679189 | 412 | const struct svc_version **pg_vers; /* version array */ |
1da177e4 LT |
413 | char * pg_name; /* service name */ |
414 | char * pg_class; /* class name: services sharing authentication */ | |
415 | struct svc_stat * pg_stats; /* rpc statistics */ | |
416 | int (*pg_authenticate)(struct svc_rqst *); | |
8e5b6773 TM |
417 | __be32 (*pg_init_request)(struct svc_rqst *, |
418 | const struct svc_program *, | |
419 | struct svc_process_info *); | |
642ee6b2 TM |
420 | int (*pg_rpcbind_set)(struct net *net, |
421 | const struct svc_program *, | |
422 | u32 version, int family, | |
423 | unsigned short proto, | |
424 | unsigned short port); | |
1da177e4 LT |
425 | }; |
426 | ||
427 | /* | |
428 | * RPC program version | |
429 | */ | |
430 | struct svc_version { | |
431 | u32 vs_vers; /* version number */ | |
432 | u32 vs_nproc; /* number of procedures */ | |
860bda29 | 433 | const struct svc_procedure *vs_proc; /* per-procedure info */ |
7fd38af9 | 434 | unsigned int *vs_count; /* call counts */ |
1da177e4 LT |
435 | u32 vs_xdrsize; /* xdrsize needed for this version */ |
436 | ||
05a45a2d JL |
437 | /* Don't register with rpcbind */ |
438 | bool vs_hidden; | |
439 | ||
440 | /* Don't care if the rpcbind registration fails */ | |
441 | bool vs_rpcb_optnl; | |
bc5fea42 | 442 | |
5283b03e JL |
443 | /* Need xprt with congestion control */ |
444 | bool vs_need_cong_ctrl; | |
445 | ||
0ae93b99 | 446 | /* Dispatch function */ |
d8ed029d | 447 | int (*vs_dispatch)(struct svc_rqst *, __be32 *); |
1da177e4 LT |
448 | }; |
449 | ||
450 | /* | |
451 | * RPC procedure info | |
452 | */ | |
1da177e4 | 453 | struct svc_procedure { |
a6beb732 CH |
454 | /* process the request: */ |
455 | __be32 (*pc_func)(struct svc_rqst *); | |
026fec7e CH |
456 | /* XDR decode args: */ |
457 | int (*pc_decode)(struct svc_rqst *, __be32 *data); | |
63f8de37 CH |
458 | /* XDR encode result: */ |
459 | int (*pc_encode)(struct svc_rqst *, __be32 *data); | |
8537488b CH |
460 | /* XDR free result: */ |
461 | void (*pc_release)(struct svc_rqst *); | |
1da177e4 LT |
462 | unsigned int pc_argsize; /* argument struct size */ |
463 | unsigned int pc_ressize; /* result struct size */ | |
1da177e4 LT |
464 | unsigned int pc_cachetype; /* cache info (NFS) */ |
465 | unsigned int pc_xdrressize; /* maximum size of XDR reply */ | |
2289e87b | 466 | const char * pc_name; /* for display */ |
1da177e4 LT |
467 | }; |
468 | ||
d70bc0c6 JL |
469 | /* |
470 | * Mode for mapping cpus to pools. | |
471 | */ | |
472 | enum { | |
473 | SVC_POOL_AUTO = -1, /* choose one of the others */ | |
474 | SVC_POOL_GLOBAL, /* no mapping, just a single global pool | |
475 | * (legacy & UP mode) */ | |
476 | SVC_POOL_PERCPU, /* one pool per cpu */ | |
477 | SVC_POOL_PERNODE /* one pool per numa node */ | |
478 | }; | |
479 | ||
480 | struct svc_pool_map { | |
481 | int count; /* How many svc_servs use us */ | |
482 | int mode; /* Note: int not enum to avoid | |
483 | * warnings about "enumeration value | |
484 | * not handled in switch" */ | |
485 | unsigned int npools; | |
486 | unsigned int *pool_to; /* maps pool id to cpu or node */ | |
487 | unsigned int *to_pool; /* maps cpu or node to pool id */ | |
488 | }; | |
489 | ||
490 | extern struct svc_pool_map svc_pool_map; | |
491 | ||
1da177e4 LT |
492 | /* |
493 | * Function prototypes. | |
494 | */ | |
bb2224df | 495 | int svc_rpcb_setup(struct svc_serv *serv, struct net *net); |
5ecebb7c | 496 | void svc_rpcb_cleanup(struct svc_serv *serv, struct net *net); |
9793f7c8 | 497 | int svc_bind(struct svc_serv *serv, struct net *net); |
49a9072f | 498 | struct svc_serv *svc_create(struct svc_program *, unsigned int, |
afea5657 | 499 | const struct svc_serv_ops *); |
1b6dc1df JL |
500 | struct svc_rqst *svc_rqst_alloc(struct svc_serv *serv, |
501 | struct svc_pool *pool, int node); | |
0113ab34 | 502 | struct svc_rqst *svc_prepare_thread(struct svc_serv *serv, |
11fd165c | 503 | struct svc_pool *pool, int node); |
2f0f88f4 CL |
504 | void svc_rqst_replace_page(struct svc_rqst *rqstp, |
505 | struct page *page); | |
1b6dc1df | 506 | void svc_rqst_free(struct svc_rqst *); |
1da177e4 | 507 | void svc_exit_thread(struct svc_rqst *); |
d70bc0c6 JL |
508 | unsigned int svc_pool_map_get(void); |
509 | void svc_pool_map_put(void); | |
a7455442 | 510 | struct svc_serv * svc_create_pooled(struct svc_program *, unsigned int, |
afea5657 | 511 | const struct svc_serv_ops *); |
a7455442 | 512 | int svc_set_num_threads(struct svc_serv *, struct svc_pool *, int); |
ed6473dd | 513 | int svc_set_num_threads_sync(struct svc_serv *, struct svc_pool *, int); |
03cf6c9f | 514 | int svc_pool_stats_open(struct svc_serv *serv, struct file *file); |
1da177e4 | 515 | void svc_destroy(struct svc_serv *); |
bb2224df | 516 | void svc_shutdown_net(struct svc_serv *, struct net *); |
6fb2b47f | 517 | int svc_process(struct svc_rqst *); |
4d6bbb62 RL |
518 | int bc_svc_process(struct svc_serv *, struct rpc_rqst *, |
519 | struct svc_rqst *); | |
5247fab5 | 520 | int svc_register(const struct svc_serv *, struct net *, const int, |
4b62e58c | 521 | const unsigned short, const unsigned short); |
a26cfad6 | 522 | |
1da177e4 LT |
523 | void svc_wake_up(struct svc_serv *); |
524 | void svc_reserve(struct svc_rqst *rqstp, int space); | |
bfd24160 | 525 | struct svc_pool * svc_pool_for_cpu(struct svc_serv *serv, int cpu); |
ad06e4bd | 526 | char * svc_print_addr(struct svc_rqst *, char *, size_t); |
5c117207 | 527 | const char * svc_proc_name(const struct svc_rqst *rqstp); |
03493bca CL |
528 | int svc_encode_result_payload(struct svc_rqst *rqstp, |
529 | unsigned int offset, | |
530 | unsigned int length); | |
8154ef27 | 531 | unsigned int svc_fill_write_vector(struct svc_rqst *rqstp, |
dae9a6ca | 532 | struct xdr_buf *payload); |
38a70315 | 533 | char *svc_fill_symlink_pathname(struct svc_rqst *rqstp, |
11b4d66e CL |
534 | struct kvec *first, void *p, |
535 | size_t total); | |
8e5b6773 TM |
536 | __be32 svc_generic_init_request(struct svc_rqst *rqstp, |
537 | const struct svc_program *progp, | |
538 | struct svc_process_info *procinfo); | |
642ee6b2 TM |
539 | int svc_generic_rpcbind_set(struct net *net, |
540 | const struct svc_program *progp, | |
541 | u32 version, int family, | |
542 | unsigned short proto, | |
543 | unsigned short port); | |
544 | int svc_rpcbind_set_version(struct net *net, | |
545 | const struct svc_program *progp, | |
546 | u32 version, int family, | |
547 | unsigned short proto, | |
548 | unsigned short port); | |
ad06e4bd CL |
549 | |
550 | #define RPC_MAX_ADDRBUFLEN (63U) | |
1da177e4 | 551 | |
cd123012 JL |
552 | /* |
553 | * When we want to reduce the size of the reserved space in the response | |
554 | * buffer, we need to take into account the size of any checksum data that | |
555 | * may be at the end of the packet. This is difficult to determine exactly | |
556 | * for all cases without actually generating the checksum, so we just use a | |
557 | * static value. | |
558 | */ | |
fbb7878c | 559 | static inline void svc_reserve_auth(struct svc_rqst *rqstp, int space) |
cd123012 | 560 | { |
a5cddc88 | 561 | svc_reserve(rqstp, space + rqstp->rq_auth_slack); |
cd123012 JL |
562 | } |
563 | ||
5191955d CL |
564 | /** |
565 | * svcxdr_init_decode - Prepare an xdr_stream for svc Call decoding | |
566 | * @rqstp: controlling server RPC transaction context | |
567 | * | |
568 | */ | |
569 | static inline void svcxdr_init_decode(struct svc_rqst *rqstp) | |
570 | { | |
571 | struct xdr_stream *xdr = &rqstp->rq_arg_stream; | |
572 | struct kvec *argv = rqstp->rq_arg.head; | |
573 | ||
574 | xdr_init_decode(xdr, &rqstp->rq_arg, argv->iov_base, NULL); | |
575 | xdr_set_scratch_page(xdr, rqstp->rq_scratch_page); | |
576 | } | |
577 | ||
bddfdbcd CL |
578 | /** |
579 | * svcxdr_init_encode - Prepare an xdr_stream for svc Reply encoding | |
580 | * @rqstp: controlling server RPC transaction context | |
581 | * | |
582 | */ | |
583 | static inline void svcxdr_init_encode(struct svc_rqst *rqstp) | |
584 | { | |
585 | struct xdr_stream *xdr = &rqstp->rq_res_stream; | |
586 | struct xdr_buf *buf = &rqstp->rq_res; | |
587 | struct kvec *resv = buf->head; | |
588 | ||
589 | xdr_reset_scratch_buffer(xdr); | |
590 | ||
591 | xdr->buf = buf; | |
592 | xdr->iov = resv; | |
593 | xdr->p = resv->iov_base + resv->iov_len; | |
594 | xdr->end = resv->iov_base + PAGE_SIZE - rqstp->rq_auth_slack; | |
595 | buf->len = resv->iov_len; | |
596 | xdr->page_ptr = buf->pages - 1; | |
597 | buf->buflen = PAGE_SIZE * (1 + rqstp->rq_page_end - buf->pages); | |
598 | buf->buflen -= rqstp->rq_auth_slack; | |
599 | xdr->rqst = NULL; | |
600 | } | |
601 | ||
1da177e4 | 602 | #endif /* SUNRPC_SVC_H */ |