1191783Srmacklem/*- 2191783Srmacklem * Copyright (c) 1989, 1993 3191783Srmacklem * The Regents of the University of California. All rights reserved. 4191783Srmacklem * 5191783Srmacklem * This code is derived from software contributed to Berkeley by 6191783Srmacklem * Rick Macklem at The University of Guelph. 7191783Srmacklem * 8191783Srmacklem * Redistribution and use in source and binary forms, with or without 9191783Srmacklem * modification, are permitted provided that the following conditions 10191783Srmacklem * are met: 11191783Srmacklem * 1. Redistributions of source code must retain the above copyright 12191783Srmacklem * notice, this list of conditions and the following disclaimer. 13191783Srmacklem * 2. Redistributions in binary form must reproduce the above copyright 14191783Srmacklem * notice, this list of conditions and the following disclaimer in the 15191783Srmacklem * documentation and/or other materials provided with the distribution. 16191783Srmacklem * 4. Neither the name of the University nor the names of its contributors 17191783Srmacklem * may be used to endorse or promote products derived from this software 18191783Srmacklem * without specific prior written permission. 19191783Srmacklem * 20191783Srmacklem * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21191783Srmacklem * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22191783Srmacklem * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23191783Srmacklem * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24191783Srmacklem * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25191783Srmacklem * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26191783Srmacklem * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27191783Srmacklem * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28191783Srmacklem * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29191783Srmacklem * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30191783Srmacklem * SUCH DAMAGE. 31191783Srmacklem * 32191783Srmacklem * $FreeBSD$ 33191783Srmacklem */ 34191783Srmacklem 35191783Srmacklem#ifndef _NFS_NFSPORT_H_ 36207785Srmacklem#define _NFS_NFSPORT_H_ 37191783Srmacklem 38191783Srmacklem/* 39191783Srmacklem * In general, I'm not fond of #includes in .h files, but this seems 40191783Srmacklem * to be the cleanest way to handle #include files for the ports. 41191783Srmacklem */ 42191783Srmacklem#ifdef _KERNEL 43191783Srmacklem#include <sys/unistd.h> 44191783Srmacklem#include <sys/param.h> 45191783Srmacklem#include <sys/systm.h> 46191783Srmacklem#include <sys/conf.h> 47191783Srmacklem#include <sys/dirent.h> 48191783Srmacklem#include <sys/domain.h> 49191783Srmacklem#include <sys/fcntl.h> 50191783Srmacklem#include <sys/file.h> 51191783Srmacklem#include <sys/filedesc.h> 52193066Sjamie#include <sys/jail.h> 53191783Srmacklem#include <sys/kernel.h> 54191783Srmacklem#include <sys/lockf.h> 55191783Srmacklem#include <sys/malloc.h> 56191783Srmacklem#include <sys/mbuf.h> 57191783Srmacklem#include <sys/mount.h> 58191783Srmacklem#include <sys/namei.h> 59191783Srmacklem#include <sys/proc.h> 60191783Srmacklem#include <sys/protosw.h> 61191783Srmacklem#include <sys/reboot.h> 62191783Srmacklem#include <sys/resourcevar.h> 63191783Srmacklem#include <sys/signalvar.h> 64191783Srmacklem#include <sys/socket.h> 65191783Srmacklem#include <sys/socketvar.h> 66191783Srmacklem#include <sys/stat.h> 67191783Srmacklem#include <sys/syslog.h> 68191783Srmacklem#include <sys/sysproto.h> 69191783Srmacklem#include <sys/time.h> 70191783Srmacklem#include <sys/uio.h> 71191783Srmacklem#include <sys/vnode.h> 72191783Srmacklem#include <sys/bio.h> 73191783Srmacklem#include <sys/buf.h> 74191783Srmacklem#include <sys/acl.h> 75191783Srmacklem#include <sys/module.h> 76191783Srmacklem#include <sys/sysent.h> 77191783Srmacklem#include <sys/syscall.h> 78191783Srmacklem#include <sys/priv.h> 79191783Srmacklem#include <sys/kthread.h> 80191783Srmacklem#include <sys/syscallsubr.h> 81191783Srmacklem#include <net/if.h> 82191783Srmacklem#include <net/radix.h> 83191783Srmacklem#include <net/route.h> 84191783Srmacklem#include <net/if_dl.h> 85191783Srmacklem#include <netinet/in.h> 86191783Srmacklem#include <netinet/in_pcb.h> 87191783Srmacklem#include <netinet/in_systm.h> 88191783Srmacklem#include <netinet/in_var.h> 89191783Srmacklem#include <netinet/ip.h> 90191783Srmacklem#include <netinet/ip_var.h> 91191783Srmacklem#include <netinet/tcp.h> 92191783Srmacklem#include <netinet/tcp_fsm.h> 93191783Srmacklem#include <netinet/tcp_seq.h> 94191783Srmacklem#include <netinet/tcp_timer.h> 95191783Srmacklem#include <netinet/tcp_var.h> 96191783Srmacklem#include <machine/in_cksum.h> 97191783Srmacklem#include <crypto/des/des.h> 98191783Srmacklem#include <sys/md5.h> 99191783Srmacklem#include <rpc/rpc.h> 100191783Srmacklem#include <rpc/rpcsec_gss.h> 101191783Srmacklem 102191783Srmacklem/* 103191783Srmacklem * For Darwin, these functions should be "static" when built in a kext. 104191783Srmacklem * (This is always defined as nil otherwise.) 105191783Srmacklem */ 106191783Srmacklem#define APPLESTATIC 107191783Srmacklem#include <ufs/ufs/dir.h> 108191783Srmacklem#include <ufs/ufs/quota.h> 109191783Srmacklem#include <ufs/ufs/inode.h> 110191783Srmacklem#include <ufs/ufs/extattr.h> 111191783Srmacklem#include <ufs/ufs/ufsmount.h> 112191783Srmacklem#include <vm/uma.h> 113191783Srmacklem#include <vm/vm.h> 114191783Srmacklem#include <vm/vm_object.h> 115191783Srmacklem#include <vm/vm_extern.h> 116191783Srmacklem#include <nfs/nfssvc.h> 117191783Srmacklem#include "opt_nfs.h" 118191783Srmacklem#include "opt_ufs.h" 119191783Srmacklem 120191783Srmacklem/* 121191783Srmacklem * These types must be defined before the nfs includes. 122191783Srmacklem */ 123191783Srmacklem#define NFSSOCKADDR_T struct sockaddr * 124191783Srmacklem#define NFSPROC_T struct thread 125191783Srmacklem#define NFSDEV_T dev_t 126191783Srmacklem#define NFSSVCARGS nfssvc_args 127191783Srmacklem#define NFSACL_T struct acl 128191783Srmacklem 129191783Srmacklem/* 130191783Srmacklem * These should be defined as the types used for the corresponding VOP's 131191783Srmacklem * argument type. 132191783Srmacklem */ 133191783Srmacklem#define NFS_ACCESS_ARGS struct vop_access_args 134191783Srmacklem#define NFS_OPEN_ARGS struct vop_open_args 135191783Srmacklem#define NFS_GETATTR_ARGS struct vop_getattr_args 136191783Srmacklem#define NFS_LOOKUP_ARGS struct vop_lookup_args 137191783Srmacklem#define NFS_READDIR_ARGS struct vop_readdir_args 138191783Srmacklem 139191783Srmacklem/* 140191783Srmacklem * Allocate mbufs. Must succeed and never set the mbuf ptr to NULL. 141191783Srmacklem */ 142191783Srmacklem#define NFSMGET(m) do { \ 143248188Sglebius MGET((m), M_WAITOK, MT_DATA); \ 144191783Srmacklem while ((m) == NULL ) { \ 145207170Srmacklem (void) nfs_catnap(PZERO, 0, "nfsmget"); \ 146248188Sglebius MGET((m), M_WAITOK, MT_DATA); \ 147191783Srmacklem } \ 148191783Srmacklem } while (0) 149191783Srmacklem#define NFSMGETHDR(m) do { \ 150248188Sglebius MGETHDR((m), M_WAITOK, MT_DATA); \ 151191783Srmacklem while ((m) == NULL ) { \ 152207170Srmacklem (void) nfs_catnap(PZERO, 0, "nfsmget"); \ 153248188Sglebius MGETHDR((m), M_WAITOK, MT_DATA); \ 154191783Srmacklem } \ 155191783Srmacklem } while (0) 156191783Srmacklem#define NFSMCLGET(m, w) do { \ 157248188Sglebius MGET((m), M_WAITOK, MT_DATA); \ 158191783Srmacklem while ((m) == NULL ) { \ 159207170Srmacklem (void) nfs_catnap(PZERO, 0, "nfsmget"); \ 160248188Sglebius MGET((m), M_WAITOK, MT_DATA); \ 161191783Srmacklem } \ 162191783Srmacklem MCLGET((m), (w)); \ 163191783Srmacklem } while (0) 164191783Srmacklem#define NFSMCLGETHDR(m, w) do { \ 165248188Sglebius MGETHDR((m), M_WAITOK, MT_DATA); \ 166191783Srmacklem while ((m) == NULL ) { \ 167207170Srmacklem (void) nfs_catnap(PZERO, 0, "nfsmget"); \ 168248188Sglebius MGETHDR((m), M_WAITOK, MT_DATA); \ 169191783Srmacklem } \ 170191783Srmacklem } while (0) 171191783Srmacklem#define NFSMTOD mtod 172191783Srmacklem 173191783Srmacklem/* 174191783Srmacklem * Client side constant for size of a lockowner name. 175191783Srmacklem */ 176191783Srmacklem#define NFSV4CL_LOCKNAMELEN 12 177191783Srmacklem 178191783Srmacklem/* 179191783Srmacklem * Type for a mutex lock. 180191783Srmacklem */ 181191783Srmacklem#define NFSMUTEX_T struct mtx 182191783Srmacklem 183192152Srmacklem#endif /* _KERNEL */ 184192152Srmacklem 185192152Srmacklem/* 186192152Srmacklem * NFSv4 Operation numbers. 187192152Srmacklem */ 188192152Srmacklem#define NFSV4OP_ACCESS 3 189192152Srmacklem#define NFSV4OP_CLOSE 4 190192152Srmacklem#define NFSV4OP_COMMIT 5 191192152Srmacklem#define NFSV4OP_CREATE 6 192192152Srmacklem#define NFSV4OP_DELEGPURGE 7 193192152Srmacklem#define NFSV4OP_DELEGRETURN 8 194192152Srmacklem#define NFSV4OP_GETATTR 9 195192152Srmacklem#define NFSV4OP_GETFH 10 196192152Srmacklem#define NFSV4OP_LINK 11 197192152Srmacklem#define NFSV4OP_LOCK 12 198192152Srmacklem#define NFSV4OP_LOCKT 13 199192152Srmacklem#define NFSV4OP_LOCKU 14 200192152Srmacklem#define NFSV4OP_LOOKUP 15 201192152Srmacklem#define NFSV4OP_LOOKUPP 16 202192152Srmacklem#define NFSV4OP_NVERIFY 17 203192152Srmacklem#define NFSV4OP_OPEN 18 204192152Srmacklem#define NFSV4OP_OPENATTR 19 205192152Srmacklem#define NFSV4OP_OPENCONFIRM 20 206192152Srmacklem#define NFSV4OP_OPENDOWNGRADE 21 207192152Srmacklem#define NFSV4OP_PUTFH 22 208192152Srmacklem#define NFSV4OP_PUTPUBFH 23 209192152Srmacklem#define NFSV4OP_PUTROOTFH 24 210192152Srmacklem#define NFSV4OP_READ 25 211192152Srmacklem#define NFSV4OP_READDIR 26 212192152Srmacklem#define NFSV4OP_READLINK 27 213192152Srmacklem#define NFSV4OP_REMOVE 28 214192152Srmacklem#define NFSV4OP_RENAME 29 215192152Srmacklem#define NFSV4OP_RENEW 30 216192152Srmacklem#define NFSV4OP_RESTOREFH 31 217192152Srmacklem#define NFSV4OP_SAVEFH 32 218192152Srmacklem#define NFSV4OP_SECINFO 33 219192152Srmacklem#define NFSV4OP_SETATTR 34 220192152Srmacklem#define NFSV4OP_SETCLIENTID 35 221192152Srmacklem#define NFSV4OP_SETCLIENTIDCFRM 36 222192152Srmacklem#define NFSV4OP_VERIFY 37 223192152Srmacklem#define NFSV4OP_WRITE 38 224192152Srmacklem#define NFSV4OP_RELEASELCKOWN 39 225192152Srmacklem 226192152Srmacklem/* 227192152Srmacklem * Must be one greater than the last Operation#. 228192152Srmacklem */ 229192152Srmacklem#define NFSV4OP_NOPS 40 230192152Srmacklem 231244042Srmacklem/* 232244042Srmacklem * Additional Ops for NFSv4.1. 233244042Srmacklem */ 234244042Srmacklem#define NFSV4OP_BACKCHANNELCTL 40 235244042Srmacklem#define NFSV4OP_BINDCONNTOSESS 41 236244042Srmacklem#define NFSV4OP_EXCHANGEID 42 237244042Srmacklem#define NFSV4OP_CREATESESSION 43 238244042Srmacklem#define NFSV4OP_DESTROYSESSION 44 239244042Srmacklem#define NFSV4OP_FREESTATEID 45 240244042Srmacklem#define NFSV4OP_GETDIRDELEG 46 241244042Srmacklem#define NFSV4OP_GETDEVINFO 47 242244042Srmacklem#define NFSV4OP_GETDEVLIST 48 243244042Srmacklem#define NFSV4OP_LAYOUTCOMMIT 49 244244042Srmacklem#define NFSV4OP_LAYOUTGET 50 245244042Srmacklem#define NFSV4OP_LAYOUTRETURN 51 246244042Srmacklem#define NFSV4OP_SECINFONONAME 52 247244042Srmacklem#define NFSV4OP_SEQUENCE 53 248244042Srmacklem#define NFSV4OP_SETSSV 54 249244042Srmacklem#define NFSV4OP_TESTSTATEID 55 250244042Srmacklem#define NFSV4OP_WANTDELEG 56 251244042Srmacklem#define NFSV4OP_DESTROYCLIENTID 57 252244042Srmacklem#define NFSV4OP_RECLAIMCOMPL 58 253244042Srmacklem 254244042Srmacklem/* 255244042Srmacklem * Must be one more than last op#. 256244042Srmacklem */ 257244042Srmacklem#define NFSV41_NOPS 59 258244042Srmacklem 259192781Srmacklem/* Quirky case if the illegal op code */ 260192781Srmacklem#define NFSV4OP_OPILLEGAL 10044 261192781Srmacklem 262192152Srmacklem/* 263192152Srmacklem * Fake NFSV4OP_xxx used for nfsstat. Start at NFSV4OP_NOPS. 264192152Srmacklem */ 265192152Srmacklem#define NFSV4OP_SYMLINK (NFSV4OP_NOPS) 266192152Srmacklem#define NFSV4OP_MKDIR (NFSV4OP_NOPS + 1) 267192152Srmacklem#define NFSV4OP_RMDIR (NFSV4OP_NOPS + 2) 268192152Srmacklem#define NFSV4OP_READDIRPLUS (NFSV4OP_NOPS + 3) 269192152Srmacklem#define NFSV4OP_MKNOD (NFSV4OP_NOPS + 4) 270192152Srmacklem#define NFSV4OP_FSSTAT (NFSV4OP_NOPS + 5) 271192152Srmacklem#define NFSV4OP_FSINFO (NFSV4OP_NOPS + 6) 272192152Srmacklem#define NFSV4OP_PATHCONF (NFSV4OP_NOPS + 7) 273192152Srmacklem#define NFSV4OP_V3CREATE (NFSV4OP_NOPS + 8) 274192152Srmacklem 275192152Srmacklem/* 276192152Srmacklem * This is the count of the fake operations listed above. 277192152Srmacklem */ 278192152Srmacklem#define NFSV4OP_FAKENOPS 9 279192152Srmacklem 280192152Srmacklem/* 281192152Srmacklem * and the Callback OPs 282192152Srmacklem */ 283192152Srmacklem#define NFSV4OP_CBGETATTR 3 284192152Srmacklem#define NFSV4OP_CBRECALL 4 285192152Srmacklem 286192152Srmacklem/* 287192152Srmacklem * Must be one greater than the last Callback Operation#. 288192152Srmacklem */ 289192152Srmacklem#define NFSV4OP_CBNOPS 5 290192152Srmacklem 291192152Srmacklem/* 292244042Srmacklem * Additional Callback Ops for NFSv4.1 only. Not yet in nfsstats. 293244042Srmacklem */ 294244042Srmacklem#define NFSV4OP_CBLAYOUTRECALL 5 295244042Srmacklem#define NFSV4OP_CBNOTIFY 6 296244042Srmacklem#define NFSV4OP_CBPUSHDELEG 7 297244042Srmacklem#define NFSV4OP_CBRECALLANY 8 298244042Srmacklem#define NFSV4OP_CBRECALLOBJAVAIL 9 299244042Srmacklem#define NFSV4OP_CBRECALLSLOT 10 300244042Srmacklem#define NFSV4OP_CBSEQUENCE 11 301244042Srmacklem#define NFSV4OP_CBWANTCANCELLED 12 302244042Srmacklem#define NFSV4OP_CBNOTIFYLOCK 13 303244042Srmacklem#define NFSV4OP_CBNOTIFYDEVID 14 304244042Srmacklem 305244042Srmacklem/* 306192152Srmacklem * The lower numbers -> 21 are used by NFSv2 and v3. These define higher 307192152Srmacklem * numbers used by NFSv4. 308192152Srmacklem * NFS_V3NPROCS is one greater than the last V3 op and NFS_NPROCS is 309192152Srmacklem * one greater than the last number. 310192152Srmacklem */ 311223280Srmacklem#ifndef NFS_V3NPROCS 312192152Srmacklem#define NFS_V3NPROCS 22 313192152Srmacklem 314192152Srmacklem#define NFSPROC_LOOKUPP 22 315192152Srmacklem#define NFSPROC_SETCLIENTID 23 316192152Srmacklem#define NFSPROC_SETCLIENTIDCFRM 24 317192152Srmacklem#define NFSPROC_LOCK 25 318192152Srmacklem#define NFSPROC_LOCKU 26 319192152Srmacklem#define NFSPROC_OPEN 27 320192152Srmacklem#define NFSPROC_CLOSE 28 321192152Srmacklem#define NFSPROC_OPENCONFIRM 29 322192152Srmacklem#define NFSPROC_LOCKT 30 323192152Srmacklem#define NFSPROC_OPENDOWNGRADE 31 324192152Srmacklem#define NFSPROC_RENEW 32 325192152Srmacklem#define NFSPROC_PUTROOTFH 33 326192152Srmacklem#define NFSPROC_RELEASELCKOWN 34 327192152Srmacklem#define NFSPROC_DELEGRETURN 35 328192152Srmacklem#define NFSPROC_RETDELEGREMOVE 36 329192152Srmacklem#define NFSPROC_RETDELEGRENAME1 37 330192152Srmacklem#define NFSPROC_RETDELEGRENAME2 38 331192152Srmacklem#define NFSPROC_GETACL 39 332192152Srmacklem#define NFSPROC_SETACL 40 333192152Srmacklem 334192152Srmacklem/* 335192152Srmacklem * Must be defined as one higher than the last Proc# above. 336192152Srmacklem */ 337192152Srmacklem#define NFSV4_NPROCS 41 338244042Srmacklem 339244042Srmacklem/* Additional procedures for NFSv4.1. */ 340244042Srmacklem#define NFSPROC_EXCHANGEID 41 341244042Srmacklem#define NFSPROC_CREATESESSION 42 342244042Srmacklem#define NFSPROC_DESTROYSESSION 43 343244042Srmacklem#define NFSPROC_DESTROYCLIENT 44 344244042Srmacklem#define NFSPROC_FREESTATEID 45 345244042Srmacklem#define NFSPROC_LAYOUTGET 46 346244042Srmacklem#define NFSPROC_GETDEVICEINFO 47 347244042Srmacklem#define NFSPROC_LAYOUTCOMMIT 48 348244042Srmacklem#define NFSPROC_LAYOUTRETURN 49 349244042Srmacklem#define NFSPROC_RECLAIMCOMPL 50 350244042Srmacklem#define NFSPROC_WRITEDS 51 351244042Srmacklem#define NFSPROC_READDS 52 352244042Srmacklem#define NFSPROC_COMMITDS 53 353244042Srmacklem 354244042Srmacklem/* 355244042Srmacklem * Must be defined as one higher than the last NFSv4.1 Proc# above. 356244042Srmacklem */ 357244042Srmacklem#define NFSV41_NPROCS 54 358244042Srmacklem 359223280Srmacklem#endif /* NFS_V3NPROCS */ 360192152Srmacklem 361192152Srmacklem/* 362192152Srmacklem * Stats structure 363192152Srmacklem */ 364192152Srmacklemstruct ext_nfsstats { 365192152Srmacklem int attrcache_hits; 366192152Srmacklem int attrcache_misses; 367192152Srmacklem int lookupcache_hits; 368192152Srmacklem int lookupcache_misses; 369192152Srmacklem int direofcache_hits; 370192152Srmacklem int direofcache_misses; 371192152Srmacklem int accesscache_hits; 372192152Srmacklem int accesscache_misses; 373192152Srmacklem int biocache_reads; 374192152Srmacklem int read_bios; 375192152Srmacklem int read_physios; 376192152Srmacklem int biocache_writes; 377192152Srmacklem int write_bios; 378192152Srmacklem int write_physios; 379192152Srmacklem int biocache_readlinks; 380192152Srmacklem int readlink_bios; 381192152Srmacklem int biocache_readdirs; 382192152Srmacklem int readdir_bios; 383192152Srmacklem int rpccnt[NFSV4_NPROCS]; 384192152Srmacklem int rpcretries; 385192152Srmacklem int srvrpccnt[NFSV4OP_NOPS + NFSV4OP_FAKENOPS]; 386192152Srmacklem int srvrpc_errs; 387192152Srmacklem int srv_errs; 388192152Srmacklem int rpcrequests; 389192152Srmacklem int rpctimeouts; 390192152Srmacklem int rpcunexpected; 391192152Srmacklem int rpcinvalid; 392192152Srmacklem int srvcache_inproghits; 393192152Srmacklem int srvcache_idemdonehits; 394192152Srmacklem int srvcache_nonidemdonehits; 395192152Srmacklem int srvcache_misses; 396192152Srmacklem int srvcache_tcppeak; 397192152Srmacklem int srvcache_size; 398192152Srmacklem int srvclients; 399192152Srmacklem int srvopenowners; 400192152Srmacklem int srvopens; 401192152Srmacklem int srvlockowners; 402192152Srmacklem int srvlocks; 403192152Srmacklem int srvdelegates; 404192152Srmacklem int cbrpccnt[NFSV4OP_CBNOPS]; 405192152Srmacklem int clopenowners; 406192152Srmacklem int clopens; 407192152Srmacklem int cllockowners; 408192152Srmacklem int cllocks; 409192152Srmacklem int cldelegates; 410192152Srmacklem int cllocalopenowners; 411192152Srmacklem int cllocalopens; 412192152Srmacklem int cllocallockowners; 413192152Srmacklem int cllocallocks; 414192152Srmacklem}; 415192152Srmacklem 416192152Srmacklem#ifdef _KERNEL 417192152Srmacklem/* 418192152Srmacklem * Define the ext_nfsstats as nfsstats for the kernel code. 419192152Srmacklem */ 420192152Srmacklem#define nfsstats ext_nfsstats 421192152Srmacklem 422192152Srmacklem/* 423192152Srmacklem * Define NFS_NPROCS as NFSV4_NPROCS for the experimental kernel code. 424192152Srmacklem */ 425223280Srmacklem#ifndef NFS_NPROCS 426192152Srmacklem#define NFS_NPROCS NFSV4_NPROCS 427223280Srmacklem#endif 428192152Srmacklem 429191783Srmacklem#include <fs/nfs/nfskpiport.h> 430191783Srmacklem#include <fs/nfs/nfsdport.h> 431191783Srmacklem#include <fs/nfs/rpcv2.h> 432191783Srmacklem#include <fs/nfs/nfsproto.h> 433191783Srmacklem#include <fs/nfs/nfs.h> 434244042Srmacklem#include <fs/nfs/nfsclstate.h> 435191783Srmacklem#include <fs/nfs/nfs_var.h> 436191783Srmacklem#include <fs/nfs/nfsm_subs.h> 437191783Srmacklem#include <fs/nfs/nfsrvcache.h> 438191783Srmacklem#include <fs/nfs/nfsrvstate.h> 439191783Srmacklem#include <fs/nfs/xdr_subs.h> 440191783Srmacklem#include <fs/nfs/nfscl.h> 441221014Srmacklem#include <nfsclient/nfsargs.h> 442191783Srmacklem#include <fs/nfsclient/nfsmount.h> 443191783Srmacklem 444191783Srmacklem/* 445191783Srmacklem * Just to keep nfs_var.h happy. 446191783Srmacklem */ 447191783Srmacklemstruct nfs_vattr { 448191783Srmacklem int junk; 449191783Srmacklem}; 450191783Srmacklem 451191783Srmacklemstruct nfsvattr { 452191783Srmacklem struct vattr na_vattr; 453191783Srmacklem nfsattrbit_t na_suppattr; 454191783Srmacklem u_int32_t na_mntonfileno; 455191783Srmacklem u_int64_t na_filesid[2]; 456191783Srmacklem}; 457191783Srmacklem 458191783Srmacklem#define na_type na_vattr.va_type 459191783Srmacklem#define na_mode na_vattr.va_mode 460191783Srmacklem#define na_nlink na_vattr.va_nlink 461191783Srmacklem#define na_uid na_vattr.va_uid 462191783Srmacklem#define na_gid na_vattr.va_gid 463191783Srmacklem#define na_fsid na_vattr.va_fsid 464191783Srmacklem#define na_fileid na_vattr.va_fileid 465191783Srmacklem#define na_size na_vattr.va_size 466191783Srmacklem#define na_blocksize na_vattr.va_blocksize 467191783Srmacklem#define na_atime na_vattr.va_atime 468191783Srmacklem#define na_mtime na_vattr.va_mtime 469191783Srmacklem#define na_ctime na_vattr.va_ctime 470191783Srmacklem#define na_gen na_vattr.va_gen 471191783Srmacklem#define na_flags na_vattr.va_flags 472191783Srmacklem#define na_rdev na_vattr.va_rdev 473191783Srmacklem#define na_bytes na_vattr.va_bytes 474191783Srmacklem#define na_filerev na_vattr.va_filerev 475191783Srmacklem#define na_vaflags na_vattr.va_vaflags 476191783Srmacklem 477191783Srmacklem#include <fs/nfsclient/nfsnode.h> 478191783Srmacklem 479191783Srmacklem/* 480191783Srmacklem * This is the header structure used for the lists, etc. (It has the 481191783Srmacklem * above record in it. 482191783Srmacklem */ 483191783Srmacklemstruct nfsrv_stablefirst { 484191783Srmacklem LIST_HEAD(, nfsrv_stable) nsf_head; /* Head of nfsrv_stable list */ 485191783Srmacklem time_t nsf_eograce; /* Time grace period ends */ 486191783Srmacklem time_t *nsf_bootvals; /* Previous boottime values */ 487191783Srmacklem struct file *nsf_fp; /* File table pointer */ 488191783Srmacklem u_char nsf_flags; /* NFSNSF_ flags */ 489191783Srmacklem struct nfsf_rec nsf_rec; /* and above first record */ 490191783Srmacklem}; 491191783Srmacklem#define nsf_lease nsf_rec.lease 492191783Srmacklem#define nsf_numboots nsf_rec.numboots 493191783Srmacklem 494191783Srmacklem/* NFSNSF_xxx flags */ 495191783Srmacklem#define NFSNSF_UPDATEDONE 0x01 496191783Srmacklem#define NFSNSF_GRACEOVER 0x02 497191783Srmacklem#define NFSNSF_NEEDLOCK 0x04 498191783Srmacklem#define NFSNSF_EXPIREDCLIENT 0x08 499191783Srmacklem#define NFSNSF_NOOPENS 0x10 500191783Srmacklem#define NFSNSF_OK 0x20 501191783Srmacklem 502191783Srmacklem/* 503191783Srmacklem * Maximum number of boot times allowed in record. Although there is 504191783Srmacklem * really no need for a fixed upper bound, this serves as a sanity check 505191783Srmacklem * for a corrupted file. 506191783Srmacklem */ 507191783Srmacklem#define NFSNSF_MAXNUMBOOTS 10000 508191783Srmacklem 509191783Srmacklem/* 510191783Srmacklem * This structure defines the other records in the file. The 511191783Srmacklem * nst_client array is actually the size of the client string name. 512191783Srmacklem */ 513191783Srmacklemstruct nfst_rec { 514191783Srmacklem u_int16_t len; 515191783Srmacklem u_char flag; 516191783Srmacklem u_char client[1]; 517191783Srmacklem}; 518191783Srmacklem/* and the values for flag */ 519191783Srmacklem#define NFSNST_NEWSTATE 0x1 520191783Srmacklem#define NFSNST_REVOKE 0x2 521191783Srmacklem#define NFSNST_GOTSTATE 0x4 522191783Srmacklem 523191783Srmacklem/* 524191783Srmacklem * This structure is linked onto nfsrv_stablefirst for the duration of 525191783Srmacklem * reclaim. 526191783Srmacklem */ 527191783Srmacklemstruct nfsrv_stable { 528191783Srmacklem LIST_ENTRY(nfsrv_stable) nst_list; 529191783Srmacklem struct nfsclient *nst_clp; 530191783Srmacklem struct nfst_rec nst_rec; 531191783Srmacklem}; 532191783Srmacklem#define nst_timestamp nst_rec.timestamp 533191783Srmacklem#define nst_len nst_rec.len 534191783Srmacklem#define nst_flag nst_rec.flag 535191783Srmacklem#define nst_client nst_rec.client 536191783Srmacklem 537191783Srmacklem/* 538191783Srmacklem * At some point the server will run out of kernel storage for 539191783Srmacklem * state structures. For FreeBSD5.2, this results in a panic 540191783Srmacklem * kmem_map is full. It happens at well over 1000000 opens plus 541191783Srmacklem * locks on a PIII-800 with 256Mbytes, so that is where I've set 542191783Srmacklem * the limit. If your server panics due to too many opens/locks, 543191783Srmacklem * decrease the size of NFSRV_V4STATELIMIT. If you find the server 544191783Srmacklem * returning NFS4ERR_RESOURCE a lot and have lots of memory, try 545191783Srmacklem * increasing it. 546191783Srmacklem */ 547191783Srmacklem#define NFSRV_V4STATELIMIT 500000 /* Max # of Opens + Locks */ 548191783Srmacklem 549191783Srmacklem/* 550191783Srmacklem * The type required differs with BSDen (just the second arg). 551191783Srmacklem */ 552191783Srmacklemvoid nfsrvd_rcv(struct socket *, void *, int); 553191783Srmacklem 554191783Srmacklem/* 555191783Srmacklem * Macros for handling socket addresses. (Hopefully this makes the code 556191783Srmacklem * more portable, since I've noticed some 'BSD don't have sockaddrs in 557191783Srmacklem * mbufs any more.) 558191783Srmacklem */ 559191783Srmacklem#define NFSSOCKADDR(a, t) ((t)(a)) 560191783Srmacklem#define NFSSOCKADDRALLOC(a) \ 561191783Srmacklem do { \ 562191783Srmacklem MALLOC((a), struct sockaddr *, sizeof (struct sockaddr), \ 563191783Srmacklem M_SONAME, M_WAITOK); \ 564191783Srmacklem NFSBZERO((a), sizeof (struct sockaddr)); \ 565191783Srmacklem } while (0) 566191783Srmacklem#define NFSSOCKADDRSIZE(a, s) ((a)->sa_len = (s)) 567191783Srmacklem#define NFSSOCKADDRFREE(a) \ 568191783Srmacklem do { \ 569191783Srmacklem if (a) \ 570191783Srmacklem FREE((caddr_t)(a), M_SONAME); \ 571191783Srmacklem } while (0) 572191783Srmacklem 573191783Srmacklem/* 574191783Srmacklem * These should be defined as a process or thread structure, as required 575191783Srmacklem * for signal handling, etc. 576191783Srmacklem */ 577191783Srmacklem#define NFSNEWCRED(c) (crdup(c)) 578191783Srmacklem#define NFSPROCCRED(p) ((p)->td_ucred) 579191783Srmacklem#define NFSFREECRED(c) (crfree(c)) 580191783Srmacklem#define NFSUIOPROC(u, p) ((u)->uio_td = NULL) 581191783Srmacklem#define NFSPROCP(p) ((p)->td_proc) 582191783Srmacklem 583191783Srmacklem/* 584191783Srmacklem * Define these so that cn_hash and its length is ignored. 585191783Srmacklem */ 586191783Srmacklem#define NFSCNHASHZERO(c) 587191783Srmacklem#define NFSCNHASH(c, v) 588191783Srmacklem#define NCHNAMLEN 9999999 589191783Srmacklem 590191783Srmacklem/* 591191783Srmacklem * These macros are defined to initialize and set the timer routine. 592191783Srmacklem */ 593191783Srmacklem#define NFS_TIMERINIT \ 594191783Srmacklem newnfs_timer(NULL) 595191783Srmacklem 596191783Srmacklem/* 597191783Srmacklem * Handle SMP stuff: 598191783Srmacklem */ 599191783Srmacklem#define NFSSTATESPINLOCK extern struct mtx nfs_state_mutex 600191783Srmacklem#define NFSLOCKSTATE() mtx_lock(&nfs_state_mutex) 601191783Srmacklem#define NFSUNLOCKSTATE() mtx_unlock(&nfs_state_mutex) 602205941Srmacklem#define NFSSTATEMUTEXPTR (&nfs_state_mutex) 603191783Srmacklem#define NFSREQSPINLOCK extern struct mtx nfs_req_mutex 604191783Srmacklem#define NFSLOCKREQ() mtx_lock(&nfs_req_mutex) 605191783Srmacklem#define NFSUNLOCKREQ() mtx_unlock(&nfs_req_mutex) 606191783Srmacklem#define NFSSOCKMUTEX extern struct mtx nfs_slock_mutex 607191783Srmacklem#define NFSSOCKMUTEXPTR (&nfs_slock_mutex) 608191783Srmacklem#define NFSLOCKSOCK() mtx_lock(&nfs_slock_mutex) 609191783Srmacklem#define NFSUNLOCKSOCK() mtx_unlock(&nfs_slock_mutex) 610191783Srmacklem#define NFSNAMEIDMUTEX extern struct mtx nfs_nameid_mutex 611191783Srmacklem#define NFSLOCKNAMEID() mtx_lock(&nfs_nameid_mutex) 612191783Srmacklem#define NFSUNLOCKNAMEID() mtx_unlock(&nfs_nameid_mutex) 613191783Srmacklem#define NFSNAMEIDREQUIRED() mtx_assert(&nfs_nameid_mutex, MA_OWNED) 614191783Srmacklem#define NFSCLSTATEMUTEX extern struct mtx nfs_clstate_mutex 615191783Srmacklem#define NFSCLSTATEMUTEXPTR (&nfs_clstate_mutex) 616191783Srmacklem#define NFSLOCKCLSTATE() mtx_lock(&nfs_clstate_mutex) 617191783Srmacklem#define NFSUNLOCKCLSTATE() mtx_unlock(&nfs_clstate_mutex) 618191783Srmacklem#define NFSDLOCKMUTEX extern struct mtx newnfsd_mtx 619191783Srmacklem#define NFSDLOCKMUTEXPTR (&newnfsd_mtx) 620191783Srmacklem#define NFSD_LOCK() mtx_lock(&newnfsd_mtx) 621191783Srmacklem#define NFSD_UNLOCK() mtx_unlock(&newnfsd_mtx) 622191783Srmacklem#define NFSD_LOCK_ASSERT() mtx_assert(&newnfsd_mtx, MA_OWNED) 623191783Srmacklem#define NFSD_UNLOCK_ASSERT() mtx_assert(&newnfsd_mtx, MA_NOTOWNED) 624191783Srmacklem#define NFSV4ROOTLOCKMUTEX extern struct mtx nfs_v4root_mutex 625191783Srmacklem#define NFSV4ROOTLOCKMUTEXPTR (&nfs_v4root_mutex) 626191783Srmacklem#define NFSLOCKV4ROOTMUTEX() mtx_lock(&nfs_v4root_mutex) 627191783Srmacklem#define NFSUNLOCKV4ROOTMUTEX() mtx_unlock(&nfs_v4root_mutex) 628191783Srmacklem#define NFSLOCKNODE(n) mtx_lock(&((n)->n_mtx)) 629191783Srmacklem#define NFSUNLOCKNODE(n) mtx_unlock(&((n)->n_mtx)) 630191783Srmacklem#define NFSLOCKMNT(m) mtx_lock(&((m)->nm_mtx)) 631191783Srmacklem#define NFSUNLOCKMNT(m) mtx_unlock(&((m)->nm_mtx)) 632191783Srmacklem#define NFSLOCKREQUEST(r) mtx_lock(&((r)->r_mtx)) 633191783Srmacklem#define NFSUNLOCKREQUEST(r) mtx_unlock(&((r)->r_mtx)) 634191783Srmacklem#define NFSPROCLISTLOCK() sx_slock(&allproc_lock) 635191783Srmacklem#define NFSPROCLISTUNLOCK() sx_sunlock(&allproc_lock) 636191783Srmacklem#define NFSLOCKSOCKREQ(r) mtx_lock(&((r)->nr_mtx)) 637191783Srmacklem#define NFSUNLOCKSOCKREQ(r) mtx_unlock(&((r)->nr_mtx)) 638244042Srmacklem#define NFSLOCKDS(d) mtx_lock(&((d)->nfsclds_mtx)) 639244042Srmacklem#define NFSUNLOCKDS(d) mtx_unlock(&((d)->nfsclds_mtx)) 640269398Srmacklem#define NFSSESSIONMUTEXPTR(s) (&((s)->mtx)) 641269398Srmacklem#define NFSLOCKSESSION(s) mtx_lock(&((s)->mtx)) 642269398Srmacklem#define NFSUNLOCKSESSION(s) mtx_unlock(&((s)->mtx)) 643191783Srmacklem 644191783Srmacklem/* 645191783Srmacklem * Use these macros to initialize/free a mutex. 646191783Srmacklem */ 647191783Srmacklem#define NFSINITSOCKMUTEX(m) mtx_init((m), "nfssock", NULL, MTX_DEF) 648191783Srmacklem#define NFSFREEMUTEX(m) mtx_destroy((m)) 649191783Srmacklem 650191783Srmacklemint nfsmsleep(void *, void *, int, const char *, struct timespec *); 651191783Srmacklem 652191783Srmacklem/* 653191783Srmacklem * And weird vm stuff in the nfs server. 654191783Srmacklem */ 655191783Srmacklem#define PDIRUNLOCK 0x0 656191783Srmacklem#define MAX_COMMIT_COUNT (1024 * 1024) 657191783Srmacklem 658191783Srmacklem/* 659191783Srmacklem * Define these to handle the type of va_rdev. 660191783Srmacklem */ 661191783Srmacklem#define NFSMAKEDEV(m, n) makedev((m), (n)) 662191783Srmacklem#define NFSMAJOR(d) major(d) 663191783Srmacklem#define NFSMINOR(d) minor(d) 664191783Srmacklem 665191783Srmacklem/* 666191783Srmacklem * Define this to be the macro that returns the minimum size required 667191783Srmacklem * for a directory entry. 668191783Srmacklem */ 669191783Srmacklem#define DIRENT_SIZE(dp) GENERIC_DIRSIZ(dp) 670191783Srmacklem 671191783Srmacklem/* 672191783Srmacklem * The vnode tag for nfsv4root. 673191783Srmacklem */ 674191783Srmacklem#define VT_NFSV4ROOT "nfsv4root" 675191783Srmacklem 676191783Srmacklem/* 677191783Srmacklem * Define whatever it takes to do a vn_rdwr(). 678191783Srmacklem */ 679191783Srmacklem#define NFSD_RDWR(r, v, b, l, o, s, i, c, a, p) \ 680194292Srmacklem vn_rdwr((r), (v), (b), (l), (o), (s), (i), (c), NULL, (a), (p)) 681191783Srmacklem 682191783Srmacklem/* 683191783Srmacklem * Macros for handling memory for different BSDen. 684191783Srmacklem * NFSBCOPY(src, dst, len) - copies len bytes, non-overlapping 685191783Srmacklem * NFSOVBCOPY(src, dst, len) - ditto, but data areas might overlap 686191783Srmacklem * NFSBCMP(cp1, cp2, len) - compare len bytes, return 0 if same 687191783Srmacklem * NFSBZERO(cp, len) - set len bytes to 0x0 688191783Srmacklem */ 689191783Srmacklem#define NFSBCOPY(s, d, l) bcopy((s), (d), (l)) 690191783Srmacklem#define NFSOVBCOPY(s, d, l) ovbcopy((s), (d), (l)) 691191783Srmacklem#define NFSBCMP(s, d, l) bcmp((s), (d), (l)) 692191783Srmacklem#define NFSBZERO(s, l) bzero((s), (l)) 693191783Srmacklem 694191783Srmacklem/* 695191783Srmacklem * Some queue.h files don't have these dfined in them. 696191783Srmacklem */ 697191783Srmacklem#define LIST_END(head) NULL 698191783Srmacklem#define SLIST_END(head) NULL 699191783Srmacklem#define TAILQ_END(head) NULL 700191783Srmacklem 701191783Srmacklem/* 702217922Sgnn * This must be defined to be a global variable that increments once 703191783Srmacklem * per second, but never stops or goes backwards, even when a "date" 704217922Sgnn * command changes the TOD clock. It is used for delta times for 705191783Srmacklem * leases, etc. 706191783Srmacklem */ 707191783Srmacklem#define NFSD_MONOSEC time_uptime 708191783Srmacklem 709191783Srmacklem/* 710191783Srmacklem * Declare the malloc types. 711191783Srmacklem */ 712191783SrmacklemMALLOC_DECLARE(M_NEWNFSRVCACHE); 713191783SrmacklemMALLOC_DECLARE(M_NEWNFSDCLIENT); 714191783SrmacklemMALLOC_DECLARE(M_NEWNFSDSTATE); 715191783SrmacklemMALLOC_DECLARE(M_NEWNFSDLOCK); 716191783SrmacklemMALLOC_DECLARE(M_NEWNFSDLOCKFILE); 717191783SrmacklemMALLOC_DECLARE(M_NEWNFSSTRING); 718191783SrmacklemMALLOC_DECLARE(M_NEWNFSUSERGROUP); 719191783SrmacklemMALLOC_DECLARE(M_NEWNFSDREQ); 720191783SrmacklemMALLOC_DECLARE(M_NEWNFSFH); 721191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLOWNER); 722191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLOPEN); 723191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLDELEG); 724191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLCLIENT); 725191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLLOCKOWNER); 726191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLLOCK); 727191783SrmacklemMALLOC_DECLARE(M_NEWNFSDIROFF); 728191783SrmacklemMALLOC_DECLARE(M_NEWNFSV4NODE); 729191783SrmacklemMALLOC_DECLARE(M_NEWNFSDIRECTIO); 730191783SrmacklemMALLOC_DECLARE(M_NEWNFSMNT); 731205941SrmacklemMALLOC_DECLARE(M_NEWNFSDROLLBACK); 732244042SrmacklemMALLOC_DECLARE(M_NEWNFSLAYOUT); 733244042SrmacklemMALLOC_DECLARE(M_NEWNFSFLAYOUT); 734244042SrmacklemMALLOC_DECLARE(M_NEWNFSDEVINFO); 735244042SrmacklemMALLOC_DECLARE(M_NEWNFSSOCKREQ); 736244042SrmacklemMALLOC_DECLARE(M_NEWNFSCLDS); 737244042SrmacklemMALLOC_DECLARE(M_NEWNFSLAYRECALL); 738269398SrmacklemMALLOC_DECLARE(M_NEWNFSDSESSION); 739191783Srmacklem#define M_NFSRVCACHE M_NEWNFSRVCACHE 740191783Srmacklem#define M_NFSDCLIENT M_NEWNFSDCLIENT 741191783Srmacklem#define M_NFSDSTATE M_NEWNFSDSTATE 742191783Srmacklem#define M_NFSDLOCK M_NEWNFSDLOCK 743191783Srmacklem#define M_NFSDLOCKFILE M_NEWNFSDLOCKFILE 744191783Srmacklem#define M_NFSSTRING M_NEWNFSSTRING 745191783Srmacklem#define M_NFSUSERGROUP M_NEWNFSUSERGROUP 746191783Srmacklem#define M_NFSDREQ M_NEWNFSDREQ 747191783Srmacklem#define M_NFSFH M_NEWNFSFH 748191783Srmacklem#define M_NFSCLOWNER M_NEWNFSCLOWNER 749191783Srmacklem#define M_NFSCLOPEN M_NEWNFSCLOPEN 750191783Srmacklem#define M_NFSCLDELEG M_NEWNFSCLDELEG 751191783Srmacklem#define M_NFSCLCLIENT M_NEWNFSCLCLIENT 752191783Srmacklem#define M_NFSCLLOCKOWNER M_NEWNFSCLLOCKOWNER 753191783Srmacklem#define M_NFSCLLOCK M_NEWNFSCLLOCK 754191783Srmacklem#define M_NFSDIROFF M_NEWNFSDIROFF 755191783Srmacklem#define M_NFSV4NODE M_NEWNFSV4NODE 756191783Srmacklem#define M_NFSDIRECTIO M_NEWNFSDIRECTIO 757205941Srmacklem#define M_NFSDROLLBACK M_NEWNFSDROLLBACK 758244042Srmacklem#define M_NFSLAYOUT M_NEWNFSLAYOUT 759244042Srmacklem#define M_NFSFLAYOUT M_NEWNFSFLAYOUT 760244042Srmacklem#define M_NFSDEVINFO M_NEWNFSDEVINFO 761244042Srmacklem#define M_NFSSOCKREQ M_NEWNFSSOCKREQ 762244042Srmacklem#define M_NFSCLDS M_NEWNFSCLDS 763244042Srmacklem#define M_NFSLAYRECALL M_NEWNFSLAYRECALL 764269398Srmacklem#define M_NFSDSESSION M_NEWNFSDSESSION 765191783Srmacklem 766191783Srmacklem#define NFSINT_SIGMASK(set) \ 767191783Srmacklem (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \ 768191783Srmacklem SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \ 769191783Srmacklem SIGISMEMBER(set, SIGQUIT)) 770191783Srmacklem 771191783Srmacklem/* 772191783Srmacklem * Convert a quota block count to byte count. 773191783Srmacklem */ 774191783Srmacklem#define NFSQUOTABLKTOBYTE(q, b) (q) *= (b) 775191783Srmacklem 776191783Srmacklem/* 777191783Srmacklem * Define this as the largest file size supported. (It should probably 778191783Srmacklem * be available via a VFS_xxx Op, but it isn't. 779191783Srmacklem */ 780191783Srmacklem#define NFSRV_MAXFILESIZE ((u_int64_t)0x800000000000) 781191783Srmacklem 782191783Srmacklem/* 783191783Srmacklem * Set this macro to index() or strchr(), whichever is supported. 784191783Srmacklem */ 785229272Sed#define STRCHR(s, c) strchr((s), (c)) 786191783Srmacklem 787191783Srmacklem/* 788191783Srmacklem * Set the n_time in the client write rpc, as required. 789191783Srmacklem */ 790191783Srmacklem#define NFSWRITERPC_SETTIME(w, n, v4) \ 791191783Srmacklem do { \ 792191783Srmacklem if (w) { \ 793191783Srmacklem (n)->n_mtime = (n)->n_vattr.na_vattr.va_mtime; \ 794191783Srmacklem if (v4) \ 795191783Srmacklem (n)->n_change = (n)->n_vattr.na_vattr.va_filerev; \ 796191783Srmacklem } \ 797191783Srmacklem } while (0) 798191783Srmacklem 799191783Srmacklem/* 800191783Srmacklem * Fake value, just to make the client work. 801191783Srmacklem */ 802191783Srmacklem#define NFS_LATTR_NOSHRINK 1 803191783Srmacklem 804191783Srmacklem/* 805191783Srmacklem * Prototypes for functions where the arguments vary for different ports. 806191783Srmacklem */ 807191783Srmacklemint nfscl_loadattrcache(struct vnode **, struct nfsvattr *, void *, void *, 808191783Srmacklem int, int); 809249592Skenint newnfs_realign(struct mbuf **, int); 810191783Srmacklem 811191783Srmacklem/* 812191783Srmacklem * If the port runs on an SMP box that can enforce Atomic ops with low 813191783Srmacklem * overheads, define these as atomic increments/decrements. If not, 814191783Srmacklem * don't worry about it, since these are used for stats that can be 815191783Srmacklem * "out by one" without disastrous consequences. 816191783Srmacklem */ 817191783Srmacklem#define NFSINCRGLOBAL(a) ((a)++) 818191783Srmacklem 819191783Srmacklem/* 820191783Srmacklem * Assorted funky stuff to make things work under Darwin8. 821191783Srmacklem */ 822191783Srmacklem/* 823191783Srmacklem * These macros checks for a field in vattr being set. 824191783Srmacklem */ 825191783Srmacklem#define NFSATTRISSET(t, v, a) ((v)->a != (t)VNOVAL) 826191783Srmacklem#define NFSATTRISSETTIME(v, a) ((v)->a.tv_sec != VNOVAL) 827191783Srmacklem 828191783Srmacklem/* 829191783Srmacklem * Manipulate mount flags. 830191783Srmacklem */ 831191783Srmacklem#define NFSSTA_HASWRITEVERF 0x00040000 /* Has write verifier */ 832191783Srmacklem#define NFSSTA_GOTFSINFO 0x00100000 /* Got the fsinfo */ 833244042Srmacklem#define NFSSTA_NOLAYOUTCOMMIT 0x04000000 /* Don't do LayoutCommit */ 834244042Srmacklem#define NFSSTA_SESSPERSIST 0x08000000 /* Has a persistent session */ 835191783Srmacklem#define NFSSTA_TIMEO 0x10000000 /* Experiencing a timeout */ 836191783Srmacklem#define NFSSTA_LOCKTIMEO 0x20000000 /* Experiencing a lockd timeout */ 837191783Srmacklem#define NFSSTA_HASSETFSID 0x40000000 /* Has set the fsid */ 838244042Srmacklem#define NFSSTA_PNFS 0x80000000 /* pNFS is enabled */ 839191783Srmacklem 840191783Srmacklem#define NFSHASNFSV3(n) ((n)->nm_flag & NFSMNT_NFSV3) 841191783Srmacklem#define NFSHASNFSV4(n) ((n)->nm_flag & NFSMNT_NFSV4) 842244042Srmacklem#define NFSHASNFSV4N(n) ((n)->nm_minorvers > 0) 843191783Srmacklem#define NFSHASNFSV3OR4(n) ((n)->nm_flag & (NFSMNT_NFSV3 | NFSMNT_NFSV4)) 844191783Srmacklem#define NFSHASGOTFSINFO(n) ((n)->nm_state & NFSSTA_GOTFSINFO) 845191783Srmacklem#define NFSHASHASSETFSID(n) ((n)->nm_state & NFSSTA_HASSETFSID) 846191783Srmacklem#define NFSHASSTRICT3530(n) ((n)->nm_flag & NFSMNT_STRICT3530) 847191783Srmacklem#define NFSHASWRITEVERF(n) ((n)->nm_state & NFSSTA_HASWRITEVERF) 848191783Srmacklem#define NFSHASINT(n) ((n)->nm_flag & NFSMNT_INT) 849191783Srmacklem#define NFSHASSOFT(n) ((n)->nm_flag & NFSMNT_SOFT) 850191783Srmacklem#define NFSHASINTORSOFT(n) ((n)->nm_flag & (NFSMNT_INT | NFSMNT_SOFT)) 851191783Srmacklem#define NFSHASDUMBTIMR(n) ((n)->nm_flag & NFSMNT_DUMBTIMR) 852191783Srmacklem#define NFSHASNOCONN(n) ((n)->nm_flag & NFSMNT_MNTD) 853191783Srmacklem#define NFSHASKERB(n) ((n)->nm_flag & NFSMNT_KERB) 854191783Srmacklem#define NFSHASALLGSSNAME(n) ((n)->nm_flag & NFSMNT_ALLGSSNAME) 855191783Srmacklem#define NFSHASINTEGRITY(n) ((n)->nm_flag & NFSMNT_INTEGRITY) 856191783Srmacklem#define NFSHASPRIVACY(n) ((n)->nm_flag & NFSMNT_PRIVACY) 857191783Srmacklem#define NFSSETWRITEVERF(n) ((n)->nm_state |= NFSSTA_HASWRITEVERF) 858191783Srmacklem#define NFSSETHASSETFSID(n) ((n)->nm_state |= NFSSTA_HASSETFSID) 859244042Srmacklem#define NFSHASPNFSOPT(n) ((n)->nm_flag & NFSMNT_PNFS) 860244042Srmacklem#define NFSHASNOLAYOUTCOMMIT(n) ((n)->nm_state & NFSSTA_NOLAYOUTCOMMIT) 861244042Srmacklem#define NFSHASSESSPERSIST(n) ((n)->nm_state & NFSSTA_SESSPERSIST) 862244042Srmacklem#define NFSHASPNFS(n) ((n)->nm_state & NFSSTA_PNFS) 863191783Srmacklem 864191783Srmacklem/* 865191783Srmacklem * Gets the stats field out of the mount structure. 866191783Srmacklem */ 867191783Srmacklem#define vfs_statfs(m) (&((m)->mnt_stat)) 868191783Srmacklem 869191783Srmacklem/* 870191783Srmacklem * Set boottime. 871191783Srmacklem */ 872191783Srmacklem#define NFSSETBOOTTIME(b) ((b) = boottime) 873191783Srmacklem 874191783Srmacklem/* 875191783Srmacklem * The size of directory blocks in the buffer cache. 876191783Srmacklem * MUST BE in the range of PAGE_SIZE <= NFS_DIRBLKSIZ <= MAXBSIZE!! 877191783Srmacklem */ 878191783Srmacklem#define NFS_DIRBLKSIZ (16 * DIRBLKSIZ) /* Must be a multiple of DIRBLKSIZ */ 879191783Srmacklem 880191783Srmacklem/* 881191783Srmacklem * Define these macros to access mnt_flag fields. 882191783Srmacklem */ 883191783Srmacklem#define NFSMNT_RDONLY(m) ((m)->mnt_flag & MNT_RDONLY) 884191783Srmacklem#endif /* _KERNEL */ 885191783Srmacklem 886191783Srmacklem/* 887191783Srmacklem * Define a structure similar to ufs_args for use in exporting the V4 root. 888191783Srmacklem */ 889191783Srmacklemstruct nfsex_args { 890191783Srmacklem char *fspec; 891191783Srmacklem struct export_args export; 892191783Srmacklem}; 893191783Srmacklem 894191783Srmacklem/* 895191783Srmacklem * These export flags should be defined, but there are no bits left. 896191783Srmacklem * Maybe a separate mnt_exflag field could be added or the mnt_flag 897191783Srmacklem * field increased to 64 bits? 898191783Srmacklem */ 899191783Srmacklem#ifndef MNT_EXSTRICTACCESS 900191783Srmacklem#define MNT_EXSTRICTACCESS 0x0 901191783Srmacklem#endif 902191783Srmacklem#ifndef MNT_EXV4ONLY 903191783Srmacklem#define MNT_EXV4ONLY 0x0 904191783Srmacklem#endif 905191783Srmacklem 906191783Srmacklem#ifdef _KERNEL 907191783Srmacklem/* 908191783Srmacklem * Define this to invalidate the attribute cache for the nfs node. 909191783Srmacklem */ 910191783Srmacklem#define NFSINVALATTRCACHE(n) ((n)->n_attrstamp = 0) 911191783Srmacklem 912191783Srmacklem/* Used for FreeBSD only */ 913191783Srmacklemvoid nfsd_mntinit(void); 914191783Srmacklem 915191783Srmacklem/* 916191783Srmacklem * Define these for vnode lock/unlock ops. 917224080Szack * 918224080Szack * These are good abstractions to macro out, so that they can be added to 919224080Szack * later, for debugging or stats, etc. 920191783Srmacklem */ 921224080Szack#define NFSVOPLOCK(v, f) vn_lock((v), (f)) 922224080Szack#define NFSVOPUNLOCK(v, f) VOP_UNLOCK((v), (f)) 923224080Szack#define NFSVOPISLOCKED(v) VOP_ISLOCKED((v)) 924191783Srmacklem 925191783Srmacklem/* 926191783Srmacklem * Define ncl_hash(). 927191783Srmacklem */ 928191783Srmacklem#define ncl_hash(f, l) (fnv_32_buf((f), (l), FNV1_32_INIT)) 929191783Srmacklem 930191783Srmacklemint newnfs_iosize(struct nfsmount *); 931191783Srmacklem 932191783Srmacklem#ifdef NFS_DEBUG 933191783Srmacklem 934191783Srmacklemextern int nfs_debug; 935191783Srmacklem#define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */ 936191783Srmacklem#define NFS_DEBUG_WG 2 /* server write gathering */ 937191783Srmacklem#define NFS_DEBUG_RC 4 /* server request caching */ 938191783Srmacklem 939191783Srmacklem#define NFS_DPF(cat, args) \ 940191783Srmacklem do { \ 941191783Srmacklem if (nfs_debug & NFS_DEBUG_##cat) printf args; \ 942191783Srmacklem } while (0) 943191783Srmacklem 944191783Srmacklem#else 945191783Srmacklem 946191783Srmacklem#define NFS_DPF(cat, args) 947191783Srmacklem 948191783Srmacklem#endif 949191783Srmacklem 950191783Srmacklemint newnfs_vncmpf(struct vnode *, void *); 951191783Srmacklem 952191783Srmacklem#ifndef NFS_MINDIRATTRTIMO 953191783Srmacklem#define NFS_MINDIRATTRTIMO 3 /* VDIR attrib cache timeout in sec */ 954191783Srmacklem#endif 955191783Srmacklem#ifndef NFS_MAXDIRATTRTIMO 956191783Srmacklem#define NFS_MAXDIRATTRTIMO 60 957191783Srmacklem#endif 958191783Srmacklem 959191783Srmacklem/* 960191783Srmacklem * Nfs outstanding request list element 961191783Srmacklem */ 962191783Srmacklemstruct nfsreq { 963191783Srmacklem TAILQ_ENTRY(nfsreq) r_chain; 964191783Srmacklem u_int32_t r_flags; /* flags on request, see below */ 965191783Srmacklem struct nfsmount *r_nmp; /* Client mnt ptr */ 966191783Srmacklem struct mtx r_mtx; /* Mutex lock for this structure */ 967191783Srmacklem}; 968191783Srmacklem 969191783Srmacklem#ifndef NFS_MAXBSIZE 970191783Srmacklem#define NFS_MAXBSIZE MAXBSIZE 971191783Srmacklem#endif 972191783Srmacklem 973191783Srmacklem/* 974191783Srmacklem * This macro checks to see if issuing of delegations is allowed for this 975191783Srmacklem * vnode. 976191783Srmacklem */ 977191783Srmacklem#ifdef VV_DISABLEDELEG 978191783Srmacklem#define NFSVNO_DELEGOK(v) \ 979191783Srmacklem ((v) == NULL || ((v)->v_vflag & VV_DISABLEDELEG) == 0) 980191783Srmacklem#else 981191783Srmacklem#define NFSVNO_DELEGOK(v) (1) 982191783Srmacklem#endif 983191783Srmacklem 984191783Srmacklem#endif /* _KERNEL */ 985191783Srmacklem 986207785Srmacklem#endif /* _NFS_NFSPORT_H */ 987