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