1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 1989, 1993, 1995 5 * The Regents of the University of California. All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * Rick Macklem at The University of Guelph. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)nfs.h 8.4 (Berkeley) 5/1/95 35 * $FreeBSD$ 36 */ 37 38 #ifndef _NFSCLIENT_NFS_H_ 39 #define _NFSCLIENT_NFS_H_ 40 41 #ifdef _KERNEL 42 #include "opt_nfs.h" 43 #endif 44 45 #include <nfsclient/nfsargs.h> 46 47 /* 48 * Tunable constants for nfs 49 */ 50 51 #define NFS_TICKINTVL 10 /* Desired time for a tick (msec) */ 52 #define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */ 53 #define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */ 54 #define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */ 55 #define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */ 56 #define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/ 57 #define NFS_MAXREXMIT 100 /* Stop counting after this many */ 58 #define NFS_RETRANS 10 /* Num of retrans for UDP soft mounts */ 59 #define NFS_RETRANS_TCP 2 /* Num of retrans for TCP soft mounts */ 60 #define NFS_MAXGRPS 16 /* Max. size of groups list */ 61 #ifndef NFS_MINATTRTIMO 62 #define NFS_MINATTRTIMO 3 /* VREG attrib cache timeout in sec */ 63 #endif 64 #ifndef NFS_MAXATTRTIMO 65 #define NFS_MAXATTRTIMO 60 66 #endif 67 #ifndef NFS_MINDIRATTRTIMO 68 #define NFS_MINDIRATTRTIMO 3 /* VDIR attrib cache timeout in sec */ 69 #endif 70 #ifndef NFS_MAXDIRATTRTIMO 71 #define NFS_MAXDIRATTRTIMO 60 72 #endif 73 #ifndef NFS_ACCESSCACHESIZE 74 #define NFS_ACCESSCACHESIZE 8 /* Per-node access cache entries */ 75 #endif 76 #define NFS_WSIZE 8192 /* Def. write data size <= 8192 */ 77 #define NFS_RSIZE 8192 /* Def. read data size <= 8192 */ 78 #define NFS_READDIRSIZE 8192 /* Def. readdir size */ 79 #define NFS_DEFRAHEAD 1 /* Def. read ahead # blocks */ 80 #define NFS_MAXRAHEAD 4 /* Max. read ahead # blocks */ 81 #define NFS_MAXASYNCDAEMON 64 /* Max. number async_daemons runnable */ 82 #define NFS_DIRBLKSIZ 4096 /* Must be a multiple of DIRBLKSIZ */ 83 #ifdef _KERNEL 84 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */ 85 #endif 86 #define NFS_MAXDEADTHRESH 9 /* How long till we say 'server not responding' */ 87 88 /* 89 * Oddballs 90 */ 91 #define NFS_CMPFH(n, f, s) \ 92 ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s))) 93 #define NFS_ISV3(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3) 94 #define NFS_ISV4(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV4) 95 96 #define NFSSTA_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */ 97 #define NFSSTA_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */ 98 #define NFSSTA_SNDLOCK 0x01000000 /* Send socket lock */ 99 #define NFSSTA_WANTSND 0x02000000 /* Want above */ 100 #define NFSSTA_TIMEO 0x10000000 /* Experiencing a timeout */ 101 #define NFSSTA_LOCKTIMEO 0x20000000 /* Experiencing a lockd timeout */ 102 103 /* 104 * XXX to allow amd to include nfs.h without nfsproto.h 105 */ 106 #ifdef NFS_NPROCS 107 #include <nfsclient/nfsstats.h> 108 #endif 109 110 /* 111 * vfs.oldnfs sysctl(3) identifiers 112 */ 113 #define NFS_NFSSTATS 1 /* struct: struct nfsstats */ 114 115 #ifdef _KERNEL 116 117 #ifdef MALLOC_DECLARE 118 MALLOC_DECLARE(M_NFSDIROFF); 119 MALLOC_DECLARE(M_NFSDIRECTIO); 120 #endif 121 122 extern struct uma_zone *nfsmount_zone; 123 124 extern struct nfsstats nfsstats; 125 extern struct mtx nfs_iod_mtx; 126 extern struct task nfs_nfsiodnew_task; 127 128 extern int nfs_numasync; 129 extern unsigned int nfs_iodmax; 130 extern int nfs_pbuf_freecnt; 131 extern int nfs_ticks; 132 133 /* Data constants in XDR form */ 134 extern u_int32_t nfs_true, nfs_false, nfs_xdrneg1; 135 extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers; 136 extern u_int32_t rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr; 137 138 extern int nfsv3_procid[NFS_NPROCS]; 139 140 /* 141 * Socket errors ignored for connectionless sockets?? 142 * For now, ignore them all 143 */ 144 #define NFSIGNORE_SOERROR(s, e) \ 145 ((e) != EINTR && (e) != EIO && \ 146 (e) != ERESTART && (e) != EWOULDBLOCK && \ 147 ((s) & PR_CONNREQUIRED) == 0) 148 149 struct nfsmount; 150 151 struct buf; 152 struct socket; 153 struct uio; 154 struct vattr; 155 156 /* 157 * Pointers to ops that differ from v3 to v4 158 */ 159 struct nfs_rpcops { 160 int (*nr_readrpc)(struct vnode *vp, struct uio *uiop, 161 struct ucred *cred); 162 int (*nr_writerpc)(struct vnode *vp, struct uio *uiop, 163 struct ucred *cred, int *iomode, int *must_commit); 164 int (*nr_writebp)(struct buf *bp, int force, struct thread *td); 165 int (*nr_readlinkrpc)(struct vnode *vp, struct uio *uiop, 166 struct ucred *cred); 167 void (*nr_invaldir)(struct vnode *vp); 168 int (*nr_commit)(struct vnode *vp, u_quad_t offset, int cnt, 169 struct ucred *cred, struct thread *td); 170 }; 171 172 /* 173 * Defines for WebNFS 174 */ 175 176 #define WEBNFS_ESC_CHAR '%' 177 #define WEBNFS_SPECCHAR_START 0x80 178 179 #define WEBNFS_NATIVE_CHAR 0x80 180 /* 181 * .. 182 * Possibly more here in the future. 183 */ 184 185 /* 186 * Macro for converting escape characters in WebNFS pathnames. 187 * Should really be in libkern. 188 */ 189 190 #define HEXTOC(c) \ 191 ((c) >= 'a' ? ((c) - ('a' - 10)) : \ 192 ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0'))) 193 #define HEXSTRTOI(p) \ 194 ((HEXTOC(p[0]) << 4) + HEXTOC(p[1])) 195 196 /* nfs_sigintr() helper, when 'rep' has all we need */ 197 #define NFS_SIGREP(rep) nfs_sigintr((rep)->r_nmp, (rep), (rep)->r_td) 198 199 #ifdef NFS_DEBUG 200 201 extern int nfs_debug; 202 #define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */ 203 #define NFS_DEBUG_WG 2 /* server write gathering */ 204 #define NFS_DEBUG_RC 4 /* server request caching */ 205 206 #define NFS_DPF(cat, args) \ 207 do { \ 208 if (nfs_debug & NFS_DEBUG_##cat) printf args; \ 209 } while (0) 210 211 #else 212 213 #define NFS_DPF(cat, args) 214 215 #endif 216 217 /* 218 * On fast networks, the estimator will try to reduce the 219 * timeout lower than the latency of the server's disks, 220 * which results in too many timeouts, so cap the lower 221 * bound. 222 */ 223 #define NFS_MINRTO (NFS_HZ >> 2) 224 225 /* 226 * Keep the RTO from increasing to unreasonably large values 227 * when a server is not responding. 228 */ 229 #define NFS_MAXRTO (20 * NFS_HZ) 230 231 enum nfs_rto_timer_t { 232 NFS_DEFAULT_TIMER, 233 NFS_GETATTR_TIMER, 234 NFS_LOOKUP_TIMER, 235 NFS_READ_TIMER, 236 NFS_WRITE_TIMER, 237 }; 238 #define NFS_MAX_TIMER (NFS_WRITE_TIMER) 239 240 #define NFS_INITRTT (NFS_HZ << 3) 241 242 vfs_init_t nfs_init; 243 vfs_uninit_t nfs_uninit; 244 int nfs_mountroot(struct mount *mp); 245 246 void nfs_purgecache(struct vnode *); 247 int nfs_vinvalbuf(struct vnode *, int, struct thread *, int); 248 int nfs_readrpc(struct vnode *, struct uio *, struct ucred *); 249 int nfs_writerpc(struct vnode *, struct uio *, struct ucred *, int *, 250 int *); 251 int nfs_commit(struct vnode *vp, u_quad_t offset, int cnt, 252 struct ucred *cred, struct thread *td); 253 int nfs_readdirrpc(struct vnode *, struct uio *, struct ucred *); 254 void nfs_nfsiodnew(void); 255 void nfs_nfsiodnew_tq(__unused void *, int); 256 int nfs_asyncio(struct nfsmount *, struct buf *, struct ucred *, struct thread *); 257 int nfs_doio(struct vnode *, struct buf *, struct ucred *, struct thread *); 258 void nfs_doio_directwrite (struct buf *); 259 int nfs_readlinkrpc(struct vnode *, struct uio *, struct ucred *); 260 int nfs_sigintr(struct nfsmount *, struct thread *); 261 int nfs_readdirplusrpc(struct vnode *, struct uio *, struct ucred *); 262 int nfs_request(struct vnode *, struct mbuf *, int, struct thread *, 263 struct ucred *, struct mbuf **, struct mbuf **, caddr_t *); 264 int nfs_loadattrcache(struct vnode **, struct mbuf **, caddr_t *, 265 struct vattr *, int); 266 int nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *); 267 void nfs_nhinit(void); 268 void nfs_nhuninit(void); 269 int nfs_nmcancelreqs(struct nfsmount *); 270 void nfs_timer(void*); 271 272 int nfs_connect(struct nfsmount *); 273 void nfs_disconnect(struct nfsmount *); 274 void nfs_safedisconnect(struct nfsmount *); 275 int nfs_getattrcache(struct vnode *, struct vattr *); 276 int nfs_iosize(struct nfsmount *nmp); 277 int nfsm_strtmbuf(struct mbuf **, char **, const char *, long); 278 int nfs_bioread(struct vnode *, struct uio *, int, struct ucred *); 279 int nfsm_uiotombuf(struct uio *, struct mbuf **, int, caddr_t *); 280 void nfs_clearcommit(struct mount *); 281 int nfs_writebp(struct buf *, int, struct thread *); 282 int nfs_fsinfo(struct nfsmount *, struct vnode *, struct ucred *, 283 struct thread *); 284 int nfs_meta_setsize (struct vnode *, struct ucred *, 285 struct thread *, u_quad_t); 286 287 void nfs_set_sigmask(struct thread *td, sigset_t *oldset); 288 void nfs_restore_sigmask(struct thread *td, sigset_t *set); 289 int nfs_msleep(struct thread *td, void *ident, struct mtx *mtx, 290 int priority, char *wmesg, int timo); 291 292 #endif /* _KERNEL */ 293 294 #endif 295