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: stable/10/sys/fs/nfs/nfsport.h 336422 2018-07-17 19:26:17Z rmacklem $ 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/* 263306663Srmacklem * Fake NFSV4OP_xxx used for nfsstat. Start at NFSV4OP_NOPS. 264192152Srmacklem */ 265306663Srmacklem#define NFSV4OP_SYMLINK (NFSV4OP_NOPS) 266306663Srmacklem#define NFSV4OP_MKDIR (NFSV4OP_NOPS + 1) 267306663Srmacklem#define NFSV4OP_RMDIR (NFSV4OP_NOPS + 2) 268306663Srmacklem#define NFSV4OP_READDIRPLUS (NFSV4OP_NOPS + 3) 269306663Srmacklem#define NFSV4OP_MKNOD (NFSV4OP_NOPS + 4) 270306663Srmacklem#define NFSV4OP_FSSTAT (NFSV4OP_NOPS + 5) 271306663Srmacklem#define NFSV4OP_FSINFO (NFSV4OP_NOPS + 6) 272306663Srmacklem#define NFSV4OP_PATHCONF (NFSV4OP_NOPS + 7) 273306663Srmacklem#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/* 287306663Srmacklem * Must be one greater than the last Callback Operation#. 288192152Srmacklem */ 289192152Srmacklem#define NFSV4OP_CBNOPS 5 290192152Srmacklem 291192152Srmacklem/* 292306663Srmacklem * 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/* 362306663Srmacklem * 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/* 418306663Srmacklem * Define the ext_nfsstats as nfsstats for the kernel code. 419306663Srmacklem */ 420306663Srmacklem#define nfsstats ext_nfsstats 421306663Srmacklem 422306663Srmacklem/* 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 522336422Srmacklem#define NFSNST_RECLAIMED 0x8 523191783Srmacklem 524191783Srmacklem/* 525191783Srmacklem * This structure is linked onto nfsrv_stablefirst for the duration of 526191783Srmacklem * reclaim. 527191783Srmacklem */ 528191783Srmacklemstruct nfsrv_stable { 529191783Srmacklem LIST_ENTRY(nfsrv_stable) nst_list; 530191783Srmacklem struct nfsclient *nst_clp; 531191783Srmacklem struct nfst_rec nst_rec; 532191783Srmacklem}; 533191783Srmacklem#define nst_timestamp nst_rec.timestamp 534191783Srmacklem#define nst_len nst_rec.len 535191783Srmacklem#define nst_flag nst_rec.flag 536191783Srmacklem#define nst_client nst_rec.client 537191783Srmacklem 538191783Srmacklem/* 539191783Srmacklem * At some point the server will run out of kernel storage for 540191783Srmacklem * state structures. For FreeBSD5.2, this results in a panic 541191783Srmacklem * kmem_map is full. It happens at well over 1000000 opens plus 542191783Srmacklem * locks on a PIII-800 with 256Mbytes, so that is where I've set 543191783Srmacklem * the limit. If your server panics due to too many opens/locks, 544191783Srmacklem * decrease the size of NFSRV_V4STATELIMIT. If you find the server 545191783Srmacklem * returning NFS4ERR_RESOURCE a lot and have lots of memory, try 546191783Srmacklem * increasing it. 547191783Srmacklem */ 548191783Srmacklem#define NFSRV_V4STATELIMIT 500000 /* Max # of Opens + Locks */ 549191783Srmacklem 550191783Srmacklem/* 551191783Srmacklem * The type required differs with BSDen (just the second arg). 552191783Srmacklem */ 553191783Srmacklemvoid nfsrvd_rcv(struct socket *, void *, int); 554191783Srmacklem 555191783Srmacklem/* 556191783Srmacklem * Macros for handling socket addresses. (Hopefully this makes the code 557191783Srmacklem * more portable, since I've noticed some 'BSD don't have sockaddrs in 558191783Srmacklem * mbufs any more.) 559191783Srmacklem */ 560191783Srmacklem#define NFSSOCKADDR(a, t) ((t)(a)) 561191783Srmacklem#define NFSSOCKADDRALLOC(a) \ 562191783Srmacklem do { \ 563191783Srmacklem MALLOC((a), struct sockaddr *, sizeof (struct sockaddr), \ 564191783Srmacklem M_SONAME, M_WAITOK); \ 565191783Srmacklem NFSBZERO((a), sizeof (struct sockaddr)); \ 566191783Srmacklem } while (0) 567191783Srmacklem#define NFSSOCKADDRSIZE(a, s) ((a)->sa_len = (s)) 568191783Srmacklem#define NFSSOCKADDRFREE(a) \ 569191783Srmacklem do { \ 570191783Srmacklem if (a) \ 571191783Srmacklem FREE((caddr_t)(a), M_SONAME); \ 572191783Srmacklem } while (0) 573191783Srmacklem 574191783Srmacklem/* 575191783Srmacklem * These should be defined as a process or thread structure, as required 576191783Srmacklem * for signal handling, etc. 577191783Srmacklem */ 578191783Srmacklem#define NFSNEWCRED(c) (crdup(c)) 579191783Srmacklem#define NFSPROCCRED(p) ((p)->td_ucred) 580191783Srmacklem#define NFSFREECRED(c) (crfree(c)) 581191783Srmacklem#define NFSUIOPROC(u, p) ((u)->uio_td = NULL) 582191783Srmacklem#define NFSPROCP(p) ((p)->td_proc) 583191783Srmacklem 584191783Srmacklem/* 585191783Srmacklem * Define these so that cn_hash and its length is ignored. 586191783Srmacklem */ 587191783Srmacklem#define NFSCNHASHZERO(c) 588191783Srmacklem#define NFSCNHASH(c, v) 589191783Srmacklem#define NCHNAMLEN 9999999 590191783Srmacklem 591191783Srmacklem/* 592191783Srmacklem * These macros are defined to initialize and set the timer routine. 593191783Srmacklem */ 594191783Srmacklem#define NFS_TIMERINIT \ 595191783Srmacklem newnfs_timer(NULL) 596191783Srmacklem 597191783Srmacklem/* 598191783Srmacklem * Handle SMP stuff: 599191783Srmacklem */ 600191783Srmacklem#define NFSSTATESPINLOCK extern struct mtx nfs_state_mutex 601191783Srmacklem#define NFSLOCKSTATE() mtx_lock(&nfs_state_mutex) 602191783Srmacklem#define NFSUNLOCKSTATE() mtx_unlock(&nfs_state_mutex) 603205941Srmacklem#define NFSSTATEMUTEXPTR (&nfs_state_mutex) 604191783Srmacklem#define NFSREQSPINLOCK extern struct mtx nfs_req_mutex 605191783Srmacklem#define NFSLOCKREQ() mtx_lock(&nfs_req_mutex) 606191783Srmacklem#define NFSUNLOCKREQ() mtx_unlock(&nfs_req_mutex) 607191783Srmacklem#define NFSSOCKMUTEX extern struct mtx nfs_slock_mutex 608191783Srmacklem#define NFSSOCKMUTEXPTR (&nfs_slock_mutex) 609191783Srmacklem#define NFSLOCKSOCK() mtx_lock(&nfs_slock_mutex) 610191783Srmacklem#define NFSUNLOCKSOCK() mtx_unlock(&nfs_slock_mutex) 611191783Srmacklem#define NFSNAMEIDMUTEX extern struct mtx nfs_nameid_mutex 612191783Srmacklem#define NFSLOCKNAMEID() mtx_lock(&nfs_nameid_mutex) 613191783Srmacklem#define NFSUNLOCKNAMEID() mtx_unlock(&nfs_nameid_mutex) 614191783Srmacklem#define NFSNAMEIDREQUIRED() mtx_assert(&nfs_nameid_mutex, MA_OWNED) 615191783Srmacklem#define NFSCLSTATEMUTEX extern struct mtx nfs_clstate_mutex 616191783Srmacklem#define NFSCLSTATEMUTEXPTR (&nfs_clstate_mutex) 617191783Srmacklem#define NFSLOCKCLSTATE() mtx_lock(&nfs_clstate_mutex) 618191783Srmacklem#define NFSUNLOCKCLSTATE() mtx_unlock(&nfs_clstate_mutex) 619191783Srmacklem#define NFSDLOCKMUTEX extern struct mtx newnfsd_mtx 620191783Srmacklem#define NFSDLOCKMUTEXPTR (&newnfsd_mtx) 621191783Srmacklem#define NFSD_LOCK() mtx_lock(&newnfsd_mtx) 622191783Srmacklem#define NFSD_UNLOCK() mtx_unlock(&newnfsd_mtx) 623191783Srmacklem#define NFSD_LOCK_ASSERT() mtx_assert(&newnfsd_mtx, MA_OWNED) 624191783Srmacklem#define NFSD_UNLOCK_ASSERT() mtx_assert(&newnfsd_mtx, MA_NOTOWNED) 625191783Srmacklem#define NFSV4ROOTLOCKMUTEX extern struct mtx nfs_v4root_mutex 626191783Srmacklem#define NFSV4ROOTLOCKMUTEXPTR (&nfs_v4root_mutex) 627191783Srmacklem#define NFSLOCKV4ROOTMUTEX() mtx_lock(&nfs_v4root_mutex) 628191783Srmacklem#define NFSUNLOCKV4ROOTMUTEX() mtx_unlock(&nfs_v4root_mutex) 629191783Srmacklem#define NFSLOCKNODE(n) mtx_lock(&((n)->n_mtx)) 630191783Srmacklem#define NFSUNLOCKNODE(n) mtx_unlock(&((n)->n_mtx)) 631191783Srmacklem#define NFSLOCKMNT(m) mtx_lock(&((m)->nm_mtx)) 632191783Srmacklem#define NFSUNLOCKMNT(m) mtx_unlock(&((m)->nm_mtx)) 633191783Srmacklem#define NFSLOCKREQUEST(r) mtx_lock(&((r)->r_mtx)) 634191783Srmacklem#define NFSUNLOCKREQUEST(r) mtx_unlock(&((r)->r_mtx)) 635191783Srmacklem#define NFSPROCLISTLOCK() sx_slock(&allproc_lock) 636191783Srmacklem#define NFSPROCLISTUNLOCK() sx_sunlock(&allproc_lock) 637191783Srmacklem#define NFSLOCKSOCKREQ(r) mtx_lock(&((r)->nr_mtx)) 638191783Srmacklem#define NFSUNLOCKSOCKREQ(r) mtx_unlock(&((r)->nr_mtx)) 639244042Srmacklem#define NFSLOCKDS(d) mtx_lock(&((d)->nfsclds_mtx)) 640244042Srmacklem#define NFSUNLOCKDS(d) mtx_unlock(&((d)->nfsclds_mtx)) 641269398Srmacklem#define NFSSESSIONMUTEXPTR(s) (&((s)->mtx)) 642269398Srmacklem#define NFSLOCKSESSION(s) mtx_lock(&((s)->mtx)) 643269398Srmacklem#define NFSUNLOCKSESSION(s) mtx_unlock(&((s)->mtx)) 644191783Srmacklem 645191783Srmacklem/* 646191783Srmacklem * Use these macros to initialize/free a mutex. 647191783Srmacklem */ 648191783Srmacklem#define NFSINITSOCKMUTEX(m) mtx_init((m), "nfssock", NULL, MTX_DEF) 649191783Srmacklem#define NFSFREEMUTEX(m) mtx_destroy((m)) 650191783Srmacklem 651191783Srmacklemint nfsmsleep(void *, void *, int, const char *, struct timespec *); 652191783Srmacklem 653191783Srmacklem/* 654191783Srmacklem * And weird vm stuff in the nfs server. 655191783Srmacklem */ 656191783Srmacklem#define PDIRUNLOCK 0x0 657191783Srmacklem#define MAX_COMMIT_COUNT (1024 * 1024) 658191783Srmacklem 659191783Srmacklem/* 660191783Srmacklem * Define these to handle the type of va_rdev. 661191783Srmacklem */ 662191783Srmacklem#define NFSMAKEDEV(m, n) makedev((m), (n)) 663191783Srmacklem#define NFSMAJOR(d) major(d) 664191783Srmacklem#define NFSMINOR(d) minor(d) 665191783Srmacklem 666191783Srmacklem/* 667191783Srmacklem * Define this to be the macro that returns the minimum size required 668191783Srmacklem * for a directory entry. 669191783Srmacklem */ 670191783Srmacklem#define DIRENT_SIZE(dp) GENERIC_DIRSIZ(dp) 671191783Srmacklem 672191783Srmacklem/* 673191783Srmacklem * The vnode tag for nfsv4root. 674191783Srmacklem */ 675191783Srmacklem#define VT_NFSV4ROOT "nfsv4root" 676191783Srmacklem 677191783Srmacklem/* 678191783Srmacklem * Define whatever it takes to do a vn_rdwr(). 679191783Srmacklem */ 680191783Srmacklem#define NFSD_RDWR(r, v, b, l, o, s, i, c, a, p) \ 681194292Srmacklem vn_rdwr((r), (v), (b), (l), (o), (s), (i), (c), NULL, (a), (p)) 682191783Srmacklem 683191783Srmacklem/* 684191783Srmacklem * Macros for handling memory for different BSDen. 685191783Srmacklem * NFSBCOPY(src, dst, len) - copies len bytes, non-overlapping 686191783Srmacklem * NFSOVBCOPY(src, dst, len) - ditto, but data areas might overlap 687191783Srmacklem * NFSBCMP(cp1, cp2, len) - compare len bytes, return 0 if same 688191783Srmacklem * NFSBZERO(cp, len) - set len bytes to 0x0 689191783Srmacklem */ 690191783Srmacklem#define NFSBCOPY(s, d, l) bcopy((s), (d), (l)) 691191783Srmacklem#define NFSOVBCOPY(s, d, l) ovbcopy((s), (d), (l)) 692191783Srmacklem#define NFSBCMP(s, d, l) bcmp((s), (d), (l)) 693191783Srmacklem#define NFSBZERO(s, l) bzero((s), (l)) 694191783Srmacklem 695191783Srmacklem/* 696191783Srmacklem * Some queue.h files don't have these dfined in them. 697191783Srmacklem */ 698191783Srmacklem#define LIST_END(head) NULL 699191783Srmacklem#define SLIST_END(head) NULL 700191783Srmacklem#define TAILQ_END(head) NULL 701191783Srmacklem 702191783Srmacklem/* 703217922Sgnn * This must be defined to be a global variable that increments once 704191783Srmacklem * per second, but never stops or goes backwards, even when a "date" 705217922Sgnn * command changes the TOD clock. It is used for delta times for 706191783Srmacklem * leases, etc. 707191783Srmacklem */ 708191783Srmacklem#define NFSD_MONOSEC time_uptime 709191783Srmacklem 710191783Srmacklem/* 711191783Srmacklem * Declare the malloc types. 712191783Srmacklem */ 713191783SrmacklemMALLOC_DECLARE(M_NEWNFSRVCACHE); 714191783SrmacklemMALLOC_DECLARE(M_NEWNFSDCLIENT); 715191783SrmacklemMALLOC_DECLARE(M_NEWNFSDSTATE); 716191783SrmacklemMALLOC_DECLARE(M_NEWNFSDLOCK); 717191783SrmacklemMALLOC_DECLARE(M_NEWNFSDLOCKFILE); 718191783SrmacklemMALLOC_DECLARE(M_NEWNFSSTRING); 719191783SrmacklemMALLOC_DECLARE(M_NEWNFSUSERGROUP); 720191783SrmacklemMALLOC_DECLARE(M_NEWNFSDREQ); 721191783SrmacklemMALLOC_DECLARE(M_NEWNFSFH); 722191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLOWNER); 723191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLOPEN); 724191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLDELEG); 725191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLCLIENT); 726191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLLOCKOWNER); 727191783SrmacklemMALLOC_DECLARE(M_NEWNFSCLLOCK); 728191783SrmacklemMALLOC_DECLARE(M_NEWNFSDIROFF); 729191783SrmacklemMALLOC_DECLARE(M_NEWNFSV4NODE); 730191783SrmacklemMALLOC_DECLARE(M_NEWNFSDIRECTIO); 731191783SrmacklemMALLOC_DECLARE(M_NEWNFSMNT); 732205941SrmacklemMALLOC_DECLARE(M_NEWNFSDROLLBACK); 733244042SrmacklemMALLOC_DECLARE(M_NEWNFSLAYOUT); 734244042SrmacklemMALLOC_DECLARE(M_NEWNFSFLAYOUT); 735244042SrmacklemMALLOC_DECLARE(M_NEWNFSDEVINFO); 736244042SrmacklemMALLOC_DECLARE(M_NEWNFSSOCKREQ); 737244042SrmacklemMALLOC_DECLARE(M_NEWNFSCLDS); 738244042SrmacklemMALLOC_DECLARE(M_NEWNFSLAYRECALL); 739269398SrmacklemMALLOC_DECLARE(M_NEWNFSDSESSION); 740191783Srmacklem#define M_NFSRVCACHE M_NEWNFSRVCACHE 741191783Srmacklem#define M_NFSDCLIENT M_NEWNFSDCLIENT 742191783Srmacklem#define M_NFSDSTATE M_NEWNFSDSTATE 743191783Srmacklem#define M_NFSDLOCK M_NEWNFSDLOCK 744191783Srmacklem#define M_NFSDLOCKFILE M_NEWNFSDLOCKFILE 745191783Srmacklem#define M_NFSSTRING M_NEWNFSSTRING 746191783Srmacklem#define M_NFSUSERGROUP M_NEWNFSUSERGROUP 747191783Srmacklem#define M_NFSDREQ M_NEWNFSDREQ 748191783Srmacklem#define M_NFSFH M_NEWNFSFH 749191783Srmacklem#define M_NFSCLOWNER M_NEWNFSCLOWNER 750191783Srmacklem#define M_NFSCLOPEN M_NEWNFSCLOPEN 751191783Srmacklem#define M_NFSCLDELEG M_NEWNFSCLDELEG 752191783Srmacklem#define M_NFSCLCLIENT M_NEWNFSCLCLIENT 753191783Srmacklem#define M_NFSCLLOCKOWNER M_NEWNFSCLLOCKOWNER 754191783Srmacklem#define M_NFSCLLOCK M_NEWNFSCLLOCK 755191783Srmacklem#define M_NFSDIROFF M_NEWNFSDIROFF 756191783Srmacklem#define M_NFSV4NODE M_NEWNFSV4NODE 757191783Srmacklem#define M_NFSDIRECTIO M_NEWNFSDIRECTIO 758205941Srmacklem#define M_NFSDROLLBACK M_NEWNFSDROLLBACK 759244042Srmacklem#define M_NFSLAYOUT M_NEWNFSLAYOUT 760244042Srmacklem#define M_NFSFLAYOUT M_NEWNFSFLAYOUT 761244042Srmacklem#define M_NFSDEVINFO M_NEWNFSDEVINFO 762244042Srmacklem#define M_NFSSOCKREQ M_NEWNFSSOCKREQ 763244042Srmacklem#define M_NFSCLDS M_NEWNFSCLDS 764244042Srmacklem#define M_NFSLAYRECALL M_NEWNFSLAYRECALL 765269398Srmacklem#define M_NFSDSESSION M_NEWNFSDSESSION 766191783Srmacklem 767191783Srmacklem#define NFSINT_SIGMASK(set) \ 768191783Srmacklem (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \ 769191783Srmacklem SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \ 770191783Srmacklem SIGISMEMBER(set, SIGQUIT)) 771191783Srmacklem 772191783Srmacklem/* 773191783Srmacklem * Convert a quota block count to byte count. 774191783Srmacklem */ 775191783Srmacklem#define NFSQUOTABLKTOBYTE(q, b) (q) *= (b) 776191783Srmacklem 777191783Srmacklem/* 778191783Srmacklem * Define this as the largest file size supported. (It should probably 779191783Srmacklem * be available via a VFS_xxx Op, but it isn't. 780191783Srmacklem */ 781191783Srmacklem#define NFSRV_MAXFILESIZE ((u_int64_t)0x800000000000) 782191783Srmacklem 783191783Srmacklem/* 784191783Srmacklem * Set this macro to index() or strchr(), whichever is supported. 785191783Srmacklem */ 786229272Sed#define STRCHR(s, c) strchr((s), (c)) 787191783Srmacklem 788191783Srmacklem/* 789191783Srmacklem * Set the n_time in the client write rpc, as required. 790191783Srmacklem */ 791299204Srmacklem#define NFSWRITERPC_SETTIME(w, n, a, v4) \ 792191783Srmacklem do { \ 793191783Srmacklem if (w) { \ 794299204Srmacklem mtx_lock(&((n)->n_mtx)); \ 795299204Srmacklem (n)->n_mtime = (a)->na_mtime; \ 796191783Srmacklem if (v4) \ 797299204Srmacklem (n)->n_change = (a)->na_filerev; \ 798299204Srmacklem mtx_unlock(&((n)->n_mtx)); \ 799191783Srmacklem } \ 800191783Srmacklem } while (0) 801191783Srmacklem 802191783Srmacklem/* 803191783Srmacklem * Fake value, just to make the client work. 804191783Srmacklem */ 805191783Srmacklem#define NFS_LATTR_NOSHRINK 1 806191783Srmacklem 807191783Srmacklem/* 808191783Srmacklem * Prototypes for functions where the arguments vary for different ports. 809191783Srmacklem */ 810191783Srmacklemint nfscl_loadattrcache(struct vnode **, struct nfsvattr *, void *, void *, 811191783Srmacklem int, int); 812249592Skenint newnfs_realign(struct mbuf **, int); 813191783Srmacklem 814191783Srmacklem/* 815191783Srmacklem * If the port runs on an SMP box that can enforce Atomic ops with low 816191783Srmacklem * overheads, define these as atomic increments/decrements. If not, 817191783Srmacklem * don't worry about it, since these are used for stats that can be 818191783Srmacklem * "out by one" without disastrous consequences. 819191783Srmacklem */ 820191783Srmacklem#define NFSINCRGLOBAL(a) ((a)++) 821191783Srmacklem 822191783Srmacklem/* 823191783Srmacklem * Assorted funky stuff to make things work under Darwin8. 824191783Srmacklem */ 825191783Srmacklem/* 826191783Srmacklem * These macros checks for a field in vattr being set. 827191783Srmacklem */ 828191783Srmacklem#define NFSATTRISSET(t, v, a) ((v)->a != (t)VNOVAL) 829191783Srmacklem#define NFSATTRISSETTIME(v, a) ((v)->a.tv_sec != VNOVAL) 830191783Srmacklem 831191783Srmacklem/* 832191783Srmacklem * Manipulate mount flags. 833191783Srmacklem */ 834191783Srmacklem#define NFSSTA_HASWRITEVERF 0x00040000 /* Has write verifier */ 835191783Srmacklem#define NFSSTA_GOTFSINFO 0x00100000 /* Got the fsinfo */ 836317984Srmacklem#define NFSSTA_OPENMODE 0x00200000 /* Must use correct open mode */ 837244042Srmacklem#define NFSSTA_NOLAYOUTCOMMIT 0x04000000 /* Don't do LayoutCommit */ 838244042Srmacklem#define NFSSTA_SESSPERSIST 0x08000000 /* Has a persistent session */ 839191783Srmacklem#define NFSSTA_TIMEO 0x10000000 /* Experiencing a timeout */ 840191783Srmacklem#define NFSSTA_LOCKTIMEO 0x20000000 /* Experiencing a lockd timeout */ 841191783Srmacklem#define NFSSTA_HASSETFSID 0x40000000 /* Has set the fsid */ 842244042Srmacklem#define NFSSTA_PNFS 0x80000000 /* pNFS is enabled */ 843191783Srmacklem 844191783Srmacklem#define NFSHASNFSV3(n) ((n)->nm_flag & NFSMNT_NFSV3) 845191783Srmacklem#define NFSHASNFSV4(n) ((n)->nm_flag & NFSMNT_NFSV4) 846244042Srmacklem#define NFSHASNFSV4N(n) ((n)->nm_minorvers > 0) 847191783Srmacklem#define NFSHASNFSV3OR4(n) ((n)->nm_flag & (NFSMNT_NFSV3 | NFSMNT_NFSV4)) 848191783Srmacklem#define NFSHASGOTFSINFO(n) ((n)->nm_state & NFSSTA_GOTFSINFO) 849191783Srmacklem#define NFSHASHASSETFSID(n) ((n)->nm_state & NFSSTA_HASSETFSID) 850191783Srmacklem#define NFSHASSTRICT3530(n) ((n)->nm_flag & NFSMNT_STRICT3530) 851191783Srmacklem#define NFSHASWRITEVERF(n) ((n)->nm_state & NFSSTA_HASWRITEVERF) 852191783Srmacklem#define NFSHASINT(n) ((n)->nm_flag & NFSMNT_INT) 853191783Srmacklem#define NFSHASSOFT(n) ((n)->nm_flag & NFSMNT_SOFT) 854191783Srmacklem#define NFSHASINTORSOFT(n) ((n)->nm_flag & (NFSMNT_INT | NFSMNT_SOFT)) 855191783Srmacklem#define NFSHASDUMBTIMR(n) ((n)->nm_flag & NFSMNT_DUMBTIMR) 856191783Srmacklem#define NFSHASNOCONN(n) ((n)->nm_flag & NFSMNT_MNTD) 857191783Srmacklem#define NFSHASKERB(n) ((n)->nm_flag & NFSMNT_KERB) 858191783Srmacklem#define NFSHASALLGSSNAME(n) ((n)->nm_flag & NFSMNT_ALLGSSNAME) 859191783Srmacklem#define NFSHASINTEGRITY(n) ((n)->nm_flag & NFSMNT_INTEGRITY) 860191783Srmacklem#define NFSHASPRIVACY(n) ((n)->nm_flag & NFSMNT_PRIVACY) 861191783Srmacklem#define NFSSETWRITEVERF(n) ((n)->nm_state |= NFSSTA_HASWRITEVERF) 862191783Srmacklem#define NFSSETHASSETFSID(n) ((n)->nm_state |= NFSSTA_HASSETFSID) 863244042Srmacklem#define NFSHASPNFSOPT(n) ((n)->nm_flag & NFSMNT_PNFS) 864244042Srmacklem#define NFSHASNOLAYOUTCOMMIT(n) ((n)->nm_state & NFSSTA_NOLAYOUTCOMMIT) 865244042Srmacklem#define NFSHASSESSPERSIST(n) ((n)->nm_state & NFSSTA_SESSPERSIST) 866244042Srmacklem#define NFSHASPNFS(n) ((n)->nm_state & NFSSTA_PNFS) 867317984Srmacklem#define NFSHASOPENMODE(n) ((n)->nm_state & NFSSTA_OPENMODE) 868317525Srmacklem#define NFSHASONEOPENOWN(n) (((n)->nm_flag & NFSMNT_ONEOPENOWN) != 0 && \ 869317525Srmacklem (n)->nm_minorvers > 0) 870191783Srmacklem 871191783Srmacklem/* 872191783Srmacklem * Gets the stats field out of the mount structure. 873191783Srmacklem */ 874191783Srmacklem#define vfs_statfs(m) (&((m)->mnt_stat)) 875191783Srmacklem 876191783Srmacklem/* 877191783Srmacklem * Set boottime. 878191783Srmacklem */ 879191783Srmacklem#define NFSSETBOOTTIME(b) ((b) = boottime) 880191783Srmacklem 881191783Srmacklem/* 882191783Srmacklem * The size of directory blocks in the buffer cache. 883191783Srmacklem * MUST BE in the range of PAGE_SIZE <= NFS_DIRBLKSIZ <= MAXBSIZE!! 884191783Srmacklem */ 885191783Srmacklem#define NFS_DIRBLKSIZ (16 * DIRBLKSIZ) /* Must be a multiple of DIRBLKSIZ */ 886191783Srmacklem 887191783Srmacklem/* 888191783Srmacklem * Define these macros to access mnt_flag fields. 889191783Srmacklem */ 890191783Srmacklem#define NFSMNT_RDONLY(m) ((m)->mnt_flag & MNT_RDONLY) 891191783Srmacklem#endif /* _KERNEL */ 892191783Srmacklem 893191783Srmacklem/* 894191783Srmacklem * Define a structure similar to ufs_args for use in exporting the V4 root. 895191783Srmacklem */ 896191783Srmacklemstruct nfsex_args { 897191783Srmacklem char *fspec; 898191783Srmacklem struct export_args export; 899191783Srmacklem}; 900191783Srmacklem 901191783Srmacklem/* 902191783Srmacklem * These export flags should be defined, but there are no bits left. 903191783Srmacklem * Maybe a separate mnt_exflag field could be added or the mnt_flag 904191783Srmacklem * field increased to 64 bits? 905191783Srmacklem */ 906191783Srmacklem#ifndef MNT_EXSTRICTACCESS 907191783Srmacklem#define MNT_EXSTRICTACCESS 0x0 908191783Srmacklem#endif 909191783Srmacklem#ifndef MNT_EXV4ONLY 910191783Srmacklem#define MNT_EXV4ONLY 0x0 911191783Srmacklem#endif 912191783Srmacklem 913191783Srmacklem#ifdef _KERNEL 914191783Srmacklem/* 915191783Srmacklem * Define this to invalidate the attribute cache for the nfs node. 916191783Srmacklem */ 917191783Srmacklem#define NFSINVALATTRCACHE(n) ((n)->n_attrstamp = 0) 918191783Srmacklem 919191783Srmacklem/* Used for FreeBSD only */ 920191783Srmacklemvoid nfsd_mntinit(void); 921191783Srmacklem 922191783Srmacklem/* 923191783Srmacklem * Define these for vnode lock/unlock ops. 924224080Szack * 925224080Szack * These are good abstractions to macro out, so that they can be added to 926224080Szack * later, for debugging or stats, etc. 927191783Srmacklem */ 928224080Szack#define NFSVOPLOCK(v, f) vn_lock((v), (f)) 929224080Szack#define NFSVOPUNLOCK(v, f) VOP_UNLOCK((v), (f)) 930224080Szack#define NFSVOPISLOCKED(v) VOP_ISLOCKED((v)) 931191783Srmacklem 932191783Srmacklem/* 933191783Srmacklem * Define ncl_hash(). 934191783Srmacklem */ 935191783Srmacklem#define ncl_hash(f, l) (fnv_32_buf((f), (l), FNV1_32_INIT)) 936191783Srmacklem 937191783Srmacklemint newnfs_iosize(struct nfsmount *); 938191783Srmacklem 939191783Srmacklem#ifdef NFS_DEBUG 940191783Srmacklem 941191783Srmacklemextern int nfs_debug; 942191783Srmacklem#define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */ 943191783Srmacklem#define NFS_DEBUG_WG 2 /* server write gathering */ 944191783Srmacklem#define NFS_DEBUG_RC 4 /* server request caching */ 945191783Srmacklem 946191783Srmacklem#define NFS_DPF(cat, args) \ 947191783Srmacklem do { \ 948191783Srmacklem if (nfs_debug & NFS_DEBUG_##cat) printf args; \ 949191783Srmacklem } while (0) 950191783Srmacklem 951191783Srmacklem#else 952191783Srmacklem 953191783Srmacklem#define NFS_DPF(cat, args) 954191783Srmacklem 955191783Srmacklem#endif 956191783Srmacklem 957191783Srmacklemint newnfs_vncmpf(struct vnode *, void *); 958191783Srmacklem 959191783Srmacklem#ifndef NFS_MINDIRATTRTIMO 960191783Srmacklem#define NFS_MINDIRATTRTIMO 3 /* VDIR attrib cache timeout in sec */ 961191783Srmacklem#endif 962191783Srmacklem#ifndef NFS_MAXDIRATTRTIMO 963191783Srmacklem#define NFS_MAXDIRATTRTIMO 60 964191783Srmacklem#endif 965191783Srmacklem 966191783Srmacklem/* 967191783Srmacklem * Nfs outstanding request list element 968191783Srmacklem */ 969191783Srmacklemstruct nfsreq { 970191783Srmacklem TAILQ_ENTRY(nfsreq) r_chain; 971191783Srmacklem u_int32_t r_flags; /* flags on request, see below */ 972191783Srmacklem struct nfsmount *r_nmp; /* Client mnt ptr */ 973191783Srmacklem struct mtx r_mtx; /* Mutex lock for this structure */ 974191783Srmacklem}; 975191783Srmacklem 976191783Srmacklem#ifndef NFS_MAXBSIZE 977282933Srmacklem#define NFS_MAXBSIZE MAXBCACHEBUF 978191783Srmacklem#endif 979191783Srmacklem 980191783Srmacklem/* 981191783Srmacklem * This macro checks to see if issuing of delegations is allowed for this 982191783Srmacklem * vnode. 983191783Srmacklem */ 984191783Srmacklem#ifdef VV_DISABLEDELEG 985191783Srmacklem#define NFSVNO_DELEGOK(v) \ 986191783Srmacklem ((v) == NULL || ((v)->v_vflag & VV_DISABLEDELEG) == 0) 987191783Srmacklem#else 988191783Srmacklem#define NFSVNO_DELEGOK(v) (1) 989191783Srmacklem#endif 990191783Srmacklem 991292895Smckusick/* 992292895Smckusick * Name used by getnewvnode() to describe filesystem, "newnfs". 993292895Smckusick * For perfomance reasons it is useful to have the same string 994292895Smckusick * used in both places that call getnewvnode(). 995292895Smckusick */ 996292895Smckusickextern const char nfs_vnode_tag[]; 997292895Smckusick 998191783Srmacklem#endif /* _KERNEL */ 999191783Srmacklem 1000207785Srmacklem#endif /* _NFS_NFSPORT_H */ 1001