nfsrvstats.h revision 3820
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1989, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * This code is derived from software contributed to Berkeley by 61541Srgrimes * Rick Macklem at The University of Guelph. 71541Srgrimes * 81541Srgrimes * Redistribution and use in source and binary forms, with or without 91541Srgrimes * modification, are permitted provided that the following conditions 101541Srgrimes * are met: 111541Srgrimes * 1. Redistributions of source code must retain the above copyright 121541Srgrimes * notice, this list of conditions and the following disclaimer. 131541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer in the 151541Srgrimes * documentation and/or other materials provided with the distribution. 161541Srgrimes * 3. All advertising materials mentioning features or use of this software 171541Srgrimes * must display the following acknowledgement: 181541Srgrimes * This product includes software developed by the University of 191541Srgrimes * California, Berkeley and its contributors. 201541Srgrimes * 4. Neither the name of the University nor the names of its contributors 211541Srgrimes * may be used to endorse or promote products derived from this software 221541Srgrimes * without specific prior written permission. 231541Srgrimes * 241541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 251541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 261541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 271541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 281541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 291541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 301541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 311541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 321541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 331541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 341541Srgrimes * SUCH DAMAGE. 351541Srgrimes * 361541Srgrimes * @(#)nfs.h 8.1 (Berkeley) 6/10/93 373820Swollman * $Id: nfs.h,v 1.6 1994/10/17 17:47:30 phk Exp $ 381541Srgrimes */ 391541Srgrimes 402175Spaul#ifndef _NFS_NFS_H_ 412175Spaul#define _NFS_NFS_H_ 422175Spaul 431541Srgrimes/* 441541Srgrimes * Tunable constants for nfs 451541Srgrimes */ 461541Srgrimes 471541Srgrimes#define NFS_MAXIOVEC 34 481541Srgrimes#define NFS_HZ 25 /* Ticks per second for NFS timeouts */ 491541Srgrimes#define NFS_TIMEO (1*NFS_HZ) /* Default timeout = 1 second */ 501541Srgrimes#define NFS_MINTIMEO (1*NFS_HZ) /* Min timeout to use */ 511541Srgrimes#define NFS_MAXTIMEO (60*NFS_HZ) /* Max timeout to backoff to */ 521541Srgrimes#define NFS_MINIDEMTIMEO (5*NFS_HZ) /* Min timeout for non-idempotent ops*/ 531541Srgrimes#define NFS_MAXREXMIT 100 /* Stop counting after this many */ 541541Srgrimes#define NFS_MAXWINDOW 1024 /* Max number of outstanding requests */ 551541Srgrimes#define NFS_RETRANS 10 /* Num of retrans for soft mounts */ 561541Srgrimes#define NFS_MAXGRPS 16 /* Max. size of groups list */ 571828Sdg#ifndef NFS_MINATTRTIMO 581541Srgrimes#define NFS_MINATTRTIMO 5 /* Attribute cache timeout in sec */ 591828Sdg#endif 601828Sdg#ifndef NFS_MAXATTRTIMO 611541Srgrimes#define NFS_MAXATTRTIMO 60 621828Sdg#endif 631541Srgrimes#define NFS_WSIZE 8192 /* Def. write data size <= 8192 */ 641541Srgrimes#define NFS_RSIZE 8192 /* Def. read data size <= 8192 */ 651541Srgrimes#define NFS_DEFRAHEAD 1 /* Def. read ahead # blocks */ 661541Srgrimes#define NFS_MAXRAHEAD 4 /* Max. read ahead # blocks */ 671541Srgrimes#define NFS_MAXREADDIR NFS_MAXDATA /* Max. size of directory read */ 681541Srgrimes#define NFS_MAXUIDHASH 64 /* Max. # of hashed uid entries/mp */ 691541Srgrimes#define NFS_MAXASYNCDAEMON 20 /* Max. number async_daemons runable */ 701541Srgrimes#define NFS_DIRBLKSIZ 1024 /* Size of an NFS directory block */ 711541Srgrimes#define NMOD(a) ((a) % nfs_asyncdaemons) 721541Srgrimes 731541Srgrimes/* 741541Srgrimes * Set the attribute timeout based on how recently the file has been modified. 751541Srgrimes */ 761541Srgrimes#define NFS_ATTRTIMEO(np) \ 771541Srgrimes ((((np)->n_flag & NMODIFIED) || \ 781541Srgrimes (time.tv_sec - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \ 791541Srgrimes ((time.tv_sec - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \ 801541Srgrimes (time.tv_sec - (np)->n_mtime) / 10)) 811541Srgrimes 821541Srgrimes/* 831541Srgrimes * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs 841541Srgrimes * should ever try and use it. 851541Srgrimes */ 861541Srgrimesstruct nfsd_args { 871541Srgrimes int sock; /* Socket to serve */ 881541Srgrimes caddr_t name; /* Client address for connection based sockets */ 891541Srgrimes int namelen; /* Length of name */ 901541Srgrimes}; 911541Srgrimes 921541Srgrimesstruct nfsd_srvargs { 931541Srgrimes struct nfsd *nsd_nfsd; /* Pointer to in kernel nfsd struct */ 941541Srgrimes uid_t nsd_uid; /* Effective uid mapped to cred */ 951541Srgrimes u_long nsd_haddr; /* Ip address of client */ 961541Srgrimes struct ucred nsd_cr; /* Cred. uid maps to */ 971541Srgrimes int nsd_authlen; /* Length of auth string (ret) */ 981541Srgrimes char *nsd_authstr; /* Auth string (ret) */ 991541Srgrimes}; 1001541Srgrimes 1011541Srgrimesstruct nfsd_cargs { 1021541Srgrimes char *ncd_dirp; /* Mount dir path */ 1031541Srgrimes uid_t ncd_authuid; /* Effective uid */ 1041541Srgrimes int ncd_authtype; /* Type of authenticator */ 1051541Srgrimes int ncd_authlen; /* Length of authenticator string */ 1061541Srgrimes char *ncd_authstr; /* Authenticator string */ 1071541Srgrimes}; 1081541Srgrimes 1091541Srgrimes/* 1101541Srgrimes * Stats structure 1111541Srgrimes */ 1121541Srgrimesstruct nfsstats { 1131541Srgrimes int attrcache_hits; 1141541Srgrimes int attrcache_misses; 1151541Srgrimes int lookupcache_hits; 1161541Srgrimes int lookupcache_misses; 1171541Srgrimes int direofcache_hits; 1181541Srgrimes int direofcache_misses; 1191541Srgrimes int biocache_reads; 1201541Srgrimes int read_bios; 1211541Srgrimes int read_physios; 1221541Srgrimes int biocache_writes; 1231541Srgrimes int write_bios; 1241541Srgrimes int write_physios; 1251541Srgrimes int biocache_readlinks; 1261541Srgrimes int readlink_bios; 1271541Srgrimes int biocache_readdirs; 1281541Srgrimes int readdir_bios; 1291541Srgrimes int rpccnt[NFS_NPROCS]; 1301541Srgrimes int rpcretries; 1311541Srgrimes int srvrpccnt[NFS_NPROCS]; 1321541Srgrimes int srvrpc_errs; 1331541Srgrimes int srv_errs; 1341541Srgrimes int rpcrequests; 1351541Srgrimes int rpctimeouts; 1361541Srgrimes int rpcunexpected; 1371541Srgrimes int rpcinvalid; 1381541Srgrimes int srvcache_inproghits; 1391541Srgrimes int srvcache_idemdonehits; 1401541Srgrimes int srvcache_nonidemdonehits; 1411541Srgrimes int srvcache_misses; 1421541Srgrimes int srvnqnfs_leases; 1431541Srgrimes int srvnqnfs_maxleases; 1441541Srgrimes int srvnqnfs_getleases; 1451541Srgrimes}; 1461541Srgrimes 1471541Srgrimes/* 1481541Srgrimes * Flags for nfssvc() system call. 1491541Srgrimes */ 1501541Srgrimes#define NFSSVC_BIOD 0x002 1511541Srgrimes#define NFSSVC_NFSD 0x004 1521541Srgrimes#define NFSSVC_ADDSOCK 0x008 1531541Srgrimes#define NFSSVC_AUTHIN 0x010 1541541Srgrimes#define NFSSVC_GOTAUTH 0x040 1551541Srgrimes#define NFSSVC_AUTHINFAIL 0x080 1561541Srgrimes#define NFSSVC_MNTD 0x100 1571541Srgrimes 1581541Srgrimes/* 1593820Swollman * fs.nfs sysctl(3) identifiers 1603820Swollman */ 1613820Swollman#define NFS_NFSSTATS 1 /* struct: struct nfsstats */ 1623820Swollman 1633820Swollman#define FS_NFS_NAMES { \ 1643820Swollman { 0, 0 }, \ 1653820Swollman { "nfsstats", CTLTYPE_STRUCT }, \ 1663820Swollman} 1673820Swollman 1683820Swollman/* 1691541Srgrimes * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts. 1701541Srgrimes * What should be in this set is open to debate, but I believe that since 1711541Srgrimes * I/O system calls on ufs are never interrupted by signals the set should 1721541Srgrimes * be minimal. My reasoning is that many current programs that use signals 1731541Srgrimes * such as SIGALRM will not expect file I/O system calls to be interrupted 1741541Srgrimes * by them and break. 1751541Srgrimes */ 1761541Srgrimes#ifdef KERNEL 1771541Srgrimes#define NFSINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \ 1781541Srgrimes sigmask(SIGHUP)|sigmask(SIGQUIT)) 1791541Srgrimes 1801541Srgrimes/* 1811541Srgrimes * Socket errors ignored for connectionless sockets?? 1821541Srgrimes * For now, ignore them all 1831541Srgrimes */ 1841541Srgrimes#define NFSIGNORE_SOERROR(s, e) \ 1851541Srgrimes ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \ 1861541Srgrimes ((s) & PR_CONNREQUIRED) == 0) 1871541Srgrimes 1881541Srgrimes/* 1891541Srgrimes * Nfs outstanding request list element 1901541Srgrimes */ 1911541Srgrimesstruct nfsreq { 1923664Sphk TAILQ_ENTRY(nfsreq) r_chain; 1931541Srgrimes struct mbuf *r_mreq; 1941541Srgrimes struct mbuf *r_mrep; 1951541Srgrimes struct mbuf *r_md; 1961541Srgrimes caddr_t r_dpos; 1971541Srgrimes struct nfsmount *r_nmp; 1981541Srgrimes struct vnode *r_vp; 1991541Srgrimes u_long r_xid; 2001541Srgrimes int r_flags; /* flags on request, see below */ 2011541Srgrimes int r_retry; /* max retransmission count */ 2021541Srgrimes int r_rexmit; /* current retrans count */ 2031541Srgrimes int r_timer; /* tick counter on reply */ 2041541Srgrimes int r_procnum; /* NFS procedure number */ 2051541Srgrimes int r_rtt; /* RTT for rpc */ 2061541Srgrimes struct proc *r_procp; /* Proc that did I/O system call */ 2071541Srgrimes}; 2081541Srgrimes 2093664Sphk/* 2103664Sphk * Queue head for nfsreq's 2113664Sphk */ 2123664SphkTAILQ_HEAD(, nfsreq) nfs_reqq; 2133664Sphk 2141541Srgrimes/* Flag values for r_flags */ 2151541Srgrimes#define R_TIMING 0x01 /* timing request (in mntp) */ 2161541Srgrimes#define R_SENT 0x02 /* request has been sent */ 2171541Srgrimes#define R_SOFTTERM 0x04 /* soft mnt, too many retries */ 2181541Srgrimes#define R_INTR 0x08 /* intr mnt, signal pending */ 2191541Srgrimes#define R_SOCKERR 0x10 /* Fatal error on socket */ 2201541Srgrimes#define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */ 2211541Srgrimes#define R_MUSTRESEND 0x40 /* Must resend request */ 2221541Srgrimes#define R_GETONEREP 0x80 /* Probe for one reply only */ 2231541Srgrimes 2243820Swollmanextern struct nfsstats nfsstats; 2251541Srgrimes 2261541Srgrimes/* 2271541Srgrimes * A list of nfssvc_sock structures is maintained with all the sockets 2281541Srgrimes * that require service by the nfsd. 2291541Srgrimes * The nfsuid structs hang off of the nfssvc_sock structs in both lru 2301541Srgrimes * and uid hash lists. 2311541Srgrimes */ 2321541Srgrimes#define NUIDHASHSIZ 32 2333664Sphk#define NUIDHASH(sock, uid) \ 2343664Sphk (&(sock)->ns_uidhashtbl[(uid) & (sock)->ns_uidhash]) 2351541Srgrimes 2361541Srgrimes/* 2371541Srgrimes * Network address hash list element 2381541Srgrimes */ 2391541Srgrimesunion nethostaddr { 2401541Srgrimes u_long had_inetaddr; 2411541Srgrimes struct mbuf *had_nam; 2421541Srgrimes}; 2431541Srgrimes 2441541Srgrimesstruct nfsuid { 2453664Sphk TAILQ_ENTRY(nfsuid) nu_lru; /* LRU chain */ 2463664Sphk LIST_ENTRY(nfsuid) nu_hash; /* Hash list */ 2471541Srgrimes int nu_flag; /* Flags */ 2481541Srgrimes uid_t nu_uid; /* Uid mapped by this entry */ 2491541Srgrimes union nethostaddr nu_haddr; /* Host addr. for dgram sockets */ 2501541Srgrimes struct ucred nu_cr; /* Cred uid mapped to */ 2511541Srgrimes}; 2521541Srgrimes 2531541Srgrimes#define nu_inetaddr nu_haddr.had_inetaddr 2541541Srgrimes#define nu_nam nu_haddr.had_nam 2551541Srgrimes/* Bits for nu_flag */ 2561541Srgrimes#define NU_INETADDR 0x1 2571541Srgrimes 2581541Srgrimesstruct nfssvc_sock { 2593664Sphk TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */ 2603664Sphk TAILQ_HEAD(, nfsuid) ns_uidlruhead; 2613664Sphk LIST_HEAD(, nfsuid) *ns_uidhashtbl; 2623664Sphk u_long ns_uidhash; 2633664Sphk 2641541Srgrimes int ns_flag; 2651541Srgrimes u_long ns_sref; 2661541Srgrimes struct file *ns_fp; 2671541Srgrimes struct socket *ns_so; 2681541Srgrimes int ns_solock; 2691541Srgrimes struct mbuf *ns_nam; 2701541Srgrimes int ns_cc; 2711541Srgrimes struct mbuf *ns_raw; 2721541Srgrimes struct mbuf *ns_rawend; 2731541Srgrimes int ns_reclen; 2741541Srgrimes struct mbuf *ns_rec; 2751541Srgrimes struct mbuf *ns_recend; 2761541Srgrimes int ns_numuids; 2771541Srgrimes}; 2781541Srgrimes 2791541Srgrimes/* Bits for "ns_flag" */ 2801541Srgrimes#define SLP_VALID 0x01 2811541Srgrimes#define SLP_DOREC 0x02 2821541Srgrimes#define SLP_NEEDQ 0x04 2831541Srgrimes#define SLP_DISCONN 0x08 2841541Srgrimes#define SLP_GETSTREAM 0x10 2851541Srgrimes#define SLP_ALLFLAGS 0xff 2861541Srgrimes 2873664SphkTAILQ_HEAD(, nfssvc_sock) nfssvc_sockhead; 2883664Sphkint nfssvc_sockhead_flag; 2893664Sphk#define SLP_INIT 0x01 2903664Sphk#define SLP_WANTINIT 0x02 2913664Sphk 2921541Srgrimes/* 2931541Srgrimes * One of these structures is allocated for each nfsd. 2941541Srgrimes */ 2951541Srgrimesstruct nfsd { 2963664Sphk TAILQ_ENTRY(nfsd) nd_chain; /* List of all nfsd's */ 2971541Srgrimes int nd_flag; /* NFSD_ flags */ 2981541Srgrimes struct nfssvc_sock *nd_slp; /* Current socket */ 2991541Srgrimes struct mbuf *nd_nam; /* Client addr for datagram req. */ 3001541Srgrimes struct mbuf *nd_mrep; /* Req. mbuf list */ 3011541Srgrimes struct mbuf *nd_md; 3021541Srgrimes caddr_t nd_dpos; /* Position in list */ 3031541Srgrimes int nd_procnum; /* RPC procedure number */ 3041541Srgrimes u_long nd_retxid; /* RPC xid */ 3051541Srgrimes int nd_repstat; /* Reply status value */ 3061541Srgrimes struct ucred nd_cr; /* Credentials for req. */ 3071541Srgrimes int nd_nqlflag; /* Leasing flag */ 3083305Sphk u_long nd_duration; /* Lease duration */ 3091541Srgrimes int nd_authlen; /* Authenticator len */ 3101541Srgrimes u_char nd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */ 3111541Srgrimes struct proc *nd_procp; /* Proc ptr */ 3121541Srgrimes}; 3131541Srgrimes 3143664Sphk/* Bits for "nd_flag" */ 3151541Srgrimes#define NFSD_WAITING 0x01 3163664Sphk#define NFSD_REQINPROG 0x02 3173664Sphk#define NFSD_NEEDAUTH 0x04 3183664Sphk#define NFSD_AUTHFAIL 0x08 3193305Sphk 3203664SphkTAILQ_HEAD(, nfsd) nfsd_head; 3213664Sphkint nfsd_head_flag; 3223664Sphk#define NFSD_CHECKSLP 0x01 3233664Sphk 3243305Sphkint nfs_reply __P((struct nfsreq *)); 3253305Sphkint nfs_getreq __P((struct nfsd *,int)); 3263305Sphkint nfs_send __P((struct socket *,struct mbuf *,struct mbuf *,struct nfsreq *)); 3273305Sphkint nfs_rephead __P((int,struct nfsd *,int,int,u_quad_t *,struct mbuf **,struct mbuf **,caddr_t *)); 3283305Sphkint nfs_sndlock __P((int *,struct nfsreq *)); 3293305Sphkint nfs_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *)); 3303305Sphkint nfs_vinvalbuf __P((struct vnode *,int,struct ucred *,struct proc *,int)); 3313305Sphkint nfs_readrpc __P((struct vnode *,struct uio *,struct ucred *)); 3323305Sphkint nfs_writerpc __P((struct vnode *,struct uio *,struct ucred *,int)); 3333305Sphkint nfs_readdirrpc __P((register struct vnode *,struct uio *,struct ucred *)); 3343305Sphkint nfs_asyncio __P((struct buf *,struct ucred *)); 3353305Sphkint nfs_doio __P((struct buf *,struct ucred *,struct proc *)); 3363305Sphkint nfs_readlinkrpc __P((struct vnode *,struct uio *,struct ucred *)); 3373305Sphkint nfs_sigintr __P((struct nfsmount *,struct nfsreq *r,struct proc *)); 3383305Sphkint nfs_readdirlookrpc __P((struct vnode *,register struct uio *,struct ucred *)); 3393305Sphkint nfsm_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *)); 3403305Sphkint nfsrv_fhtovp __P((fhandle_t *,int,struct vnode **,struct ucred *,struct nfssvc_sock *,struct mbuf *,int *)); 3413305Sphkint nfsrv_access __P((struct vnode *,int,struct ucred *,int,struct proc *)); 3423305Sphkint netaddr_match __P((int,union nethostaddr *,struct mbuf *)); 3433305Sphkint nfs_request __P((struct vnode *,struct mbuf *,int,struct proc *,struct ucred *,struct mbuf **,struct mbuf **,caddr_t *)); 3443305Sphkint nfs_loadattrcache __P((struct vnode **,struct mbuf **,caddr_t *,struct vattr *)); 3453305Sphkint nfs_namei __P((struct nameidata *,fhandle_t *,int,struct nfssvc_sock *,struct mbuf *,struct mbuf **,caddr_t *,struct proc *)); 3463305Sphkvoid nfsm_adj __P((struct mbuf *,int,int)); 3473305Sphkint nfsm_mbuftouio __P((struct mbuf **,struct uio *,int,caddr_t *)); 3483305Sphkvoid nfsrv_initcache __P((void)); 3493305Sphkint nfs_rcvlock __P((struct nfsreq *)); 3503305Sphkint nfs_getauth __P((struct nfsmount *,struct nfsreq *,struct ucred *,int *,char **,int *)); 3513305Sphkint nfs_msg __P((struct proc *,char *,char *)); 3523305Sphkint nfs_adv __P((struct mbuf **,caddr_t *,int,int)); 3533305Sphkint nfsrv_getstream __P((struct nfssvc_sock *,int)); 3543305Sphkvoid nfs_nhinit __P((void)); 3553305Sphkvoid nfs_timer __P((void*)); 3563664Sphkstruct nfsnodehashhead * nfs_hash __P((nfsv2fh_t *)); 3573305Sphkint nfssvc_iod __P((struct proc *)); 3583305Sphkint nfssvc_nfsd __P((struct nfsd_srvargs *,caddr_t,struct proc *)); 3593305Sphkint nfssvc_addsock __P((struct file *,struct mbuf *)); 3603305Sphkint nfsrv_dorec __P((struct nfssvc_sock *,struct nfsd *)); 3613305Sphkint nfsrv_getcache __P((struct mbuf *,struct nfsd *,struct mbuf **)); 3623305Sphkvoid nfsrv_updatecache __P((struct mbuf *,struct nfsd *,int,struct mbuf *)); 3633305Sphkint mountnfs __P((struct nfs_args *,struct mount *,struct mbuf *,char *,char *,struct vnode **)); 3643305Sphkint nfs_connect __P((struct nfsmount *,struct nfsreq *)); 3653305Sphkint nfs_getattrcache __P((struct vnode *,struct vattr *)); 3663305Sphkint nfsm_strtmbuf __P((struct mbuf **,char **,char *,long)); 3673305Sphkint nfs_bioread __P((struct vnode *,struct uio *,int,struct ucred *)); 3683305Sphkint nfsm_uiotombuf __P((struct uio *,struct mbuf **,int,caddr_t *)); 3693305Sphkvoid nfsrv_init __P((int)); 3701541Srgrimes#endif /* KERNEL */ 3712175Spaul 3722175Spaul#endif 373