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