xref: /freebsd/sys/nfsclient/nfs.h (revision a220d00e74dd245b4fca59c5eca0c53963686325)
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  * 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.4 (Berkeley) 5/1/95
37  * $FreeBSD$
38  */
39 
40 #ifndef _NFSCLIENT_NFS_H_
41 #define _NFSCLIENT_NFS_H_
42 
43 #ifdef _KERNEL
44 #include "opt_nfs.h"
45 #endif
46 
47 #include <nfsclient/nfsargs.h>
48 
49 /*
50  * Tunable constants for nfs
51  */
52 
53 #define NFS_TICKINTVL	5		/* Desired time for a tick (msec) */
54 #define NFS_HZ		(hz / nfs_ticks) /* Ticks/sec */
55 #define	NFS_TIMEO	(1 * NFS_HZ)	/* Default timeout = 1 second */
56 #define	NFS_MINTIMEO	(1 * NFS_HZ)	/* Min timeout to use */
57 #define	NFS_MAXTIMEO	(60 * NFS_HZ)	/* Max timeout to backoff to */
58 #define	NFS_MINIDEMTIMEO (5 * NFS_HZ)	/* Min timeout for non-idempotent ops*/
59 #define	NFS_MAXREXMIT	100		/* Stop counting after this many */
60 #define	NFS_RETRANS	10		/* Num of retrans for soft mounts */
61 #define	NFS_MAXGRPS	16		/* Max. size of groups list */
62 #ifndef NFS_MINATTRTIMO
63 #define	NFS_MINATTRTIMO 3		/* VREG attrib cache timeout in sec */
64 #endif
65 #ifndef NFS_MAXATTRTIMO
66 #define	NFS_MAXATTRTIMO 60
67 #endif
68 #ifndef NFS_MINDIRATTRTIMO
69 #define	NFS_MINDIRATTRTIMO 30		/* VDIR attrib cache timeout in sec */
70 #endif
71 #ifndef NFS_MAXDIRATTRTIMO
72 #define	NFS_MAXDIRATTRTIMO 60
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 	20	/* 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 
93 #define NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier for V3 */
94 #define NFSSTA_GOTFSINFO	0x00100000  /* Got the V3 fsinfo */
95 #define	NFSSTA_SNDLOCK		0x01000000  /* Send socket lock */
96 #define	NFSSTA_WANTSND		0x02000000  /* Want above */
97 #define	NFSSTA_RCVLOCK		0x04000000  /* Rcv socket lock */
98 #define	NFSSTA_WANTRCV		0x08000000  /* Want above */
99 
100 /*
101  * XXX to allow amd to include nfs.h without nfsproto.h
102  */
103 #ifdef NFS_NPROCS
104 #include <nfsclient/nfsstats.h>
105 #endif
106 /*
107  * Flags for nfsclnt() system call.
108  */
109 #define	NFSCLNT_LOCKDANS 0x200
110 
111 /*
112  * vfs.nfs sysctl(3) identifiers
113  */
114 #define NFS_NFSSTATS	1		/* struct: struct nfsstats */
115 
116 #ifdef _KERNEL
117 
118 #ifdef MALLOC_DECLARE
119 MALLOC_DECLARE(M_NFSREQ);
120 MALLOC_DECLARE(M_NFSDIROFF);
121 MALLOC_DECLARE(M_NFSBIGFH);
122 MALLOC_DECLARE(M_NFSHASH);
123 #endif
124 
125 #ifdef ZONE_INTERRUPT
126 extern vm_zone_t nfsmount_zone;
127 #endif
128 
129 extern struct callout_handle nfs_timer_handle;
130 extern struct nfsstats nfsstats;
131 
132 extern int nfs_numasync;
133 extern int nfs_pbuf_freecnt;
134 extern int nfs_ticks;
135 
136 /* Data constants in XDR form */
137 extern u_int32_t nfs_true, nfs_false, nfs_xdrneg1;
138 extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers;
139 extern u_int32_t rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr;
140 
141 extern int nfsv3_procid[NFS_NPROCS];
142 
143 struct uio;
144 struct buf;
145 struct vattr;
146 struct nameidata;
147 
148 /*
149  * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
150  * What should be in this set is open to debate, but I believe that since
151  * I/O system calls on ufs are never interrupted by signals the set should
152  * be minimal. My reasoning is that many current programs that use signals
153  * such as SIGALRM will not expect file I/O system calls to be interrupted
154  * by them and break.
155  */
156 #define	NFSINT_SIGMASK(set) 						\
157 	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
158 	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
159 	 SIGISMEMBER(set, SIGQUIT))
160 
161 /*
162  * Socket errors ignored for connectionless sockets??
163  * For now, ignore them all
164  */
165 #define	NFSIGNORE_SOERROR(s, e) \
166 		((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
167 		((s) & PR_CONNREQUIRED) == 0)
168 
169 /*
170  * Nfs outstanding request list element
171  */
172 struct nfsreq {
173 	TAILQ_ENTRY(nfsreq) r_chain;
174 	struct mbuf	*r_mreq;
175 	struct mbuf	*r_mrep;
176 	struct mbuf	*r_md;
177 	caddr_t		r_dpos;
178 	struct nfsmount *r_nmp;
179 	struct vnode	*r_vp;
180 	u_int32_t	r_xid;
181 	int		r_flags;	/* flags on request, see below */
182 	int		r_retry;	/* max retransmission count */
183 	int		r_rexmit;	/* current retrans count */
184 	int		r_timer;	/* tick counter on reply */
185 	u_int32_t	r_procnum;	/* NFS procedure number */
186 	int		r_rtt;		/* RTT for rpc */
187 	struct thread	*r_td;		/* Proc that did I/O system call */
188 };
189 
190 /*
191  * Queue head for nfsreq's
192  */
193 extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq;
194 
195 /* Flag values for r_flags */
196 #define R_TIMING	0x01		/* timing request (in mntp) */
197 #define R_SENT		0x02		/* request has been sent */
198 #define	R_SOFTTERM	0x04		/* soft mnt, too many retries */
199 #define	R_INTR		0x08		/* intr mnt, signal pending */
200 #define	R_SOCKERR	0x10		/* Fatal error on socket */
201 #define	R_TPRINTFMSG	0x20		/* Did a tprintf msg. */
202 #define	R_MUSTRESEND	0x40		/* Must resend request */
203 #define	R_GETONEREP	0x80		/* Probe for one reply only */
204 
205 extern struct nfsnodehashhead *nfsnodehashtbl;
206 extern u_long	nfsnodehash;
207 
208 #define	NFSNOHASH(fhsum) \
209 	(&nfsnodehashtbl[(fhsum) & nfsnodehash])
210 
211 /*
212  * Defines for WebNFS
213  */
214 
215 #define WEBNFS_ESC_CHAR		'%'
216 #define WEBNFS_SPECCHAR_START	0x80
217 
218 #define WEBNFS_NATIVE_CHAR	0x80
219 /*
220  * ..
221  * Possibly more here in the future.
222  */
223 
224 /*
225  * Macro for converting escape characters in WebNFS pathnames.
226  * Should really be in libkern.
227  */
228 
229 #define HEXTOC(c) \
230 	((c) >= 'a' ? ((c) - ('a' - 10)) : \
231 	    ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
232 #define HEXSTRTOI(p) \
233 	((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
234 
235 #ifdef NFS_DEBUG
236 
237 extern int nfs_debug;
238 #define NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
239 #define NFS_DEBUG_WG		2 /* server write gathering */
240 #define NFS_DEBUG_RC		4 /* server request caching */
241 
242 #define NFS_DPF(cat, args)					\
243 	do {							\
244 		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
245 	} while (0)
246 
247 #else
248 
249 #define NFS_DPF(cat, args)
250 
251 #endif
252 
253 int	nfs_init(struct vfsconf *vfsp);
254 int	nfs_uninit(struct vfsconf *vfsp);
255 int	nfs_mountroot(struct mount *mp);
256 int	nfs_send(struct socket *, struct sockaddr *, struct mbuf *,
257 	    struct nfsreq *);
258 int	nfs_sndlock(struct nfsreq *);
259 void	nfs_sndunlock(struct nfsreq *);
260 int	nfs_vinvalbuf(struct vnode *, int, struct ucred *, struct thread *,
261 	    int);
262 int	nfs_readrpc(struct vnode *, struct uio *, struct ucred *);
263 int	nfs_writerpc(struct vnode *, struct uio *, struct ucred *, int *,
264 	    int *);
265 int	nfs_commit(struct vnode *vp, u_quad_t offset, int cnt,
266 	    struct ucred *cred, struct thread *td);
267 int	nfs_readdirrpc(struct vnode *, struct uio *, struct ucred *);
268 int	nfs_asyncio(struct buf *, struct ucred *, struct thread *);
269 int	nfs_doio(struct buf *, struct ucred *, struct thread *);
270 int	nfs_readlinkrpc(struct vnode *, struct uio *, struct ucred *);
271 int	nfs_sigintr(struct nfsmount *, struct nfsreq *, struct proc *);
272 int	nfs_readdirplusrpc(struct vnode *, struct uio *, struct ucred *);
273 int	nfs_request(struct vnode *, struct mbuf *, int, struct thread *,
274 	    struct ucred *, struct mbuf **, struct mbuf **, caddr_t *);
275 int	nfs_loadattrcache(struct vnode **, struct mbuf **, caddr_t *,
276 	    struct vattr *, int);
277 int	nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *);
278 void	nfs_nhinit(void);
279 void	nfs_timer(void*);
280 int	nfs_connect(struct nfsmount *, struct nfsreq *);
281 void	nfs_disconnect(struct nfsmount *);
282 void	nfs_safedisconnect(struct nfsmount *);
283 int	nfs_getattrcache(struct vnode *, struct vattr *);
284 int	nfsm_strtmbuf(struct mbuf **, char **, const char *, long);
285 int	nfs_bioread(struct vnode *, struct uio *, int, struct ucred *);
286 int	nfsm_uiotombuf(struct uio *, struct mbuf **, int, caddr_t *);
287 void	nfs_clearcommit(struct mount *);
288 int	nfs_writebp(struct buf *, int, struct thread *);
289 int	nfs_fsinfo(struct nfsmount *, struct vnode *, struct ucred *,
290 	    struct thread *);
291 
292 #endif	/* _KERNEL */
293 
294 #endif
295