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 
18 /*
19  * RPC service.
20  *
21  * An RPC service is a ``daemon,'' possibly multithreaded, which
22  * receives and processes incoming RPC messages.
23  * It has one or more transport sockets associated with it, and maintains
24  * a list of idle threads waiting for input.
25  *
26  * We currently do not support more than one RPC program per daemon.
27  */
28 struct svc_serv {
29 	struct list_head	sv_threads;	/* idle server threads */
30 	struct list_head	sv_sockets;	/* pending sockets */
31 	struct svc_program *	sv_program;	/* RPC program */
32 	struct svc_stat *	sv_stats;	/* RPC statistics */
33 	spinlock_t		sv_lock;
34 	unsigned int		sv_nrthreads;	/* # of server threads */
35 	unsigned int		sv_bufsz;	/* datagram buffer size */
36 	unsigned int		sv_xdrsize;	/* XDR buffer size */
37 
38 	struct list_head	sv_permsocks;	/* all permanent sockets */
39 	struct list_head	sv_tempsocks;	/* all temporary sockets */
40 	int			sv_tmpcnt;	/* count of temporary sockets */
41 
42 	char *			sv_name;	/* service name */
43 };
44 
45 /*
46  * Maximum payload size supported by a kernel RPC server.
47  * This is use to determine the max number of pages nfsd is
48  * willing to return in a single READ operation.
49  */
50 #define RPCSVC_MAXPAYLOAD	16384u
51 
52 /*
53  * Buffer to store RPC requests or replies in.
54  * Each server thread has one of these beasts.
55  *
56  * Area points to the allocated memory chunk currently owned by the
57  * buffer. Base points to the buffer containing the request, which is
58  * different from area when directly reading from an sk_buff. buf is
59  * the current read/write position while processing an RPC request.
60  *
61  * The array of iovecs can hold additional data that the server process
62  * may not want to copy into the RPC reply buffer, but pass to the
63  * network sendmsg routines directly. The prime candidate for this
64  * will of course be NFS READ operations, but one might also want to
65  * do something about READLINK and READDIR. It might be worthwhile
66  * to implement some generic readdir cache in the VFS layer...
67  *
68  * On the receiving end of the RPC server, the iovec may be used to hold
69  * the list of IP fragments once we get to process fragmented UDP
70  * datagrams directly.
71  */
72 #define RPCSVC_MAXIOV		((RPCSVC_MAXPAYLOAD+PAGE_SIZE-1)/PAGE_SIZE + 1)
73 struct svc_buf {
74 	u32 *			area;	/* allocated memory */
75 	u32 *			base;	/* base of RPC datagram */
76 	int			buflen;	/* total length of buffer */
77 	u32 *			buf;	/* read/write pointer */
78 	int			len;	/* current end of buffer */
79 
80 	/* iovec for zero-copy NFS READs */
81 	struct iovec		iov[RPCSVC_MAXIOV];
82 	int			nriov;
83 };
84 #define svc_getlong(argp, val)	{ (val) = *(argp)->buf++; (argp)->len--; }
85 #define svc_putlong(resp, val)	{ *(resp)->buf++ = (val); (resp)->len++; }
86 
87 /*
88  * The context of a single thread, including the request currently being
89  * processed.
90  * NOTE: First two items must be prev/next.
91  */
92 struct svc_rqst {
93 	struct list_head	rq_list;	/* idle list */
94 	struct svc_sock *	rq_sock;	/* socket */
95 	struct sockaddr_in	rq_addr;	/* peer address */
96 	int			rq_addrlen;
97 
98 	struct svc_serv *	rq_server;	/* RPC service definition */
99 	struct svc_procedure *	rq_procinfo;	/* procedure info */
100 	struct svc_cred		rq_cred;	/* auth info */
101 	struct sk_buff *	rq_skbuff;	/* fast recv inet buffer */
102 	struct svc_buf		rq_defbuf;	/* default buffer */
103 	struct svc_buf		rq_argbuf;	/* argument buffer */
104 	struct svc_buf		rq_resbuf;	/* result buffer */
105 	u32			rq_xid;		/* transmission id */
106 	u32			rq_prog;	/* program number */
107 	u32			rq_vers;	/* program version */
108 	u32			rq_proc;	/* procedure number */
109 	u32			rq_prot;	/* IP protocol */
110 	unsigned short		rq_verfed  : 1,	/* reply has verifier */
111 				rq_userset : 1,	/* auth->setuser OK */
112 				rq_secure  : 1,	/* secure port */
113 				rq_auth    : 1;	/* check client */
114 
115 	__u32			rq_daddr;	/* dest addr of request - reply from here */
116 
117 	void *			rq_argp;	/* decoded arguments */
118 	void *			rq_resp;	/* xdr'd results */
119 
120 	int			rq_reserved;	/* space on socket outq
121 						 * reserved for this request
122 						 */
123 
124 	/* Catering to nfsd */
125 	struct svc_client *	rq_client;	/* RPC peer info */
126 	struct svc_cacherep *	rq_cacherep;	/* cache info */
127 	struct knfsd_fh *	rq_reffh;	/* Referrence filehandle, used to
128 						 * determine what device number
129 						 * to report (real or virtual)
130 						 */
131 
132 	wait_queue_head_t	rq_wait;	/* synchronozation */
133 };
134 
135 /*
136  * RPC program
137  */
138 struct svc_program {
139 	u32			pg_prog;	/* program number */
140 	unsigned int		pg_lovers;	/* lowest version */
141 	unsigned int		pg_hivers;	/* lowest version */
142 	unsigned int		pg_nvers;	/* number of versions */
143 	struct svc_version **	pg_vers;	/* version array */
144 	char *			pg_name;	/* service name */
145 	struct svc_stat *	pg_stats;	/* rpc statistics */
146 };
147 
148 /*
149  * RPC program version
150  */
151 struct svc_version {
152 	u32			vs_vers;	/* version number */
153 	u32			vs_nproc;	/* number of procedures */
154 	struct svc_procedure *	vs_proc;	/* per-procedure info */
155 
156 	/* Override dispatch function (e.g. when caching replies).
157 	 * A return value of 0 means drop the request.
158 	 * vs_dispatch == NULL means use default dispatcher.
159 	 */
160 	int			(*vs_dispatch)(struct svc_rqst *, u32 *);
161 };
162 
163 /*
164  * RPC procedure info
165  */
166 typedef int	(*svc_procfunc)(struct svc_rqst *, void *argp, void *resp);
167 struct svc_procedure {
168 	svc_procfunc		pc_func;	/* process the request */
169 	kxdrproc_t		pc_decode;	/* XDR decode args */
170 	kxdrproc_t		pc_encode;	/* XDR encode result */
171 	kxdrproc_t		pc_release;	/* XDR free result */
172 	unsigned int		pc_argsize;	/* argument struct size */
173 	unsigned int		pc_ressize;	/* result struct size */
174 	unsigned int		pc_count;	/* call count */
175 	unsigned int		pc_cachetype;	/* cache info (NFS) */
176 	unsigned int		pc_xdrressize;	/* maximum size of XDR reply */
177 };
178 
179 /*
180  * This is the RPC server thread function prototype
181  */
182 typedef void		(*svc_thread_fn)(struct svc_rqst *);
183 
184 /*
185  * Function prototypes.
186  */
187 struct svc_serv *  svc_create(struct svc_program *, unsigned int, unsigned int);
188 int		   svc_create_thread(svc_thread_fn, struct svc_serv *);
189 void		   svc_exit_thread(struct svc_rqst *);
190 void		   svc_destroy(struct svc_serv *);
191 int		   svc_process(struct svc_serv *, struct svc_rqst *);
192 int		   svc_register(struct svc_serv *, int, unsigned short);
193 void		   svc_wake_up(struct svc_serv *);
194 void		   svc_reserve(struct svc_rqst *rqstp, int space);
195 
196 #endif /* SUNRPC_SVC_H */
197