nfsargs.h revision 34961
11541Srgrimes/* 222521Sdyson * Copyright (c) 1989, 1993, 1995 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 * 3622521Sdyson * @(#)nfs.h 8.4 (Berkeley) 5/1/95 3734961Sphk * $Id: nfs.h,v 1.33 1998/02/01 21:23:29 bde 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 489336Sdfr#define NFS_TICKINTVL 5 /* Desired time for a tick (msec) */ 499336Sdfr#define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */ 509336Sdfr#define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */ 519336Sdfr#define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */ 529336Sdfr#define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */ 539336Sdfr#define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/ 541541Srgrimes#define NFS_MAXREXMIT 100 /* Stop counting after this many */ 551541Srgrimes#define NFS_MAXWINDOW 1024 /* Max number of outstanding requests */ 561541Srgrimes#define NFS_RETRANS 10 /* Num of retrans for soft mounts */ 571541Srgrimes#define NFS_MAXGRPS 16 /* Max. size of groups list */ 581828Sdg#ifndef NFS_MINATTRTIMO 591541Srgrimes#define NFS_MINATTRTIMO 5 /* Attribute cache timeout in sec */ 601828Sdg#endif 611828Sdg#ifndef NFS_MAXATTRTIMO 621541Srgrimes#define NFS_MAXATTRTIMO 60 631828Sdg#endif 641541Srgrimes#define NFS_WSIZE 8192 /* Def. write data size <= 8192 */ 651541Srgrimes#define NFS_RSIZE 8192 /* Def. read data size <= 8192 */ 669336Sdfr#define NFS_READDIRSIZE 8192 /* Def. readdir size */ 671541Srgrimes#define NFS_DEFRAHEAD 1 /* Def. read ahead # blocks */ 681541Srgrimes#define NFS_MAXRAHEAD 4 /* Max. read ahead # blocks */ 691541Srgrimes#define NFS_MAXUIDHASH 64 /* Max. # of hashed uid entries/mp */ 7024378Sbde#define NFS_MAXASYNCDAEMON 20 /* Max. number async_daemons runnable */ 719336Sdfr#define NFS_MAXGATHERDELAY 100 /* Max. write gather delay (msec) */ 729336Sdfr#ifndef NFS_GATHERDELAY 739336Sdfr#define NFS_GATHERDELAY 10 /* Default write gather delay (msec) */ 749336Sdfr#endif 759336Sdfr#define NFS_DIRBLKSIZ 4096 /* Must be a multiple of DIRBLKSIZ */ 7624378Sbde#ifdef KERNEL 7724378Sbde#define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */ 7824378Sbde#endif 799336Sdfr 809336Sdfr/* 819336Sdfr * Oddballs 829336Sdfr */ 831541Srgrimes#define NMOD(a) ((a) % nfs_asyncdaemons) 849336Sdfr#define NFS_CMPFH(n, f, s) \ 859336Sdfr ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s))) 869336Sdfr#define NFS_ISV3(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3) 879336Sdfr#define NFS_SRVMAXDATA(n) \ 889336Sdfr (((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \ 899336Sdfr NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA) 901541Srgrimes 911541Srgrimes/* 929336Sdfr * XXX 939336Sdfr * The B_INVAFTERWRITE flag should be set to whatever is required by the 949336Sdfr * buffer cache code to say "Invalidate the block after it is written back". 959336Sdfr */ 969336Sdfr#define B_INVAFTERWRITE B_NOCACHE 979336Sdfr 989336Sdfr/* 999336Sdfr * The IO_METASYNC flag should be implemented for local file systems. 1009336Sdfr * (Until then, it is nothin at all.) 1019336Sdfr */ 1029336Sdfr#ifndef IO_METASYNC 1039336Sdfr#define IO_METASYNC 0 1049336Sdfr#endif 1059336Sdfr 1069336Sdfr/* 1071541Srgrimes * Set the attribute timeout based on how recently the file has been modified. 1081541Srgrimes */ 1091541Srgrimes#define NFS_ATTRTIMEO(np) \ 1101541Srgrimes ((((np)->n_flag & NMODIFIED) || \ 11134961Sphk (time_second - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \ 11234961Sphk ((time_second - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \ 11334961Sphk (time_second - (np)->n_mtime) / 10)) 1141541Srgrimes 1151541Srgrimes/* 1169336Sdfr * Expected allocation sizes for major data structures. If the actual size 1179336Sdfr * of the structure exceeds these sizes, then malloc() will be allocating 1189336Sdfr * almost twice the memory required. This is used in nfs_init() to warn 1199336Sdfr * the sysadmin that the size of a structure should be reduced. 1209336Sdfr * (These sizes are always a power of 2. If the kernel malloc() changes 1219336Sdfr * to one that does not allocate space in powers of 2 size, then this all 1229336Sdfr * becomes bunk!) 1239336Sdfr */ 1249336Sdfr#define NFS_NODEALLOC 256 1259336Sdfr#define NFS_MNTALLOC 512 1269336Sdfr#define NFS_SVCALLOC 256 1279336Sdfr#define NFS_UIDALLOC 128 1289336Sdfr 1299336Sdfr/* 13022521Sdyson * Arguments to mount NFS 13122521Sdyson */ 13222521Sdyson#define NFS_ARGSVERSION 3 /* change when nfs_args changes */ 13322521Sdysonstruct nfs_args { 13422521Sdyson int version; /* args structure version number */ 13522521Sdyson struct sockaddr *addr; /* file server address */ 13622521Sdyson int addrlen; /* length of address */ 13722521Sdyson int sotype; /* Socket type */ 13822521Sdyson int proto; /* and Protocol */ 13922521Sdyson u_char *fh; /* File handle to be mounted */ 14022521Sdyson int fhsize; /* Size, in bytes, of fh */ 14122521Sdyson int flags; /* flags */ 14222521Sdyson int wsize; /* write size in bytes */ 14322521Sdyson int rsize; /* read size in bytes */ 14422521Sdyson int readdirsize; /* readdir size in bytes */ 14522521Sdyson int timeo; /* initial timeout in .1 secs */ 14622521Sdyson int retrans; /* times to retry send */ 14722521Sdyson int maxgrouplist; /* Max. size of group list */ 14822521Sdyson int readahead; /* # of blocks to readahead */ 14922521Sdyson int leaseterm; /* Term (sec) of lease */ 15022521Sdyson int deadthresh; /* Retrans threshold */ 15122521Sdyson char *hostname; /* server's name */ 15222521Sdyson}; 15322521Sdyson 15422521Sdyson/* 15522521Sdyson * NFS mount option flags 15622521Sdyson */ 15722521Sdyson#define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */ 15822521Sdyson#define NFSMNT_WSIZE 0x00000002 /* set write size */ 15922521Sdyson#define NFSMNT_RSIZE 0x00000004 /* set read size */ 16022521Sdyson#define NFSMNT_TIMEO 0x00000008 /* set initial timeout */ 16122521Sdyson#define NFSMNT_RETRANS 0x00000010 /* set number of request retries */ 16222521Sdyson#define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */ 16322521Sdyson#define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */ 16422521Sdyson#define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */ 16522521Sdyson#define NFSMNT_NQNFS 0x00000100 /* Use Nqnfs protocol */ 16622521Sdyson#define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */ 16722521Sdyson#define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */ 16822521Sdyson#define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */ 16922521Sdyson#define NFSMNT_LEASETERM 0x00001000 /* set lease term (nqnfs) */ 17022521Sdyson#define NFSMNT_READAHEAD 0x00002000 /* set read ahead */ 17122521Sdyson#define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */ 17222521Sdyson#define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */ 17322521Sdyson#define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */ 17422521Sdyson#define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */ 17522521Sdyson#define NFSMNT_INTERNAL 0xfffc0000 /* Bits set internally */ 17622521Sdyson#define NFSMNT_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */ 17722521Sdyson#define NFSMNT_GOTPATHCONF 0x00080000 /* Got the V3 pathconf info */ 17822521Sdyson#define NFSMNT_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */ 17922521Sdyson#define NFSMNT_MNTD 0x00200000 /* Mnt server for mnt point */ 18022521Sdyson#define NFSMNT_DISMINPROG 0x00400000 /* Dismount in progress */ 18122521Sdyson#define NFSMNT_DISMNT 0x00800000 /* Dismounted */ 18222521Sdyson#define NFSMNT_SNDLOCK 0x01000000 /* Send socket lock */ 18322521Sdyson#define NFSMNT_WANTSND 0x02000000 /* Want above */ 18422521Sdyson#define NFSMNT_RCVLOCK 0x04000000 /* Rcv socket lock */ 18522521Sdyson#define NFSMNT_WANTRCV 0x08000000 /* Want above */ 18622521Sdyson#define NFSMNT_WAITAUTH 0x10000000 /* Wait for authentication */ 18722521Sdyson#define NFSMNT_HASAUTH 0x20000000 /* Has authenticator */ 18822521Sdyson#define NFSMNT_WANTAUTH 0x40000000 /* Wants an authenticator */ 18922521Sdyson#define NFSMNT_AUTHERR 0x80000000 /* Authentication error */ 19022521Sdyson 19122521Sdyson/* 1921541Srgrimes * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs 1931541Srgrimes * should ever try and use it. 1941541Srgrimes */ 1951541Srgrimesstruct nfsd_args { 1961541Srgrimes int sock; /* Socket to serve */ 19722521Sdyson caddr_t name; /* Client addr for connection based sockets */ 1981541Srgrimes int namelen; /* Length of name */ 1991541Srgrimes}; 2001541Srgrimes 2011541Srgrimesstruct nfsd_srvargs { 2021541Srgrimes struct nfsd *nsd_nfsd; /* Pointer to in kernel nfsd struct */ 2031541Srgrimes uid_t nsd_uid; /* Effective uid mapped to cred */ 2041541Srgrimes u_long nsd_haddr; /* Ip address of client */ 2051541Srgrimes struct ucred nsd_cr; /* Cred. uid maps to */ 2061541Srgrimes int nsd_authlen; /* Length of auth string (ret) */ 2079336Sdfr u_char *nsd_authstr; /* Auth string (ret) */ 2089336Sdfr int nsd_verflen; /* and the verfier */ 2099336Sdfr u_char *nsd_verfstr; 2109336Sdfr struct timeval nsd_timestamp; /* timestamp from verifier */ 2119336Sdfr u_long nsd_ttl; /* credential ttl (sec) */ 2129336Sdfr NFSKERBKEY_T nsd_key; /* Session key */ 2131541Srgrimes}; 2141541Srgrimes 2151541Srgrimesstruct nfsd_cargs { 2161541Srgrimes char *ncd_dirp; /* Mount dir path */ 2171541Srgrimes uid_t ncd_authuid; /* Effective uid */ 2181541Srgrimes int ncd_authtype; /* Type of authenticator */ 2191541Srgrimes int ncd_authlen; /* Length of authenticator string */ 2209336Sdfr u_char *ncd_authstr; /* Authenticator string */ 2219336Sdfr int ncd_verflen; /* and the verifier */ 2229336Sdfr u_char *ncd_verfstr; 2239336Sdfr NFSKERBKEY_T ncd_key; /* Session key */ 2241541Srgrimes}; 2251541Srgrimes 2261541Srgrimes/* 22722521Sdyson * XXX to allow amd to include nfs.h without nfsproto.h 22822521Sdyson */ 22922521Sdyson#ifdef NFS_NPROCS 23022521Sdyson/* 2311541Srgrimes * Stats structure 2321541Srgrimes */ 2331541Srgrimesstruct nfsstats { 2341541Srgrimes int attrcache_hits; 2351541Srgrimes int attrcache_misses; 2361541Srgrimes int lookupcache_hits; 2371541Srgrimes int lookupcache_misses; 2381541Srgrimes int direofcache_hits; 2391541Srgrimes int direofcache_misses; 2401541Srgrimes int biocache_reads; 2411541Srgrimes int read_bios; 2421541Srgrimes int read_physios; 2431541Srgrimes int biocache_writes; 2441541Srgrimes int write_bios; 2451541Srgrimes int write_physios; 2461541Srgrimes int biocache_readlinks; 2471541Srgrimes int readlink_bios; 2481541Srgrimes int biocache_readdirs; 2491541Srgrimes int readdir_bios; 2501541Srgrimes int rpccnt[NFS_NPROCS]; 2511541Srgrimes int rpcretries; 2521541Srgrimes int srvrpccnt[NFS_NPROCS]; 2531541Srgrimes int srvrpc_errs; 2541541Srgrimes int srv_errs; 2551541Srgrimes int rpcrequests; 2561541Srgrimes int rpctimeouts; 2571541Srgrimes int rpcunexpected; 2581541Srgrimes int rpcinvalid; 2591541Srgrimes int srvcache_inproghits; 2601541Srgrimes int srvcache_idemdonehits; 2611541Srgrimes int srvcache_nonidemdonehits; 2621541Srgrimes int srvcache_misses; 2631541Srgrimes int srvnqnfs_leases; 2641541Srgrimes int srvnqnfs_maxleases; 2651541Srgrimes int srvnqnfs_getleases; 2669336Sdfr int srvvop_writes; 2671541Srgrimes}; 26822521Sdyson#endif 2691541Srgrimes 2701541Srgrimes/* 2711541Srgrimes * Flags for nfssvc() system call. 2721541Srgrimes */ 2731541Srgrimes#define NFSSVC_BIOD 0x002 2741541Srgrimes#define NFSSVC_NFSD 0x004 2751541Srgrimes#define NFSSVC_ADDSOCK 0x008 2761541Srgrimes#define NFSSVC_AUTHIN 0x010 2771541Srgrimes#define NFSSVC_GOTAUTH 0x040 2781541Srgrimes#define NFSSVC_AUTHINFAIL 0x080 2791541Srgrimes#define NFSSVC_MNTD 0x100 2801541Srgrimes 2811541Srgrimes/* 2823820Swollman * fs.nfs sysctl(3) identifiers 2833820Swollman */ 2843820Swollman#define NFS_NFSSTATS 1 /* struct: struct nfsstats */ 28524330Sguido#define NFS_NFSPRIVPORT 2 /* int: prohibit nfs to resvports */ 2863820Swollman 2873820Swollman#define FS_NFS_NAMES { \ 2883820Swollman { 0, 0 }, \ 2893820Swollman { "nfsstats", CTLTYPE_STRUCT }, \ 29024330Sguido { "nfsprivport", CTLTYPE_INT }, \ 2913820Swollman} 2923820Swollman 2933820Swollman/* 29432998Sbde * Network address hash list element 2951541Srgrimes */ 29632998Sbdeunion nethostaddr { 29732998Sbde u_long had_inetaddr; 29832998Sbde struct sockaddr *had_nam; 29932998Sbde}; 30032998Sbde 30122521Sdyson#ifdef KERNEL 3024067Swollman 30330354Sphk#ifdef MALLOC_DECLARE 30430354SphkMALLOC_DECLARE(M_NFSREQ); 30530354SphkMALLOC_DECLARE(M_NFSMNT); 30630354SphkMALLOC_DECLARE(M_NFSDIROFF); 30730354SphkMALLOC_DECLARE(M_NFSRVDESC); 30830354SphkMALLOC_DECLARE(M_NFSUID); 30930354SphkMALLOC_DECLARE(M_NQLEASE); 31030354SphkMALLOC_DECLARE(M_NFSD); 31130354SphkMALLOC_DECLARE(M_NFSBIGFH); 31230354Sphk#endif 31330354Sphk 3144067Swollmanstruct uio; struct buf; struct vattr; struct nameidata; /* XXX */ 3154067Swollman 31632998Sbde/* 31732998Sbde * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts. 31832998Sbde * What should be in this set is open to debate, but I believe that since 31932998Sbde * I/O system calls on ufs are never interrupted by signals the set should 32032998Sbde * be minimal. My reasoning is that many current programs that use signals 32132998Sbde * such as SIGALRM will not expect file I/O system calls to be interrupted 32232998Sbde * by them and break. 32332998Sbde */ 3241541Srgrimes#define NFSINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \ 3251541Srgrimes sigmask(SIGHUP)|sigmask(SIGQUIT)) 3261541Srgrimes 3271541Srgrimes/* 3281541Srgrimes * Socket errors ignored for connectionless sockets?? 3291541Srgrimes * For now, ignore them all 3301541Srgrimes */ 3311541Srgrimes#define NFSIGNORE_SOERROR(s, e) \ 3321541Srgrimes ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \ 3331541Srgrimes ((s) & PR_CONNREQUIRED) == 0) 3341541Srgrimes 3351541Srgrimes/* 3361541Srgrimes * Nfs outstanding request list element 3371541Srgrimes */ 3381541Srgrimesstruct nfsreq { 3393664Sphk TAILQ_ENTRY(nfsreq) r_chain; 3401541Srgrimes struct mbuf *r_mreq; 3411541Srgrimes struct mbuf *r_mrep; 3421541Srgrimes struct mbuf *r_md; 3431541Srgrimes caddr_t r_dpos; 3441541Srgrimes struct nfsmount *r_nmp; 3451541Srgrimes struct vnode *r_vp; 3461541Srgrimes u_long r_xid; 3471541Srgrimes int r_flags; /* flags on request, see below */ 3481541Srgrimes int r_retry; /* max retransmission count */ 3491541Srgrimes int r_rexmit; /* current retrans count */ 3501541Srgrimes int r_timer; /* tick counter on reply */ 35126420Sdfr u_int32_t r_procnum; /* NFS procedure number */ 3521541Srgrimes int r_rtt; /* RTT for rpc */ 3531541Srgrimes struct proc *r_procp; /* Proc that did I/O system call */ 3541541Srgrimes}; 3551541Srgrimes 3563664Sphk/* 3573664Sphk * Queue head for nfsreq's 3583664Sphk */ 3599759Sbdeextern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq; 3603664Sphk 3611541Srgrimes/* Flag values for r_flags */ 3621541Srgrimes#define R_TIMING 0x01 /* timing request (in mntp) */ 3631541Srgrimes#define R_SENT 0x02 /* request has been sent */ 3641541Srgrimes#define R_SOFTTERM 0x04 /* soft mnt, too many retries */ 3651541Srgrimes#define R_INTR 0x08 /* intr mnt, signal pending */ 3661541Srgrimes#define R_SOCKERR 0x10 /* Fatal error on socket */ 3671541Srgrimes#define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */ 3681541Srgrimes#define R_MUSTRESEND 0x40 /* Must resend request */ 3691541Srgrimes#define R_GETONEREP 0x80 /* Probe for one reply only */ 3701541Srgrimes 3711541Srgrimes/* 3721541Srgrimes * A list of nfssvc_sock structures is maintained with all the sockets 3731541Srgrimes * that require service by the nfsd. 3741541Srgrimes * The nfsuid structs hang off of the nfssvc_sock structs in both lru 3751541Srgrimes * and uid hash lists. 3761541Srgrimes */ 3779336Sdfr#ifndef NFS_UIDHASHSIZ 3789336Sdfr#define NFS_UIDHASHSIZ 29 /* Tune the size of nfssvc_sock with this */ 3799336Sdfr#endif 3803664Sphk#define NUIDHASH(sock, uid) \ 3819336Sdfr (&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ]) 3829336Sdfr#ifndef NFS_WDELAYHASHSIZ 3839336Sdfr#define NFS_WDELAYHASHSIZ 16 /* and with this */ 3849336Sdfr#endif 3859336Sdfr#define NWDELAYHASH(sock, f) \ 3869336Sdfr (&(sock)->ns_wdelayhashtbl[(*((u_long *)(f))) % NFS_WDELAYHASHSIZ]) 3879336Sdfr#ifndef NFS_MUIDHASHSIZ 38819449Sdfr#define NFS_MUIDHASHSIZ 63 /* Tune the size of nfsmount with this */ 3899336Sdfr#endif 3909336Sdfr#define NMUIDHASH(nmp, uid) \ 3919336Sdfr (&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ]) 3929336Sdfr#define NFSNOHASH(fhsum) \ 3939336Sdfr (&nfsnodehashtbl[(fhsum) & nfsnodehash]) 3941541Srgrimes 3951541Srgrimesstruct nfsuid { 3963664Sphk TAILQ_ENTRY(nfsuid) nu_lru; /* LRU chain */ 3973664Sphk LIST_ENTRY(nfsuid) nu_hash; /* Hash list */ 3981541Srgrimes int nu_flag; /* Flags */ 3991541Srgrimes union nethostaddr nu_haddr; /* Host addr. for dgram sockets */ 4001541Srgrimes struct ucred nu_cr; /* Cred uid mapped to */ 4019336Sdfr int nu_expire; /* Expiry time (sec) */ 4029336Sdfr struct timeval nu_timestamp; /* Kerb. timestamp */ 4039336Sdfr u_long nu_nickname; /* Nickname on server */ 4049336Sdfr NFSKERBKEY_T nu_key; /* and session key */ 4051541Srgrimes}; 4061541Srgrimes 4071541Srgrimes#define nu_inetaddr nu_haddr.had_inetaddr 4081541Srgrimes#define nu_nam nu_haddr.had_nam 4091541Srgrimes/* Bits for nu_flag */ 4101541Srgrimes#define NU_INETADDR 0x1 4119336Sdfr#define NU_NAM 0x2 4129336Sdfr#define NU_NETFAM(u) (((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO) 4131541Srgrimes 41425781Sdfrstruct nfsrv_rec { 41525781Sdfr STAILQ_ENTRY(nfsrv_rec) nr_link; 41628270Swollman struct sockaddr *nr_address; 41725781Sdfr struct mbuf *nr_packet; 41825781Sdfr}; 41925781Sdfr 4201541Srgrimesstruct nfssvc_sock { 4213664Sphk TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */ 4223664Sphk TAILQ_HEAD(, nfsuid) ns_uidlruhead; 4231541Srgrimes struct file *ns_fp; 4241541Srgrimes struct socket *ns_so; 42528270Swollman struct sockaddr *ns_nam; 4261541Srgrimes struct mbuf *ns_raw; 4271541Srgrimes struct mbuf *ns_rawend; 42825781Sdfr STAILQ_HEAD(, nfsrv_rec) ns_rec; 4299336Sdfr struct mbuf *ns_frag; 4309336Sdfr int ns_flag; 4319336Sdfr int ns_solock; 4329336Sdfr int ns_cc; 4339336Sdfr int ns_reclen; 4341541Srgrimes int ns_numuids; 4359336Sdfr u_long ns_sref; 4369336Sdfr LIST_HEAD(, nfsrv_descript) ns_tq; /* Write gather lists */ 4379336Sdfr LIST_HEAD(, nfsuid) ns_uidhashtbl[NFS_UIDHASHSIZ]; 4389336Sdfr LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ]; 4391541Srgrimes}; 4401541Srgrimes 4411541Srgrimes/* Bits for "ns_flag" */ 4421541Srgrimes#define SLP_VALID 0x01 4431541Srgrimes#define SLP_DOREC 0x02 4441541Srgrimes#define SLP_NEEDQ 0x04 4451541Srgrimes#define SLP_DISCONN 0x08 4461541Srgrimes#define SLP_GETSTREAM 0x10 4479336Sdfr#define SLP_LASTFRAG 0x20 4481541Srgrimes#define SLP_ALLFLAGS 0xff 4491541Srgrimes 4509759Sbdeextern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead; 4519759Sbdeextern int nfssvc_sockhead_flag; 4523664Sphk#define SLP_INIT 0x01 4533664Sphk#define SLP_WANTINIT 0x02 4543664Sphk 4551541Srgrimes/* 4561541Srgrimes * One of these structures is allocated for each nfsd. 4571541Srgrimes */ 4581541Srgrimesstruct nfsd { 4599336Sdfr TAILQ_ENTRY(nfsd) nfsd_chain; /* List of all nfsd's */ 4609336Sdfr int nfsd_flag; /* NFSD_ flags */ 4619336Sdfr struct nfssvc_sock *nfsd_slp; /* Current socket */ 4629336Sdfr int nfsd_authlen; /* Authenticator len */ 4639336Sdfr u_char nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */ 4649336Sdfr int nfsd_verflen; /* and the Verifier */ 4659336Sdfr u_char nfsd_verfstr[RPCVERF_MAXSIZ]; 4669336Sdfr struct proc *nfsd_procp; /* Proc ptr */ 4679336Sdfr struct nfsrv_descript *nfsd_nd; /* Associated nfsrv_descript */ 4681541Srgrimes}; 4691541Srgrimes 4709336Sdfr/* Bits for "nfsd_flag" */ 4711541Srgrimes#define NFSD_WAITING 0x01 4723664Sphk#define NFSD_REQINPROG 0x02 4733664Sphk#define NFSD_NEEDAUTH 0x04 4743664Sphk#define NFSD_AUTHFAIL 0x08 4753305Sphk 4769336Sdfr/* 4779336Sdfr * This structure is used by the server for describing each request. 4789336Sdfr * Some fields are used only when write request gathering is performed. 4799336Sdfr */ 4809336Sdfrstruct nfsrv_descript { 4819336Sdfr u_quad_t nd_time; /* Write deadline (usec) */ 4829336Sdfr off_t nd_off; /* Start byte offset */ 4839336Sdfr off_t nd_eoff; /* and end byte offset */ 4849336Sdfr LIST_ENTRY(nfsrv_descript) nd_hash; /* Hash list */ 4859336Sdfr LIST_ENTRY(nfsrv_descript) nd_tq; /* and timer list */ 4869336Sdfr LIST_HEAD(,nfsrv_descript) nd_coalesce; /* coalesced writes */ 4879336Sdfr struct mbuf *nd_mrep; /* Request mbuf list */ 4889336Sdfr struct mbuf *nd_md; /* Current dissect mbuf */ 4899336Sdfr struct mbuf *nd_mreq; /* Reply mbuf list */ 49028270Swollman struct sockaddr *nd_nam; /* and socket addr */ 49128270Swollman struct sockaddr *nd_nam2; /* return socket addr */ 4929336Sdfr caddr_t nd_dpos; /* Current dissect pos */ 49326420Sdfr u_int32_t nd_procnum; /* RPC # */ 4949336Sdfr int nd_stable; /* storage type */ 4959336Sdfr int nd_flag; /* nd_flag */ 4969336Sdfr int nd_len; /* Length of this write */ 4979336Sdfr int nd_repstat; /* Reply status */ 4989336Sdfr u_long nd_retxid; /* Reply xid */ 4999336Sdfr u_long nd_duration; /* Lease duration */ 5009336Sdfr struct timeval nd_starttime; /* Time RPC initiated */ 5019336Sdfr fhandle_t nd_fh; /* File handle */ 5029336Sdfr struct ucred nd_cr; /* Credentials */ 5039336Sdfr}; 5049336Sdfr 5059336Sdfr/* Bits for "nd_flag" */ 5069336Sdfr#define ND_READ LEASE_READ 5079336Sdfr#define ND_WRITE LEASE_WRITE 5089336Sdfr#define ND_CHECK 0x04 5099336Sdfr#define ND_LEASE (ND_READ | ND_WRITE | ND_CHECK) 5109336Sdfr#define ND_NFSV3 0x08 5119336Sdfr#define ND_NQNFS 0x10 5129336Sdfr#define ND_KERBNICK 0x20 5139336Sdfr#define ND_KERBFULL 0x40 5149336Sdfr#define ND_KERBAUTH (ND_KERBNICK | ND_KERBFULL) 5159336Sdfr 5169759Sbdeextern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head; 5179759Sbdeextern int nfsd_head_flag; 5183664Sphk#define NFSD_CHECKSLP 0x01 5193664Sphk 5209336Sdfr/* 5219336Sdfr * These macros compare nfsrv_descript structures. 5229336Sdfr */ 5239336Sdfr#define NFSW_CONTIG(o, n) \ 5249336Sdfr ((o)->nd_eoff >= (n)->nd_off && \ 5259336Sdfr !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH)) 5269336Sdfr 5279336Sdfr#define NFSW_SAMECRED(o, n) \ 5289336Sdfr (((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \ 5299336Sdfr !bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \ 5309336Sdfr sizeof (struct ucred))) 5319336Sdfr 53227446Sdfr/* 53327446Sdfr * Defines for WebNFS 53427446Sdfr */ 53527446Sdfr 53627446Sdfr#define WEBNFS_ESC_CHAR '%' 53727446Sdfr#define WEBNFS_SPECCHAR_START 0x80 53827446Sdfr 53927446Sdfr#define WEBNFS_NATIVE_CHAR 0x80 54027446Sdfr/* 54127446Sdfr * .. 54227446Sdfr * Possibly more here in the future. 54327446Sdfr */ 54427446Sdfr 54527446Sdfr/* 54627446Sdfr * Macro for converting escape characters in WebNFS pathnames. 54727446Sdfr * Should really be in libkern. 54827446Sdfr */ 54927446Sdfr 55027446Sdfr#define HEXTOC(c) \ 55127446Sdfr ((c) >= 'a' ? ((c) - ('a' - 10)) : \ 55227446Sdfr ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0'))) 55327446Sdfr#define HEXSTRTOI(p) \ 55427446Sdfr ((HEXTOC(p[0]) << 4) + HEXTOC(p[1])) 55527446Sdfr 55625663Sdfr#ifdef NFS_DEBUG 55722521Sdyson 55825663Sdfrextern int nfs_debug; 55925663Sdfr#define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */ 56025663Sdfr#define NFS_DEBUG_WG 2 /* server write gathering */ 56125663Sdfr#define NFS_DEBUG_RC 4 /* server request caching */ 56225663Sdfr 56325663Sdfr#define NFS_DPF(cat, args) \ 56425663Sdfr do { \ 56525663Sdfr if (nfs_debug & NFS_DEBUG_##cat) printf args; \ 56625663Sdfr } while (0) 56725663Sdfr 56825663Sdfr#else 56925663Sdfr 57025663Sdfr#define NFS_DPF(cat, args) 57125663Sdfr 57225663Sdfr#endif 57325663Sdfr 57434961Sphku_quad_t nfs_curusec __P((void)); 57522521Sdysonint nfs_init __P((struct vfsconf *vfsp)); 5763305Sphkint nfs_reply __P((struct nfsreq *)); 5779336Sdfrint nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int)); 57828270Swollmanint nfs_send __P((struct socket *, struct sockaddr *, struct mbuf *, 57928270Swollman struct nfsreq *)); 58028270Swollmanint nfs_rephead __P((int, struct nfsrv_descript *, struct nfssvc_sock *, 58128270Swollman int, int, u_quad_t *, struct mbuf **, struct mbuf **, 58228270Swollman caddr_t *)); 58328270Swollmanint nfs_sndlock __P((int *, struct nfsreq *)); 58412453Sbdevoid nfs_sndunlock __P((int *flagp)); 58528270Swollmanint nfs_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *)); 58628270Swollmanint nfs_vinvalbuf __P((struct vnode *, int, struct ucred *, struct proc *, 58728270Swollman int)); 58828270Swollmanint nfs_readrpc __P((struct vnode *, struct uio *, struct ucred *)); 58928270Swollmanint nfs_writerpc __P((struct vnode *, struct uio *, struct ucred *, int *, 59028270Swollman int *)); 59128270Swollmanint nfs_readdirrpc __P((struct vnode *, struct uio *, struct ucred *)); 59228270Swollmanint nfs_asyncio __P((struct buf *, struct ucred *)); 59328270Swollmanint nfs_doio __P((struct buf *, struct ucred *, struct proc *)); 59428270Swollmanint nfs_readlinkrpc __P((struct vnode *, struct uio *, struct ucred *)); 59528270Swollmanint nfs_sigintr __P((struct nfsmount *, struct nfsreq *, struct proc *)); 59628270Swollmanint nfs_readdirplusrpc __P((struct vnode *, struct uio *, struct ucred *)); 59728270Swollmanint nfsm_disct __P((struct mbuf **, caddr_t *, int, int, caddr_t *)); 59828270Swollmanvoid nfsm_srvfattr __P((struct nfsrv_descript *, struct vattr *, 59928270Swollman struct nfs_fattr *)); 60028270Swollmanvoid nfsm_srvwcc __P((struct nfsrv_descript *, int, struct vattr *, int, 60128270Swollman struct vattr *, struct mbuf **, char **)); 60228270Swollmanvoid nfsm_srvpostopattr __P((struct nfsrv_descript *, int, struct vattr *, 60328270Swollman struct mbuf **, char **)); 60428270Swollmanint netaddr_match __P((int, union nethostaddr *, struct sockaddr *)); 60528270Swollmanint nfs_request __P((struct vnode *, struct mbuf *, int, struct proc *, 60628270Swollman struct ucred *, struct mbuf **, struct mbuf **, 60728270Swollman caddr_t *)); 60828270Swollmanint nfs_loadattrcache __P((struct vnode **, struct mbuf **, caddr_t *, 60928270Swollman struct vattr *)); 61028270Swollmanint nfs_namei __P((struct nameidata *, fhandle_t *, int, 61128270Swollman struct nfssvc_sock *, struct sockaddr *, struct mbuf **, 61228270Swollman caddr_t *, struct vnode **, struct proc *, int, int)); 61328270Swollmanvoid nfsm_adj __P((struct mbuf *, int, int)); 61428270Swollmanint nfsm_mbuftouio __P((struct mbuf **, struct uio *, int, caddr_t *)); 6153305Sphkvoid nfsrv_initcache __P((void)); 61628270Swollmanint nfs_getauth __P((struct nfsmount *, struct nfsreq *, struct ucred *, 61728270Swollman char **, int *, char *, int *, NFSKERBKEY_T)); 61828270Swollmanint nfs_getnickauth __P((struct nfsmount *, struct ucred *, char **, 61928270Swollman int *, char *, int)); 62028270Swollmanint nfs_savenickauth __P((struct nfsmount *, struct ucred *, int, 62128270Swollman NFSKERBKEY_T, struct mbuf **, char **, 62228270Swollman struct mbuf *)); 62328270Swollmanint nfs_adv __P((struct mbuf **, caddr_t *, int, int)); 6243305Sphkvoid nfs_nhinit __P((void)); 6253305Sphkvoid nfs_timer __P((void*)); 62628270Swollmanu_long nfs_hash __P((nfsfh_t *, int)); 62728270Swollmanint nfsrv_dorec __P((struct nfssvc_sock *, struct nfsd *, 62828270Swollman struct nfsrv_descript **)); 62928270Swollmanint nfsrv_getcache __P((struct nfsrv_descript *, struct nfssvc_sock *, 63028270Swollman struct mbuf **)); 63128270Swollmanvoid nfsrv_updatecache __P((struct nfsrv_descript *, int, struct mbuf *)); 63222521Sdysonvoid nfsrv_cleancache __P((void)); 63328270Swollmanint nfs_connect __P((struct nfsmount *, struct nfsreq *)); 63422521Sdysonvoid nfs_disconnect __P((struct nfsmount *)); 63528270Swollmanint nfs_getattrcache __P((struct vnode *, struct vattr *)); 63628270Swollmanint nfsm_strtmbuf __P((struct mbuf **, char **, char *, long)); 63728270Swollmanint nfs_bioread __P((struct vnode *, struct uio *, int, struct ucred *, 63828270Swollman int)); 63928270Swollmanint nfsm_uiotombuf __P((struct uio *, struct mbuf **, int, caddr_t *)); 6403305Sphkvoid nfsrv_init __P((int)); 6419336Sdfrvoid nfs_clearcommit __P((struct mount *)); 6429336Sdfrint nfsrv_errmap __P((struct nfsrv_descript *, int)); 64328270Swollmanvoid nfsrvw_sort __P((gid_t *, int)); 64428270Swollmanvoid nfsrv_setcred __P((struct ucred *, struct ucred *)); 64528270Swollmanint nfs_writebp __P((struct buf *, int)); 64628270Swollmanint nfsrv_object_create __P((struct vnode *)); 64712588Sbdevoid nfsrv_wakenfsd __P((struct nfssvc_sock *slp)); 6489336Sdfrint nfsrv_writegather __P((struct nfsrv_descript **, struct nfssvc_sock *, 6499336Sdfr struct proc *, struct mbuf **)); 6509336Sdfrint nfs_fsinfo __P((struct nfsmount *, struct vnode *, struct ucred *, 6519336Sdfr struct proc *p)); 6526361Sphk 65328270Swollmanint nfsrv3_access __P((struct nfsrv_descript *nfsd, 65428270Swollman struct nfssvc_sock *slp, 65512588Sbde struct proc *procp, struct mbuf **mrq)); 65612588Sbdeint nfsrv_commit __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 65712588Sbde struct proc *procp, struct mbuf **mrq)); 65812588Sbdeint nfsrv_create __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 65912588Sbde struct proc *procp, struct mbuf **mrq)); 66028270Swollmanint nfsrv_fhtovp __P((fhandle_t *, int, struct vnode **, struct ucred *, 66128270Swollman struct nfssvc_sock *, struct sockaddr *, int *, 66228270Swollman int, int)); 66327446Sdfrint nfsrv_setpublicfs __P((struct mount *, struct netexport *, 66427446Sdfr struct export_args *)); 66527446Sdfrint nfs_ispublicfh __P((fhandle_t *)); 66612588Sbdeint nfsrv_fsinfo __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 66712588Sbde struct proc *procp, struct mbuf **mrq)); 66812588Sbdeint nfsrv_getattr __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 66912588Sbde struct proc *procp, struct mbuf **mrq)); 67012588Sbdeint nfsrv_link __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 67112588Sbde struct proc *procp, struct mbuf **mrq)); 67212588Sbdeint nfsrv_lookup __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 67312588Sbde struct proc *procp, struct mbuf **mrq)); 67412588Sbdeint nfsrv_mkdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 67512588Sbde struct proc *procp, struct mbuf **mrq)); 67612588Sbdeint nfsrv_mknod __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 67712588Sbde struct proc *procp, struct mbuf **mrq)); 67812588Sbdeint nfsrv_noop __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 67912588Sbde struct proc *procp, struct mbuf **mrq)); 68012588Sbdeint nfsrv_null __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 68112588Sbde struct proc *procp, struct mbuf **mrq)); 68212588Sbdeint nfsrv_pathconf __P((struct nfsrv_descript *nfsd, 68312588Sbde struct nfssvc_sock *slp, struct proc *procp, 68412588Sbde struct mbuf **mrq)); 68512588Sbdeint nfsrv_read __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 68612588Sbde struct proc *procp, struct mbuf **mrq)); 68728270Swollmanint nfsrv_readdir __P((struct nfsrv_descript *nfsd, 68828270Swollman struct nfssvc_sock *slp, 68912588Sbde struct proc *procp, struct mbuf **mrq)); 69012588Sbdeint nfsrv_readdirplus __P((struct nfsrv_descript *nfsd, 69112588Sbde struct nfssvc_sock *slp, struct proc *procp, 69212588Sbde struct mbuf **mrq)); 69312588Sbdeint nfsrv_readlink __P((struct nfsrv_descript *nfsd, 69412588Sbde struct nfssvc_sock *slp, struct proc *procp, 69512588Sbde struct mbuf **mrq)); 69612588Sbdeint nfsrv_remove __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 69712588Sbde struct proc *procp, struct mbuf **mrq)); 69812588Sbdeint nfsrv_rename __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 69912588Sbde struct proc *procp, struct mbuf **mrq)); 70012588Sbdeint nfsrv_rmdir __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 70112588Sbde struct proc *procp, struct mbuf **mrq)); 70228270Swollmanint nfsrv_setattr __P((struct nfsrv_descript *nfsd, 70328270Swollman struct nfssvc_sock *slp, 70412588Sbde struct proc *procp, struct mbuf **mrq)); 70528270Swollmanint nfsrv_statfs __P((struct nfsrv_descript *nfsd, 70628270Swollman struct nfssvc_sock *slp, 70712588Sbde struct proc *procp, struct mbuf **mrq)); 70828270Swollmanint nfsrv_symlink __P((struct nfsrv_descript *nfsd, 70928270Swollman struct nfssvc_sock *slp, 71012588Sbde struct proc *procp, struct mbuf **mrq)); 71112588Sbdeint nfsrv_write __P((struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 71212588Sbde struct proc *procp, struct mbuf **mrq)); 71322521Sdysonvoid nfsrv_rcv __P((struct socket *so, caddr_t arg, int waitflag)); 71422521Sdysonvoid nfsrv_slpderef __P((struct nfssvc_sock *slp)); 7151541Srgrimes#endif /* KERNEL */ 7162175Spaul 7172175Spaul#endif 718