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