xref: /freebsd/sys/nfsclient/nfs.h (revision e4e9813eb92cd7c4d4b819a8fbed5cbd3d92f5d8)
1 /*-
2  * Copyright (c) 1989, 1993, 1995
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  * 4. Neither the name of the University nor the names of its contributors
17  *    may be used to endorse or promote products derived from this software
18  *    without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  *	@(#)nfs.h	8.4 (Berkeley) 5/1/95
33  * $FreeBSD$
34  */
35 
36 #ifndef _NFSCLIENT_NFS_H_
37 #define _NFSCLIENT_NFS_H_
38 
39 #ifdef _KERNEL
40 #include "opt_nfs.h"
41 #endif
42 
43 #include <nfsclient/nfsargs.h>
44 
45 /*
46  * Tunable constants for nfs
47  */
48 
49 #define NFS_TICKINTVL	10		/* Desired time for a tick (msec) */
50 #define NFS_HZ		(hz / nfs_ticks) /* Ticks/sec */
51 #define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
52 #define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
53 #define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
54 #define	NFS_MINIDEMTIMEO (5 * NFS_HZ)	/* Min timeout for non-idempotent ops*/
55 #define	NFS_MAXREXMIT	100		/* Stop counting after this many */
56 #define	NFS_RETRANS	10		/* Num of retrans for UDP soft mounts */
57 #define	NFS_RETRANS_TCP	2		/* Num of retrans for TCP soft mounts */
58 #define	NFS_MAXGRPS	16		/* Max. size of groups list */
59 #ifndef NFS_MINATTRTIMO
60 #define	NFS_MINATTRTIMO 3		/* VREG attrib cache timeout in sec */
61 #endif
62 #ifndef NFS_MAXATTRTIMO
63 #define	NFS_MAXATTRTIMO 60
64 #endif
65 #ifndef NFS_MINDIRATTRTIMO
66 #define	NFS_MINDIRATTRTIMO 30		/* VDIR attrib cache timeout in sec */
67 #endif
68 #ifndef NFS_MAXDIRATTRTIMO
69 #define	NFS_MAXDIRATTRTIMO 60
70 #endif
71 #define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
72 #define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
73 #define NFS_READDIRSIZE	8192		/* Def. readdir size */
74 #define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
75 #define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
76 #define	NFS_MAXASYNCDAEMON 	64	/* Max. number async_daemons runnable */
77 #define	NFS_DIRBLKSIZ	4096		/* Must be a multiple of DIRBLKSIZ */
78 #ifdef _KERNEL
79 #define	DIRBLKSIZ	512		/* XXX we used to use ufs's DIRBLKSIZ */
80 #endif
81 #define NFS_MAXDEADTHRESH	9	/* How long till we say 'server not responding' */
82 
83 /*
84  * Oddballs
85  */
86 #define NFS_CMPFH(n, f, s) \
87 	((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
88 #define NFS_ISV3(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
89 #define NFS_ISV4(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV4)
90 
91 #define NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier for V3 */
92 #define NFSSTA_GOTFSINFO	0x00100000  /* Got the V3 fsinfo */
93 #define	NFSSTA_SNDLOCK		0x01000000  /* Send socket lock */
94 #define	NFSSTA_WANTSND		0x02000000  /* Want above */
95 #define	NFSSTA_TIMEO		0x10000000  /* Experiencing a timeout */
96 
97 
98 /*
99  * XXX to allow amd to include nfs.h without nfsproto.h
100  */
101 #ifdef NFS_NPROCS
102 #include <nfsclient/nfsstats.h>
103 #endif
104 
105 /*
106  * vfs.nfs sysctl(3) identifiers
107  */
108 #define NFS_NFSSTATS	1		/* struct: struct nfsstats */
109 
110 /*
111  * File context information for nfsv4.	Currently, there is only one
112  * lockowner for the whole machine "0."
113  */
114 struct nfs4_fctx {
115 	TAILQ_ENTRY(nfs4_fstate) next;
116 	uint32_t	refcnt;
117 	struct nfs4_lowner *lop;
118 	struct nfsnode *np;
119 	char		stateid[NFSX_V4STATEID];
120 };
121 
122 #ifdef _KERNEL
123 
124 #ifdef MALLOC_DECLARE
125 MALLOC_DECLARE(M_NFSREQ);
126 MALLOC_DECLARE(M_NFSDIROFF);
127 MALLOC_DECLARE(M_NFSBIGFH);
128 MALLOC_DECLARE(M_NFSHASH);
129 MALLOC_DECLARE(M_NFSDIRECTIO);
130 #endif
131 
132 extern struct uma_zone *nfsmount_zone;
133 
134 extern struct callout nfs_callout;
135 extern struct nfsstats nfsstats;
136 extern struct mtx nfs_iod_mtx;
137 
138 extern int nfs_numasync;
139 extern unsigned int nfs_iodmax;
140 extern int nfs_pbuf_freecnt;
141 extern int nfs_ticks;
142 
143 /* Data constants in XDR form */
144 extern u_int32_t nfs_true, nfs_false, nfs_xdrneg1;
145 extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers;
146 extern u_int32_t rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr;
147 
148 extern int nfsv3_procid[NFS_NPROCS];
149 
150 struct uio;
151 struct buf;
152 struct vattr;
153 struct nameidata;
154 
155 /*
156  * Socket errors ignored for connectionless sockets??
157  * For now, ignore them all
158  */
159 #define	NFSIGNORE_SOERROR(s, e) \
160 		((e) != EINTR && (e) != EIO && \
161 		 (e) != ERESTART && (e) != EWOULDBLOCK && \
162 		((s) & PR_CONNREQUIRED) == 0)
163 
164 /*
165  * Nfs outstanding request list element
166  */
167 struct nfsreq {
168 	TAILQ_ENTRY(nfsreq) r_chain;
169 	struct mbuf	*r_mreq;
170 	struct mbuf	*r_mrep;
171 	struct mbuf	*r_md;
172 	caddr_t		r_dpos;
173 	struct nfsmount *r_nmp;
174 	struct vnode	*r_vp;
175 	u_int32_t	r_xid;
176 	int		r_flags;	/* flags on request, see below */
177 	int		r_retry;	/* max retransmission count */
178 	int		r_rexmit;	/* current retrans count */
179 	int		r_timer;	/* tick counter on reply */
180 	u_int32_t	r_procnum;	/* NFS procedure number */
181 	int		r_rtt;		/* RTT for rpc */
182 	int		r_lastmsg;	/* last tprintf */
183 	struct thread	*r_td;		/* Proc that did I/O system call */
184 	struct mtx	r_mtx;		/* Protects nfsreq fields */
185 };
186 
187 /*
188  * Queue head for nfsreq's
189  */
190 extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
191 
192 /* Flag values for r_flags */
193 #define R_TIMING	0x01		/* timing request (in mntp) */
194 #define R_SENT		0x02		/* request has been sent */
195 #define	R_SOFTTERM	0x04		/* soft mnt, too many retries */
196 #define	R_RESENDERR	0x08		/* Resend failed */
197 #define	R_SOCKERR	0x10		/* Fatal error on socket */
198 #define	R_TPRINTFMSG	0x20		/* Did a tprintf msg. */
199 #define	R_MUSTRESEND	0x40		/* Must resend request */
200 #define	R_GETONEREP	0x80		/* Probe for one reply only */
201 #define	R_REXMIT_INPROG	0x100		/* Re-transmit in progress */
202 
203 /*
204  * Pointers to ops that differ from v3 to v4
205  */
206 struct nfs_rpcops {
207 	int	(*nr_readrpc)(struct vnode *vp, struct uio *uiop, struct ucred *cred);
208 	int	(*nr_writerpc)(struct vnode *vp, struct uio *uiop, struct ucred *cred,
209 			       int *iomode, int *must_commit);
210 	int	(*nr_writebp)(struct buf *bp, int force, struct thread *td);
211 	int	(*nr_readlinkrpc)(struct vnode *vp, struct uio *uiop, struct ucred *cred);
212 	void	(*nr_invaldir)(struct vnode *vp);
213 	int	(*nr_commit)(struct vnode *vp, u_quad_t offset, int cnt,
214 			     struct ucred *cred, struct thread *td);
215 };
216 
217 /*
218  * Defines for WebNFS
219  */
220 
221 #define WEBNFS_ESC_CHAR		'%'
222 #define WEBNFS_SPECCHAR_START	0x80
223 
224 #define WEBNFS_NATIVE_CHAR	0x80
225 /*
226  * ..
227  * Possibly more here in the future.
228  */
229 
230 /*
231  * Macro for converting escape characters in WebNFS pathnames.
232  * Should really be in libkern.
233  */
234 
235 #define HEXTOC(c) \
236 	((c) >= 'a' ? ((c) - ('a' - 10)) : \
237 	    ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
238 #define HEXSTRTOI(p) \
239 	((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
240 
241 /* nfs_sigintr() helper, when 'rep' has all we need */
242 #define NFS_SIGREP(rep)		nfs_sigintr((rep)->r_nmp, (rep), (rep)->r_td)
243 
244 #ifdef NFS_DEBUG
245 
246 extern int nfs_debug;
247 #define NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
248 #define NFS_DEBUG_WG		2 /* server write gathering */
249 #define NFS_DEBUG_RC		4 /* server request caching */
250 
251 #define NFS_DPF(cat, args)					\
252 	do {							\
253 		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
254 	} while (0)
255 
256 #else
257 
258 #define NFS_DPF(cat, args)
259 
260 #endif
261 
262 /*
263  * On fast networks, the estimator will try to reduce the
264  * timeout lower than the latency of the server's disks,
265  * which results in too many timeouts, so cap the lower
266  * bound.
267  */
268 #define NFS_MINRTO	(NFS_HZ >> 2)
269 
270 /*
271  * Keep the RTO from increasing to unreasonably large values
272  * when a server is not responding.
273  */
274 #define NFS_MAXRTO	(20 * NFS_HZ)
275 
276 enum nfs_rto_timer_t {
277 	NFS_DEFAULT_TIMER,
278 	NFS_GETATTR_TIMER,
279 	NFS_LOOKUP_TIMER,
280 	NFS_READ_TIMER,
281 	NFS_WRITE_TIMER,
282 };
283 #define NFS_MAX_TIMER	(NFS_WRITE_TIMER)
284 
285 #define NFS_INITRTT	(NFS_HZ << 3)
286 
287 vfs_init_t nfs_init;
288 vfs_uninit_t nfs_uninit;
289 int	nfs_mountroot(struct mount *mp, struct thread *td);
290 
291 #ifndef NFS4_USE_RPCCLNT
292 int	nfs_send(struct socket *, struct sockaddr *, struct mbuf *,
293 	    struct nfsreq *);
294 int	nfs_sndlock(struct nfsreq *);
295 void	nfs_sndunlock(struct nfsreq *);
296 #endif /* ! NFS4_USE_RPCCLNT */
297 
298 int	nfs_vinvalbuf(struct vnode *, int, struct thread *, int);
299 int	nfs_readrpc(struct vnode *, struct uio *, struct ucred *);
300 int	nfs_writerpc(struct vnode *, struct uio *, struct ucred *, int *,
301 	    int *);
302 int	nfs_commit(struct vnode *vp, u_quad_t offset, int cnt,
303 	    struct ucred *cred, struct thread *td);
304 int	nfs_readdirrpc(struct vnode *, struct uio *, struct ucred *);
305 int	nfs_nfsiodnew(void);
306 int	nfs_asyncio(struct nfsmount *, struct buf *, struct ucred *, struct thread *);
307 int	nfs_doio(struct vnode *, struct buf *, struct ucred *, struct thread *);
308 void    nfs_doio_directwrite (struct buf *);
309 void    nfs_up(struct nfsreq *, struct nfsmount *, struct thread *,
310 	    const char *, int);
311 void	nfs_down(struct nfsreq *, struct nfsmount *, struct thread *,
312 	    const char *, int, int);
313 int	nfs_readlinkrpc(struct vnode *, struct uio *, struct ucred *);
314 int	nfs_sigintr(struct nfsmount *, struct nfsreq *, struct thread *);
315 int	nfs_readdirplusrpc(struct vnode *, struct uio *, struct ucred *);
316 int	nfs_request(struct vnode *, struct mbuf *, int, struct thread *,
317 	    struct ucred *, struct mbuf **, struct mbuf **, caddr_t *);
318 int	nfs_loadattrcache(struct vnode **, struct mbuf **, caddr_t *,
319 	    struct vattr *, int);
320 int	nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *);
321 void	nfs_nhinit(void);
322 void	nfs_nhuninit(void);
323 int	nfs_nmcancelreqs(struct nfsmount *);
324 void	nfs_timer(void*);
325 
326 int	nfs_connect(struct nfsmount *, struct nfsreq *);
327 void	nfs_disconnect(struct nfsmount *);
328 void	nfs_safedisconnect(struct nfsmount *);
329 int	nfs_getattrcache(struct vnode *, struct vattr *);
330 int	nfsm_strtmbuf(struct mbuf **, char **, const char *, long);
331 int	nfs_bioread(struct vnode *, struct uio *, int, struct ucred *);
332 int	nfsm_uiotombuf(struct uio *, struct mbuf **, int, caddr_t *);
333 void	nfs_clearcommit(struct mount *);
334 int	nfs_writebp(struct buf *, int, struct thread *);
335 int	nfs_fsinfo(struct nfsmount *, struct vnode *, struct ucred *,
336 	    struct thread *);
337 int	nfs_meta_setsize (struct vnode *, struct ucred *,
338 	    struct thread *, u_quad_t);
339 
340 void    nfs_set_sigmask __P((struct thread *td, sigset_t *oldset));
341 void    nfs_restore_sigmask __P((struct thread *td, sigset_t *set));
342 int     nfs_msleep __P((struct thread *td, void *ident, struct mtx *mtx, int priority,
343 			char *wmesg, int timo));
344 
345 #endif	/* _KERNEL */
346 
347 #endif
348