xref: /freebsd/sys/nfsclient/nfsargs.h (revision 6ae324074ae50984e852f8b7b7f5c944120eb110)
1 /*
2  * Copyright (c) 1989, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Rick Macklem at The University of Guelph.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by the University of
19  *	California, Berkeley and its contributors.
20  * 4. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *	@(#)nfs.h	8.1 (Berkeley) 6/10/93
37  * $Id: nfs.h,v 1.5 1994/10/02 17:26:54 phk Exp $
38  */
39 
40 #ifndef _NFS_NFS_H_
41 #define _NFS_NFS_H_
42 
43 /*
44  * Tunable constants for nfs
45  */
46 
47 #define	NFS_MAXIOVEC	34
48 #define NFS_HZ		25		/* Ticks per second for NFS timeouts */
49 #define	NFS_TIMEO	(1*NFS_HZ)	/* Default timeout = 1 second */
50 #define	NFS_MINTIMEO	(1*NFS_HZ)	/* Min timeout to use */
51 #define	NFS_MAXTIMEO	(60*NFS_HZ)	/* Max timeout to backoff to */
52 #define	NFS_MINIDEMTIMEO (5*NFS_HZ)	/* Min timeout for non-idempotent ops*/
53 #define	NFS_MAXREXMIT	100		/* Stop counting after this many */
54 #define	NFS_MAXWINDOW	1024		/* Max number of outstanding requests */
55 #define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
56 #define	NFS_MAXGRPS	16		/* Max. size of groups list */
57 #ifndef NFS_MINATTRTIMO
58 #define	NFS_MINATTRTIMO 5		/* Attribute cache timeout in sec */
59 #endif
60 #ifndef NFS_MAXATTRTIMO
61 #define	NFS_MAXATTRTIMO 60
62 #endif
63 #define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
64 #define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
65 #define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
66 #define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
67 #define	NFS_MAXREADDIR	NFS_MAXDATA	/* Max. size of directory read */
68 #define	NFS_MAXUIDHASH	64		/* Max. # of hashed uid entries/mp */
69 #define	NFS_MAXASYNCDAEMON 20	/* Max. number async_daemons runable */
70 #define	NFS_DIRBLKSIZ	1024		/* Size of an NFS directory block */
71 #define	NMOD(a)		((a) % nfs_asyncdaemons)
72 
73 /*
74  * Set the attribute timeout based on how recently the file has been modified.
75  */
76 #define	NFS_ATTRTIMEO(np) \
77 	((((np)->n_flag & NMODIFIED) || \
78 	 (time.tv_sec - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \
79 	 ((time.tv_sec - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \
80 	  (time.tv_sec - (np)->n_mtime) / 10))
81 
82 /*
83  * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
84  * should ever try and use it.
85  */
86 struct nfsd_args {
87 	int	sock;		/* Socket to serve */
88 	caddr_t	name;		/* Client address for connection based sockets */
89 	int	namelen;	/* Length of name */
90 };
91 
92 struct nfsd_srvargs {
93 	struct nfsd	*nsd_nfsd;	/* Pointer to in kernel nfsd struct */
94 	uid_t		nsd_uid;	/* Effective uid mapped to cred */
95 	u_long		nsd_haddr;	/* Ip address of client */
96 	struct ucred	nsd_cr;		/* Cred. uid maps to */
97 	int		nsd_authlen;	/* Length of auth string (ret) */
98 	char		*nsd_authstr;	/* Auth string (ret) */
99 };
100 
101 struct nfsd_cargs {
102 	char		*ncd_dirp;	/* Mount dir path */
103 	uid_t		ncd_authuid;	/* Effective uid */
104 	int		ncd_authtype;	/* Type of authenticator */
105 	int		ncd_authlen;	/* Length of authenticator string */
106 	char		*ncd_authstr;	/* Authenticator string */
107 };
108 
109 /*
110  * Stats structure
111  */
112 struct nfsstats {
113 	int	attrcache_hits;
114 	int	attrcache_misses;
115 	int	lookupcache_hits;
116 	int	lookupcache_misses;
117 	int	direofcache_hits;
118 	int	direofcache_misses;
119 	int	biocache_reads;
120 	int	read_bios;
121 	int	read_physios;
122 	int	biocache_writes;
123 	int	write_bios;
124 	int	write_physios;
125 	int	biocache_readlinks;
126 	int	readlink_bios;
127 	int	biocache_readdirs;
128 	int	readdir_bios;
129 	int	rpccnt[NFS_NPROCS];
130 	int	rpcretries;
131 	int	srvrpccnt[NFS_NPROCS];
132 	int	srvrpc_errs;
133 	int	srv_errs;
134 	int	rpcrequests;
135 	int	rpctimeouts;
136 	int	rpcunexpected;
137 	int	rpcinvalid;
138 	int	srvcache_inproghits;
139 	int	srvcache_idemdonehits;
140 	int	srvcache_nonidemdonehits;
141 	int	srvcache_misses;
142 	int	srvnqnfs_leases;
143 	int	srvnqnfs_maxleases;
144 	int	srvnqnfs_getleases;
145 };
146 
147 /*
148  * Flags for nfssvc() system call.
149  */
150 #define	NFSSVC_BIOD	0x002
151 #define	NFSSVC_NFSD	0x004
152 #define	NFSSVC_ADDSOCK	0x008
153 #define	NFSSVC_AUTHIN	0x010
154 #define	NFSSVC_GOTAUTH	0x040
155 #define	NFSSVC_AUTHINFAIL 0x080
156 #define	NFSSVC_MNTD	0x100
157 
158 /*
159  * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
160  * What should be in this set is open to debate, but I believe that since
161  * I/O system calls on ufs are never interrupted by signals the set should
162  * be minimal. My reasoning is that many current programs that use signals
163  * such as SIGALRM will not expect file I/O system calls to be interrupted
164  * by them and break.
165  */
166 #ifdef KERNEL
167 #define	NFSINT_SIGMASK	(sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
168 			 sigmask(SIGHUP)|sigmask(SIGQUIT))
169 
170 /*
171  * Socket errors ignored for connectionless sockets??
172  * For now, ignore them all
173  */
174 #define	NFSIGNORE_SOERROR(s, e) \
175 		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
176 		((s) & PR_CONNREQUIRED) == 0)
177 
178 /*
179  * Nfs outstanding request list element
180  */
181 struct nfsreq {
182 	TAILQ_ENTRY(nfsreq) r_chain;
183 	struct mbuf	*r_mreq;
184 	struct mbuf	*r_mrep;
185 	struct mbuf	*r_md;
186 	caddr_t		r_dpos;
187 	struct nfsmount *r_nmp;
188 	struct vnode	*r_vp;
189 	u_long		r_xid;
190 	int		r_flags;	/* flags on request, see below */
191 	int		r_retry;	/* max retransmission count */
192 	int		r_rexmit;	/* current retrans count */
193 	int		r_timer;	/* tick counter on reply */
194 	int		r_procnum;	/* NFS procedure number */
195 	int		r_rtt;		/* RTT for rpc */
196 	struct proc	*r_procp;	/* Proc that did I/O system call */
197 };
198 
199 /*
200  * Queue head for nfsreq's
201  */
202 TAILQ_HEAD(, nfsreq) nfs_reqq;
203 
204 /* Flag values for r_flags */
205 #define R_TIMING	0x01		/* timing request (in mntp) */
206 #define R_SENT		0x02		/* request has been sent */
207 #define	R_SOFTTERM	0x04		/* soft mnt, too many retries */
208 #define	R_INTR		0x08		/* intr mnt, signal pending */
209 #define	R_SOCKERR	0x10		/* Fatal error on socket */
210 #define	R_TPRINTFMSG	0x20		/* Did a tprintf msg. */
211 #define	R_MUSTRESEND	0x40		/* Must resend request */
212 #define	R_GETONEREP	0x80		/* Probe for one reply only */
213 
214 struct nfsstats nfsstats;
215 
216 /*
217  * A list of nfssvc_sock structures is maintained with all the sockets
218  * that require service by the nfsd.
219  * The nfsuid structs hang off of the nfssvc_sock structs in both lru
220  * and uid hash lists.
221  */
222 #define	NUIDHASHSIZ	32
223 #define	NUIDHASH(sock, uid) \
224 	(&(sock)->ns_uidhashtbl[(uid) & (sock)->ns_uidhash])
225 
226 /*
227  * Network address hash list element
228  */
229 union nethostaddr {
230 	u_long had_inetaddr;
231 	struct mbuf *had_nam;
232 };
233 
234 struct nfsuid {
235 	TAILQ_ENTRY(nfsuid) nu_lru;	/* LRU chain */
236 	LIST_ENTRY(nfsuid) nu_hash;	/* Hash list */
237 	int		nu_flag;	/* Flags */
238 	uid_t		nu_uid;		/* Uid mapped by this entry */
239 	union nethostaddr nu_haddr;	/* Host addr. for dgram sockets */
240 	struct ucred	nu_cr;		/* Cred uid mapped to */
241 };
242 
243 #define	nu_inetaddr	nu_haddr.had_inetaddr
244 #define	nu_nam		nu_haddr.had_nam
245 /* Bits for nu_flag */
246 #define	NU_INETADDR	0x1
247 
248 struct nfssvc_sock {
249 	TAILQ_ENTRY(nfssvc_sock) ns_chain;	/* List of all nfssvc_sock's */
250 	TAILQ_HEAD(, nfsuid) ns_uidlruhead;
251 	LIST_HEAD(, nfsuid) *ns_uidhashtbl;
252 	u_long		ns_uidhash;
253 
254 	int		ns_flag;
255 	u_long		ns_sref;
256 	struct file	*ns_fp;
257 	struct socket	*ns_so;
258 	int		ns_solock;
259 	struct mbuf	*ns_nam;
260 	int		ns_cc;
261 	struct mbuf	*ns_raw;
262 	struct mbuf	*ns_rawend;
263 	int		ns_reclen;
264 	struct mbuf	*ns_rec;
265 	struct mbuf	*ns_recend;
266 	int		ns_numuids;
267 };
268 
269 /* Bits for "ns_flag" */
270 #define	SLP_VALID	0x01
271 #define	SLP_DOREC	0x02
272 #define	SLP_NEEDQ	0x04
273 #define	SLP_DISCONN	0x08
274 #define	SLP_GETSTREAM	0x10
275 #define SLP_ALLFLAGS	0xff
276 
277 TAILQ_HEAD(, nfssvc_sock) nfssvc_sockhead;
278 int nfssvc_sockhead_flag;
279 #define	SLP_INIT	0x01
280 #define	SLP_WANTINIT	0x02
281 
282 /*
283  * One of these structures is allocated for each nfsd.
284  */
285 struct nfsd {
286 	TAILQ_ENTRY(nfsd) nd_chain;	/* List of all nfsd's */
287 	int		nd_flag;	/* NFSD_ flags */
288 	struct nfssvc_sock *nd_slp;	/* Current socket */
289 	struct mbuf	*nd_nam;	/* Client addr for datagram req. */
290 	struct mbuf	*nd_mrep;	/* Req. mbuf list */
291 	struct mbuf	*nd_md;
292 	caddr_t		nd_dpos;	/* Position in list */
293 	int		nd_procnum;	/* RPC procedure number */
294 	u_long		nd_retxid;	/* RPC xid */
295 	int		nd_repstat;	/* Reply status value */
296 	struct ucred	nd_cr;		/* Credentials for req. */
297 	int		nd_nqlflag;	/* Leasing flag */
298 	u_long		nd_duration;	/* Lease duration */
299 	int		nd_authlen;	/* Authenticator len */
300 	u_char		nd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
301 	struct proc	*nd_procp;	/* Proc ptr */
302 };
303 
304 /* Bits for "nd_flag" */
305 #define	NFSD_WAITING	0x01
306 #define	NFSD_REQINPROG	0x02
307 #define	NFSD_NEEDAUTH	0x04
308 #define	NFSD_AUTHFAIL	0x08
309 
310 TAILQ_HEAD(, nfsd) nfsd_head;
311 int nfsd_head_flag;
312 #define	NFSD_CHECKSLP	0x01
313 
314 int	nfs_reply __P((struct nfsreq *));
315 int	nfs_getreq __P((struct nfsd *,int));
316 int	nfs_send __P((struct socket *,struct mbuf *,struct mbuf *,struct nfsreq *));
317 int	nfs_rephead __P((int,struct nfsd *,int,int,u_quad_t *,struct mbuf **,struct mbuf **,caddr_t *));
318 int	nfs_sndlock __P((int *,struct nfsreq *));
319 int	nfs_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *));
320 int	nfs_vinvalbuf __P((struct vnode *,int,struct ucred *,struct proc *,int));
321 int	nfs_readrpc __P((struct vnode *,struct uio *,struct ucred *));
322 int	nfs_writerpc __P((struct vnode *,struct uio *,struct ucred *,int));
323 int	nfs_readdirrpc __P((register struct vnode *,struct uio *,struct ucred *));
324 int	nfs_asyncio __P((struct buf *,struct ucred *));
325 int	nfs_doio __P((struct buf *,struct ucred *,struct proc *));
326 int	nfs_readlinkrpc __P((struct vnode *,struct uio *,struct ucred *));
327 int	nfs_sigintr __P((struct nfsmount *,struct nfsreq *r,struct proc *));
328 int	nfs_readdirlookrpc __P((struct vnode *,register struct uio *,struct ucred *));
329 int	nfsm_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *));
330 int	nfsrv_fhtovp __P((fhandle_t *,int,struct vnode **,struct ucred *,struct nfssvc_sock *,struct mbuf *,int *));
331 int	nfsrv_access __P((struct vnode *,int,struct ucred *,int,struct proc *));
332 int	netaddr_match __P((int,union nethostaddr *,struct mbuf *));
333 int	nfs_request __P((struct vnode *,struct mbuf *,int,struct proc *,struct ucred *,struct mbuf **,struct mbuf **,caddr_t *));
334 int	nfs_loadattrcache __P((struct vnode **,struct mbuf **,caddr_t *,struct vattr *));
335 int	nfs_namei __P((struct nameidata *,fhandle_t *,int,struct nfssvc_sock *,struct mbuf *,struct mbuf **,caddr_t *,struct proc *));
336 void	nfsm_adj __P((struct mbuf *,int,int));
337 int	nfsm_mbuftouio __P((struct mbuf **,struct uio *,int,caddr_t *));
338 void	nfsrv_initcache __P((void));
339 int	nfs_rcvlock __P((struct nfsreq *));
340 int	nfs_getauth __P((struct nfsmount *,struct nfsreq *,struct ucred *,int *,char **,int *));
341 int	nfs_msg __P((struct proc *,char *,char *));
342 int	nfs_adv __P((struct mbuf **,caddr_t *,int,int));
343 int	nfsrv_getstream __P((struct nfssvc_sock *,int));
344 void	nfs_nhinit __P((void));
345 void	nfs_timer __P((void*));
346 struct nfsnodehashhead * nfs_hash __P((nfsv2fh_t *));
347 int	nfssvc_iod __P((struct proc *));
348 int	nfssvc_nfsd __P((struct nfsd_srvargs *,caddr_t,struct proc *));
349 int	nfssvc_addsock __P((struct file *,struct mbuf *));
350 int	nfsrv_dorec __P((struct nfssvc_sock *,struct nfsd *));
351 int	nfsrv_getcache __P((struct mbuf *,struct nfsd *,struct mbuf **));
352 void	nfsrv_updatecache __P((struct mbuf *,struct nfsd *,int,struct mbuf *));
353 int	mountnfs __P((struct nfs_args *,struct mount *,struct mbuf *,char *,char *,struct vnode **));
354 int	nfs_connect __P((struct nfsmount *,struct nfsreq *));
355 int	nfs_getattrcache __P((struct vnode *,struct vattr *));
356 int	nfsm_strtmbuf __P((struct mbuf **,char **,char *,long));
357 int	nfs_bioread __P((struct vnode *,struct uio *,int,struct ucred *));
358 int	nfsm_uiotombuf __P((struct uio *,struct mbuf **,int,caddr_t *));
359 void	nfsrv_init __P((int));
360 #endif	/* KERNEL */
361 
362 #endif
363