nfs.h revision 192000
1212793Sdim/*- 2212793Sdim * Copyright (c) 1989, 1993 3212793Sdim * The Regents of the University of California. All rights reserved. 4212793Sdim * 5212793Sdim * This code is derived from software contributed to Berkeley by 6212793Sdim * Rick Macklem at The University of Guelph. 7212793Sdim * 8212793Sdim * Redistribution and use in source and binary forms, with or without 9212793Sdim * modification, are permitted provided that the following conditions 10212793Sdim * are met: 11212793Sdim * 1. Redistributions of source code must retain the above copyright 12212793Sdim * notice, this list of conditions and the following disclaimer. 13212793Sdim * 2. Redistributions in binary form must reproduce the above copyright 14212793Sdim * notice, this list of conditions and the following disclaimer in the 15218893Sdim * documentation and/or other materials provided with the distribution. 16212793Sdim * 4. Neither the name of the University nor the names of its contributors 17212793Sdim * may be used to endorse or promote products derived from this software 18221345Sdim * without specific prior written permission. 19212793Sdim * 20234353Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21218893Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22212793Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23226633Sdim * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24212793Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25212793Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26212793Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27212793Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28212793Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29212793Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30212793Sdim * SUCH DAMAGE. 31212793Sdim * 32221345Sdim * $FreeBSD: head/sys/fs/nfs/nfs.h 192000 2009-05-11 19:37:05Z rmacklem $ 33221345Sdim */ 34223017Sdim 35223017Sdim#ifndef _NFS_NFS_H_ 36223017Sdim#define _NFS_NFS_H_ 37212793Sdim/* 38212793Sdim * Tunable constants for nfs 39212793Sdim */ 40212793Sdim 41212793Sdim#define NFS_MAXIOVEC 34 42218893Sdim#define NFS_TICKINTVL 10 /* Desired time for a tick (msec) */ 43212793Sdim#define NFS_HZ (hz / nfscl_ticks) /* Ticks/sec */ 44212793Sdim#define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */ 45218893Sdim#define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */ 46218893Sdim#define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */ 47218893Sdim#define NFS_TCPTIMEO 300 /* TCP timeout */ 48218893Sdim#define NFS_MAXRCVTIMEO 60 /* 1 minute in seconds */ 49218893Sdim#define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/ 50221345Sdim#define NFS_MAXREXMIT 100 /* Stop counting after this many */ 51221345Sdim#define NFSV4_CALLBACKTIMEO (2 * NFS_HZ) /* Timeout in ticks */ 52212793Sdim#define NFSV4_CALLBACKRETRY 5 /* Number of retries before failure */ 53212793Sdim#define NFSV4_CBRETRYCNT 4 /* # of CBRecall retries upon err */ 54218893Sdim#define NFSV4_UPCALLTIMEO (15 * NFS_HZ) /* Timeout in ticks for upcalls */ 55221345Sdim /* to gssd or nfsuserd */ 56221345Sdim#define NFSV4_UPCALLRETRY 4 /* Number of retries before failure */ 57218893Sdim#define NFS_MAXWINDOW 1024 /* Max number of outstanding requests */ 58223017Sdim#define NFS_RETRANS 10 /* Num of retrans for soft mounts */ 59212793Sdim#define NFS_MAXGRPS 16 /* Max. size of groups list */ 60212793Sdim#define NFS_TRYLATERDEL 15 /* Maximum delay timeout (sec) */ 61221345Sdim#ifndef NFS_REMOVETIMEO 62221345Sdim#define NFS_REMOVETIMEO 15 /* # sec to wait for delegret in local syscall */ 63221345Sdim#endif 64221345Sdim#ifndef NFS_MINATTRTIMO 65234353Sdim#define NFS_MINATTRTIMO 5 /* Attribute cache timeout in sec */ 66221345Sdim#endif 67221345Sdim#ifndef NFS_MAXATTRTIMO 68221345Sdim#define NFS_MAXATTRTIMO 60 69221345Sdim#endif 70221345Sdim#define NFS_WSIZE 8192 /* Def. write data size <= 8192 */ 71221345Sdim#define NFS_RSIZE 8192 /* Def. read data size <= 8192 */ 72234353Sdim#define NFS_READDIRSIZE 8192 /* Def. readdir size */ 73221345Sdim#define NFS_DEFRAHEAD 0 /* Def. read ahead # blocks */ 74221345Sdim#define NFS_MAXRAHEAD 32 /* Max. read ahead # blocks */ 75221345Sdim#define NFS_MAXUIDHASH 64 /* Max. # of hashed uid entries/mp */ 76221345Sdim#ifndef NFSRV_LEASE 77221345Sdim#define NFSRV_LEASE 120 /* Lease time in seconds for V4 */ 78221345Sdim#endif /* assigned to nfsrv_lease */ 79221345Sdim#ifndef NFSRV_STALELEASE 80221345Sdim#define NFSRV_STALELEASE (5 * nfsrv_lease) 81224145Sdim#endif 82224145Sdim#ifndef NFSRV_MOULDYLEASE 83224145Sdim#define NFSRV_MOULDYLEASE 604800 /* One week (in sec) */ 84234353Sdim#endif 85221345Sdim#ifndef NFSCLIENTHASHSIZE 86221345Sdim#define NFSCLIENTHASHSIZE 20 /* Size of server client hash table */ 87221345Sdim#endif 88224145Sdim#ifndef NFSLOCKHASHSIZE 89221345Sdim#define NFSLOCKHASHSIZE 20 /* Size of server nfslock hash table */ 90221345Sdim#endif 91221345Sdim#define NFSSTATEHASHSIZE 10 /* Size of server stateid hash table */ 92221345Sdim#ifndef NFSUSERHASHSIZE 93234353Sdim#define NFSUSERHASHSIZE 30 /* Size of user id hash table */ 94221345Sdim#endif 95234353Sdim#ifndef NFSGROUPHASHSIZE 96234353Sdim#define NFSGROUPHASHSIZE 5 /* Size of group id hash table */ 97234353Sdim#endif 98234353Sdim#ifndef NFSCLDELEGHIGHWATER 99234353Sdim#define NFSCLDELEGHIGHWATER 10000 /* limit for client delegations */ 100234353Sdim#endif 101234353Sdim#ifndef NFSNOOPEN /* Inactive open owner (sec) */ 102234353Sdim#define NFSNOOPEN 120 103234353Sdim#endif 104234353Sdim#define NFSRV_LEASEDELTA 15 /* # of seconds to delay beyond lease */ 105234353Sdim#define NFS_IDMAXSIZE 4 /* max sizeof (in_addr_t) */ 106234353Sdim#ifndef NFSRVCACHE_UDPTIMEOUT 107234353Sdim#define NFSRVCACHE_UDPTIMEOUT 30 /* # of sec to hold cached rpcs(udp) */ 108234353Sdim#endif 109234353Sdim#ifndef NFSRVCACHE_UDPHIGHWATER 110234353Sdim#define NFSRVCACHE_UDPHIGHWATER 500 /* Max # of udp cache entries */ 111212793Sdim#endif 112212793Sdim#ifndef NFSRVCACHE_TCPTIMEOUT 113234353Sdim#define NFSRVCACHE_TCPTIMEOUT (3600*12) /*#of sec to hold cached rpcs(tcp) */ 114234353Sdim#endif 115234353Sdim#ifndef NFSRVCACHE_FLOODLEVEL 116234353Sdim#define NFSRVCACHE_FLOODLEVEL 16384 /* Very high water mark for cache */ 117234353Sdim#endif 118234353Sdim#ifndef NFSRV_CLIENTHIGHWATER 119234353Sdim#define NFSRV_CLIENTHIGHWATER 1000 120234353Sdim#endif 121218893Sdim#ifndef NFSRV_MAXDUMPLIST 122212793Sdim#define NFSRV_MAXDUMPLIST 10000 123221345Sdim#endif 124221345Sdim#ifndef NFS_ACCESSCACHESIZE 125221345Sdim#define NFS_ACCESSCACHESIZE 8 126221345Sdim#endif 127221345Sdim#define NFSV4_CBPORT 7745 /* Callback port for testing */ 128221345Sdim 129221345Sdim/* 130221345Sdim * This macro defines the high water mark for issuing V4 delegations. 131221345Sdim * (It is currently set at a conservative 20% of NFSRV_V4STATELIMIT. This 132221345Sdim * may want to increase when clients can make more effective use of 133218893Sdim * delegations.) 134221345Sdim */ 135221345Sdim#define NFSRV_V4DELEGLIMIT(c) (((c) * 5) > NFSRV_V4STATELIMIT) 136221345Sdim 137221345Sdim#define NFS_READDIRBLKSIZ DIRBLKSIZ /* Minimal nm_readdirsize */ 138234353Sdim 139221345Sdim/* 140221345Sdim * Oddballs 141221345Sdim */ 142221345Sdim#define NFS_CMPFH(n, f, s) \ 143221345Sdim ((n)->n_fhp->nfh_len == (s) && !NFSBCMP((n)->n_fhp->nfh_fh, (caddr_t)(f), (s))) 144221345Sdim#define NFSRV_CMPFH(nf, ns, f, s) \ 145221345Sdim ((ns) == (s) && !NFSBCMP((caddr_t)(nf), (caddr_t)(f), (s))) 146221345Sdim#define NFS_CMPTIME(t1, t2) \ 147221345Sdim ((t1).tv_sec == (t2).tv_sec && (t1).tv_nsec == (t2).tv_nsec) 148221345Sdim#define NFS_SETTIME(t) do { \ 149221345Sdim (t).tv_sec = time.tv_sec; (t).tv_nsec = 1000 * time.tv_usec; } while (0) 150221345Sdim#define NFS_SRVMAXDATA(n) \ 151224145Sdim (((n)->nd_flag & (ND_NFSV3 | ND_NFSV4)) ? \ 152223017Sdim NFS_MAXDATA : NFS_V2MAXDATA) 153223017Sdim#define NFS64BITSSET 0xffffffffffffffffull 154221345Sdim#define NFS64BITSMINUS1 0xfffffffffffffffeull 155221345Sdim 156221345Sdim/* 157221345Sdim * Structures for the nfssvc(2) syscall. Not that anyone but nfsd, mount_nfs 158221345Sdim * and nfsloaduser should ever try and use it. 159221345Sdim */ 160221345Sdimstruct nfsd_addsock_args { 161221345Sdim int sock; /* Socket to serve */ 162212793Sdim caddr_t name; /* Client addr for connection based sockets */ 163221345Sdim int namelen; /* Length of name */ 164221345Sdim}; 165221345Sdim 166221345Sdim/* 167221345Sdim * nfsd argument for new krpc. 168212793Sdim */ 169212793Sdimstruct nfsd_nfsd_args { 170218893Sdim const char *principal; /* GSS-API service principal name */ 171218893Sdim int minthreads; /* minimum service thread count */ 172221345Sdim int maxthreads; /* maximum service thread count */ 173221345Sdim}; 174223017Sdim 175218893Sdim/* 176221345Sdim * Arguments for use by the callback daemon. 177212793Sdim */ 178218893Sdimstruct nfsd_nfscbd_args { 179218893Sdim const char *principal; /* GSS-API service principal name */ 180212793Sdim}; 181218893Sdim 182218893Sdimstruct nfscbd_args { 183218893Sdim int sock; /* Socket to serve */ 184212793Sdim caddr_t name; /* Client addr for connection based sockets */ 185218893Sdim int namelen; /* Length of name */ 186218893Sdim u_short port; /* Port# for callbacks */ 187218893Sdim}; 188218893Sdim 189218893Sdimstruct nfsd_idargs { 190218893Sdim int nid_flag; /* Flags (see below) */ 191218893Sdim uid_t nid_uid; /* user/group id */ 192212793Sdim gid_t nid_gid; 193223017Sdim int nid_usermax; /* Upper bound on user name cache */ 194224145Sdim int nid_usertimeout;/* User name timeout (minutes) */ 195223017Sdim u_char *nid_name; /* Name */ 196223017Sdim int nid_namelen; /* and its length */ 197223017Sdim}; 198223017Sdim 199223017Sdimstruct nfsd_clid { 200223017Sdim int nclid_idlen; /* Length of client id */ 201223017Sdim u_char nclid_id[NFSV4_OPAQUELIMIT]; /* and name */ 202223017Sdim}; 203223017Sdim 204223017Sdimstruct nfsd_dumplist { 205226633Sdim int ndl_size; /* Number of elements */ 206226633Sdim void *ndl_list; /* and the list of elements */ 207218893Sdim}; 208218893Sdim 209226633Sdimstruct nfsd_dumpclients { 210226633Sdim u_int32_t ndcl_flags; /* LCL_xxx flags */ 211212793Sdim u_int32_t ndcl_nopenowners; /* Number of openowners */ 212223017Sdim u_int32_t ndcl_nopens; /* and opens */ 213223017Sdim u_int32_t ndcl_nlockowners; /* and of lockowners */ 214223017Sdim u_int32_t ndcl_nlocks; /* and of locks */ 215226633Sdim u_int32_t ndcl_ndelegs; /* and of delegations */ 216226633Sdim u_int32_t ndcl_nolddelegs; /* and old delegations */ 217226633Sdim sa_family_t ndcl_addrfam; /* Callback address */ 218226633Sdim union { 219226633Sdim struct in_addr sin_addr; 220226633Sdim struct in6_addr sin6_addr; 221226633Sdim } ndcl_cbaddr; 222223017Sdim struct nfsd_clid ndcl_clid; /* and client id */ 223223017Sdim}; 224223017Sdim 225223017Sdimstruct nfsd_dumplocklist { 226223017Sdim char *ndllck_fname; /* File Name */ 227223017Sdim int ndllck_size; /* Number of elements */ 228226633Sdim void *ndllck_list; /* and the list of elements */ 229223017Sdim}; 230223017Sdim 231226633Sdimstruct nfsd_dumplocks { 232223017Sdim u_int32_t ndlck_flags; /* state flags NFSLCK_xxx */ 233223017Sdim nfsv4stateid_t ndlck_stateid; /* stateid */ 234223017Sdim u_int64_t ndlck_first; /* lock byte range */ 235223017Sdim u_int64_t ndlck_end; 236223017Sdim struct nfsd_clid ndlck_owner; /* Owner of open/lock */ 237223017Sdim sa_family_t ndlck_addrfam; /* Callback address */ 238223017Sdim union { 239223017Sdim struct in_addr sin_addr; 240226633Sdim struct in6_addr sin6_addr; 241223017Sdim } ndlck_cbaddr; 242223017Sdim struct nfsd_clid ndlck_clid; /* and client id */ 243223017Sdim}; 244223017Sdim 245226633Sdim/* 246223017Sdim * Structure for referral information. 247226633Sdim */ 248226633Sdimstruct nfsreferral { 249226633Sdim u_char *nfr_srvlist; /* List of servers */ 250226633Sdim int nfr_srvcnt; /* number of servers */ 251226633Sdim vnode_t nfr_vp; /* vnode for referral */ 252218893Sdim u_int32_t nfr_dfileno; /* assigned dir inode# */ 253212793Sdim}; 254221345Sdim 255223017Sdim/* 256223017Sdim * Flags for lc_flags and opsflags for nfsrv_getclient(). 257223017Sdim */ 258223017Sdim#define LCL_NEEDSCONFIRM 0x00000001 259221345Sdim#define LCL_DONTCLEAN 0x00000002 260212793Sdim#define LCL_WAKEUPWANTED 0x00000004 261218893Sdim#define LCL_TCPCALLBACK 0x00000008 262218893Sdim#define LCL_CALLBACKSON 0x00000010 263218893Sdim#define LCL_INDEXNOTOK 0x00000020 264218893Sdim#define LCL_STAMPEDSTABLE 0x00000040 265218893Sdim#define LCL_EXPIREIT 0x00000080 266218893Sdim#define LCL_CBDOWN 0x00000100 267218893Sdim#define LCL_KERBV 0x00000400 268218893Sdim#define LCL_NAME 0x00000800 269218893Sdim#define LCL_NEEDSCBNULL 0x00001000 270212793Sdim#define LCL_GSSINTEGRITY 0x00002000 271223017Sdim#define LCL_GSSPRIVACY 0x00004000 272223017Sdim#define LCL_ADMINREVOKED 0x00008000 273221345Sdim 274212793Sdim#define LCL_GSS LCL_KERBV /* Or of all mechs */ 275212793Sdim 276221345Sdim/* 277221345Sdim * Bits for flags in nfslock and nfsstate. 278221345Sdim * The access, deny, NFSLCK_READ and NFSLCK_WRITE bits must be defined as 279221345Sdim * below, in the correct order, so the shifts work for tests. 280221345Sdim */ 281221345Sdim#define NFSLCK_READACCESS 0x00000001 282221345Sdim#define NFSLCK_WRITEACCESS 0x00000002 283221345Sdim#define NFSLCK_ACCESSBITS (NFSLCK_READACCESS | NFSLCK_WRITEACCESS) 284221345Sdim#define NFSLCK_SHIFT 2 285221345Sdim#define NFSLCK_READDENY 0x00000004 286221345Sdim#define NFSLCK_WRITEDENY 0x00000008 287221345Sdim#define NFSLCK_DENYBITS (NFSLCK_READDENY | NFSLCK_WRITEDENY) 288221345Sdim#define NFSLCK_SHAREBITS \ 289221345Sdim (NFSLCK_READACCESS|NFSLCK_WRITEACCESS|NFSLCK_READDENY|NFSLCK_WRITEDENY) 290221345Sdim#define NFSLCK_LOCKSHIFT 4 291221345Sdim#define NFSLCK_READ 0x00000010 292221345Sdim#define NFSLCK_WRITE 0x00000020 293221345Sdim#define NFSLCK_BLOCKING 0x00000040 294221345Sdim#define NFSLCK_RECLAIM 0x00000080 295221345Sdim#define NFSLCK_OPENTOLOCK 0x00000100 296221345Sdim#define NFSLCK_TEST 0x00000200 297221345Sdim#define NFSLCK_LOCK 0x00000400 298221345Sdim#define NFSLCK_UNLOCK 0x00000800 299219077Sdim#define NFSLCK_OPEN 0x00001000 300219077Sdim#define NFSLCK_CLOSE 0x00002000 301219077Sdim#define NFSLCK_CHECK 0x00004000 302219077Sdim#define NFSLCK_RELEASE 0x00008000 303219077Sdim#define NFSLCK_NEEDSCONFIRM 0x00010000 304219077Sdim#define NFSLCK_CONFIRM 0x00020000 305219077Sdim#define NFSLCK_DOWNGRADE 0x00040000 306219077Sdim#define NFSLCK_DELEGREAD 0x00080000 307219077Sdim#define NFSLCK_DELEGWRITE 0x00100000 308219077Sdim#define NFSLCK_DELEGCUR 0x00200000 309219077Sdim#define NFSLCK_DELEGPREV 0x00400000 310219077Sdim#define NFSLCK_OLDDELEG 0x00800000 311219077Sdim#define NFSLCK_DELEGRECALL 0x01000000 312219077Sdim#define NFSLCK_SETATTR 0x02000000 313212793Sdim#define NFSLCK_DELEGPURGE 0x04000000 314212793Sdim#define NFSLCK_DELEGRETURN 0x08000000 315218893Sdim 316212793Sdim/* And bits for nid_flag */ 317212793Sdim#define NFSID_INITIALIZE 0x0001 318212793Sdim#define NFSID_ADDUID 0x0002 319212793Sdim#define NFSID_DELUID 0x0004 320218893Sdim#define NFSID_ADDUSERNAME 0x0008 321221345Sdim#define NFSID_DELUSERNAME 0x0010 322218893Sdim#define NFSID_ADDGID 0x0020 323212793Sdim#define NFSID_DELGID 0x0040 324221345Sdim#define NFSID_ADDGROUPNAME 0x0080 325221345Sdim#define NFSID_DELGROUPNAME 0x0100 326221345Sdim 327221345Sdim/* 328221345Sdim * Stats structure 329221345Sdim */ 330221345Sdimstruct nfsstats { 331221345Sdim int attrcache_hits; 332221345Sdim int attrcache_misses; 333221345Sdim int lookupcache_hits; 334221345Sdim int lookupcache_misses; 335221345Sdim int direofcache_hits; 336226633Sdim int direofcache_misses; 337221345Sdim int accesscache_hits; 338221345Sdim int accesscache_misses; 339212793Sdim int biocache_reads; 340226633Sdim int read_bios; 341226633Sdim int read_physios; 342226633Sdim int biocache_writes; 343221345Sdim int write_bios; 344221345Sdim int write_physios; 345218893Sdim int biocache_readlinks; 346221345Sdim int readlink_bios; 347226633Sdim int biocache_readdirs; 348239462Sdim int readdir_bios; 349239462Sdim int rpccnt[NFS_NPROCS]; 350226633Sdim int rpcretries; 351239462Sdim int srvrpccnt[NFSV4OP_NOPS + NFSV4OP_FAKENOPS]; 352239462Sdim int srvrpc_errs; 353221345Sdim int srv_errs; 354221345Sdim int rpcrequests; 355221345Sdim int rpctimeouts; 356234353Sdim int rpcunexpected; 357212793Sdim int rpcinvalid; 358212793Sdim int srvcache_inproghits; 359221345Sdim int srvcache_idemdonehits; 360221345Sdim int srvcache_nonidemdonehits; 361221345Sdim int srvcache_misses; 362221345Sdim int srvcache_tcppeak; 363221345Sdim int srvcache_size; 364221345Sdim int srvclients; 365221345Sdim int srvopenowners; 366221345Sdim int srvopens; 367221345Sdim int srvlockowners; 368212793Sdim int srvlocks; 369212793Sdim int srvdelegates; 370221345Sdim int cbrpccnt[NFSV4OP_CBNOPS]; 371221345Sdim int clopenowners; 372221345Sdim int clopens; 373212793Sdim int cllockowners; 374212793Sdim int cllocks; 375221345Sdim int cldelegates; 376221345Sdim int cllocalopenowners; 377212793Sdim int cllocalopens; 378218893Sdim int cllocallockowners; 379234353Sdim int cllocallocks; 380212793Sdim}; 381218893Sdim 382221345Sdim/* 383226633Sdim * fs.nfs sysctl(3) identifiers 384226633Sdim */ 385218893Sdim#define NFS_NFSSTATS 1 /* struct: struct nfsstats */ 386221345Sdim 387221345Sdim#define FS_NFS_NAMES { \ 388221345Sdim { 0, 0 }, \ 389221345Sdim { "nfsstats", CTLTYPE_STRUCT }, \ 390221345Sdim} 391221345Sdim 392226633Sdim/* 393221345Sdim * Here is the definition of the attribute bits array and macros that 394234353Sdim * manipulate it. 395226633Sdim * THE MACROS MUST BE MANUALLY MODIFIED IF NFSATTRBIT_MAXWORDS CHANGES!! 396226633Sdim * It is (NFSATTRBIT_MAX + 31) / 32. 397221345Sdim */ 398218893Sdim#define NFSATTRBIT_MAXWORDS 2 399221345Sdim 400221345Sdimtypedef struct { 401234353Sdim u_int32_t bits[NFSATTRBIT_MAXWORDS]; 402221345Sdim} nfsattrbit_t; 403212793Sdim 404212793Sdim#define NFSZERO_ATTRBIT(b) do { (b)->bits[0] = 0; (b)->bits[1] = 0; } while (0) 405212793Sdim#define NFSSET_ATTRBIT(t, f) do { (t)->bits[0] = (f)->bits[0]; \ 406226633Sdim (t)->bits[1] = (f)->bits[1]; } while (0) 407212793Sdim#define NFSSETSUPP_ATTRBIT(b) do { \ 408226633Sdim (b)->bits[0] = NFSATTRBIT_SUPP0; \ 409226633Sdim (b)->bits[1] = (NFSATTRBIT_SUPP1 | NFSATTRBIT_SUPPSETONLY); } while (0) 410212793Sdim#define NFSISSET_ATTRBIT(b, p) ((b)->bits[(p) / 32] & (1 << ((p) % 32))) 411226633Sdim#define NFSSETBIT_ATTRBIT(b, p) ((b)->bits[(p) / 32] |= (1 << ((p) % 32))) 412226633Sdim#define NFSCLRBIT_ATTRBIT(b, p) ((b)->bits[(p) / 32] &= ~(1 << ((p) % 32))) 413226633Sdim#define NFSCLRALL_ATTRBIT(b, a) do { \ 414226633Sdim (b)->bits[0] &= ~((a)->bits[0]); \ 415221345Sdim (b)->bits[1] &= ~((a)->bits[1]); \ 416226633Sdim } while (0) 417212793Sdim#define NFSCLRNOT_ATTRBIT(b, a) do { \ 418221345Sdim (b)->bits[0] &= ((a)->bits[0]); \ 419221345Sdim (b)->bits[1] &= ((a)->bits[1]); \ 420221345Sdim } while (0) 421234353Sdim#define NFSCLRNOTFILLABLE_ATTRBIT(b) do { \ 422226633Sdim (b)->bits[0] &= NFSATTRBIT_SUPP0; \ 423226633Sdim (b)->bits[1] &= NFSATTRBIT_SUPP1; } while (0) 424221345Sdim#define NFSCLRNOTSETABLE_ATTRBIT(b) do { \ 425218893Sdim (b)->bits[0] &= NFSATTRBIT_SETABLE0; \ 426218893Sdim (b)->bits[1] &= NFSATTRBIT_SETABLE1; } while (0) 427218893Sdim#define NFSNONZERO_ATTRBIT(b) ((b)->bits[0] || (b)->bits[1]) 428218893Sdim#define NFSEQUAL_ATTRBIT(b, p) \ 429218893Sdim ((b)->bits[0] == (p)->bits[0] && (b)->bits[1] == (p)->bits[1]) 430218893Sdim#define NFSGETATTR_ATTRBIT(b) do { \ 431218893Sdim (b)->bits[0] = NFSATTRBIT_GETATTR0; \ 432218893Sdim (b)->bits[1] = NFSATTRBIT_GETATTR1; } while (0) 433221345Sdim#define NFSWCCATTR_ATTRBIT(b) do { \ 434212793Sdim (b)->bits[0] = NFSATTRBIT_WCCATTR0; \ 435221345Sdim (b)->bits[1] = NFSATTRBIT_WCCATTR1; } while (0) 436221345Sdim#define NFSWRITEGETATTR_ATTRBIT(b) do { \ 437221345Sdim (b)->bits[0] = NFSATTRBIT_WRITEGETATTR0; \ 438221345Sdim (b)->bits[1] = NFSATTRBIT_WRITEGETATTR1; } while (0) 439218893Sdim#define NFSCBGETATTR_ATTRBIT(b, c) do { \ 440218893Sdim (c)->bits[0] = ((b)->bits[0] & NFSATTRBIT_CBGETATTR0); \ 441234353Sdim (c)->bits[1] = ((b)->bits[1] & NFSATTRBIT_CBGETATTR1); } while (0) 442234353Sdim#define NFSPATHCONF_GETATTRBIT(b) do { \ 443223017Sdim (b)->bits[0] = NFSGETATTRBIT_PATHCONF0; \ 444218893Sdim (b)->bits[1] = NFSGETATTRBIT_PATHCONF1; } while (0) 445218893Sdim#define NFSSTATFS_GETATTRBIT(b) do { \ 446218893Sdim (b)->bits[0] = NFSGETATTRBIT_STATFS0; \ 447221345Sdim (b)->bits[1] = NFSGETATTRBIT_STATFS1; } while (0) 448221345Sdim#define NFSISSETSTATFS_ATTRBIT(b) \ 449234353Sdim (((b)->bits[0] & NFSATTRBIT_STATFS0) || \ 450223017Sdim ((b)->bits[1] & NFSATTRBIT_STATFS1)) 451212793Sdim#define NFSCLRSTATFS_ATTRBIT(b) do { \ 452212793Sdim (b)->bits[0] &= ~NFSATTRBIT_STATFS0; \ 453218893Sdim (b)->bits[1] &= ~NFSATTRBIT_STATFS1; } while (0) 454234353Sdim#define NFSREADDIRPLUS_ATTRBIT(b) do { \ 455212793Sdim (b)->bits[0] = NFSATTRBIT_READDIRPLUS0; \ 456212793Sdim (b)->bits[1] = NFSATTRBIT_READDIRPLUS1; } while (0) 457212793Sdim#define NFSREFERRAL_ATTRBIT(b) do { \ 458221345Sdim (b)->bits[0] = NFSATTRBIT_REFERRAL0; \ 459218893Sdim (b)->bits[1] = NFSATTRBIT_REFERRAL1; } while (0) 460221345Sdim 461234353Sdim/* 462212793Sdim * Store uid, gid creds that handle maps to. 463218893Sdim * Since some BSDen define cr_gid as cr_groups[0], I'll just keep them 464221345Sdim * all in nfsc_groups[NGROUPS + 1]. 465234353Sdim */ 466221345Sdimstruct nfscred { 467212793Sdim uid_t nfsc_uid; 468212793Sdim gid_t nfsc_groups[NGROUPS + 1]; 469221345Sdim int nfsc_ngroups; 470221345Sdim}; 471221345Sdim 472224145Sdim/* 473221345Sdim * Constants that define the file handle for the V4 root directory. 474221345Sdim * (The FSID must never be used by other file systems that are exported.) 475221345Sdim */ 476218893Sdim#define NFSV4ROOT_FSID0 ((int32_t) -1) 477218893Sdim#define NFSV4ROOT_FSID1 ((int32_t) -1) 478218893Sdim#define NFSV4ROOT_REFERRAL ((int32_t) -2) 479218893Sdim#define NFSV4ROOT_INO 2 /* It's traditional */ 480221345Sdim#define NFSV4ROOT_GEN 1 481218893Sdim 482218893Sdim/* 483218893Sdim * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts. 484212793Sdim * What should be in this set is open to debate, but I believe that since 485218893Sdim * I/O system calls on ufs are never interrupted by signals the set should 486218893Sdim * be minimal. My reasoning is that many current programs that use signals 487218893Sdim * such as SIGALRM will not expect file I/O system calls to be interrupted 488212793Sdim * by them and break. 489218893Sdim */ 490218893Sdim#if defined(_KERNEL) || defined(KERNEL) 491218893Sdim 492212793Sdimstruct uio; struct buf; struct vattr; struct nameidata; /* XXX */ 493224145Sdim 494224145Sdim/* 495224145Sdim * Socket errors ignored for connectionless sockets? 496224145Sdim * For now, ignore them all 497224145Sdim */ 498224145Sdim#define NFSIGNORE_SOERROR(s, e) \ 499224145Sdim ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \ 500224145Sdim ((s) & PR_CONNREQUIRED) == 0) 501224145Sdim 502224145Sdim 503224145Sdim/* 504224145Sdim * This structure holds socket information for a connection. Used by the 505224145Sdim * client and the server for callbacks. 506224145Sdim */ 507224145Sdimstruct nfssockreq { 508224145Sdim NFSSOCKADDR_T nr_nam; 509224145Sdim int nr_sotype; 510224145Sdim int nr_soproto; 511218893Sdim int nr_soflags; 512218893Sdim struct ucred *nr_cred; 513218893Sdim int nr_lock; 514218893Sdim NFSMUTEX_T nr_mtx; 515218893Sdim u_int32_t nr_prog; 516221345Sdim u_int32_t nr_vers; 517218893Sdim struct __rpc_client *nr_client; 518218893Sdim}; 519218893Sdim 520212793Sdim/* 521218893Sdim * And associated nr_lock bits. 522218893Sdim */ 523234353Sdim#define NFSR_SNDLOCK 0x01 524218893Sdim#define NFSR_WANTSND 0x02 525218893Sdim#define NFSR_RCVLOCK 0x04 526218893Sdim#define NFSR_WANTRCV 0x08 527212793Sdim#define NFSR_RESERVEDPORT 0x10 528212793Sdim#define NFSR_LOCALHOST 0x20 529218893Sdim 530212793Sdim/* 531218893Sdim * Queue head for nfsreq's 532212793Sdim */ 533212793SdimTAILQ_HEAD(nfsreqhead, nfsreq); 534212793Sdim 535218893Sdim/* First 8 R_xxx flags defined in rpc/rpcclnt.h, the rest are here */ 536218893Sdim#define R_DONTRECOVER 0x00000100 /* don't initiate recovery when this 537218893Sdim rpc gets a stale state reply */ 538218893Sdim 539218893Sdim/* 540212793Sdim * Network address hash list element 541218893Sdim */ 542218893Sdimunion nethostaddr { 543218893Sdim struct in_addr had_inet; 544212793Sdim struct in6_addr had_inet6; 545218893Sdim}; 546226633Sdim 547226633Sdim/* 548218893Sdim * Structure of list of mechanisms. 549218893Sdim */ 550226633Sdimstruct nfsgss_mechlist { 551212793Sdim int len; 552218893Sdim const u_char *str; 553226633Sdim int totlen; 554226633Sdim}; 555212793Sdim#define KERBV_MECH 0 /* position in list */ 556226633Sdim 557226633Sdim/* 558226633Sdim * This structure is used by the server for describing each request. 559226633Sdim */ 560226633Sdimstruct nfsrv_descript { 561226633Sdim mbuf_t nd_mrep; /* Request mbuf list */ 562226633Sdim mbuf_t nd_md; /* Current dissect mbuf */ 563226633Sdim mbuf_t nd_mreq; /* Reply mbuf list */ 564226633Sdim mbuf_t nd_mb; /* Current build mbuf */ 565226633Sdim NFSSOCKADDR_T nd_nam; /* and socket addr */ 566226633Sdim NFSSOCKADDR_T nd_nam2; /* return socket addr */ 567226633Sdim caddr_t nd_dpos; /* Current dissect pos */ 568218893Sdim caddr_t nd_bpos; /* Current build pos */ 569218893Sdim u_int16_t nd_procnum; /* RPC # */ 570212793Sdim u_int32_t nd_flag; /* nd_flag */ 571212793Sdim u_int32_t nd_repstat; /* Reply status */ 572218893Sdim int *nd_errp; /* Pointer to ret status */ 573218893Sdim u_int32_t nd_retxid; /* Reply xid */ 574218893Sdim struct nfsrvcache *nd_rp; /* Assoc. cache entry */ 575212793Sdim struct timeval nd_starttime; /* Time RPC initiated */ 576218893Sdim fhandle_t nd_fh; /* File handle */ 577226633Sdim struct ucred *nd_cred; /* Credentials */ 578221345Sdim uid_t nd_saveduid; /* Saved uid */ 579218893Sdim u_int64_t nd_sockref; /* Rcv socket ref# */ 580218893Sdim u_int64_t nd_compref; /* Compound RPC ref# */ 581218893Sdim time_t nd_tcpconntime; /* Time TCP connection est. */ 582212793Sdim nfsquad_t nd_clientid; /* Implied clientid */ 583218893Sdim int nd_credflavor; /* credential flavor */ 584212793Sdim int nd_gssnamelen; /* principal name length */ 585218893Sdim char *nd_gssname; /* principal name */ 586218893Sdim}; 587218893Sdim 588218893Sdim#define nd_princlen nd_gssnamelen 589212793Sdim#define nd_principal nd_gssname 590212793Sdim 591218893Sdim/* Bits for "nd_flag" */ 592218893Sdim#define ND_DONTSAVEREPLY 0x00000001 593218893Sdim#define ND_SAVEREPLY 0x00000002 594218893Sdim#define ND_NFSV2 0x00000004 595212793Sdim#define ND_NFSV3 0x00000008 596221345Sdim#define ND_NFSV4 0x00000010 597218893Sdim#define ND_KERBV 0x00000020 598218893Sdim#define ND_GSSINTEGRITY 0x00000040 599218893Sdim#define ND_GSSPRIVACY 0x00000080 600212793Sdim#define ND_WINDOWVERF 0x00000100 601212793Sdim#define ND_GSSINITREPLY 0x00000200 602218893Sdim#define ND_STREAMSOCK 0x00000400 603218893Sdim#define ND_PUBLOOKUP 0x00000800 604218893Sdim#define ND_USEGSSNAME 0x00001000 605218893Sdim#define ND_SAMETCPCONN 0x00002000 606218893Sdim#define ND_IMPLIEDCLID 0x00004000 607218893Sdim#define ND_NOMOREDATA 0x00008000 608212793Sdim#define ND_V4WCCATTR 0x00010000 609218893Sdim#define ND_NFSCB 0x00020000 610218893Sdim#define ND_AUTHNONE 0x00040000 611221345Sdim#define ND_EXGSSONLY 0x00080000 612234353Sdim#define ND_INCRSEQID 0x00100000 613218893Sdim 614218893Sdim/* 615218893Sdim * ND_GSS should be the "or" of all GSS type authentications. 616212793Sdim */ 617226633Sdim#define ND_GSS (ND_KERBV) 618221345Sdim 619226633Sdimstruct nfsv4_opflag { 620218893Sdim int retfh; 621218893Sdim int needscfh; 622218893Sdim int savereply; 623212793Sdim int modifyfs; 624212793Sdim}; 625226633Sdim 626226633Sdim/* 627226633Sdim * Flags used to indicate what to do w.r.t. seqid checking. 628226633Sdim */ 629226633Sdim#define NFSRVSEQID_FIRST 0x01 630226633Sdim#define NFSRVSEQID_LAST 0x02 631226633Sdim#define NFSRVSEQID_OPEN 0x04 632226633Sdim 633226633Sdim/* 634226633Sdim * MNT_EXGSSONLY is the Or of all the EXGSS bits. 635226633Sdim */ 636226633Sdim#define MNT_EXGSSONLY MNT_EXGSSKRB5 637226633Sdim 638226633Sdim/* 639226633Sdim * assign a doubly linked list to a new head 640226633Sdim * and prepend one list into another. 641226633Sdim */ 642226633Sdim#define LIST_NEWHEAD(nhead, ohead, field) do { \ 643226633Sdim if (((nhead)->lh_first = (ohead)->lh_first) != NULL) \ 644226633Sdim (ohead)->lh_first->field.le_prev = &(nhead)->lh_first; \ 645226633Sdim (ohead)->lh_first = NULL; \ 646226633Sdim } while (0) 647226633Sdim 648226633Sdim#define LIST_PREPEND(head, phead, lelm, field) do { \ 649226633Sdim if ((head)->lh_first != NULL) { \ 650226633Sdim (lelm)->field.le_next = (head)->lh_first; \ 651226633Sdim (lelm)->field.le_next->field.le_prev = \ 652226633Sdim &(lelm)->field.le_next; \ 653226633Sdim } \ 654226633Sdim (head)->lh_first = (phead)->lh_first; \ 655239462Sdim (head)->lh_first->field.le_prev = &(head)->lh_first; \ 656226633Sdim } while (0) 657226633Sdim 658226633Sdim/* 659226633Sdim * File handle structure for client. Malloc'd to the correct length with 660226633Sdim * malloc type M_NFSFH. 661226633Sdim */ 662226633Sdimstruct nfsfh { 663226633Sdim u_int16_t nfh_len; /* Length of file handle */ 664226633Sdim u_int8_t nfh_fh[1]; /* and the file handle */ 665226633Sdim}; 666234353Sdim 667226633Sdim/* 668226633Sdim * File handle structure for server. The NFSRV_MAXFH constant is 669226633Sdim * set in nfsdport.h. I use a 32bit length, so that alignment is 670226633Sdim * preserved. 671226633Sdim */ 672226633Sdimstruct nfsrvfh { 673226633Sdim u_int32_t nfsrvfh_len; 674226633Sdim u_int8_t nfsrvfh_data[NFSRV_MAXFH]; 675226633Sdim}; 676226633Sdim 677226633Sdim/* 678226633Sdim * This structure is used for sleep locks on the NFSv4 nfsd threads and 679226633Sdim * NFSv4 client data structures. 680226633Sdim */ 681226633Sdimstruct nfsv4lock { 682226633Sdim u_int32_t nfslock_usecnt; 683226633Sdim u_int8_t nfslock_lock; 684226633Sdim}; 685226633Sdim#define NFSV4LOCK_LOCK 0x01 686226633Sdim#define NFSV4LOCK_LOCKWANTED 0x02 687226633Sdim#define NFSV4LOCK_WANTED 0x04 688226633Sdim 689226633Sdim/* 690226633Sdim * Values for the override argument for nfsvno_accchk(). 691226633Sdim */ 692226633Sdim#define NFSACCCHK_NOOVERRIDE 0 693226633Sdim#define NFSACCCHK_ALLOWROOT 1 694226633Sdim#define NFSACCCHK_ALLOWOWNER 2 695226633Sdim 696226633Sdim/* 697226633Sdim * and values for the vpislocked argument for nfsvno_accchk(). 698226633Sdim */ 699226633Sdim#define NFSACCCHK_VPNOTLOCKED 0 700226633Sdim#define NFSACCCHK_VPISLOCKED 1 701226633Sdim 702226633Sdim#endif /* _KERNEL */ 703226633Sdim 704226633Sdim#endif /* _NFS_NFS_H */ 705226633Sdim