1 /* $OpenBSD: nfs.h,v 1.53 2017/02/22 11:42:46 mpi Exp $ */ 2 /* $NetBSD: nfs.h,v 1.10.4.1 1996/05/27 11:23:56 fvdl Exp $ */ 3 4 /* 5 * Copyright (c) 1989, 1993, 1995 6 * The Regents of the University of California. All rights reserved. 7 * 8 * This code is derived from software contributed to Berkeley by 9 * Rick Macklem at The University of Guelph. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. Neither the name of the University nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 * 35 * @(#)nfs.h 8.4 (Berkeley) 5/1/95 36 */ 37 38 #ifndef _NFS_NFS_H_ 39 #define _NFS_NFS_H_ 40 41 #define NFS_TICKINTVL 5 /* Desired time for a tick (msec) */ 42 #define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */ 43 #define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */ 44 #define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */ 45 #define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */ 46 #define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/ 47 #define NFS_TIMEOUTMUL 2 /* Timeout/Delay multiplier */ 48 #define NFS_MAXREXMIT 100 /* Stop counting after this many */ 49 #define NFS_RETRANS 10 /* Num of retrans for soft mounts */ 50 #define NFS_MAXGRPS 16 /* Max. size of groups list */ 51 #define NFS_MINATTRTIMO 5 /* Attribute cache timeout in sec */ 52 #define NFS_MAXATTRTIMO 60 53 #define NFS_WSIZE 8192 /* Def. write data size <= 8192 */ 54 #define NFS_RSIZE 8192 /* Def. read data size <= 8192 */ 55 #define NFS_READDIRSIZE 8192 /* Def. readdir size */ 56 #define NFS_DEFRAHEAD 1 /* Def. read ahead # blocks */ 57 #define NFS_MAXRAHEAD 4 /* Max. read ahead # blocks */ 58 #define NFS_MAXASYNCDAEMON 20 /* Max. number async_daemons runable */ 59 60 /* 61 * Ideally, NFS_DIRBLKSIZ should be bigger, but I've seen servers with 62 * broken NFS/ethernet drivers that won't work with anything bigger (Linux..) 63 */ 64 #define NFS_DIRBLKSIZ 1024 /* Must be a multiple of DIRBLKSIZ */ 65 #define NFS_READDIRBLKSIZ 512 /* Size of read dir blocks. XXX */ 66 67 /* 68 * Oddballs 69 */ 70 #define NFS_CMPFH(n, f, s) \ 71 ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s))) 72 #define NFS_ISV3(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3) 73 #define NFS_SRVMAXDATA(n) \ 74 (((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \ 75 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA) 76 77 /* 78 * sys/malloc.h needs M_NFSDIROFF, M_NFSRVDESC and M_NFSBIGFH added. 79 */ 80 #ifndef M_NFSRVDESC 81 #define M_NFSRVDESC M_TEMP 82 #endif 83 #ifndef M_NFSDIROFF 84 #define M_NFSDIROFF M_TEMP 85 #endif 86 #ifndef M_NFSBIGFH 87 #define M_NFSBIGFH M_TEMP 88 #endif 89 90 /* 91 * The B_INVAFTERWRITE flag should be set to whatever is required by the 92 * buffer cache code to say "Invalidate the block after it is written back". 93 */ 94 #define B_INVAFTERWRITE B_INVAL 95 96 /* 97 * Structures for the nfssvc(2) syscall. 98 * Not that anyone besides nfsd(8) should ever use it. 99 */ 100 struct nfsd_args { 101 int sock; /* Socket to serve */ 102 caddr_t name; /* Client addr for connection based sockets */ 103 int namelen; /* Length of name */ 104 }; 105 106 struct nfsd_srvargs { 107 struct nfsd *nsd_nfsd; /* Pointer to in kernel nfsd struct */ 108 uid_t nsd_uid; /* Effective uid mapped to cred */ 109 u_int32_t nsd_haddr; /* IP address of client */ 110 struct xucred nsd_cr; /* Cred. uid maps to */ 111 int nsd_authlen; /* Length of auth string (ret) */ 112 u_char *nsd_authstr; /* Auth string (ret) */ 113 int nsd_verflen; /* and the verifier */ 114 u_char *nsd_verfstr; 115 struct timeval nsd_timestamp; /* timestamp from verifier */ 116 u_int32_t nsd_ttl; /* credential ttl (sec) */ 117 }; 118 119 /* 120 * Stats structure 121 */ 122 struct nfsstats { 123 uint64_t attrcache_hits; 124 uint64_t attrcache_misses; 125 uint64_t lookupcache_hits; 126 uint64_t lookupcache_misses; 127 uint64_t direofcache_hits; 128 uint64_t direofcache_misses; 129 uint64_t biocache_reads; 130 uint64_t read_bios; 131 uint64_t read_physios; 132 uint64_t biocache_writes; 133 uint64_t write_bios; 134 uint64_t write_physios; 135 uint64_t biocache_readlinks; 136 uint64_t readlink_bios; 137 uint64_t biocache_readdirs; 138 uint64_t readdir_bios; 139 uint64_t rpccnt[NFS_NPROCS]; 140 uint64_t rpcretries; 141 uint64_t srvrpccnt[NFS_NPROCS]; 142 uint64_t srvrpc_errs; 143 uint64_t srv_errs; 144 uint64_t rpcrequests; 145 uint64_t rpctimeouts; 146 uint64_t rpcunexpected; 147 uint64_t rpcinvalid; 148 uint64_t srvcache_inproghits; 149 uint64_t srvcache_idemdonehits; 150 uint64_t srvcache_nonidemdonehits; 151 uint64_t srvcache_misses; 152 uint64_t forcedsync; 153 uint64_t srvnqnfs_leases; 154 uint64_t srvnqnfs_maxleases; 155 uint64_t srvnqnfs_getleases; 156 uint64_t srvvop_writes; 157 }; 158 159 /* 160 * Flags for nfssvc() system call. 161 */ 162 #define NFSSVC_BIOD 0x002 163 #define NFSSVC_NFSD 0x004 164 #define NFSSVC_ADDSOCK 0x008 165 #define NFSSVC_AUTHIN 0x010 166 #define NFSSVC_GOTAUTH 0x040 167 #define NFSSVC_AUTHINFAIL 0x080 168 #define NFSSVC_MNTD 0x100 169 170 /* 171 * fs.nfs sysctl(3) identifiers 172 */ 173 #define NFS_NFSSTATS 1 /* struct: struct nfsstats */ 174 #define NFS_NIOTHREADS 2 /* number of i/o threads */ 175 #define NFS_MAXID 3 176 177 #define FS_NFS_NAMES { \ 178 { 0, 0 }, \ 179 { "nfsstats", CTLTYPE_STRUCT }, \ 180 { "iothreads", CTLTYPE_INT } \ 181 } 182 183 /* 184 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts. 185 * What should be in this set is open to debate, but I believe that since 186 * I/O system calls on ufs are never interrupted by signals the set should 187 * be minimal. My reasoning is that many current programs that use signals 188 * such as SIGALRM will not expect file I/O system calls to be interrupted 189 * by them and break. 190 */ 191 #ifdef _KERNEL 192 extern int nfs_niothreads; 193 194 struct uio; struct buf; struct vattr; struct nameidata; /* XXX */ 195 196 #define NFSINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \ 197 sigmask(SIGHUP)|sigmask(SIGQUIT)) 198 199 /* 200 * Socket errors ignored for connectionless sockets?? 201 * For now, ignore them all 202 */ 203 #define NFSIGNORE_SOERROR(s, e) \ 204 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \ 205 ((s) & PR_CONNREQUIRED) == 0) 206 207 /* 208 * Nfs outstanding request list element 209 */ 210 struct nfsreq { 211 TAILQ_ENTRY(nfsreq) r_chain; 212 struct mbuf *r_mreq; 213 struct mbuf *r_mrep; 214 struct mbuf *r_md; 215 caddr_t r_dpos; 216 struct nfsmount *r_nmp; 217 struct vnode *r_vp; 218 u_int32_t r_xid; 219 int r_flags; /* flags on request, see below */ 220 int r_rexmit; /* current retrans count */ 221 int r_timer; /* tick counter on reply */ 222 int r_procnum; /* NFS procedure number */ 223 int r_rtt; /* RTT for rpc */ 224 struct proc *r_procp; /* Proc that did I/O system call */ 225 }; 226 227 /* Flag values for r_flags */ 228 #define R_TIMING 0x01 /* timing request (in mntp) */ 229 #define R_SENT 0x02 /* request has been sent */ 230 #define R_SOFTTERM 0x04 /* soft mnt, too many retries */ 231 #define R_INTR 0x08 /* intr mnt, signal pending */ 232 #define R_SOCKERR 0x10 /* Fatal error on socket */ 233 #define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */ 234 #define R_MUSTRESEND 0x40 /* Must resend request */ 235 236 /* 237 * On fast networks, the estimator will try to reduce the 238 * timeout lower than the latency of the server's disks, 239 * which results in too many timeouts, so cap the lower 240 * bound. 241 */ 242 #define NFS_MINRTO (NFS_HZ >> 2) 243 244 /* 245 * Keep the RTO from increasing to unreasonably large values 246 * when a server is not responding. 247 */ 248 #define NFS_MAXRTO (20 * NFS_HZ) 249 250 enum nfs_rto_timers { 251 NFS_DEFAULT_TIMER, 252 NFS_GETATTR_TIMER, 253 NFS_LOOKUP_TIMER, 254 NFS_READ_TIMER, 255 NFS_WRITE_TIMER, 256 }; 257 #define NFS_MAX_TIMER (NFS_WRITE_TIMER) 258 259 #define NFS_INITRTT (NFS_HZ << 3) 260 261 /* 262 * Network address hash list element 263 */ 264 union nethostaddr { 265 u_int32_t had_inetaddr; 266 struct mbuf *had_nam; 267 }; 268 269 struct nfssvc_sock { 270 TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */ 271 struct file *ns_fp; /* fp from the... */ 272 struct socket *ns_so; /* ...socket this struct wraps */ 273 struct mbuf *ns_nam; /* MT_SONAME of client */ 274 struct mbuf *ns_raw; /* head of unpeeked mbufs */ 275 struct mbuf *ns_rawend; /* tail of unpeeked mbufs */ 276 struct mbuf *ns_rec; /* queued RPC records */ 277 struct mbuf *ns_recend; /* last queued RPC record */ 278 struct mbuf *ns_frag; /* end of record fragment */ 279 int ns_flag; /* socket status flags */ 280 int ns_solock; /* lock for connected socket */ 281 int ns_cc; /* actual chars queued */ 282 int ns_reclen; /* length of first queued record */ 283 u_int32_t ns_sref; /* # of refs to this struct */ 284 }; 285 286 /* Bits for "ns_flag" */ 287 #define SLP_VALID 0x01 /* connection is usable */ 288 #define SLP_DOREC 0x02 /* receive operation required */ 289 #define SLP_NEEDQ 0x04 /* connection has data to queue from socket */ 290 #define SLP_DISCONN 0x08 /* connection is closed */ 291 #define SLP_GETSTREAM 0x10 /* extracting RPC from TCP connection */ 292 #define SLP_LASTFRAG 0x20 /* last fragment received on TCP connection */ 293 #define SLP_ALLFLAGS 0xff /* convenience */ 294 295 /* 296 * One of these structures is allocated for each nfsd. 297 */ 298 struct nfsd { 299 TAILQ_ENTRY(nfsd) nfsd_chain; /* List of all nfsd's */ 300 int nfsd_flag; /* NFSD_ flags */ 301 struct nfssvc_sock *nfsd_slp; /* Current socket */ 302 struct proc *nfsd_procp; /* Proc ptr */ 303 struct nfsrv_descript *nfsd_nd; /* Associated nfsrv_descript */ 304 }; 305 306 /* Bits for "nfsd_flag" */ 307 #define NFSD_WAITING 0x01 308 #define NFSD_REQINPROG 0x02 309 #define NFSD_NEEDAUTH 0x04 310 #define NFSD_AUTHFAIL 0x08 311 312 /* 313 * This structure is used by the server for describing each request. 314 */ 315 struct nfsrv_descript { 316 struct mbuf *nd_mrep; /* Request mbuf list */ 317 struct mbuf *nd_md; /* Current dissect mbuf */ 318 struct mbuf *nd_nam; /* and socket addr */ 319 struct mbuf *nd_nam2; /* return socket addr */ 320 caddr_t nd_dpos; /* Current dissect pos */ 321 unsigned int nd_procnum; /* RPC # */ 322 int nd_flag; /* nd_flag */ 323 int nd_repstat; /* Reply status */ 324 u_int32_t nd_retxid; /* Reply xid */ 325 struct ucred nd_cr; /* Credentials */ 326 }; 327 328 /* Bits for "nd_flag" */ 329 #define ND_NFSV3 0x08 330 331 extern struct pool nfsreqpl; 332 extern struct pool nfs_node_pool; 333 extern TAILQ_HEAD(nfsdhead, nfsd) nfsd_head; 334 extern int nfsd_head_flag; 335 #define NFSD_CHECKSLP 0x01 336 337 #endif /* _KERNEL */ 338 #endif /* _NFS_NFS_H */ 339