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