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