]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/nfsserver/nfs.h
This commit was generated by cvs2svn to compensate for changes in r128671,
[FreeBSD/FreeBSD.git] / sys / nfsserver / nfs.h
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 /*
44  * Tunable constants for nfs
45  */
46
47 #define NFS_TICKINTVL   10              /* Desired time for a tick (msec) */
48 #define NFS_HZ          (hz / nfs_ticks) /* Ticks/sec */
49 #define NFS_TIMEO       (1 * NFS_HZ)    /* Default timeout = 1 second */
50 #define NFS_MINTIMEO    (1 * NFS_HZ)    /* Min timeout to use */
51 #define NFS_MAXTIMEO    (60 * NFS_HZ)   /* Max timeout to backoff to */
52 #define NFS_MINIDEMTIMEO (5 * NFS_HZ)   /* Min timeout for non-idempotent ops*/
53 #define NFS_MAXUIDHASH  64              /* Max. # of hashed uid entries/mp */
54 #ifndef NFS_GATHERDELAY
55 #define NFS_GATHERDELAY         10      /* Default write gather delay (msec) */
56 #endif
57 #ifdef _KERNEL
58 #define DIRBLKSIZ       512             /* XXX we used to use ufs's DIRBLKSIZ */
59 #endif
60
61 /*
62  * Oddballs
63  */
64 #define NFS_SRVMAXDATA(n) \
65                 (((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
66                  NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
67
68 /*
69  * XXX
70  * The B_INVAFTERWRITE flag should be set to whatever is required by the
71  * buffer cache code to say "Invalidate the block after it is written back".
72  */
73 #define B_INVAFTERWRITE B_NOCACHE
74
75 /*
76  * The IO_METASYNC flag should be implemented for local filesystems.
77  * (Until then, it is nothin at all.)
78  */
79 #ifndef IO_METASYNC
80 #define IO_METASYNC     0
81 #endif
82
83
84 /* NFS state flags XXX -Wunused */
85 #define NFSRV_SNDLOCK           0x01000000  /* Send socket lock */
86 #define NFSRV_WANTSND           0x02000000  /* Want above */
87
88 /*
89  * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
90  * should ever try and use it.
91  */
92 struct nfsd_args {
93         int     sock;           /* Socket to serve */
94         caddr_t name;           /* Client addr for connection based sockets */
95         int     namelen;        /* Length of name */
96 };
97
98 /*
99  * XXX to allow amd to include nfs.h without nfsproto.h
100  */
101 #ifdef NFS_NPROCS
102 #include <nfsserver/nfsrvstats.h>
103 #endif
104
105 /*
106  * Flags for nfssvc() system call.
107  */
108 #define NFSSVC_NFSD     0x004
109 #define NFSSVC_ADDSOCK  0x008
110
111 /*
112  * vfs.nfsrv sysctl(3) identifiers
113  */
114 #define NFS_NFSRVSTATS  1               /* struct: struct nfsrvstats */
115 #define NFS_NFSPRIVPORT 2               /* int: prohibit nfs to resvports */
116
117 #ifdef _KERNEL
118
119 #ifdef MALLOC_DECLARE
120 MALLOC_DECLARE(M_NFSRVDESC);
121 MALLOC_DECLARE(M_NFSD);
122 #endif
123
124 /* Forward declarations */
125 struct nfssvc_sock;
126 struct nfsrv_descript;
127 struct uio;
128 struct vattr;
129 struct nameidata;
130
131 extern struct callout nfsrv_callout;
132 extern struct nfsrvstats nfsrvstats;
133
134 extern int      nfsrv_ticks;
135 extern int      nfsrvw_procrastinate;
136 extern int      nfsrvw_procrastinate_v3;
137 extern int      nfsrv_numnfsd;
138
139 /* Various values converted to XDR form. */
140 extern u_int32_t nfsrv_nfs_false, nfsrv_nfs_true, nfsrv_nfs_xdrneg1,
141         nfsrv_nfs_prog;
142 extern u_int32_t nfsrv_rpc_reply, nfsrv_rpc_msgdenied, nfsrv_rpc_mismatch,
143         nfsrv_rpc_vers;
144 extern u_int32_t nfsrv_rpc_auth_unix, nfsrv_rpc_msgaccepted, nfsrv_rpc_call,
145         nfsrv_rpc_autherr;
146
147 /* Procedure table data */
148 extern int      nfsrvv2_procid[NFS_NPROCS];
149 extern int      nfsrv_nfsv3_procid[NFS_NPROCS];
150 extern int32_t (*nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *nd,
151                     struct nfssvc_sock *slp, struct thread *td,
152                     struct mbuf **mreqp);
153
154 /*
155  * A list of nfssvc_sock structures is maintained with all the sockets
156  * that require service by the nfsd.
157  */
158 #ifndef NFS_WDELAYHASHSIZ
159 #define NFS_WDELAYHASHSIZ 16    /* and with this */
160 #endif
161 #define NWDELAYHASH(sock, f) \
162         (&(sock)->ns_wdelayhashtbl[(*((u_int32_t *)(f))) % NFS_WDELAYHASHSIZ])
163
164 /*
165  * Network address hash list element
166  */
167 union nethostaddr {
168         u_int32_t had_inetaddr;
169         struct sockaddr *had_nam;
170 };
171
172 struct nfsrv_rec {
173         STAILQ_ENTRY(nfsrv_rec) nr_link;
174         struct sockaddr *nr_address;
175         struct mbuf     *nr_packet;
176 };
177
178 struct nfssvc_sock {
179         TAILQ_ENTRY(nfssvc_sock) ns_chain;      /* List of all nfssvc_sock's */
180         struct file     *ns_fp;
181         struct socket   *ns_so;
182         struct sockaddr *ns_nam;
183         struct mbuf     *ns_raw;
184         struct mbuf     *ns_rawend;
185         STAILQ_HEAD(, nfsrv_rec) ns_rec;
186         struct mbuf     *ns_frag;
187         int             ns_flag;
188         int             ns_solock;
189         int             ns_cc;
190         int             ns_reclen;
191         u_int32_t       ns_sref;
192         LIST_HEAD(, nfsrv_descript) ns_tq;      /* Write gather lists */
193         LIST_HEAD(nfsrvw_delayhash, nfsrv_descript) ns_wdelayhashtbl[NFS_WDELAYHASHSIZ];
194 };
195
196 /* Bits for "ns_flag" */
197 #define SLP_VALID       0x01            /* Socket valid for use (XXX) */
198 #define SLP_DOREC       0x02            /* Socket ready for processing */
199 #define SLP_NEEDQ       0x04            /* Socket has request queued */
200 #define SLP_DISCONN     0x08            /* Error received from stream socket */
201 #define SLP_GETSTREAM   0x10            /* nfsrv_getstream in prog on sock */
202 #define SLP_LASTFRAG    0x20            /* Socket received end-of-record */
203 #define SLP_ALLFLAGS    0xff
204
205 extern TAILQ_HEAD(nfssvc_sockhead, nfssvc_sock) nfssvc_sockhead;
206 extern int nfssvc_sockhead_flag;
207 #define SLP_INIT        0x01
208 #define SLP_WANTINIT    0x02
209
210 /*
211  * One of these structures is allocated for each nfsd.
212  */
213 struct nfsd {
214         TAILQ_ENTRY(nfsd) nfsd_chain;   /* List of all nfsd's */
215         int             nfsd_flag;      /* NFSD_ flags */
216         struct nfssvc_sock *nfsd_slp;   /* Current socket */
217         int             nfsd_authlen;   /* Authenticator len */
218         u_char          nfsd_authstr[RPCAUTH_MAXSIZ]; /* Authenticator data */
219         int             nfsd_verflen;   /* and the Verifier */
220         u_char          nfsd_verfstr[RPCVERF_MAXSIZ];
221         struct thread   *nfsd_td;       /* daemon thread ptr */
222         struct nfsrv_descript *nfsd_nd; /* Associated nfsrv_descript */
223 };
224
225 /* Bits for "nfsd_flag" */
226 #define NFSD_WAITING    0x01
227 #define NFSD_REQINPROG  0x02
228
229 /*
230  * This structure is used by the server for describing each request.
231  * Some fields are used only when write request gathering is performed.
232  */
233 struct nfsrv_descript {
234         u_quad_t                nd_time;        /* Write deadline (usec) */
235         off_t                   nd_off;         /* Start byte offset */
236         off_t                   nd_eoff;        /* and end byte offset */
237         LIST_ENTRY(nfsrv_descript) nd_hash;     /* Hash list */
238         LIST_ENTRY(nfsrv_descript) nd_tq;       /* and timer list */
239         LIST_HEAD(, nfsrv_descript) nd_coalesce;/* coalesced writes */
240         struct mbuf             *nd_mrep;       /* Request mbuf list */
241         struct mbuf             *nd_md;         /* Current dissect mbuf */
242         struct mbuf             *nd_mreq;       /* Reply mbuf list */
243         struct sockaddr         *nd_nam;        /* and socket addr */
244         struct sockaddr         *nd_nam2;       /* return socket addr */
245         caddr_t                 nd_dpos;        /* Current dissect pos */
246         u_int32_t               nd_procnum;     /* RPC # */
247         int                     nd_stable;      /* storage type */
248         int                     nd_flag;        /* nd_flag */
249         int                     nd_len;         /* Length of this write */
250         int                     nd_repstat;     /* Reply status */
251         u_int32_t               nd_retxid;      /* Reply xid */
252         struct timeval          nd_starttime;   /* Time RPC initiated */
253         fhandle_t               nd_fh;          /* File handle */
254         struct ucred            nd_cr;          /* Credentials */
255 };
256
257 /* Bits for "nd_flag" */
258 #define ND_NFSV3        0x08
259
260 extern TAILQ_HEAD(nfsd_head, nfsd) nfsd_head;
261 extern int nfsd_head_flag;
262 #define NFSD_CHECKSLP   0x01
263
264 /*
265  * These macros compare nfsrv_descript structures.
266  */
267 #define NFSW_CONTIG(o, n) \
268                 ((o)->nd_eoff >= (n)->nd_off && \
269                  !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
270
271 #define NFSW_SAMECRED(o, n) \
272         (!bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
273                 sizeof (struct ucred)))
274
275 /*
276  * Defines for WebNFS
277  */
278
279 #define WEBNFS_ESC_CHAR         '%'
280 #define WEBNFS_SPECCHAR_START   0x80
281
282 #define WEBNFS_NATIVE_CHAR      0x80
283 /*
284  * ..
285  * Possibly more here in the future.
286  */
287
288 /*
289  * Macro for converting escape characters in WebNFS pathnames.
290  * Should really be in libkern.
291  */
292
293 #define HEXTOC(c) \
294         ((c) >= 'a' ? ((c) - ('a' - 10)) : \
295             ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
296 #define HEXSTRTOI(p) \
297         ((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
298
299 #ifdef NFS_DEBUG
300
301 extern int nfs_debug;
302 #define NFS_DEBUG_ASYNCIO       1 /* asynchronous i/o */
303 #define NFS_DEBUG_WG            2 /* server write gathering */
304 #define NFS_DEBUG_RC            4 /* server request caching */
305
306 #define NFS_DPF(cat, args)                                      \
307         do {                                                    \
308                 if (nfs_debug & NFS_DEBUG_##cat) printf args;   \
309         } while (0)
310
311 #else
312
313 #define NFS_DPF(cat, args)
314
315 #endif
316
317 int     nfs_getreq(struct nfsrv_descript *, struct nfsd *, int);
318 int     nfsrv_send(struct socket *, struct sockaddr *, struct mbuf *);
319 struct mbuf *nfs_rephead(int, struct nfsrv_descript *, int, struct mbuf **,
320             caddr_t *);
321 int     nfs_slplock(struct nfssvc_sock *, int);
322 void    nfs_slpunlock(struct nfssvc_sock *);
323 void    nfsm_srvfattr(struct nfsrv_descript *, struct vattr *,
324             struct nfs_fattr *);
325 void    nfsm_srvwcc(struct nfsrv_descript *, int, struct vattr *, int,
326             struct vattr *, struct mbuf **, char **);
327 void    nfsm_srvpostopattr(struct nfsrv_descript *, int, struct vattr *,
328             struct mbuf **, char **);
329 int     netaddr_match(int, union nethostaddr *, struct sockaddr *);
330 int     nfs_namei(struct nameidata *, fhandle_t *, int,
331             struct nfssvc_sock *, struct sockaddr *, struct mbuf **,
332             caddr_t *, struct vnode **, int, struct vattr *, int *,
333             struct thread *, int);
334 void    nfsm_adj(struct mbuf *, int, int);
335 int     nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *);
336 void    nfsrv_initcache(void);
337 void    nfsrv_timer(void *);
338 int     nfsrv_dorec(struct nfssvc_sock *, struct nfsd *,
339             struct nfsrv_descript **);
340 int     nfsrv_getcache(struct nfsrv_descript *, struct mbuf **);
341 void    nfsrv_updatecache(struct nfsrv_descript *, int, struct mbuf *);
342 void    nfsrv_cleancache(void);
343 void    nfsrv_init(int);
344 int     nfsrv_errmap(struct nfsrv_descript *, int);
345 void    nfsrvw_sort(gid_t *, int);
346 void    nfsrv_setcred(struct ucred *, struct ucred *);
347 int     nfsrv_object_create(struct vnode *);
348 void    nfsrv_wakenfsd(struct nfssvc_sock *slp);
349 int     nfsrv_writegather(struct nfsrv_descript **, struct nfssvc_sock *,
350             struct thread *, struct mbuf **);
351
352 int     nfsrv3_access(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
353             struct thread *td, struct mbuf **mrq);
354 int     nfsrv_commit(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
355             struct thread *td, struct mbuf **mrq);
356 int     nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
357             struct thread *td, struct mbuf **mrq);
358 int     nfsrv_fhtovp(fhandle_t *, int, struct vnode **, struct ucred *,
359             struct nfssvc_sock *, struct sockaddr *, int *, int);
360 int     nfsrv_setpublicfs(struct mount *, struct netexport *,
361             struct export_args *);
362 int     nfs_ispublicfh(fhandle_t *);
363 int     nfsrv_fsinfo(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
364             struct thread *td, struct mbuf **mrq);
365 int     nfsrv_getattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
366             struct thread *td, struct mbuf **mrq);
367 int     nfsrv_link(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
368             struct thread *td, struct mbuf **mrq);
369 int     nfsrv_lookup(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
370             struct thread *td, struct mbuf **mrq);
371 int     nfsrv_mkdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
372             struct thread *td, struct mbuf **mrq);
373 int     nfsrv_mknod(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
374             struct thread *td, struct mbuf **mrq);
375 int     nfsrv_noop(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
376             struct thread *td, struct mbuf **mrq);
377 int     nfsrv_null(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
378             struct thread *td, struct mbuf **mrq);
379 int     nfsrv_pathconf(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
380             struct thread *td, struct mbuf **mrq);
381 int     nfsrv_read(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
382             struct thread *td, struct mbuf **mrq);
383 int     nfsrv_readdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
384             struct thread *td, struct mbuf **mrq);
385 int     nfsrv_readdirplus(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
386             struct thread *td, struct mbuf **mrq);
387 int     nfsrv_readlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
388             struct thread *td, struct mbuf **mrq);
389 int     nfsrv_remove(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
390             struct thread *td, struct mbuf **mrq);
391 int     nfsrv_rename(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
392             struct thread *td, struct mbuf **mrq);
393 int     nfsrv_rmdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
394             struct thread *td, struct mbuf **mrq);
395 int     nfsrv_setattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
396             struct thread *td, struct mbuf **mrq);
397 int     nfsrv_statfs(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
398             struct thread *td, struct mbuf **mrq);
399 int     nfsrv_symlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
400             struct thread *td, struct mbuf **mrq);
401 int     nfsrv_write(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
402             struct thread *td, struct mbuf **mrq);
403 void    nfsrv_rcv(struct socket *so, void *arg, int waitflag);
404 void    nfsrv_slpderef(struct nfssvc_sock *slp);
405 #endif  /* _KERNEL */
406
407 #endif