1c398230bSWarner Losh /*- 2*51369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 3*51369649SPedro F. Giffuni * 4996c772fSJohn Dyson * Copyright (c) 1989, 1993, 1995 5df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 6df8bae1dSRodney W. Grimes * 7df8bae1dSRodney W. Grimes * This code is derived from software contributed to Berkeley by 8df8bae1dSRodney W. Grimes * Rick Macklem at The University of Guelph. 9df8bae1dSRodney W. Grimes * 10df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 11df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 12df8bae1dSRodney W. Grimes * are met: 13df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 14df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 15df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 16df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 17df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 18fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 19df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 20df8bae1dSRodney W. Grimes * without specific prior written permission. 21df8bae1dSRodney W. Grimes * 22df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32df8bae1dSRodney W. Grimes * SUCH DAMAGE. 33df8bae1dSRodney W. Grimes */ 34df8bae1dSRodney W. Grimes 35eb25edbdSPeter Wemm #ifndef _NFSCLIENT_NFS_H_ 36eb25edbdSPeter Wemm #define _NFSCLIENT_NFS_H_ 3733420ec6SPaul Richards 38c4473420SPeter Wemm #ifdef _KERNEL 39df394affSJohn-Mark Gurney #include "opt_nfs.h" 4056786ee9SJohn-Mark Gurney #endif 41df394affSJohn-Mark Gurney 42eb25edbdSPeter Wemm #include <nfsclient/nfsargs.h> 43eb25edbdSPeter Wemm 44df8bae1dSRodney W. Grimes /* 45df8bae1dSRodney W. Grimes * Tunable constants for nfs 46df8bae1dSRodney W. Grimes */ 47df8bae1dSRodney W. Grimes 486df06172SPeter Wemm #define NFS_TICKINTVL 10 /* Desired time for a tick (msec) */ 49a62dc406SDoug Rabson #define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */ 50df8bae1dSRodney W. Grimes #define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */ 51df8bae1dSRodney W. Grimes #define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */ 52df8bae1dSRodney W. Grimes #define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */ 53df8bae1dSRodney W. Grimes #define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/ 54df8bae1dSRodney W. Grimes #define NFS_MAXREXMIT 100 /* Stop counting after this many */ 556d0699a5SChuck Lever #define NFS_RETRANS 10 /* Num of retrans for UDP soft mounts */ 566d0699a5SChuck Lever #define NFS_RETRANS_TCP 2 /* Num of retrans for TCP soft mounts */ 57df8bae1dSRodney W. Grimes #define NFS_MAXGRPS 16 /* Max. size of groups list */ 58b1b76581SDavid Greenman #ifndef NFS_MINATTRTIMO 59fe6c0d45SPeter Wemm #define NFS_MINATTRTIMO 3 /* VREG attrib cache timeout in sec */ 60b1b76581SDavid Greenman #endif 61b1b76581SDavid Greenman #ifndef NFS_MAXATTRTIMO 62df8bae1dSRodney W. Grimes #define NFS_MAXATTRTIMO 60 63b1b76581SDavid Greenman #endif 64fe6c0d45SPeter Wemm #ifndef NFS_MINDIRATTRTIMO 65a58158efSJohn Baldwin #define NFS_MINDIRATTRTIMO 3 /* VDIR attrib cache timeout in sec */ 66fe6c0d45SPeter Wemm #endif 67fe6c0d45SPeter Wemm #ifndef NFS_MAXDIRATTRTIMO 68fe6c0d45SPeter Wemm #define NFS_MAXDIRATTRTIMO 60 69fe6c0d45SPeter Wemm #endif 702a3f3a09SJohn Baldwin #ifndef NFS_ACCESSCACHESIZE 712a3f3a09SJohn Baldwin #define NFS_ACCESSCACHESIZE 8 /* Per-node access cache entries */ 722a3f3a09SJohn Baldwin #endif 73df8bae1dSRodney W. Grimes #define NFS_WSIZE 8192 /* Def. write data size <= 8192 */ 74df8bae1dSRodney W. Grimes #define NFS_RSIZE 8192 /* Def. read data size <= 8192 */ 75a62dc406SDoug Rabson #define NFS_READDIRSIZE 8192 /* Def. readdir size */ 76df8bae1dSRodney W. Grimes #define NFS_DEFRAHEAD 1 /* Def. read ahead # blocks */ 77df8bae1dSRodney W. Grimes #define NFS_MAXRAHEAD 4 /* Max. read ahead # blocks */ 781bde5686SPeter Wemm #define NFS_MAXASYNCDAEMON 64 /* Max. number async_daemons runnable */ 79a62dc406SDoug Rabson #define NFS_DIRBLKSIZ 4096 /* Must be a multiple of DIRBLKSIZ */ 80c4473420SPeter Wemm #ifdef _KERNEL 8100780cefSBruce Evans #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */ 8200780cefSBruce Evans #endif 83eb25edbdSPeter Wemm #define NFS_MAXDEADTHRESH 9 /* How long till we say 'server not responding' */ 84a62dc406SDoug Rabson 85a62dc406SDoug Rabson /* 86a62dc406SDoug Rabson * Oddballs 87a62dc406SDoug Rabson */ 88a62dc406SDoug Rabson #define NFS_CMPFH(n, f, s) \ 89a62dc406SDoug Rabson ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s))) 90a62dc406SDoug Rabson #define NFS_ISV3(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3) 915bbfbd14SMohan Srinivasan #define NFS_ISV4(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV4) 92fe6c0d45SPeter Wemm 93fe6c0d45SPeter Wemm #define NFSSTA_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */ 94fe6c0d45SPeter Wemm #define NFSSTA_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */ 95fe6c0d45SPeter Wemm #define NFSSTA_SNDLOCK 0x01000000 /* Send socket lock */ 96fe6c0d45SPeter Wemm #define NFSSTA_WANTSND 0x02000000 /* Want above */ 97c713aaaeSAlfred Perlstein #define NFSSTA_TIMEO 0x10000000 /* Experiencing a timeout */ 98c675522fSDoug Rabson #define NFSSTA_LOCKTIMEO 0x20000000 /* Experiencing a lockd timeout */ 99c713aaaeSAlfred Perlstein 100df8bae1dSRodney W. Grimes /* 101996c772fSJohn Dyson * XXX to allow amd to include nfs.h without nfsproto.h 102996c772fSJohn Dyson */ 103996c772fSJohn Dyson #ifdef NFS_NPROCS 104eb25edbdSPeter Wemm #include <nfsclient/nfsstats.h> 105996c772fSJohn Dyson #endif 106df8bae1dSRodney W. Grimes 107df8bae1dSRodney W. Grimes /* 108e4301e17SRick Macklem * vfs.oldnfs sysctl(3) identifiers 109b43e29afSGarrett Wollman */ 110b43e29afSGarrett Wollman #define NFS_NFSSTATS 1 /* struct: struct nfsstats */ 111b43e29afSGarrett Wollman 112c4473420SPeter Wemm #ifdef _KERNEL 113d9e91095SGarrett Wollman 114a1c995b6SPoul-Henning Kamp #ifdef MALLOC_DECLARE 115a1c995b6SPoul-Henning Kamp MALLOC_DECLARE(M_NFSDIROFF); 116a7500bceSPaul Saab MALLOC_DECLARE(M_NFSDIRECTIO); 1170d7d0fcfSPeter Wemm #endif 1180d7d0fcfSPeter Wemm 1196af7f1e5SBruce Evans extern struct uma_zone *nfsmount_zone; 120a1c995b6SPoul-Henning Kamp 121eb25edbdSPeter Wemm extern struct nfsstats nfsstats; 122f1cdf899SMohan Srinivasan extern struct mtx nfs_iod_mtx; 12357bfe0a9SKonstantin Belousov extern struct task nfs_nfsiodnew_task; 124cae300beSBruce Evans 125eb25edbdSPeter Wemm extern int nfs_numasync; 1261630ff08SPeter Edwards extern unsigned int nfs_iodmax; 127eb25edbdSPeter Wemm extern int nfs_pbuf_freecnt; 128eb25edbdSPeter Wemm extern int nfs_ticks; 129eb25edbdSPeter Wemm 130eb25edbdSPeter Wemm /* Data constants in XDR form */ 131eb25edbdSPeter Wemm extern u_int32_t nfs_true, nfs_false, nfs_xdrneg1; 132eb25edbdSPeter Wemm extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers; 133eb25edbdSPeter Wemm extern u_int32_t rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr; 134eb25edbdSPeter Wemm 135eb25edbdSPeter Wemm extern int nfsv3_procid[NFS_NPROCS]; 136eb25edbdSPeter Wemm 137bc3de552SBruce Evans /* 138df8bae1dSRodney W. Grimes * Socket errors ignored for connectionless sockets?? 139df8bae1dSRodney W. Grimes * For now, ignore them all 140df8bae1dSRodney W. Grimes */ 141df8bae1dSRodney W. Grimes #define NFSIGNORE_SOERROR(s, e) \ 142c713aaaeSAlfred Perlstein ((e) != EINTR && (e) != EIO && \ 143c713aaaeSAlfred Perlstein (e) != ERESTART && (e) != EWOULDBLOCK && \ 144df8bae1dSRodney W. Grimes ((s) & PR_CONNREQUIRED) == 0) 145df8bae1dSRodney W. Grimes 146a9148abdSDoug Rabson struct nfsmount; 147a9148abdSDoug Rabson 14835259c2cSBruce Evans struct buf; 14935259c2cSBruce Evans struct socket; 15035259c2cSBruce Evans struct uio; 15135259c2cSBruce Evans struct vattr; 15235259c2cSBruce Evans 153e8cf20c8SPeter Wemm /* 15490abe7f2SAlfred Perlstein * Pointers to ops that differ from v3 to v4 15590abe7f2SAlfred Perlstein */ 15690abe7f2SAlfred Perlstein struct nfs_rpcops { 15735259c2cSBruce Evans int (*nr_readrpc)(struct vnode *vp, struct uio *uiop, 15835259c2cSBruce Evans struct ucred *cred); 15935259c2cSBruce Evans int (*nr_writerpc)(struct vnode *vp, struct uio *uiop, 16035259c2cSBruce Evans struct ucred *cred, int *iomode, int *must_commit); 16190abe7f2SAlfred Perlstein int (*nr_writebp)(struct buf *bp, int force, struct thread *td); 16235259c2cSBruce Evans int (*nr_readlinkrpc)(struct vnode *vp, struct uio *uiop, 16335259c2cSBruce Evans struct ucred *cred); 16490abe7f2SAlfred Perlstein void (*nr_invaldir)(struct vnode *vp); 16590abe7f2SAlfred Perlstein int (*nr_commit)(struct vnode *vp, u_quad_t offset, int cnt, 16690abe7f2SAlfred Perlstein struct ucred *cred, struct thread *td); 16790abe7f2SAlfred Perlstein }; 16890abe7f2SAlfred Perlstein 16990abe7f2SAlfred Perlstein /* 170e7756081SDoug Rabson * Defines for WebNFS 171e7756081SDoug Rabson */ 172e7756081SDoug Rabson 173e7756081SDoug Rabson #define WEBNFS_ESC_CHAR '%' 174e7756081SDoug Rabson #define WEBNFS_SPECCHAR_START 0x80 175e7756081SDoug Rabson 176e7756081SDoug Rabson #define WEBNFS_NATIVE_CHAR 0x80 177e7756081SDoug Rabson /* 178e7756081SDoug Rabson * .. 179e7756081SDoug Rabson * Possibly more here in the future. 180e7756081SDoug Rabson */ 181e7756081SDoug Rabson 182e7756081SDoug Rabson /* 183e7756081SDoug Rabson * Macro for converting escape characters in WebNFS pathnames. 184e7756081SDoug Rabson * Should really be in libkern. 185e7756081SDoug Rabson */ 186e7756081SDoug Rabson 187e7756081SDoug Rabson #define HEXTOC(c) \ 188e7756081SDoug Rabson ((c) >= 'a' ? ((c) - ('a' - 10)) : \ 189e7756081SDoug Rabson ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0'))) 190e7756081SDoug Rabson #define HEXSTRTOI(p) \ 191e7756081SDoug Rabson ((HEXTOC(p[0]) << 4) + HEXTOC(p[1])) 192e7756081SDoug Rabson 193c713aaaeSAlfred Perlstein /* nfs_sigintr() helper, when 'rep' has all we need */ 194c713aaaeSAlfred Perlstein #define NFS_SIGREP(rep) nfs_sigintr((rep)->r_nmp, (rep), (rep)->r_td) 195c713aaaeSAlfred Perlstein 1965ae0f718SDoug Rabson #ifdef NFS_DEBUG 1975ae0f718SDoug Rabson 1985ae0f718SDoug Rabson extern int nfs_debug; 1995ae0f718SDoug Rabson #define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */ 2005ae0f718SDoug Rabson #define NFS_DEBUG_WG 2 /* server write gathering */ 2015ae0f718SDoug Rabson #define NFS_DEBUG_RC 4 /* server request caching */ 2025ae0f718SDoug Rabson 2035ae0f718SDoug Rabson #define NFS_DPF(cat, args) \ 2045ae0f718SDoug Rabson do { \ 2055ae0f718SDoug Rabson if (nfs_debug & NFS_DEBUG_##cat) printf args; \ 2065ae0f718SDoug Rabson } while (0) 2075ae0f718SDoug Rabson 2085ae0f718SDoug Rabson #else 2095ae0f718SDoug Rabson 2105ae0f718SDoug Rabson #define NFS_DPF(cat, args) 2115ae0f718SDoug Rabson 2125ae0f718SDoug Rabson #endif 213996c772fSJohn Dyson 21494163ea2SChuck Lever /* 21594163ea2SChuck Lever * On fast networks, the estimator will try to reduce the 21694163ea2SChuck Lever * timeout lower than the latency of the server's disks, 21794163ea2SChuck Lever * which results in too many timeouts, so cap the lower 21894163ea2SChuck Lever * bound. 21994163ea2SChuck Lever */ 22094163ea2SChuck Lever #define NFS_MINRTO (NFS_HZ >> 2) 22194163ea2SChuck Lever 22294163ea2SChuck Lever /* 22394163ea2SChuck Lever * Keep the RTO from increasing to unreasonably large values 22494163ea2SChuck Lever * when a server is not responding. 22594163ea2SChuck Lever */ 22694163ea2SChuck Lever #define NFS_MAXRTO (20 * NFS_HZ) 22794163ea2SChuck Lever 22894163ea2SChuck Lever enum nfs_rto_timer_t { 22994163ea2SChuck Lever NFS_DEFAULT_TIMER, 23094163ea2SChuck Lever NFS_GETATTR_TIMER, 23194163ea2SChuck Lever NFS_LOOKUP_TIMER, 23294163ea2SChuck Lever NFS_READ_TIMER, 23394163ea2SChuck Lever NFS_WRITE_TIMER, 23494163ea2SChuck Lever }; 23594163ea2SChuck Lever #define NFS_MAX_TIMER (NFS_WRITE_TIMER) 23694163ea2SChuck Lever 23794163ea2SChuck Lever #define NFS_INITRTT (NFS_HZ << 3) 23894163ea2SChuck Lever 2399bf1a756SPoul-Henning Kamp vfs_init_t nfs_init; 2409bf1a756SPoul-Henning Kamp vfs_uninit_t nfs_uninit; 241dfd233edSAttilio Rao int nfs_mountroot(struct mount *mp); 2421bf87204SAlfred Perlstein 24334291180SJohn Baldwin void nfs_purgecache(struct vnode *); 24456dd36b1SPoul-Henning Kamp int nfs_vinvalbuf(struct vnode *, int, struct thread *, int); 245eb25edbdSPeter Wemm int nfs_readrpc(struct vnode *, struct uio *, struct ucred *); 246eb25edbdSPeter Wemm int nfs_writerpc(struct vnode *, struct uio *, struct ucred *, int *, 247eb25edbdSPeter Wemm int *); 248eb25edbdSPeter Wemm int nfs_commit(struct vnode *vp, u_quad_t offset, int cnt, 249eb25edbdSPeter Wemm struct ucred *cred, struct thread *td); 250eb25edbdSPeter Wemm int nfs_readdirrpc(struct vnode *, struct uio *, struct ucred *); 251223073fdSKonstantin Belousov void nfs_nfsiodnew(void); 25257bfe0a9SKonstantin Belousov void nfs_nfsiodnew_tq(__unused void *, int); 25335f13408SPoul-Henning Kamp int nfs_asyncio(struct nfsmount *, struct buf *, struct ucred *, struct thread *); 2549f2b7bc4SPoul-Henning Kamp int nfs_doio(struct vnode *, struct buf *, struct ucred *, struct thread *); 255a7500bceSPaul Saab void nfs_doio_directwrite (struct buf *); 256eb25edbdSPeter Wemm int nfs_readlinkrpc(struct vnode *, struct uio *, struct ucred *); 25798c49725SDoug Rabson int nfs_sigintr(struct nfsmount *, struct thread *); 258eb25edbdSPeter Wemm int nfs_readdirplusrpc(struct vnode *, struct uio *, struct ucred *); 259eb25edbdSPeter Wemm int nfs_request(struct vnode *, struct mbuf *, int, struct thread *, 260eb25edbdSPeter Wemm struct ucred *, struct mbuf **, struct mbuf **, caddr_t *); 261eb25edbdSPeter Wemm int nfs_loadattrcache(struct vnode **, struct mbuf **, caddr_t *, 262eb25edbdSPeter Wemm struct vattr *, int); 263eb25edbdSPeter Wemm int nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *); 264eb25edbdSPeter Wemm void nfs_nhinit(void); 2651630ff08SPeter Edwards void nfs_nhuninit(void); 2661278d57aSIan Dowse int nfs_nmcancelreqs(struct nfsmount *); 267eb25edbdSPeter Wemm void nfs_timer(void*); 2681bf87204SAlfred Perlstein 26998c49725SDoug Rabson int nfs_connect(struct nfsmount *); 270eb25edbdSPeter Wemm void nfs_disconnect(struct nfsmount *); 271eb25edbdSPeter Wemm void nfs_safedisconnect(struct nfsmount *); 272eb25edbdSPeter Wemm int nfs_getattrcache(struct vnode *, struct vattr *); 273e43982a8SBruce Evans int nfs_iosize(struct nfsmount *nmp); 274eb25edbdSPeter Wemm int nfsm_strtmbuf(struct mbuf **, char **, const char *, long); 275eb25edbdSPeter Wemm int nfs_bioread(struct vnode *, struct uio *, int, struct ucred *); 276eb25edbdSPeter Wemm int nfsm_uiotombuf(struct uio *, struct mbuf **, int, caddr_t *); 277eb25edbdSPeter Wemm void nfs_clearcommit(struct mount *); 278eb25edbdSPeter Wemm int nfs_writebp(struct buf *, int, struct thread *); 279eb25edbdSPeter Wemm int nfs_fsinfo(struct nfsmount *, struct vnode *, struct ucred *, 280eb25edbdSPeter Wemm struct thread *); 2813ebeaf59SMatthew Dillon int nfs_meta_setsize (struct vnode *, struct ucred *, 2823ebeaf59SMatthew Dillon struct thread *, u_quad_t); 283473e9734SPoul-Henning Kamp 28435259c2cSBruce Evans void nfs_set_sigmask(struct thread *td, sigset_t *oldset); 28535259c2cSBruce Evans void nfs_restore_sigmask(struct thread *td, sigset_t *set); 28635259c2cSBruce Evans int nfs_msleep(struct thread *td, void *ident, struct mtx *mtx, 28735259c2cSBruce Evans int priority, char *wmesg, int timo); 28835ec46b7SPaul Saab 289c4473420SPeter Wemm #endif /* _KERNEL */ 29033420ec6SPaul Richards 29133420ec6SPaul Richards #endif 292