nfsrvstats.h revision 4067
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 374067Swollman * $Id: nfs.h,v 1.7 1994/10/23 23:26:15 wollman 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 1774067Swollman 1784067Swollmanstruct uio; struct buf; struct vattr; struct nameidata; /* XXX */ 1794067Swollman 1801541Srgrimes#define NFSINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \ 1811541Srgrimes sigmask(SIGHUP)|sigmask(SIGQUIT)) 1821541Srgrimes 1831541Srgrimes/* 1841541Srgrimes * Socket errors ignored for connectionless sockets?? 1851541Srgrimes * For now, ignore them all 1861541Srgrimes */ 1871541Srgrimes#define NFSIGNORE_SOERROR(s, e) \ 1881541Srgrimes ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \ 1891541Srgrimes ((s) & PR_CONNREQUIRED) == 0) 1901541Srgrimes 1911541Srgrimes/* 1921541Srgrimes * Nfs outstanding request list element 1931541Srgrimes */ 1941541Srgrimesstruct nfsreq { 1953664Sphk TAILQ_ENTRY(nfsreq) r_chain; 1961541Srgrimes struct mbuf *r_mreq; 1971541Srgrimes struct mbuf *r_mrep; 1981541Srgrimes struct mbuf *r_md; 1991541Srgrimes caddr_t r_dpos; 2001541Srgrimes struct nfsmount *r_nmp; 2011541Srgrimes struct vnode *r_vp; 2021541Srgrimes u_long r_xid; 2031541Srgrimes int r_flags; /* flags on request, see below */ 2041541Srgrimes int r_retry; /* max retransmission count */ 2051541Srgrimes int r_rexmit; /* current retrans count */ 2061541Srgrimes int r_timer; /* tick counter on reply */ 2071541Srgrimes int r_procnum; /* NFS procedure number */ 2081541Srgrimes int r_rtt; /* RTT for rpc */ 2091541Srgrimes struct proc *r_procp; /* Proc that did I/O system call */ 2101541Srgrimes}; 2111541Srgrimes 2123664Sphk/* 2133664Sphk * Queue head for nfsreq's 2143664Sphk */ 2153664SphkTAILQ_HEAD(, nfsreq) nfs_reqq; 2163664Sphk 2171541Srgrimes/* Flag values for r_flags */ 2181541Srgrimes#define R_TIMING 0x01 /* timing request (in mntp) */ 2191541Srgrimes#define R_SENT 0x02 /* request has been sent */ 2201541Srgrimes#define R_SOFTTERM 0x04 /* soft mnt, too many retries */ 2211541Srgrimes#define R_INTR 0x08 /* intr mnt, signal pending */ 2221541Srgrimes#define R_SOCKERR 0x10 /* Fatal error on socket */ 2231541Srgrimes#define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */ 2241541Srgrimes#define R_MUSTRESEND 0x40 /* Must resend request */ 2251541Srgrimes#define R_GETONEREP 0x80 /* Probe for one reply only */ 2261541Srgrimes 2273820Swollmanextern struct nfsstats nfsstats; 2281541Srgrimes 2291541Srgrimes/* 2301541Srgrimes * A list of nfssvc_sock structures is maintained with all the sockets 2311541Srgrimes * that require service by the nfsd. 2321541Srgrimes * The nfsuid structs hang off of the nfssvc_sock structs in both lru 2331541Srgrimes * and uid hash lists. 2341541Srgrimes */ 2351541Srgrimes#define NUIDHASHSIZ 32 2363664Sphk#define NUIDHASH(sock, uid) \ 2373664Sphk (&(sock)->ns_uidhashtbl[(uid) & (sock)->ns_uidhash]) 2381541Srgrimes 2391541Srgrimes/* 2401541Srgrimes * Network address hash list element 2411541Srgrimes */ 2421541Srgrimesunion nethostaddr { 2431541Srgrimes u_long had_inetaddr; 2441541Srgrimes struct mbuf *had_nam; 2451541Srgrimes}; 2461541Srgrimes 2471541Srgrimesstruct nfsuid { 2483664Sphk TAILQ_ENTRY(nfsuid) nu_lru; /* LRU chain */ 2493664Sphk LIST_ENTRY(nfsuid) nu_hash; /* Hash list */ 2501541Srgrimes int nu_flag; /* Flags */ 2511541Srgrimes uid_t nu_uid; /* Uid mapped by this entry */ 2521541Srgrimes union nethostaddr nu_haddr; /* Host addr. for dgram sockets */ 2531541Srgrimes struct ucred nu_cr; /* Cred uid mapped to */ 2541541Srgrimes}; 2551541Srgrimes 2561541Srgrimes#define nu_inetaddr nu_haddr.had_inetaddr 2571541Srgrimes#define nu_nam nu_haddr.had_nam 2581541Srgrimes/* Bits for nu_flag */ 2591541Srgrimes#define NU_INETADDR 0x1 2601541Srgrimes 2611541Srgrimesstruct nfssvc_sock { 2623664Sphk TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */ 2633664Sphk TAILQ_HEAD(, nfsuid) ns_uidlruhead; 2643664Sphk LIST_HEAD(, nfsuid) *ns_uidhashtbl; 2653664Sphk u_long ns_uidhash; 2663664Sphk 2671541Srgrimes int ns_flag; 2681541Srgrimes u_long ns_sref; 2691541Srgrimes struct file *ns_fp; 2701541Srgrimes struct socket *ns_so; 2711541Srgrimes int ns_solock; 2721541Srgrimes struct mbuf *ns_nam; 2731541Srgrimes int ns_cc; 2741541Srgrimes struct mbuf *ns_raw; 2751541Srgrimes struct mbuf *ns_rawend; 2761541Srgrimes int ns_reclen; 2771541Srgrimes struct mbuf *ns_rec; 2781541Srgrimes struct mbuf *ns_recend; 2791541Srgrimes int ns_numuids; 2801541Srgrimes}; 2811541Srgrimes 2821541Srgrimes/* Bits for "ns_flag" */ 2831541Srgrimes#define SLP_VALID 0x01 2841541Srgrimes#define SLP_DOREC 0x02 2851541Srgrimes#define SLP_NEEDQ 0x04 2861541Srgrimes#define SLP_DISCONN 0x08 2871541Srgrimes#define SLP_GETSTREAM 0x10 2881541Srgrimes#define SLP_ALLFLAGS 0xff 2891541Srgrimes 2903664SphkTAILQ_HEAD(, nfssvc_sock) nfssvc_sockhead; 2913664Sphkint nfssvc_sockhead_flag; 2923664Sphk#define SLP_INIT 0x01 2933664Sphk#define SLP_WANTINIT 0x02 2943664Sphk 2951541Srgrimes/* 2961541Srgrimes * One of these structures is allocated for each nfsd. 2971541Srgrimes */ 2981541Srgrimesstruct nfsd { 2993664Sphk TAILQ_ENTRY(nfsd) nd_chain; /* List of all nfsd's */ 3001541Srgrimes int nd_flag; /* NFSD_ flags */ 3011541Srgrimes struct nfssvc_sock *nd_slp; /* Current socket */ 3021541Srgrimes struct mbuf *nd_nam; /* Client addr for datagram req. */ 3031541Srgrimes struct mbuf *nd_mrep; /* Req. mbuf list */ 3041541Srgrimes struct mbuf *nd_md; 3051541Srgrimes caddr_t nd_dpos; /* Position in list */ 3061541Srgrimes int nd_procnum; /* RPC procedure number */ 3071541Srgrimes u_long nd_retxid; /* RPC xid */ 3081541Srgrimes int nd_repstat; /* Reply status value */ 3091541Srgrimes struct ucred nd_cr; /* Credentials for req. */ 3101541Srgrimes int nd_nqlflag; /* Leasing flag */ 3113305Sphk u_long nd_duration; /* Lease duration */ 3121541Srgrimes int nd_authlen; /* Authenticator len */ 3131541Srgrimes u_char nd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */ 3141541Srgrimes struct proc *nd_procp; /* Proc ptr */ 3151541Srgrimes}; 3161541Srgrimes 3173664Sphk/* Bits for "nd_flag" */ 3181541Srgrimes#define NFSD_WAITING 0x01 3193664Sphk#define NFSD_REQINPROG 0x02 3203664Sphk#define NFSD_NEEDAUTH 0x04 3213664Sphk#define NFSD_AUTHFAIL 0x08 3223305Sphk 3233664SphkTAILQ_HEAD(, nfsd) nfsd_head; 3243664Sphkint nfsd_head_flag; 3253664Sphk#define NFSD_CHECKSLP 0x01 3263664Sphk 3273305Sphkint nfs_reply __P((struct nfsreq *)); 3283305Sphkint nfs_getreq __P((struct nfsd *,int)); 3293305Sphkint nfs_send __P((struct socket *,struct mbuf *,struct mbuf *,struct nfsreq *)); 3303305Sphkint nfs_rephead __P((int,struct nfsd *,int,int,u_quad_t *,struct mbuf **,struct mbuf **,caddr_t *)); 3313305Sphkint nfs_sndlock __P((int *,struct nfsreq *)); 3323305Sphkint nfs_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *)); 3333305Sphkint nfs_vinvalbuf __P((struct vnode *,int,struct ucred *,struct proc *,int)); 3343305Sphkint nfs_readrpc __P((struct vnode *,struct uio *,struct ucred *)); 3353305Sphkint nfs_writerpc __P((struct vnode *,struct uio *,struct ucred *,int)); 3363305Sphkint nfs_readdirrpc __P((register struct vnode *,struct uio *,struct ucred *)); 3373305Sphkint nfs_asyncio __P((struct buf *,struct ucred *)); 3383305Sphkint nfs_doio __P((struct buf *,struct ucred *,struct proc *)); 3393305Sphkint nfs_readlinkrpc __P((struct vnode *,struct uio *,struct ucred *)); 3403305Sphkint nfs_sigintr __P((struct nfsmount *,struct nfsreq *r,struct proc *)); 3413305Sphkint nfs_readdirlookrpc __P((struct vnode *,register struct uio *,struct ucred *)); 3423305Sphkint nfsm_disct __P((struct mbuf **,caddr_t *,int,int,caddr_t *)); 3433305Sphkint nfsrv_fhtovp __P((fhandle_t *,int,struct vnode **,struct ucred *,struct nfssvc_sock *,struct mbuf *,int *)); 3443305Sphkint nfsrv_access __P((struct vnode *,int,struct ucred *,int,struct proc *)); 3453305Sphkint netaddr_match __P((int,union nethostaddr *,struct mbuf *)); 3463305Sphkint nfs_request __P((struct vnode *,struct mbuf *,int,struct proc *,struct ucred *,struct mbuf **,struct mbuf **,caddr_t *)); 3473305Sphkint nfs_loadattrcache __P((struct vnode **,struct mbuf **,caddr_t *,struct vattr *)); 3483305Sphkint nfs_namei __P((struct nameidata *,fhandle_t *,int,struct nfssvc_sock *,struct mbuf *,struct mbuf **,caddr_t *,struct proc *)); 3493305Sphkvoid nfsm_adj __P((struct mbuf *,int,int)); 3503305Sphkint nfsm_mbuftouio __P((struct mbuf **,struct uio *,int,caddr_t *)); 3513305Sphkvoid nfsrv_initcache __P((void)); 3523305Sphkint nfs_rcvlock __P((struct nfsreq *)); 3533305Sphkint nfs_getauth __P((struct nfsmount *,struct nfsreq *,struct ucred *,int *,char **,int *)); 3543305Sphkint nfs_msg __P((struct proc *,char *,char *)); 3553305Sphkint nfs_adv __P((struct mbuf **,caddr_t *,int,int)); 3563305Sphkint nfsrv_getstream __P((struct nfssvc_sock *,int)); 3573305Sphkvoid nfs_nhinit __P((void)); 3583305Sphkvoid nfs_timer __P((void*)); 3593664Sphkstruct nfsnodehashhead * nfs_hash __P((nfsv2fh_t *)); 3603305Sphkint nfssvc_iod __P((struct proc *)); 3613305Sphkint nfssvc_nfsd __P((struct nfsd_srvargs *,caddr_t,struct proc *)); 3623305Sphkint nfssvc_addsock __P((struct file *,struct mbuf *)); 3633305Sphkint nfsrv_dorec __P((struct nfssvc_sock *,struct nfsd *)); 3643305Sphkint nfsrv_getcache __P((struct mbuf *,struct nfsd *,struct mbuf **)); 3653305Sphkvoid nfsrv_updatecache __P((struct mbuf *,struct nfsd *,int,struct mbuf *)); 3663305Sphkint mountnfs __P((struct nfs_args *,struct mount *,struct mbuf *,char *,char *,struct vnode **)); 3673305Sphkint nfs_connect __P((struct nfsmount *,struct nfsreq *)); 3683305Sphkint nfs_getattrcache __P((struct vnode *,struct vattr *)); 3693305Sphkint nfsm_strtmbuf __P((struct mbuf **,char **,char *,long)); 3703305Sphkint nfs_bioread __P((struct vnode *,struct uio *,int,struct ucred *)); 3713305Sphkint nfsm_uiotombuf __P((struct uio *,struct mbuf **,int,caddr_t *)); 3723305Sphkvoid nfsrv_init __P((int)); 3731541Srgrimes#endif /* KERNEL */ 3742175Spaul 3752175Spaul#endif 376