HardenedBSD src tree
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

296 lines
9.5KB

  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. #ifndef _NFSCLIENT_NFS_H_
  38. #define _NFSCLIENT_NFS_H_
  39. #ifdef _KERNEL
  40. #include "opt_nfs.h"
  41. #endif
  42. #include <nfsclient/nfsargs.h>
  43. /*
  44. * Tunable constants for nfs
  45. */
  46. #define NFS_TICKINTVL 10 /* Desired time for a tick (msec) */
  47. #define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */
  48. #define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */
  49. #define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */
  50. #define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */
  51. #define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/
  52. #define NFS_MAXREXMIT 100 /* Stop counting after this many */
  53. #define NFS_RETRANS 10 /* Num of retrans for UDP soft mounts */
  54. #define NFS_RETRANS_TCP 2 /* Num of retrans for TCP soft mounts */
  55. #define NFS_MAXGRPS 16 /* Max. size of groups list */
  56. #ifndef NFS_MINATTRTIMO
  57. #define NFS_MINATTRTIMO 3 /* VREG attrib cache timeout in sec */
  58. #endif
  59. #ifndef NFS_MAXATTRTIMO
  60. #define NFS_MAXATTRTIMO 60
  61. #endif
  62. #ifndef NFS_MINDIRATTRTIMO
  63. #define NFS_MINDIRATTRTIMO 3 /* VDIR attrib cache timeout in sec */
  64. #endif
  65. #ifndef NFS_MAXDIRATTRTIMO
  66. #define NFS_MAXDIRATTRTIMO 60
  67. #endif
  68. #ifndef NFS_ACCESSCACHESIZE
  69. #define NFS_ACCESSCACHESIZE 8 /* Per-node access cache entries */
  70. #endif
  71. #define NFS_WSIZE 8192 /* Def. write data size <= 8192 */
  72. #define NFS_RSIZE 8192 /* Def. read data size <= 8192 */
  73. #define NFS_READDIRSIZE 8192 /* Def. readdir size */
  74. #define NFS_DEFRAHEAD 1 /* Def. read ahead # blocks */
  75. #define NFS_MAXRAHEAD 4 /* Max. read ahead # blocks */
  76. #define NFS_MAXASYNCDAEMON 64 /* Max. number async_daemons runnable */
  77. #define NFS_DIRBLKSIZ 4096 /* Must be a multiple of DIRBLKSIZ */
  78. #ifdef _KERNEL
  79. #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
  80. #endif
  81. #define NFS_MAXDEADTHRESH 9 /* How long till we say 'server not responding' */
  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. #define NFS_ISV4(v) (VFSTONFS((v)->v_mount)->nm_flag & NFSMNT_NFSV4)
  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_TIMEO 0x10000000 /* Experiencing a timeout */
  94. #define NFSSTA_LOCKTIMEO 0x20000000 /* Experiencing a lockd timeout */
  95. /*
  96. * XXX to allow amd to include nfs.h without nfsproto.h
  97. */
  98. #ifdef NFS_NPROCS
  99. #include <nfsclient/nfsstats.h>
  100. #endif
  101. /*
  102. * vfs.oldnfs sysctl(3) identifiers
  103. */
  104. #define NFS_NFSSTATS 1 /* struct: struct nfsstats */
  105. #ifdef _KERNEL
  106. #ifdef MALLOC_DECLARE
  107. MALLOC_DECLARE(M_NFSDIROFF);
  108. MALLOC_DECLARE(M_NFSDIRECTIO);
  109. #endif
  110. extern struct uma_zone *nfsmount_zone;
  111. extern struct nfsstats nfsstats;
  112. extern struct mtx nfs_iod_mtx;
  113. extern struct task nfs_nfsiodnew_task;
  114. extern int nfs_numasync;
  115. extern unsigned int nfs_iodmax;
  116. extern int nfs_pbuf_freecnt;
  117. extern int nfs_ticks;
  118. /* Data constants in XDR form */
  119. extern u_int32_t nfs_true, nfs_false, nfs_xdrneg1;
  120. extern u_int32_t rpc_reply, rpc_msgdenied, rpc_mismatch, rpc_vers;
  121. extern u_int32_t rpc_auth_unix, rpc_msgaccepted, rpc_call, rpc_autherr;
  122. extern int nfsv3_procid[NFS_NPROCS];
  123. /*
  124. * Socket errors ignored for connectionless sockets??
  125. * For now, ignore them all
  126. */
  127. #define NFSIGNORE_SOERROR(s, e) \
  128. ((e) != EINTR && (e) != EIO && \
  129. (e) != ERESTART && (e) != EWOULDBLOCK && \
  130. ((s) & PR_CONNREQUIRED) == 0)
  131. struct nfsmount;
  132. struct buf;
  133. struct socket;
  134. struct uio;
  135. struct vattr;
  136. /*
  137. * Pointers to ops that differ from v3 to v4
  138. */
  139. struct nfs_rpcops {
  140. int (*nr_readrpc)(struct vnode *vp, struct uio *uiop,
  141. struct ucred *cred);
  142. int (*nr_writerpc)(struct vnode *vp, struct uio *uiop,
  143. struct ucred *cred, int *iomode, int *must_commit);
  144. int (*nr_writebp)(struct buf *bp, int force, struct thread *td);
  145. int (*nr_readlinkrpc)(struct vnode *vp, struct uio *uiop,
  146. struct ucred *cred);
  147. void (*nr_invaldir)(struct vnode *vp);
  148. int (*nr_commit)(struct vnode *vp, u_quad_t offset, int cnt,
  149. struct ucred *cred, struct thread *td);
  150. };
  151. /*
  152. * Defines for WebNFS
  153. */
  154. #define WEBNFS_ESC_CHAR '%'
  155. #define WEBNFS_SPECCHAR_START 0x80
  156. #define WEBNFS_NATIVE_CHAR 0x80
  157. /*
  158. * ..
  159. * Possibly more here in the future.
  160. */
  161. /*
  162. * Macro for converting escape characters in WebNFS pathnames.
  163. * Should really be in libkern.
  164. */
  165. #define HEXTOC(c) \
  166. ((c) >= 'a' ? ((c) - ('a' - 10)) : \
  167. ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
  168. #define HEXSTRTOI(p) \
  169. ((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
  170. /* nfs_sigintr() helper, when 'rep' has all we need */
  171. #define NFS_SIGREP(rep) nfs_sigintr((rep)->r_nmp, (rep), (rep)->r_td)
  172. #ifdef NFS_DEBUG
  173. extern int nfs_debug;
  174. #define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */
  175. #define NFS_DEBUG_WG 2 /* server write gathering */
  176. #define NFS_DEBUG_RC 4 /* server request caching */
  177. #define NFS_DPF(cat, args) \
  178. do { \
  179. if (nfs_debug & NFS_DEBUG_##cat) printf args; \
  180. } while (0)
  181. #else
  182. #define NFS_DPF(cat, args)
  183. #endif
  184. /*
  185. * On fast networks, the estimator will try to reduce the
  186. * timeout lower than the latency of the server's disks,
  187. * which results in too many timeouts, so cap the lower
  188. * bound.
  189. */
  190. #define NFS_MINRTO (NFS_HZ >> 2)
  191. /*
  192. * Keep the RTO from increasing to unreasonably large values
  193. * when a server is not responding.
  194. */
  195. #define NFS_MAXRTO (20 * NFS_HZ)
  196. enum nfs_rto_timer_t {
  197. NFS_DEFAULT_TIMER,
  198. NFS_GETATTR_TIMER,
  199. NFS_LOOKUP_TIMER,
  200. NFS_READ_TIMER,
  201. NFS_WRITE_TIMER,
  202. };
  203. #define NFS_MAX_TIMER (NFS_WRITE_TIMER)
  204. #define NFS_INITRTT (NFS_HZ << 3)
  205. vfs_init_t nfs_init;
  206. vfs_uninit_t nfs_uninit;
  207. int nfs_mountroot(struct mount *mp);
  208. void nfs_purgecache(struct vnode *);
  209. int nfs_vinvalbuf(struct vnode *, int, struct thread *, int);
  210. int nfs_readrpc(struct vnode *, struct uio *, struct ucred *);
  211. int nfs_writerpc(struct vnode *, struct uio *, struct ucred *, int *,
  212. int *);
  213. int nfs_commit(struct vnode *vp, u_quad_t offset, int cnt,
  214. struct ucred *cred, struct thread *td);
  215. int nfs_readdirrpc(struct vnode *, struct uio *, struct ucred *);
  216. void nfs_nfsiodnew(void);
  217. void nfs_nfsiodnew_tq(__unused void *, int);
  218. int nfs_asyncio(struct nfsmount *, struct buf *, struct ucred *, struct thread *);
  219. int nfs_doio(struct vnode *, struct buf *, struct ucred *, struct thread *);
  220. void nfs_doio_directwrite (struct buf *);
  221. int nfs_readlinkrpc(struct vnode *, struct uio *, struct ucred *);
  222. int nfs_sigintr(struct nfsmount *, struct thread *);
  223. int nfs_readdirplusrpc(struct vnode *, struct uio *, struct ucred *);
  224. int nfs_request(struct vnode *, struct mbuf *, int, struct thread *,
  225. struct ucred *, struct mbuf **, struct mbuf **, caddr_t *);
  226. int nfs_loadattrcache(struct vnode **, struct mbuf **, caddr_t *,
  227. struct vattr *, int);
  228. int nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *);
  229. void nfs_nhinit(void);
  230. void nfs_nhuninit(void);
  231. int nfs_nmcancelreqs(struct nfsmount *);
  232. void nfs_timer(void*);
  233. int nfs_connect(struct nfsmount *);
  234. void nfs_disconnect(struct nfsmount *);
  235. void nfs_safedisconnect(struct nfsmount *);
  236. int nfs_getattrcache(struct vnode *, struct vattr *);
  237. int nfs_iosize(struct nfsmount *nmp);
  238. int nfsm_strtmbuf(struct mbuf **, char **, const char *, long);
  239. int nfs_bioread(struct vnode *, struct uio *, int, struct ucred *);
  240. int nfsm_uiotombuf(struct uio *, struct mbuf **, int, caddr_t *);
  241. void nfs_clearcommit(struct mount *);
  242. int nfs_writebp(struct buf *, int, struct thread *);
  243. int nfs_fsinfo(struct nfsmount *, struct vnode *, struct ucred *,
  244. struct thread *);
  245. int nfs_meta_setsize (struct vnode *, struct ucred *,
  246. struct thread *, u_quad_t);
  247. void nfs_set_sigmask(struct thread *td, sigset_t *oldset);
  248. void nfs_restore_sigmask(struct thread *td, sigset_t *set);
  249. int nfs_msleep(struct thread *td, void *ident, struct mtx *mtx,
  250. int priority, char *wmesg, int timo);
  251. #endif /* _KERNEL */
  252. #endif