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