1 /* $OpenBSD: nfs.h,v 1.38 2009/01/24 23:35:47 thib 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 /* 42 * Tunable constants for nfs 43 */ 44 45 #define NFS_MAXIOVEC 34 46 #define NFS_TICKINTVL 5 /* Desired time for a tick (msec) */ 47 #define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */ 48 #define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */ 49 #define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */ 50 #define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */ 51 #define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/ 52 #define NFS_TIMEOUTMUL 2 /* Timeout/Delay multiplier */ 53 #define NFS_MAXREXMIT 100 /* Stop counting after this many */ 54 #define NFS_MAXWINDOW 1024 /* Max number of outstanding requests */ 55 #define NFS_RETRANS 10 /* Num of retrans for soft mounts */ 56 #define NFS_MAXGRPS 16 /* Max. size of groups list */ 57 #ifndef NFS_MINATTRTIMO 58 #define NFS_MINATTRTIMO 5 /* Attribute cache timeout in sec */ 59 #endif 60 #ifndef NFS_MAXATTRTIMO 61 #define NFS_MAXATTRTIMO 60 62 #endif 63 #define NFS_WSIZE 8192 /* Def. write data size <= 8192 */ 64 #define NFS_RSIZE 8192 /* Def. read data size <= 8192 */ 65 #define NFS_READDIRSIZE 8192 /* Def. readdir size */ 66 #define NFS_DEFRAHEAD 1 /* Def. read ahead # blocks */ 67 #define NFS_MAXRAHEAD 4 /* Max. read ahead # blocks */ 68 #define NFS_MAXASYNCDAEMON 20 /* Max. number async_daemons runable */ 69 #define NFS_MAXGATHERDELAY 100 /* Max. write gather delay (msec) */ 70 #ifndef NFS_GATHERDELAY 71 #define NFS_GATHERDELAY 10 /* Default write gather delay (msec) */ 72 #endif 73 /* 74 * Ideally, NFS_DIRBLKSIZ should be bigger, but I've seen servers with 75 * broken NFS/ethernet drivers that won't work with anything bigger (Linux..) 76 */ 77 #define NFS_DIRBLKSIZ 1024 /* Must be a multiple of DIRBLKSIZ */ 78 #define NFS_READDIRBLKSIZ 512 /* Size of read dir blocks. XXX */ 79 80 /* 81 * Oddballs 82 */ 83 #define NFS_CMPFH(n, f, s) \ 84 ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s))) 85 #define NFS_ISV3(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3) 86 #define NFS_SRVMAXDATA(n) \ 87 (((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \ 88 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA) 89 90 /* 91 * sys/malloc.h needs M_NFSDIROFF, M_NFSRVDESC and M_NFSBIGFH added. 92 */ 93 #ifndef M_NFSRVDESC 94 #define M_NFSRVDESC M_TEMP 95 #endif 96 #ifndef M_NFSDIROFF 97 #define M_NFSDIROFF M_TEMP 98 #endif 99 #ifndef M_NFSBIGFH 100 #define M_NFSBIGFH M_TEMP 101 #endif 102 103 /* 104 * The B_INVAFTERWRITE flag should be set to whatever is required by the 105 * buffer cache code to say "Invalidate the block after it is written back". 106 */ 107 #define B_INVAFTERWRITE B_INVAL 108 109 /* 110 * The IO_METASYNC flag should be implemented for local file systems. 111 * (Until then, it is nothin at all.) 112 */ 113 #ifndef IO_METASYNC 114 #define IO_METASYNC 0 115 #endif 116 117 /* 118 * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs 119 * should ever try and use it. 120 */ 121 struct nfsd_args { 122 int sock; /* Socket to serve */ 123 caddr_t name; /* Client addr for connection based sockets */ 124 int namelen; /* Length of name */ 125 }; 126 127 struct nfsd_srvargs { 128 struct nfsd *nsd_nfsd; /* Pointer to in kernel nfsd struct */ 129 uid_t nsd_uid; /* Effective uid mapped to cred */ 130 u_int32_t nsd_haddr; /* IP address of client */ 131 struct ucred nsd_cr; /* Cred. uid maps to */ 132 int nsd_authlen; /* Length of auth string (ret) */ 133 u_char *nsd_authstr; /* Auth string (ret) */ 134 int nsd_verflen; /* and the verifier */ 135 u_char *nsd_verfstr; 136 struct timeval nsd_timestamp; /* timestamp from verifier */ 137 u_int32_t nsd_ttl; /* credential ttl (sec) */ 138 }; 139 140 /* 141 * Stats structure 142 */ 143 struct nfsstats { 144 uint64_t attrcache_hits; 145 uint64_t attrcache_misses; 146 uint64_t lookupcache_hits; 147 uint64_t lookupcache_misses; 148 uint64_t direofcache_hits; 149 uint64_t direofcache_misses; 150 uint64_t biocache_reads; 151 uint64_t read_bios; 152 uint64_t read_physios; 153 uint64_t biocache_writes; 154 uint64_t write_bios; 155 uint64_t write_physios; 156 uint64_t biocache_readlinks; 157 uint64_t readlink_bios; 158 uint64_t biocache_readdirs; 159 uint64_t readdir_bios; 160 uint64_t rpccnt[NFS_NPROCS]; 161 uint64_t rpcretries; 162 uint64_t srvrpccnt[NFS_NPROCS]; 163 uint64_t srvrpc_errs; 164 uint64_t srv_errs; 165 uint64_t rpcrequests; 166 uint64_t rpctimeouts; 167 uint64_t rpcunexpected; 168 uint64_t rpcinvalid; 169 uint64_t srvcache_inproghits; 170 uint64_t srvcache_idemdonehits; 171 uint64_t srvcache_nonidemdonehits; 172 uint64_t srvcache_misses; 173 uint64_t forcedsync; 174 uint64_t srvnqnfs_leases; 175 uint64_t srvnqnfs_maxleases; 176 uint64_t srvnqnfs_getleases; 177 uint64_t srvvop_writes; 178 }; 179 180 /* 181 * Flags for nfssvc() system call. 182 */ 183 #define NFSSVC_BIOD 0x002 184 #define NFSSVC_NFSD 0x004 185 #define NFSSVC_ADDSOCK 0x008 186 #define NFSSVC_AUTHIN 0x010 187 #define NFSSVC_GOTAUTH 0x040 188 #define NFSSVC_AUTHINFAIL 0x080 189 #define NFSSVC_MNTD 0x100 190 191 /* 192 * fs.nfs sysctl(3) identifiers 193 */ 194 #define NFS_NFSSTATS 1 /* struct: struct nfsstats */ 195 #define NFS_NIOTHREADS 2 /* number of i/o threads */ 196 #define NFS_MAXID 3 197 198 #define FS_NFS_NAMES { \ 199 { 0, 0 }, \ 200 { "nfsstats", CTLTYPE_STRUCT }, \ 201 { "iothreads", CTLTYPE_INT } \ 202 } 203 204 /* 205 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts. 206 * What should be in this set is open to debate, but I believe that since 207 * I/O system calls on ufs are never interrupted by signals the set should 208 * be minimal. My reasoning is that many current programs that use signals 209 * such as SIGALRM will not expect file I/O system calls to be interrupted 210 * by them and break. 211 */ 212 #ifdef _KERNEL 213 extern int nfs_niothreads; 214 215 struct uio; struct buf; struct vattr; struct nameidata; /* XXX */ 216 217 #define NFSINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \ 218 sigmask(SIGHUP)|sigmask(SIGQUIT)) 219 220 /* 221 * Socket errors ignored for connectionless sockets?? 222 * For now, ignore them all 223 */ 224 #define NFSIGNORE_SOERROR(s, e) \ 225 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \ 226 ((s) & PR_CONNREQUIRED) == 0) 227 228 /* 229 * Nfs outstanding request list element 230 */ 231 struct nfsreq { 232 TAILQ_ENTRY(nfsreq) r_chain; 233 struct mbuf *r_mreq; 234 struct mbuf *r_mrep; 235 struct mbuf *r_md; 236 caddr_t r_dpos; 237 struct nfsmount *r_nmp; 238 struct vnode *r_vp; 239 u_int32_t r_xid; 240 int r_flags; /* flags on request, see below */ 241 int r_retry; /* max retransmission count */ 242 int r_rexmit; /* current retrans count */ 243 int r_timer; /* tick counter on reply */ 244 int r_procnum; /* NFS procedure number */ 245 int r_rtt; /* RTT for rpc */ 246 struct proc *r_procp; /* Proc that did I/O system call */ 247 }; 248 249 /* 250 * Queue head for nfsreq's 251 */ 252 extern TAILQ_HEAD(nfsreqhead, nfsreq) nfs_reqq; 253 254 /* Flag values for r_flags */ 255 #define R_TIMING 0x01 /* timing request (in mntp) */ 256 #define R_SENT 0x02 /* request has been sent */ 257 #define R_SOFTTERM 0x04 /* soft mnt, too many retries */ 258 #define R_INTR 0x08 /* intr mnt, signal pending */ 259 #define R_SOCKERR 0x10 /* Fatal error on socket */ 260 #define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */ 261 #define R_MUSTRESEND 0x40 /* Must resend request */ 262 263 /* 264 * A list of nfssvc_sock structures is maintained with all the sockets 265 * that require service by the nfsd. 266 */ 267 #ifndef NFS_WDELAYHASHSIZ 268 #define NFS_WDELAYHASHSIZ 16 /* and with this */ 269 #endif 270 #define NWDELAYHASH(sock, f) \ 271 (&(sock)->ns_wdelayhashtbl[(*((u_int32_t *)(f))) % NFS_WDELAYHASHSIZ]) 272 #define NFSNOHASH(fhsum) \ 273 (&nfsnodehashtbl[(fhsum) & nfsnodehash]) 274 275 /* 276 * Network address hash list element 277 */ 278 union nethostaddr { 279 u_int32_t had_inetaddr; 280 struct mbuf *had_nam; 281 }; 282 283 struct nfssvc_sock { 284 TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */ 285 struct file *ns_fp; 286 struct socket *ns_so; 287 struct mbuf *ns_nam; 288 struct mbuf *ns_raw; 289 struct mbuf *ns_rawend; 290 struct mbuf *ns_rec; 291 struct mbuf *ns_recend; 292 struct mbuf *ns_frag; 293 int ns_flag; 294 int ns_solock; 295 int ns_cc; 296 int ns_reclen; 297 u_int32_t ns_sref; 298 LIST_HEAD(, nfsrv_descript) ns_tq; /* Write gather lists */ 299 LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ]; 300 }; 301 302 /* Bits for "ns_flag" */ 303 #define SLP_VALID 0x01 /* connection is usable */ 304 #define SLP_DOREC 0x02 /* receive operation required */ 305 #define SLP_NEEDQ 0x04 /* connection has data to queue from socket */ 306 #define SLP_DISCONN 0x08 /* connection is closed */ 307 #define SLP_GETSTREAM 0x10 /* extracting RPC from TCP connection */ 308 #define SLP_LASTFRAG 0x20 /* last fragment received on TCP connection */ 309 #define SLP_ALLFLAGS 0xff /* convenience */ 310 311 extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead; 312 extern int nfssvc_sockhead_flag; 313 #define SLP_INIT 0x01 /* NFS data undergoing initialization */ 314 #define SLP_WANTINIT 0x02 /* thread waiting on NFS initialization */ 315 316 /* 317 * One of these structures is allocated for each nfsd. 318 */ 319 struct nfsd { 320 TAILQ_ENTRY(nfsd) nfsd_chain; /* List of all nfsd's */ 321 int nfsd_flag; /* NFSD_ flags */ 322 struct nfssvc_sock *nfsd_slp; /* Current socket */ 323 struct proc *nfsd_procp; /* Proc ptr */ 324 struct nfsrv_descript *nfsd_nd; /* Associated nfsrv_descript */ 325 }; 326 327 /* Bits for "nfsd_flag" */ 328 #define NFSD_WAITING 0x01 329 #define NFSD_REQINPROG 0x02 330 #define NFSD_NEEDAUTH 0x04 331 #define NFSD_AUTHFAIL 0x08 332 333 /* 334 * This structure is used by the server for describing each request. 335 * Some fields are used only when write request gathering is performed. 336 */ 337 struct nfsrv_descript { 338 struct timeval nd_time; /* Write deadline */ 339 off_t nd_off; /* Start byte offset */ 340 off_t nd_eoff; /* and end byte offset */ 341 LIST_ENTRY(nfsrv_descript) nd_hash; /* Hash list */ 342 LIST_ENTRY(nfsrv_descript) nd_tq; /* and timer list */ 343 LIST_HEAD(,nfsrv_descript) nd_coalesce; /* coalesced writes */ 344 struct mbuf *nd_mrep; /* Request mbuf list */ 345 struct mbuf *nd_md; /* Current dissect mbuf */ 346 struct mbuf *nd_mreq; /* Reply mbuf list */ 347 struct mbuf *nd_nam; /* and socket addr */ 348 struct mbuf *nd_nam2; /* return socket addr */ 349 caddr_t nd_dpos; /* Current dissect pos */ 350 unsigned int nd_procnum; /* RPC # */ 351 int nd_stable; /* storage type */ 352 int nd_flag; /* nd_flag */ 353 int nd_len; /* Length of this write */ 354 int nd_repstat; /* Reply status */ 355 u_int32_t nd_retxid; /* Reply xid */ 356 struct timeval nd_starttime; /* Time RPC initiated */ 357 fhandle_t nd_fh; /* File handle */ 358 struct ucred nd_cr; /* Credentials */ 359 }; 360 361 /* Bits for "nd_flag" */ 362 #define ND_NFSV3 0x08 363 #define ND_KERBNICK 0x20 364 #define ND_KERBFULL 0x40 365 #define ND_KERBAUTH (ND_KERBNICK | ND_KERBFULL) 366 367 extern struct pool nfsreqpl; 368 extern TAILQ_HEAD(nfsdhead, nfsd) nfsd_head; 369 extern int nfsd_head_flag; 370 #define NFSD_CHECKSLP 0x01 371 372 /* 373 * These macros compare nfsrv_descript structures. 374 */ 375 #define NFSW_CONTIG(o, n) \ 376 ((o)->nd_eoff >= (n)->nd_off && \ 377 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH)) 378 379 #define NFSW_SAMECRED(o, n) \ 380 (((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \ 381 !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \ 382 sizeof (struct ucred))) 383 384 #endif /* _KERNEL */ 385 #endif /* _NFS_NFS_H */ 386