1 /* 2 * Copyright (c) 1989, 1993, 1995 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Rick Macklem at The University of Guelph. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * @(#)nfs.h 8.4 (Berkeley) 5/1/95 37 * $FreeBSD$ 38 */ 39 40 #ifndef _NFSCLIENT_NFS_H_ 41 #define _NFSCLIENT_NFS_H_ 42 43 #ifdef _KERNEL 44 #include "opt_nfs.h" 45 #endif 46 47 #include <nfsclient/nfsargs.h> 48 49 /* 50 * Tunable constants for nfs 51 */ 52 53 #define NFS_TICKINTVL 5 /* Desired time for a tick (msec) */ 54 #define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */ 55 #define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */ 56 #define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */ 57 #define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */ 58 #define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/ 59 #define NFS_MAXREXMIT 100 /* Stop counting after this many */ 60 #define NFS_RETRANS 10 /* Num of retrans for soft mounts */ 61 #define NFS_MAXGRPS 16 /* Max. size of groups list */ 62 #ifndef NFS_MINATTRTIMO 63 #define NFS_MINATTRTIMO 3 /* VREG attrib cache timeout in sec */ 64 #endif 65 #ifndef NFS_MAXATTRTIMO 66 #define NFS_MAXATTRTIMO 60 67 #endif 68 #ifndef NFS_MINDIRATTRTIMO 69 #define NFS_MINDIRATTRTIMO 30 /* VDIR attrib cache timeout in sec */ 70 #endif 71 #ifndef NFS_MAXDIRATTRTIMO 72 #define NFS_MAXDIRATTRTIMO 60 73 #endif 74 #define NFS_WSIZE 8192 /* Def. write data size <= 8192 */ 75 #define NFS_RSIZE 8192 /* Def. read data size <= 8192 */ 76 #define NFS_READDIRSIZE 8192 /* Def. readdir size */ 77 #define NFS_DEFRAHEAD 1 /* Def. read ahead # blocks */ 78 #define NFS_MAXRAHEAD 4 /* Max. read ahead # blocks */ 79 #define NFS_MAXASYNCDAEMON 64 /* Max. number async_daemons runnable */ 80 #define NFS_DIRBLKSIZ 4096 /* Must be a multiple of DIRBLKSIZ */ 81 #ifdef _KERNEL 82 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */ 83 #endif 84 #define NFS_MAXDEADTHRESH 9 /* How long till we say 'server not responding' */ 85 86 /* 87 * Oddballs 88 */ 89 #define NFS_CMPFH(n, f, s) \ 90 ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s))) 91 #define NFS_ISV3(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV3) 92 93 #define NFSSTA_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */ 94 #define NFSSTA_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */ 95 #define NFSSTA_SNDLOCK 0x01000000 /* Send socket lock */ 96 #define NFSSTA_WANTSND 0x02000000 /* Want above */ 97 #define NFSSTA_RCVLOCK 0x04000000 /* Rcv socket lock */ 98 #define NFSSTA_WANTRCV 0x08000000 /* Want above */ 99 100 /* 101 * XXX to allow amd to include nfs.h without nfsproto.h 102 */ 103 #ifdef NFS_NPROCS 104 #include <nfsclient/nfsstats.h> 105 #endif 106 /* 107 * Flags for nfsclnt() system call. 108 */ 109 #define NFSCLNT_LOCKDANS 0x200 110 111 /* 112 * vfs.nfs sysctl(3) identifiers 113 */ 114 #define NFS_NFSSTATS 1 /* struct: struct nfsstats */ 115 116 #ifdef _KERNEL 117 118 #ifdef MALLOC_DECLARE 119 MALLOC_DECLARE(M_NFSREQ); 120 MALLOC_DECLARE(M_NFSDIROFF); 121 MALLOC_DECLARE(M_NFSBIGFH); 122 MALLOC_DECLARE(M_NFSHASH); 123 #endif 124 125 extern uma_zone_t nfsmount_zone; 126 127 extern struct callout_handle nfs_timer_handle; 128 extern struct nfsstats nfsstats; 129 130 extern int nfs_numasync; 131 extern int nfs_pbuf_freecnt; 132 extern int nfs_ticks; 133 134 /* Data constants in XDR form */ 135 extern u_int32_t nfs_true, nfs_false, nfs_xdrneg1; 136 extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers; 137 extern u_int32_t rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr; 138 139 extern int nfsv3_procid[NFS_NPROCS]; 140 141 struct uio; 142 struct buf; 143 struct vattr; 144 struct nameidata; 145 146 /* 147 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts. 148 * What should be in this set is open to debate, but I believe that since 149 * I/O system calls on ufs are never interrupted by signals the set should 150 * be minimal. My reasoning is that many current programs that use signals 151 * such as SIGALRM will not expect file I/O system calls to be interrupted 152 * by them and break. 153 */ 154 #define NFSINT_SIGMASK(set) \ 155 (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \ 156 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \ 157 SIGISMEMBER(set, SIGQUIT)) 158 159 /* 160 * Socket errors ignored for connectionless sockets?? 161 * For now, ignore them all 162 */ 163 #define NFSIGNORE_SOERROR(s, e) \ 164 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \ 165 ((s) & PR_CONNREQUIRED) == 0) 166 167 /* 168 * Nfs outstanding request list element 169 */ 170 struct nfsreq { 171 TAILQ_ENTRY(nfsreq) r_chain; 172 struct mbuf *r_mreq; 173 struct mbuf *r_mrep; 174 struct mbuf *r_md; 175 caddr_t r_dpos; 176 struct nfsmount *r_nmp; 177 struct vnode *r_vp; 178 u_int32_t r_xid; 179 int r_flags; /* flags on request, see below */ 180 int r_retry; /* max retransmission count */ 181 int r_rexmit; /* current retrans count */ 182 int r_timer; /* tick counter on reply */ 183 u_int32_t r_procnum; /* NFS procedure number */ 184 int r_rtt; /* RTT for rpc */ 185 struct thread *r_td; /* Proc that did I/O system call */ 186 }; 187 188 /* 189 * Queue head for nfsreq's 190 */ 191 extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq; 192 193 /* Flag values for r_flags */ 194 #define R_TIMING 0x01 /* timing request (in mntp) */ 195 #define R_SENT 0x02 /* request has been sent */ 196 #define R_SOFTTERM 0x04 /* soft mnt, too many retries */ 197 #define R_INTR 0x08 /* intr mnt, signal pending */ 198 #define R_SOCKERR 0x10 /* Fatal error on socket */ 199 #define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */ 200 #define R_MUSTRESEND 0x40 /* Must resend request */ 201 #define R_GETONEREP 0x80 /* Probe for one reply only */ 202 203 extern struct nfsnodehashhead *nfsnodehashtbl; 204 extern u_long nfsnodehash; 205 206 #define NFSNOHASH(fhsum) \ 207 (&nfsnodehashtbl[(fhsum) & nfsnodehash]) 208 209 /* 210 * Defines for WebNFS 211 */ 212 213 #define WEBNFS_ESC_CHAR '%' 214 #define WEBNFS_SPECCHAR_START 0x80 215 216 #define WEBNFS_NATIVE_CHAR 0x80 217 /* 218 * .. 219 * Possibly more here in the future. 220 */ 221 222 /* 223 * Macro for converting escape characters in WebNFS pathnames. 224 * Should really be in libkern. 225 */ 226 227 #define HEXTOC(c) \ 228 ((c) >= 'a' ? ((c) - ('a' - 10)) : \ 229 ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0'))) 230 #define HEXSTRTOI(p) \ 231 ((HEXTOC(p[0]) << 4) + HEXTOC(p[1])) 232 233 #ifdef NFS_DEBUG 234 235 extern int nfs_debug; 236 #define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */ 237 #define NFS_DEBUG_WG 2 /* server write gathering */ 238 #define NFS_DEBUG_RC 4 /* server request caching */ 239 240 #define NFS_DPF(cat, args) \ 241 do { \ 242 if (nfs_debug & NFS_DEBUG_##cat) printf args; \ 243 } while (0) 244 245 #else 246 247 #define NFS_DPF(cat, args) 248 249 #endif 250 251 int nfs_init(struct vfsconf *vfsp); 252 int nfs_uninit(struct vfsconf *vfsp); 253 int nfs_mountroot(struct mount *mp, struct thread *td); 254 int nfs_send(struct socket *, struct sockaddr *, struct mbuf *, 255 struct nfsreq *); 256 int nfs_sndlock(struct nfsreq *); 257 void nfs_sndunlock(struct nfsreq *); 258 int nfs_vinvalbuf(struct vnode *, int, struct ucred *, struct thread *, 259 int); 260 int nfs_readrpc(struct vnode *, struct uio *, struct ucred *); 261 int nfs_writerpc(struct vnode *, struct uio *, struct ucred *, int *, 262 int *); 263 int nfs_commit(struct vnode *vp, u_quad_t offset, int cnt, 264 struct ucred *cred, struct thread *td); 265 int nfs_readdirrpc(struct vnode *, struct uio *, struct ucred *); 266 int nfs_nfsiodnew(void); 267 int nfs_asyncio(struct buf *, struct ucred *, struct thread *); 268 int nfs_doio(struct buf *, struct ucred *, struct thread *); 269 int nfs_readlinkrpc(struct vnode *, struct uio *, struct ucred *); 270 int nfs_sigintr(struct nfsmount *, struct nfsreq *, struct proc *); 271 int nfs_readdirplusrpc(struct vnode *, struct uio *, struct ucred *); 272 int nfs_request(struct vnode *, struct mbuf *, int, struct thread *, 273 struct ucred *, struct mbuf **, struct mbuf **, caddr_t *); 274 int nfs_loadattrcache(struct vnode **, struct mbuf **, caddr_t *, 275 struct vattr *, int); 276 int nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *); 277 void nfs_nhinit(void); 278 int nfs_nmcancelreqs(struct nfsmount *); 279 void nfs_timer(void*); 280 int nfs_connect(struct nfsmount *, struct nfsreq *); 281 void nfs_disconnect(struct nfsmount *); 282 void nfs_safedisconnect(struct nfsmount *); 283 int nfs_getattrcache(struct vnode *, struct vattr *); 284 int nfsm_strtmbuf(struct mbuf **, char **, const char *, long); 285 int nfs_bioread(struct vnode *, struct uio *, int, struct ucred *); 286 int nfsm_uiotombuf(struct uio *, struct mbuf **, int, caddr_t *); 287 void nfs_clearcommit(struct mount *); 288 int nfs_writebp(struct buf *, int, struct thread *); 289 int nfs_fsinfo(struct nfsmount *, struct vnode *, struct ucred *, 290 struct thread *); 291 int nfs_meta_setsize (struct vnode *, struct ucred *, 292 struct thread *, u_quad_t); 293 294 #endif /* _KERNEL */ 295 296 #endif 297