1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1989, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * 5df8bae1dSRodney W. Grimes * This code is derived from software contributed to Berkeley by 6df8bae1dSRodney W. Grimes * Rick Macklem at The University of Guelph. 7df8bae1dSRodney W. Grimes * 8df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 9df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 10df8bae1dSRodney W. Grimes * are met: 11df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 12df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 13df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 14df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 15df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 16df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 17df8bae1dSRodney W. Grimes * must display the following acknowledgement: 18df8bae1dSRodney W. Grimes * This product includes software developed by the University of 19df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 20df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 21df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 22df8bae1dSRodney W. Grimes * without specific prior written permission. 23df8bae1dSRodney W. Grimes * 24df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34df8bae1dSRodney W. Grimes * SUCH DAMAGE. 35df8bae1dSRodney W. Grimes * 36df8bae1dSRodney W. Grimes * @(#)nfs.h 8.1 (Berkeley) 6/10/93 37df8bae1dSRodney W. Grimes */ 38df8bae1dSRodney W. Grimes 39df8bae1dSRodney W. Grimes /* 40df8bae1dSRodney W. Grimes * Tunable constants for nfs 41df8bae1dSRodney W. Grimes */ 42df8bae1dSRodney W. Grimes 43df8bae1dSRodney W. Grimes #define NFS_MAXIOVEC 34 44df8bae1dSRodney W. Grimes #define NFS_HZ 25 /* Ticks per second for NFS timeouts */ 45df8bae1dSRodney W. Grimes #define NFS_TIMEO (1*NFS_HZ) /* Default timeout = 1 second */ 46df8bae1dSRodney W. Grimes #define NFS_MINTIMEO (1*NFS_HZ) /* Min timeout to use */ 47df8bae1dSRodney W. Grimes #define NFS_MAXTIMEO (60*NFS_HZ) /* Max timeout to backoff to */ 48df8bae1dSRodney W. Grimes #define NFS_MINIDEMTIMEO (5*NFS_HZ) /* Min timeout for non-idempotent ops*/ 49df8bae1dSRodney W. Grimes #define NFS_MAXREXMIT 100 /* Stop counting after this many */ 50df8bae1dSRodney W. Grimes #define NFS_MAXWINDOW 1024 /* Max number of outstanding requests */ 51df8bae1dSRodney W. Grimes #define NFS_RETRANS 10 /* Num of retrans for soft mounts */ 52df8bae1dSRodney W. Grimes #define NFS_MAXGRPS 16 /* Max. size of groups list */ 53df8bae1dSRodney W. Grimes #define NFS_MINATTRTIMO 5 /* Attribute cache timeout in sec */ 54df8bae1dSRodney W. Grimes #define NFS_MAXATTRTIMO 60 55df8bae1dSRodney W. Grimes #define NFS_WSIZE 8192 /* Def. write data size <= 8192 */ 56df8bae1dSRodney W. Grimes #define NFS_RSIZE 8192 /* Def. read data size <= 8192 */ 57df8bae1dSRodney W. Grimes #define NFS_DEFRAHEAD 1 /* Def. read ahead # blocks */ 58df8bae1dSRodney W. Grimes #define NFS_MAXRAHEAD 4 /* Max. read ahead # blocks */ 59df8bae1dSRodney W. Grimes #define NFS_MAXREADDIR NFS_MAXDATA /* Max. size of directory read */ 60df8bae1dSRodney W. Grimes #define NFS_MAXUIDHASH 64 /* Max. # of hashed uid entries/mp */ 61df8bae1dSRodney W. Grimes #define NFS_MAXASYNCDAEMON 20 /* Max. number async_daemons runable */ 62df8bae1dSRodney W. Grimes #define NFS_DIRBLKSIZ 1024 /* Size of an NFS directory block */ 63df8bae1dSRodney W. Grimes #define NMOD(a) ((a) % nfs_asyncdaemons) 64df8bae1dSRodney W. Grimes 65df8bae1dSRodney W. Grimes /* 66df8bae1dSRodney W. Grimes * Set the attribute timeout based on how recently the file has been modified. 67df8bae1dSRodney W. Grimes */ 68df8bae1dSRodney W. Grimes #define NFS_ATTRTIMEO(np) \ 69df8bae1dSRodney W. Grimes ((((np)->n_flag & NMODIFIED) || \ 70df8bae1dSRodney W. Grimes (time.tv_sec - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \ 71df8bae1dSRodney W. Grimes ((time.tv_sec - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \ 72df8bae1dSRodney W. Grimes (time.tv_sec - (np)->n_mtime) / 10)) 73df8bae1dSRodney W. Grimes 74df8bae1dSRodney W. Grimes /* 75df8bae1dSRodney W. Grimes * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs 76df8bae1dSRodney W. Grimes * should ever try and use it. 77df8bae1dSRodney W. Grimes */ 78df8bae1dSRodney W. Grimes struct nfsd_args { 79df8bae1dSRodney W. Grimes int sock; /* Socket to serve */ 80df8bae1dSRodney W. Grimes caddr_t name; /* Client address for connection based sockets */ 81df8bae1dSRodney W. Grimes int namelen; /* Length of name */ 82df8bae1dSRodney W. Grimes }; 83df8bae1dSRodney W. Grimes 84df8bae1dSRodney W. Grimes struct nfsd_srvargs { 85df8bae1dSRodney W. Grimes struct nfsd *nsd_nfsd; /* Pointer to in kernel nfsd struct */ 86df8bae1dSRodney W. Grimes uid_t nsd_uid; /* Effective uid mapped to cred */ 87df8bae1dSRodney W. Grimes u_long nsd_haddr; /* Ip address of client */ 88df8bae1dSRodney W. Grimes struct ucred nsd_cr; /* Cred. uid maps to */ 89df8bae1dSRodney W. Grimes int nsd_authlen; /* Length of auth string (ret) */ 90df8bae1dSRodney W. Grimes char *nsd_authstr; /* Auth string (ret) */ 91df8bae1dSRodney W. Grimes }; 92df8bae1dSRodney W. Grimes 93df8bae1dSRodney W. Grimes struct nfsd_cargs { 94df8bae1dSRodney W. Grimes char *ncd_dirp; /* Mount dir path */ 95df8bae1dSRodney W. Grimes uid_t ncd_authuid; /* Effective uid */ 96df8bae1dSRodney W. Grimes int ncd_authtype; /* Type of authenticator */ 97df8bae1dSRodney W. Grimes int ncd_authlen; /* Length of authenticator string */ 98df8bae1dSRodney W. Grimes char *ncd_authstr; /* Authenticator string */ 99df8bae1dSRodney W. Grimes }; 100df8bae1dSRodney W. Grimes 101df8bae1dSRodney W. Grimes /* 102df8bae1dSRodney W. Grimes * Stats structure 103df8bae1dSRodney W. Grimes */ 104df8bae1dSRodney W. Grimes struct nfsstats { 105df8bae1dSRodney W. Grimes int attrcache_hits; 106df8bae1dSRodney W. Grimes int attrcache_misses; 107df8bae1dSRodney W. Grimes int lookupcache_hits; 108df8bae1dSRodney W. Grimes int lookupcache_misses; 109df8bae1dSRodney W. Grimes int direofcache_hits; 110df8bae1dSRodney W. Grimes int direofcache_misses; 111df8bae1dSRodney W. Grimes int biocache_reads; 112df8bae1dSRodney W. Grimes int read_bios; 113df8bae1dSRodney W. Grimes int read_physios; 114df8bae1dSRodney W. Grimes int biocache_writes; 115df8bae1dSRodney W. Grimes int write_bios; 116df8bae1dSRodney W. Grimes int write_physios; 117df8bae1dSRodney W. Grimes int biocache_readlinks; 118df8bae1dSRodney W. Grimes int readlink_bios; 119df8bae1dSRodney W. Grimes int biocache_readdirs; 120df8bae1dSRodney W. Grimes int readdir_bios; 121df8bae1dSRodney W. Grimes int rpccnt[NFS_NPROCS]; 122df8bae1dSRodney W. Grimes int rpcretries; 123df8bae1dSRodney W. Grimes int srvrpccnt[NFS_NPROCS]; 124df8bae1dSRodney W. Grimes int srvrpc_errs; 125df8bae1dSRodney W. Grimes int srv_errs; 126df8bae1dSRodney W. Grimes int rpcrequests; 127df8bae1dSRodney W. Grimes int rpctimeouts; 128df8bae1dSRodney W. Grimes int rpcunexpected; 129df8bae1dSRodney W. Grimes int rpcinvalid; 130df8bae1dSRodney W. Grimes int srvcache_inproghits; 131df8bae1dSRodney W. Grimes int srvcache_idemdonehits; 132df8bae1dSRodney W. Grimes int srvcache_nonidemdonehits; 133df8bae1dSRodney W. Grimes int srvcache_misses; 134df8bae1dSRodney W. Grimes int srvnqnfs_leases; 135df8bae1dSRodney W. Grimes int srvnqnfs_maxleases; 136df8bae1dSRodney W. Grimes int srvnqnfs_getleases; 137df8bae1dSRodney W. Grimes }; 138df8bae1dSRodney W. Grimes 139df8bae1dSRodney W. Grimes /* 140df8bae1dSRodney W. Grimes * Flags for nfssvc() system call. 141df8bae1dSRodney W. Grimes */ 142df8bae1dSRodney W. Grimes #define NFSSVC_BIOD 0x002 143df8bae1dSRodney W. Grimes #define NFSSVC_NFSD 0x004 144df8bae1dSRodney W. Grimes #define NFSSVC_ADDSOCK 0x008 145df8bae1dSRodney W. Grimes #define NFSSVC_AUTHIN 0x010 146df8bae1dSRodney W. Grimes #define NFSSVC_GOTAUTH 0x040 147df8bae1dSRodney W. Grimes #define NFSSVC_AUTHINFAIL 0x080 148df8bae1dSRodney W. Grimes #define NFSSVC_MNTD 0x100 149df8bae1dSRodney W. Grimes 150df8bae1dSRodney W. Grimes /* 151df8bae1dSRodney W. Grimes * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts. 152df8bae1dSRodney W. Grimes * What should be in this set is open to debate, but I believe that since 153df8bae1dSRodney W. Grimes * I/O system calls on ufs are never interrupted by signals the set should 154df8bae1dSRodney W. Grimes * be minimal. My reasoning is that many current programs that use signals 155df8bae1dSRodney W. Grimes * such as SIGALRM will not expect file I/O system calls to be interrupted 156df8bae1dSRodney W. Grimes * by them and break. 157df8bae1dSRodney W. Grimes */ 158df8bae1dSRodney W. Grimes #ifdef KERNEL 159df8bae1dSRodney W. Grimes #define NFSINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \ 160df8bae1dSRodney W. Grimes sigmask(SIGHUP)|sigmask(SIGQUIT)) 161df8bae1dSRodney W. Grimes 162df8bae1dSRodney W. Grimes /* 163df8bae1dSRodney W. Grimes * Socket errors ignored for connectionless sockets?? 164df8bae1dSRodney W. Grimes * For now, ignore them all 165df8bae1dSRodney W. Grimes */ 166df8bae1dSRodney W. Grimes #define NFSIGNORE_SOERROR(s, e) \ 167df8bae1dSRodney W. Grimes ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \ 168df8bae1dSRodney W. Grimes ((s) & PR_CONNREQUIRED) == 0) 169df8bae1dSRodney W. Grimes 170df8bae1dSRodney W. Grimes /* 171df8bae1dSRodney W. Grimes * Nfs outstanding request list element 172df8bae1dSRodney W. Grimes */ 173df8bae1dSRodney W. Grimes struct nfsreq { 174df8bae1dSRodney W. Grimes struct nfsreq *r_next; 175df8bae1dSRodney W. Grimes struct nfsreq *r_prev; 176df8bae1dSRodney W. Grimes struct mbuf *r_mreq; 177df8bae1dSRodney W. Grimes struct mbuf *r_mrep; 178df8bae1dSRodney W. Grimes struct mbuf *r_md; 179df8bae1dSRodney W. Grimes caddr_t r_dpos; 180df8bae1dSRodney W. Grimes struct nfsmount *r_nmp; 181df8bae1dSRodney W. Grimes struct vnode *r_vp; 182df8bae1dSRodney W. Grimes u_long r_xid; 183df8bae1dSRodney W. Grimes int r_flags; /* flags on request, see below */ 184df8bae1dSRodney W. Grimes int r_retry; /* max retransmission count */ 185df8bae1dSRodney W. Grimes int r_rexmit; /* current retrans count */ 186df8bae1dSRodney W. Grimes int r_timer; /* tick counter on reply */ 187df8bae1dSRodney W. Grimes int r_procnum; /* NFS procedure number */ 188df8bae1dSRodney W. Grimes int r_rtt; /* RTT for rpc */ 189df8bae1dSRodney W. Grimes struct proc *r_procp; /* Proc that did I/O system call */ 190df8bae1dSRodney W. Grimes }; 191df8bae1dSRodney W. Grimes 192df8bae1dSRodney W. Grimes /* Flag values for r_flags */ 193df8bae1dSRodney W. Grimes #define R_TIMING 0x01 /* timing request (in mntp) */ 194df8bae1dSRodney W. Grimes #define R_SENT 0x02 /* request has been sent */ 195df8bae1dSRodney W. Grimes #define R_SOFTTERM 0x04 /* soft mnt, too many retries */ 196df8bae1dSRodney W. Grimes #define R_INTR 0x08 /* intr mnt, signal pending */ 197df8bae1dSRodney W. Grimes #define R_SOCKERR 0x10 /* Fatal error on socket */ 198df8bae1dSRodney W. Grimes #define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */ 199df8bae1dSRodney W. Grimes #define R_MUSTRESEND 0x40 /* Must resend request */ 200df8bae1dSRodney W. Grimes #define R_GETONEREP 0x80 /* Probe for one reply only */ 201df8bae1dSRodney W. Grimes 202df8bae1dSRodney W. Grimes struct nfsstats nfsstats; 203df8bae1dSRodney W. Grimes 204df8bae1dSRodney W. Grimes /* 205df8bae1dSRodney W. Grimes * A list of nfssvc_sock structures is maintained with all the sockets 206df8bae1dSRodney W. Grimes * that require service by the nfsd. 207df8bae1dSRodney W. Grimes * The nfsuid structs hang off of the nfssvc_sock structs in both lru 208df8bae1dSRodney W. Grimes * and uid hash lists. 209df8bae1dSRodney W. Grimes */ 210df8bae1dSRodney W. Grimes #define NUIDHASHSIZ 32 211df8bae1dSRodney W. Grimes #define NUIDHASH(uid) ((uid) & (NUIDHASHSIZ - 1)) 212df8bae1dSRodney W. Grimes 213df8bae1dSRodney W. Grimes /* 214df8bae1dSRodney W. Grimes * Network address hash list element 215df8bae1dSRodney W. Grimes */ 216df8bae1dSRodney W. Grimes union nethostaddr { 217df8bae1dSRodney W. Grimes u_long had_inetaddr; 218df8bae1dSRodney W. Grimes struct mbuf *had_nam; 219df8bae1dSRodney W. Grimes }; 220df8bae1dSRodney W. Grimes 221df8bae1dSRodney W. Grimes struct nfsuid { 222df8bae1dSRodney W. Grimes struct nfsuid *nu_lrunext; /* MUST be first */ 223df8bae1dSRodney W. Grimes struct nfsuid *nu_lruprev; 224df8bae1dSRodney W. Grimes struct nfsuid *nu_hnext; 225df8bae1dSRodney W. Grimes struct nfsuid *nu_hprev; 226df8bae1dSRodney W. Grimes int nu_flag; /* Flags */ 227df8bae1dSRodney W. Grimes uid_t nu_uid; /* Uid mapped by this entry */ 228df8bae1dSRodney W. Grimes union nethostaddr nu_haddr; /* Host addr. for dgram sockets */ 229df8bae1dSRodney W. Grimes struct ucred nu_cr; /* Cred uid mapped to */ 230df8bae1dSRodney W. Grimes }; 231df8bae1dSRodney W. Grimes 232df8bae1dSRodney W. Grimes #define nu_inetaddr nu_haddr.had_inetaddr 233df8bae1dSRodney W. Grimes #define nu_nam nu_haddr.had_nam 234df8bae1dSRodney W. Grimes /* Bits for nu_flag */ 235df8bae1dSRodney W. Grimes #define NU_INETADDR 0x1 236df8bae1dSRodney W. Grimes 237df8bae1dSRodney W. Grimes struct nfssvc_sock { 238df8bae1dSRodney W. Grimes struct nfsuid *ns_lrunext; /* MUST be first */ 239df8bae1dSRodney W. Grimes struct nfsuid *ns_lruprev; 240df8bae1dSRodney W. Grimes struct nfssvc_sock *ns_next; 241df8bae1dSRodney W. Grimes struct nfssvc_sock *ns_prev; 242df8bae1dSRodney W. Grimes int ns_flag; 243df8bae1dSRodney W. Grimes u_long ns_sref; 244df8bae1dSRodney W. Grimes struct file *ns_fp; 245df8bae1dSRodney W. Grimes struct socket *ns_so; 246df8bae1dSRodney W. Grimes int ns_solock; 247df8bae1dSRodney W. Grimes struct mbuf *ns_nam; 248df8bae1dSRodney W. Grimes int ns_cc; 249df8bae1dSRodney W. Grimes struct mbuf *ns_raw; 250df8bae1dSRodney W. Grimes struct mbuf *ns_rawend; 251df8bae1dSRodney W. Grimes int ns_reclen; 252df8bae1dSRodney W. Grimes struct mbuf *ns_rec; 253df8bae1dSRodney W. Grimes struct mbuf *ns_recend; 254df8bae1dSRodney W. Grimes int ns_numuids; 255df8bae1dSRodney W. Grimes struct nfsuid *ns_uidh[NUIDHASHSIZ]; 256df8bae1dSRodney W. Grimes }; 257df8bae1dSRodney W. Grimes 258df8bae1dSRodney W. Grimes /* Bits for "ns_flag" */ 259df8bae1dSRodney W. Grimes #define SLP_VALID 0x01 260df8bae1dSRodney W. Grimes #define SLP_DOREC 0x02 261df8bae1dSRodney W. Grimes #define SLP_NEEDQ 0x04 262df8bae1dSRodney W. Grimes #define SLP_DISCONN 0x08 263df8bae1dSRodney W. Grimes #define SLP_GETSTREAM 0x10 264df8bae1dSRodney W. Grimes #define SLP_INIT 0x20 265df8bae1dSRodney W. Grimes #define SLP_WANTINIT 0x40 266df8bae1dSRodney W. Grimes 267df8bae1dSRodney W. Grimes #define SLP_ALLFLAGS 0xff 268df8bae1dSRodney W. Grimes 269df8bae1dSRodney W. Grimes /* 270df8bae1dSRodney W. Grimes * One of these structures is allocated for each nfsd. 271df8bae1dSRodney W. Grimes */ 272df8bae1dSRodney W. Grimes struct nfsd { 273df8bae1dSRodney W. Grimes struct nfsd *nd_next; /* Must be first */ 274df8bae1dSRodney W. Grimes struct nfsd *nd_prev; 275df8bae1dSRodney W. Grimes int nd_flag; /* NFSD_ flags */ 276df8bae1dSRodney W. Grimes struct nfssvc_sock *nd_slp; /* Current socket */ 277df8bae1dSRodney W. Grimes struct mbuf *nd_nam; /* Client addr for datagram req. */ 278df8bae1dSRodney W. Grimes struct mbuf *nd_mrep; /* Req. mbuf list */ 279df8bae1dSRodney W. Grimes struct mbuf *nd_md; 280df8bae1dSRodney W. Grimes caddr_t nd_dpos; /* Position in list */ 281df8bae1dSRodney W. Grimes int nd_procnum; /* RPC procedure number */ 282df8bae1dSRodney W. Grimes u_long nd_retxid; /* RPC xid */ 283df8bae1dSRodney W. Grimes int nd_repstat; /* Reply status value */ 284df8bae1dSRodney W. Grimes struct ucred nd_cr; /* Credentials for req. */ 285df8bae1dSRodney W. Grimes int nd_nqlflag; /* Leasing flag */ 286df8bae1dSRodney W. Grimes int nd_duration; /* Lease duration */ 287df8bae1dSRodney W. Grimes int nd_authlen; /* Authenticator len */ 288df8bae1dSRodney W. Grimes u_char nd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */ 289df8bae1dSRodney W. Grimes struct proc *nd_procp; /* Proc ptr */ 290df8bae1dSRodney W. Grimes }; 291df8bae1dSRodney W. Grimes 292df8bae1dSRodney W. Grimes #define NFSD_WAITING 0x01 293df8bae1dSRodney W. Grimes #define NFSD_CHECKSLP 0x02 294df8bae1dSRodney W. Grimes #define NFSD_REQINPROG 0x04 295df8bae1dSRodney W. Grimes #define NFSD_NEEDAUTH 0x08 296df8bae1dSRodney W. Grimes #define NFSD_AUTHFAIL 0x10 297df8bae1dSRodney W. Grimes #endif /* KERNEL */ 298