xref: /freebsd/sys/nfsclient/nfs.h (revision bb15ca603fa442c72dde3f3cb8b46db6970e3950)
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 3		/* VDIR attrib cache timeout in sec */
67 #endif
68 #ifndef NFS_MAXDIRATTRTIMO
69 #define	NFS_MAXDIRATTRTIMO 60
70 #endif
71 #ifndef	NFS_ACCESSCACHESIZE
72 #define	NFS_ACCESSCACHESIZE 8		/* Per-node access cache entries */
73 #endif
74 #define	NFS_WSIZE	8192		/* Def. write data size <= 8192 */
75 #define	NFS_RSIZE	8192		/* Def. read data size <= 8192 */
76 #define NFS_READDIRSIZE	8192		/* Def. readdir size */
77 #define	NFS_DEFRAHEAD	1		/* Def. read ahead # blocks */
78 #define	NFS_MAXRAHEAD	4		/* Max. read ahead # blocks */
79 #define	NFS_MAXASYNCDAEMON 	64	/* Max. number async_daemons runnable */
80 #define	NFS_DIRBLKSIZ	4096		/* Must be a multiple of DIRBLKSIZ */
81 #ifdef _KERNEL
82 #define	DIRBLKSIZ	512		/* XXX we used to use ufs's DIRBLKSIZ */
83 #endif
84 #define NFS_MAXDEADTHRESH	9	/* How long till we say 'server not responding' */
85 
86 /*
87  * Oddballs
88  */
89 #define NFS_CMPFH(n, f, s) \
90 	((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
91 #define NFS_ISV3(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3)
92 #define NFS_ISV4(v)	(VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV4)
93 
94 #define NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier for V3 */
95 #define NFSSTA_GOTFSINFO	0x00100000  /* Got the V3 fsinfo */
96 #define	NFSSTA_SNDLOCK		0x01000000  /* Send socket lock */
97 #define	NFSSTA_WANTSND		0x02000000  /* Want above */
98 #define	NFSSTA_TIMEO		0x10000000  /* Experiencing a timeout */
99 #define	NFSSTA_LOCKTIMEO	0x20000000  /* Experiencing a lockd timeout */
100 
101 
102 /*
103  * XXX to allow amd to include nfs.h without nfsproto.h
104  */
105 #ifdef NFS_NPROCS
106 #include <nfsclient/nfsstats.h>
107 #endif
108 
109 /*
110  * vfs.oldnfs sysctl(3) identifiers
111  */
112 #define NFS_NFSSTATS	1		/* struct: struct nfsstats */
113 
114 #ifdef _KERNEL
115 
116 #ifdef MALLOC_DECLARE
117 MALLOC_DECLARE(M_NFSREQ);
118 MALLOC_DECLARE(M_NFSDIROFF);
119 MALLOC_DECLARE(M_NFSBIGFH);
120 MALLOC_DECLARE(M_NFSHASH);
121 MALLOC_DECLARE(M_NFSDIRECTIO);
122 #endif
123 
124 extern struct uma_zone *nfsmount_zone;
125 
126 extern struct nfsstats nfsstats;
127 extern struct mtx nfs_iod_mtx;
128 extern struct task nfs_nfsiodnew_task;
129 
130 extern int nfs_numasync;
131 extern unsigned int nfs_iodmax;
132 extern int nfs_pbuf_freecnt;
133 extern int nfs_ticks;
134 
135 /* Data constants in XDR form */
136 extern u_int32_t nfs_true, nfs_false, nfs_xdrneg1;
137 extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers;
138 extern u_int32_t rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr;
139 
140 extern int nfsv3_procid[NFS_NPROCS];
141 
142 /*
143  * Socket errors ignored for connectionless sockets??
144  * For now, ignore them all
145  */
146 #define	NFSIGNORE_SOERROR(s, e) \
147 		((e) != EINTR && (e) != EIO && \
148 		(e) != ERESTART && (e) != EWOULDBLOCK && \
149 		((s) & PR_CONNREQUIRED) == 0)
150 
151 struct nfsmount;
152 
153 struct buf;
154 struct socket;
155 struct uio;
156 struct vattr;
157 
158 /*
159  * Pointers to ops that differ from v3 to v4
160  */
161 struct nfs_rpcops {
162 	int	(*nr_readrpc)(struct vnode *vp, struct uio *uiop,
163 		    struct ucred *cred);
164 	int	(*nr_writerpc)(struct vnode *vp, struct uio *uiop,
165 		    struct ucred *cred, int *iomode, int *must_commit);
166 	int	(*nr_writebp)(struct buf *bp, int force, struct thread *td);
167 	int	(*nr_readlinkrpc)(struct vnode *vp, struct uio *uiop,
168 		    struct ucred *cred);
169 	void	(*nr_invaldir)(struct vnode *vp);
170 	int	(*nr_commit)(struct vnode *vp, u_quad_t offset, int cnt,
171 		    struct ucred *cred, struct thread *td);
172 };
173 
174 /*
175  * Defines for WebNFS
176  */
177 
178 #define WEBNFS_ESC_CHAR		'%'
179 #define WEBNFS_SPECCHAR_START	0x80
180 
181 #define WEBNFS_NATIVE_CHAR	0x80
182 /*
183  * ..
184  * Possibly more here in the future.
185  */
186 
187 /*
188  * Macro for converting escape characters in WebNFS pathnames.
189  * Should really be in libkern.
190  */
191 
192 #define HEXTOC(c) \
193 	((c) >= 'a' ? ((c) - ('a' - 10)) : \
194 	    ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
195 #define HEXSTRTOI(p) \
196 	((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
197 
198 /* nfs_sigintr() helper, when 'rep' has all we need */
199 #define NFS_SIGREP(rep)		nfs_sigintr((rep)->r_nmp, (rep), (rep)->r_td)
200 
201 #ifdef NFS_DEBUG
202 
203 extern int nfs_debug;
204 #define NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
205 #define NFS_DEBUG_WG		2 /* server write gathering */
206 #define NFS_DEBUG_RC		4 /* server request caching */
207 
208 #define NFS_DPF(cat, args)					\
209 	do {							\
210 		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
211 	} while (0)
212 
213 #else
214 
215 #define NFS_DPF(cat, args)
216 
217 #endif
218 
219 /*
220  * On fast networks, the estimator will try to reduce the
221  * timeout lower than the latency of the server's disks,
222  * which results in too many timeouts, so cap the lower
223  * bound.
224  */
225 #define NFS_MINRTO	(NFS_HZ >> 2)
226 
227 /*
228  * Keep the RTO from increasing to unreasonably large values
229  * when a server is not responding.
230  */
231 #define NFS_MAXRTO	(20 * NFS_HZ)
232 
233 enum nfs_rto_timer_t {
234 	NFS_DEFAULT_TIMER,
235 	NFS_GETATTR_TIMER,
236 	NFS_LOOKUP_TIMER,
237 	NFS_READ_TIMER,
238 	NFS_WRITE_TIMER,
239 };
240 #define NFS_MAX_TIMER	(NFS_WRITE_TIMER)
241 
242 #define NFS_INITRTT	(NFS_HZ << 3)
243 
244 vfs_init_t nfs_init;
245 vfs_uninit_t nfs_uninit;
246 int	nfs_mountroot(struct mount *mp);
247 
248 void	nfs_purgecache(struct vnode *);
249 int	nfs_vinvalbuf(struct vnode *, int, struct thread *, int);
250 int	nfs_readrpc(struct vnode *, struct uio *, struct ucred *);
251 int	nfs_writerpc(struct vnode *, struct uio *, struct ucred *, int *,
252 	    int *);
253 int	nfs_commit(struct vnode *vp, u_quad_t offset, int cnt,
254 	    struct ucred *cred, struct thread *td);
255 int	nfs_readdirrpc(struct vnode *, struct uio *, struct ucred *);
256 void	nfs_nfsiodnew(void);
257 void	nfs_nfsiodnew_tq(__unused void *, int);
258 int	nfs_asyncio(struct nfsmount *, struct buf *, struct ucred *, struct thread *);
259 int	nfs_doio(struct vnode *, struct buf *, struct ucred *, struct thread *);
260 void	nfs_doio_directwrite (struct buf *);
261 int	nfs_readlinkrpc(struct vnode *, struct uio *, struct ucred *);
262 int	nfs_sigintr(struct nfsmount *, struct thread *);
263 int	nfs_readdirplusrpc(struct vnode *, struct uio *, struct ucred *);
264 int	nfs_request(struct vnode *, struct mbuf *, int, struct thread *,
265 	    struct ucred *, struct mbuf **, struct mbuf **, caddr_t *);
266 int	nfs_loadattrcache(struct vnode **, struct mbuf **, caddr_t *,
267 	    struct vattr *, int);
268 int	nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *);
269 void	nfs_nhinit(void);
270 void	nfs_nhuninit(void);
271 int	nfs_nmcancelreqs(struct nfsmount *);
272 void	nfs_timer(void*);
273 
274 int	nfs_connect(struct nfsmount *);
275 void	nfs_disconnect(struct nfsmount *);
276 void	nfs_safedisconnect(struct nfsmount *);
277 int	nfs_getattrcache(struct vnode *, struct vattr *);
278 int	nfs_iosize(struct nfsmount *nmp);
279 int	nfsm_strtmbuf(struct mbuf **, char **, const char *, long);
280 int	nfs_bioread(struct vnode *, struct uio *, int, struct ucred *);
281 int	nfsm_uiotombuf(struct uio *, struct mbuf **, int, caddr_t *);
282 void	nfs_clearcommit(struct mount *);
283 int	nfs_writebp(struct buf *, int, struct thread *);
284 int	nfs_fsinfo(struct nfsmount *, struct vnode *, struct ucred *,
285 	    struct thread *);
286 int	nfs_meta_setsize (struct vnode *, struct ucred *,
287 	    struct thread *, u_quad_t);
288 
289 void	nfs_set_sigmask(struct thread *td, sigset_t *oldset);
290 void	nfs_restore_sigmask(struct thread *td, sigset_t *set);
291 int	nfs_msleep(struct thread *td, void *ident, struct mtx *mtx,
292 	    int priority, char *wmesg, int timo);
293 
294 #endif	/* _KERNEL */
295 
296 #endif
297