xref: /freebsd/sys/nfsserver/nfs.h (revision 830940567b49bb0c08dfaed40418999e76616909)
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 _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  */
98 struct 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  */
107 struct 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 
128 extern 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
136 MALLOC_DECLARE(M_NFSRVDESC);
137 MALLOC_DECLARE(M_NFSD);
138 #endif
139 
140 /* Forward declarations */
141 struct nfssvc_sock;
142 struct nfsrv_descript;
143 struct uio;
144 struct vattr;
145 struct nameidata;
146 
147 extern struct callout nfsrv_callout;
148 extern struct nfsrvstats nfsrvstats;
149 
150 extern int	nfsrv_ticks;
151 extern int	nfsrvw_procrastinate;
152 extern int	nfsrvw_procrastinate_v3;
153 extern int 	nfsrv_numnfsd;
154 
155 /* Various values converted to XDR form. */
156 extern u_int32_t nfsrv_nfs_false, nfsrv_nfs_true, nfsrv_nfs_xdrneg1,
157 	nfsrv_nfs_prog;
158 extern u_int32_t nfsrv_rpc_reply, nfsrv_rpc_msgdenied, nfsrv_rpc_mismatch,
159 	nfsrv_rpc_vers;
160 extern u_int32_t nfsrv_rpc_auth_unix, nfsrv_rpc_msgaccepted, nfsrv_rpc_call,
161 	nfsrv_rpc_autherr;
162 
163 /* Procedure table data */
164 extern const int	nfsrvv2_procid[NFS_NPROCS];
165 extern const int	nfsrv_nfsv3_procid[NFS_NPROCS];
166 extern 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  */
182 struct 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 
227 extern 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 
243 struct mbuf *nfs_rephead(int, struct nfsrv_descript *, int, struct mbuf **,
244 	    caddr_t *);
245 void	nfsm_srvfattr(struct nfsrv_descript *, struct vattr *,
246 	    struct nfs_fattr *);
247 void	nfsm_srvwcc(struct nfsrv_descript *, int, struct vattr *, int,
248 	    struct vattr *, struct mbuf **, char **);
249 void	nfsm_srvpostopattr(struct nfsrv_descript *, int, struct vattr *,
250 	    struct mbuf **, char **);
251 int	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);
254 void	nfsm_adj(struct mbuf *, int, int);
255 int	nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *);
256 void	nfsrv_init(int);
257 int	nfsrv_errmap(struct nfsrv_descript *, int);
258 void	nfsrvw_sort(gid_t *, int);
259 
260 int	nfsrv3_access(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
261 	    struct mbuf **mrq);
262 int	nfsrv_commit(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
263 	    struct mbuf **mrq);
264 int	nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
265 	    struct mbuf **mrq);
266 int	nfsrv_fhtovp(fhandle_t *, int, struct vnode **, int *,
267 	    struct nfsrv_descript *, struct nfssvc_sock *, struct sockaddr *,
268 	    int *, int);
269 int	nfsrv_setpublicfs(struct mount *, struct netexport *,
270 	    struct export_args *);
271 int	nfs_ispublicfh(fhandle_t *);
272 int	nfsrv_fsinfo(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
273 	    struct mbuf **mrq);
274 int	nfsrv_getattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
275 	    struct mbuf **mrq);
276 int	nfsrv_link(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
277 	    struct mbuf **mrq);
278 int	nfsrv_lookup(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
279 	    struct mbuf **mrq);
280 int	nfsrv_mkdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
281 	    struct mbuf **mrq);
282 int	nfsrv_mknod(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
283 	    struct mbuf **mrq);
284 int	nfsrv_noop(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
285 	    struct mbuf **mrq);
286 int	nfsrv_null(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
287 	    struct mbuf **mrq);
288 int	nfsrv_pathconf(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
289 	    struct mbuf **mrq);
290 int	nfsrv_read(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
291 	    struct mbuf **mrq);
292 int	nfsrv_readdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
293 	    struct mbuf **mrq);
294 int	nfsrv_readdirplus(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
295 	    struct mbuf **mrq);
296 int	nfsrv_readlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
297 	    struct mbuf **mrq);
298 int	nfsrv_remove(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
299 	    struct mbuf **mrq);
300 int	nfsrv_rename(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
301 	    struct mbuf **mrq);
302 int	nfsrv_rmdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
303 	    struct mbuf **mrq);
304 int	nfsrv_setattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
305 	    struct mbuf **mrq);
306 int	nfsrv_statfs(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
307 	    struct mbuf **mrq);
308 int	nfsrv_symlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
309 	    struct mbuf **mrq);
310 int	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_
317 int nfssvc_nfsserver(struct thread *, struct nfssvc_args *);
318 #endif
319 #endif	/* _KERNEL */
320 
321 #endif
322