]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/sunrpc/svc.h
[PATCH] knfsd: Drop 'serv' option to svc_recv and svc_process
[mirror_ubuntu-bionic-kernel.git] / include / linux / sunrpc / svc.h
1 /*
2 * linux/include/linux/sunrpc/svc.h
3 *
4 * RPC server declarations.
5 *
6 * Copyright (C) 1995, 1996 Olaf Kirch <okir@monad.swb.de>
7 */
8
9
10 #ifndef SUNRPC_SVC_H
11 #define SUNRPC_SVC_H
12
13 #include <linux/in.h>
14 #include <linux/sunrpc/types.h>
15 #include <linux/sunrpc/xdr.h>
16 #include <linux/sunrpc/svcauth.h>
17 #include <linux/wait.h>
18 #include <linux/mm.h>
19
20 /*
21 * RPC service.
22 *
23 * An RPC service is a ``daemon,'' possibly multithreaded, which
24 * receives and processes incoming RPC messages.
25 * It has one or more transport sockets associated with it, and maintains
26 * a list of idle threads waiting for input.
27 *
28 * We currently do not support more than one RPC program per daemon.
29 */
30 struct svc_serv {
31 struct list_head sv_threads; /* idle server threads */
32 struct list_head sv_sockets; /* pending sockets */
33 struct svc_program * sv_program; /* RPC program */
34 struct svc_stat * sv_stats; /* RPC statistics */
35 spinlock_t sv_lock;
36 unsigned int sv_nrthreads; /* # of server threads */
37 unsigned int sv_bufsz; /* datagram buffer size */
38 unsigned int sv_xdrsize; /* XDR buffer size */
39
40 struct list_head sv_permsocks; /* all permanent sockets */
41 struct list_head sv_tempsocks; /* all temporary sockets */
42 int sv_tmpcnt; /* count of temporary sockets */
43
44 char * sv_name; /* service name */
45
46 void (*sv_shutdown)(struct svc_serv *serv);
47 /* Callback to use when last thread
48 * exits.
49 */
50 };
51
52 /*
53 * Maximum payload size supported by a kernel RPC server.
54 * This is use to determine the max number of pages nfsd is
55 * willing to return in a single READ operation.
56 */
57 #define RPCSVC_MAXPAYLOAD (64*1024u)
58
59 /*
60 * RPC Requsts and replies are stored in one or more pages.
61 * We maintain an array of pages for each server thread.
62 * Requests are copied into these pages as they arrive. Remaining
63 * pages are available to write the reply into.
64 *
65 * Pages are sent using ->sendpage so each server thread needs to
66 * allocate more to replace those used in sending. To help keep track
67 * of these pages we have a receive list where all pages initialy live,
68 * and a send list where pages are moved to when there are to be part
69 * of a reply.
70 *
71 * We use xdr_buf for holding responses as it fits well with NFS
72 * read responses (that have a header, and some data pages, and possibly
73 * a tail) and means we can share some client side routines.
74 *
75 * The xdr_buf.head kvec always points to the first page in the rq_*pages
76 * list. The xdr_buf.pages pointer points to the second page on that
77 * list. xdr_buf.tail points to the end of the first page.
78 * This assumes that the non-page part of an rpc reply will fit
79 * in a page - NFSd ensures this. lockd also has no trouble.
80 *
81 * Each request/reply pair can have at most one "payload", plus two pages,
82 * one for the request, and one for the reply.
83 */
84 #define RPCSVC_MAXPAGES ((RPCSVC_MAXPAYLOAD+PAGE_SIZE-1)/PAGE_SIZE + 2)
85
86 static inline u32 svc_getnl(struct kvec *iov)
87 {
88 __be32 val, *vp;
89 vp = iov->iov_base;
90 val = *vp++;
91 iov->iov_base = (void*)vp;
92 iov->iov_len -= sizeof(__be32);
93 return ntohl(val);
94 }
95
96 static inline void svc_putnl(struct kvec *iov, u32 val)
97 {
98 __be32 *vp = iov->iov_base + iov->iov_len;
99 *vp = htonl(val);
100 iov->iov_len += sizeof(__be32);
101 }
102
103 static inline __be32 svc_getu32(struct kvec *iov)
104 {
105 __be32 val, *vp;
106 vp = iov->iov_base;
107 val = *vp++;
108 iov->iov_base = (void*)vp;
109 iov->iov_len -= sizeof(__be32);
110 return val;
111 }
112
113 static inline void svc_ungetu32(struct kvec *iov)
114 {
115 __be32 *vp = (__be32 *)iov->iov_base;
116 iov->iov_base = (void *)(vp - 1);
117 iov->iov_len += sizeof(*vp);
118 }
119
120 static inline void svc_putu32(struct kvec *iov, __be32 val)
121 {
122 __be32 *vp = iov->iov_base + iov->iov_len;
123 *vp = val;
124 iov->iov_len += sizeof(__be32);
125 }
126
127
128 /*
129 * The context of a single thread, including the request currently being
130 * processed.
131 * NOTE: First two items must be prev/next.
132 */
133 struct svc_rqst {
134 struct list_head rq_list; /* idle list */
135 struct svc_sock * rq_sock; /* socket */
136 struct sockaddr_in rq_addr; /* peer address */
137 int rq_addrlen;
138
139 struct svc_serv * rq_server; /* RPC service definition */
140 struct svc_procedure * rq_procinfo; /* procedure info */
141 struct auth_ops * rq_authop; /* authentication flavour */
142 struct svc_cred rq_cred; /* auth info */
143 struct sk_buff * rq_skbuff; /* fast recv inet buffer */
144 struct svc_deferred_req*rq_deferred; /* deferred request we are replaying */
145
146 struct xdr_buf rq_arg;
147 struct xdr_buf rq_res;
148 struct page * rq_argpages[RPCSVC_MAXPAGES];
149 struct page * rq_respages[RPCSVC_MAXPAGES];
150 int rq_restailpage;
151 short rq_argused; /* pages used for argument */
152 short rq_arghi; /* pages available in argument page list */
153 short rq_resused; /* pages used for result */
154
155 __be32 rq_xid; /* transmission id */
156 u32 rq_prog; /* program number */
157 u32 rq_vers; /* program version */
158 u32 rq_proc; /* procedure number */
159 u32 rq_prot; /* IP protocol */
160 unsigned short
161 rq_secure : 1; /* secure port */
162
163
164 __be32 rq_daddr; /* dest addr of request - reply from here */
165
166 void * rq_argp; /* decoded arguments */
167 void * rq_resp; /* xdr'd results */
168 void * rq_auth_data; /* flavor-specific data */
169
170 int rq_reserved; /* space on socket outq
171 * reserved for this request
172 */
173
174 struct cache_req rq_chandle; /* handle passed to caches for
175 * request delaying
176 */
177 /* Catering to nfsd */
178 struct auth_domain * rq_client; /* RPC peer info */
179 struct svc_cacherep * rq_cacherep; /* cache info */
180 struct knfsd_fh * rq_reffh; /* Referrence filehandle, used to
181 * determine what device number
182 * to report (real or virtual)
183 */
184 int rq_sendfile_ok; /* turned off in gss privacy
185 * to prevent encrypting page
186 * cache pages */
187 wait_queue_head_t rq_wait; /* synchronization */
188 };
189
190 /*
191 * Check buffer bounds after decoding arguments
192 */
193 static inline int
194 xdr_argsize_check(struct svc_rqst *rqstp, __be32 *p)
195 {
196 char *cp = (char *)p;
197 struct kvec *vec = &rqstp->rq_arg.head[0];
198 return cp >= (char*)vec->iov_base
199 && cp <= (char*)vec->iov_base + vec->iov_len;
200 }
201
202 static inline int
203 xdr_ressize_check(struct svc_rqst *rqstp, __be32 *p)
204 {
205 struct kvec *vec = &rqstp->rq_res.head[0];
206 char *cp = (char*)p;
207
208 vec->iov_len = cp - (char*)vec->iov_base;
209
210 return vec->iov_len <= PAGE_SIZE;
211 }
212
213 static inline struct page *
214 svc_take_res_page(struct svc_rqst *rqstp)
215 {
216 if (rqstp->rq_arghi <= rqstp->rq_argused)
217 return NULL;
218 rqstp->rq_arghi--;
219 rqstp->rq_respages[rqstp->rq_resused] =
220 rqstp->rq_argpages[rqstp->rq_arghi];
221 return rqstp->rq_respages[rqstp->rq_resused++];
222 }
223
224 static inline void svc_take_page(struct svc_rqst *rqstp)
225 {
226 if (rqstp->rq_arghi <= rqstp->rq_argused) {
227 WARN_ON(1);
228 return;
229 }
230 rqstp->rq_arghi--;
231 rqstp->rq_respages[rqstp->rq_resused] =
232 rqstp->rq_argpages[rqstp->rq_arghi];
233 rqstp->rq_resused++;
234 }
235
236 static inline void svc_pushback_allpages(struct svc_rqst *rqstp)
237 {
238 while (rqstp->rq_resused) {
239 if (rqstp->rq_respages[--rqstp->rq_resused] == NULL)
240 continue;
241 rqstp->rq_argpages[rqstp->rq_arghi++] =
242 rqstp->rq_respages[rqstp->rq_resused];
243 rqstp->rq_respages[rqstp->rq_resused] = NULL;
244 }
245 }
246
247 static inline void svc_pushback_unused_pages(struct svc_rqst *rqstp)
248 {
249 while (rqstp->rq_resused &&
250 rqstp->rq_res.pages != &rqstp->rq_respages[rqstp->rq_resused]) {
251
252 if (rqstp->rq_respages[--rqstp->rq_resused] != NULL) {
253 rqstp->rq_argpages[rqstp->rq_arghi++] =
254 rqstp->rq_respages[rqstp->rq_resused];
255 rqstp->rq_respages[rqstp->rq_resused] = NULL;
256 }
257 }
258 }
259
260 static inline void svc_free_allpages(struct svc_rqst *rqstp)
261 {
262 while (rqstp->rq_resused) {
263 if (rqstp->rq_respages[--rqstp->rq_resused] == NULL)
264 continue;
265 put_page(rqstp->rq_respages[rqstp->rq_resused]);
266 rqstp->rq_respages[rqstp->rq_resused] = NULL;
267 }
268 }
269
270 struct svc_deferred_req {
271 u32 prot; /* protocol (UDP or TCP) */
272 struct sockaddr_in addr;
273 struct svc_sock *svsk; /* where reply must go */
274 __be32 daddr; /* where reply must come from */
275 struct cache_deferred_req handle;
276 int argslen;
277 __be32 args[0];
278 };
279
280 /*
281 * List of RPC programs on the same transport endpoint
282 */
283 struct svc_program {
284 struct svc_program * pg_next; /* other programs (same xprt) */
285 u32 pg_prog; /* program number */
286 unsigned int pg_lovers; /* lowest version */
287 unsigned int pg_hivers; /* lowest version */
288 unsigned int pg_nvers; /* number of versions */
289 struct svc_version ** pg_vers; /* version array */
290 char * pg_name; /* service name */
291 char * pg_class; /* class name: services sharing authentication */
292 struct svc_stat * pg_stats; /* rpc statistics */
293 int (*pg_authenticate)(struct svc_rqst *);
294 };
295
296 /*
297 * RPC program version
298 */
299 struct svc_version {
300 u32 vs_vers; /* version number */
301 u32 vs_nproc; /* number of procedures */
302 struct svc_procedure * vs_proc; /* per-procedure info */
303 u32 vs_xdrsize; /* xdrsize needed for this version */
304
305 /* Override dispatch function (e.g. when caching replies).
306 * A return value of 0 means drop the request.
307 * vs_dispatch == NULL means use default dispatcher.
308 */
309 int (*vs_dispatch)(struct svc_rqst *, __be32 *);
310 };
311
312 /*
313 * RPC procedure info
314 */
315 typedef int (*svc_procfunc)(struct svc_rqst *, void *argp, void *resp);
316 struct svc_procedure {
317 svc_procfunc pc_func; /* process the request */
318 kxdrproc_t pc_decode; /* XDR decode args */
319 kxdrproc_t pc_encode; /* XDR encode result */
320 kxdrproc_t pc_release; /* XDR free result */
321 unsigned int pc_argsize; /* argument struct size */
322 unsigned int pc_ressize; /* result struct size */
323 unsigned int pc_count; /* call count */
324 unsigned int pc_cachetype; /* cache info (NFS) */
325 unsigned int pc_xdrressize; /* maximum size of XDR reply */
326 };
327
328 /*
329 * This is the RPC server thread function prototype
330 */
331 typedef void (*svc_thread_fn)(struct svc_rqst *);
332
333 /*
334 * Function prototypes.
335 */
336 struct svc_serv * svc_create(struct svc_program *, unsigned int,
337 void (*shutdown)(struct svc_serv*));
338 int svc_create_thread(svc_thread_fn, struct svc_serv *);
339 void svc_exit_thread(struct svc_rqst *);
340 void svc_destroy(struct svc_serv *);
341 int svc_process(struct svc_rqst *);
342 int svc_register(struct svc_serv *, int, unsigned short);
343 void svc_wake_up(struct svc_serv *);
344 void svc_reserve(struct svc_rqst *rqstp, int space);
345
346 #endif /* SUNRPC_SVC_H */