nfsport.h revision 192121
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 * 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 * $FreeBSD: head/sys/fs/nfs/nfsport.h 192121 2009-05-14 21:39:08Z rmacklem $
33 */
34
35#ifndef _NFS_NFSPORT_H_
36#define	_NFSPORT_NFS_H_
37
38/*
39 * In general, I'm not fond of #includes in .h files, but this seems
40 * to be the cleanest way to handle #include files for the ports.
41 */
42#ifdef _KERNEL
43#include <sys/unistd.h>
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/conf.h>
47#include <sys/dirent.h>
48#include <sys/domain.h>
49#include <sys/fcntl.h>
50#include <sys/file.h>
51#include <sys/filedesc.h>
52#include <sys/kernel.h>
53#include <sys/lockf.h>
54#include <sys/malloc.h>
55#include <sys/mbuf.h>
56#include <sys/mount.h>
57#include <sys/namei.h>
58#include <sys/proc.h>
59#include <sys/protosw.h>
60#include <sys/reboot.h>
61#include <sys/resourcevar.h>
62#include <sys/signalvar.h>
63#include <sys/socket.h>
64#include <sys/socketvar.h>
65#include <sys/stat.h>
66#include <sys/syslog.h>
67#include <sys/sysproto.h>
68#include <sys/time.h>
69#include <sys/uio.h>
70#include <sys/vnode.h>
71#include <sys/bio.h>
72#include <sys/buf.h>
73#include <sys/acl.h>
74#include <sys/module.h>
75#include <sys/sysent.h>
76#include <sys/syscall.h>
77#include <sys/priv.h>
78#include <sys/kthread.h>
79#include <sys/syscallsubr.h>
80#include <fs/fifofs/fifo.h>
81#include <net/if.h>
82#include <net/radix.h>
83#include <net/route.h>
84#include <net/if_dl.h>
85#include <netinet/in.h>
86#include <netinet/in_pcb.h>
87#include <netinet/in_systm.h>
88#include <netinet/in_var.h>
89#include <netinet/ip.h>
90#include <netinet/ip_var.h>
91#include <netinet/tcp.h>
92#include <netinet/tcp_fsm.h>
93#include <netinet/tcp_seq.h>
94#include <netinet/tcp_timer.h>
95#include <netinet/tcp_var.h>
96#include <netinet/vinet.h>
97#include <machine/in_cksum.h>
98#include <crypto/des/des.h>
99#include <sys/md5.h>
100#include <rpc/rpc.h>
101#include <rpc/rpcclnt.h>
102#include <rpc/rpcsec_gss.h>
103
104/*
105 * For Darwin, these functions should be "static" when built in a kext.
106 * (This is always defined as nil otherwise.)
107 */
108#define	APPLESTATIC
109#include <ufs/ufs/dir.h>
110#include <ufs/ufs/quota.h>
111#include <ufs/ufs/inode.h>
112#include <ufs/ufs/extattr.h>
113#include <ufs/ufs/ufsmount.h>
114#include <vm/uma.h>
115#include <vm/vm.h>
116#include <vm/vm_object.h>
117#include <vm/vm_extern.h>
118#include <nfs/nfssvc.h>
119#include "opt_nfs.h"
120#include "opt_ufs.h"
121
122/*
123 * These types must be defined before the nfs includes.
124 */
125#define	NFSSOCKADDR_T	struct sockaddr *
126#define	NFSPROC_T	struct thread
127#define	NFSDEV_T	dev_t
128#define	NFSSVCARGS	nfssvc_args
129#ifdef NFS4_ACL_EXTATTR_NAME
130#define	NFSACL_T	struct acl
131#else
132#define	NFSACL_T	void
133#endif
134
135/*
136 * These should be defined as the types used for the corresponding VOP's
137 * argument type.
138 */
139#define	NFS_ACCESS_ARGS		struct vop_access_args
140#define	NFS_OPEN_ARGS		struct vop_open_args
141#define	NFS_GETATTR_ARGS	struct vop_getattr_args
142#define	NFS_LOOKUP_ARGS		struct vop_lookup_args
143#define	NFS_READDIR_ARGS	struct vop_readdir_args
144
145/*
146 * Allocate mbufs. Must succeed and never set the mbuf ptr to NULL.
147 */
148#define	NFSMGET(m)	do { 					\
149		MGET((m), M_TRYWAIT, MT_DATA); 			\
150		while ((m) == NULL ) { 				\
151			(void) nfs_catnap(PZERO, "nfsmget");	\
152			MGET((m), M_TRYWAIT, MT_DATA); 		\
153		} 						\
154	} while (0)
155#define	NFSMGETHDR(m)	do { 					\
156		MGETHDR((m), M_TRYWAIT, MT_DATA);		\
157		while ((m) == NULL ) { 				\
158			(void) nfs_catnap(PZERO, "nfsmget");	\
159			MGETHDR((m), M_TRYWAIT, MT_DATA); 	\
160		} 						\
161	} while (0)
162#define	NFSMCLGET(m, w)	do { 					\
163		MGET((m), M_TRYWAIT, MT_DATA); 			\
164		while ((m) == NULL ) { 				\
165			(void) nfs_catnap(PZERO, "nfsmget");	\
166			MGET((m), M_TRYWAIT, MT_DATA); 		\
167		} 						\
168		MCLGET((m), (w));				\
169	} while (0)
170#define	NFSMCLGETHDR(m, w) do { 				\
171		MGETHDR((m), M_TRYWAIT, MT_DATA);		\
172		while ((m) == NULL ) { 				\
173			(void) nfs_catnap(PZERO, "nfsmget");	\
174			MGETHDR((m), M_TRYWAIT, MT_DATA); 	\
175		} 						\
176	} while (0)
177#define	NFSMTOD	mtod
178
179/*
180 * Client side constant for size of a lockowner name.
181 */
182#define	NFSV4CL_LOCKNAMELEN	12
183
184/*
185 * Type for a mutex lock.
186 */
187#define	NFSMUTEX_T		struct mtx
188
189#include <fs/nfs/nfskpiport.h>
190#include <fs/nfs/nfsdport.h>
191#include <fs/nfs/rpcv2.h>
192#include <fs/nfs/nfsproto.h>
193#include <fs/nfs/nfs.h>
194#include <fs/nfs/nfs_var.h>
195#include <fs/nfs/nfsm_subs.h>
196#include <fs/nfs/nfsrvcache.h>
197#include <fs/nfs/nfsrvstate.h>
198#include <fs/nfs/xdr_subs.h>
199#include <fs/nfs/nfscl.h>
200#include <fs/nfs/nfsclstate.h>
201#include <fs/nfsclient/nfsargs.h>
202#include <fs/nfsclient/nfsmount.h>
203
204/*
205 * Just to keep nfs_var.h happy.
206 */
207struct nfs_vattr {
208	int	junk;
209};
210
211struct nfsvattr {
212	struct vattr	na_vattr;
213	nfsattrbit_t	na_suppattr;
214	u_int32_t	na_mntonfileno;
215	u_int64_t	na_filesid[2];
216};
217
218#define	na_type		na_vattr.va_type
219#define	na_mode		na_vattr.va_mode
220#define	na_nlink	na_vattr.va_nlink
221#define	na_uid		na_vattr.va_uid
222#define	na_gid		na_vattr.va_gid
223#define	na_fsid		na_vattr.va_fsid
224#define	na_fileid	na_vattr.va_fileid
225#define	na_size		na_vattr.va_size
226#define	na_blocksize	na_vattr.va_blocksize
227#define	na_atime	na_vattr.va_atime
228#define	na_mtime	na_vattr.va_mtime
229#define	na_ctime	na_vattr.va_ctime
230#define	na_gen		na_vattr.va_gen
231#define	na_flags	na_vattr.va_flags
232#define	na_rdev		na_vattr.va_rdev
233#define	na_bytes	na_vattr.va_bytes
234#define	na_filerev	na_vattr.va_filerev
235#define	na_vaflags	na_vattr.va_vaflags
236
237#include <fs/nfsclient/nfsnode.h>
238
239/*
240 * This is the header structure used for the lists, etc. (It has the
241 * above record in it.
242 */
243struct nfsrv_stablefirst {
244	LIST_HEAD(, nfsrv_stable) nsf_head;	/* Head of nfsrv_stable list */
245	time_t		nsf_eograce;	/* Time grace period ends */
246	time_t		*nsf_bootvals;	/* Previous boottime values */
247	struct file	*nsf_fp;	/* File table pointer */
248	u_char		nsf_flags;	/* NFSNSF_ flags */
249	struct nfsf_rec	nsf_rec;	/* and above first record */
250};
251#define	nsf_lease	nsf_rec.lease
252#define	nsf_numboots	nsf_rec.numboots
253
254/* NFSNSF_xxx flags */
255#define	NFSNSF_UPDATEDONE	0x01
256#define	NFSNSF_GRACEOVER	0x02
257#define	NFSNSF_NEEDLOCK		0x04
258#define	NFSNSF_EXPIREDCLIENT	0x08
259#define	NFSNSF_NOOPENS		0x10
260#define	NFSNSF_OK		0x20
261
262/*
263 * Maximum number of boot times allowed in record. Although there is
264 * really no need for a fixed upper bound, this serves as a sanity check
265 * for a corrupted file.
266 */
267#define	NFSNSF_MAXNUMBOOTS	10000
268
269/*
270 * This structure defines the other records in the file. The
271 * nst_client array is actually the size of the client string name.
272 */
273struct nfst_rec {
274	u_int16_t	len;
275	u_char		flag;
276	u_char		client[1];
277};
278/* and the values for flag */
279#define	NFSNST_NEWSTATE	0x1
280#define	NFSNST_REVOKE		0x2
281#define	NFSNST_GOTSTATE		0x4
282
283/*
284 * This structure is linked onto nfsrv_stablefirst for the duration of
285 * reclaim.
286 */
287struct nfsrv_stable {
288	LIST_ENTRY(nfsrv_stable) nst_list;
289	struct nfsclient	*nst_clp;
290	struct nfst_rec		nst_rec;
291};
292#define	nst_timestamp	nst_rec.timestamp
293#define	nst_len		nst_rec.len
294#define	nst_flag	nst_rec.flag
295#define	nst_client	nst_rec.client
296
297/*
298 * At some point the server will run out of kernel storage for
299 * state structures. For FreeBSD5.2, this results in a panic
300 * kmem_map is full. It happens at well over 1000000 opens plus
301 * locks on a PIII-800 with 256Mbytes, so that is where I've set
302 * the limit. If your server panics due to too many opens/locks,
303 * decrease the size of NFSRV_V4STATELIMIT. If you find the server
304 * returning NFS4ERR_RESOURCE a lot and have lots of memory, try
305 * increasing it.
306 */
307#define	NFSRV_V4STATELIMIT	500000	/* Max # of Opens + Locks */
308
309/*
310 * The type required differs with BSDen (just the second arg).
311 */
312void nfsrvd_rcv(struct socket *, void *, int);
313
314/*
315 * Macros for handling socket addresses. (Hopefully this makes the code
316 * more portable, since I've noticed some 'BSD don't have sockaddrs in
317 * mbufs any more.)
318 */
319#define	NFSSOCKADDR(a, t)	((t)(a))
320#define	NFSSOCKADDRALLOC(a) 					\
321    do {							\
322	MALLOC((a), struct sockaddr *, sizeof (struct sockaddr), \
323	    M_SONAME, M_WAITOK); 				\
324	NFSBZERO((a), sizeof (struct sockaddr)); 		\
325    } while (0)
326#define	NFSSOCKADDRSIZE(a, s)		((a)->sa_len = (s))
327#define	NFSSOCKADDRFREE(a) 					\
328	do { 							\
329		if (a) 						\
330			FREE((caddr_t)(a), M_SONAME); 		\
331	} while (0)
332
333/*
334 * These should be defined as a process or thread structure, as required
335 * for signal handling, etc.
336 */
337#define	NFSNEWCRED(c)		(crdup(c))
338#define	NFSPROCCRED(p)		((p)->td_ucred)
339#define	NFSFREECRED(c)		(crfree(c))
340#define	NFSUIOPROC(u, p)	((u)->uio_td = NULL)
341#define	NFSPROCP(p)		((p)->td_proc)
342
343/*
344 * Define these so that cn_hash and its length is ignored.
345 */
346#define	NFSCNHASHZERO(c)
347#define	NFSCNHASH(c, v)
348#define	NCHNAMLEN	9999999
349
350/*
351 * Define these to use the time of day clock.
352 */
353#define	NFSGETTIME(t)		(getmicrotime(t))
354#define	NFSGETNANOTIME(t)	(getnanotime(t))
355
356/*
357 * These macros are defined to initialize and set the timer routine.
358 */
359#define	NFS_TIMERINIT \
360	newnfs_timer(NULL)
361
362/*
363 * Handle SMP stuff:
364 */
365#define	NFSSTATESPINLOCK	extern struct mtx nfs_state_mutex
366#define	NFSLOCKSTATE()		mtx_lock(&nfs_state_mutex)
367#define	NFSUNLOCKSTATE()	mtx_unlock(&nfs_state_mutex)
368#define	NFSREQSPINLOCK		extern struct mtx nfs_req_mutex
369#define	NFSLOCKREQ()		mtx_lock(&nfs_req_mutex)
370#define	NFSUNLOCKREQ()		mtx_unlock(&nfs_req_mutex)
371#define	NFSCACHEMUTEX		extern struct mtx nfs_cache_mutex
372#define	NFSCACHEMUTEXPTR	(&nfs_cache_mutex)
373#define	NFSLOCKCACHE()		mtx_lock(&nfs_cache_mutex)
374#define	NFSUNLOCKCACHE()	mtx_unlock(&nfs_cache_mutex)
375#define	NFSCACHELOCKREQUIRED()	mtx_assert(&nfs_cache_mutex, MA_OWNED)
376#define	NFSSOCKMUTEX		extern struct mtx nfs_slock_mutex
377#define	NFSSOCKMUTEXPTR		(&nfs_slock_mutex)
378#define	NFSLOCKSOCK()		mtx_lock(&nfs_slock_mutex)
379#define	NFSUNLOCKSOCK()		mtx_unlock(&nfs_slock_mutex)
380#define	NFSNAMEIDMUTEX		extern struct mtx nfs_nameid_mutex
381#define	NFSLOCKNAMEID()		mtx_lock(&nfs_nameid_mutex)
382#define	NFSUNLOCKNAMEID()	mtx_unlock(&nfs_nameid_mutex)
383#define	NFSNAMEIDREQUIRED()	mtx_assert(&nfs_nameid_mutex, MA_OWNED)
384#define	NFSCLSTATEMUTEX		extern struct mtx nfs_clstate_mutex
385#define	NFSCLSTATEMUTEXPTR	(&nfs_clstate_mutex)
386#define	NFSLOCKCLSTATE()	mtx_lock(&nfs_clstate_mutex)
387#define	NFSUNLOCKCLSTATE()	mtx_unlock(&nfs_clstate_mutex)
388#define	NFSDLOCKMUTEX		extern struct mtx newnfsd_mtx
389#define	NFSDLOCKMUTEXPTR	(&newnfsd_mtx)
390#define	NFSD_LOCK()		mtx_lock(&newnfsd_mtx)
391#define	NFSD_UNLOCK()		mtx_unlock(&newnfsd_mtx)
392#define	NFSD_LOCK_ASSERT()	mtx_assert(&newnfsd_mtx, MA_OWNED)
393#define	NFSD_UNLOCK_ASSERT()	mtx_assert(&newnfsd_mtx, MA_NOTOWNED)
394#define	NFSV4ROOTLOCKMUTEX	extern struct mtx nfs_v4root_mutex
395#define	NFSV4ROOTLOCKMUTEXPTR	(&nfs_v4root_mutex)
396#define	NFSLOCKV4ROOTMUTEX()	mtx_lock(&nfs_v4root_mutex)
397#define	NFSUNLOCKV4ROOTMUTEX()	mtx_unlock(&nfs_v4root_mutex)
398#define	NFSLOCKNODE(n)		mtx_lock(&((n)->n_mtx))
399#define	NFSUNLOCKNODE(n)	mtx_unlock(&((n)->n_mtx))
400#define	NFSLOCKMNT(m)		mtx_lock(&((m)->nm_mtx))
401#define	NFSUNLOCKMNT(m)		mtx_unlock(&((m)->nm_mtx))
402#define	NFSLOCKREQUEST(r)	mtx_lock(&((r)->r_mtx))
403#define	NFSUNLOCKREQUEST(r)	mtx_unlock(&((r)->r_mtx))
404#define	NFSPROCLISTLOCK()	sx_slock(&allproc_lock)
405#define	NFSPROCLISTUNLOCK()	sx_sunlock(&allproc_lock)
406#define	NFSLOCKSOCKREQ(r)	mtx_lock(&((r)->nr_mtx))
407#define	NFSUNLOCKSOCKREQ(r)	mtx_unlock(&((r)->nr_mtx))
408
409/*
410 * Use these macros to initialize/free a mutex.
411 */
412#define	NFSINITSOCKMUTEX(m)	mtx_init((m), "nfssock", NULL, MTX_DEF)
413#define	NFSFREEMUTEX(m)		mtx_destroy((m))
414
415int nfsmsleep(void *, void *, int, const char *, struct timespec *);
416
417/*
418 * And weird vm stuff in the nfs server.
419 */
420#define	PDIRUNLOCK	0x0
421#define	MAX_COMMIT_COUNT	(1024 * 1024)
422
423/*
424 * These macros are called at the start and end of operations that
425 * might modify the underlying file system.
426 */
427#define	NFS_STARTWRITE(v, m)	vn_start_write((v), (m), V_WAIT)
428#define	NFS_ENDWRITE(m)		vn_finished_write(m)
429
430/*
431 * Define these to handle the type of va_rdev.
432 */
433#define	NFSMAKEDEV(m, n)	makedev((m), (n))
434#define	NFSMAJOR(d)		major(d)
435#define	NFSMINOR(d)		minor(d)
436
437/*
438 * Define this to be the macro that returns the minimum size required
439 * for a directory entry.
440 */
441#define	DIRENT_SIZE(dp)		GENERIC_DIRSIZ(dp)
442
443/*
444 * The vnode tag for nfsv4root.
445 */
446#define	VT_NFSV4ROOT		"nfsv4root"
447
448/*
449 * Define whatever it takes to do a vn_rdwr().
450 */
451#define	NFSD_RDWR(r, v, b, l, o, s, i, c, a, p) \
452	vn_rdwr((r), (v), (b), (l), (o), (s), (i), (c), NULL, (int *)(a), (p))
453
454/*
455 * Macros for handling memory for different BSDen.
456 * NFSBCOPY(src, dst, len) - copies len bytes, non-overlapping
457 * NFSOVBCOPY(src, dst, len) - ditto, but data areas might overlap
458 * NFSBCMP(cp1, cp2, len) - compare len bytes, return 0 if same
459 * NFSBZERO(cp, len) - set len bytes to 0x0
460 */
461#define	NFSBCOPY(s, d, l)	bcopy((s), (d), (l))
462#define	NFSOVBCOPY(s, d, l)	ovbcopy((s), (d), (l))
463#define	NFSBCMP(s, d, l)	bcmp((s), (d), (l))
464#define	NFSBZERO(s, l)		bzero((s), (l))
465
466/*
467 * Some queue.h files don't have these dfined in them.
468 */
469#define	LIST_END(head)		NULL
470#define	SLIST_END(head)		NULL
471#define	TAILQ_END(head)		NULL
472
473/*
474 * This must be defined to be a global variable the increments once
475 * per second, but never stops or goes backwards, even when a "date"
476 * command changes the tod clock. It is used for delta times for
477 * leases, etc.
478 */
479#define	NFSD_MONOSEC		time_uptime
480
481/*
482 * Declare the malloc types.
483 */
484MALLOC_DECLARE(M_NEWNFSRVCACHE);
485MALLOC_DECLARE(M_NEWNFSDCLIENT);
486MALLOC_DECLARE(M_NEWNFSDSTATE);
487MALLOC_DECLARE(M_NEWNFSDLOCK);
488MALLOC_DECLARE(M_NEWNFSDLOCKFILE);
489MALLOC_DECLARE(M_NEWNFSSTRING);
490MALLOC_DECLARE(M_NEWNFSUSERGROUP);
491MALLOC_DECLARE(M_NEWNFSDREQ);
492MALLOC_DECLARE(M_NEWNFSFH);
493MALLOC_DECLARE(M_NEWNFSCLOWNER);
494MALLOC_DECLARE(M_NEWNFSCLOPEN);
495MALLOC_DECLARE(M_NEWNFSCLDELEG);
496MALLOC_DECLARE(M_NEWNFSCLCLIENT);
497MALLOC_DECLARE(M_NEWNFSCLLOCKOWNER);
498MALLOC_DECLARE(M_NEWNFSCLLOCK);
499MALLOC_DECLARE(M_NEWNFSDIROFF);
500MALLOC_DECLARE(M_NEWNFSV4NODE);
501MALLOC_DECLARE(M_NEWNFSDIRECTIO);
502MALLOC_DECLARE(M_NEWNFSMNT);
503#define	M_NFSRVCACHE	M_NEWNFSRVCACHE
504#define	M_NFSDCLIENT	M_NEWNFSDCLIENT
505#define	M_NFSDSTATE	M_NEWNFSDSTATE
506#define	M_NFSDLOCK	M_NEWNFSDLOCK
507#define	M_NFSDLOCKFILE	M_NEWNFSDLOCKFILE
508#define	M_NFSSTRING	M_NEWNFSSTRING
509#define	M_NFSUSERGROUP	M_NEWNFSUSERGROUP
510#define	M_NFSDREQ	M_NEWNFSDREQ
511#define	M_NFSFH		M_NEWNFSFH
512#define	M_NFSCLOWNER	M_NEWNFSCLOWNER
513#define	M_NFSCLOPEN	M_NEWNFSCLOPEN
514#define	M_NFSCLDELEG	M_NEWNFSCLDELEG
515#define	M_NFSCLCLIENT	M_NEWNFSCLCLIENT
516#define	M_NFSCLLOCKOWNER M_NEWNFSCLLOCKOWNER
517#define	M_NFSCLLOCK	M_NEWNFSCLLOCK
518#define	M_NFSDIROFF	M_NEWNFSDIROFF
519#define	M_NFSV4NODE	M_NEWNFSV4NODE
520#define	M_NFSDIRECTIO	M_NEWNFSDIRECTIO
521
522#define	NFSINT_SIGMASK(set) 						\
523	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
524	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
525	 SIGISMEMBER(set, SIGQUIT))
526
527/*
528 * Convert a quota block count to byte count.
529 */
530#define	NFSQUOTABLKTOBYTE(q, b)	(q) *= (b)
531
532/*
533 * Define this as the largest file size supported. (It should probably
534 * be available via a VFS_xxx Op, but it isn't.
535 */
536#define	NFSRV_MAXFILESIZE	((u_int64_t)0x800000000000)
537
538/*
539 * Set this macro to index() or strchr(), whichever is supported.
540 */
541#define	STRCHR(s, c)	index((s), (c))
542
543/*
544 * Set the n_time in the client write rpc, as required.
545 */
546#define	NFSWRITERPC_SETTIME(w, n, v4)					\
547	do {								\
548		if (w) {						\
549			(n)->n_mtime = (n)->n_vattr.na_vattr.va_mtime; \
550			if (v4)						\
551			    (n)->n_change = (n)->n_vattr.na_vattr.va_filerev; \
552		}							\
553	} while (0)
554
555/*
556 * Fake value, just to make the client work.
557 */
558#define	NFS_LATTR_NOSHRINK	1
559
560/*
561 * Prototypes for functions where the arguments vary for different ports.
562 */
563int nfscl_loadattrcache(struct vnode **, struct nfsvattr *, void *, void *,
564    int, int);
565void newnfs_realign(struct mbuf **);
566
567/*
568 * If the port runs on an SMP box that can enforce Atomic ops with low
569 * overheads, define these as atomic increments/decrements. If not,
570 * don't worry about it, since these are used for stats that can be
571 * "out by one" without disastrous consequences.
572 */
573#define	NFSINCRGLOBAL(a)	((a)++)
574
575/*
576 * Assorted funky stuff to make things work under Darwin8.
577 */
578/*
579 * These macros checks for a field in vattr being set.
580 */
581#define	NFSATTRISSET(t, v, a)	((v)->a != (t)VNOVAL)
582#define	NFSATTRISSETTIME(v, a)	((v)->a.tv_sec != VNOVAL)
583
584/*
585 * Manipulate mount flags.
586 */
587#define	NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier */
588#define	NFSSTA_GOTFSINFO	0x00100000  /* Got the fsinfo */
589#define	NFSSTA_TIMEO		0x10000000  /* Experiencing a timeout */
590#define	NFSSTA_LOCKTIMEO	0x20000000  /* Experiencing a lockd timeout */
591#define	NFSSTA_HASSETFSID	0x40000000  /* Has set the fsid */
592
593#define	NFSHASNFSV3(n)		((n)->nm_flag & NFSMNT_NFSV3)
594#define	NFSHASNFSV4(n)		((n)->nm_flag & NFSMNT_NFSV4)
595#define	NFSHASNFSV3OR4(n)	((n)->nm_flag & (NFSMNT_NFSV3 | NFSMNT_NFSV4))
596#define	NFSHASGOTFSINFO(n)	((n)->nm_state & NFSSTA_GOTFSINFO)
597#define	NFSHASHASSETFSID(n)	((n)->nm_state & NFSSTA_HASSETFSID)
598#define	NFSHASSTRICT3530(n)	((n)->nm_flag & NFSMNT_STRICT3530)
599#define	NFSHASWRITEVERF(n)	((n)->nm_state & NFSSTA_HASWRITEVERF)
600#define	NFSHASINT(n)		((n)->nm_flag & NFSMNT_INT)
601#define	NFSHASSOFT(n)		((n)->nm_flag & NFSMNT_SOFT)
602#define	NFSHASINTORSOFT(n)	((n)->nm_flag & (NFSMNT_INT | NFSMNT_SOFT))
603#define	NFSHASDUMBTIMR(n)	((n)->nm_flag & NFSMNT_DUMBTIMR)
604#define	NFSHASNOCONN(n)		((n)->nm_flag & NFSMNT_MNTD)
605#define	NFSHASKERB(n)		((n)->nm_flag & NFSMNT_KERB)
606#define	NFSHASALLGSSNAME(n)	((n)->nm_flag & NFSMNT_ALLGSSNAME)
607#define	NFSHASINTEGRITY(n)	((n)->nm_flag & NFSMNT_INTEGRITY)
608#define	NFSHASPRIVACY(n)	((n)->nm_flag & NFSMNT_PRIVACY)
609#define	NFSSETWRITEVERF(n)	((n)->nm_state |= NFSSTA_HASWRITEVERF)
610#define	NFSSETHASSETFSID(n)	((n)->nm_state |= NFSSTA_HASSETFSID)
611#ifdef NFS4_ACL_EXTATTR_NAME
612#define	NFSHASNFS4ACL(m)	((m)->mnt_flag & MNT_NFS4ACLS)
613#else
614#define	NFSHASNFS4ACL(m)	0
615#endif
616
617/*
618 * Gets the stats field out of the mount structure.
619 */
620#define	vfs_statfs(m)	(&((m)->mnt_stat))
621
622/*
623 * Set boottime.
624 */
625#define	NFSSETBOOTTIME(b)	((b) = boottime)
626
627/*
628 * The size of directory blocks in the buffer cache.
629 * MUST BE in the range of PAGE_SIZE <= NFS_DIRBLKSIZ <= MAXBSIZE!!
630 */
631#define	NFS_DIRBLKSIZ	(16 * DIRBLKSIZ) /* Must be a multiple of DIRBLKSIZ */
632
633/*
634 * Define these macros to access mnt_flag fields.
635 */
636#define	NFSMNT_RDONLY(m)	((m)->mnt_flag & MNT_RDONLY)
637#endif	/* _KERNEL */
638
639/*
640 * Define a structure similar to ufs_args for use in exporting the V4 root.
641 */
642struct nfsex_args {
643	char	*fspec;
644	struct export_args	export;
645};
646
647/*
648 * These export flags should be defined, but there are no bits left.
649 * Maybe a separate mnt_exflag field could be added or the mnt_flag
650 * field increased to 64 bits?
651 */
652#ifndef	MNT_EXSTRICTACCESS
653#define	MNT_EXSTRICTACCESS	0x0
654#endif
655#ifndef MNT_EXV4ONLY
656#define	MNT_EXV4ONLY		0x0
657#endif
658
659#ifdef _KERNEL
660/*
661 * Define this to invalidate the attribute cache for the nfs node.
662 */
663#define	NFSINVALATTRCACHE(n)	((n)->n_attrstamp = 0)
664
665/* Used for FreeBSD only */
666void nfsd_mntinit(void);
667
668/*
669 * Define these for vnode lock/unlock ops.
670 */
671#define	NFSVOPLOCK(v, f, p)	vn_lock((v), (f))
672#define	NFSVOPUNLOCK(v, f, p)	VOP_UNLOCK((v), (f))
673#define	NFSVOPISLOCKED(v, p)	VOP_ISLOCKED((v))
674
675/*
676 * Define ncl_hash().
677 */
678#define	ncl_hash(f, l)	(fnv_32_buf((f), (l), FNV1_32_INIT))
679
680int newnfs_iosize(struct nfsmount *);
681
682#ifdef NFS_DEBUG
683
684extern int nfs_debug;
685#define	NFS_DEBUG_ASYNCIO	1 /* asynchronous i/o */
686#define	NFS_DEBUG_WG		2 /* server write gathering */
687#define	NFS_DEBUG_RC		4 /* server request caching */
688
689#define	NFS_DPF(cat, args)					\
690	do {							\
691		if (nfs_debug & NFS_DEBUG_##cat) printf args;	\
692	} while (0)
693
694#else
695
696#define	NFS_DPF(cat, args)
697
698#endif
699
700int newnfs_vncmpf(struct vnode *, void *);
701
702#ifndef NFS_MINDIRATTRTIMO
703#define	NFS_MINDIRATTRTIMO 3		/* VDIR attrib cache timeout in sec */
704#endif
705#ifndef NFS_MAXDIRATTRTIMO
706#define	NFS_MAXDIRATTRTIMO 60
707#endif
708
709/*
710 * Nfs outstanding request list element
711 */
712struct nfsreq {
713	TAILQ_ENTRY(nfsreq) r_chain;
714	u_int32_t	r_flags;	/* flags on request, see below */
715	struct nfsmount *r_nmp;		/* Client mnt ptr */
716	struct mtx	r_mtx;		/* Mutex lock for this structure */
717};
718
719#ifndef NFS_MAXBSIZE
720#define	NFS_MAXBSIZE	MAXBSIZE
721#endif
722
723/*
724 * This macro checks to see if issuing of delegations is allowed for this
725 * vnode.
726 */
727#ifdef VV_DISABLEDELEG
728#define	NFSVNO_DELEGOK(v)						\
729	((v) == NULL || ((v)->v_vflag & VV_DISABLEDELEG) == 0)
730#else
731#define	NFSVNO_DELEGOK(v)	(1)
732#endif
733
734#endif	/* _KERNEL */
735
736#endif	/* _NFSPORT_NFS_H */
737