xref: /freebsd/sys/fs/nfs/nfsport.h (revision d6eb98610fa65663bf0df4574b7cb2c5c4ffda71)
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1989, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Rick Macklem at The University of Guelph.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. Neither the name of the University nor the names of its contributors
19  *    may be used to endorse or promote products derived from this software
20  *    without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  *
34  * $FreeBSD$
35  */
36 
37 #ifndef _NFS_NFSPORT_H_
38 #define	_NFS_NFSPORT_H_
39 
40 /*
41  * In general, I'm not fond of #includes in .h files, but this seems
42  * to be the cleanest way to handle #include files for the ports.
43  */
44 #ifdef _KERNEL
45 #include <sys/unistd.h>
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/conf.h>
49 #include <sys/dirent.h>
50 #include <sys/domain.h>
51 #include <sys/fcntl.h>
52 #include <sys/file.h>
53 #include <sys/filedesc.h>
54 #include <sys/jail.h>
55 #include <sys/kernel.h>
56 #include <sys/lockf.h>
57 #include <sys/malloc.h>
58 #include <sys/mbuf.h>
59 #include <sys/mount.h>
60 #include <sys/mutex.h>
61 #include <sys/namei.h>
62 #include <sys/proc.h>
63 #include <sys/protosw.h>
64 #include <sys/reboot.h>
65 #include <sys/resourcevar.h>
66 #include <sys/signalvar.h>
67 #include <sys/socket.h>
68 #include <sys/socketvar.h>
69 #include <sys/stat.h>
70 #include <sys/syslog.h>
71 #include <sys/sysproto.h>
72 #include <sys/time.h>
73 #include <sys/uio.h>
74 #include <sys/vnode.h>
75 #include <sys/bio.h>
76 #include <sys/buf.h>
77 #include <sys/acl.h>
78 #include <sys/module.h>
79 #include <sys/sysent.h>
80 #include <sys/syscall.h>
81 #include <sys/priv.h>
82 #include <sys/kthread.h>
83 #include <sys/syscallsubr.h>
84 #include <net/if.h>
85 #include <net/if_var.h>
86 #include <net/radix.h>
87 #include <net/route.h>
88 #include <net/if_dl.h>
89 #include <netinet/in.h>
90 #include <netinet/in_pcb.h>
91 #include <netinet/in_systm.h>
92 #include <netinet/in_var.h>
93 #include <netinet/ip.h>
94 #include <netinet/ip_var.h>
95 #include <netinet/tcp.h>
96 #include <netinet/tcp_fsm.h>
97 #include <netinet/tcp_seq.h>
98 #include <netinet/tcp_timer.h>
99 #include <netinet/tcp_var.h>
100 #include <machine/in_cksum.h>
101 #include <crypto/des/des.h>
102 #include <sys/md5.h>
103 #include <rpc/rpc.h>
104 #include <rpc/rpcsec_gss.h>
105 
106 /*
107  * For Darwin, these functions should be "static" when built in a kext.
108  * (This is always defined as nil otherwise.)
109  */
110 #define	APPLESTATIC
111 #include <ufs/ufs/dir.h>
112 #include <ufs/ufs/quota.h>
113 #include <ufs/ufs/inode.h>
114 #include <ufs/ufs/extattr.h>
115 #include <ufs/ufs/ufsmount.h>
116 #include <vm/uma.h>
117 #include <vm/vm.h>
118 #include <vm/vm_object.h>
119 #include <vm/vm_extern.h>
120 #include <nfs/nfssvc.h>
121 #include "opt_nfs.h"
122 #include "opt_ufs.h"
123 
124 /*
125  * These types must be defined before the nfs includes.
126  */
127 #define	NFSSOCKADDR_T	struct sockaddr *
128 #define	NFSPROC_T	struct thread
129 #define	NFSDEV_T	dev_t
130 #define	NFSSVCARGS	nfssvc_args
131 #define	NFSACL_T	struct acl
132 
133 /*
134  * These should be defined as the types used for the corresponding VOP's
135  * argument type.
136  */
137 #define	NFS_ACCESS_ARGS		struct vop_access_args
138 #define	NFS_OPEN_ARGS		struct vop_open_args
139 #define	NFS_GETATTR_ARGS	struct vop_getattr_args
140 #define	NFS_LOOKUP_ARGS		struct vop_lookup_args
141 #define	NFS_READDIR_ARGS	struct vop_readdir_args
142 
143 /*
144  * Allocate mbufs. Must succeed and never set the mbuf ptr to NULL.
145  */
146 #define	NFSMGET(m)	do { 					\
147 		MGET((m), M_WAITOK, MT_DATA); 			\
148 		while ((m) == NULL ) { 				\
149 			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
150 			MGET((m), M_WAITOK, MT_DATA); 		\
151 		} 						\
152 	} while (0)
153 #define	NFSMGETHDR(m)	do { 					\
154 		MGETHDR((m), M_WAITOK, MT_DATA);		\
155 		while ((m) == NULL ) { 				\
156 			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
157 			MGETHDR((m), M_WAITOK, MT_DATA); 	\
158 		} 						\
159 	} while (0)
160 #define	NFSMCLGET(m, w)	do { 					\
161 		MGET((m), M_WAITOK, MT_DATA); 			\
162 		while ((m) == NULL ) { 				\
163 			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
164 			MGET((m), M_WAITOK, MT_DATA); 		\
165 		} 						\
166 		MCLGET((m), (w));				\
167 	} while (0)
168 #define	NFSMCLGETHDR(m, w) do { 				\
169 		MGETHDR((m), M_WAITOK, MT_DATA);		\
170 		while ((m) == NULL ) { 				\
171 			(void) nfs_catnap(PZERO, 0, "nfsmget");	\
172 			MGETHDR((m), M_WAITOK, MT_DATA); 	\
173 		} 						\
174 	} while (0)
175 #define	NFSMTOD	mtod
176 
177 /*
178  * Client side constant for size of a lockowner name.
179  */
180 #define	NFSV4CL_LOCKNAMELEN	12
181 
182 /*
183  * Type for a mutex lock.
184  */
185 #define	NFSMUTEX_T		struct mtx
186 
187 #endif	/* _KERNEL */
188 
189 /*
190  * NFSv4 Operation numbers.
191  */
192 #define	NFSV4OP_ACCESS		3
193 #define	NFSV4OP_CLOSE		4
194 #define	NFSV4OP_COMMIT		5
195 #define	NFSV4OP_CREATE		6
196 #define	NFSV4OP_DELEGPURGE	7
197 #define	NFSV4OP_DELEGRETURN	8
198 #define	NFSV4OP_GETATTR		9
199 #define	NFSV4OP_GETFH		10
200 #define	NFSV4OP_LINK		11
201 #define	NFSV4OP_LOCK		12
202 #define	NFSV4OP_LOCKT		13
203 #define	NFSV4OP_LOCKU		14
204 #define	NFSV4OP_LOOKUP		15
205 #define	NFSV4OP_LOOKUPP		16
206 #define	NFSV4OP_NVERIFY		17
207 #define	NFSV4OP_OPEN		18
208 #define	NFSV4OP_OPENATTR	19
209 #define	NFSV4OP_OPENCONFIRM	20
210 #define	NFSV4OP_OPENDOWNGRADE	21
211 #define	NFSV4OP_PUTFH		22
212 #define	NFSV4OP_PUTPUBFH	23
213 #define	NFSV4OP_PUTROOTFH	24
214 #define	NFSV4OP_READ		25
215 #define	NFSV4OP_READDIR		26
216 #define	NFSV4OP_READLINK	27
217 #define	NFSV4OP_REMOVE		28
218 #define	NFSV4OP_RENAME		29
219 #define	NFSV4OP_RENEW		30
220 #define	NFSV4OP_RESTOREFH	31
221 #define	NFSV4OP_SAVEFH		32
222 #define	NFSV4OP_SECINFO		33
223 #define	NFSV4OP_SETATTR		34
224 #define	NFSV4OP_SETCLIENTID	35
225 #define	NFSV4OP_SETCLIENTIDCFRM	36
226 #define	NFSV4OP_VERIFY		37
227 #define	NFSV4OP_WRITE		38
228 #define	NFSV4OP_RELEASELCKOWN	39
229 
230 /*
231  * Must be one greater than the last Operation#.
232  */
233 #define	NFSV4OP_NOPS		40
234 
235 /*
236  * Additional Ops for NFSv4.1.
237  */
238 #define	NFSV4OP_BACKCHANNELCTL	40
239 #define	NFSV4OP_BINDCONNTOSESS	41
240 #define	NFSV4OP_EXCHANGEID	42
241 #define	NFSV4OP_CREATESESSION	43
242 #define	NFSV4OP_DESTROYSESSION	44
243 #define	NFSV4OP_FREESTATEID	45
244 #define	NFSV4OP_GETDIRDELEG	46
245 #define	NFSV4OP_GETDEVINFO	47
246 #define	NFSV4OP_GETDEVLIST	48
247 #define	NFSV4OP_LAYOUTCOMMIT	49
248 #define	NFSV4OP_LAYOUTGET	50
249 #define	NFSV4OP_LAYOUTRETURN	51
250 #define	NFSV4OP_SECINFONONAME	52
251 #define	NFSV4OP_SEQUENCE	53
252 #define	NFSV4OP_SETSSV		54
253 #define	NFSV4OP_TESTSTATEID	55
254 #define	NFSV4OP_WANTDELEG	56
255 #define	NFSV4OP_DESTROYCLIENTID	57
256 #define	NFSV4OP_RECLAIMCOMPL	58
257 
258 /*
259  * Must be one more than last op#.
260  * NFSv4.2 isn't implemented yet, but define the op# limit for it.
261  */
262 #define	NFSV41_NOPS		59
263 #define	NFSV42_NOPS		72
264 
265 /* Quirky case if the illegal op code */
266 #define	NFSV4OP_OPILLEGAL	10044
267 
268 /*
269  * Fake NFSV4OP_xxx used for nfsstat. Start at NFSV42_NOPS.
270  */
271 #define	NFSV4OP_SYMLINK		(NFSV42_NOPS)
272 #define	NFSV4OP_MKDIR		(NFSV42_NOPS + 1)
273 #define	NFSV4OP_RMDIR		(NFSV42_NOPS + 2)
274 #define	NFSV4OP_READDIRPLUS	(NFSV42_NOPS + 3)
275 #define	NFSV4OP_MKNOD		(NFSV42_NOPS + 4)
276 #define	NFSV4OP_FSSTAT		(NFSV42_NOPS + 5)
277 #define	NFSV4OP_FSINFO		(NFSV42_NOPS + 6)
278 #define	NFSV4OP_PATHCONF	(NFSV42_NOPS + 7)
279 #define	NFSV4OP_V3CREATE	(NFSV42_NOPS + 8)
280 
281 /*
282  * This is the count of the fake operations listed above.
283  */
284 #define	NFSV4OP_FAKENOPS	9
285 
286 /*
287  * and the Callback OPs
288  */
289 #define	NFSV4OP_CBGETATTR	3
290 #define	NFSV4OP_CBRECALL	4
291 
292 /*
293  * Must be one greater than the last Callback Operation# for NFSv4.0.
294  */
295 #define	NFSV4OP_CBNOPS		5
296 
297 /*
298  * Additional Callback Ops for NFSv4.1 only.
299  */
300 #define	NFSV4OP_CBLAYOUTRECALL	5
301 #define	NFSV4OP_CBNOTIFY	6
302 #define	NFSV4OP_CBPUSHDELEG	7
303 #define	NFSV4OP_CBRECALLANY	8
304 #define	NFSV4OP_CBRECALLOBJAVAIL 9
305 #define	NFSV4OP_CBRECALLSLOT	10
306 #define	NFSV4OP_CBSEQUENCE	11
307 #define	NFSV4OP_CBWANTCANCELLED	12
308 #define	NFSV4OP_CBNOTIFYLOCK	13
309 #define	NFSV4OP_CBNOTIFYDEVID	14
310 
311 #define	NFSV41_CBNOPS		15
312 #define	NFSV42_CBNOPS		16
313 
314 /*
315  * The lower numbers -> 21 are used by NFSv2 and v3. These define higher
316  * numbers used by NFSv4.
317  * NFS_V3NPROCS is one greater than the last V3 op and NFS_NPROCS is
318  * one greater than the last number.
319  */
320 #ifndef	NFS_V3NPROCS
321 #define	NFS_V3NPROCS		22
322 
323 #define	NFSPROC_LOOKUPP		22
324 #define	NFSPROC_SETCLIENTID	23
325 #define	NFSPROC_SETCLIENTIDCFRM	24
326 #define	NFSPROC_LOCK		25
327 #define	NFSPROC_LOCKU		26
328 #define	NFSPROC_OPEN		27
329 #define	NFSPROC_CLOSE		28
330 #define	NFSPROC_OPENCONFIRM	29
331 #define	NFSPROC_LOCKT		30
332 #define	NFSPROC_OPENDOWNGRADE	31
333 #define	NFSPROC_RENEW		32
334 #define	NFSPROC_PUTROOTFH	33
335 #define	NFSPROC_RELEASELCKOWN	34
336 #define	NFSPROC_DELEGRETURN	35
337 #define	NFSPROC_RETDELEGREMOVE	36
338 #define	NFSPROC_RETDELEGRENAME1	37
339 #define	NFSPROC_RETDELEGRENAME2	38
340 #define	NFSPROC_GETACL		39
341 #define	NFSPROC_SETACL		40
342 
343 /*
344  * Must be defined as one higher than the last Proc# above.
345  */
346 #define	NFSV4_NPROCS		41
347 
348 /* Additional procedures for NFSv4.1. */
349 #define	NFSPROC_EXCHANGEID	41
350 #define	NFSPROC_CREATESESSION	42
351 #define	NFSPROC_DESTROYSESSION	43
352 #define	NFSPROC_DESTROYCLIENT	44
353 #define	NFSPROC_FREESTATEID	45
354 #define	NFSPROC_LAYOUTGET	46
355 #define	NFSPROC_GETDEVICEINFO	47
356 #define	NFSPROC_LAYOUTCOMMIT	48
357 #define	NFSPROC_LAYOUTRETURN	49
358 #define	NFSPROC_RECLAIMCOMPL	50
359 #define	NFSPROC_WRITEDS		51
360 #define	NFSPROC_READDS		52
361 #define	NFSPROC_COMMITDS	53
362 #define	NFSPROC_OPENLAYGET	54
363 #define	NFSPROC_CREATELAYGET	55
364 
365 /*
366  * Must be defined as one higher than the last NFSv4.1 Proc# above.
367  */
368 #define	NFSV41_NPROCS		56
369 
370 #endif	/* NFS_V3NPROCS */
371 
372 /*
373  * New stats structure.
374  * The vers field will be set to NFSSTATS_V1 by the caller.
375  */
376 #define	NFSSTATS_V1	1
377 struct nfsstatsv1 {
378 	int		vers;	/* Set to version requested by caller. */
379 	uint64_t	attrcache_hits;
380 	uint64_t	attrcache_misses;
381 	uint64_t	lookupcache_hits;
382 	uint64_t	lookupcache_misses;
383 	uint64_t	direofcache_hits;
384 	uint64_t	direofcache_misses;
385 	uint64_t	accesscache_hits;
386 	uint64_t	accesscache_misses;
387 	uint64_t	biocache_reads;
388 	uint64_t	read_bios;
389 	uint64_t	read_physios;
390 	uint64_t	biocache_writes;
391 	uint64_t	write_bios;
392 	uint64_t	write_physios;
393 	uint64_t	biocache_readlinks;
394 	uint64_t	readlink_bios;
395 	uint64_t	biocache_readdirs;
396 	uint64_t	readdir_bios;
397 	uint64_t	rpccnt[NFSV41_NPROCS + 13];
398 	uint64_t	rpcretries;
399 	uint64_t	srvrpccnt[NFSV42_NOPS + NFSV4OP_FAKENOPS];
400 	uint64_t	srvrpc_errs;
401 	uint64_t	srv_errs;
402 	uint64_t	rpcrequests;
403 	uint64_t	rpctimeouts;
404 	uint64_t	rpcunexpected;
405 	uint64_t	rpcinvalid;
406 	uint64_t	srvcache_inproghits;
407 	uint64_t	srvcache_idemdonehits;
408 	uint64_t	srvcache_nonidemdonehits;
409 	uint64_t	srvcache_misses;
410 	uint64_t	srvcache_tcppeak;
411 	int		srvcache_size;	/* Updated by atomic_xx_int(). */
412 	uint64_t	srvclients;
413 	uint64_t	srvopenowners;
414 	uint64_t	srvopens;
415 	uint64_t	srvlockowners;
416 	uint64_t	srvlocks;
417 	uint64_t	srvdelegates;
418 	uint64_t	cbrpccnt[NFSV42_CBNOPS];
419 	uint64_t	clopenowners;
420 	uint64_t	clopens;
421 	uint64_t	cllockowners;
422 	uint64_t	cllocks;
423 	uint64_t	cldelegates;
424 	uint64_t	cllocalopenowners;
425 	uint64_t	cllocalopens;
426 	uint64_t	cllocallockowners;
427 	uint64_t	cllocallocks;
428 	uint64_t	srvstartcnt;
429 	uint64_t	srvdonecnt;
430 	uint64_t	srvbytes[NFSV42_NOPS + NFSV4OP_FAKENOPS];
431 	uint64_t	srvops[NFSV42_NOPS + NFSV4OP_FAKENOPS];
432 	struct bintime	srvduration[NFSV42_NOPS + NFSV4OP_FAKENOPS];
433 	struct bintime	busyfrom;
434 	struct bintime	busytime;
435 };
436 
437 /*
438  * Old stats structure.
439  */
440 struct ext_nfsstats {
441 	int	attrcache_hits;
442 	int	attrcache_misses;
443 	int	lookupcache_hits;
444 	int	lookupcache_misses;
445 	int	direofcache_hits;
446 	int	direofcache_misses;
447 	int	accesscache_hits;
448 	int	accesscache_misses;
449 	int	biocache_reads;
450 	int	read_bios;
451 	int	read_physios;
452 	int	biocache_writes;
453 	int	write_bios;
454 	int	write_physios;
455 	int	biocache_readlinks;
456 	int	readlink_bios;
457 	int	biocache_readdirs;
458 	int	readdir_bios;
459 	int	rpccnt[NFSV4_NPROCS];
460 	int	rpcretries;
461 	int	srvrpccnt[NFSV4OP_NOPS + NFSV4OP_FAKENOPS];
462 	int	srvrpc_errs;
463 	int	srv_errs;
464 	int	rpcrequests;
465 	int	rpctimeouts;
466 	int	rpcunexpected;
467 	int	rpcinvalid;
468 	int	srvcache_inproghits;
469 	int	srvcache_idemdonehits;
470 	int	srvcache_nonidemdonehits;
471 	int	srvcache_misses;
472 	int	srvcache_tcppeak;
473 	int	srvcache_size;
474 	int	srvclients;
475 	int	srvopenowners;
476 	int	srvopens;
477 	int	srvlockowners;
478 	int	srvlocks;
479 	int	srvdelegates;
480 	int	cbrpccnt[NFSV4OP_CBNOPS];
481 	int	clopenowners;
482 	int	clopens;
483 	int	cllockowners;
484 	int	cllocks;
485 	int	cldelegates;
486 	int	cllocalopenowners;
487 	int	cllocalopens;
488 	int	cllocallockowners;
489 	int	cllocallocks;
490 };
491 
492 #ifdef _KERNEL
493 /*
494  * Define NFS_NPROCS as NFSV4_NPROCS for the experimental kernel code.
495  */
496 #ifndef	NFS_NPROCS
497 #define	NFS_NPROCS		NFSV4_NPROCS
498 #endif
499 
500 #include <fs/nfs/nfskpiport.h>
501 #include <fs/nfs/nfsdport.h>
502 #include <fs/nfs/rpcv2.h>
503 #include <fs/nfs/nfsproto.h>
504 #include <fs/nfs/nfs.h>
505 #include <fs/nfs/nfsclstate.h>
506 #include <fs/nfs/nfs_var.h>
507 #include <fs/nfs/nfsm_subs.h>
508 #include <fs/nfs/nfsrvcache.h>
509 #include <fs/nfs/nfsrvstate.h>
510 #include <fs/nfs/xdr_subs.h>
511 #include <fs/nfs/nfscl.h>
512 #include <nfsclient/nfsargs.h>
513 #include <fs/nfsclient/nfsmount.h>
514 
515 /*
516  * Just to keep nfs_var.h happy.
517  */
518 struct nfs_vattr {
519 	int	junk;
520 };
521 
522 struct nfsvattr {
523 	struct vattr	na_vattr;
524 	nfsattrbit_t	na_suppattr;
525 	u_int64_t	na_mntonfileno;
526 	u_int64_t	na_filesid[2];
527 };
528 
529 #define	na_type		na_vattr.va_type
530 #define	na_mode		na_vattr.va_mode
531 #define	na_nlink	na_vattr.va_nlink
532 #define	na_uid		na_vattr.va_uid
533 #define	na_gid		na_vattr.va_gid
534 #define	na_fsid		na_vattr.va_fsid
535 #define	na_fileid	na_vattr.va_fileid
536 #define	na_size		na_vattr.va_size
537 #define	na_blocksize	na_vattr.va_blocksize
538 #define	na_atime	na_vattr.va_atime
539 #define	na_mtime	na_vattr.va_mtime
540 #define	na_ctime	na_vattr.va_ctime
541 #define	na_gen		na_vattr.va_gen
542 #define	na_flags	na_vattr.va_flags
543 #define	na_rdev		na_vattr.va_rdev
544 #define	na_bytes	na_vattr.va_bytes
545 #define	na_filerev	na_vattr.va_filerev
546 #define	na_vaflags	na_vattr.va_vaflags
547 
548 #include <fs/nfsclient/nfsnode.h>
549 
550 /*
551  * This is the header structure used for the lists, etc. (It has the
552  * above record in it.
553  */
554 struct nfsrv_stablefirst {
555 	LIST_HEAD(, nfsrv_stable) nsf_head;	/* Head of nfsrv_stable list */
556 	time_t		nsf_eograce;	/* Time grace period ends */
557 	time_t		*nsf_bootvals;	/* Previous boottime values */
558 	struct file	*nsf_fp;	/* File table pointer */
559 	u_char		nsf_flags;	/* NFSNSF_ flags */
560 	struct nfsf_rec	nsf_rec;	/* and above first record */
561 };
562 #define	nsf_lease	nsf_rec.lease
563 #define	nsf_numboots	nsf_rec.numboots
564 
565 /* NFSNSF_xxx flags */
566 #define	NFSNSF_UPDATEDONE	0x01
567 #define	NFSNSF_GRACEOVER	0x02
568 #define	NFSNSF_NEEDLOCK		0x04
569 #define	NFSNSF_EXPIREDCLIENT	0x08
570 #define	NFSNSF_NOOPENS		0x10
571 #define	NFSNSF_OK		0x20
572 
573 /*
574  * Maximum number of boot times allowed in record. Although there is
575  * really no need for a fixed upper bound, this serves as a sanity check
576  * for a corrupted file.
577  */
578 #define	NFSNSF_MAXNUMBOOTS	10000
579 
580 /*
581  * This structure defines the other records in the file. The
582  * nst_client array is actually the size of the client string name.
583  */
584 struct nfst_rec {
585 	u_int16_t	len;
586 	u_char		flag;
587 	u_char		client[1];
588 };
589 /* and the values for flag */
590 #define	NFSNST_NEWSTATE	0x1
591 #define	NFSNST_REVOKE		0x2
592 #define	NFSNST_GOTSTATE		0x4
593 #define	NFSNST_RECLAIMED	0x8
594 
595 /*
596  * This structure is linked onto nfsrv_stablefirst for the duration of
597  * reclaim.
598  */
599 struct nfsrv_stable {
600 	LIST_ENTRY(nfsrv_stable) nst_list;
601 	struct nfsclient	*nst_clp;
602 	struct nfst_rec		nst_rec;
603 };
604 #define	nst_timestamp	nst_rec.timestamp
605 #define	nst_len		nst_rec.len
606 #define	nst_flag	nst_rec.flag
607 #define	nst_client	nst_rec.client
608 
609 /*
610  * At some point the server will run out of kernel storage for
611  * state structures. For FreeBSD5.2, this results in a panic
612  * kmem_map is full. It happens at well over 1000000 opens plus
613  * locks on a PIII-800 with 256Mbytes, so that is where I've set
614  * the limit. If your server panics due to too many opens/locks,
615  * decrease the size of NFSRV_V4STATELIMIT. If you find the server
616  * returning NFS4ERR_RESOURCE a lot and have lots of memory, try
617  * increasing it.
618  */
619 #define	NFSRV_V4STATELIMIT	500000	/* Max # of Opens + Locks */
620 
621 /*
622  * The type required differs with BSDen (just the second arg).
623  */
624 void nfsrvd_rcv(struct socket *, void *, int);
625 
626 /*
627  * Macros for handling socket addresses. (Hopefully this makes the code
628  * more portable, since I've noticed some 'BSD don't have sockaddrs in
629  * mbufs any more.)
630  */
631 #define	NFSSOCKADDR(a, t)	((t)(a))
632 #define	NFSSOCKADDRSIZE(a, s)		((a)->sa_len = (s))
633 
634 /*
635  * These should be defined as a process or thread structure, as required
636  * for signal handling, etc.
637  */
638 #define	NFSNEWCRED(c)		(crdup(c))
639 #define	NFSPROCCRED(p)		((p)->td_ucred)
640 #define	NFSFREECRED(c)		(crfree(c))
641 #define	NFSUIOPROC(u, p)	((u)->uio_td = NULL)
642 #define	NFSPROCP(p)		((p)->td_proc)
643 
644 /*
645  * Define these so that cn_hash and its length is ignored.
646  */
647 #define	NFSCNHASHZERO(c)
648 #define	NFSCNHASH(c, v)
649 #define	NCHNAMLEN	9999999
650 
651 /*
652  * These macros are defined to initialize and set the timer routine.
653  */
654 #define	NFS_TIMERINIT \
655 	newnfs_timer(NULL)
656 
657 /*
658  * Handle SMP stuff:
659  */
660 #define	NFSSTATESPINLOCK	extern struct mtx nfs_state_mutex
661 #define	NFSLOCKSTATE()		mtx_lock(&nfs_state_mutex)
662 #define	NFSUNLOCKSTATE()	mtx_unlock(&nfs_state_mutex)
663 #define	NFSSTATEMUTEXPTR	(&nfs_state_mutex)
664 #define	NFSREQSPINLOCK		extern struct mtx nfs_req_mutex
665 #define	NFSLOCKREQ()		mtx_lock(&nfs_req_mutex)
666 #define	NFSUNLOCKREQ()		mtx_unlock(&nfs_req_mutex)
667 #define	NFSSOCKMUTEX		extern struct mtx nfs_slock_mutex
668 #define	NFSSOCKMUTEXPTR		(&nfs_slock_mutex)
669 #define	NFSLOCKSOCK()		mtx_lock(&nfs_slock_mutex)
670 #define	NFSUNLOCKSOCK()		mtx_unlock(&nfs_slock_mutex)
671 #define	NFSNAMEIDMUTEX		extern struct mtx nfs_nameid_mutex
672 #define	NFSLOCKNAMEID()		mtx_lock(&nfs_nameid_mutex)
673 #define	NFSUNLOCKNAMEID()	mtx_unlock(&nfs_nameid_mutex)
674 #define	NFSNAMEIDREQUIRED()	mtx_assert(&nfs_nameid_mutex, MA_OWNED)
675 #define	NFSCLSTATEMUTEX		extern struct mtx nfs_clstate_mutex
676 #define	NFSCLSTATEMUTEXPTR	(&nfs_clstate_mutex)
677 #define	NFSLOCKCLSTATE()	mtx_lock(&nfs_clstate_mutex)
678 #define	NFSUNLOCKCLSTATE()	mtx_unlock(&nfs_clstate_mutex)
679 #define	NFSDLOCKMUTEX		extern struct mtx newnfsd_mtx
680 #define	NFSDLOCKMUTEXPTR	(&newnfsd_mtx)
681 #define	NFSD_LOCK()		mtx_lock(&newnfsd_mtx)
682 #define	NFSD_UNLOCK()		mtx_unlock(&newnfsd_mtx)
683 #define	NFSD_LOCK_ASSERT()	mtx_assert(&newnfsd_mtx, MA_OWNED)
684 #define	NFSD_UNLOCK_ASSERT()	mtx_assert(&newnfsd_mtx, MA_NOTOWNED)
685 #define	NFSV4ROOTLOCKMUTEX	extern struct mtx nfs_v4root_mutex
686 #define	NFSV4ROOTLOCKMUTEXPTR	(&nfs_v4root_mutex)
687 #define	NFSLOCKV4ROOTMUTEX()	mtx_lock(&nfs_v4root_mutex)
688 #define	NFSUNLOCKV4ROOTMUTEX()	mtx_unlock(&nfs_v4root_mutex)
689 #define	NFSLOCKNODE(n)		mtx_lock(&((n)->n_mtx))
690 #define	NFSUNLOCKNODE(n)	mtx_unlock(&((n)->n_mtx))
691 #define	NFSLOCKMNT(m)		mtx_lock(&((m)->nm_mtx))
692 #define	NFSUNLOCKMNT(m)		mtx_unlock(&((m)->nm_mtx))
693 #define	NFSLOCKREQUEST(r)	mtx_lock(&((r)->r_mtx))
694 #define	NFSUNLOCKREQUEST(r)	mtx_unlock(&((r)->r_mtx))
695 #define	NFSLOCKSOCKREQ(r)	mtx_lock(&((r)->nr_mtx))
696 #define	NFSUNLOCKSOCKREQ(r)	mtx_unlock(&((r)->nr_mtx))
697 #define	NFSLOCKDS(d)		mtx_lock(&((d)->nfsclds_mtx))
698 #define	NFSUNLOCKDS(d)		mtx_unlock(&((d)->nfsclds_mtx))
699 #define	NFSSESSIONMUTEXPTR(s)	(&((s)->mtx))
700 #define	NFSLOCKSESSION(s)	mtx_lock(&((s)->mtx))
701 #define	NFSUNLOCKSESSION(s)	mtx_unlock(&((s)->mtx))
702 #define	NFSLAYOUTMUTEXPTR(l)	(&((l)->mtx))
703 #define	NFSLOCKLAYOUT(l)	mtx_lock(&((l)->mtx))
704 #define	NFSUNLOCKLAYOUT(l)	mtx_unlock(&((l)->mtx))
705 #define	NFSDDSMUTEXPTR		(&nfsrv_dslock_mtx)
706 #define	NFSDDSLOCK()		mtx_lock(&nfsrv_dslock_mtx)
707 #define	NFSDDSUNLOCK()		mtx_unlock(&nfsrv_dslock_mtx)
708 #define	NFSDDONTLISTMUTEXPTR	(&nfsrv_dontlistlock_mtx)
709 #define	NFSDDONTLISTLOCK()	mtx_lock(&nfsrv_dontlistlock_mtx)
710 #define	NFSDDONTLISTUNLOCK()	mtx_unlock(&nfsrv_dontlistlock_mtx)
711 #define	NFSDRECALLMUTEXPTR	(&nfsrv_recalllock_mtx)
712 #define	NFSDRECALLLOCK()	mtx_lock(&nfsrv_recalllock_mtx)
713 #define	NFSDRECALLUNLOCK()	mtx_unlock(&nfsrv_recalllock_mtx)
714 
715 /*
716  * Use these macros to initialize/free a mutex.
717  */
718 #define	NFSINITSOCKMUTEX(m)	mtx_init((m), "nfssock", NULL, MTX_DEF)
719 #define	NFSFREEMUTEX(m)		mtx_destroy((m))
720 
721 int nfsmsleep(void *, void *, int, const char *, struct timespec *);
722 
723 /*
724  * And weird vm stuff in the nfs server.
725  */
726 #define	PDIRUNLOCK	0x0
727 #define	MAX_COMMIT_COUNT	(1024 * 1024)
728 
729 /*
730  * Define these to handle the type of va_rdev.
731  */
732 #define	NFSMAKEDEV(m, n)	makedev((m), (n))
733 #define	NFSMAJOR(d)		major(d)
734 #define	NFSMINOR(d)		minor(d)
735 
736 /*
737  * The vnode tag for nfsv4root.
738  */
739 #define	VT_NFSV4ROOT		"nfsv4root"
740 
741 /*
742  * Define whatever it takes to do a vn_rdwr().
743  */
744 #define	NFSD_RDWR(r, v, b, l, o, s, i, c, a, p) \
745 	vn_rdwr((r), (v), (b), (l), (o), (s), (i), (c), NULL, (a), (p))
746 
747 /*
748  * Macros for handling memory for different BSDen.
749  * NFSBCOPY(src, dst, len) - copies len bytes, non-overlapping
750  * NFSOVBCOPY(src, dst, len) - ditto, but data areas might overlap
751  * NFSBCMP(cp1, cp2, len) - compare len bytes, return 0 if same
752  * NFSBZERO(cp, len) - set len bytes to 0x0
753  */
754 #define	NFSBCOPY(s, d, l)	bcopy((s), (d), (l))
755 #define	NFSOVBCOPY(s, d, l)	ovbcopy((s), (d), (l))
756 #define	NFSBCMP(s, d, l)	bcmp((s), (d), (l))
757 #define	NFSBZERO(s, l)		bzero((s), (l))
758 
759 /*
760  * Some queue.h files don't have these dfined in them.
761  */
762 #define	LIST_END(head)		NULL
763 #define	SLIST_END(head)		NULL
764 #define	TAILQ_END(head)		NULL
765 
766 /*
767  * This must be defined to be a global variable that increments once
768  * per second, but never stops or goes backwards, even when a "date"
769  * command changes the TOD clock. It is used for delta times for
770  * leases, etc.
771  */
772 #define	NFSD_MONOSEC		time_uptime
773 
774 /*
775  * Declare the malloc types.
776  */
777 MALLOC_DECLARE(M_NEWNFSRVCACHE);
778 MALLOC_DECLARE(M_NEWNFSDCLIENT);
779 MALLOC_DECLARE(M_NEWNFSDSTATE);
780 MALLOC_DECLARE(M_NEWNFSDLOCK);
781 MALLOC_DECLARE(M_NEWNFSDLOCKFILE);
782 MALLOC_DECLARE(M_NEWNFSSTRING);
783 MALLOC_DECLARE(M_NEWNFSUSERGROUP);
784 MALLOC_DECLARE(M_NEWNFSDREQ);
785 MALLOC_DECLARE(M_NEWNFSFH);
786 MALLOC_DECLARE(M_NEWNFSCLOWNER);
787 MALLOC_DECLARE(M_NEWNFSCLOPEN);
788 MALLOC_DECLARE(M_NEWNFSCLDELEG);
789 MALLOC_DECLARE(M_NEWNFSCLCLIENT);
790 MALLOC_DECLARE(M_NEWNFSCLLOCKOWNER);
791 MALLOC_DECLARE(M_NEWNFSCLLOCK);
792 MALLOC_DECLARE(M_NEWNFSDIROFF);
793 MALLOC_DECLARE(M_NEWNFSV4NODE);
794 MALLOC_DECLARE(M_NEWNFSDIRECTIO);
795 MALLOC_DECLARE(M_NEWNFSMNT);
796 MALLOC_DECLARE(M_NEWNFSDROLLBACK);
797 MALLOC_DECLARE(M_NEWNFSLAYOUT);
798 MALLOC_DECLARE(M_NEWNFSFLAYOUT);
799 MALLOC_DECLARE(M_NEWNFSDEVINFO);
800 MALLOC_DECLARE(M_NEWNFSSOCKREQ);
801 MALLOC_DECLARE(M_NEWNFSCLDS);
802 MALLOC_DECLARE(M_NEWNFSLAYRECALL);
803 MALLOC_DECLARE(M_NEWNFSDSESSION);
804 #define	M_NFSRVCACHE	M_NEWNFSRVCACHE
805 #define	M_NFSDCLIENT	M_NEWNFSDCLIENT
806 #define	M_NFSDSTATE	M_NEWNFSDSTATE
807 #define	M_NFSDLOCK	M_NEWNFSDLOCK
808 #define	M_NFSDLOCKFILE	M_NEWNFSDLOCKFILE
809 #define	M_NFSSTRING	M_NEWNFSSTRING
810 #define	M_NFSUSERGROUP	M_NEWNFSUSERGROUP
811 #define	M_NFSDREQ	M_NEWNFSDREQ
812 #define	M_NFSFH		M_NEWNFSFH
813 #define	M_NFSCLOWNER	M_NEWNFSCLOWNER
814 #define	M_NFSCLOPEN	M_NEWNFSCLOPEN
815 #define	M_NFSCLDELEG	M_NEWNFSCLDELEG
816 #define	M_NFSCLCLIENT	M_NEWNFSCLCLIENT
817 #define	M_NFSCLLOCKOWNER M_NEWNFSCLLOCKOWNER
818 #define	M_NFSCLLOCK	M_NEWNFSCLLOCK
819 #define	M_NFSDIROFF	M_NEWNFSDIROFF
820 #define	M_NFSV4NODE	M_NEWNFSV4NODE
821 #define	M_NFSDIRECTIO	M_NEWNFSDIRECTIO
822 #define	M_NFSDROLLBACK	M_NEWNFSDROLLBACK
823 #define	M_NFSLAYOUT	M_NEWNFSLAYOUT
824 #define	M_NFSFLAYOUT	M_NEWNFSFLAYOUT
825 #define	M_NFSDEVINFO	M_NEWNFSDEVINFO
826 #define	M_NFSSOCKREQ	M_NEWNFSSOCKREQ
827 #define	M_NFSCLDS	M_NEWNFSCLDS
828 #define	M_NFSLAYRECALL	M_NEWNFSLAYRECALL
829 #define	M_NFSDSESSION	M_NEWNFSDSESSION
830 
831 #define	NFSINT_SIGMASK(set) 						\
832 	(SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) ||	\
833 	 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) ||	\
834 	 SIGISMEMBER(set, SIGQUIT))
835 
836 /*
837  * Convert a quota block count to byte count.
838  */
839 #define	NFSQUOTABLKTOBYTE(q, b)	(q) *= (b)
840 
841 /*
842  * Define this as the largest file size supported. (It should probably
843  * be available via a VFS_xxx Op, but it isn't.
844  */
845 #define	NFSRV_MAXFILESIZE	((u_int64_t)0x800000000000)
846 
847 /*
848  * Set this macro to index() or strchr(), whichever is supported.
849  */
850 #define	STRCHR(s, c)		strchr((s), (c))
851 
852 /*
853  * Set the n_time in the client write rpc, as required.
854  */
855 #define	NFSWRITERPC_SETTIME(w, n, a, v4)				\
856 	do {								\
857 		if (w) {						\
858 			mtx_lock(&((n)->n_mtx));			\
859 			(n)->n_mtime = (a)->na_mtime;			\
860 			if (v4)						\
861 				(n)->n_change = (a)->na_filerev;	\
862 			mtx_unlock(&((n)->n_mtx));			\
863 		}							\
864 	} while (0)
865 
866 /*
867  * Fake value, just to make the client work.
868  */
869 #define	NFS_LATTR_NOSHRINK	1
870 
871 /*
872  * Prototypes for functions where the arguments vary for different ports.
873  */
874 int nfscl_loadattrcache(struct vnode **, struct nfsvattr *, void *, void *,
875     int, int);
876 int newnfs_realign(struct mbuf **, int);
877 
878 /*
879  * If the port runs on an SMP box that can enforce Atomic ops with low
880  * overheads, define these as atomic increments/decrements. If not,
881  * don't worry about it, since these are used for stats that can be
882  * "out by one" without disastrous consequences.
883  */
884 #define	NFSINCRGLOBAL(a)	((a)++)
885 
886 /*
887  * Assorted funky stuff to make things work under Darwin8.
888  */
889 /*
890  * These macros checks for a field in vattr being set.
891  */
892 #define	NFSATTRISSET(t, v, a)	((v)->a != (t)VNOVAL)
893 #define	NFSATTRISSETTIME(v, a)	((v)->a.tv_sec != VNOVAL)
894 
895 /*
896  * Manipulate mount flags.
897  */
898 #define	NFSSTA_HASWRITEVERF	0x00040000  /* Has write verifier */
899 #define	NFSSTA_GOTFSINFO	0x00100000  /* Got the fsinfo */
900 #define	NFSSTA_OPENMODE		0x00200000  /* Must use correct open mode */
901 #define	NFSSTA_FLEXFILE		0x00800000  /* Use Flex File Layout */
902 #define	NFSSTA_NOLAYOUTCOMMIT	0x04000000  /* Don't do LayoutCommit */
903 #define	NFSSTA_SESSPERSIST	0x08000000  /* Has a persistent session */
904 #define	NFSSTA_TIMEO		0x10000000  /* Experiencing a timeout */
905 #define	NFSSTA_LOCKTIMEO	0x20000000  /* Experiencing a lockd timeout */
906 #define	NFSSTA_HASSETFSID	0x40000000  /* Has set the fsid */
907 #define	NFSSTA_PNFS		0x80000000  /* pNFS is enabled */
908 
909 #define	NFSHASNFSV3(n)		((n)->nm_flag & NFSMNT_NFSV3)
910 #define	NFSHASNFSV4(n)		((n)->nm_flag & NFSMNT_NFSV4)
911 #define	NFSHASNFSV4N(n)		((n)->nm_minorvers > 0)
912 #define	NFSHASNFSV3OR4(n)	((n)->nm_flag & (NFSMNT_NFSV3 | NFSMNT_NFSV4))
913 #define	NFSHASGOTFSINFO(n)	((n)->nm_state & NFSSTA_GOTFSINFO)
914 #define	NFSHASHASSETFSID(n)	((n)->nm_state & NFSSTA_HASSETFSID)
915 #define	NFSHASSTRICT3530(n)	((n)->nm_flag & NFSMNT_STRICT3530)
916 #define	NFSHASWRITEVERF(n)	((n)->nm_state & NFSSTA_HASWRITEVERF)
917 #define	NFSHASINT(n)		((n)->nm_flag & NFSMNT_INT)
918 #define	NFSHASSOFT(n)		((n)->nm_flag & NFSMNT_SOFT)
919 #define	NFSHASINTORSOFT(n)	((n)->nm_flag & (NFSMNT_INT | NFSMNT_SOFT))
920 #define	NFSHASDUMBTIMR(n)	((n)->nm_flag & NFSMNT_DUMBTIMR)
921 #define	NFSHASNOCONN(n)		((n)->nm_flag & NFSMNT_MNTD)
922 #define	NFSHASKERB(n)		((n)->nm_flag & NFSMNT_KERB)
923 #define	NFSHASALLGSSNAME(n)	((n)->nm_flag & NFSMNT_ALLGSSNAME)
924 #define	NFSHASINTEGRITY(n)	((n)->nm_flag & NFSMNT_INTEGRITY)
925 #define	NFSHASPRIVACY(n)	((n)->nm_flag & NFSMNT_PRIVACY)
926 #define	NFSSETWRITEVERF(n)	((n)->nm_state |= NFSSTA_HASWRITEVERF)
927 #define	NFSSETHASSETFSID(n)	((n)->nm_state |= NFSSTA_HASSETFSID)
928 #define	NFSHASPNFSOPT(n)	((n)->nm_flag & NFSMNT_PNFS)
929 #define	NFSHASNOLAYOUTCOMMIT(n)	((n)->nm_state & NFSSTA_NOLAYOUTCOMMIT)
930 #define	NFSHASSESSPERSIST(n)	((n)->nm_state & NFSSTA_SESSPERSIST)
931 #define	NFSHASPNFS(n)		((n)->nm_state & NFSSTA_PNFS)
932 #define	NFSHASFLEXFILE(n)	((n)->nm_state & NFSSTA_FLEXFILE)
933 #define	NFSHASOPENMODE(n)	((n)->nm_state & NFSSTA_OPENMODE)
934 #define	NFSHASONEOPENOWN(n)	(((n)->nm_flag & NFSMNT_ONEOPENOWN) != 0 &&	\
935 				    (n)->nm_minorvers > 0)
936 
937 /*
938  * Gets the stats field out of the mount structure.
939  */
940 #define	vfs_statfs(m)	(&((m)->mnt_stat))
941 
942 /*
943  * Set boottime.
944  */
945 #define	NFSSETBOOTTIME(b)	(getboottime(&b))
946 
947 /*
948  * The size of directory blocks in the buffer cache.
949  * MUST BE in the range of PAGE_SIZE <= NFS_DIRBLKSIZ <= MAXBSIZE!!
950  */
951 #define	NFS_DIRBLKSIZ	(16 * DIRBLKSIZ) /* Must be a multiple of DIRBLKSIZ */
952 
953 /*
954  * Define these macros to access mnt_flag fields.
955  */
956 #define	NFSMNT_RDONLY(m)	((m)->mnt_flag & MNT_RDONLY)
957 #endif	/* _KERNEL */
958 
959 /*
960  * Define a structure similar to ufs_args for use in exporting the V4 root.
961  */
962 struct nfsex_args {
963 	char	*fspec;
964 	struct export_args	export;
965 };
966 
967 /*
968  * These export flags should be defined, but there are no bits left.
969  * Maybe a separate mnt_exflag field could be added or the mnt_flag
970  * field increased to 64 bits?
971  */
972 #ifndef	MNT_EXSTRICTACCESS
973 #define	MNT_EXSTRICTACCESS	0x0
974 #endif
975 #ifndef MNT_EXV4ONLY
976 #define	MNT_EXV4ONLY		0x0
977 #endif
978 
979 #ifdef _KERNEL
980 /*
981  * Define this to invalidate the attribute cache for the nfs node.
982  */
983 #define	NFSINVALATTRCACHE(n)	((n)->n_attrstamp = 0)
984 
985 /* Used for FreeBSD only */
986 void nfsd_mntinit(void);
987 
988 /*
989  * Define these for vnode lock/unlock ops.
990  *
991  * These are good abstractions to macro out, so that they can be added to
992  * later, for debugging or stats, etc.
993  */
994 #define	NFSVOPLOCK(v, f)	vn_lock((v), (f))
995 #define	NFSVOPUNLOCK(v, f)	VOP_UNLOCK((v), (f))
996 #define	NFSVOPISLOCKED(v)	VOP_ISLOCKED((v))
997 
998 /*
999  * Define ncl_hash().
1000  */
1001 #define	ncl_hash(f, l)	(fnv_32_buf((f), (l), FNV1_32_INIT))
1002 
1003 int newnfs_iosize(struct nfsmount *);
1004 
1005 int newnfs_vncmpf(struct vnode *, void *);
1006 
1007 #ifndef NFS_MINDIRATTRTIMO
1008 #define	NFS_MINDIRATTRTIMO 3		/* VDIR attrib cache timeout in sec */
1009 #endif
1010 #ifndef NFS_MAXDIRATTRTIMO
1011 #define	NFS_MAXDIRATTRTIMO 60
1012 #endif
1013 
1014 /*
1015  * Nfs outstanding request list element
1016  */
1017 struct nfsreq {
1018 	TAILQ_ENTRY(nfsreq) r_chain;
1019 	u_int32_t	r_flags;	/* flags on request, see below */
1020 	struct nfsmount *r_nmp;		/* Client mnt ptr */
1021 	struct mtx	r_mtx;		/* Mutex lock for this structure */
1022 };
1023 
1024 #ifndef NFS_MAXBSIZE
1025 #define	NFS_MAXBSIZE	(maxbcachebuf)
1026 #endif
1027 
1028 /*
1029  * This macro checks to see if issuing of delegations is allowed for this
1030  * vnode.
1031  */
1032 #ifdef VV_DISABLEDELEG
1033 #define	NFSVNO_DELEGOK(v)						\
1034 	((v) == NULL || ((v)->v_vflag & VV_DISABLEDELEG) == 0)
1035 #else
1036 #define	NFSVNO_DELEGOK(v)	(1)
1037 #endif
1038 
1039 /*
1040  * Name used by getnewvnode() to describe filesystem, "nfs".
1041  * For performance reasons it is useful to have the same string
1042  * used in both places that call getnewvnode().
1043  */
1044 extern const char nfs_vnode_tag[];
1045 
1046 /*
1047  * Check for the errors that indicate a DS should be disabled.
1048  * ENXIO indicates that the krpc cannot do an RPC on the DS.
1049  * EIO is returned by the RPC as an indication of I/O problems on the
1050  * server.
1051  * Are there other fatal errors?
1052  */
1053 #define	nfsds_failerr(e)	((e) == ENXIO || (e) == EIO)
1054 
1055 /*
1056  * Get a pointer to the MDS session, which is always the first element
1057  * in the list.
1058  * This macro can only be safely used when the NFSLOCKMNT() lock is held.
1059  * The inline function can be used when the lock isn't held.
1060  */
1061 #define	NFSMNT_MDSSESSION(m)	(&(TAILQ_FIRST(&((m)->nm_sess))->nfsclds_sess))
1062 
1063 static __inline struct nfsclsession *
1064 nfsmnt_mdssession(struct nfsmount *nmp)
1065 {
1066 	struct nfsclsession *tsep;
1067 
1068 	tsep = NULL;
1069 	mtx_lock(&nmp->nm_mtx);
1070 	if (TAILQ_FIRST(&nmp->nm_sess) != NULL)
1071 		tsep = NFSMNT_MDSSESSION(nmp);
1072 	mtx_unlock(&nmp->nm_mtx);
1073 	return (tsep);
1074 }
1075 
1076 #endif	/* _KERNEL */
1077 
1078 #endif	/* _NFS_NFSPORT_H */
1079