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