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