1/*	$OpenBSD: nfs.h,v 1.54 2024/05/04 10:53:37 jsg Exp $	*/
2/*	$NetBSD: nfs.h,v 1.10.4.1 1996/05/27 11:23:56 fvdl Exp $	*/
3
4/*
5 * Copyright (c) 1989, 1993, 1995
6 *	The Regents of the University of California.  All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Rick Macklem at The University of Guelph.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 *    notice, this list of conditions and the following disclaimer in the
18 *    documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 *    may be used to endorse or promote products derived from this software
21 *    without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 *	@(#)nfs.h	8.4 (Berkeley) 5/1/95
36 */
37
38#ifndef _NFS_NFS_H_
39#define _NFS_NFS_H_
40
41#define NFS_TICKINTVL	5		/* Desired time for a tick (msec) */
42#define NFS_HZ		(hz / nfs_ticks) /* Ticks/sec */
43#define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
44#define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
45#define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
46#define	NFS_TIMEOUTMUL	2		/* Timeout/Delay multiplier */
47#define	NFS_MAXREXMIT	100		/* Stop counting after this many */
48#define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
49#define	NFS_MAXGRPS	16		/* Max. size of groups list */
50#define	NFS_MINATTRTIMO 5		/* Attribute cache timeout in sec */
51#define	NFS_MAXATTRTIMO 60
52#define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
53#define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
54#define NFS_READDIRSIZE	8192		/* Def. readdir size */
55#define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
56#define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
57#define	NFS_MAXASYNCDAEMON 	20	/* Max. number async_daemons runable */
58
59/*
60 * Ideally, NFS_DIRBLKSIZ should be bigger, but I've seen servers with
61 * broken NFS/ethernet drivers that won't work with anything bigger (Linux..)
62 */
63#define	NFS_DIRBLKSIZ	1024		/* Must be a multiple of DIRBLKSIZ */
64#define NFS_READDIRBLKSIZ	512	/* Size of read dir blocks. XXX */
65
66/*
67 * Oddballs
68 */
69#define NFS_CMPFH(n, f, s) \
70	((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
71#define NFS_ISV3(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
72#define NFS_SRVMAXDATA(n) \
73		(((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
74		 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
75
76/*
77 * The B_INVAFTERWRITE flag should be set to whatever is required by the
78 * buffer cache code to say "Invalidate the block after it is written back".
79 */
80#define	B_INVAFTERWRITE	B_INVAL
81
82/*
83 * Structures for the nfssvc(2) syscall.
84 * Not that anyone besides nfsd(8) should ever use it.
85 */
86struct nfsd_args {
87	int	sock;		/* Socket to serve */
88	caddr_t	name;		/* Client addr for connection based sockets */
89	int	namelen;	/* Length of name */
90};
91
92struct 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_int32_t	nsd_haddr;	/* IP address of client */
96	struct xucred	nsd_cr;		/* Cred. uid maps to */
97	int		nsd_authlen;	/* Length of auth string (ret) */
98	u_char		*nsd_authstr;	/* Auth string (ret) */
99	int		nsd_verflen;	/* and the verifier */
100	u_char		*nsd_verfstr;
101	struct timeval	nsd_timestamp;	/* timestamp from verifier */
102	u_int32_t	nsd_ttl;	/* credential ttl (sec) */
103};
104
105/*
106 * Stats structure
107 */
108struct nfsstats {
109	uint64_t	attrcache_hits;
110	uint64_t	attrcache_misses;
111	uint64_t	lookupcache_hits;
112	uint64_t	lookupcache_misses;
113	uint64_t	direofcache_hits;
114	uint64_t	direofcache_misses;
115	uint64_t	biocache_reads;
116	uint64_t	read_bios;
117	uint64_t	read_physios;
118	uint64_t	biocache_writes;
119	uint64_t	write_bios;
120	uint64_t	write_physios;
121	uint64_t	biocache_readlinks;
122	uint64_t	readlink_bios;
123	uint64_t	biocache_readdirs;
124	uint64_t	readdir_bios;
125	uint64_t	rpccnt[NFS_NPROCS];
126	uint64_t	rpcretries;
127	uint64_t	srvrpccnt[NFS_NPROCS];
128	uint64_t	srvrpc_errs;
129	uint64_t	srv_errs;
130	uint64_t	rpcrequests;
131	uint64_t	rpctimeouts;
132	uint64_t	rpcunexpected;
133	uint64_t	rpcinvalid;
134	uint64_t	srvcache_inproghits;
135	uint64_t	srvcache_idemdonehits;
136	uint64_t	srvcache_nonidemdonehits;
137	uint64_t	srvcache_misses;
138	uint64_t	forcedsync;
139	uint64_t	srvnqnfs_leases;
140	uint64_t	srvnqnfs_maxleases;
141	uint64_t	srvnqnfs_getleases;
142	uint64_t	srvvop_writes;
143};
144
145/*
146 * Flags for nfssvc() system call.
147 */
148#define	NFSSVC_NFSD	0x004
149#define	NFSSVC_ADDSOCK	0x008
150
151/*
152 * fs.nfs sysctl(3) identifiers
153 */
154#define	NFS_NFSSTATS	1	/* struct: struct nfsstats */
155#define	NFS_NIOTHREADS	2	/* number of i/o threads */
156#define	NFS_MAXID	3
157
158#define FS_NFS_NAMES { \
159			{ 0, 0 }, \
160			{ "nfsstats", CTLTYPE_STRUCT }, \
161			{ "iothreads", CTLTYPE_INT } \
162}
163
164/*
165 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
166 * What should be in this set is open to debate, but I believe that since
167 * I/O system calls on ufs are never interrupted by signals the set should
168 * be minimal. My reasoning is that many current programs that use signals
169 * such as SIGALRM will not expect file I/O system calls to be interrupted
170 * by them and break.
171 */
172#ifdef _KERNEL
173extern int nfs_niothreads;
174
175struct uio; struct buf; struct vattr; struct nameidata;	/* XXX */
176
177#define	NFSINT_SIGMASK	(sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
178			 sigmask(SIGHUP)|sigmask(SIGQUIT))
179
180/*
181 * Socket errors ignored for connectionless sockets??
182 * For now, ignore them all
183 */
184#define	NFSIGNORE_SOERROR(s, e) \
185		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
186		((s) & PR_CONNREQUIRED) == 0)
187
188/*
189 * Nfs outstanding request list element
190 */
191struct nfsreq {
192	TAILQ_ENTRY(nfsreq) r_chain;
193	struct mbuf	*r_mreq;
194	struct mbuf	*r_mrep;
195	struct mbuf	*r_md;
196	caddr_t		r_dpos;
197	struct nfsmount *r_nmp;
198	struct vnode	*r_vp;
199	u_int32_t	r_xid;
200	int		r_flags;	/* flags on request, see below */
201	int		r_rexmit;	/* current retrans count */
202	int		r_timer;	/* tick counter on reply */
203	int		r_procnum;	/* NFS procedure number */
204	int		r_rtt;		/* RTT for rpc */
205	struct proc	*r_procp;	/* Proc that did I/O system call */
206};
207
208/* Flag values for r_flags */
209#define R_TIMING	0x01		/* timing request (in mntp) */
210#define R_SENT		0x02		/* request has been sent */
211#define	R_SOFTTERM	0x04		/* soft mnt, too many retries */
212#define	R_INTR		0x08		/* intr mnt, signal pending */
213#define	R_SOCKERR	0x10		/* Fatal error on socket */
214#define	R_TPRINTFMSG	0x20		/* Did a tprintf msg. */
215#define	R_MUSTRESEND	0x40		/* Must resend request */
216
217/*
218 * On fast networks, the estimator will try to reduce the
219 * timeout lower than the latency of the server's disks,
220 * which results in too many timeouts, so cap the lower
221 * bound.
222 */
223#define NFS_MINRTO	(NFS_HZ >> 2)
224
225/*
226 * Keep the RTO from increasing to unreasonably large values
227 * when a server is not responding.
228 */
229#define NFS_MAXRTO	(20 * NFS_HZ)
230
231enum nfs_rto_timers {
232	NFS_DEFAULT_TIMER,
233	NFS_GETATTR_TIMER,
234	NFS_LOOKUP_TIMER,
235	NFS_READ_TIMER,
236	NFS_WRITE_TIMER,
237};
238#define NFS_MAX_TIMER	(NFS_WRITE_TIMER)
239
240#define NFS_INITRTT	(NFS_HZ << 3)
241
242/*
243 * Network address hash list element
244 */
245union nethostaddr {
246	u_int32_t had_inetaddr;
247	struct mbuf *had_nam;
248};
249
250struct nfssvc_sock {
251	TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */
252	struct file	*ns_fp;		/* fp from the... */
253	struct socket	*ns_so;		/* ...socket this struct wraps */
254	struct mbuf	*ns_nam;	/* MT_SONAME of client */
255	struct mbuf	*ns_raw;	/* head of unpeeked mbufs */
256	struct mbuf	*ns_rawend;	/* tail of unpeeked mbufs */
257	struct mbuf	*ns_rec;	/* queued RPC records */
258	struct mbuf	*ns_recend;	/* last queued RPC record */
259	struct mbuf	*ns_frag;	/* end of record fragment */
260	int		ns_flag;	/* socket status flags */
261	int		ns_solock;	/* lock for connected socket */
262	int		ns_cc;		/* actual chars queued */
263	int		ns_reclen;	/* length of first queued record */
264	u_int32_t	ns_sref;	/* # of refs to this struct */
265};
266
267/* Bits for "ns_flag" */
268#define	SLP_VALID	0x01	/* connection is usable */
269#define	SLP_DOREC	0x02	/* receive operation required */
270#define	SLP_NEEDQ	0x04	/* connection has data to queue from socket */
271#define	SLP_DISCONN	0x08	/* connection is closed */
272#define	SLP_GETSTREAM	0x10	/* extracting RPC from TCP connection */
273#define	SLP_LASTFRAG	0x20	/* last fragment received on TCP connection */
274#define	SLP_ALLFLAGS	0xff	/* convenience */
275
276/*
277 * One of these structures is allocated for each nfsd.
278 */
279struct nfsd {
280	TAILQ_ENTRY(nfsd) nfsd_chain;	/* List of all nfsd's */
281	int		nfsd_flag;	/* NFSD_ flags */
282	struct nfssvc_sock *nfsd_slp;	/* Current socket */
283	struct proc	*nfsd_procp;	/* Proc ptr */
284	struct nfsrv_descript *nfsd_nd;	/* Associated nfsrv_descript */
285};
286
287/* Bits for "nfsd_flag" */
288#define	NFSD_WAITING	0x01
289#define	NFSD_REQINPROG	0x02
290
291/*
292 * This structure is used by the server for describing each request.
293 */
294struct nfsrv_descript {
295	struct mbuf		*nd_mrep;	/* Request mbuf list */
296	struct mbuf		*nd_md;		/* Current dissect mbuf */
297	struct mbuf		*nd_nam;	/* and socket addr */
298	struct mbuf		*nd_nam2;	/* return socket addr */
299	caddr_t			nd_dpos;	/* Current dissect pos */
300	unsigned int		nd_procnum;	/* RPC # */
301	int			nd_flag;	/* nd_flag */
302	int			nd_repstat;	/* Reply status */
303	u_int32_t		nd_retxid;	/* Reply xid */
304	struct ucred		nd_cr;		/* Credentials */
305};
306
307/* Bits for "nd_flag" */
308#define ND_NFSV3	0x08
309
310extern struct pool nfsreqpl;
311extern struct pool nfs_node_pool;
312extern TAILQ_HEAD(nfsdhead, nfsd) nfsd_head;
313extern int nfsd_head_flag;
314#define	NFSD_CHECKSLP	0x01
315
316#endif	/* _KERNEL */
317#endif /* _NFS_NFS_H */
318