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 10 /* 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 /* 117 * File context information for nfsv4. Currently, there is only one 118 * lockowner for the whole machine "0." 119 */ 120 struct nfs4_fctx { 121 TAILQ_ENTRY(nfs4_fstate) next; 122 uint32_t refcnt; 123 struct nfs4_lowner *lop; 124 struct nfsnode *np; 125 char stateid[NFSX_V4STATEID]; 126 }; 127 128 #ifdef _KERNEL 129 130 #ifdef MALLOC_DECLARE 131 MALLOC_DECLARE(M_NFSREQ); 132 MALLOC_DECLARE(M_NFSDIROFF); 133 MALLOC_DECLARE(M_NFSBIGFH); 134 MALLOC_DECLARE(M_NFSHASH); 135 #endif 136 137 extern struct uma_zone *nfsmount_zone; 138 139 extern struct callout nfs_callout; 140 extern struct nfsstats nfsstats; 141 142 extern int nfs_numasync; 143 extern int nfs_pbuf_freecnt; 144 extern int nfs_ticks; 145 146 /* Data constants in XDR form */ 147 extern u_int32_t nfs_true, nfs_false, nfs_xdrneg1; 148 extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers; 149 extern u_int32_t rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr; 150 151 extern int nfsv3_procid[NFS_NPROCS]; 152 153 struct uio; 154 struct buf; 155 struct vattr; 156 struct nameidata; 157 158 /* 159 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts. 160 * What should be in this set is open to debate, but I believe that since 161 * I/O system calls on ufs are never interrupted by signals the set should 162 * be minimal. My reasoning is that many current programs that use signals 163 * such as SIGALRM will not expect file I/O system calls to be interrupted 164 * by them and break. 165 */ 166 #define NFSINT_SIGMASK(set) \ 167 (SIGISMEMBER(set, SIGINT) || SIGISMEMBER(set, SIGTERM) || \ 168 SIGISMEMBER(set, SIGHUP) || SIGISMEMBER(set, SIGKILL) || \ 169 SIGISMEMBER(set, SIGQUIT)) 170 171 /* 172 * Socket errors ignored for connectionless sockets?? 173 * For now, ignore them all 174 */ 175 #define NFSIGNORE_SOERROR(s, e) \ 176 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \ 177 ((s) & PR_CONNREQUIRED) == 0) 178 179 /* 180 * Nfs outstanding request list element 181 */ 182 struct nfsreq { 183 TAILQ_ENTRY(nfsreq) r_chain; 184 struct mbuf *r_mreq; 185 struct mbuf *r_mrep; 186 struct mbuf *r_md; 187 caddr_t r_dpos; 188 struct nfsmount *r_nmp; 189 struct vnode *r_vp; 190 u_int32_t r_xid; 191 int r_flags; /* flags on request, see below */ 192 int r_retry; /* max retransmission count */ 193 int r_rexmit; /* current retrans count */ 194 int r_timer; /* tick counter on reply */ 195 u_int32_t r_procnum; /* NFS procedure number */ 196 int r_rtt; /* RTT for rpc */ 197 struct thread *r_td; /* Proc that did I/O system call */ 198 }; 199 200 /* 201 * Queue head for nfsreq's 202 */ 203 extern TAILQ_HEAD(nfs_reqq, nfsreq) nfs_reqq; 204 205 /* Flag values for r_flags */ 206 #define R_TIMING 0x01 /* timing request (in mntp) */ 207 #define R_SENT 0x02 /* request has been sent */ 208 #define R_SOFTTERM 0x04 /* soft mnt, too many retries */ 209 #define R_INTR 0x08 /* intr mnt, signal pending */ 210 #define R_SOCKERR 0x10 /* Fatal error on socket */ 211 #define R_TPRINTFMSG 0x20 /* Did a tprintf msg. */ 212 #define R_MUSTRESEND 0x40 /* Must resend request */ 213 #define R_GETONEREP 0x80 /* Probe for one reply only */ 214 215 /* 216 * Pointers to ops that differ from v3 to v4 217 */ 218 struct nfs_rpcops { 219 int (*nr_readrpc)(struct vnode *vp, struct uio *uiop, struct ucred *cred); 220 int (*nr_writerpc)(struct vnode *vp, struct uio *uiop, struct ucred *cred, 221 int *iomode, int *must_commit); 222 int (*nr_writebp)(struct buf *bp, int force, struct thread *td); 223 int (*nr_readlinkrpc)(struct vnode *vp, struct uio *uiop, struct ucred *cred); 224 void (*nr_invaldir)(struct vnode *vp); 225 int (*nr_commit)(struct vnode *vp, u_quad_t offset, int cnt, 226 struct ucred *cred, struct thread *td); 227 }; 228 229 /* 230 * Defines for WebNFS 231 */ 232 233 #define WEBNFS_ESC_CHAR '%' 234 #define WEBNFS_SPECCHAR_START 0x80 235 236 #define WEBNFS_NATIVE_CHAR 0x80 237 /* 238 * .. 239 * Possibly more here in the future. 240 */ 241 242 /* 243 * Macro for converting escape characters in WebNFS pathnames. 244 * Should really be in libkern. 245 */ 246 247 #define HEXTOC(c) \ 248 ((c) >= 'a' ? ((c) - ('a' - 10)) : \ 249 ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0'))) 250 #define HEXSTRTOI(p) \ 251 ((HEXTOC(p[0]) << 4) + HEXTOC(p[1])) 252 253 #ifdef NFS_DEBUG 254 255 extern int nfs_debug; 256 #define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */ 257 #define NFS_DEBUG_WG 2 /* server write gathering */ 258 #define NFS_DEBUG_RC 4 /* server request caching */ 259 260 #define NFS_DPF(cat, args) \ 261 do { \ 262 if (nfs_debug & NFS_DEBUG_##cat) printf args; \ 263 } while (0) 264 265 #else 266 267 #define NFS_DPF(cat, args) 268 269 #endif 270 271 vfs_init_t nfs_init; 272 vfs_uninit_t nfs_uninit; 273 int nfs_mountroot(struct mount *mp, struct thread *td); 274 275 #ifndef NFS4_USE_RPCCLNT 276 int nfs_send(struct socket *, struct sockaddr *, struct mbuf *, 277 struct nfsreq *); 278 int nfs_sndlock(struct nfsreq *); 279 void nfs_sndunlock(struct nfsreq *); 280 #endif /* ! NFS4_USE_RPCCLNT */ 281 282 int nfs_vinvalbuf(struct vnode *, int, struct ucred *, struct thread *, 283 int); 284 int nfs_readrpc(struct vnode *, struct uio *, struct ucred *); 285 int nfs_writerpc(struct vnode *, struct uio *, struct ucred *, int *, 286 int *); 287 int nfs_commit(struct vnode *vp, u_quad_t offset, int cnt, 288 struct ucred *cred, struct thread *td); 289 int nfs_readdirrpc(struct vnode *, struct uio *, struct ucred *); 290 int nfs_nfsiodnew(void); 291 int nfs_asyncio(struct buf *, struct ucred *, struct thread *); 292 int nfs_doio(struct buf *, struct ucred *, struct thread *); 293 int nfs_readlinkrpc(struct vnode *, struct uio *, struct ucred *); 294 int nfs_sigintr(struct nfsmount *, struct nfsreq *, struct thread *); 295 int nfs_readdirplusrpc(struct vnode *, struct uio *, struct ucred *); 296 int nfs_request(struct vnode *, struct mbuf *, int, struct thread *, 297 struct ucred *, struct mbuf **, struct mbuf **, caddr_t *); 298 int nfs_loadattrcache(struct vnode **, struct mbuf **, caddr_t *, 299 struct vattr *, int); 300 int nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *); 301 void nfs_nhinit(void); 302 int nfs_nmcancelreqs(struct nfsmount *); 303 void nfs_timer(void*); 304 305 int nfs_connect(struct nfsmount *, struct nfsreq *); 306 void nfs_disconnect(struct nfsmount *); 307 void nfs_safedisconnect(struct nfsmount *); 308 int nfs_getattrcache(struct vnode *, struct vattr *); 309 int nfsm_strtmbuf(struct mbuf **, char **, const char *, long); 310 int nfs_bioread(struct vnode *, struct uio *, int, struct ucred *); 311 int nfsm_uiotombuf(struct uio *, struct mbuf **, int, caddr_t *); 312 void nfs_clearcommit(struct mount *); 313 int nfs_writebp(struct buf *, int, struct thread *); 314 int nfs_fsinfo(struct nfsmount *, struct vnode *, struct ucred *, 315 struct thread *); 316 int nfs_meta_setsize (struct vnode *, struct ucred *, 317 struct thread *, u_quad_t); 318 319 #endif /* _KERNEL */ 320 321 #endif 322