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 */
28struct 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)
73struct 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 */
92struct 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	void *			rq_argp;	/* decoded arguments */
116	void *			rq_resp;	/* xdr'd results */
117
118	int			rq_reserved;	/* space on socket outq
119						 * reserved for this request
120						 */
121
122	/* Catering to nfsd */
123	struct svc_client *	rq_client;	/* RPC peer info */
124	struct svc_cacherep *	rq_cacherep;	/* cache info */
125	struct knfsd_fh *	rq_reffh;	/* Referrence filehandle, used to
126						 * determine what device number
127						 * to report (real or virtual)
128						 */
129
130	wait_queue_head_t	rq_wait;	/* synchronozation */
131};
132
133/*
134 * RPC program
135 */
136struct svc_program {
137	u32			pg_prog;	/* program number */
138	unsigned int		pg_lovers;	/* lowest version */
139	unsigned int		pg_hivers;	/* lowest version */
140	unsigned int		pg_nvers;	/* number of versions */
141	struct svc_version **	pg_vers;	/* version array */
142	char *			pg_name;	/* service name */
143	struct svc_stat *	pg_stats;	/* rpc statistics */
144};
145
146/*
147 * RPC program version
148 */
149struct svc_version {
150	u32			vs_vers;	/* version number */
151	u32			vs_nproc;	/* number of procedures */
152	struct svc_procedure *	vs_proc;	/* per-procedure info */
153
154	/* Override dispatch function (e.g. when caching replies).
155	 * A return value of 0 means drop the request.
156	 * vs_dispatch == NULL means use default dispatcher.
157	 */
158	int			(*vs_dispatch)(struct svc_rqst *, u32 *);
159};
160
161/*
162 * RPC procedure info
163 */
164typedef int	(*svc_procfunc)(struct svc_rqst *, void *argp, void *resp);
165struct svc_procedure {
166	svc_procfunc		pc_func;	/* process the request */
167	kxdrproc_t		pc_decode;	/* XDR decode args */
168	kxdrproc_t		pc_encode;	/* XDR encode result */
169	kxdrproc_t		pc_release;	/* XDR free result */
170	unsigned int		pc_argsize;	/* argument struct size */
171	unsigned int		pc_ressize;	/* result struct size */
172	unsigned int		pc_count;	/* call count */
173	unsigned int		pc_cachetype;	/* cache info (NFS) */
174	unsigned int		pc_xdrressize;	/* maximum size of XDR reply */
175};
176
177/*
178 * This is the RPC server thread function prototype
179 */
180typedef void		(*svc_thread_fn)(struct svc_rqst *);
181
182/*
183 * Function prototypes.
184 */
185struct svc_serv *  svc_create(struct svc_program *, unsigned int, unsigned int);
186int		   svc_create_thread(svc_thread_fn, struct svc_serv *);
187void		   svc_exit_thread(struct svc_rqst *);
188void		   svc_destroy(struct svc_serv *);
189int		   svc_process(struct svc_serv *, struct svc_rqst *);
190int		   svc_register(struct svc_serv *, int, unsigned short);
191void		   svc_wake_up(struct svc_serv *);
192void		   svc_reserve(struct svc_rqst *rqstp, int space);
193
194#endif /* SUNRPC_SVC_H */
195