nfs.h revision 195202
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: head/sys/nfsserver/nfs.h 195202 2009-06-30 19:03:27Z dfr $ 34 */ 35 36#ifndef _NFSSERVER_NFS_H_ 37#define _NFSSERVER_NFS_H_ 38 39#ifdef _KERNEL 40#include "opt_nfs.h" 41#endif 42 43#include <nfs/nfssvc.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_MAXUIDHASH 64 /* Max. # of hashed uid entries/mp */ 56#ifndef NFS_GATHERDELAY 57#define NFS_GATHERDELAY 10 /* Default write gather delay (msec) */ 58#endif 59#ifdef _KERNEL 60#define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */ 61#endif 62 63/* 64 * Oddballs 65 */ 66#define NFS_SRVMAXDATA(n) \ 67 (((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \ 68 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA) 69 70/* 71 * XXX 72 * The B_INVAFTERWRITE flag should be set to whatever is required by the 73 * buffer cache code to say "Invalidate the block after it is written back". 74 */ 75#define B_INVAFTERWRITE B_NOCACHE 76 77/* 78 * The IO_METASYNC flag should be implemented for local filesystems. 79 * (Until then, it is nothin at all.) 80 */ 81#ifndef IO_METASYNC 82#define IO_METASYNC 0 83#endif 84 85 86/* NFS state flags XXX -Wunused */ 87#define NFSRV_SNDLOCK 0x01000000 /* Send socket lock */ 88#define NFSRV_WANTSND 0x02000000 /* Want above */ 89 90/* 91 * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs 92 * should ever try and use it. 93 */ 94 95/* 96 * Add a socket to monitor for NFS requests. 97 */ 98struct nfsd_addsock_args { 99 int sock; /* Socket to serve */ 100 caddr_t name; /* Client addr for connection based sockets */ 101 int namelen; /* Length of name */ 102}; 103 104/* 105 * Start processing requests. 106 */ 107struct nfsd_nfsd_args { 108 const char *principal; /* GSS-API service principal name */ 109 int minthreads; /* minimum service thread count */ 110 int maxthreads; /* maximum service thread count */ 111}; 112 113/* 114 * XXX to allow amd to include nfs.h without nfsproto.h 115 */ 116#ifdef NFS_NPROCS 117#include <nfsserver/nfsrvstats.h> 118#endif 119 120/* 121 * vfs.nfsrv sysctl(3) identifiers 122 */ 123#define NFS_NFSRVSTATS 1 /* struct: struct nfsrvstats */ 124#define NFS_NFSPRIVPORT 2 /* int: prohibit nfs to resvports */ 125 126#ifdef _KERNEL 127 128extern struct mtx nfsd_mtx; 129#define NFSD_LOCK_ASSERT() mtx_assert(&nfsd_mtx, MA_OWNED) 130#define NFSD_UNLOCK_ASSERT() mtx_assert(&nfsd_mtx, MA_NOTOWNED) 131#define NFSD_LOCK_DONTCARE() 132#define NFSD_LOCK() mtx_lock(&nfsd_mtx) 133#define NFSD_UNLOCK() mtx_unlock(&nfsd_mtx) 134 135#ifdef MALLOC_DECLARE 136MALLOC_DECLARE(M_NFSRVDESC); 137MALLOC_DECLARE(M_NFSD); 138#endif 139 140/* Forward declarations */ 141struct nfssvc_sock; 142struct nfsrv_descript; 143struct uio; 144struct vattr; 145struct nameidata; 146 147extern struct callout nfsrv_callout; 148extern struct nfsrvstats nfsrvstats; 149 150extern int nfsrv_ticks; 151extern int nfsrvw_procrastinate; 152extern int nfsrvw_procrastinate_v3; 153extern int nfsrv_numnfsd; 154 155/* Various values converted to XDR form. */ 156extern u_int32_t nfsrv_nfs_false, nfsrv_nfs_true, nfsrv_nfs_xdrneg1, 157 nfsrv_nfs_prog; 158extern u_int32_t nfsrv_rpc_reply, nfsrv_rpc_msgdenied, nfsrv_rpc_mismatch, 159 nfsrv_rpc_vers; 160extern u_int32_t nfsrv_rpc_auth_unix, nfsrv_rpc_msgaccepted, nfsrv_rpc_call, 161 nfsrv_rpc_autherr; 162 163/* Procedure table data */ 164extern const int nfsrvv2_procid[NFS_NPROCS]; 165extern const int nfsrv_nfsv3_procid[NFS_NPROCS]; 166extern int32_t (*nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *nd, 167 struct nfssvc_sock *slp, struct mbuf **mreqp); 168 169/* 170 * A list of nfssvc_sock structures is maintained with all the sockets 171 * that require service by the nfsd. 172 */ 173#ifndef NFS_WDELAYHASHSIZ 174#define NFS_WDELAYHASHSIZ 16 /* and with this */ 175#endif 176#define NWDELAYHASH(sock, f) \ 177 (&(sock)->ns_wdelayhashtbl[(*((u_int32_t *)(f))) % NFS_WDELAYHASHSIZ]) 178 179/* 180 * This structure is used by the server for describing each request. 181 */ 182struct nfsrv_descript { 183 struct mbuf *nd_mrep; /* Request mbuf list */ 184 struct mbuf *nd_md; /* Current dissect mbuf */ 185 struct mbuf *nd_mreq; /* Reply mbuf list */ 186 struct sockaddr *nd_nam; /* and socket addr */ 187 struct sockaddr *nd_nam2; /* return socket addr */ 188 caddr_t nd_dpos; /* Current dissect pos */ 189 u_int32_t nd_procnum; /* RPC # */ 190 int nd_stable; /* storage type */ 191 int nd_flag; /* nd_flag */ 192 int nd_repstat; /* Reply status */ 193 fhandle_t nd_fh; /* File handle */ 194 struct ucred *nd_cr; /* Credentials */ 195 int nd_credflavor; /* Security flavor */ 196}; 197 198/* Bits for "nd_flag" */ 199#define ND_NFSV3 0x08 200 201/* 202 * Defines for WebNFS 203 */ 204 205#define WEBNFS_ESC_CHAR '%' 206#define WEBNFS_SPECCHAR_START 0x80 207 208#define WEBNFS_NATIVE_CHAR 0x80 209/* 210 * .. 211 * Possibly more here in the future. 212 */ 213 214/* 215 * Macro for converting escape characters in WebNFS pathnames. 216 * Should really be in libkern. 217 */ 218 219#define HEXTOC(c) \ 220 ((c) >= 'a' ? ((c) - ('a' - 10)) : \ 221 ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0'))) 222#define HEXSTRTOI(p) \ 223 ((HEXTOC(p[0]) << 4) + HEXTOC(p[1])) 224 225#ifdef NFS_DEBUG 226 227extern int nfs_debug; 228#define NFS_DEBUG_ASYNCIO 1 /* asynchronous i/o */ 229#define NFS_DEBUG_WG 2 /* server write gathering */ 230#define NFS_DEBUG_RC 4 /* server request caching */ 231 232#define NFS_DPF(cat, args) \ 233 do { \ 234 if (nfs_debug & NFS_DEBUG_##cat) printf args; \ 235 } while (0) 236 237#else 238 239#define NFS_DPF(cat, args) 240 241#endif 242 243struct mbuf *nfs_rephead(int, struct nfsrv_descript *, int, struct mbuf **, 244 caddr_t *); 245void nfsm_srvfattr(struct nfsrv_descript *, struct vattr *, 246 struct nfs_fattr *); 247void nfsm_srvwcc(struct nfsrv_descript *, int, struct vattr *, int, 248 struct vattr *, struct mbuf **, char **); 249void nfsm_srvpostopattr(struct nfsrv_descript *, int, struct vattr *, 250 struct mbuf **, char **); 251int nfs_namei(struct nameidata *, struct nfsrv_descript *, fhandle_t *, 252 int, struct nfssvc_sock *, struct sockaddr *, struct mbuf **, 253 caddr_t *, struct vnode **, int, struct vattr *, int *, int); 254void nfsm_adj(struct mbuf *, int, int); 255int nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *); 256void nfsrv_init(int); 257int nfsrv_errmap(struct nfsrv_descript *, int); 258void nfsrvw_sort(gid_t *, int); 259 260int nfsrv3_access(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 261 struct mbuf **mrq); 262int nfsrv_commit(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 263 struct mbuf **mrq); 264int nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 265 struct mbuf **mrq); 266int nfsrv_fhtovp(fhandle_t *, int, struct vnode **, int *, 267 struct nfsrv_descript *, struct nfssvc_sock *, struct sockaddr *, 268 int *, int); 269int nfsrv_setpublicfs(struct mount *, struct netexport *, 270 struct export_args *); 271int nfs_ispublicfh(fhandle_t *); 272int nfsrv_fsinfo(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 273 struct mbuf **mrq); 274int nfsrv_getattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 275 struct mbuf **mrq); 276int nfsrv_link(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 277 struct mbuf **mrq); 278int nfsrv_lookup(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 279 struct mbuf **mrq); 280int nfsrv_mkdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 281 struct mbuf **mrq); 282int nfsrv_mknod(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 283 struct mbuf **mrq); 284int nfsrv_noop(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 285 struct mbuf **mrq); 286int nfsrv_null(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 287 struct mbuf **mrq); 288int nfsrv_pathconf(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 289 struct mbuf **mrq); 290int nfsrv_read(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 291 struct mbuf **mrq); 292int nfsrv_readdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 293 struct mbuf **mrq); 294int nfsrv_readdirplus(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 295 struct mbuf **mrq); 296int nfsrv_readlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 297 struct mbuf **mrq); 298int nfsrv_remove(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 299 struct mbuf **mrq); 300int nfsrv_rename(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 301 struct mbuf **mrq); 302int nfsrv_rmdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 303 struct mbuf **mrq); 304int nfsrv_setattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 305 struct mbuf **mrq); 306int nfsrv_statfs(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 307 struct mbuf **mrq); 308int nfsrv_symlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 309 struct mbuf **mrq); 310int nfsrv_write(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, 311 struct mbuf **mrq); 312/* 313 * #ifdef _SYS_SYSPROTO_H_ so that it is only defined when sysproto.h 314 * has been included, so that "struct nfssvc_args" is defined. 315 */ 316#ifdef _SYS_SYSPROTO_H_ 317int nfssvc_nfsserver(struct thread *, struct nfssvc_args *); 318#endif 319#endif /* _KERNEL */ 320 321#endif 322